getting ready for enum file split
This commit is contained in:
parent
0e1d740591
commit
f268317561
|
@ -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
|
// 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
|
// see also gen_config_and_enums.bat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "global.h"
|
|
||||||
#include "rusefi_enums.h"
|
|
||||||
const char *getPidAutoTune_AutoTunerState(PidAutoTune_AutoTunerState value){
|
const char *getPidAutoTune_AutoTunerState(PidAutoTune_AutoTunerState value){
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case AUTOTUNER_OFF:
|
case AUTOTUNER_OFF:
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
// auto-generated from.\controllers/algo/rusefi_enums.h
|
// auto-generated from rusefi_enums.h
|
||||||
// by enum2string.jar tool
|
// 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
|
// see also gen_config_and_enums.bat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "rusefi_enums.h"
|
||||||
#ifndef _A_H_HEADER_
|
#ifndef _A_H_HEADER_
|
||||||
#define _A_H_HEADER_
|
#define _A_H_HEADER_
|
||||||
#include "rusefi_enums.h"
|
|
||||||
const char *getPidAutoTune_AutoTunerState(PidAutoTune_AutoTunerState value);
|
const char *getPidAutoTune_AutoTunerState(PidAutoTune_AutoTunerState value);
|
||||||
const char *getPidAutoTune_Peak(PidAutoTune_Peak value);
|
const char *getPidAutoTune_Peak(PidAutoTune_Peak value);
|
||||||
const char *getAdc_channel_e(adc_channel_e value);
|
const char *getAdc_channel_e(adc_channel_e value);
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
rem This batch files reads rusefi_enums.h and produses auto_generated_enums.* files
|
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.
|
@ -43,7 +43,7 @@ public class BoardReader {
|
||||||
Map<String, Object> data = yaml.load(new FileReader(firmwarePath + "/config/boards/" + boardName + "/mapping.yaml"));
|
Map<String, Object> data = yaml.load(new FileReader(firmwarePath + "/config/boards/" + boardName + "/mapping.yaml"));
|
||||||
System.out.println(data);
|
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"));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(outputPath + File.separator + boardName + "_prefix.txt"));
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -12,26 +12,70 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
public class EnumToString {
|
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();
|
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 {
|
public static void main(String[] args) throws IOException {
|
||||||
if (args.length != 2) {
|
if (args.length < 4) {
|
||||||
System.out.println("Please specify two parameters: path to firmware folder and path to output folder");
|
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;
|
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("#ifndef _A_H_HEADER_\r\n");
|
||||||
headerFileContent.append("#define _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");
|
headerFileContent.append("#endif /*_A_H_HEADER_ */\r\n");
|
||||||
|
|
||||||
writeCppAndHeaderFiles(outputPath + File.separator + "auto_generated_enums");
|
writeCppAndHeaderFiles(outputPath + File.separator + "auto_generated_enums");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeCppAndHeaderFiles(String outFileName) throws IOException {
|
private static void writeCppAndHeaderFiles(String outFileName) throws IOException {
|
||||||
|
@ -44,32 +88,18 @@ public class EnumToString {
|
||||||
bw.close();
|
bw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processFile(String inFileName) throws IOException {
|
private static void consumeFile(String inputPath, String inFileName) throws IOException {
|
||||||
String header = "// auto-generated from" + inFileName + "\r\n" +
|
File f = new File(inputPath + File.separator + inFileName);
|
||||||
"// 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);
|
|
||||||
System.out.println("Reading from " + inFileName);
|
System.out.println("Reading from " + inFileName);
|
||||||
String simpleFileName = f.getName();
|
String simpleFileName = f.getName();
|
||||||
|
|
||||||
cppFileContent.append("#include \"global.h\"\r\n");
|
bothFilesHeader.insert(0, "// auto-generated from " + simpleFileName + "\r\n");
|
||||||
cppFileContent.append("#include \"" + simpleFileName + "\"\r\n");
|
|
||||||
EnumToString.headerFileContent.append("#include \"" + 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 {
|
public static void outputData() {
|
||||||
EnumsReader.process(reader);
|
|
||||||
for (Map.Entry<String, Map<String, Value>> e : EnumsReader.enums.entrySet()) {
|
for (Map.Entry<String, Map<String, Value>> e : EnumsReader.enums.entrySet()) {
|
||||||
String enumName = e.getKey();
|
String enumName = e.getKey();
|
||||||
cppFileContent.append(makeCode(enumName, e.getValue().values()));
|
cppFileContent.append(makeCode(enumName, e.getValue().values()));
|
||||||
|
@ -106,4 +136,8 @@ public class EnumToString {
|
||||||
private static String capitalize(String enumName) {
|
private static String capitalize(String enumName) {
|
||||||
return Character.toUpperCase(enumName.charAt(0)) + enumName.substring(1);
|
return Character.toUpperCase(enumName.charAt(0)) + enumName.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getCppFileContent() {
|
||||||
|
return cppFileContent.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,21 @@ import com.rusefi.enum_reader.Value;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static com.rusefi.EnumsReader.isKeyValueLine;
|
import static com.rusefi.EnumsReader.isKeyValueLine;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class EnumToStringTest {
|
public class EnumToStringTest {
|
||||||
|
public static void process(Reader reader) throws IOException {
|
||||||
|
EnumsReader.process(reader);
|
||||||
|
EnumToString.outputData();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseLine() {
|
public void testParseLine() {
|
||||||
assertTrue(isKeyValueLine("MIN"));
|
assertTrue(isKeyValueLine("MIN"));
|
||||||
|
@ -24,7 +29,7 @@ public class EnumToStringTest {
|
||||||
@Test
|
@Test
|
||||||
public void parseEnum() throws IOException {
|
public void parseEnum() throws IOException {
|
||||||
EnumToString.clear();
|
EnumToString.clear();
|
||||||
EnumToString.process(new StringReader(
|
process(new StringReader(
|
||||||
"typedef enum {\n" +
|
"typedef enum {\n" +
|
||||||
"\tGPIO_UNASSIGNED = 0,\n" +
|
"\tGPIO_UNASSIGNED = 0,\n" +
|
||||||
"\tGPIO_INVALID = 1,\n" +
|
"\tGPIO_INVALID = 1,\n" +
|
||||||
|
@ -43,13 +48,13 @@ public class EnumToStringTest {
|
||||||
" return \"GPIO_UNASSIGNED\";\r\n" +
|
" return \"GPIO_UNASSIGNED\";\r\n" +
|
||||||
" }\r\n" +
|
" }\r\n" +
|
||||||
" return NULL;\r\n" +
|
" return NULL;\r\n" +
|
||||||
"}\r\n", EnumToString.cppFileContent.toString());
|
"}\r\n", EnumToString.getCppFileContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parsePackedEnum() throws IOException {
|
public void parsePackedEnum() throws IOException {
|
||||||
EnumToString.clear();
|
EnumToString.clear();
|
||||||
EnumToString.process(new StringReader(
|
process(new StringReader(
|
||||||
"typedef enum __attribute__ ((__packed__)) {\n" +
|
"typedef enum __attribute__ ((__packed__)) {\n" +
|
||||||
"\tGPIO_UNASSIGNED = 0,\n" +
|
"\tGPIO_UNASSIGNED = 0,\n" +
|
||||||
"\tGPIO_INVALID = 1,\n" +
|
"\tGPIO_INVALID = 1,\n" +
|
||||||
|
@ -62,6 +67,6 @@ public class EnumToStringTest {
|
||||||
" return \"GPIO_UNASSIGNED\";\r\n" +
|
" return \"GPIO_UNASSIGNED\";\r\n" +
|
||||||
" }\r\n" +
|
" }\r\n" +
|
||||||
" return NULL;\r\n" +
|
" return NULL;\r\n" +
|
||||||
"}\r\n", EnumToString.cppFileContent.toString());
|
"}\r\n", EnumToString.getCppFileContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue