generator refactoring
This commit is contained in:
parent
1b84bac3d5
commit
2656f4b7b7
Binary file not shown.
|
@ -58,12 +58,14 @@ public class ConfigStructure {
|
|||
* we make alignment decision based on C fields since we expect iteration and non-iteration fields
|
||||
* to match in size
|
||||
*/
|
||||
FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(cFields);
|
||||
for (int i = 0; i < cFields.size(); i++) {
|
||||
iterator.start(i);
|
||||
iterator.end();
|
||||
iterator.currentOffset += iterator.cf.getSize(iterator.next);
|
||||
}
|
||||
FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(cFields) {
|
||||
@Override
|
||||
public void end() {
|
||||
super.end();
|
||||
currentOffset += cf.getSize(next);
|
||||
}
|
||||
};
|
||||
iterator.loop();
|
||||
|
||||
totalSize = iterator.currentOffset;
|
||||
int fillSize = totalSize % 4 == 0 ? 0 : 4 - (totalSize % 4);
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
import java.io.CharArrayWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static com.rusefi.ConfigField.unquote;
|
||||
|
@ -40,8 +41,9 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
@Override
|
||||
public void handleEndStruct(ConfigStructure structure) throws IOException {
|
||||
if (state.stack.isEmpty()) {
|
||||
FieldIterator iterator = new FieldIterator(structure.tsFields);
|
||||
String content = handleFields(structure, iterator, "");
|
||||
DataLogFieldIterator iterator = new DataLogFieldIterator(structure.tsFields, "");
|
||||
iterator.loop();
|
||||
String content = iterator.sb.toString();
|
||||
tsWriter.append(content);
|
||||
}
|
||||
|
||||
|
@ -52,17 +54,21 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
private String handleFields(ConfigStructure structure, FieldIterator iterator, String prefix) {
|
||||
class DataLogFieldIterator extends FieldIterator {
|
||||
private final String prefix;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < structure.tsFields.size(); i++) {
|
||||
iterator.start(i);
|
||||
|
||||
String content = handle(iterator.cf, prefix);
|
||||
sb.append(content);
|
||||
iterator.end();
|
||||
|
||||
public DataLogFieldIterator(List<ConfigField> fields, String prefix) {
|
||||
super(fields);
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
String content = handle(cf, prefix);
|
||||
sb.append(content);
|
||||
super.end();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String handle(ConfigField configField, String prefix) {
|
||||
|
@ -72,7 +78,9 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
ConfigStructure cs = configField.getState().structures.get(configField.getType());
|
||||
if (cs != null) {
|
||||
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
|
||||
return handleFields(cs, new FieldIterator(cs.tsFields), extraPrefix);
|
||||
DataLogFieldIterator fieldIterator = new DataLogFieldIterator(cs.tsFields, extraPrefix);
|
||||
fieldIterator.loop();
|
||||
return fieldIterator.sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,14 +9,14 @@ import java.util.List;
|
|||
* custom iterator with references to previous and next elements
|
||||
*/
|
||||
public class FieldIterator {
|
||||
private final List<ConfigField> tsFields;
|
||||
private final List<ConfigField> fields;
|
||||
BitState bitState = new BitState();
|
||||
private ConfigField prev = ConfigField.VOID;
|
||||
ConfigField next;
|
||||
ConfigField cf;
|
||||
|
||||
public FieldIterator(List<ConfigField> tsFields) {
|
||||
this.tsFields = tsFields;
|
||||
public FieldIterator(List<ConfigField> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,11 +28,18 @@ public class FieldIterator {
|
|||
|
||||
public void start(int index) {
|
||||
int nextIndex = index + 1;
|
||||
while (nextIndex < tsFields.size() && tsFields.get(nextIndex).isDirective())
|
||||
while (nextIndex < fields.size() && fields.get(nextIndex).isDirective())
|
||||
nextIndex++;
|
||||
|
||||
next = nextIndex >= tsFields.size() ? ConfigField.VOID : tsFields.get(nextIndex);
|
||||
cf = tsFields.get(index);
|
||||
next = nextIndex >= fields.size() ? ConfigField.VOID : fields.get(nextIndex);
|
||||
cf = fields.get(index);
|
||||
}
|
||||
|
||||
public void loop() {
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
start(i);
|
||||
end();
|
||||
}
|
||||
}
|
||||
|
||||
public void end() {
|
||||
|
|
Loading…
Reference in New Issue