only:refactoring
This commit is contained in:
parent
942d25f176
commit
1efdf5bb5b
|
@ -1,6 +1,6 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.newparse.ParseState;
|
||||
import com.rusefi.newparse.DefinitionsState;
|
||||
import com.rusefi.output.*;
|
||||
import com.rusefi.pinout.PinoutLogic;
|
||||
import com.rusefi.trigger.TriggerWheelTSLogic;
|
||||
|
@ -63,10 +63,8 @@ public class ConfigDefinition {
|
|||
SystemOut.println(ConfigDefinition.class + " Invoked with " + Arrays.toString(args));
|
||||
|
||||
String tsInputFileFolder = null;
|
||||
String destCDefinesFileName = null;
|
||||
// we postpone reading so that in case of cache hit we do less work
|
||||
String firingEnumFileName = null;
|
||||
String triggersInputFolder = null;
|
||||
|
||||
DefinitionsState parseState = state.getEnumsReader().parseState;
|
||||
String signatureDestination = null;
|
||||
String signaturePrependFile = null;
|
||||
List<String> enumInputFiles = new ArrayList<>();
|
||||
|
@ -96,7 +94,7 @@ public class ConfigDefinition {
|
|||
state.setWithC_Defines(Boolean.parseBoolean(args[i + 1]));
|
||||
break;
|
||||
case KEY_C_DEFINES:
|
||||
destCDefinesFileName = args[i + 1];
|
||||
state.destCDefinesFileName = args[i + 1];
|
||||
break;
|
||||
case KEY_JAVA_DESTINATION:
|
||||
state.addJavaDestination(args[i + 1]);
|
||||
|
@ -118,12 +116,16 @@ public class ConfigDefinition {
|
|||
throw new IllegalStateException("While processing " + fileName, e);
|
||||
}
|
||||
state.addInputFile(fileName);
|
||||
case KEY_FIRING:
|
||||
firingEnumFileName = args[i + 1];
|
||||
case KEY_FIRING: {
|
||||
String firingEnumFileName = args[i + 1];
|
||||
ExtraUtil.handleFiringOrder(firingEnumFileName, state.getVariableRegistry(), parseState);
|
||||
state.addInputFile(firingEnumFileName);
|
||||
}
|
||||
break;
|
||||
case "-triggerInputFolder":
|
||||
triggersInputFolder = args[i + 1];
|
||||
case "-triggerInputFolder": {
|
||||
String triggersInputFolder = args[i + 1];
|
||||
new TriggerWheelTSLogic().execute(triggersInputFolder, state.getVariableRegistry());
|
||||
}
|
||||
break;
|
||||
case KEY_PREPEND:
|
||||
state.addPrepend(args[i + 1].trim());
|
||||
|
@ -164,47 +166,15 @@ public class ConfigDefinition {
|
|||
SystemOut.println(state.getEnumsReader().getEnums().size() + " total enumsReader");
|
||||
}
|
||||
|
||||
ParseState parseState = new ParseState(state.getEnumsReader());
|
||||
// Add the variable for the config signature
|
||||
FirmwareVersion uniqueId = new FirmwareVersion(IoUtil2.getCrc32(state.getInputFiles()));
|
||||
SignatureConsumer.storeUniqueBuildId(state, parseState, tsInputFileFolder, uniqueId);
|
||||
|
||||
ExtraUtil.handleFiringOrder(firingEnumFileName, state.getVariableRegistry(), parseState);
|
||||
|
||||
new TriggerWheelTSLogic().execute(triggersInputFolder, state.getVariableRegistry());
|
||||
|
||||
if (pinoutLogic != null) {
|
||||
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) {
|
||||
state.addDestination(new TSProjectConsumer(tsInputFileFolder, state));
|
||||
|
||||
|
@ -215,13 +185,6 @@ public class ConfigDefinition {
|
|||
state.addDestination(new SignatureConsumer(signatureDestination, tmpRegistry));
|
||||
}
|
||||
|
||||
if (state.isDestinationsEmpty())
|
||||
throw new IllegalArgumentException("No destinations specified");
|
||||
|
||||
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
|
||||
private String tsFileOutputName = "rusefi.ini";
|
||||
private String definitionInputFile = null;
|
||||
String destCDefinesFileName = null;
|
||||
private boolean withC_Defines = true;
|
||||
private final List<String> prependFiles = new ArrayList<>();
|
||||
private final List<ConfigurationConsumer> destinations = new ArrayList<>();
|
||||
|
@ -93,6 +94,9 @@ public class ReaderStateImpl implements ReaderState {
|
|||
|
||||
@Override
|
||||
public void doJob() throws IOException {
|
||||
if (isDestinationsEmpty())
|
||||
throw new IllegalArgumentException("No destinations specified");
|
||||
|
||||
for (String prependFile : prependFiles)
|
||||
variableRegistry.readPrependValues(prependFile);
|
||||
|
||||
|
@ -103,6 +107,10 @@ public class ReaderStateImpl implements ReaderState {
|
|||
SystemOut.println("Reading definition from " + definitionInputFile);
|
||||
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
|
||||
readBufferedReader(definitionReader, destinations);
|
||||
|
||||
if (destCDefinesFileName != null) {
|
||||
ExtraUtil.writeDefinesToFile(getVariableRegistry(), destCDefinesFileName, definitionInputFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void read(Reader reader) throws IOException {
|
||||
|
@ -417,11 +425,6 @@ public class ReaderStateImpl implements ReaderState {
|
|||
this.tsFileOutputName = tsFileOutputName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefinitionInputFile() {
|
||||
return definitionInputFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPrependFiles() {
|
||||
return prependFiles;
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package com.rusefi.pinout;
|
||||
|
||||
import com.rusefi.EnumsReader;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.ReaderStateImpl;
|
||||
import com.rusefi.VariableRegistry;
|
||||
import com.rusefi.enum_reader.Value;
|
||||
import com.rusefi.newparse.ParseState;
|
||||
import com.rusefi.newparse.DefinitionsState;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -105,7 +102,7 @@ public class PinoutLogicIntegratedTest {
|
|||
"E11 = 0x0B,\n" +
|
||||
"};"));
|
||||
|
||||
ParseState definitionState = new ParseState(state.getEnumsReader());
|
||||
DefinitionsState definitionState = state.getEnumsReader().parseState;
|
||||
|
||||
PinoutLogic logic = new PinoutLogic(testBoard);
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@ public interface ReaderState {
|
|||
|
||||
void setTsFileOutputName(String tsFileOutputName);
|
||||
|
||||
String getDefinitionInputFile();
|
||||
|
||||
List<String> getPrependFiles();
|
||||
|
||||
boolean isDestinationsEmpty();
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.rusefi;
|
|||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.enum_reader.Value;
|
||||
|
||||
import com.rusefi.newparse.DefinitionsState;
|
||||
import com.rusefi.newparse.DefinitionsStateImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -28,6 +30,8 @@ public class EnumsReader {
|
|||
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -8,12 +8,12 @@ import com.rusefi.newparse.parsing.Definition;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ParseState implements DefinitionsState {
|
||||
public class DefinitionsStateImpl implements DefinitionsState {
|
||||
private final Map<String, Definition> definitions = new HashMap<>();
|
||||
|
||||
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()) {
|
||||
String name = enumType.getKey();
|
|
@ -16,6 +16,6 @@ public class Definition {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.value.toString();
|
||||
return value.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue