refactoring

This commit is contained in:
rusefillc 2023-01-06 10:54:29 -05:00
parent ac1da4856f
commit 160e12a8bd
14 changed files with 48 additions and 33 deletions

View File

@ -63,15 +63,15 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer {
@Override
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) {
if (structure.comment != null) {
content.append("/**" + EOL + packComment(structure.comment, "") + EOL + "*/" + EOL);
if (structure.getComment() != null) {
content.append("/**" + EOL + packComment(structure.getComment(), "") + EOL + "*/" + EOL);
}
content.append("// start of " + structure.name + EOL);
content.append("struct " + structure.name + " {" + EOL);
content.append("// start of " + structure.getName() + EOL);
content.append("struct " + structure.getName() + " {" + EOL);
FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(structure.cFields);
for (int i = 0; i < structure.cFields.size(); i++) {
FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(structure.getcFields());
for (int i = 0; i < structure.getcFields().size(); i++) {
iterator.start(i);
content.append(getHeaderText(iterator));
@ -80,7 +80,7 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer {
}
content.append("};" + EOL);
content.append("static_assert(sizeof(" + structure.name + ") == " + iterator.currentOffset + ");\n");
content.append("static_assert(sizeof(" + structure.getName() + ") == " + iterator.currentOffset + ");\n");
content.append(EOL);
}

View File

@ -23,19 +23,15 @@ public class ConfigStructure {
public static final String UNUSED_ANYTHING_PREFIX = "unused";
public static final String UNUSED_BIT_PREFIX = "unusedBit_";
public final String name;
public final String comment;
public final boolean withPrefix;
/**
* We have two different collections because if 'array iterate' feature which is handled differently
* in C and TS
*/
public final List<ConfigField> cFields = new ArrayList<>();
public final List<ConfigField> tsFields = new ArrayList<>();
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 int totalSize;
public final BitState readingBitState = new BitState();
private final BitState readingBitState = new BitState();
private ConfigField cPrevField = ConfigField.VOID;
private final Set<String> names = new HashSet<>();
@ -129,4 +125,24 @@ public class ConfigStructure {
public int getTotalSize() {
return totalSize;
}
public List<ConfigField> getTsFields() {
return tsFields;
}
/**
* We have two different collections because if 'array iterate' feature which is handled differently
* in C and TS
*/
public List<ConfigField> getcFields() {
return cFields;
}
public boolean isWithPrefix() {
return withPrefix;
}
public String getComment() {
return comment;
}
}

View File

@ -34,7 +34,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
@Override
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
if (readerState.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.tsFields, "",
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.getTsFields(), "",
(configField, prefix, prefix2) -> handle(prefix, prefix2));
iterator.loop();
String content = iterator.getContent();

View File

@ -2,14 +2,13 @@ package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.IReaderState;
import com.rusefi.ReaderState;
import java.util.List;
public abstract class FieldsStrategy {
public int run(IReaderState state, ConfigStructure structure, int sensorTsPosition) {
if (state.isStackEmpty()) {
return writeFields(structure.tsFields, "", sensorTsPosition);
return writeFields(structure.getTsFields(), "", sensorTsPosition);
}
return sensorTsPosition;
}

View File

@ -43,8 +43,8 @@ public class FragmentDialogConsumer implements ConfigurationConsumer {
ConfigStructure cs = configField.getStructureType();
if (cs != null) {
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
return writeFields(cs.tsFields, prefix + extraPrefix, tsPosition);
String extraPrefix = cs.isWithPrefix() ? configField.getName() + "_" : "";
return writeFields(cs.getTsFields(), prefix + extraPrefix, tsPosition);
}
if (configField.getName().startsWith(ConfigStructure.UNUSED_BIT_PREFIX))

View File

@ -20,7 +20,7 @@ public class GaugeConsumer implements ConfigurationConsumer {
@Override
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
if (readerState.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.tsFields, "",
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.getTsFields(), "",
(state, configField, prefix) -> handle(configField, prefix));
iterator.loop();
String content = iterator.getContent();

View File

@ -62,7 +62,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
@Override
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
if (state.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "",
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.getTsFields(), "",
this::processConfig, ".");
iterator.loop();
}

View File

@ -35,7 +35,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
@Override
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
if (state.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "",
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.getTsFields(), "",
this::processOutput, ".");
iterator.loop();
}

View File

@ -66,8 +66,8 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
}
ConfigStructure cs = configField.getStructureType();
if (cs != null) {
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
return writeFields(cs.tsFields, prefix + extraPrefix, tsPosition);
String extraPrefix = cs.isWithPrefix() ? configField.getName() + "_" : "";
return writeFields(cs.getTsFields(), prefix + extraPrefix, tsPosition);
}
String nameWithPrefix = prefix + configField.getName();

View File

@ -39,7 +39,7 @@ class PerFieldWithStructuresIterator extends FieldIterator {
} else {
// java side of things does not care for 'cs.withPrefix'
String extraPrefix = prefix + cf.getName() + prefixSeparator;
PerFieldWithStructuresIterator fieldIterator = new PerFieldWithStructuresIterator(state, cs.tsFields, extraPrefix, strategy, prefixSeparator);
PerFieldWithStructuresIterator fieldIterator = new PerFieldWithStructuresIterator(state, cs.getTsFields(), extraPrefix, strategy, prefixSeparator);
fieldIterator.loop();
content = fieldIterator.sb.toString();
}

View File

@ -14,7 +14,7 @@ public class SdCardFieldsContent {
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
if (state.isStackEmpty()) {
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "",
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.getTsFields(), "",
(configField, prefix, prefix2) -> processOutput(prefix, prefix2), ".");
iterator.loop();
String content = iterator.getContent();

View File

@ -144,7 +144,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
@Override
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
state.getVariableRegistry().register(structure.name + "_size", structure.getTotalSize());
state.getVariableRegistry().register(structure.getName() + "_size", structure.getTotalSize());
totalTsSize = tsOutput.run(readerState, structure, 0);
if (state.isStackEmpty()) {

View File

@ -73,8 +73,8 @@ public class TsOutput {
}
if (cs != null) {
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
return writeFields(cs.tsFields, prefix + extraPrefix, tsPosition);
String extraPrefix = cs.isWithPrefix() ? configField.getName() + "_" : "";
return writeFields(cs.getTsFields(), prefix + extraPrefix, tsPosition);
}
if (configField.isBit()) {

View File

@ -164,7 +164,7 @@ public class ConfigFieldParserTest {
assertEquals(16, TypesHelper.getElementSize(state, "pid_s"));
ConfigStructure structure = state.getStructures().get("pid_s");
ConfigField firstField = structure.cFields.get(0);
ConfigField firstField = structure.getcFields().get(0);
assertEquals("ms", firstField.getUnits());
}