mirror of https://github.com/FOME-Tech/fome-fw.git
new parser writes offset assertions
This commit is contained in:
parent
7fd38084e0
commit
bbbf46deea
|
@ -7,6 +7,7 @@ import com.rusefi.ReaderState;
|
|||
import com.rusefi.ReaderStateImpl;
|
||||
import com.rusefi.RusefiParseErrorStrategy;
|
||||
import com.rusefi.newparse.ParseState;
|
||||
import com.rusefi.newparse.outputs.CStructWriter;
|
||||
import com.rusefi.newparse.outputs.OutputChannelWriter;
|
||||
import com.rusefi.newparse.parsing.Definition;
|
||||
import com.rusefi.output.*;
|
||||
|
@ -114,7 +115,8 @@ public class LiveDataProcessor {
|
|||
if (extraPrepend != null)
|
||||
state.addPrepend(extraPrepend);
|
||||
state.addPrepend(prepend);
|
||||
state.addCHeaderDestination(folder + File.separator + name + "_generated.h");
|
||||
String cHeaderDestination = folder + File.separator + name + "_generated.h";
|
||||
state.addCHeaderDestination(cHeaderDestination);
|
||||
|
||||
int baseOffset = outputsSections.getBaseOffset();
|
||||
state.addDestination(new FileJavaFieldsConsumer(state, "../java_console/models/src/main/java/com/rusefi/config/generated/" + javaName, baseOffset));
|
||||
|
@ -142,11 +144,14 @@ public class LiveDataProcessor {
|
|||
|
||||
RusefiParseErrorStrategy.parseDefinitionFile(parseState.getListener(), state.getDefinitionInputFile());
|
||||
|
||||
// CStructWriter cStructs = new CStructWriter();
|
||||
// cStructs.writeCStructs(parseState, cHeaderDestination);
|
||||
|
||||
// if (outputNames.length == 0) {
|
||||
// outputChannelWriter.writeOutputChannels(parseState, null);
|
||||
// } else {
|
||||
// for (int i = 0; i < outputNames.length; i++) {
|
||||
// outputChannelWriter.writeOutputChannels(parseState, fragmentDialogConsumer, outputNames[i]);
|
||||
// outputChannelWriter.writeOutputChannels(parseState, outputNames[i]);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -74,6 +74,11 @@ public class ArrayLayout extends Layout {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCOffsetCheck(PrintStream ps, String parentTypeName) {
|
||||
this.prototypeLayout.writeCOffsetCheck(ps, parentTypeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeOutputChannelLayout(PrintStream ps, StructNamePrefixer prefixer, int offsetAdd) {
|
||||
this.prototypeLayout.writeOutputChannelLayout(ps, prefixer, offsetAdd, this.length);
|
||||
|
|
|
@ -65,6 +65,8 @@ public abstract class Layout {
|
|||
throw new IllegalStateException("This type can't be in an array!");
|
||||
}
|
||||
|
||||
public void writeCOffsetCheck(PrintStream ps, String parentTypeName) { }
|
||||
|
||||
public void writeOutputChannelLayout(PrintStream ps, String prefix, int offsetAdd) {
|
||||
StructNamePrefixer prefixer = new StructNamePrefixer();
|
||||
|
||||
|
|
|
@ -148,6 +148,17 @@ public class ScalarLayout extends Layout {
|
|||
ps.println("\t" + cTypeName + " " + this.name + "[" + al + "];");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCOffsetCheck(PrintStream ps, String parentTypeName) {
|
||||
ps.print("static_assert(offsetof(");
|
||||
ps.print(parentTypeName);
|
||||
ps.print(", ");
|
||||
ps.print(this.name);
|
||||
ps.print(") == ");
|
||||
ps.print(this.offsetWithinStruct);
|
||||
ps.println(");");
|
||||
}
|
||||
|
||||
private void writeOutputChannelLayout(PrintStream ps, StructNamePrefixer prefixer, int offsetAdd, String name) {
|
||||
ps.print(prefixer.get(name));
|
||||
//ps.print(" = " + fieldType + ", ");
|
||||
|
|
|
@ -59,4 +59,15 @@ public class StringLayout extends Layout {
|
|||
this.writeCOffsetHeader(ps, this.comment, null);
|
||||
ps.println("\tchar " + this.name + "[" + arrayLength[0] + "][" + this.size + "];");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCOffsetCheck(PrintStream ps, String parentTypeName) {
|
||||
ps.print("static_assert(offsetof(");
|
||||
ps.print(parentTypeName);
|
||||
ps.print(", ");
|
||||
ps.print(this.name);
|
||||
ps.print(") == ");
|
||||
ps.print(this.offsetWithinStruct);
|
||||
ps.println(");");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,6 +189,9 @@ public class StructLayout extends Layout {
|
|||
ps.println("};");
|
||||
ps.println("static_assert(sizeof(" + this.typeName + ") == " + getSize() + ");");
|
||||
|
||||
// Emit assertions to check that the offset of each child is correct according to the C++ compiler
|
||||
this.children.forEach(c -> c.writeCOffsetCheck(ps, this.typeName));
|
||||
|
||||
ps.println();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue