Skip to content

Commit

Permalink
We have to move either forward or backwards with newparse #4441
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Jun 16, 2023
1 parent e6ca0a4 commit 752a10e
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 1,126 deletions.
Binary file modified java_tools/ConfigDefinition.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -452,78 +452,6 @@ public void enterBitField(RusefiConfigGrammarParser.BitFieldContext ctx) {

@Override
public void exitArrayField(RusefiConfigGrammarParser.ArrayFieldContext ctx) {
String type = ctx.identifier(0).getText();
String name = ctx.identifier(1).getText();
int[] length = this.arrayDim;
// check if the iterate token is present
boolean iterate = ctx.Iterate() != null;
boolean autoscale = ctx.Autoscale() != null;

if (iterate && length.length != 1) {
throw new IllegalStateException("Cannot iterate multi dimensional array: " + name);
}

// First check if this is an array of structs
if (structs.containsKey(type)) {
// iterate required for structs
assert(iterate);

scope.structFields.add(new ArrayField<>(new StructField(structs.get(type), name), length, iterate));
return;
}

// Check first if we have a typedef for this type
Typedef typedef = typedefs.get(type);

FieldOptions options;
if (typedef != null) {
if (typedef instanceof ScalarTypedef) {
ScalarTypedef scTypedef = (ScalarTypedef) typedef;
// Copy the typedef's options list - we don't want to edit it
options = scTypedef.options.copy();
// Switch to the "real" type, that is the typedef's type
type = scTypedef.type.cType;
} else if (typedef instanceof EnumTypedef) {
EnumTypedef bTypedef = (EnumTypedef) typedef;

options = new FieldOptions();
handleFieldOptionsList(options, ctx.fieldOptionsList());

EnumField prototype = new EnumField(bTypedef.type, type, name, bTypedef.endBit, bTypedef.values, options);

scope.structFields.add(new ArrayField<>(prototype, length, iterate));
return;
} else if (typedef instanceof StringTypedef) {
StringTypedef sTypedef = (StringTypedef) typedef;

// iterate required for strings
assert(iterate);

options = new FieldOptions();
handleFieldOptionsList(options, ctx.fieldOptionsList());

StringField prototype = new StringField(name, sTypedef.size, options.comment);
scope.structFields.add(new ArrayField<>(prototype, length, iterate));
return;
} else {
throw new RuntimeException("didn't understand type " + type + " for element " + name);
}
} else {
// If no typedef found, it MUST be a native type
if (!Type.findByCtype(type).isPresent()) {
throw new RuntimeException("didn't understand type " + type + " for element " + name);
}

// no typedef found, create new options list
options = new FieldOptions();
}

// Merge the read-in options list with the default from the typedef (if exists)
handleFieldOptionsList(options, ctx.fieldOptionsList());

ScalarField prototype = new ScalarField(Type.findByCtype(type).get(), name, options, autoscale);

scope.structFields.add(new ArrayField<>(prototype, length, iterate));
}

private int[] arrayDim = null;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@

import com.rusefi.BitState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.newparse.outputs.OutputChannelWriter;
import com.rusefi.output.DataLogConsumer;
import com.rusefi.output.GaugeConsumer;
import com.rusefi.output.GetOutputValueConsumer;
import com.rusefi.output.OutputsSectionConsumer;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;

import java.io.IOException;

import static com.rusefi.test.newParse.NewParseHelper.parseToOutputChannels;
import static org.junit.Assert.assertEquals;

public class OutputsTest {
@Test
public void generateSomething() throws IOException {
public void generateSomething() {
ReaderStateImpl state = new ReaderStateImpl();
state.getVariableRegistry().register("GAUGE_NAME_FUEL_WALL_CORRECTION", "wall");
String test = "struct total\n" +
Expand All @@ -29,15 +24,6 @@ public void generateSomething() throws IOException {
"float tCharge;speed density\n" +
"end_struct\n";

String expected = "root_afr_type = scalar, F32, 0, \"ms\", 1, 0\n" +
"root_afr_typet = scalar, U08, 4, \"ms\", 1, 0\n" +
"root_isForcedInduction = bits, U32, 8, [0:0]\n" +
"root_enableFan1WithAc = bits, U32, 8, [1:1]\n" +
"root_m_requested_pump = scalar, F32, 12, \"\", 1, 0\n" +
"root_tCharge = scalar, F32, 16, \"\", 1, 0\n" +
"; total TS size = 20\n";
assertEquals(expected, parseToOutputChannels(test));

String expectedLegacy = "afr_type = scalar, F32, 0, \"ms\", 1, 0\n" +
"afr_typet = scalar, U08, 4, \"ms\", 1, 0\n" +
"isForcedInduction = bits, U32, 8, [0:0]\n" +
Expand All @@ -59,9 +45,6 @@ public void tooManyBits() {
runOriginalImplementation(test);
}

/**
* while we have {@link OutputChannelWriter} here we use the current 'legacy' implementation
*/
private static OutputsSectionConsumer runOriginalImplementation(String test) {
ReaderStateImpl state = new ReaderStateImpl();

Expand Down

0 comments on commit 752a10e

Please sign in to comment.