refactoring
This commit is contained in:
parent
44ad5fc3c8
commit
6028c26ed9
|
@ -8,8 +8,6 @@ import java.util.Objects;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.rusefi.ConfigDefinition.EOL;
|
||||
|
||||
/**
|
||||
* This is an immutable model of an individual field
|
||||
* (c) Andrey Belomutskiy
|
||||
|
@ -31,16 +29,13 @@ public class ConfigField {
|
|||
|
||||
private final String name;
|
||||
private final String comment;
|
||||
public final String arraySizeAsText;
|
||||
public final String arraySizeVariableName;
|
||||
private final String type;
|
||||
private final int arraySize;
|
||||
|
||||
public final String tsInfo;
|
||||
/**
|
||||
* this property of array expands field into a bunch of variables like field1 field2 field3 etc
|
||||
*/
|
||||
public final boolean isIterate;
|
||||
public final ReaderState state;
|
||||
private final String tsInfo;
|
||||
private final boolean isIterate;
|
||||
private final ReaderState state;
|
||||
|
||||
public ConfigField(ReaderState state,
|
||||
String name,
|
||||
|
@ -62,7 +57,7 @@ public class ConfigField {
|
|||
if (!isVoid())
|
||||
Objects.requireNonNull(type);
|
||||
this.type = type;
|
||||
this.arraySizeAsText = arraySizeAsText;
|
||||
this.arraySizeVariableName = arraySizeAsText;
|
||||
this.arraySize = arraySize;
|
||||
this.tsInfo = tsInfo;
|
||||
this.isIterate = isIterate;
|
||||
|
@ -168,5 +163,20 @@ public class ConfigField {
|
|||
public int getElementSize() {
|
||||
return isVoid() ? 0 : TypesHelper.getElementSize(state, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* this property of array expands field into a bunch of variables like field1 field2 field3 etc
|
||||
*/
|
||||
public boolean isIterate() {
|
||||
return isIterate;
|
||||
}
|
||||
|
||||
public ReaderState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getTsInfo() {
|
||||
return tsInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.output.CHeaderConsumer;
|
||||
import com.rusefi.output.ConfigurationConsumer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -155,11 +154,11 @@ public class ReaderState {
|
|||
throw new IllegalStateException(cf.getName() + ": Not enclosed in a struct");
|
||||
ConfigStructure structure = state.stack.peek();
|
||||
|
||||
if (cf.isIterate) {
|
||||
if (cf.isIterate()) {
|
||||
structure.addC(cf);
|
||||
for (int i = 1; i <= cf.getArraySize(); i++) {
|
||||
ConfigField element = new ConfigField(state, cf.getName() + i, cf.getComment(), null,
|
||||
cf.getType(), 1, cf.tsInfo, false);
|
||||
cf.getType(), 1, cf.getTsInfo(), false);
|
||||
structure.addTs(element);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -37,7 +37,7 @@ public class CHeaderConsumer implements ConfigurationConsumer {
|
|||
// not an array
|
||||
cEntry += "\t" + configField.getType() + " " + configField.getName() + ";" + EOL;
|
||||
} else {
|
||||
cEntry += "\t" + configField.getType() + " " + configField.getName() + "[" + configField.arraySizeAsText + "];" + EOL;
|
||||
cEntry += "\t" + configField.getType() + " " + configField.getName() + "[" + configField.arraySizeVariableName + "];" + EOL;
|
||||
}
|
||||
return cEntry;
|
||||
}
|
||||
|
|
|
@ -43,10 +43,10 @@ public class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
|
||||
public static int writeJavaFields(ConfigField configField, String prefix, Writer javaFieldsWriter, int tsPosition, ConfigField next, int bitIndex) throws IOException {
|
||||
ConfigStructure cs = configField.state.structures.get(configField.getType());
|
||||
ConfigStructure cs = configField.getState().structures.get(configField.getType());
|
||||
if (cs != null) {
|
||||
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
|
||||
return writeJavaFields(cs.tsFields, configField.state, prefix + extraPrefix, javaFieldsWriter, tsPosition);
|
||||
return writeJavaFields(cs.tsFields, configField.getState(), prefix + extraPrefix, javaFieldsWriter, tsPosition);
|
||||
}
|
||||
|
||||
String nameWithPrefix = prefix + configField.getName();
|
||||
|
|
|
@ -29,7 +29,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
|||
|
||||
VariableRegistry.INSTANCE.register(nameWithPrefix + "_offset", tsPosition);
|
||||
|
||||
ConfigStructure cs = configField.state.structures.get(configField.getType());
|
||||
ConfigStructure cs = configField.getState().structures.get(configField.getType());
|
||||
if (cs != null) {
|
||||
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
|
||||
return cs.writeTunerStudio(prefix + extraPrefix, tsHeader, tsPosition);
|
||||
|
@ -47,17 +47,17 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
|||
return tsPosition;
|
||||
}
|
||||
|
||||
if (configField.state.tsCustomLine.containsKey(configField.getType())) {
|
||||
String bits = configField.state.tsCustomLine.get(configField.getType());
|
||||
if (configField.getState().tsCustomLine.containsKey(configField.getType())) {
|
||||
String bits = configField.getState().tsCustomLine.get(configField.getType());
|
||||
tsHeader.write("\t" + addTabsUpTo(nameWithPrefix, LENGTH));
|
||||
int size = configField.state.tsCustomSize.get(configField.getType());
|
||||
int size = configField.getState().tsCustomSize.get(configField.getType());
|
||||
// tsHeader.headerWrite("\t" + size + ",");
|
||||
// tsHeader.headerWrite("\t" + tsPosition + ",");
|
||||
bits = bits.replaceAll("@OFFSET@", "" + tsPosition);
|
||||
tsHeader.write("\t = " + bits);
|
||||
|
||||
tsPosition += size;
|
||||
} else if (configField.tsInfo == null) {
|
||||
} else if (configField.getTsInfo() == null) {
|
||||
tsHeader.write(";no TS info - skipping " + prefix + configField.getName() + " offset " + tsPosition);
|
||||
tsPosition += configField.getArraySize() * configField.getElementSize();
|
||||
} else if (configField.getArraySize() != 1) {
|
||||
|
@ -65,14 +65,14 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
|||
tsHeader.write(TypesHelper.convertToTs(configField.getType()) + ",");
|
||||
tsHeader.write("\t" + tsPosition + ",");
|
||||
tsHeader.write("\t[" + configField.getArraySize() + "],");
|
||||
tsHeader.write("\t" + configField.tsInfo);
|
||||
tsHeader.write("\t" + configField.getTsInfo());
|
||||
|
||||
tsPosition += configField.getArraySize() * configField.getElementSize();
|
||||
} else {
|
||||
tsHeader.write("\t" + addTabsUpTo(nameWithPrefix, LENGTH) + "\t\t= scalar, ");
|
||||
tsHeader.write(TypesHelper.convertToTs(configField.getType()) + ",");
|
||||
tsHeader.write("\t" + tsPosition + ",");
|
||||
tsHeader.write("\t" + configField.tsInfo);
|
||||
tsHeader.write("\t" + configField.getTsInfo());
|
||||
tsPosition += configField.getArraySize() * configField.getElementSize();
|
||||
}
|
||||
tsHeader.write(EOL);
|
||||
|
|
|
@ -20,7 +20,7 @@ public class ConfigFieldParserTest {
|
|||
assertEquals(cf.getType(), "uint8_t");
|
||||
assertEquals(cf.getArraySize(), 8);
|
||||
assertEquals(cf.getSize(null), 8);
|
||||
assertFalse("isIterate", cf.isIterate);
|
||||
assertFalse("isIterate", cf.isIterate());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,13 +43,13 @@ public class ConfigFieldParserTest {
|
|||
assertEquals(cf.getType(), "int_8");
|
||||
assertEquals(cf.getName(), "fi_eld");
|
||||
assertEquals("Comment", cf.getComment(), "comm_");
|
||||
assertEquals(cf.tsInfo, "ts");
|
||||
assertEquals(cf.getTsInfo(), "ts");
|
||||
}
|
||||
{
|
||||
ConfigField cf = ConfigField.parse(state, "int[3 iterate] field");
|
||||
assertEquals(cf.getType(), "int");
|
||||
assertEquals(cf.getArraySize(), 3);
|
||||
assertTrue("isIterate", cf.isIterate);
|
||||
assertTrue("isIterate", cf.isIterate());
|
||||
}
|
||||
{
|
||||
ConfigField cf = ConfigField.parse(state, "int16_t crankingRpm;This,. value controls what RPM values we consider 'cranking' (any RPM below 'crankingRpm')\\nAnything above 'crankingRpm' would be 'running'");
|
||||
|
|
Loading…
Reference in New Issue