generator refactoring

This commit is contained in:
rusefillc 2021-12-11 04:04:15 -05:00
parent d129c43e0a
commit 1b84bac3d5
4 changed files with 24 additions and 13 deletions

Binary file not shown.

View File

@ -8,13 +8,14 @@ public abstract class BaseCHeaderConsumer implements ConfigurationConsumer {
private static final String BOOLEAN_TYPE = "bool"; private static final String BOOLEAN_TYPE = "bool";
private final StringBuilder content = new StringBuilder(); private final StringBuilder content = new StringBuilder();
private static String getHeaderText(ConfigField configField, int currentOffset, int bitIndex) { private static String getHeaderText(FieldIteratorWithOffset iterator) {
ConfigField configField = iterator.cf;
if (configField.isBit()) { if (configField.isBit()) {
String comment = "\t/**" + EOL + ConfigDefinition.packComment(configField.getCommentContent(), "\t") + "\toffset " + currentOffset + " bit " + bitIndex + " */" + EOL; String comment = "\t/**" + EOL + ConfigDefinition.packComment(configField.getCommentContent(), "\t") + "\toffset " + iterator.currentOffset + " bit " + iterator.bitState.get() + " */" + EOL;
return comment + "\t" + BOOLEAN_TYPE + " " + configField.getName() + " : 1 {};" + EOL; return comment + "\t" + BOOLEAN_TYPE + " " + configField.getName() + " : 1 {};" + EOL;
} }
String cEntry = ConfigDefinition.getComment(configField.getCommentContent(), currentOffset, configField.getUnits()); String cEntry = ConfigDefinition.getComment(configField.getCommentContent(), iterator.currentOffset, configField.getUnits());
String typeName = configField.getType(); String typeName = configField.getType();
@ -46,19 +47,16 @@ public abstract class BaseCHeaderConsumer implements ConfigurationConsumer {
content.append("// start of " + structure.name + EOL); content.append("// start of " + structure.name + EOL);
content.append("struct " + structure.name + " {" + EOL); content.append("struct " + structure.name + " {" + EOL);
int currentOffset = 0; FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(structure.cFields);
FieldIterator iterator = new FieldIterator(structure.cFields);
for (int i = 0; i < structure.cFields.size(); i++) { for (int i = 0; i < structure.cFields.size(); i++) {
iterator.start(i); iterator.start(i);
content.append(getHeaderText(iterator.cf, currentOffset, iterator.bitState.get())); content.append(getHeaderText(iterator));
// todo: do we have a bug with conditional field offsets being wrong? iterator.currentOffset += iterator.cf.getSize(iterator.next);
currentOffset += iterator.cf.getSize(iterator.next);
iterator.end(); iterator.end();
} }
content.append("\t/** total size " + currentOffset + "*/" + EOL); content.append("\t/** total size " + iterator.currentOffset + "*/" + EOL);
content.append("};" + EOL + EOL); content.append("};" + EOL + EOL);
} }

View File

@ -58,14 +58,14 @@ public class ConfigStructure {
* we make alignment decision based on C fields since we expect iteration and non-iteration fields * we make alignment decision based on C fields since we expect iteration and non-iteration fields
* to match in size * to match in size
*/ */
totalSize = 0; FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(cFields);
FieldIterator iterator = new FieldIterator(cFields);
for (int i = 0; i < cFields.size(); i++) { for (int i = 0; i < cFields.size(); i++) {
iterator.start(i); iterator.start(i);
iterator.end(); iterator.end();
totalSize += iterator.cf.getSize(iterator.next); iterator.currentOffset += iterator.cf.getSize(iterator.next);
} }
totalSize = iterator.currentOffset;
int fillSize = totalSize % 4 == 0 ? 0 : 4 - (totalSize % 4); int fillSize = totalSize % 4 == 0 ? 0 : 4 - (totalSize % 4);
if (fillSize != 0) { if (fillSize != 0) {

View File

@ -0,0 +1,13 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import java.util.List;
public class FieldIteratorWithOffset extends FieldIterator {
public int currentOffset;
public FieldIteratorWithOffset(List<ConfigField> tsFields) {
super(tsFields);
}
}