getting ready for enum file split

This commit is contained in:
rusefi 2019-06-02 16:16:06 -04:00
parent 0e1d740591
commit f268317561
8 changed files with 80 additions and 41 deletions

View File

@ -1,12 +1,12 @@
// auto-generated from.\controllers/algo/rusefi_enums.h
#include "global.h"
#include "rusefi_enums.h"
// auto-generated from rusefi_enums.h
// by enum2string.jar tool
// on Tue May 28 22:08:21 EDT 2019
// on Sun Jun 02 16:14:34 EDT 2019
// see also gen_config_and_enums.bat
#include "global.h"
#include "rusefi_enums.h"
const char *getPidAutoTune_AutoTunerState(PidAutoTune_AutoTunerState value){
switch(value) {
case AUTOTUNER_OFF:

View File

@ -1,13 +1,13 @@
// auto-generated from.\controllers/algo/rusefi_enums.h
// auto-generated from rusefi_enums.h
// by enum2string.jar tool
// on Tue May 28 22:08:21 EDT 2019
// on Sun Jun 02 16:14:34 EDT 2019
// see also gen_config_and_enums.bat
#include "rusefi_enums.h"
#ifndef _A_H_HEADER_
#define _A_H_HEADER_
#include "rusefi_enums.h"
const char *getPidAutoTune_AutoTunerState(PidAutoTune_AutoTunerState value);
const char *getPidAutoTune_Peak(PidAutoTune_Peak value);
const char *getAdc_channel_e(adc_channel_e value);

View File

@ -1,3 +1,3 @@
rem This batch files reads rusefi_enums.h and produses auto_generated_enums.* files
java -jar ../java_tools/enum2string.jar . controllers/algo
java -jar ../java_tools/enum2string.jar -inputPath . -outputPath controllers/algo

Binary file not shown.

View File

@ -43,7 +43,7 @@ public class BoardReader {
Map<String, Object> data = yaml.load(new FileReader(firmwarePath + "/config/boards/" + boardName + "/mapping.yaml"));
System.out.println(data);
EnumsReader.process(new FileReader(firmwarePath + File.separator + EnumToString.RELATIVE_PATH));
EnumsReader.process(new FileReader(firmwarePath + File.separator + EnumToString.COMMON_HEADER_RELATIVE_NAME));
BufferedWriter bw = new BufferedWriter(new FileWriter(outputPath + File.separator + boardName + "_prefix.txt"));

Binary file not shown.

View File

@ -12,26 +12,70 @@ import java.util.*;
*/
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
public class EnumToString {
public final static StringBuilder cppFileContent = new StringBuilder();
private final static StringBuilder cppFileContent = new StringBuilder();
private final static StringBuilder includesSection = new StringBuilder();
private final static StringBuilder bothFilesHeader = new StringBuilder("// by enum2string.jar tool\r\n" +
"// on " + new Date() + "\r\n" +
"// see also gen_config_and_enums.bat\r\n" +
"\r\n" +
"\r\n" +
"\r\n");
private final static StringBuilder headerFileContent = new StringBuilder();
public static final String RELATIVE_PATH = "controllers/algo/rusefi_enums.h";
public static final String COMMON_HEADER_RELATIVE_NAME = "controllers/algo/rusefi_enums.h";
private final static String KEY_INPUT_PATH = "-inputPath";
// private final static String KEY_INPUT_FILE = "-inputFile";
private final static String KEY_OUTPUT = "-outputPath";
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("Please specify two parameters: path to firmware folder and path to output folder");
if (args.length < 4) {
System.out.println("Please specify at least\n\n" +
KEY_INPUT_PATH + "XXX\r\n" +
// KEY_INPUT_FILE + "XXX" +
KEY_OUTPUT + "XXX\r\n"
);
return;
}
String inputPath = args[0];
String outputPath = args[1];
String inputPath = null;
String outputPath = null;
for (int i = 0; i < args.length - 1; i += 2) {
String key = args[i];
if (key.equals(KEY_INPUT_PATH)) {
inputPath = args[i + 1];
// } else if (key.equals(KEY_INPUT_FILE)) {
// String inputFile = args[i + 1];
// consumeFile(inputPath, inputFile);
} else if (key.equals(KEY_OUTPUT)) {
outputPath = args[i + 1];
}
}
consumeFile(inputPath, COMMON_HEADER_RELATIVE_NAME);
headerFileContent.append("#ifndef _A_H_HEADER_\r\n");
headerFileContent.append("#define _A_H_HEADER_\r\n");
processFile(inputPath + File.separator + RELATIVE_PATH);
outputData();
cppFileContent.insert(0, bothFilesHeader.toString());
cppFileContent.insert(0, includesSection);
headerFileContent.insert(0, includesSection);
System.out.println("includesSection:\r\n" + includesSection + "end of includesSection\r\n");
cppFileContent.insert(0, "#include \"global.h\"\r\n");
headerFileContent.insert(0, bothFilesHeader.toString());
headerFileContent.append("#endif /*_A_H_HEADER_ */\r\n");
writeCppAndHeaderFiles(outputPath + File.separator + "auto_generated_enums");
}
private static void writeCppAndHeaderFiles(String outFileName) throws IOException {
@ -44,32 +88,18 @@ public class EnumToString {
bw.close();
}
private static void processFile(String inFileName) throws IOException {
String header = "// auto-generated from" + inFileName + "\r\n" +
"// by enum2string.jar tool\r\n" +
"// on " + new Date() +"\r\n" +
"// see also gen_config_and_enums.bat\r\n" +
"\r\n" +
"\r\n" +
"\r\n";
cppFileContent.append(header);
EnumToString.headerFileContent.insert(0, header);
File f = new File(inFileName);
private static void consumeFile(String inputPath, String inFileName) throws IOException {
File f = new File(inputPath + File.separator + inFileName);
System.out.println("Reading from " + inFileName);
String simpleFileName = f.getName();
cppFileContent.append("#include \"global.h\"\r\n");
cppFileContent.append("#include \"" + simpleFileName + "\"\r\n");
EnumToString.headerFileContent.append("#include \"" + simpleFileName + "\"\r\n");
bothFilesHeader.insert(0, "// auto-generated from " + simpleFileName + "\r\n");
process(new FileReader(inFileName));
includesSection.append("#include \"" + simpleFileName + "\"\r\n");
EnumsReader.process(new FileReader(inFileName));
}
public static void process(Reader reader) throws IOException {
EnumsReader.process(reader);
public static void outputData() {
for (Map.Entry<String, Map<String, Value>> e : EnumsReader.enums.entrySet()) {
String enumName = e.getKey();
cppFileContent.append(makeCode(enumName, e.getValue().values()));
@ -106,4 +136,8 @@ public class EnumToString {
private static String capitalize(String enumName) {
return Character.toUpperCase(enumName.charAt(0)) + enumName.substring(1);
}
public static String getCppFileContent() {
return cppFileContent.toString();
}
}

View File

@ -4,16 +4,21 @@ import com.rusefi.enum_reader.Value;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static com.rusefi.EnumsReader.isKeyValueLine;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class EnumToStringTest {
public static void process(Reader reader) throws IOException {
EnumsReader.process(reader);
EnumToString.outputData();
}
@Test
public void testParseLine() {
assertTrue(isKeyValueLine("MIN"));
@ -24,7 +29,7 @@ public class EnumToStringTest {
@Test
public void parseEnum() throws IOException {
EnumToString.clear();
EnumToString.process(new StringReader(
process(new StringReader(
"typedef enum {\n" +
"\tGPIO_UNASSIGNED = 0,\n" +
"\tGPIO_INVALID = 1,\n" +
@ -43,13 +48,13 @@ public class EnumToStringTest {
" return \"GPIO_UNASSIGNED\";\r\n" +
" }\r\n" +
" return NULL;\r\n" +
"}\r\n", EnumToString.cppFileContent.toString());
"}\r\n", EnumToString.getCppFileContent());
}
@Test
public void parsePackedEnum() throws IOException {
EnumToString.clear();
EnumToString.process(new StringReader(
process(new StringReader(
"typedef enum __attribute__ ((__packed__)) {\n" +
"\tGPIO_UNASSIGNED = 0,\n" +
"\tGPIO_INVALID = 1,\n" +
@ -62,6 +67,6 @@ public class EnumToStringTest {
" return \"GPIO_UNASSIGNED\";\r\n" +
" }\r\n" +
" return NULL;\r\n" +
"}\r\n", EnumToString.cppFileContent.toString());
"}\r\n", EnumToString.getCppFileContent());
}
}