diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/ParseState.java b/java_tools/configuration_definition/src/com/rusefi/newparse/ParseState.java index ca3016996d..bffde37fb9 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/ParseState.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/ParseState.java @@ -224,14 +224,12 @@ public class ParseState extends RusefiConfigGrammarBaseListener { @Override public void exitArrayTypedefSuffix(RusefiConfigGrammarParser.ArrayTypedefSuffixContext ctx) { - int arrayLength = this.arrayDim; - Type datatype = Type.findByTsType(ctx.Datatype().getText()); FieldOptions options = new FieldOptions(); handleFieldOptionsList(options, ctx.fieldOptionsList()); - this.typedefs.put(this.typedefName, new ArrayTypedef(this.typedefName, arrayLength, datatype, options)); + this.typedefs.put(this.typedefName, new ArrayTypedef(this.typedefName, this.arrayDim, datatype, options)); } @Override @@ -349,7 +347,7 @@ public class ParseState extends RusefiConfigGrammarBaseListener { handleFieldOptionsList(options, ctx.fieldOptionsList()); ScalarField prototype = new ScalarField(arTypedef.type, name, options); - scope.structFields.add(new ArrayField(prototype, arTypedef.length, false)); + scope.structFields.add(new ArrayField<>(prototype, arTypedef.length, false)); return; } else if (typedef instanceof EnumTypedef) { EnumTypedef bTypedef = (EnumTypedef) typedef; @@ -421,7 +419,7 @@ public class ParseState extends RusefiConfigGrammarBaseListener { public void exitArrayField(RusefiConfigGrammarParser.ArrayFieldContext ctx) { String type = ctx.identifier(0).getText(); String name = ctx.identifier(1).getText(); - int length = this.arrayDim; + int[] length = this.arrayDim; // check if the iterate token is present boolean iterate = ctx.Iterate() != null; @@ -453,7 +451,7 @@ public class ParseState extends RusefiConfigGrammarBaseListener { EnumField prototype = new EnumField(bTypedef.type, type, name, bTypedef.endBit, bTypedef.values, options); - scope.structFields.add(new ArrayField(prototype, length, iterate)); + scope.structFields.add(new ArrayField<>(prototype, length, iterate)); return; } else if (typedef instanceof StringTypedef) { StringTypedef sTypedef = (StringTypedef) typedef; @@ -462,7 +460,7 @@ public class ParseState extends RusefiConfigGrammarBaseListener { assert(iterate); StringField prototype = new StringField(name, sTypedef.size); - scope.structFields.add(new ArrayField(prototype, length, iterate)); + scope.structFields.add(new ArrayField<>(prototype, length, iterate)); return; } else { throw new RuntimeException("didn't understand type " + type + " for element " + name); @@ -482,17 +480,19 @@ public class ParseState extends RusefiConfigGrammarBaseListener { ScalarField prototype = new ScalarField(Type.findByCtype(type).get(), name, options); - scope.structFields.add(new ArrayField(prototype, length, iterate)); + scope.structFields.add(new ArrayField<>(prototype, length, iterate)); } - private int arrayDim = 0; + private int[] arrayDim = null; @Override public void exitArrayLengthSpec(RusefiConfigGrammarParser.ArrayLengthSpecContext ctx) { - arrayDim = evalResults.remove().intValue(); + int arrayDim0 = evalResults.remove().intValue(); if (ctx.ArrayDimensionSeparator() != null) { - arrayDim *= evalResults.remove().intValue(); + this.arrayDim = new int[] { arrayDim0, evalResults.remove().intValue() }; + } else { + this.arrayDim = new int[] { arrayDim0 }; } } diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayIterateScalarLayout.java b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayIterateScalarLayout.java index 9399a86051..f977d649de 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayIterateScalarLayout.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayIterateScalarLayout.java @@ -6,7 +6,7 @@ import com.rusefi.newparse.parsing.*; import java.io.PrintStream; public class ArrayIterateScalarLayout extends ArrayLayout { - public ArrayIterateScalarLayout(PrototypeField prototype, int length) { + public ArrayIterateScalarLayout(PrototypeField prototype, int[] length) { super(prototype, length); } @@ -24,7 +24,7 @@ public class ArrayIterateScalarLayout extends ArrayLayout { protected void writeTunerstudioLayout(PrintStream ps, TsMetadata meta, StructNamePrefixer prefixer, int offsetAdd) { // Time to iterate: emit one scalar per array element, with the name modified accordingly - for (int i = 0; i < this.length; i++) { + for (int i = 0; i < this.length[0]; i++) { emitOne(ps, meta, prefixer, this.offset + offsetAdd, i); } } diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayIterateStructLayout.java b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayIterateStructLayout.java index 776b985353..38a6b5eaae 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayIterateStructLayout.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayIterateStructLayout.java @@ -6,7 +6,7 @@ import com.rusefi.newparse.parsing.*; import java.io.PrintStream; public class ArrayIterateStructLayout extends ArrayLayout { - public ArrayIterateStructLayout(StructField prototype, int length) { + public ArrayIterateStructLayout(StructField prototype, int[] length) { super(prototype, length); } @@ -24,7 +24,7 @@ public class ArrayIterateStructLayout extends ArrayLayout { protected void writeTunerstudioLayout(PrintStream ps, TsMetadata meta, StructNamePrefixer prefixer, int offsetAdd) { // Time to iterate: emit one scalar per array element, with the name modified accordingly - for (int i = 0; i < this.length; i++) { + for (int i = 0; i < this.length[0]; i++) { emitOne(ps, meta, prefixer, this.offset + offsetAdd, i); } } diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayLayout.java b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayLayout.java index bae0c020c2..c7a7a06386 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayLayout.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ArrayLayout.java @@ -6,11 +6,11 @@ import com.rusefi.newparse.parsing.*; import java.io.PrintStream; public class ArrayLayout extends Layout { - protected final int length; + protected final int[] length; protected final Layout prototypeLayout; - public ArrayLayout(PrototypeField prototype, int length) { + public ArrayLayout(PrototypeField prototype, int[] length) { this.length = length; if (prototype instanceof ScalarField) { @@ -29,7 +29,13 @@ public class ArrayLayout extends Layout { @Override public int getSize() { - return this.prototypeLayout.getSize() * this.length; + int size = this.prototypeLayout.getSize(); + + for (int x : this.length) { + size *= x; + } + + return size; } @Override @@ -52,7 +58,7 @@ public class ArrayLayout extends Layout { @Override public String toString() { - return "Array of " + this.prototypeLayout.toString() + " length " + this.length + " " + super.toString(); + return "Array of " + this.prototypeLayout.toString() + " length " + this.length[0] + " " + super.toString(); } @Override @@ -63,7 +69,7 @@ public class ArrayLayout extends Layout { @Override public void writeCLayout(PrintStream ps) { // Skip zero length arrays, they may be used for padding - if (this.length > 0) { + if (this.length[0] > 0) { this.prototypeLayout.writeCLayout(ps, this.length); } } diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/EnumLayout.java b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/EnumLayout.java index a4f83cde64..6ca15fb859 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/EnumLayout.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/EnumLayout.java @@ -75,8 +75,8 @@ public class EnumLayout extends Layout { } @Override - public void writeCLayout(PrintStream ps, int arrayLength) { + public void writeCLayout(PrintStream ps, int[] arrayLength) { this.writeCOffsetHeader(ps, this.options.comment, this.options.units); - ps.println("\t" + this.enumType + " " + this.name + "[" + arrayLength + "];"); + ps.println("\t" + this.enumType + " " + this.name + "[" + arrayLength[0] + "];"); } } diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/Layout.java b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/Layout.java index 5e719cc74f..944ee27041 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/Layout.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/Layout.java @@ -33,7 +33,7 @@ public abstract class Layout { protected void writeTunerstudioLayout(PrintStream ps, TsMetadata meta, StructNamePrefixer prefixer, int offsetAdd) {} - protected void writeTunerstudioLayout(PrintStream ps, TsMetadata meta, StructNamePrefixer prefixer, int offsetAdd, int arrayLength) { + protected void writeTunerstudioLayout(PrintStream ps, TsMetadata meta, StructNamePrefixer prefixer, int offsetAdd, int[] arrayLength) { throw new IllegalStateException("This type can't be in an array!"); } @@ -64,7 +64,7 @@ public abstract class Layout { public void writeCLayout(PrintStream ps) { } - public void writeCLayout(PrintStream ps, int arrayLength) { + public void writeCLayout(PrintStream ps, int[] arrayLength) { throw new IllegalStateException("This type can't be in an array!"); } } diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ScalarLayout.java b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ScalarLayout.java index 1340427595..24a22ecf59 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ScalarLayout.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/ScalarLayout.java @@ -48,11 +48,11 @@ public class ScalarLayout extends Layout { } @Override - protected void writeTunerstudioLayout(PrintStream ps, TsMetadata meta, StructNamePrefixer prefixer, int offsetAdd, int arrayLength) { - if (arrayLength == 0) { + protected void writeTunerstudioLayout(PrintStream ps, TsMetadata meta, StructNamePrefixer prefixer, int offsetAdd, int[] arrayLength) { + if (arrayLength[0] == 0) { // Skip zero length arrays, they may be used for dynamic padding but TS doesn't like them return; - } else if (arrayLength == 1) { + } else if (arrayLength[0] == 1) { // For 1-length arrays, emit as a plain scalar instead writeTunerstudioLayout(ps, meta, prefixer, offsetAdd); return; @@ -61,7 +61,17 @@ public class ScalarLayout extends Layout { printBeforeArrayLength(ps, meta, prefixer, "array", offsetAdd); ps.print("["); - ps.print(arrayLength); + ps.print(arrayLength[0]); + + for (int i = 1; i < arrayLength.length; i++) { + if (arrayLength[i] == 1) { + continue; + } + + ps.print('x'); + ps.print(arrayLength[i]); + } + ps.print("], "); printAfterArrayLength(ps); @@ -86,8 +96,18 @@ public class ScalarLayout extends Layout { } @Override - public void writeCLayout(PrintStream ps, int arrayLength) { + public void writeCLayout(PrintStream ps, int[] arrayLength) { this.writeCOffsetHeader(ps, this.options.comment, this.options.units); - ps.println("\t" + this.type.cType.replaceAll("^int32_t$", "int") + " " + this.name + "[" + arrayLength + "];"); + + StringBuilder al = new StringBuilder(); + + al.append(arrayLength[0]); + + for (int i = 1; i < arrayLength.length; i++) { + al.append("]["); + al.append(arrayLength[i]); + } + + ps.println("\t" + this.type.cType.replaceAll("^int32_t$", "int") + " " + this.name + "[" + al + "];"); } } diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/StringLayout.java b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/StringLayout.java index 3b4a4aec39..b2f597ea58 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/StringLayout.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/StringLayout.java @@ -53,8 +53,8 @@ public class StringLayout extends Layout { } @Override - public void writeCLayout(PrintStream ps, int arrayLength) { + public void writeCLayout(PrintStream ps, int[] arrayLength) { this.writeCOffsetHeader(ps, null, null); - ps.println("\tchar " + this.name + "[" + arrayLength + "][" + this.size + "];"); + ps.println("\tchar " + this.name + "[" + arrayLength[0] + "][" + this.size + "];"); } } diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/StructLayout.java b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/StructLayout.java index 22c764d8e5..bece08fdbf 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/layout/StructLayout.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/layout/StructLayout.java @@ -177,9 +177,9 @@ public class StructLayout extends Layout { } @Override - public void writeCLayout(PrintStream ps, int arrayLength) { + public void writeCLayout(PrintStream ps, int[] arrayLength) { this.writeCOffsetHeader(ps, null, null); - ps.println("\t" + this.typeName + " " + this.name + "[" + arrayLength + "];"); + ps.println("\t" + this.typeName + " " + this.name + "[" + arrayLength[0] + "];"); } public void writeCLayoutRoot(PrintStream ps) { diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/parsing/ArrayField.java b/java_tools/configuration_definition/src/com/rusefi/newparse/parsing/ArrayField.java index ee725495c5..5ef828df98 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/parsing/ArrayField.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/parsing/ArrayField.java @@ -1,11 +1,11 @@ package com.rusefi.newparse.parsing; public class ArrayField implements Field { - public final int length; + public final int[] length; public final Boolean iterate; public final PrototypeType prototype; - public ArrayField(PrototypeType prototype, int length, Boolean iterate) { + public ArrayField(PrototypeType prototype, int[] length, Boolean iterate) { this.length = length; this.iterate = iterate; this.prototype = prototype; diff --git a/java_tools/configuration_definition/src/com/rusefi/newparse/parsing/ArrayTypedef.java b/java_tools/configuration_definition/src/com/rusefi/newparse/parsing/ArrayTypedef.java index d864cb3475..d4523da5db 100644 --- a/java_tools/configuration_definition/src/com/rusefi/newparse/parsing/ArrayTypedef.java +++ b/java_tools/configuration_definition/src/com/rusefi/newparse/parsing/ArrayTypedef.java @@ -3,9 +3,9 @@ package com.rusefi.newparse.parsing; public class ArrayTypedef extends Typedef { public final FieldOptions options; public final Type type; - public final int length; + public final int[] length; - public ArrayTypedef(String name, int length, Type type, FieldOptions options) { + public ArrayTypedef(String name, int[] length, Type type, FieldOptions options) { super(name); this.length = length;