From ed799501a89ce04cd427a14292b27efc7f562f93 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sat, 16 Oct 2021 20:44:07 -0400 Subject: [PATCH] probably progress --- .../java/com/rusefi/newparse/ParseState.java | 16 ++++++++-------- .../java/com/rusefi/newparse/parsing/Type.java | 3 ++- .../com/rusefi/test/ConfigFieldParserTest.java | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/ParseState.java b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/ParseState.java index bffde37fb9..a091987728 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/ParseState.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/ParseState.java @@ -14,10 +14,10 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; public class ParseState extends RusefiConfigGrammarBaseListener { - Map definitions = new HashMap<>(); - Map structs = new HashMap<>(); - List structList = new ArrayList<>(); - Map typedefs = new HashMap<>(); + private final Map definitions = new HashMap<>(); + private final Map structs = new HashMap<>(); + private final List structList = new ArrayList<>(); + private final Map typedefs = new HashMap<>(); private final EnumsReader enumsReader; @@ -176,7 +176,7 @@ public class ParseState extends RusefiConfigGrammarBaseListener { FieldOptions options = new FieldOptions(); handleFieldOptionsList(options, ctx.fieldOptionsList()); - this.typedefs.put(this.typedefName, new ScalarTypedef(this.typedefName, datatype, options)); + typedefs.put(this.typedefName, new ScalarTypedef(this.typedefName, datatype, options)); } @Override @@ -219,7 +219,7 @@ public class ParseState extends RusefiConfigGrammarBaseListener { .toArray(n -> new String[n]); // Convert back to array } - this.typedefs.put(this.typedefName, new EnumTypedef(this.typedefName, datatype, endBit, values)); + typedefs.put(this.typedefName, new EnumTypedef(this.typedefName, datatype, endBit, values)); } @Override @@ -229,7 +229,7 @@ public class ParseState extends RusefiConfigGrammarBaseListener { FieldOptions options = new FieldOptions(); handleFieldOptionsList(options, ctx.fieldOptionsList()); - this.typedefs.put(this.typedefName, new ArrayTypedef(this.typedefName, this.arrayDim, datatype, options)); + typedefs.put(this.typedefName, new ArrayTypedef(this.typedefName, this.arrayDim, datatype, options)); } @Override @@ -328,7 +328,7 @@ public class ParseState extends RusefiConfigGrammarBaseListener { } // Check first if we have a typedef for this type - Typedef typedef = this.typedefs.get(type); + Typedef typedef = typedefs.get(type); FieldOptions options = null; if (typedef != null) { diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/parsing/Type.java b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/parsing/Type.java index c3c7a8610d..fb9ed17c05 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/parsing/Type.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/parsing/Type.java @@ -27,7 +27,8 @@ public enum Type { } public static Optional findByCtype(String cType) { - return Arrays.stream(Type.values()).filter(t -> t.cType.equals(cType)).findFirst(); + String cTypeWithAlas = "floatms_t".equals(cType) ? "float" : cType; + return Arrays.stream(Type.values()).filter(t -> t.cType.equals(cTypeWithAlas)).findFirst(); } public static Type findByTsType(String tsType) { diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/test/ConfigFieldParserTest.java b/java_tools/configuration_definition/src/main/java/com/rusefi/test/ConfigFieldParserTest.java index 46880659e8..b66e74b324 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/test/ConfigFieldParserTest.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/test/ConfigFieldParserTest.java @@ -31,6 +31,23 @@ public class ConfigFieldParserTest { } } + @Test + public void testFloatMsAlias() throws IOException { + String test = "struct pid_s\n" + + "floatms_t afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" + + "percent_t afr_typet;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" + + "end_struct\n"; + ReaderState state = new ReaderState(); + BufferedReader reader = new BufferedReader(new StringReader(test)); + + CharArrayWriter writer = new CharArrayWriter(); + TestTSProjectConsumer javaFieldsConsumer = new TestTSProjectConsumer(writer, "", state); + state.readBufferedReader(reader, Arrays.asList(javaFieldsConsumer)); + assertEquals("afr_type = scalar, F32, 0, \"ms\", 1, 0, 0, 3000, 0\n" + + "afr_typet = scalar, F32, 4, \"ms\", 1, 0, 0, 3000, 0\n" + + "; total TS size = 8\n", new String(writer.toCharArray())); + } + @Test public void testCustomEnum() throws IOException { String test = "struct pid_s\n" +