only:Split ConfigGenerator around trigger_defines.txt #5051
This commit is contained in:
parent
de44c57bda
commit
346a704935
|
@ -33,12 +33,6 @@ public class ConfigDefinition {
|
|||
private static final String KEY_ZERO_INIT = "-initialize_to_zero";
|
||||
private static final String KEY_BOARD_NAME = "-board";
|
||||
public static final String CONFIG_PATH = "java_tools/configuration_definition/src/main/resources/config_definition.options";
|
||||
/**
|
||||
* This flag controls if we assign default zero value (useful while generating structures used for class inheritance)
|
||||
* versus not assigning default zero value like we need for non-class headers
|
||||
* This could be related to configuration header use-case versus "live data" (not very alive idea) use-case
|
||||
*/
|
||||
public static boolean needZeroInit = true;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
@ -93,7 +87,7 @@ public class ConfigDefinition {
|
|||
state.addCHeaderDestination(args[i + 1]);
|
||||
break;
|
||||
case KEY_ZERO_INIT:
|
||||
needZeroInit = Boolean.parseBoolean(args[i + 1]);
|
||||
BaseCHeaderConsumer.needZeroInit = Boolean.parseBoolean(args[i + 1]);
|
||||
break;
|
||||
case KEY_WITH_C_DEFINES:
|
||||
state.setWithC_Defines(Boolean.parseBoolean(args[i + 1]));
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.rusefi;
|
|||
|
||||
import com.rusefi.newparse.DefinitionsState;
|
||||
import com.rusefi.newparse.parsing.Definition;
|
||||
import com.rusefi.util.LazyFile;
|
||||
import com.rusefi.util.SystemOut;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -15,14 +14,4 @@ public class ExtraUtil {
|
|||
parseState.addDefinition(variableRegistry, "FIRINGORDER", result, Definition.OverwritePolicy.NotAllowed);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeDefinesToFile(VariableRegistry variableRegistry, String fileName, String headerComment) throws IOException {
|
||||
|
||||
SystemOut.println("Writing to " + fileName);
|
||||
LazyFile cHeader = new LazyFile(fileName);
|
||||
|
||||
cHeader.write("//\n// " + ToolUtil.getGeneratedAutomaticallyTag() + headerComment + "\n//\n\n");
|
||||
cHeader.write(variableRegistry.getDefinesSection());
|
||||
cHeader.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package com.rusefi;
|
||||
|
||||
public class MaybeSemicolorWasMissedException extends IllegalArgumentException {
|
||||
public MaybeSemicolorWasMissedException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
|
@ -107,7 +107,7 @@ public class ReaderStateImpl implements ReaderState {
|
|||
readBufferedReader(definitionReader, destinations);
|
||||
|
||||
if (destCDefinesFileName != null) {
|
||||
ExtraUtil.writeDefinesToFile(getVariableRegistry(), destCDefinesFileName, definitionInputFile);
|
||||
CHeaderConsumer.writeDefinesToFile(getVariableRegistry(), destCDefinesFileName, definitionInputFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class ConfigStructureImpl implements ConfigStructure {
|
|||
return name;
|
||||
}
|
||||
|
||||
public void addAlignmentFill(ReaderStateImpl state, int alignment) {
|
||||
public void addAlignmentFill(ReaderState state, int alignment) {
|
||||
if (alignment == 0)
|
||||
return;
|
||||
/**
|
||||
|
|
|
@ -32,6 +32,6 @@ public class SignatureConsumer implements ConfigurationConsumer {
|
|||
|
||||
@Override
|
||||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
ExtraUtil.writeDefinesToFile(registry, destHeader, "by SignatureConsumer");
|
||||
CHeaderConsumer.writeDefinesToFile(registry, destHeader, "by SignatureConsumer");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import com.rusefi.MaybeSemicolorWasMissedException;
|
||||
import com.rusefi.MaybeSemicolonWasMissedException;
|
||||
import com.rusefi.ReaderStateImpl;
|
||||
import com.rusefi.output.GetConfigValueConsumer;
|
||||
import org.junit.Test;
|
||||
|
@ -257,7 +257,7 @@ public class GetConfigValueConsumerTest {
|
|||
"\n", getConfigValueConsumer.getMdContent());
|
||||
}
|
||||
|
||||
@Test(expected = MaybeSemicolorWasMissedException.class)
|
||||
@Test(expected = MaybeSemicolonWasMissedException.class)
|
||||
public void generateSuspiciousTsInfo() {
|
||||
String test = "struct total\n" +
|
||||
"uint8_t hello;\"unit\", 1, 0, 0, 100, 0\n" +
|
||||
|
|
|
@ -4,7 +4,6 @@ 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;
|
||||
|
@ -13,7 +12,6 @@ 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 com.rusefi.parse.TypesHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -48,7 +46,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
|
||||
private final String tsInfo;
|
||||
private final boolean isIterate;
|
||||
private final ReaderStateImpl state;
|
||||
private final ReaderState state;
|
||||
private final boolean hasAutoscale;
|
||||
private final String trueName;
|
||||
private final String falseName;
|
||||
|
@ -59,7 +57,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
/**
|
||||
* todo: one day someone should convert this into a builder
|
||||
*/
|
||||
public ConfigFieldImpl(ReaderStateImpl state,
|
||||
public ConfigFieldImpl(ReaderState state,
|
||||
String name,
|
||||
String comment,
|
||||
String arraySizeAsText,
|
||||
|
@ -160,7 +158,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
/**
|
||||
* @see ConfigFieldParserTest#testParseLine()
|
||||
*/
|
||||
public static ConfigFieldImpl parse(ReaderStateImpl state, String line) {
|
||||
public static ConfigFieldImpl parse(ReaderState state, String line) {
|
||||
Matcher matcher = FIELD.matcher(line);
|
||||
if (!matcher.matches())
|
||||
return null;
|
||||
|
@ -219,7 +217,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
if (comment.isEmpty())
|
||||
return;
|
||||
if (comment.charAt(0) == '"' && !EnumIniField.isQuoted(comment))
|
||||
throw new MaybeSemicolorWasMissedException("This comment looks like semicolon was missed: " + comment);
|
||||
throw new MaybeSemicolonWasMissedException("This comment looks like semicolon was missed: " + comment);
|
||||
}
|
||||
|
||||
public static boolean isPreprocessorDirective(String line) {
|
||||
|
@ -445,7 +443,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
*/
|
||||
public String getCommentOrName() {
|
||||
if (comment == null || comment.trim().isEmpty())
|
||||
return quote(name);
|
||||
return VariableRegistry.quote(name);
|
||||
return comment;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.rusefi;
|
||||
|
||||
public class MaybeSemicolonWasMissedException extends IllegalArgumentException {
|
||||
public MaybeSemicolonWasMissedException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,14 @@ import static com.rusefi.ToolUtil.EOL;
|
|||
|
||||
public class BaseCHeaderConsumer implements ConfigurationConsumer {
|
||||
private static final String BOOLEAN_TYPE = "bool";
|
||||
/**
|
||||
* This flag controls if we assign default zero value (useful while generating structures used for class inheritance)
|
||||
* versus not assigning default zero value like we need for non-class headers
|
||||
* This could be related to configuration header use-case versus "live data" (not very alive idea) use-case
|
||||
*
|
||||
* TODO: STATIC MUTABLE?! Not good code at all.
|
||||
*/
|
||||
public static boolean needZeroInit = true;
|
||||
private final StringBuilder content = new StringBuilder();
|
||||
|
||||
private static String getHeaderText(FieldIteratorWithOffset iterator) {
|
||||
|
@ -29,7 +37,7 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer {
|
|||
if (!configField.isArray()) {
|
||||
// not an array
|
||||
cEntry += "\t" + typeName + " " + configField.getName();
|
||||
if (ConfigDefinition.needZeroInit && TypesHelper.isPrimitive(configField.getType())) {
|
||||
if (needZeroInit && TypesHelper.isPrimitive(configField.getType())) {
|
||||
// we need this cast in case of enums
|
||||
cEntry += " = (" + configField.getType() + ")0";
|
||||
}
|
|
@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class CHeaderConsumer extends BaseCHeaderConsumer {
|
||||
@NotNull
|
||||
private final ReaderStateImpl state;
|
||||
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
|
||||
|
@ -24,7 +24,7 @@ public class CHeaderConsumer extends BaseCHeaderConsumer {
|
|||
private final LazyFile cHeader;
|
||||
private final VariableRegistry variableRegistry;
|
||||
|
||||
public CHeaderConsumer(ReaderStateImpl state, String destCHeader, boolean withC_Defines) {
|
||||
public CHeaderConsumer(ReaderState state, String destCHeader, boolean withC_Defines) {
|
||||
this.variableRegistry = state.getVariableRegistry();
|
||||
this.state = state;
|
||||
this.withC_Defines = withC_Defines;
|
||||
|
@ -32,6 +32,16 @@ public class CHeaderConsumer extends BaseCHeaderConsumer {
|
|||
cHeader = new LazyFile(destCHeader);
|
||||
}
|
||||
|
||||
public static void writeDefinesToFile(VariableRegistry variableRegistry, String fileName, String headerComment) throws IOException {
|
||||
|
||||
SystemOut.println("Writing to " + fileName);
|
||||
LazyFile cHeader = new LazyFile(fileName);
|
||||
|
||||
cHeader.write("//\n// " + ToolUtil.getGeneratedAutomaticallyTag() + headerComment + "\n//\n\n");
|
||||
cHeader.write(variableRegistry.getDefinesSection());
|
||||
cHeader.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startFile() {
|
||||
cHeader.write("// this section " + state.getHeader() + EOL);
|
|
@ -1,7 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
Loading…
Reference in New Issue