generator refactoring
This commit is contained in:
parent
d129c43e0a
commit
1b84bac3d5
Binary file not shown.
|
@ -8,13 +8,14 @@ public abstract class BaseCHeaderConsumer implements ConfigurationConsumer {
|
|||
private static final String BOOLEAN_TYPE = "bool";
|
||||
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()) {
|
||||
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;
|
||||
}
|
||||
|
||||
String cEntry = ConfigDefinition.getComment(configField.getCommentContent(), currentOffset, configField.getUnits());
|
||||
String cEntry = ConfigDefinition.getComment(configField.getCommentContent(), iterator.currentOffset, configField.getUnits());
|
||||
|
||||
String typeName = configField.getType();
|
||||
|
||||
|
@ -46,19 +47,16 @@ public abstract class BaseCHeaderConsumer implements ConfigurationConsumer {
|
|||
content.append("// start of " + structure.name + EOL);
|
||||
content.append("struct " + structure.name + " {" + EOL);
|
||||
|
||||
int currentOffset = 0;
|
||||
|
||||
FieldIterator iterator = new FieldIterator(structure.cFields);
|
||||
FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(structure.cFields);
|
||||
for (int i = 0; i < structure.cFields.size(); 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?
|
||||
currentOffset += iterator.cf.getSize(iterator.next);
|
||||
iterator.currentOffset += iterator.cf.getSize(iterator.next);
|
||||
iterator.end();
|
||||
}
|
||||
|
||||
content.append("\t/** total size " + currentOffset + "*/" + EOL);
|
||||
content.append("\t/** total size " + iterator.currentOffset + "*/" + EOL);
|
||||
content.append("};" + EOL + EOL);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,14 +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
|
||||
*/
|
||||
totalSize = 0;
|
||||
FieldIterator iterator = new FieldIterator(cFields);
|
||||
FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(cFields);
|
||||
for (int i = 0; i < cFields.size(); i++) {
|
||||
iterator.start(i);
|
||||
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);
|
||||
|
||||
if (fillSize != 0) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue