only:refactoring
This commit is contained in:
parent
942d25f176
commit
1efdf5bb5b
|
@ -1,6 +1,6 @@
|
||||||
package com.rusefi;
|
package com.rusefi;
|
||||||
|
|
||||||
import com.rusefi.newparse.ParseState;
|
import com.rusefi.newparse.DefinitionsState;
|
||||||
import com.rusefi.output.*;
|
import com.rusefi.output.*;
|
||||||
import com.rusefi.pinout.PinoutLogic;
|
import com.rusefi.pinout.PinoutLogic;
|
||||||
import com.rusefi.trigger.TriggerWheelTSLogic;
|
import com.rusefi.trigger.TriggerWheelTSLogic;
|
||||||
|
@ -63,10 +63,8 @@ public class ConfigDefinition {
|
||||||
SystemOut.println(ConfigDefinition.class + " Invoked with " + Arrays.toString(args));
|
SystemOut.println(ConfigDefinition.class + " Invoked with " + Arrays.toString(args));
|
||||||
|
|
||||||
String tsInputFileFolder = null;
|
String tsInputFileFolder = null;
|
||||||
String destCDefinesFileName = null;
|
|
||||||
// we postpone reading so that in case of cache hit we do less work
|
DefinitionsState parseState = state.getEnumsReader().parseState;
|
||||||
String firingEnumFileName = null;
|
|
||||||
String triggersInputFolder = null;
|
|
||||||
String signatureDestination = null;
|
String signatureDestination = null;
|
||||||
String signaturePrependFile = null;
|
String signaturePrependFile = null;
|
||||||
List<String> enumInputFiles = new ArrayList<>();
|
List<String> enumInputFiles = new ArrayList<>();
|
||||||
|
@ -96,7 +94,7 @@ public class ConfigDefinition {
|
||||||
state.setWithC_Defines(Boolean.parseBoolean(args[i + 1]));
|
state.setWithC_Defines(Boolean.parseBoolean(args[i + 1]));
|
||||||
break;
|
break;
|
||||||
case KEY_C_DEFINES:
|
case KEY_C_DEFINES:
|
||||||
destCDefinesFileName = args[i + 1];
|
state.destCDefinesFileName = args[i + 1];
|
||||||
break;
|
break;
|
||||||
case KEY_JAVA_DESTINATION:
|
case KEY_JAVA_DESTINATION:
|
||||||
state.addJavaDestination(args[i + 1]);
|
state.addJavaDestination(args[i + 1]);
|
||||||
|
@ -118,12 +116,16 @@ public class ConfigDefinition {
|
||||||
throw new IllegalStateException("While processing " + fileName, e);
|
throw new IllegalStateException("While processing " + fileName, e);
|
||||||
}
|
}
|
||||||
state.addInputFile(fileName);
|
state.addInputFile(fileName);
|
||||||
case KEY_FIRING:
|
case KEY_FIRING: {
|
||||||
firingEnumFileName = args[i + 1];
|
String firingEnumFileName = args[i + 1];
|
||||||
|
ExtraUtil.handleFiringOrder(firingEnumFileName, state.getVariableRegistry(), parseState);
|
||||||
state.addInputFile(firingEnumFileName);
|
state.addInputFile(firingEnumFileName);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "-triggerInputFolder":
|
case "-triggerInputFolder": {
|
||||||
triggersInputFolder = args[i + 1];
|
String triggersInputFolder = args[i + 1];
|
||||||
|
new TriggerWheelTSLogic().execute(triggersInputFolder, state.getVariableRegistry());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case KEY_PREPEND:
|
case KEY_PREPEND:
|
||||||
state.addPrepend(args[i + 1].trim());
|
state.addPrepend(args[i + 1].trim());
|
||||||
|
@ -164,47 +166,15 @@ public class ConfigDefinition {
|
||||||
SystemOut.println(state.getEnumsReader().getEnums().size() + " total enumsReader");
|
SystemOut.println(state.getEnumsReader().getEnums().size() + " total enumsReader");
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseState parseState = new ParseState(state.getEnumsReader());
|
|
||||||
// Add the variable for the config signature
|
// Add the variable for the config signature
|
||||||
FirmwareVersion uniqueId = new FirmwareVersion(IoUtil2.getCrc32(state.getInputFiles()));
|
FirmwareVersion uniqueId = new FirmwareVersion(IoUtil2.getCrc32(state.getInputFiles()));
|
||||||
SignatureConsumer.storeUniqueBuildId(state, parseState, tsInputFileFolder, uniqueId);
|
SignatureConsumer.storeUniqueBuildId(state, parseState, tsInputFileFolder, uniqueId);
|
||||||
|
|
||||||
ExtraUtil.handleFiringOrder(firingEnumFileName, state.getVariableRegistry(), parseState);
|
|
||||||
|
|
||||||
new TriggerWheelTSLogic().execute(triggersInputFolder, state.getVariableRegistry());
|
|
||||||
|
|
||||||
if (pinoutLogic != null) {
|
if (pinoutLogic != null) {
|
||||||
pinoutLogic.registerBoardSpecificPinNames(state.getVariableRegistry(), parseState, state.getEnumsReader());
|
pinoutLogic.registerBoardSpecificPinNames(state.getVariableRegistry(), parseState, state.getEnumsReader());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the input files
|
|
||||||
{
|
|
||||||
// Load prepend files
|
|
||||||
{
|
|
||||||
// Ignore duplicates of definitions made during prepend phase
|
|
||||||
// parseState.setDefinitionPolicy(Definition.OverwritePolicy.IgnoreNew);
|
|
||||||
|
|
||||||
for (String prependFile : state.getPrependFiles()) {
|
|
||||||
// RusefiParseErrorStrategy.parseDefinitionFile(parseState.getListener(), prependFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now load the main config file
|
|
||||||
{
|
|
||||||
// don't allow duplicates in the main file
|
|
||||||
// parseState.setDefinitionPolicy(Definition.OverwritePolicy.NotAllowed);
|
|
||||||
// RusefiParseErrorStrategy.parseDefinitionFile(parseState.getListener(), state.definitionInputFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write C structs
|
|
||||||
// CStructWriter cStructs = new CStructWriter();
|
|
||||||
// cStructs.writeCStructs(parseState, destCHeaderFileName + ".test");
|
|
||||||
|
|
||||||
// Write tunerstudio layout
|
|
||||||
// TsWriter writer = new TsWriter();
|
|
||||||
// writer.writeTunerstudio(parseState, tsInputFileFolder + "/rusefi.input", tsInputFileFolder + "/" + state.tsFileOutputName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tsInputFileFolder != null) {
|
if (tsInputFileFolder != null) {
|
||||||
state.addDestination(new TSProjectConsumer(tsInputFileFolder, state));
|
state.addDestination(new TSProjectConsumer(tsInputFileFolder, state));
|
||||||
|
|
||||||
|
@ -215,13 +185,6 @@ public class ConfigDefinition {
|
||||||
state.addDestination(new SignatureConsumer(signatureDestination, tmpRegistry));
|
state.addDestination(new SignatureConsumer(signatureDestination, tmpRegistry));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.isDestinationsEmpty())
|
|
||||||
throw new IllegalArgumentException("No destinations specified");
|
|
||||||
|
|
||||||
state.doJob();
|
state.doJob();
|
||||||
|
|
||||||
if (destCDefinesFileName != null) {
|
|
||||||
ExtraUtil.writeDefinesToFile(state.getVariableRegistry(), destCDefinesFileName, state.getDefinitionInputFile());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class ReaderStateImpl implements ReaderState {
|
||||||
// well, technically those should be a builder for state, not this state class itself
|
// well, technically those should be a builder for state, not this state class itself
|
||||||
private String tsFileOutputName = "rusefi.ini";
|
private String tsFileOutputName = "rusefi.ini";
|
||||||
private String definitionInputFile = null;
|
private String definitionInputFile = null;
|
||||||
|
String destCDefinesFileName = null;
|
||||||
private boolean withC_Defines = true;
|
private boolean withC_Defines = true;
|
||||||
private final List<String> prependFiles = new ArrayList<>();
|
private final List<String> prependFiles = new ArrayList<>();
|
||||||
private final List<ConfigurationConsumer> destinations = new ArrayList<>();
|
private final List<ConfigurationConsumer> destinations = new ArrayList<>();
|
||||||
|
@ -93,6 +94,9 @@ public class ReaderStateImpl implements ReaderState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doJob() throws IOException {
|
public void doJob() throws IOException {
|
||||||
|
if (isDestinationsEmpty())
|
||||||
|
throw new IllegalArgumentException("No destinations specified");
|
||||||
|
|
||||||
for (String prependFile : prependFiles)
|
for (String prependFile : prependFiles)
|
||||||
variableRegistry.readPrependValues(prependFile);
|
variableRegistry.readPrependValues(prependFile);
|
||||||
|
|
||||||
|
@ -103,6 +107,10 @@ public class ReaderStateImpl implements ReaderState {
|
||||||
SystemOut.println("Reading definition from " + definitionInputFile);
|
SystemOut.println("Reading definition from " + definitionInputFile);
|
||||||
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
|
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
|
||||||
readBufferedReader(definitionReader, destinations);
|
readBufferedReader(definitionReader, destinations);
|
||||||
|
|
||||||
|
if (destCDefinesFileName != null) {
|
||||||
|
ExtraUtil.writeDefinesToFile(getVariableRegistry(), destCDefinesFileName, definitionInputFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(Reader reader) throws IOException {
|
public void read(Reader reader) throws IOException {
|
||||||
|
@ -417,11 +425,6 @@ public class ReaderStateImpl implements ReaderState {
|
||||||
this.tsFileOutputName = tsFileOutputName;
|
this.tsFileOutputName = tsFileOutputName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDefinitionInputFile() {
|
|
||||||
return definitionInputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getPrependFiles() {
|
public List<String> getPrependFiles() {
|
||||||
return prependFiles;
|
return prependFiles;
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package com.rusefi.pinout;
|
package com.rusefi.pinout;
|
||||||
|
|
||||||
import com.rusefi.EnumsReader;
|
|
||||||
import com.rusefi.ReaderState;
|
|
||||||
import com.rusefi.ReaderStateImpl;
|
import com.rusefi.ReaderStateImpl;
|
||||||
import com.rusefi.VariableRegistry;
|
|
||||||
import com.rusefi.enum_reader.Value;
|
import com.rusefi.enum_reader.Value;
|
||||||
import com.rusefi.newparse.ParseState;
|
import com.rusefi.newparse.DefinitionsState;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -105,7 +102,7 @@ public class PinoutLogicIntegratedTest {
|
||||||
"E11 = 0x0B,\n" +
|
"E11 = 0x0B,\n" +
|
||||||
"};"));
|
"};"));
|
||||||
|
|
||||||
ParseState definitionState = new ParseState(state.getEnumsReader());
|
DefinitionsState definitionState = state.getEnumsReader().parseState;
|
||||||
|
|
||||||
PinoutLogic logic = new PinoutLogic(testBoard);
|
PinoutLogic logic = new PinoutLogic(testBoard);
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,6 @@ public interface ReaderState {
|
||||||
|
|
||||||
void setTsFileOutputName(String tsFileOutputName);
|
void setTsFileOutputName(String tsFileOutputName);
|
||||||
|
|
||||||
String getDefinitionInputFile();
|
|
||||||
|
|
||||||
List<String> getPrependFiles();
|
List<String> getPrependFiles();
|
||||||
|
|
||||||
boolean isDestinationsEmpty();
|
boolean isDestinationsEmpty();
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.rusefi;
|
||||||
import com.devexperts.logging.Logging;
|
import com.devexperts.logging.Logging;
|
||||||
import com.rusefi.enum_reader.Value;
|
import com.rusefi.enum_reader.Value;
|
||||||
|
|
||||||
|
import com.rusefi.newparse.DefinitionsState;
|
||||||
|
import com.rusefi.newparse.DefinitionsStateImpl;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -28,6 +30,8 @@ public class EnumsReader {
|
||||||
|
|
||||||
protected final Map<String, EnumState> enums = new TreeMap<>();
|
protected final Map<String, EnumState> enums = new TreeMap<>();
|
||||||
|
|
||||||
|
public DefinitionsState parseState = new DefinitionsStateImpl(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* core implementation sorts by name, we need special considerations to sort by value
|
* core implementation sorts by name, we need special considerations to sort by value
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,12 +8,12 @@ import com.rusefi.newparse.parsing.Definition;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ParseState implements DefinitionsState {
|
public class DefinitionsStateImpl implements DefinitionsState {
|
||||||
private final Map<String, Definition> definitions = new HashMap<>();
|
private final Map<String, Definition> definitions = new HashMap<>();
|
||||||
|
|
||||||
private final Definition.OverwritePolicy definitionOverwritePolicy = Definition.OverwritePolicy.NotAllowed;
|
private final Definition.OverwritePolicy definitionOverwritePolicy = Definition.OverwritePolicy.NotAllowed;
|
||||||
|
|
||||||
public ParseState(EnumsReader enumsReader) {
|
public DefinitionsStateImpl(EnumsReader enumsReader) {
|
||||||
|
|
||||||
for (Map.Entry<String, EnumsReader.EnumState> enumType : enumsReader.getEnums().entrySet()) {
|
for (Map.Entry<String, EnumsReader.EnumState> enumType : enumsReader.getEnums().entrySet()) {
|
||||||
String name = enumType.getKey();
|
String name = enumType.getKey();
|
|
@ -16,6 +16,6 @@ public class Definition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue