more refactoring

'null' in header bugfix
This commit is contained in:
rusefillc 2022-01-05 01:10:02 -05:00
parent 7d989642f4
commit a9b8fef332
14 changed files with 32 additions and 60 deletions

Binary file not shown.

View File

@ -16,8 +16,7 @@ import java.util.*;
* @see ConfigurationConsumer
*/
public class ConfigDefinition {
static final String SIGNATURE_HASH = "SIGNATURE_HASH";
public static String MESSAGE;
public static final String SIGNATURE_HASH = "SIGNATURE_HASH";
private static final String ROM_RAIDER_XML_TEMPLATE = "rusefi_template.xml";
private static final String KEY_DEFINITION = "-definition";
@ -68,7 +67,6 @@ public class ConfigDefinition {
String tsInputFileFolder = null;
String destCDefinesFileName = null;
String javaDestinationFileName = null;
String romRaiderDestination = null;
// we postpone reading so that in case of cache hit we do less work
List<String> prependFiles = new ArrayList<>();
@ -96,6 +94,7 @@ public class ConfigDefinition {
break;
case KEY_DEFINITION:
definitionInputFile = args[i + 1];
state.headerMessage = ToolUtil.getGeneratedAutomaticallyTag() + definitionInputFile + " " + new Date();
inputFiles.add(definitionInputFile);
break;
case KEY_TS_DESTINATION:
@ -105,7 +104,7 @@ public class ConfigDefinition {
tsOutputsDestination = args[i + 1];
break;
case KEY_C_DESTINATION:
destinations.add(new CHeaderConsumer(state.variableRegistry, args[i + 1], withC_Defines));
destinations.add(new CHeaderConsumer(state, args[i + 1], withC_Defines));
break;
case KEY_ZERO_INIT:
needZeroInit = Boolean.parseBoolean(args[i + 1]);
@ -117,7 +116,7 @@ public class ConfigDefinition {
destCDefinesFileName = args[i + 1];
break;
case KEY_JAVA_DESTINATION:
javaDestinationFileName = args[i + 1];
destinations.add(new FileJavaFieldsConsumer(state, args[i + 1]));
break;
case "-field_lookup_file":
destinations.add(new GetConfigValueConsumer(args[i + 1]));
@ -195,9 +194,6 @@ public class ConfigDefinition {
ExtraUtil.handleFiringOrder(firingEnumFileName, state.variableRegistry, parseState);
MESSAGE = ToolUtil.getGeneratedAutomaticallyTag() + definitionInputFile + " " + new Date();
SystemOut.println("Reading definition from " + definitionInputFile);
for (String prependFile : prependFiles)
state.variableRegistry.readPrependValues(prependFile);
@ -235,8 +231,6 @@ public class ConfigDefinition {
// writer.writeTunerstudio(parseState, tsPath + "/rusefi.input", tsPath + "/" + TSProjectConsumer.TS_FILE_OUTPUT_NAME);
}
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
if (tsOutputsDestination != null) {
destinations.add(new OutputsSectionConsumer(tsOutputsDestination + File.separator + "generated/output_channels.ini", state));
destinations.add(new DataLogConsumer(tsOutputsDestination + File.separator + "generated/data_logs.ini"));
@ -253,16 +247,14 @@ public class ConfigDefinition {
destinations.add(new SignatureConsumer(signatureDestination, tmpRegistry));
}
if (javaDestinationFileName != null) {
destinations.add(new FileJavaFieldsConsumer(state, javaDestinationFileName));
}
if (destinations.isEmpty())
throw new IllegalArgumentException("No destinations specified");
/*
* 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()));
state.readBufferedReader(definitionReader, destinations);
if (destCDefinesFileName != null) {

View File

@ -31,6 +31,7 @@ public class ReaderState {
public final Map<String, Integer> tsCustomSize = new HashMap<>();
public final Map<String, String> tsCustomLine = new HashMap<>();
public final Map<String, ConfigStructure> structures = new HashMap<>();
public String headerMessage;
public final EnumsReader enumsReader = new EnumsReader();
public final VariableRegistry variableRegistry = new VariableRegistry();
@ -277,4 +278,9 @@ public class ReaderState {
}
}
public String getHeader() {
if (headerMessage == null)
throw new NullPointerException("No header message yet");
return headerMessage;
}
}

View File

@ -1,14 +1,4 @@
package com.rusefi.output;
import java.io.IOException;
public abstract class AbstractConfigurationConsumer implements ConfigurationConsumer {
@Override
public void startFile() throws IOException {
}
@Override
public void endFile() throws IOException {
}
}

View File

@ -4,7 +4,7 @@ import com.rusefi.*;
import static com.rusefi.ToolUtil.EOL;
public abstract class BaseCHeaderConsumer extends AbstractConfigurationConsumer {
public class BaseCHeaderConsumer extends AbstractConfigurationConsumer {
private static final String BOOLEAN_TYPE = "bool";
private final StringBuilder content = new StringBuilder();

View File

@ -12,6 +12,8 @@ import static com.rusefi.ToolUtil.EOL;
* Configuration consumer which writes C header file
*/
public class CHeaderConsumer extends BaseCHeaderConsumer {
@org.jetbrains.annotations.NotNull
private final ReaderState state;
/**
* looks like sometimes we want to not include "define XXX value" into generated C headers
* TODO: document the use-case better
@ -20,12 +22,13 @@ public class CHeaderConsumer extends BaseCHeaderConsumer {
private final LazyFile cHeader;
private final VariableRegistry variableRegistry;
public CHeaderConsumer(VariableRegistry variableRegistry, String destCHeader, boolean withC_Defines) {
this.variableRegistry = variableRegistry;
public CHeaderConsumer(ReaderState state, String destCHeader, boolean withC_Defines) {
this.variableRegistry = state.variableRegistry;
this.state = state;
this.withC_Defines = withC_Defines;
SystemOut.println("Writing C header to " + destCHeader);
cHeader = new LazyFile(destCHeader);
cHeader.write("// this section " + ConfigDefinition.MESSAGE + EOL);
cHeader.write("// this section " + state.getHeader() + EOL);
cHeader.write("// by " + getClass() + EOL);
cHeader.write("// begin" + EOL);
cHeader.write("#pragma once" + EOL);
@ -38,7 +41,7 @@ public class CHeaderConsumer extends BaseCHeaderConsumer {
cHeader.write(variableRegistry.getDefinesSection());
cHeader.write(getContent().toString());
cHeader.write("// end" + EOL);
cHeader.write("// this section " + ConfigDefinition.MESSAGE + EOL);
cHeader.write("// this section " + state.getHeader() + EOL);
cHeader.close();
}
}

View File

@ -5,9 +5,13 @@ import com.rusefi.ReaderState;
import java.io.IOException;
public interface ConfigurationConsumer {
void startFile() throws IOException;
default void startFile() {
void endFile() throws IOException;
}
default void endFile() throws IOException {
}
void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException;
}

View File

@ -29,7 +29,7 @@ public class FileJavaFieldsConsumer extends JavaFieldsConsumer {
@Override
public void startFile() {
javaFields.write("package " + JAVA_PACKAGE + ";" + ToolUtil.EOL + ToolUtil.EOL);
javaFields.write("// this file " + ConfigDefinition.MESSAGE + ToolUtil.EOL + EOL);
javaFields.write("// this file " + state.getHeader() + ToolUtil.EOL + EOL);
javaFields.write("// by " + getClass() + EOL);
javaFields.write("import com.rusefi.config.*;" + EOL + EOL);
javaFields.write("public class " + className + " {" + ToolUtil.EOL);

View File

@ -47,10 +47,6 @@ public class GetConfigValueConsumer extends AbstractConfigurationConsumer {
}
}
@Override
public void startFile() {
}
@Override
public void endFile() throws IOException {
writeStringToFile(outputFileName, getContent());

View File

@ -51,7 +51,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
tsHeader.write(tsContent.getPrefix());
tsHeader.write("; " + CONFIG_DEFINITION_START + ToolUtil.EOL);
tsHeader.write("; this section " + ConfigDefinition.MESSAGE + ToolUtil.EOL + ToolUtil.EOL);
tsHeader.write("; this section " + state.getHeader() + ToolUtil.EOL + ToolUtil.EOL);
tsHeader.write("pageSize = " + totalTsSize + ToolUtil.EOL);
tsHeader.write("page = 1" + ToolUtil.EOL);
tsHeader.write(fieldsSection);
@ -138,10 +138,6 @@ public class TSProjectConsumer implements ConfigurationConsumer {
return tsPath + File.separator + TS_FILE_INPUT_NAME;
}
@Override
public void startFile() {
}
@Override
public void endFile() throws IOException {
writeTunerStudioFile(tsPath, tsWriter.toString());

View File

@ -30,6 +30,7 @@ public class BitParsingTest {
writeContent(fieldsSection, new TsFileContent("", ""), createOutput(sw));
}
};
state.headerMessage = "test";
state.readBufferedReader(inputString, Collections.singletonList(javaFieldsConsumer));
System.out.printf("start[" + sw + "]end");

View File

@ -71,11 +71,7 @@ public class ConfigFieldParserTest {
"end_struct\n";
ReaderState state = new ReaderState();
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer() {
@Override
public void endFile() {
}
};
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer();
state.readBufferedReader(test, Collections.singletonList(consumer));
}
@ -282,11 +278,7 @@ public class ConfigFieldParserTest {
"int[ERROR_BUFFER_SIZE iterate] field\n" +
"end_struct\n" +
"";
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer() {
@Override
public void endFile() {
}
};
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer();
new ReaderState().readBufferedReader(test, Collections.singletonList(consumer));
assertEquals("// start of pid_s\n" +
"struct pid_s {\n" +

View File

@ -47,11 +47,7 @@ public class TSProjectConsumerTest {
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer() {
@Override
public void endFile() {
}
};
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer();
state.readBufferedReader(test, Arrays.asList(javaFieldsConsumer, consumer, tsProjectConsumer));

View File

@ -8,10 +8,6 @@ public class TestJavaFieldsConsumer extends JavaFieldsConsumer {
super(state);
}
@Override
public void startFile() {
}
@Override
public void endFile() {
}