refactoring

This commit is contained in:
rusefillc 2023-01-06 11:55:59 -05:00
parent 8d2842d475
commit 12102d5bf3
45 changed files with 1075 additions and 1083 deletions

View File

@ -7,7 +7,7 @@ package com.rusefi;
public class BitState {
private int bitIndex;
public void incrementBitIndex(ConfigField cf, ConfigField next) {
public void incrementBitIndex(ConfigFieldImpl cf, ConfigFieldImpl next) {
if (!cf.isBit()) {
bitIndex = 0;
return;
@ -15,7 +15,7 @@ public class BitState {
incrementBitIndex(cf);
}
public void incrementBitIndex(ConfigField cf) {
public void incrementBitIndex(ConfigFieldImpl cf) {
if (bitIndex == 32)
throw new TooManyBitsInARow("Too many bits in a row: " + cf.getName());
bitIndex++;

View File

@ -38,7 +38,7 @@ public class ConfigDefinition {
public static void main(String[] args) {
try {
doJob(args, new ReaderState());
doJob(args, new ReaderStateImpl());
} catch (Throwable e) {
SystemOut.println(e);
e.printStackTrace();
@ -48,7 +48,7 @@ public class ConfigDefinition {
SystemOut.close();
}
public static void doJob(String[] args, ReaderState state) throws IOException {
public static void doJob(String[] args, ReaderStateImpl state) throws IOException {
if (args.length < 2) {
SystemOut.println("Please specify\r\n"
+ KEY_DEFINITION + " x\r\n"

View File

@ -1,426 +1,4 @@
package com.rusefi;
import com.devexperts.logging.Logging;
import com.opensr5.ini.field.EnumIniField;
import com.rusefi.core.Pair;
import com.rusefi.output.ConfigStructure;
import com.rusefi.output.ConfigStructureImpl;
import com.rusefi.output.DataLogConsumer;
import com.rusefi.output.JavaFieldsConsumer;
import java.util.Arrays;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.devexperts.logging.Logging.getLogging;
import static com.rusefi.output.JavaSensorsConsumer.quote;
import org.jetbrains.annotations.Nullable;
/**
* This is an immutable model of an individual field
* Andrey Belomutskiy, (c) 2013-2020
* 1/15/15
*/
public class ConfigField {
private static final Logging log = getLogging(ConfigField.class);
public static final ConfigField VOID = new ConfigField(null, "", null, null, null, new int[0], null, false, false, false, null, null);
private static final String typePattern = "([\\w\\d_]+)(\\[([\\w\\d]+)(\\sx\\s([\\w\\d]+))?(\\s([\\w\\d]+))?\\])?";
private static final String namePattern = "[[\\w\\d\\s_]]+";
private static final String commentPattern = ";([^;]*)";
private static final Pattern FIELD = Pattern.compile(typePattern + "\\s(" + namePattern + ")(" + commentPattern + ")?(;(.*))?");
private static final Pattern DIRECTIVE = Pattern.compile("#(if\\s" + namePattern + "|else|elif\\s\" + namePattern + \"|endif)");
public static final String VOID_NAME = "";
public static final String BOOLEAN_T = "boolean";
public static final String DIRECTIVE_T = "directive";
private final String name;
private final String comment;
public final String arraySizeVariableName;
private final String type;
private final int[] arraySizes;
private final String tsInfo;
private final boolean isIterate;
private final ReaderState state;
private final boolean fsioVisible;
private final boolean hasAutoscale;
private final String trueName;
private final String falseName;
private boolean isFromIterate;
private String iterateOriginalName;
private int iterateIndex;
/**
* todo: one day someone should convert this into a builder
*/
public ConfigField(ReaderState state,
String name,
String comment,
String arraySizeAsText,
String type,
int[] arraySizes,
@Nullable String tsInfo,
boolean isIterate,
boolean fsioVisible,
boolean hasAutoscale,
String trueName,
String falseName) {
this.fsioVisible = fsioVisible;
this.hasAutoscale = hasAutoscale;
this.trueName = trueName == null ? "true" : trueName;
this.falseName = falseName == null ? "false" : falseName;
Objects.requireNonNull(name, comment + " " + type);
assertNoWhitespaces(name);
this.name = name;
if (!isVoid())
Objects.requireNonNull(state);
this.state = state;
this.comment = comment;
if (!isVoid())
Objects.requireNonNull(type);
this.type = type;
this.arraySizeVariableName = arraySizeAsText;
this.arraySizes = arraySizes;
this.tsInfo = tsInfo == null ? null : state.getVariableRegistry().applyVariables(tsInfo);
this.isIterate = isIterate;
if (tsInfo != null) {
String[] tokens = getTokens();
if (tokens.length > 1) {
String scale = tokens[1].trim();
Double scaleDouble;
try {
scaleDouble = Double.parseDouble(scale);
} catch (NumberFormatException ignore) {
scaleDouble = -1.0;
}
if (!hasAutoscale && scaleDouble != 1) {
throw new IllegalStateException("Unexpected scale of " + scale + " without autoscale on " + this);
}
}
}
}
private static int getSize(VariableRegistry variableRegistry, String s) {
if (variableRegistry.intValues.containsKey(s)) {
return variableRegistry.intValues.get(s);
}
return Integer.parseInt(s);
}
public ConfigStructure getStructureType() {
return getState().getStructures().get(getType());
}
public boolean isArray() {
return arraySizeVariableName != null || arraySizes.length != 0;
}
public String getTrueName() {
return trueName;
}
public String getFalseName() {
return falseName;
}
public boolean isBit() {
return BOOLEAN_T.equalsIgnoreCase(type);
}
public boolean isDirective() {
return DIRECTIVE_T.equalsIgnoreCase(type);
}
private boolean isVoid() {
return name.equals(VOID_NAME);
}
public static void assertNoWhitespaces(String name) {
if (name.contains(" ") || name.contains("\t"))
throw new IllegalArgumentException("Invalid name: " + name);
}
/**
* @see ConfigFieldParserTest#testParseLine()
*/
public static ConfigField parse(ReaderState state, String line) {
Matcher matcher = FIELD.matcher(line);
if (!matcher.matches())
return null;
String nameString = matcher.group(8).trim();
String[] nameTokens = nameString.split("\\s");
String name = nameTokens[nameTokens.length - 1];
boolean isFsioVisible = Arrays.stream(nameTokens).anyMatch(s -> s.equalsIgnoreCase("fsio_visible"));
boolean hasAutoscale = false;
for (String autoscaler : nameTokens) {
if (autoscaler.equals("autoscale")) {
hasAutoscale = true;
break;
}
}
String comment = matcher.group(10);
validateComment(comment);
String type = matcher.group(1);
int[] arraySizes;
String arraySizeAsText;
if (matcher.group(5) != null) {
arraySizeAsText = matcher.group(3) + "][" + matcher.group(5);
arraySizes = new int[2];
arraySizes[0] = getSize(state.getVariableRegistry(), matcher.group(3));
arraySizes[1] = getSize(state.getVariableRegistry(), matcher.group(5));
} else if (matcher.group(3) != null) {
arraySizeAsText = matcher.group(3);
arraySizes = new int[1];
arraySizes[0] = getSize(state.getVariableRegistry(), arraySizeAsText);
} else {
arraySizes = new int[0];
arraySizeAsText = null;
}
String tsInfo = matcher.group(12);
boolean isIterate = "iterate".equalsIgnoreCase(matcher.group(7));
ConfigField field = new ConfigField(state, name, comment, arraySizeAsText, type, arraySizes,
tsInfo, isIterate, isFsioVisible, hasAutoscale, null, null);
if (log.debugEnabled())
log.debug("type " + type);
if (log.debugEnabled())
log.debug("name " + name);
if (log.debugEnabled())
log.debug("comment " + comment);
return field;
}
private static void validateComment(String comment) {
if (comment == null)
return;
comment = comment.trim();
if (comment.isEmpty())
return;
if (comment.charAt(0) == '"' && !EnumIniField.isQuoted(comment))
throw new MaybeSemicolorWasMissedException("This comment looks like semicolon was missed: " + comment);
}
public static boolean isPreprocessorDirective(String line) {
Matcher matcher = DIRECTIVE.matcher(line);
return matcher.matches();
}
public int getSize(ConfigField next) {
if (isBit() && next.isBit()) {
// we have a protection from 33+ bits in a row in BitState, see BitState.TooManyBitsInARow
return 0;
}
if (isBit())
return 4;
int size = getElementSize();
for (int s : arraySizes) {
size *= s;
}
return size;
}
@Override
public String toString() {
return "ConfigField{" +
"name='" + name + '\'' +
", type='" + type + '\'' +
", arraySizes=" + Arrays.toString(arraySizes) +
'}';
}
public int[] getArraySizes() {
return arraySizes;
}
public String getComment() {
if (comment == null)
return null;
return comment.trim();
}
/**
* field name without structure name
*
* @see JavaFieldsConsumer#writeJavaFields prefix parameter for structure name
*/
public String getName() {
return name;
}
/**
* @see com.rusefi.newparse.parsing.Type
*/
public String getType() {
return type;
}
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 boolean isHasAutoscale() {
return hasAutoscale;
}
public ReaderState getState() {
return state;
}
public String getTsInfo() {
return tsInfo;
}
public boolean isFsioVisible() {
return fsioVisible;
}
public String autoscaleSpec() {
Pair<Integer, Integer> pair = autoscaleSpecPair();
if (pair == null)
return null;
return pair.first + ", " + pair.second;
}
public double autoscaleSpecNumber() {
Pair<Integer, Integer> pair = autoscaleSpecPair();
if (pair == null)
return 1;
return 1.0 * pair.second / pair.first;
}
public Pair<Integer, Integer> autoscaleSpecPair() {
if (!hasAutoscale) {
return null;
}
if (tsInfo == null)
throw new IllegalArgumentException("tsInfo expected with autoscale");
String[] tokens = getTokens();
if (tokens.length < 2)
throw new IllegalArgumentException("Second comma-separated token expected in [" + tsInfo + "] for " + name);
String scale = tokens[1].trim();
double factor;
if (scale.startsWith("{") && scale.endsWith("}")) {
// Handle just basic division, not a full fledged eval loop
scale = scale.substring(1, scale.length() - 1);
String[] parts = scale.split("/");
if (parts.length != 2)
throw new IllegalArgumentException(name + ": Two parts of division expected in " + scale);
factor = Double.parseDouble(parts[0]) / Double.parseDouble(parts[1]);
} else {
factor = Double.parseDouble(scale);
}
int mul, div;
if (factor < 1.d) {
mul = (int) Math.round(1. / factor);
div = 1;
} else {
mul = 1;
div = (int) factor;
}
// Verify accuracy
double factor2 = ((double) div) / mul;
double accuracy = Math.abs((factor2 / factor) - 1.);
if (accuracy > 0.0000001) {
// Don't want to deal with exception propogation; this should adequately not compile
throw new IllegalStateException("$*@#$* Cannot accurately represent autoscale for " + tokens[1]);
}
return new Pair<>(mul, div);
}
private String[] getTokens() {
if (tsInfo == null)
return new String[0];
return tsInfo.split(",");
}
public String getUnits() {
String[] tokens = getTokens();
if (tokens.length == 0)
return "";
return unquote(tokens[0].trim());
}
public double getMin() {
String[] tokens = getTokens();
if (tokens.length < 4)
return -1;
return Double.parseDouble(tokens[3]);
}
public double getMax() {
String[] tokens = getTokens();
if (tokens.length < 5)
return -1;
return Double.parseDouble(tokens[4]);
}
public int getDigits() {
String[] tokens = getTokens();
if (tokens.length < 6)
return 0;
return Integer.parseInt(tokens[5].trim());
}
// see testUnquote
public static String unquote(String token) {
return VariableRegistry.unquote(token);
}
public void setFromIterate(String iterateOriginalName, int iterateIndex) {
this.iterateOriginalName = iterateOriginalName;
this.iterateIndex = iterateIndex;
this.isFromIterate = true;
}
public String getIterateOriginalName() {
return iterateOriginalName;
}
public int getIterateIndex() {
return iterateIndex;
}
public boolean isFromIterate() {
return isFromIterate;
}
/**
* todo: find more usages for this method?
* @see DataLogConsumer.getComment
*/
public String getCommentOrName() {
if (comment == null || comment.trim().isEmpty())
return quote(name);
return comment;
}
public String getCommentTemplated() {
return state.getVariableRegistry().applyVariables(getComment());
}
public interface ConfigField {
}

View File

@ -0,0 +1,425 @@
package com.rusefi;
import com.devexperts.logging.Logging;
import com.opensr5.ini.field.EnumIniField;
import com.rusefi.core.Pair;
import com.rusefi.output.ConfigStructure;
import com.rusefi.output.DataLogConsumer;
import com.rusefi.output.JavaFieldsConsumer;
import java.util.Arrays;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.devexperts.logging.Logging.getLogging;
import static com.rusefi.output.JavaSensorsConsumer.quote;
import org.jetbrains.annotations.Nullable;
/**
* This is an immutable model of an individual field
* Andrey Belomutskiy, (c) 2013-2020
* 1/15/15
*/
public class ConfigFieldImpl implements ConfigField {
private static final Logging log = getLogging(ConfigFieldImpl.class);
public static final ConfigFieldImpl VOID = new ConfigFieldImpl(null, "", null, null, null, new int[0], null, false, false, false, null, null);
private static final String typePattern = "([\\w\\d_]+)(\\[([\\w\\d]+)(\\sx\\s([\\w\\d]+))?(\\s([\\w\\d]+))?\\])?";
private static final String namePattern = "[[\\w\\d\\s_]]+";
private static final String commentPattern = ";([^;]*)";
private static final Pattern FIELD = Pattern.compile(typePattern + "\\s(" + namePattern + ")(" + commentPattern + ")?(;(.*))?");
private static final Pattern DIRECTIVE = Pattern.compile("#(if\\s" + namePattern + "|else|elif\\s\" + namePattern + \"|endif)");
public static final String VOID_NAME = "";
public static final String BOOLEAN_T = "boolean";
public static final String DIRECTIVE_T = "directive";
private final String name;
private final String comment;
public final String arraySizeVariableName;
private final String type;
private final int[] arraySizes;
private final String tsInfo;
private final boolean isIterate;
private final ReaderStateImpl state;
private final boolean fsioVisible;
private final boolean hasAutoscale;
private final String trueName;
private final String falseName;
private boolean isFromIterate;
private String iterateOriginalName;
private int iterateIndex;
/**
* todo: one day someone should convert this into a builder
*/
public ConfigFieldImpl(ReaderStateImpl state,
String name,
String comment,
String arraySizeAsText,
String type,
int[] arraySizes,
@Nullable String tsInfo,
boolean isIterate,
boolean fsioVisible,
boolean hasAutoscale,
String trueName,
String falseName) {
this.fsioVisible = fsioVisible;
this.hasAutoscale = hasAutoscale;
this.trueName = trueName == null ? "true" : trueName;
this.falseName = falseName == null ? "false" : falseName;
Objects.requireNonNull(name, comment + " " + type);
assertNoWhitespaces(name);
this.name = name;
if (!isVoid())
Objects.requireNonNull(state);
this.state = state;
this.comment = comment;
if (!isVoid())
Objects.requireNonNull(type);
this.type = type;
this.arraySizeVariableName = arraySizeAsText;
this.arraySizes = arraySizes;
this.tsInfo = tsInfo == null ? null : state.getVariableRegistry().applyVariables(tsInfo);
this.isIterate = isIterate;
if (tsInfo != null) {
String[] tokens = getTokens();
if (tokens.length > 1) {
String scale = tokens[1].trim();
Double scaleDouble;
try {
scaleDouble = Double.parseDouble(scale);
} catch (NumberFormatException ignore) {
scaleDouble = -1.0;
}
if (!hasAutoscale && scaleDouble != 1) {
throw new IllegalStateException("Unexpected scale of " + scale + " without autoscale on " + this);
}
}
}
}
private static int getSize(VariableRegistry variableRegistry, String s) {
if (variableRegistry.intValues.containsKey(s)) {
return variableRegistry.intValues.get(s);
}
return Integer.parseInt(s);
}
public ConfigStructure getStructureType() {
return getState().getStructures().get(getType());
}
public boolean isArray() {
return arraySizeVariableName != null || arraySizes.length != 0;
}
public String getTrueName() {
return trueName;
}
public String getFalseName() {
return falseName;
}
public boolean isBit() {
return BOOLEAN_T.equalsIgnoreCase(type);
}
public boolean isDirective() {
return DIRECTIVE_T.equalsIgnoreCase(type);
}
private boolean isVoid() {
return name.equals(VOID_NAME);
}
public static void assertNoWhitespaces(String name) {
if (name.contains(" ") || name.contains("\t"))
throw new IllegalArgumentException("Invalid name: " + name);
}
/**
* @see ConfigFieldParserTest#testParseLine()
*/
public static ConfigFieldImpl parse(ReaderStateImpl state, String line) {
Matcher matcher = FIELD.matcher(line);
if (!matcher.matches())
return null;
String nameString = matcher.group(8).trim();
String[] nameTokens = nameString.split("\\s");
String name = nameTokens[nameTokens.length - 1];
boolean isFsioVisible = Arrays.stream(nameTokens).anyMatch(s -> s.equalsIgnoreCase("fsio_visible"));
boolean hasAutoscale = false;
for (String autoscaler : nameTokens) {
if (autoscaler.equals("autoscale")) {
hasAutoscale = true;
break;
}
}
String comment = matcher.group(10);
validateComment(comment);
String type = matcher.group(1);
int[] arraySizes;
String arraySizeAsText;
if (matcher.group(5) != null) {
arraySizeAsText = matcher.group(3) + "][" + matcher.group(5);
arraySizes = new int[2];
arraySizes[0] = getSize(state.getVariableRegistry(), matcher.group(3));
arraySizes[1] = getSize(state.getVariableRegistry(), matcher.group(5));
} else if (matcher.group(3) != null) {
arraySizeAsText = matcher.group(3);
arraySizes = new int[1];
arraySizes[0] = getSize(state.getVariableRegistry(), arraySizeAsText);
} else {
arraySizes = new int[0];
arraySizeAsText = null;
}
String tsInfo = matcher.group(12);
boolean isIterate = "iterate".equalsIgnoreCase(matcher.group(7));
ConfigFieldImpl field = new ConfigFieldImpl(state, name, comment, arraySizeAsText, type, arraySizes,
tsInfo, isIterate, isFsioVisible, hasAutoscale, null, null);
if (log.debugEnabled())
log.debug("type " + type);
if (log.debugEnabled())
log.debug("name " + name);
if (log.debugEnabled())
log.debug("comment " + comment);
return field;
}
private static void validateComment(String comment) {
if (comment == null)
return;
comment = comment.trim();
if (comment.isEmpty())
return;
if (comment.charAt(0) == '"' && !EnumIniField.isQuoted(comment))
throw new MaybeSemicolorWasMissedException("This comment looks like semicolon was missed: " + comment);
}
public static boolean isPreprocessorDirective(String line) {
Matcher matcher = DIRECTIVE.matcher(line);
return matcher.matches();
}
public int getSize(ConfigFieldImpl next) {
if (isBit() && next.isBit()) {
// we have a protection from 33+ bits in a row in BitState, see BitState.TooManyBitsInARow
return 0;
}
if (isBit())
return 4;
int size = getElementSize();
for (int s : arraySizes) {
size *= s;
}
return size;
}
@Override
public String toString() {
return "ConfigField{" +
"name='" + name + '\'' +
", type='" + type + '\'' +
", arraySizes=" + Arrays.toString(arraySizes) +
'}';
}
public int[] getArraySizes() {
return arraySizes;
}
public String getComment() {
if (comment == null)
return null;
return comment.trim();
}
/**
* field name without structure name
*
* @see JavaFieldsConsumer#writeJavaFields prefix parameter for structure name
*/
public String getName() {
return name;
}
/**
* @see com.rusefi.newparse.parsing.Type
*/
public String getType() {
return type;
}
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 boolean isHasAutoscale() {
return hasAutoscale;
}
public ReaderStateImpl getState() {
return state;
}
public String getTsInfo() {
return tsInfo;
}
public boolean isFsioVisible() {
return fsioVisible;
}
public String autoscaleSpec() {
Pair<Integer, Integer> pair = autoscaleSpecPair();
if (pair == null)
return null;
return pair.first + ", " + pair.second;
}
public double autoscaleSpecNumber() {
Pair<Integer, Integer> pair = autoscaleSpecPair();
if (pair == null)
return 1;
return 1.0 * pair.second / pair.first;
}
public Pair<Integer, Integer> autoscaleSpecPair() {
if (!hasAutoscale) {
return null;
}
if (tsInfo == null)
throw new IllegalArgumentException("tsInfo expected with autoscale");
String[] tokens = getTokens();
if (tokens.length < 2)
throw new IllegalArgumentException("Second comma-separated token expected in [" + tsInfo + "] for " + name);
String scale = tokens[1].trim();
double factor;
if (scale.startsWith("{") && scale.endsWith("}")) {
// Handle just basic division, not a full fledged eval loop
scale = scale.substring(1, scale.length() - 1);
String[] parts = scale.split("/");
if (parts.length != 2)
throw new IllegalArgumentException(name + ": Two parts of division expected in " + scale);
factor = Double.parseDouble(parts[0]) / Double.parseDouble(parts[1]);
} else {
factor = Double.parseDouble(scale);
}
int mul, div;
if (factor < 1.d) {
mul = (int) Math.round(1. / factor);
div = 1;
} else {
mul = 1;
div = (int) factor;
}
// Verify accuracy
double factor2 = ((double) div) / mul;
double accuracy = Math.abs((factor2 / factor) - 1.);
if (accuracy > 0.0000001) {
// Don't want to deal with exception propogation; this should adequately not compile
throw new IllegalStateException("$*@#$* Cannot accurately represent autoscale for " + tokens[1]);
}
return new Pair<>(mul, div);
}
private String[] getTokens() {
if (tsInfo == null)
return new String[0];
return tsInfo.split(",");
}
public String getUnits() {
String[] tokens = getTokens();
if (tokens.length == 0)
return "";
return unquote(tokens[0].trim());
}
public double getMin() {
String[] tokens = getTokens();
if (tokens.length < 4)
return -1;
return Double.parseDouble(tokens[3]);
}
public double getMax() {
String[] tokens = getTokens();
if (tokens.length < 5)
return -1;
return Double.parseDouble(tokens[4]);
}
public int getDigits() {
String[] tokens = getTokens();
if (tokens.length < 6)
return 0;
return Integer.parseInt(tokens[5].trim());
}
// see testUnquote
public static String unquote(String token) {
return VariableRegistry.unquote(token);
}
public void setFromIterate(String iterateOriginalName, int iterateIndex) {
this.iterateOriginalName = iterateOriginalName;
this.iterateIndex = iterateIndex;
this.isFromIterate = true;
}
public String getIterateOriginalName() {
return iterateOriginalName;
}
public int getIterateIndex() {
return iterateIndex;
}
public boolean isFromIterate() {
return isFromIterate;
}
/**
* todo: find more usages for this method?
* @see DataLogConsumer.getComment
*/
public String getCommentOrName() {
if (comment == null || comment.trim().isEmpty())
return quote(name);
return comment;
}
public String getCommentTemplated() {
return state.getVariableRegistry().applyVariables(getComment());
}
}

View File

@ -1,41 +0,0 @@
package com.rusefi;
import com.rusefi.output.ConfigurationConsumer;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public interface IReaderState {
void setWithC_Defines(boolean withC_Defines);
void doJob() throws IOException;
String getHeader();
void setDefinitionInputFile(String definitionInputFile);
void addCHeaderDestination(String cHeader);
void addPrepend(String fileName);
void addDestination(ConfigurationConsumer... consumers);
VariableRegistry getVariableRegistry();
Map<String, String> getTsCustomLine();
void setHeaderMessage(String headerMessage);
String getTsFileOutputName();
void setTsFileOutputName(String tsFileOutputName);
String getDefinitionInputFile();
List<String> getPrependFiles();
boolean isDestinationsEmpty();
boolean isStackEmpty();
}

View File

@ -46,7 +46,7 @@ public class PinoutLogic {
return null;
}
private static void registerPins(String boardName, ArrayList<PinState> listPins, VariableRegistry registry, ReaderState state, DefinitionsState parseState) {
private static void registerPins(String boardName, ArrayList<PinState> listPins, VariableRegistry registry, ReaderStateImpl state, DefinitionsState parseState) {
if (listPins == null || listPins.isEmpty()) {
return;
}
@ -220,7 +220,7 @@ public class PinoutLogic {
return new PinoutLogic(boardName, boardYamlFiles);
}
public void registerBoardSpecificPinNames(VariableRegistry registry, ReaderState state, DefinitionsState parseState) throws IOException {
public void registerBoardSpecificPinNames(VariableRegistry registry, ReaderStateImpl state, DefinitionsState parseState) throws IOException {
readFiles();
registerPins(boardName, globalList, registry, state, parseState);

View File

@ -1,436 +1,41 @@
package com.rusefi;
import com.devexperts.logging.Logging;
import com.opensr5.ini.RawIniFile;
import com.opensr5.ini.field.EnumIniField;
import com.rusefi.enum_reader.Value;
import com.rusefi.output.*;
import com.rusefi.util.IoUtils;
import com.rusefi.util.SystemOut;
import org.jetbrains.annotations.NotNull;
import com.rusefi.output.ConfigurationConsumer;
import java.io.*;
import java.util.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import static com.devexperts.logging.Logging.getLogging;
import static com.rusefi.ConfigField.BOOLEAN_T;
import static com.rusefi.VariableRegistry.unquote;
import static com.rusefi.output.JavaSensorsConsumer.quote;
public interface ReaderState {
void setWithC_Defines(boolean withC_Defines);
/**
* We keep state here as we read configuration definition
* <p>
* Andrey Belomutskiy, (c) 2013-2020
* 12/19/18
*/
public class ReaderState implements IReaderState {
private static final Logging log = getLogging(ReaderState.class);
void doJob() throws IOException;
public static final String BIT = "bit";
private static final String CUSTOM = "custom";
private static final String END_STRUCT = "end_struct";
private static final String STRUCT_NO_PREFIX = "struct_no_prefix ";
private static final String STRUCT = "struct ";
// used to update other files
private final List<String> inputFiles = new ArrayList<>();
private final Stack<ConfigStructureImpl> stack = new Stack<>();
private final Map<String, Integer> tsCustomSize = new HashMap<>();
private final Map<String, String> tsCustomLine = new HashMap<>();
private final Map<String, ConfigStructureImpl> structures = new HashMap<>();
private String headerMessage;
// well, technically those should be a builder for state, not this state class itself
private String tsFileOutputName = "rusefi.ini";
private String definitionInputFile = null;
private boolean withC_Defines = true;
private final List<String> prependFiles = new ArrayList<>();
private final List<ConfigurationConsumer> destinations = new ArrayList<>();
String getHeader();
private final EnumsReader enumsReader = new EnumsReader();
private final VariableRegistry variableRegistry = new VariableRegistry();
void setDefinitionInputFile(String definitionInputFile);
@Override
public void setWithC_Defines(boolean withC_Defines) {
this.withC_Defines = withC_Defines;
}
void addCHeaderDestination(String cHeader);
public EnumsReader getEnumsReader() {
return enumsReader;
}
void addPrepend(String fileName);
public List<String> getInputFiles() {
return inputFiles;
}
void addDestination(ConfigurationConsumer... consumers);
private static void handleBitLine(ReaderState state, String line) {
line = line.substring(BIT.length() + 1).trim();
VariableRegistry getVariableRegistry();
String bitName;
String comment;
if (!line.contains(";")) {
bitName = line;
comment = "";
} else {
int index = line.indexOf(";");
bitName = line.substring(0, index);
comment = line.substring(index + 1);
}
String[] bitNameParts = bitName.split(",");
Map<String, String> getTsCustomLine();
if (log.debugEnabled())
log.debug("Need to align before bit " + bitName);
state.stack.peek().addAlignmentFill(state, 4);
void setHeaderMessage(String headerMessage);
String trueName = bitNameParts.length > 1 ? bitNameParts[1].replaceAll("\"", "") : null;
String falseName = bitNameParts.length > 2 ? bitNameParts[2].replaceAll("\"", "") : null;
String getTsFileOutputName();
ConfigField bitField = new ConfigField(state, bitNameParts[0], comment, null, BOOLEAN_T, new int[0], null, false, false, false, trueName, falseName);
if (state.stack.isEmpty())
throw new IllegalStateException("Parent structure expected");
ConfigStructureImpl structure = state.stack.peek();
structure.addBitField(bitField);
}
void setTsFileOutputName(String tsFileOutputName);
@Override
public void doJob() throws IOException {
for (String prependFile : prependFiles)
variableRegistry.readPrependValues(prependFile);
String getDefinitionInputFile();
/*
* this is the most important invocation - here we read the primary input file and generated code into all
* the destinations/writers
*/
SystemOut.println("Reading definition from " + definitionInputFile);
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
readBufferedReader(definitionReader, destinations);
}
List<String> getPrependFiles();
public void read(Reader reader) throws IOException {
Map<String, EnumsReader.EnumState> newEnums = EnumsReader.readStatic(reader);
boolean isDestinationsEmpty();
for (Map.Entry<String, EnumsReader.EnumState> enumFamily : newEnums.entrySet()) {
for (Map.Entry<String, Value> enumValue : enumFamily.getValue().entrySet()) {
String key = enumFamily.getKey() + "_" + enumValue.getKey();
String value = enumValue.getValue().getValue();
variableRegistry.register(key, value);
try {
int numericValue = enumValue.getValue().getIntValue();
variableRegistry.registerHex(key, numericValue);
} catch (NumberFormatException ignore) {
// ENUM_32_BITS would be an example of a non-numeric enum, let's just skip for now
}
}
}
enumsReader.enums.putAll(newEnums);
}
private void handleCustomLine(String line) {
line = line.substring(CUSTOM.length() + 1).trim();
int index = line.indexOf(' ');
String name = line.substring(0, index);
String autoEnumOptions = variableRegistry.getEnumOptionsForTunerStudio(enumsReader, name);
if (autoEnumOptions != null) {
variableRegistry.register(name + VariableRegistry.AUTO_ENUM_SUFFIX, autoEnumOptions);
}
line = line.substring(index).trim();
index = line.indexOf(' ');
String customSize = line.substring(0, index);
String tunerStudioLine = line.substring(index).trim();
tunerStudioLine = variableRegistry.applyVariables(tunerStudioLine);
int size = parseSize(customSize, line);
tsCustomSize.put(name, size);
RawIniFile.Line rawLine = new RawIniFile.Line(tunerStudioLine);
//boolean isKeyValueForm = tunerStudioLine.contains("=\"");
if (rawLine.getTokens()[0].equals("bits")) {
EnumIniField.ParseBitRange bitRange = new EnumIniField.ParseBitRange().invoke(rawLine.getTokens()[3]);
int totalCount = 1 << (bitRange.getBitSize0() + 1);
List<String> enums = Arrays.asList(rawLine.getTokens()).subList(4, rawLine.getTokens().length);
// at the moment we read 0=NONE as two tokens, thus enums.size() is divided by two
if (enums.size() / 2 > totalCount)
throw new IllegalStateException(name + ": Too many options in " + tunerStudioLine + " capacity=" + totalCount + "/size=" + enums.size());
/*
this does not work right now since smt32 and kinetis enum sizes could be different but same .txt file
todo: identify relevant bitsizes and use variables for bitsizes?
if (enums.size() <= totalCount / 2)
throw new IllegalStateException("Too many bits allocated for " + enums + " capacity=" + totalCount + "/size=" + enums.size());
*/
}
tsCustomLine.put(name, tunerStudioLine);
}
public int parseSize(String customSize, String line) {
customSize = variableRegistry.applyVariables(customSize);
customSize = customSize.replaceAll("x", "*");
line = variableRegistry.applyVariables(line);
int multPosition = customSize.indexOf(VariableRegistry.MULT_TOKEN);
if (multPosition != -1) {
String firstPart = customSize.substring(0, multPosition).trim();
int first;
try {
first = Integer.parseInt(firstPart);
} catch (NumberFormatException e) {
throw new IllegalStateException("Size in " + line);
}
return first * parseSize(customSize.substring(multPosition + 1), line);
}
try {
return Integer.parseInt(customSize);
} catch (NumberFormatException e) {
throw new IllegalStateException("Size in " + line);
}
}
private void handleEndStruct(List<ConfigurationConsumer> consumers) throws IOException {
if (stack.isEmpty())
throw new IllegalStateException("Unexpected end_struct");
ConfigStructureImpl structure = stack.pop();
if (log.debugEnabled())
log.debug("Ending structure " + structure.getName());
structure.addAlignmentFill(this, 4);
structures.put(structure.getName(), structure);
for (ConfigurationConsumer consumer : consumers)
consumer.handleEndStruct(this, structure);
}
public void readBufferedReader(String inputString, ConfigurationConsumer... consumers) {
try {
readBufferedReader(new BufferedReader(new StringReader(inputString)), Arrays.asList(consumers));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public void readBufferedReader(BufferedReader definitionReader, List<ConfigurationConsumer> consumers) throws IOException {
for (ConfigurationConsumer consumer : consumers)
consumer.startFile();
int lineIndex = 0;
String line;
while ((line = definitionReader.readLine()) != null) {
lineIndex++;
line = ToolUtil.trimLine(line);
/**
* we should ignore empty lines and comments
*/
if (ToolUtil.isEmptyDefinitionLine(line))
continue;
if (line.startsWith(STRUCT)) {
handleStartStructure(this, line.substring(STRUCT.length()), true);
} else if (line.startsWith(STRUCT_NO_PREFIX)) {
handleStartStructure(this, line.substring(STRUCT_NO_PREFIX.length()), false);
} else if (line.startsWith(END_STRUCT)) {
addBitPadding();
handleEndStruct(consumers);
} else if (line.startsWith(BIT)) {
handleBitLine(this, line);
} else if (ToolUtil.startsWithToken(line, CUSTOM)) {
handleCustomLine(line);
} else if (ToolUtil.startsWithToken(line, VariableRegistry.DEFINE)) {
/**
* for example
* #define CLT_CURVE_SIZE 16
*/
variableRegistry.processDefine(line.substring(VariableRegistry.DEFINE.length()).trim());
} else {
if (stack.isEmpty())
throw new IllegalStateException("Expected to be within structure at line " + lineIndex + ": " + line);
addBitPadding();
processField(this, line);
}
}
for (ConfigurationConsumer consumer : consumers)
consumer.endFile();
ensureEmptyAfterProcessing();
}
private void addBitPadding() {
ConfigStructureImpl structure = stack.peek();
structure.addBitPadding(this);
}
public void ensureEmptyAfterProcessing() {
if (!stack.isEmpty())
throw new IllegalStateException("Unclosed structure: " + stack.peek().getName());
}
private static void handleStartStructure(ReaderState state, String line, boolean withPrefix) {
String name;
String comment;
if (line.contains(" ")) {
int index = line.indexOf(' ');
name = line.substring(0, index);
comment = line.substring(index + 1).trim();
} else {
name = line;
comment = null;
}
ConfigStructureImpl structure = new ConfigStructureImpl(name, comment, withPrefix);
state.stack.push(structure);
if (log.debugEnabled())
log.debug("Starting structure " + structure.getName());
}
private static void processField(ReaderState state, String line) {
ConfigField cf = ConfigField.parse(state, line);
if (cf == null) {
if (ConfigField.isPreprocessorDirective(line)) {
cf = new ConfigField(state, "", line, null,
ConfigField.DIRECTIVE_T, new int[0], null, false, false, false,
null, null);
} else {
throw new IllegalStateException("Cannot parse line [" + line + "]");
}
}
if (state.stack.isEmpty())
throw new IllegalStateException(cf.getName() + ": Not enclosed in a struct");
ConfigStructureImpl structure = state.stack.peek();
Integer getPrimitiveSize = TypesHelper.getPrimitiveSize(cf.getType());
Integer customTypeSize = state.tsCustomSize.get(cf.getType());
if (getPrimitiveSize != null && getPrimitiveSize > 1) {
if (log.debugEnabled())
log.debug("Need to align before " + cf.getName());
structure.addAlignmentFill(state, getPrimitiveSize);
} else if (state.structures.containsKey(cf.getType())) {
// we are here for struct members
structure.addAlignmentFill(state, 4);
} else if (customTypeSize != null) {
structure.addAlignmentFill(state, customTypeSize % 8);
}
if (cf.isIterate()) {
structure.addC(cf);
for (int i = 1; i <= cf.getArraySizes()[0]; i++) {
String commentWithIndex = getCommentWithIndex(cf, i);
ConfigField element = new ConfigField(state, cf.getName() + i, commentWithIndex, null,
cf.getType(), new int[0], cf.getTsInfo(), false, false, cf.isHasAutoscale(), null, null);
element.setFromIterate(cf.getName(), i);
structure.addTs(element);
}
} else if (cf.isDirective()) {
structure.addTs(cf);
} else {
structure.addBoth(cf);
}
}
@NotNull
private static String getCommentWithIndex(ConfigField cf, int i) {
String unquoted = unquote(cf.getCommentOrName());
String string = unquoted + " " + i;
return quote(string);
}
@Override
public String getHeader() {
if (headerMessage == null)
throw new NullPointerException("No header message yet");
return headerMessage;
}
@Override
public void setDefinitionInputFile(String definitionInputFile) {
this.definitionInputFile = definitionInputFile;
headerMessage = ToolUtil.getGeneratedAutomaticallyTag() + definitionInputFile + " " + new Date();
inputFiles.add(definitionInputFile);
}
@Override
public void addCHeaderDestination(String cHeader) {
destinations.add(new CHeaderConsumer(this, cHeader, withC_Defines));
}
public void addJavaDestination(String fileName) {
destinations.add(new FileJavaFieldsConsumer(this, fileName, 0));
}
@Override
public void addPrepend(String fileName) {
if (fileName == null || fileName.isEmpty()) {
// see LiveDataProcessor use-case with dynamic prepend usage
return;
}
prependFiles.add(fileName);
inputFiles.add(fileName);
}
@Override
public void addDestination(ConfigurationConsumer... consumers) {
destinations.addAll(Arrays.asList(consumers));
}
public void addInputFile(String fileName) {
inputFiles.add(fileName);
}
@Override
public VariableRegistry getVariableRegistry() {
return variableRegistry;
}
public Map<String, Integer> getTsCustomSize() {
return tsCustomSize;
}
public Map<String, ? extends ConfigStructure> getStructures() {
return structures;
}
@Override
public Map<String, String> getTsCustomLine() {
return tsCustomLine;
}
@Override
public void setHeaderMessage(String headerMessage) {
this.headerMessage = headerMessage;
}
@Override
public String getTsFileOutputName() {
return tsFileOutputName;
}
@Override
public void setTsFileOutputName(String tsFileOutputName) {
this.tsFileOutputName = tsFileOutputName;
}
@Override
public String getDefinitionInputFile() {
return definitionInputFile;
}
@Override
public List<String> getPrependFiles() {
return prependFiles;
}
@Override
public boolean isDestinationsEmpty() {
return destinations.isEmpty();
}
@Override
public boolean isStackEmpty() {
return stack.isEmpty();
}
boolean isStackEmpty();
}

View File

@ -0,0 +1,436 @@
package com.rusefi;
import com.devexperts.logging.Logging;
import com.opensr5.ini.RawIniFile;
import com.opensr5.ini.field.EnumIniField;
import com.rusefi.enum_reader.Value;
import com.rusefi.output.*;
import com.rusefi.util.IoUtils;
import com.rusefi.util.SystemOut;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.*;
import static com.devexperts.logging.Logging.getLogging;
import static com.rusefi.ConfigFieldImpl.BOOLEAN_T;
import static com.rusefi.VariableRegistry.unquote;
import static com.rusefi.output.JavaSensorsConsumer.quote;
/**
* We keep state here as we read configuration definition
* <p>
* Andrey Belomutskiy, (c) 2013-2020
* 12/19/18
*/
public class ReaderStateImpl implements ReaderState {
private static final Logging log = getLogging(ReaderStateImpl.class);
public static final String BIT = "bit";
private static final String CUSTOM = "custom";
private static final String END_STRUCT = "end_struct";
private static final String STRUCT_NO_PREFIX = "struct_no_prefix ";
private static final String STRUCT = "struct ";
// used to update other files
private final List<String> inputFiles = new ArrayList<>();
private final Stack<ConfigStructureImpl> stack = new Stack<>();
private final Map<String, Integer> tsCustomSize = new HashMap<>();
private final Map<String, String> tsCustomLine = new HashMap<>();
private final Map<String, ConfigStructureImpl> structures = new HashMap<>();
private String headerMessage;
// well, technically those should be a builder for state, not this state class itself
private String tsFileOutputName = "rusefi.ini";
private String definitionInputFile = null;
private boolean withC_Defines = true;
private final List<String> prependFiles = new ArrayList<>();
private final List<ConfigurationConsumer> destinations = new ArrayList<>();
private final EnumsReader enumsReader = new EnumsReader();
private final VariableRegistry variableRegistry = new VariableRegistry();
@Override
public void setWithC_Defines(boolean withC_Defines) {
this.withC_Defines = withC_Defines;
}
public EnumsReader getEnumsReader() {
return enumsReader;
}
public List<String> getInputFiles() {
return inputFiles;
}
private static void handleBitLine(ReaderStateImpl state, String line) {
line = line.substring(BIT.length() + 1).trim();
String bitName;
String comment;
if (!line.contains(";")) {
bitName = line;
comment = "";
} else {
int index = line.indexOf(";");
bitName = line.substring(0, index);
comment = line.substring(index + 1);
}
String[] bitNameParts = bitName.split(",");
if (log.debugEnabled())
log.debug("Need to align before bit " + bitName);
state.stack.peek().addAlignmentFill(state, 4);
String trueName = bitNameParts.length > 1 ? bitNameParts[1].replaceAll("\"", "") : null;
String falseName = bitNameParts.length > 2 ? bitNameParts[2].replaceAll("\"", "") : null;
ConfigFieldImpl bitField = new ConfigFieldImpl(state, bitNameParts[0], comment, null, BOOLEAN_T, new int[0], null, false, false, false, trueName, falseName);
if (state.stack.isEmpty())
throw new IllegalStateException("Parent structure expected");
ConfigStructureImpl structure = state.stack.peek();
structure.addBitField(bitField);
}
@Override
public void doJob() throws IOException {
for (String prependFile : prependFiles)
variableRegistry.readPrependValues(prependFile);
/*
* this is the most important invocation - here we read the primary input file and generated code into all
* the destinations/writers
*/
SystemOut.println("Reading definition from " + definitionInputFile);
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
readBufferedReader(definitionReader, destinations);
}
public void read(Reader reader) throws IOException {
Map<String, EnumsReader.EnumState> newEnums = EnumsReader.readStatic(reader);
for (Map.Entry<String, EnumsReader.EnumState> enumFamily : newEnums.entrySet()) {
for (Map.Entry<String, Value> enumValue : enumFamily.getValue().entrySet()) {
String key = enumFamily.getKey() + "_" + enumValue.getKey();
String value = enumValue.getValue().getValue();
variableRegistry.register(key, value);
try {
int numericValue = enumValue.getValue().getIntValue();
variableRegistry.registerHex(key, numericValue);
} catch (NumberFormatException ignore) {
// ENUM_32_BITS would be an example of a non-numeric enum, let's just skip for now
}
}
}
enumsReader.enums.putAll(newEnums);
}
private void handleCustomLine(String line) {
line = line.substring(CUSTOM.length() + 1).trim();
int index = line.indexOf(' ');
String name = line.substring(0, index);
String autoEnumOptions = variableRegistry.getEnumOptionsForTunerStudio(enumsReader, name);
if (autoEnumOptions != null) {
variableRegistry.register(name + VariableRegistry.AUTO_ENUM_SUFFIX, autoEnumOptions);
}
line = line.substring(index).trim();
index = line.indexOf(' ');
String customSize = line.substring(0, index);
String tunerStudioLine = line.substring(index).trim();
tunerStudioLine = variableRegistry.applyVariables(tunerStudioLine);
int size = parseSize(customSize, line);
tsCustomSize.put(name, size);
RawIniFile.Line rawLine = new RawIniFile.Line(tunerStudioLine);
//boolean isKeyValueForm = tunerStudioLine.contains("=\"");
if (rawLine.getTokens()[0].equals("bits")) {
EnumIniField.ParseBitRange bitRange = new EnumIniField.ParseBitRange().invoke(rawLine.getTokens()[3]);
int totalCount = 1 << (bitRange.getBitSize0() + 1);
List<String> enums = Arrays.asList(rawLine.getTokens()).subList(4, rawLine.getTokens().length);
// at the moment we read 0=NONE as two tokens, thus enums.size() is divided by two
if (enums.size() / 2 > totalCount)
throw new IllegalStateException(name + ": Too many options in " + tunerStudioLine + " capacity=" + totalCount + "/size=" + enums.size());
/*
this does not work right now since smt32 and kinetis enum sizes could be different but same .txt file
todo: identify relevant bitsizes and use variables for bitsizes?
if (enums.size() <= totalCount / 2)
throw new IllegalStateException("Too many bits allocated for " + enums + " capacity=" + totalCount + "/size=" + enums.size());
*/
}
tsCustomLine.put(name, tunerStudioLine);
}
public int parseSize(String customSize, String line) {
customSize = variableRegistry.applyVariables(customSize);
customSize = customSize.replaceAll("x", "*");
line = variableRegistry.applyVariables(line);
int multPosition = customSize.indexOf(VariableRegistry.MULT_TOKEN);
if (multPosition != -1) {
String firstPart = customSize.substring(0, multPosition).trim();
int first;
try {
first = Integer.parseInt(firstPart);
} catch (NumberFormatException e) {
throw new IllegalStateException("Size in " + line);
}
return first * parseSize(customSize.substring(multPosition + 1), line);
}
try {
return Integer.parseInt(customSize);
} catch (NumberFormatException e) {
throw new IllegalStateException("Size in " + line);
}
}
private void handleEndStruct(List<ConfigurationConsumer> consumers) throws IOException {
if (stack.isEmpty())
throw new IllegalStateException("Unexpected end_struct");
ConfigStructureImpl structure = stack.pop();
if (log.debugEnabled())
log.debug("Ending structure " + structure.getName());
structure.addAlignmentFill(this, 4);
structures.put(structure.getName(), structure);
for (ConfigurationConsumer consumer : consumers)
consumer.handleEndStruct(this, structure);
}
public void readBufferedReader(String inputString, ConfigurationConsumer... consumers) {
try {
readBufferedReader(new BufferedReader(new StringReader(inputString)), Arrays.asList(consumers));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public void readBufferedReader(BufferedReader definitionReader, List<ConfigurationConsumer> consumers) throws IOException {
for (ConfigurationConsumer consumer : consumers)
consumer.startFile();
int lineIndex = 0;
String line;
while ((line = definitionReader.readLine()) != null) {
lineIndex++;
line = ToolUtil.trimLine(line);
/**
* we should ignore empty lines and comments
*/
if (ToolUtil.isEmptyDefinitionLine(line))
continue;
if (line.startsWith(STRUCT)) {
handleStartStructure(this, line.substring(STRUCT.length()), true);
} else if (line.startsWith(STRUCT_NO_PREFIX)) {
handleStartStructure(this, line.substring(STRUCT_NO_PREFIX.length()), false);
} else if (line.startsWith(END_STRUCT)) {
addBitPadding();
handleEndStruct(consumers);
} else if (line.startsWith(BIT)) {
handleBitLine(this, line);
} else if (ToolUtil.startsWithToken(line, CUSTOM)) {
handleCustomLine(line);
} else if (ToolUtil.startsWithToken(line, VariableRegistry.DEFINE)) {
/**
* for example
* #define CLT_CURVE_SIZE 16
*/
variableRegistry.processDefine(line.substring(VariableRegistry.DEFINE.length()).trim());
} else {
if (stack.isEmpty())
throw new IllegalStateException("Expected to be within structure at line " + lineIndex + ": " + line);
addBitPadding();
processField(this, line);
}
}
for (ConfigurationConsumer consumer : consumers)
consumer.endFile();
ensureEmptyAfterProcessing();
}
private void addBitPadding() {
ConfigStructureImpl structure = stack.peek();
structure.addBitPadding(this);
}
public void ensureEmptyAfterProcessing() {
if (!stack.isEmpty())
throw new IllegalStateException("Unclosed structure: " + stack.peek().getName());
}
private static void handleStartStructure(ReaderStateImpl state, String line, boolean withPrefix) {
String name;
String comment;
if (line.contains(" ")) {
int index = line.indexOf(' ');
name = line.substring(0, index);
comment = line.substring(index + 1).trim();
} else {
name = line;
comment = null;
}
ConfigStructureImpl structure = new ConfigStructureImpl(name, comment, withPrefix);
state.stack.push(structure);
if (log.debugEnabled())
log.debug("Starting structure " + structure.getName());
}
private static void processField(ReaderStateImpl state, String line) {
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, line);
if (cf == null) {
if (ConfigFieldImpl.isPreprocessorDirective(line)) {
cf = new ConfigFieldImpl(state, "", line, null,
ConfigFieldImpl.DIRECTIVE_T, new int[0], null, false, false, false,
null, null);
} else {
throw new IllegalStateException("Cannot parse line [" + line + "]");
}
}
if (state.stack.isEmpty())
throw new IllegalStateException(cf.getName() + ": Not enclosed in a struct");
ConfigStructureImpl structure = state.stack.peek();
Integer getPrimitiveSize = TypesHelper.getPrimitiveSize(cf.getType());
Integer customTypeSize = state.tsCustomSize.get(cf.getType());
if (getPrimitiveSize != null && getPrimitiveSize > 1) {
if (log.debugEnabled())
log.debug("Need to align before " + cf.getName());
structure.addAlignmentFill(state, getPrimitiveSize);
} else if (state.structures.containsKey(cf.getType())) {
// we are here for struct members
structure.addAlignmentFill(state, 4);
} else if (customTypeSize != null) {
structure.addAlignmentFill(state, customTypeSize % 8);
}
if (cf.isIterate()) {
structure.addC(cf);
for (int i = 1; i <= cf.getArraySizes()[0]; i++) {
String commentWithIndex = getCommentWithIndex(cf, i);
ConfigFieldImpl element = new ConfigFieldImpl(state, cf.getName() + i, commentWithIndex, null,
cf.getType(), new int[0], cf.getTsInfo(), false, false, cf.isHasAutoscale(), null, null);
element.setFromIterate(cf.getName(), i);
structure.addTs(element);
}
} else if (cf.isDirective()) {
structure.addTs(cf);
} else {
structure.addBoth(cf);
}
}
@NotNull
private static String getCommentWithIndex(ConfigFieldImpl cf, int i) {
String unquoted = unquote(cf.getCommentOrName());
String string = unquoted + " " + i;
return quote(string);
}
@Override
public String getHeader() {
if (headerMessage == null)
throw new NullPointerException("No header message yet");
return headerMessage;
}
@Override
public void setDefinitionInputFile(String definitionInputFile) {
this.definitionInputFile = definitionInputFile;
headerMessage = ToolUtil.getGeneratedAutomaticallyTag() + definitionInputFile + " " + new Date();
inputFiles.add(definitionInputFile);
}
@Override
public void addCHeaderDestination(String cHeader) {
destinations.add(new CHeaderConsumer(this, cHeader, withC_Defines));
}
public void addJavaDestination(String fileName) {
destinations.add(new FileJavaFieldsConsumer(this, fileName, 0));
}
@Override
public void addPrepend(String fileName) {
if (fileName == null || fileName.isEmpty()) {
// see LiveDataProcessor use-case with dynamic prepend usage
return;
}
prependFiles.add(fileName);
inputFiles.add(fileName);
}
@Override
public void addDestination(ConfigurationConsumer... consumers) {
destinations.addAll(Arrays.asList(consumers));
}
public void addInputFile(String fileName) {
inputFiles.add(fileName);
}
@Override
public VariableRegistry getVariableRegistry() {
return variableRegistry;
}
public Map<String, Integer> getTsCustomSize() {
return tsCustomSize;
}
public Map<String, ? extends ConfigStructure> getStructures() {
return structures;
}
@Override
public Map<String, String> getTsCustomLine() {
return tsCustomLine;
}
@Override
public void setHeaderMessage(String headerMessage) {
this.headerMessage = headerMessage;
}
@Override
public String getTsFileOutputName() {
return tsFileOutputName;
}
@Override
public void setTsFileOutputName(String tsFileOutputName) {
this.tsFileOutputName = tsFileOutputName;
}
@Override
public String getDefinitionInputFile() {
return definitionInputFile;
}
@Override
public List<String> getPrependFiles() {
return prependFiles;
}
@Override
public boolean isDestinationsEmpty() {
return destinations.isEmpty();
}
@Override
public boolean isStackEmpty() {
return stack.isEmpty();
}
}

View File

@ -17,7 +17,7 @@ public class TypesHelper {
private static final String UINT_32_T = "uint32_t";
private static final String BOOLEAN_T = "boolean";
public static int getElementSize(ReaderState state, String type) {
public static int getElementSize(ReaderStateImpl state, String type) {
Objects.requireNonNull(state);
if (type == null)
return 0;

View File

@ -3,7 +3,7 @@ package com.rusefi.ldmp;
import com.devexperts.logging.Logging;
import com.rusefi.EnumToString;
import com.rusefi.InvokeReader;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.output.*;
import com.rusefi.util.LazyFile;
import org.yaml.snakeyaml.Yaml;
@ -100,7 +100,7 @@ public class LiveDataProcessor {
baseAddressCHeader.append("#define " + name.toUpperCase() + "_BASE_ADDRESS " + startingPosition + "\n");
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
state.setDefinitionInputFile(folder + File.separator + name + ".txt");
state.setWithC_Defines(withCDefines);

View File

@ -9,7 +9,7 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer {
private final StringBuilder content = new StringBuilder();
private static String getHeaderText(FieldIteratorWithOffset iterator) {
ConfigField configField = iterator.cf;
ConfigFieldImpl configField = iterator.cf;
if (configField.isBit()) {
// unused bits are needed for proper struct memsize
String comment = "\t/**" + EOL + packComment(configField.getComment(), "\t") + "\toffset " + iterator.currentOffset + " bit " + iterator.bitState.get() + " */" + EOL;
@ -62,7 +62,7 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState readerState, ConfigStructure structure) {
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) {
if (structure.getComment() != null) {
content.append("/**" + EOL + packComment(structure.getComment(), "") + EOL + "*/" + EOL);
}

View File

@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
*/
public class CHeaderConsumer extends BaseCHeaderConsumer {
@NotNull
private final ReaderState state;
private final ReaderStateImpl state;
/**
* looks like sometimes we want to not include "define XXX value" into generated C headers
* TODO: document the use-case better
@ -24,7 +24,7 @@ public class CHeaderConsumer extends BaseCHeaderConsumer {
private final LazyFile cHeader;
private final VariableRegistry variableRegistry;
public CHeaderConsumer(ReaderState state, String destCHeader, boolean withC_Defines) {
public CHeaderConsumer(ReaderStateImpl state, String destCHeader, boolean withC_Defines) {
this.variableRegistry = state.getVariableRegistry();
this.state = state;
this.withC_Defines = withC_Defines;

View File

@ -1,6 +1,6 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.ConfigFieldImpl;
import java.util.List;
@ -9,9 +9,9 @@ public interface ConfigStructure {
int getTotalSize();
List<ConfigField> getTsFields();
List<ConfigFieldImpl> getTsFields();
List<ConfigField> getcFields();
List<ConfigFieldImpl> getcFields();
boolean isWithPrefix();

View File

@ -1,8 +1,8 @@
package com.rusefi.output;
import com.rusefi.BitState;
import com.rusefi.ConfigField;
import com.rusefi.ReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderStateImpl;
import com.rusefi.TypesHelper;
import java.util.ArrayList;
@ -10,10 +10,10 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.rusefi.ConfigField.BOOLEAN_T;
import static com.rusefi.ConfigFieldImpl.BOOLEAN_T;
/**
* Mutable representation of a list of related {@link ConfigField}
* Mutable representation of a list of related {@link ConfigFieldImpl}
* <p>
* Andrey Belomutskiy, (c) 2013-2020
* 1/15/15
@ -26,14 +26,14 @@ public class ConfigStructureImpl implements ConfigStructure {
private final String name;
private final String comment;
private final boolean withPrefix;
private final List<ConfigField> cFields = new ArrayList<>();
private final List<ConfigField> tsFields = new ArrayList<>();
private final List<ConfigFieldImpl> cFields = new ArrayList<>();
private final List<ConfigFieldImpl> tsFields = new ArrayList<>();
private int totalSize;
private final BitState readingBitState = new BitState();
private ConfigField cPrevField = ConfigField.VOID;
private ConfigFieldImpl cPrevField = ConfigFieldImpl.VOID;
private final Set<String> names = new HashSet<>();
public ConfigStructureImpl(String name, String comment, boolean withPrefix) {
@ -42,7 +42,7 @@ public class ConfigStructureImpl implements ConfigStructure {
this.withPrefix = withPrefix;
}
public void addBitField(ConfigField bitField) {
public void addBitField(ConfigFieldImpl bitField) {
addBoth(bitField);
this.readingBitState.incrementBitIndex(bitField);
}
@ -52,7 +52,7 @@ public class ConfigStructureImpl implements ConfigStructure {
return name;
}
public void addAlignmentFill(ReaderState state, int alignment) {
public void addAlignmentFill(ReaderStateImpl state, int alignment) {
if (alignment == 0)
return;
/**
@ -81,7 +81,7 @@ public class ConfigStructureImpl implements ConfigStructure {
} else {
fillSizeArray = new int[0];
}
ConfigField fill = new ConfigField(state, ALIGNMENT_FILL_AT + totalSize, "need 4 byte alignment",
ConfigFieldImpl fill = new ConfigFieldImpl(state, ALIGNMENT_FILL_AT + totalSize, "need 4 byte alignment",
"" + fillSize,
TypesHelper.UINT8_T, fillSizeArray, "\"units\", 1, 0, -20, 100, 0", false, false, false, null, null);
addBoth(fill);
@ -89,12 +89,12 @@ public class ConfigStructureImpl implements ConfigStructure {
totalSize += fillSize;
}
public void addBoth(ConfigField cf) {
public void addBoth(ConfigFieldImpl cf) {
addC(cf);
tsFields.add(cf);
}
public void addC(ConfigField cf) {
public void addC(ConfigFieldImpl cf) {
// skip duplicate names - that's the weird use-case of conditional project definition like lambdaTable
if (cf.getName().equals(cPrevField.getName()))
return;
@ -108,16 +108,16 @@ public class ConfigStructureImpl implements ConfigStructure {
cPrevField = cf;
}
public void addTs(ConfigField cf) {
public void addTs(ConfigFieldImpl cf) {
tsFields.add(cf);
}
public void addBitPadding(ReaderState readerState) {
public void addBitPadding(ReaderStateImpl readerState) {
if (readingBitState.get() == 0)
return;
int sizeAtStartOfPadding = cFields.size();
while (readingBitState.get() < 32) {
ConfigField bitField = new ConfigField(readerState, UNUSED_BIT_PREFIX + sizeAtStartOfPadding + "_" + readingBitState.get(), "", null, BOOLEAN_T, new int[0], null, false, false, false, null, null);
ConfigFieldImpl bitField = new ConfigFieldImpl(readerState, UNUSED_BIT_PREFIX + sizeAtStartOfPadding + "_" + readingBitState.get(), "", null, BOOLEAN_T, new int[0], null, false, false, false, null, null);
addBitField(bitField);
}
readingBitState.reset();
@ -129,7 +129,7 @@ public class ConfigStructureImpl implements ConfigStructure {
}
@Override
public List<ConfigField> getTsFields() {
public List<ConfigFieldImpl> getTsFields() {
return tsFields;
}
@ -138,7 +138,7 @@ public class ConfigStructureImpl implements ConfigStructure {
* in C and TS
*/
@Override
public List<ConfigField> getcFields() {
public List<ConfigFieldImpl> getcFields() {
return cFields;
}

View File

@ -1,6 +1,6 @@
package com.rusefi.output;
import com.rusefi.IReaderState;
import com.rusefi.ReaderState;
import java.io.IOException;
@ -13,5 +13,5 @@ public interface ConfigurationConsumer {
}
void handleEndStruct(IReaderState readerState, ConfigStructure structure) throws IOException;
void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException;
}

View File

@ -1,7 +1,7 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import com.rusefi.TypesHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -32,7 +32,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState readerState, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
if (readerState.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.getTsFields(), "",
(configField, prefix, prefix2) -> handle(prefix, prefix2));
@ -52,7 +52,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
}
}
private String handle(ConfigField configField, String prefix) {
private String handle(ConfigFieldImpl configField, String prefix) {
if (configField.getName().contains(UNUSED))
return "";
@ -84,13 +84,13 @@ public class DataLogConsumer implements ConfigurationConsumer {
* More detailed technical explanation should be placed in consecutive lines
*/
@NotNull
public static String getHumanGaugeName(String prefix, ConfigField configField) {
public static String getHumanGaugeName(String prefix, ConfigFieldImpl configField) {
String comment = configField.getCommentTemplated();
comment = getFirstLine(comment);
if (comment.isEmpty()) {
/**
* @see ConfigField#getCommentOrName()
* @see ConfigFieldImpl#getCommentOrName()
*/
comment = prefix + unquote(configField.getName());
}

View File

@ -1,7 +1,7 @@
package com.rusefi.output;
import com.rusefi.BitState;
import com.rusefi.ConfigField;
import com.rusefi.ConfigFieldImpl;
import java.util.List;
@ -10,20 +10,20 @@ import java.util.List;
* @see PerFieldWithStructuresIterator is there a duplication?
*/
public class FieldIterator {
private final List<ConfigField> fields;
private final List<ConfigFieldImpl> fields;
BitState bitState = new BitState();
private ConfigField prev = ConfigField.VOID;
ConfigField next;
ConfigField cf;
private ConfigFieldImpl prev = ConfigFieldImpl.VOID;
ConfigFieldImpl next;
ConfigFieldImpl cf;
public FieldIterator(List<ConfigField> fields) {
public FieldIterator(List<ConfigFieldImpl> fields) {
this.fields = fields;
}
/**
* return previous field which is not a directive
*/
public ConfigField getPrev() {
public ConfigFieldImpl getPrev() {
return prev;
}
@ -32,7 +32,7 @@ public class FieldIterator {
while (nextIndex < fields.size() && fields.get(nextIndex).isDirective())
nextIndex++;
next = nextIndex >= fields.size() ? ConfigField.VOID : fields.get(nextIndex);
next = nextIndex >= fields.size() ? ConfigFieldImpl.VOID : fields.get(nextIndex);
cf = fields.get(index);
}

View File

@ -1,13 +1,13 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.ConfigFieldImpl;
import java.util.List;
public class FieldIteratorWithOffset extends FieldIterator {
public int currentOffset;
public FieldIteratorWithOffset(List<ConfigField> tsFields) {
public FieldIteratorWithOffset(List<ConfigFieldImpl> tsFields) {
super(tsFields);
}
}

View File

@ -1,19 +1,19 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import java.util.List;
public abstract class FieldsStrategy {
public int run(IReaderState state, ConfigStructure structure, int sensorTsPosition) {
public int run(ReaderState state, ConfigStructure structure, int sensorTsPosition) {
if (state.isStackEmpty()) {
return writeFields(structure.getTsFields(), "", sensorTsPosition);
}
return sensorTsPosition;
}
protected int writeFields(List<ConfigField> tsFields, String prefix, int tsPosition) {
protected int writeFields(List<ConfigFieldImpl> tsFields, String prefix, int tsPosition) {
FieldIterator iterator = new FieldIterator(tsFields);
for (int i = 0; i < tsFields.size(); i++) {
iterator.start(i);

View File

@ -1,6 +1,6 @@
package com.rusefi.output;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.ToolUtil;
import com.rusefi.util.LazyFile;
@ -18,7 +18,7 @@ public class FileJavaFieldsConsumer extends JavaFieldsConsumer {
private final LazyFile javaFields;
private final String className;
public FileJavaFieldsConsumer(ReaderState state, String javaDestination, int baseOffset) {
public FileJavaFieldsConsumer(ReaderStateImpl state, String javaDestination, int baseOffset) {
super(state, baseOffset);
javaFields = new LazyFile(javaDestination);
String className = new File(javaDestination).getName();

View File

@ -1,7 +1,7 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@ -32,11 +32,11 @@ public class FragmentDialogConsumer implements ConfigurationConsumer {
@Override
public void handleEndStruct(IReaderState readerState, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
@Override
int writeOneField(FieldIterator iterator, String prefix, int tsPosition) {
ConfigField configField = iterator.cf;
ConfigFieldImpl configField = iterator.cf;
if (configField.getName().startsWith(ConfigStructureImpl.ALIGNMENT_FILL_AT))
return 0;

View File

@ -1,7 +1,7 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import java.io.FileWriter;
import java.io.IOException;
@ -18,7 +18,7 @@ public class GaugeConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState readerState, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
if (readerState.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.getTsFields(), "",
(state, configField, prefix) -> handle(configField, prefix));
@ -34,9 +34,9 @@ public class GaugeConsumer implements ConfigurationConsumer {
}
}
private String handle(ConfigField configField, String prefix) {
private String handle(ConfigFieldImpl configField, String prefix) {
String comment = getHumanGaugeName("", configField);
comment = ConfigField.unquote(comment);
comment = ConfigFieldImpl.unquote(comment);
if (!prefix.isEmpty()) {
comment = prefix + " " + comment;
}

View File

@ -1,7 +1,7 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import com.rusefi.TypesHelper;
import com.rusefi.core.Tuple;
import org.jetbrains.annotations.NotNull;
@ -60,7 +60,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState state, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
if (state.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.getTsFields(), "",
(readerState, cf, prefix) -> processConfig(cf, prefix), ".");
@ -74,7 +74,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
writeStringToFile(mdOutputFileName, getMdContent());
}
private String processConfig(ConfigField cf, String prefix) {
private String processConfig(ConfigFieldImpl cf, String prefix) {
if (cf.getName().contains(UNUSED) || cf.getName().contains(ALIGNMENT_FILL_AT))
return "";

View File

@ -1,7 +1,7 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import com.rusefi.TypesHelper;
import com.rusefi.core.Pair;
import org.jetbrains.annotations.NotNull;
@ -33,7 +33,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState state, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
if (state.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.getTsFields(), "",
(readerState, cf, prefix) -> processOutput(cf, prefix), ".");
@ -41,7 +41,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
}
}
private String processOutput(ConfigField cf, String prefix) {
private String processOutput(ConfigFieldImpl cf, String prefix) {
if (cf.getName().contains(UNUSED) || cf.getName().contains(ALIGNMENT_FILL_AT))
return "";

View File

@ -14,10 +14,10 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
private final StringBuilder content = new StringBuilder();
protected final StringBuffer allFields = new StringBuffer("\tpublic static final Field[] VALUES = {" + EOL);
protected final ReaderState state;
protected final ReaderStateImpl state;
private final int baseOffset;
public JavaFieldsConsumer(ReaderState state, int baseOffset) {
public JavaFieldsConsumer(ReaderStateImpl state, int baseOffset) {
this.state = state;
this.baseOffset = baseOffset;
}
@ -45,18 +45,18 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
}
}
private boolean isStringField(ConfigField configField) {
private boolean isStringField(ConfigFieldImpl configField) {
String custom = state.getTsCustomLine().get(configField.getType());
return custom != null && custom.toLowerCase().startsWith(IniFileModel.FIELD_TYPE_STRING);
}
@Override
public void handleEndStruct(IReaderState readerState, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
protected int writeOneField(FieldIterator iterator, String prefix, int tsPosition) {
ConfigField prev = iterator.getPrev();
ConfigField configField = iterator.cf;
ConfigField next = iterator.next;
ConfigFieldImpl prev = iterator.getPrev();
ConfigFieldImpl configField = iterator.cf;
ConfigFieldImpl next = iterator.next;
int bitIndex = iterator.bitState.get();
if (configField.isDirective())

View File

@ -1,7 +1,7 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import java.io.IOException;
@ -19,11 +19,11 @@ public class JavaSensorsConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState readerState, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
public int writeOneField(FieldIterator iterator, String prefix, int tsPosition) {
ConfigField configField = iterator.cf;
ConfigField next = iterator.next;
ConfigFieldImpl configField = iterator.cf;
ConfigFieldImpl next = iterator.next;
if (!configField.isBit()) {
sb.append(configField.getName()).append("(");

View File

@ -1,6 +1,6 @@
package com.rusefi.output;
import com.rusefi.IReaderState;
import com.rusefi.ReaderState;
import java.io.*;
@ -27,7 +27,7 @@ public class OutputsSectionConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState readerState, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
System.out.println("handleEndStruct");
sensorTsPosition = tsOutput.run(readerState, structure, sensorTsPosition);

View File

@ -1,7 +1,7 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import java.util.List;
@ -10,13 +10,13 @@ import java.util.List;
* @see FieldIterator is there a duplication?
*/
class PerFieldWithStructuresIterator extends FieldIterator {
private final IReaderState state;
private final ReaderState state;
private final String prefix;
private final Strategy strategy;
private final String prefixSeparator;
private final StringBuilder sb = new StringBuilder();
public PerFieldWithStructuresIterator(IReaderState state, List<ConfigField> fields, String prefix, Strategy strategy, String prefixSeparator) {
public PerFieldWithStructuresIterator(ReaderState state, List<ConfigFieldImpl> fields, String prefix, Strategy strategy, String prefixSeparator) {
super(fields);
this.state = state;
this.prefix = prefix;
@ -24,7 +24,7 @@ class PerFieldWithStructuresIterator extends FieldIterator {
this.prefixSeparator = prefixSeparator;
}
public PerFieldWithStructuresIterator(IReaderState state, List<ConfigField> fields, String prefix, Strategy strategy) {
public PerFieldWithStructuresIterator(ReaderState state, List<ConfigFieldImpl> fields, String prefix, Strategy strategy) {
this(state, fields, prefix, strategy, "_");
}
@ -55,6 +55,6 @@ class PerFieldWithStructuresIterator extends FieldIterator {
}
interface Strategy {
String process(IReaderState state, ConfigField configField, String prefix);
String process(ReaderState state, ConfigFieldImpl configField, String prefix);
}
}

View File

@ -1,6 +1,6 @@
package com.rusefi.output;
import com.rusefi.IReaderState;
import com.rusefi.ReaderState;
import com.rusefi.util.LazyFile;
import java.io.IOException;
@ -31,7 +31,7 @@ public class SdCardFieldsConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState state, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
content.handleEndStruct(state, structure);
}

View File

@ -1,7 +1,7 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import java.io.IOException;
@ -12,7 +12,7 @@ public class SdCardFieldsContent {
public String home = "engine->outputChannels";
public void handleEndStruct(IReaderState state, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
if (state.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.getTsFields(), "",
(configField, prefix, prefix2) -> processOutput(prefix, prefix2), ".");
@ -22,7 +22,7 @@ public class SdCardFieldsContent {
}
}
private String processOutput(ConfigField configField, String prefix) {
private String processOutput(ConfigFieldImpl configField, String prefix) {
if (configField.getName().startsWith(ConfigStructureImpl.ALIGNMENT_FILL_AT))
return "";
if (configField.getName().startsWith(ConfigStructureImpl.UNUSED_ANYTHING_PREFIX))
@ -38,7 +38,7 @@ public class SdCardFieldsContent {
}
}
private String getLine(ConfigField configField, String prefix, String name) {
private String getLine(ConfigFieldImpl configField, String prefix, String name) {
return "\t{" + home + "." + name +
", "
+ DataLogConsumer.getHumanGaugeName(prefix, configField) +

View File

@ -20,7 +20,7 @@ public class SignatureConsumer implements ConfigurationConsumer {
this.registry = registry;
}
public static void storeUniqueBuildId(ReaderState state, DefinitionsState parseState, String tsPath, FirmwareVersion uniqueId) {
public static void storeUniqueBuildId(ReaderStateImpl state, DefinitionsState parseState, String tsPath, FirmwareVersion uniqueId) {
// store a hash as a built-in variable
// nasty trick - do not insert signature into live data files
@ -31,7 +31,7 @@ public class SignatureConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState readerState, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
ExtraUtil.writeDefinesToFile(registry, destHeader, "by SignatureConsumer");
}
}

View File

@ -21,11 +21,11 @@ public class TSProjectConsumer implements ConfigurationConsumer {
public static final String SETTING_CONTEXT_HELP = "SettingContextHelp";
private final String tsPath;
private final ReaderState state;
private final ReaderStateImpl state;
private int totalTsSize;
private final TsOutput tsOutput;
public TSProjectConsumer(String tsPath, ReaderState state) {
public TSProjectConsumer(String tsPath, ReaderStateImpl state) {
this.tsPath = tsPath;
tsOutput = new TsOutput(true);
this.state = state;
@ -143,7 +143,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
}
@Override
public void handleEndStruct(IReaderState readerState, ConfigStructure structure) throws IOException {
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
state.getVariableRegistry().register(structure.getName() + "_size", structure.getTotalSize());
totalTsSize = tsOutput.run(readerState, structure, 0);

View File

@ -1,8 +1,7 @@
package com.rusefi.output;
import com.opensr5.ini.field.IniField;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import com.rusefi.TypesHelper;
import com.rusefi.newparse.parsing.Type;
@ -35,12 +34,12 @@ public class TsOutput {
return settingContextHelp.toString();
}
public int run(IReaderState state, ConfigStructure structure, int sensorTsPosition) {
public int run(ReaderState state, ConfigStructure structure, int sensorTsPosition) {
FieldsStrategy strategy = new FieldsStrategy() {
@Override
public int writeOneField(FieldIterator it, String prefix, int tsPosition) {
ConfigField configField = it.cf;
ConfigField next = it.next;
ConfigFieldImpl configField = it.cf;
ConfigFieldImpl next = it.next;
int bitIndex = it.bitState.get();
String nameWithPrefix = prefix + configField.getName();
@ -69,7 +68,7 @@ public class TsOutput {
ConfigStructure cs = configField.getStructureType();
if (configField.getComment() != null && configField.getComment().trim().length() > 0 && cs == null) {
String commentContent = configField.getCommentTemplated();
commentContent = ConfigField.unquote(commentContent);
commentContent = ConfigFieldImpl.unquote(commentContent);
settingContextHelp.append("\t" + nameWithPrefix + " = " + quote(commentContent) + EOL);
}
@ -145,7 +144,7 @@ public class TsOutput {
return sensorTsPosition;
}
private String handleTsInfo(ConfigField configField, String tsInfo, int multiplierIndex) {
private String handleTsInfo(ConfigFieldImpl configField, String tsInfo, int multiplierIndex) {
if (tsInfo == null || tsInfo.trim().isEmpty()) {
// default units and scale
if (isConstantsSection) {

View File

@ -1,25 +1,23 @@
package com.rusefi.test;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.TsFileContent;
import com.rusefi.output.TSProjectConsumer;
import com.rusefi.util.Output;
import org.junit.Test;
import java.io.*;
import java.util.Arrays;
import java.util.Collections;
import static org.junit.Assert.assertTrue;
public class BitParsingTest {
@Test
public void testBitParser() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String inputString = "struct pid_s\n" +
ReaderState.BIT + " fieldName\n" +
ReaderState.BIT + " fieldName2,\"si\",\"nada\";comment\n" +
ReaderStateImpl.BIT + " fieldName\n" +
ReaderStateImpl.BIT + " fieldName2,\"si\",\"nada\";comment\n" +
"end_struct\n";
StringWriter sw = new StringWriter();

View File

@ -1,17 +1,15 @@
package com.rusefi.test;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.output.JavaFieldsConsumer;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
public class ConfigFieldParserIssue1057Test {
@Test
public void testBitsPadding() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
String inputString = "struct pid_s\nbit activateAuxPid1;\n" +

View File

@ -1,7 +1,7 @@
package com.rusefi.test;
import com.rusefi.ConfigField;
import com.rusefi.ReaderState;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderStateImpl;
import com.rusefi.TypesHelper;
import com.rusefi.VariableRegistry;
import com.rusefi.output.*;
@ -17,9 +17,9 @@ public class ConfigFieldParserTest {
@Test
public void testByteArray() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
{
ConfigField cf = ConfigField.parse(state, "uint8_t[8] field");
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "uint8_t[8] field");
assertEquals(cf.getType(), "uint8_t");
assertEquals(cf.getArraySizes().length, 1);
assertEquals(cf.getArraySizes()[0], 8);
@ -30,9 +30,9 @@ public class ConfigFieldParserTest {
@Test
public void testByte3dArray() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
{
ConfigField cf = ConfigField.parse(state, "uint8_t[8 x 16] field");
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "uint8_t[8 x 16] field");
assertEquals(cf.getType(), "uint8_t");
assertEquals(cf.getArraySizes().length, 2);
assertEquals(cf.getArraySizes()[0], 8);
@ -48,7 +48,7 @@ public class ConfigFieldParserTest {
"floatms_t afr_type;PID dTime;\"ms\", 1.0, 0, 0, 3000, 0, noMsqSave\n" +
"percent_t afr_typet;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
@ -64,7 +64,7 @@ public class ConfigFieldParserTest {
"int afr_type2;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"int afr_type1;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer();
state.readBufferedReader(test, consumer);
@ -79,7 +79,7 @@ public class ConfigFieldParserTest {
"ego_sensor_e afr_type2;\n" +
"int16_t int\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
@ -98,7 +98,7 @@ public class ConfigFieldParserTest {
"ego_sensor_e afr_type2;\n" +
"int8_t int\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
@ -117,7 +117,7 @@ public class ConfigFieldParserTest {
"ego_sensor_e2 afr_type1;\n" +
"ego_sensor_e2 afr_type2;\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
@ -135,7 +135,7 @@ public class ConfigFieldParserTest {
"int8_t int2\n" +
"ego_sensor_e4 afr_type3;\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
@ -153,7 +153,7 @@ public class ConfigFieldParserTest {
"\tint16_t periodMs2;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"\tint periodSec2;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
state.readBufferedReader(test, (javaFieldsConsumer));
@ -161,7 +161,7 @@ public class ConfigFieldParserTest {
assertEquals(16, TypesHelper.getElementSize(state, "pid_s"));
ConfigStructure structure = state.getStructures().get("pid_s");
ConfigField firstField = structure.getcFields().get(0);
ConfigFieldImpl firstField = structure.getcFields().get(0);
assertEquals("ms", firstField.getUnits());
}
@ -174,7 +174,7 @@ public class ConfigFieldParserTest {
"\tuint8_t[6] autoscale rpmBins;;\"rpm\", 1, 0, 0, 12000, 0\n" +
"\tuint8_t[6] autoscale values;;\"volts\", 1, 0, 0, 2.5, 2\n" +
"end_struct\n\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
state.readBufferedReader(test, (javaFieldsConsumer));
@ -191,7 +191,7 @@ public class ConfigFieldParserTest {
"#define ERROR_BUFFER_SIZE \"***\"\n" +
"end_struct\n" +
"";
new ReaderState().readBufferedReader(test);
new ReaderStateImpl().readBufferedReader(test);
}
@Test(expected = IllegalStateException.class)
@ -200,7 +200,7 @@ public class ConfigFieldParserTest {
VariableRegistry.DEFINE + " show show_Hellen121vag_presets true\n" +
"end_struct\n" +
"";
new ReaderState().readBufferedReader(test);
new ReaderStateImpl().readBufferedReader(test);
}
@Test
@ -213,7 +213,7 @@ public class ConfigFieldParserTest {
"end_struct\n" +
"";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
state.readBufferedReader(test);
assertEquals("#define ERROR_BUFFER_COUNT 120\n" +
@ -230,7 +230,7 @@ public class ConfigFieldParserTest {
"end_struct\n" +
"";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
TSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
@ -243,7 +243,7 @@ public class ConfigFieldParserTest {
@Test
public void useCustomType() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String test = "struct pid_s\n" +
"#define ERROR_BUFFER_SIZE 120\n" +
"\tcustom critical_error_message_t @@ERROR_BUFFER_SIZE@@ string, ASCII, @OFFSET@, @@ERROR_BUFFER_SIZE@@\n" +
@ -263,7 +263,7 @@ public class ConfigFieldParserTest {
@Test
public void testDefineChar() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String test =
"#define SD_r 'r'\n" +
"";
@ -278,7 +278,7 @@ public class ConfigFieldParserTest {
@Test
public void testDefine() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String test =
"#define ERROR_BUFFER_SIZE 120\n" +
"#define ERROR_BUFFER_SIZE_H 0x120\n" +
@ -296,15 +296,15 @@ public class ConfigFieldParserTest {
@Test
public void testFsioVisible() {
{
ReaderState state = new ReaderState();
ConfigField cf = ConfigField.parse(state, "int fsio_visible field");
ReaderStateImpl state = new ReaderStateImpl();
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int fsio_visible field");
assertEquals(cf.getType(), "int");
assertTrue(cf.isFsioVisible());
assertEquals("Name", cf.getName(), "field");
}
{
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String test = "struct pid_s\n" +
"\tint16_t fsio_visible offset;Linear addition to PID logic;\"\", 1, 0, -1000, 1000, 0\n" +
"\tint16_t periodMs;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
@ -355,7 +355,7 @@ public class ConfigFieldParserTest {
"";
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer();
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
state.readBufferedReader(test, consumer, javaFieldsConsumer);
assertEquals("\tpublic static final Field BYTE1 = Field.create(\"BYTE1\", 0, FieldType.INT8).setScale(1.0).setBaseOffset(0);\n" +
@ -505,7 +505,7 @@ public class ConfigFieldParserTest {
"end_struct\n" +
"";
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer();
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
state.readBufferedReader(test, consumer, javaFieldsConsumer);
assertEquals("\tpublic static final Field FIELD1 = Field.create(\"FIELD1\", 0, FieldType.INT).setScale(0.01).setBaseOffset(0);\n",
@ -534,7 +534,7 @@ public class ConfigFieldParserTest {
"end_struct\n" +
"";
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer();
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
state.readBufferedReader(test, consumer);
assertEquals("// start of struct_s\n" +
"struct struct_s {\n" +
@ -576,7 +576,7 @@ public class ConfigFieldParserTest {
"end_struct\n" +
"";
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer();
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
state.readBufferedReader(test, consumer);
assertEquals("// start of pid_s\n" +
"struct pid_s {\n" +
@ -602,46 +602,46 @@ public class ConfigFieldParserTest {
@Test
public void testParseLine() {
ReaderState state = new ReaderState();
assertNull(ConfigField.parse(state, "int"));
ReaderStateImpl state = new ReaderStateImpl();
assertNull(ConfigFieldImpl.parse(state, "int"));
{
ConfigField cf = ConfigField.parse(state, "int field");
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int field");
assertEquals(cf.getType(), "int");
assertEquals("Name", cf.getName(), "field");
}
{
ConfigField cf = ConfigField.parse(state, "int_4 fie4_ld");
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int_4 fie4_ld");
assertEquals(cf.getType(), "int_4");
assertEquals(cf.getName(), "fie4_ld");
}
{
ConfigField cf = ConfigField.parse(state, "int_8 fi_eld;comm_;ts,1,1");
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int_8 fi_eld;comm_;ts,1,1");
assertEquals(cf.getType(), "int_8");
assertEquals(cf.getName(), "fi_eld");
assertEquals("Comment", cf.getComment(), "comm_");
assertEquals(cf.getTsInfo(), "ts,1,1");
}
{
ConfigField cf = ConfigField.parse(state, "int[3 iterate] field");
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int[3 iterate] field");
assertEquals(cf.getType(), "int");
assertEquals(cf.getArraySizes().length, 1);
assertEquals(cf.getArraySizes()[0], 3);
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'");
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int16_t crankingRpm;This,. value controls what RPM values we consider 'cranking' (any RPM below 'crankingRpm')\\nAnything above 'crankingRpm' would be 'running'");
assertEquals(cf.getName(), "crankingRpm");
assertEquals(cf.getArraySizes().length, 0);
assertEquals(cf.getType(), "int16_t");
}
{
ConfigField cf = ConfigField.parse(state, "MAP_sensor_config_s map");
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "MAP_sensor_config_s map");
assertEquals(cf.getName(), "map");
assertEquals(cf.getArraySizes().length, 0);
assertEquals(cf.getType(), "MAP_sensor_config_s");
}
{
ConfigField cf = ConfigField.parse(state, "MAP_sensor_config_s map;@see hasMapSensor\\n@see isMapAveragingEnabled");
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "MAP_sensor_config_s map;@see hasMapSensor\\n@see isMapAveragingEnabled");
assertEquals(cf.getName(), "map");
assertEquals(cf.getArraySizes().length, 0);
assertEquals(cf.getType(), "MAP_sensor_config_s");
@ -651,7 +651,7 @@ public class ConfigFieldParserTest {
@Test
public void testParseSize() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
assertEquals(4, state.parseSize("4", ""));
assertEquals(12, state.parseSize("4*3", ""));
@ -673,7 +673,7 @@ public class ConfigFieldParserTest {
"end_struct\n" +
"pid_s pid;comment\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
@ -690,11 +690,11 @@ public class ConfigFieldParserTest {
@Test
public void testUnquote() {
assertEquals("x", ConfigField.unquote("\"x\""));
assertEquals("x", ConfigFieldImpl.unquote("\"x\""));
// leave broken opening-only quote!
assertEquals("\"x", ConfigField.unquote("\"x"));
assertEquals("\"x", ConfigFieldImpl.unquote("\"x"));
// this does not look great let's document this corner case for now
assertEquals("x\"\n" +
"\"y", ConfigField.unquote("\"x\"\n\"y\""));
"\"y", ConfigFieldImpl.unquote("\"x\"\n\"y\""));
}
}

View File

@ -1,7 +1,7 @@
package com.rusefi.test;
import com.rusefi.EnumsReader;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import org.junit.Test;
import java.io.BufferedReader;
@ -14,7 +14,7 @@ import static org.junit.Assert.assertNotNull;
public class EnumAsTsVariable {
@Test
public void testUseEnumAsVariable() throws IOException {
ReaderState readerState = new ReaderState();
ReaderStateImpl readerState = new ReaderStateImpl();
readerState.read(new BufferedReader(new StringReader("" +
"typedef enum {\n" +
"\tFO_1 = 0,\n" +

View File

@ -1,17 +1,15 @@
package com.rusefi.test;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.output.FragmentDialogConsumer;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
public class FragmentDialogConsumerTest {
@Test
public void generateFragmentDialog() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String outputChannels = "" +
"\n" +
"" +

View File

@ -1,7 +1,7 @@
package com.rusefi.test;
import com.rusefi.MaybeSemicolorWasMissedException;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.output.GetConfigValueConsumer;
import org.junit.Test;
@ -10,7 +10,7 @@ import static org.junit.Assert.assertEquals;
public class GetConfigValueConsumerTest {
@Test
public void testStructArrayAndCharArgument() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String test = "struct total\n" +
"custom lua_script_t 200 string, ASCII, @OFFSET@, 200\n" +
"lua_script_t luaScript;\n" +
@ -30,7 +30,7 @@ public class GetConfigValueConsumerTest {
@Test
public void generateEmbeddedStruct() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String test = "struct total\n" +
"struct_no_prefix thermistor_conf_s @brief Thermistor known values\n" +
"float tempC_1;these values are in Celcius;\"*C\", 1, 0, -40, 200, 1\n" +
@ -147,7 +147,7 @@ public class GetConfigValueConsumerTest {
"\tuint8_t unused37;;\"\",1, 0, 0, 0, 0\n" +
"bit enableFan1WithAc;Turn on this fan when AC is on.\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
state.getVariableRegistry().register("PACK_MULT_PERCENT", 100);
state.getVariableRegistry().register("GAUGE_NAME_FUEL_BASE", "hello");
@ -242,7 +242,7 @@ public class GetConfigValueConsumerTest {
String test = "struct total\n" +
"uint8_t hello;\"unit\", 1, 0, 0, 100, 0\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer();

View File

@ -1,6 +1,6 @@
package com.rusefi.test;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.output.JavaSensorsConsumer;
import org.junit.Test;
@ -9,7 +9,7 @@ import static org.junit.Assert.assertEquals;
public class JavaSensorsConsumerTest {
@Test
public void generateJavaSensors() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
state.getVariableRegistry().register("PACK_MULT_PERCENT", 100);
state.getVariableRegistry().register("GAUGE_NAME_RPM", "\"hello\"");
state.getVariableRegistry().register("GAUGE_NAME_GEAR_RATIO", "ra");
@ -43,7 +43,7 @@ public class JavaSensorsConsumerTest {
@Test
public void bitAtTheEndBug() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String outputChannels =
"struct_no_prefix output_channels_s\n" +
"bit sd_present\n" +

View File

@ -1,7 +1,7 @@
package com.rusefi.test;
import com.rusefi.BitState;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.newparse.outputs.OutputChannelWriter;
import com.rusefi.output.DataLogConsumer;
import com.rusefi.output.GaugeConsumer;
@ -18,7 +18,7 @@ import static org.junit.Assert.assertEquals;
public class OutputsTest {
@Test
public void generateSomething() throws IOException {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
state.getVariableRegistry().register("GAUGE_NAME_FUEL_WALL_CORRECTION", "wall");
String test = "struct total\n" +
"float afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
@ -63,13 +63,13 @@ public class OutputsTest {
* while we have {@link OutputChannelWriter} here we use the current 'legacy' implementation
*/
private static OutputsSectionConsumer runOriginalImplementation(String test) {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
return runOriginalImplementation(test, state);
}
@NotNull
private static OutputsSectionConsumer runOriginalImplementation(String test, ReaderState state) {
private static OutputsSectionConsumer runOriginalImplementation(String test, ReaderStateImpl state) {
OutputsSectionConsumer tsProjectConsumer = new OutputsSectionConsumer(null);
state.readBufferedReader(test, tsProjectConsumer);
return tsProjectConsumer;
@ -90,7 +90,7 @@ public class OutputsTest {
"\tuint8_t unused37;;\"\",1, 0, 0, 0, 0\n" +
"bit enableFan1WithAc;+Turn on this fan when AC is on.\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
state.getVariableRegistry().register("PACK_MULT_PERCENT", 100);
state.getVariableRegistry().register("GAUGE_NAME_FUEL_BASE", "hello");
@ -119,7 +119,7 @@ public class OutputsTest {
"\tuint16_t autoscale baseFuel;@@GAUGE_NAME_FUEL_BASE@@\\nThis is the raw value we take from the fuel map or base fuel algorithm, before the corrections;\"mg\",1, 0, 0, 0, 0\n" +
"\tuint16_t autoscale baseFuel2;\"line1\\nline2\";\"mg\",1, 0, 0, 0, 0\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
DataLogConsumer dataLogConsumer = new DataLogConsumer(null);
state.readBufferedReader(test, dataLogConsumer);
@ -139,7 +139,7 @@ public class OutputsTest {
"bit enableFan1WithAc;+Turn on this fan when AC is on.\n" +
"int hwChannel;\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
GetOutputValueConsumer outputValueConsumer = new GetOutputValueConsumer(null);
state.readBufferedReader(test, (outputValueConsumer));
@ -171,7 +171,7 @@ public class OutputsTest {
"\tpid_status_s idleStatus\n" +
"end_struct\n";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
DataLogConsumer dataLogConsumer = new DataLogConsumer(null);
GaugeConsumer gaugeConsumer = new GaugeConsumer(null);
state.readBufferedReader(test, dataLogConsumer, gaugeConsumer);
@ -192,7 +192,7 @@ public class OutputsTest {
@Test
public void testLongTooltipsIterate() {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
String test = "struct total\n" +
"\tint[3 iterate] triggerSimulatorPins;Each rusEFI piece can provide synthetic trigger signal for external ECU. Sometimes these wires are routed back into trigger inputs of the same rusEFI board.\\nSee also directSelfStimulation which is different.\n" +
"end_struct\n";

View File

@ -2,7 +2,7 @@ package com.rusefi.test;
import static org.junit.Assert.assertEquals;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.output.SdCardFieldsConsumer;
import com.rusefi.util.LazyFile;
@ -13,7 +13,7 @@ public class SdCardFieldsGeneratorTest {
public void outputs() {
Actor actor = new Actor() {
@Override
public void act(ReaderState state) {
public void act(ReaderStateImpl state) {
state.getVariableRegistry().register("PACK_MULT_PERCENT", 100);
state.getVariableRegistry().register("GAUGE_NAME_RPM", "\"hello\"");
state.getVariableRegistry().register("GAUGE_NAME_GEAR_RATIO", "ra");
@ -75,11 +75,11 @@ public class SdCardFieldsGeneratorTest {
}
interface Actor {
void act(ReaderState readerState);
void act(ReaderStateImpl readerState);
}
private static void processAndAssert(String input, String expectedOutput, Actor actor) {
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
actor.act(state);
SdCardFieldsConsumer consumer = new SdCardFieldsConsumer(LazyFile.TEST);

View File

@ -1,13 +1,11 @@
package com.rusefi.test;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.output.BaseCHeaderConsumer;
import com.rusefi.output.JavaFieldsConsumer;
import com.rusefi.output.TSProjectConsumer;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
public class TSProjectConsumerTest {
@ -39,7 +37,7 @@ public class TSProjectConsumerTest {
"end_struct\n" +
"";
ReaderState state = new ReaderState();
ReaderStateImpl state = new ReaderStateImpl();
TSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);

View File

@ -1,10 +1,10 @@
package com.rusefi.test;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.output.JavaFieldsConsumer;
public class TestJavaFieldsConsumer extends JavaFieldsConsumer {
public TestJavaFieldsConsumer(ReaderState state) {
public TestJavaFieldsConsumer(ReaderStateImpl state) {
super(state, 0);
}

View File

@ -1,12 +1,10 @@
package com.rusefi.test;
import com.rusefi.ReaderState;
import com.rusefi.ReaderStateImpl;
import com.rusefi.output.TSProjectConsumer;
import java.io.CharArrayWriter;
public class TestTSProjectConsumer extends TSProjectConsumer {
public TestTSProjectConsumer(String tsPath, ReaderState state) {
public TestTSProjectConsumer(String tsPath, ReaderStateImpl state) {
super(tsPath, state);
}