TS parser improvements, compatibility (#3479)
* scalar layout * wrong name in comments * better compatibility for tooltips starting with + or not * s * sort of handle signature * only strip nested * new parse can mostly read signature * oops * jar * jar
This commit is contained in:
parent
6a9c38f934
commit
a3c569e5f0
Binary file not shown.
|
@ -230,7 +230,9 @@ public class ConfigDefinition {
|
||||||
SystemOut.println(state.enumsReader.getEnums() + " total enumsReader");
|
SystemOut.println(state.enumsReader.getEnums() + " total enumsReader");
|
||||||
}
|
}
|
||||||
|
|
||||||
long crc32 = signatureHash(state, tsPath, inputAllFiles);
|
ParseState parseState = new ParseState(state.enumsReader);
|
||||||
|
// Add the variable for the config signature
|
||||||
|
long crc32 = signatureHash(state, parseState, tsPath, inputAllFiles);
|
||||||
|
|
||||||
handleFiringOrder(firingEnumFileName, state.variableRegistry);
|
handleFiringOrder(firingEnumFileName, state.variableRegistry);
|
||||||
|
|
||||||
|
@ -247,10 +249,8 @@ public class ConfigDefinition {
|
||||||
|
|
||||||
// Parse the input files
|
// Parse the input files
|
||||||
{
|
{
|
||||||
ParseState parseState = new ParseState(state.enumsReader);
|
|
||||||
|
|
||||||
// First process yaml files
|
// First process yaml files
|
||||||
//processYamls(listener, yamlFiles);
|
//processYamls(parseState, yamlFiles);
|
||||||
|
|
||||||
// Process firing order enum
|
// Process firing order enum
|
||||||
handleFiringOrder(firingEnumFileName, parseState);
|
handleFiringOrder(firingEnumFileName, parseState);
|
||||||
|
@ -262,7 +262,7 @@ public class ConfigDefinition {
|
||||||
|
|
||||||
//for (String prependFile : prependFiles) {
|
//for (String prependFile : prependFiles) {
|
||||||
// TODO: fix signature define file parsing
|
// TODO: fix signature define file parsing
|
||||||
//parseFile(listener, prependFile);
|
//parseFile(parseState, prependFile);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,12 +275,11 @@ public class ConfigDefinition {
|
||||||
|
|
||||||
// Write C structs
|
// Write C structs
|
||||||
// CStructWriter cStructs = new CStructWriter();
|
// CStructWriter cStructs = new CStructWriter();
|
||||||
// cStructs.writeCStructs(listener, destCHeaderFileName + ".test");
|
// cStructs.writeCStructs(parseState, destCHeaderFileName + ".test");
|
||||||
|
|
||||||
// Write tunerstudio layout
|
// Write tunerstudio layout
|
||||||
// TsWriter writer = new TsWriter();
|
// TsWriter writer = new TsWriter();
|
||||||
// writer.writeTunerstudio(listener, "TODO", tsPath + "/test.ini");
|
// writer.writeTunerstudio(parseState, tsPath + "/rusefi.input", tsPath + "/" + TSProjectConsumer.TS_FILE_OUTPUT_NAME);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
|
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
|
||||||
|
@ -346,7 +345,7 @@ public class ConfigDefinition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long signatureHash(ReaderState state, String tsPath, List<String> inputAllFiles) throws IOException {
|
private static long signatureHash(ReaderState state, ParseState parseState, String tsPath, List<String> inputAllFiles) throws IOException {
|
||||||
// get CRC32 of given input files
|
// get CRC32 of given input files
|
||||||
long crc32 = 0;
|
long crc32 = 0;
|
||||||
for (String iFile : inputAllFiles) {
|
for (String iFile : inputAllFiles) {
|
||||||
|
@ -356,8 +355,13 @@ public class ConfigDefinition {
|
||||||
}
|
}
|
||||||
SystemOut.println("CRC32 from all input files = " + crc32);
|
SystemOut.println("CRC32 from all input files = " + crc32);
|
||||||
// store the CRC32 as a built-in variable
|
// store the CRC32 as a built-in variable
|
||||||
if (tsPath != null) // nasty trick - do not insert signature into live data files
|
|
||||||
|
// nasty trick - do not insert signature into live data files
|
||||||
|
if (tsPath != null) {
|
||||||
state.variableRegistry.register(SIGNATURE_HASH, "" + crc32);
|
state.variableRegistry.register(SIGNATURE_HASH, "" + crc32);
|
||||||
|
parseState.addDefinition(SIGNATURE_HASH, Long.toString(crc32), Definition.OverwritePolicy.NotAllowed);
|
||||||
|
}
|
||||||
|
|
||||||
return crc32;
|
return crc32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,7 @@ public class ConfigField {
|
||||||
public String getCommentContent() {
|
public String getCommentContent() {
|
||||||
if (comment == null || comment.isEmpty())
|
if (comment == null || comment.isEmpty())
|
||||||
return comment;
|
return comment;
|
||||||
return comment.charAt(0) == TS_COMMENT_TAG ? comment.substring(1) : comment;
|
return (comment.charAt(0) == TS_COMMENT_TAG ? comment.substring(1) : comment).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getArraySizes() {
|
public int[] getArraySizes() {
|
||||||
|
|
|
@ -85,6 +85,28 @@ public class ScalarLayout extends Layout {
|
||||||
printAfterArrayLength(ps);
|
printAfterArrayLength(ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String makeScaleString() {
|
||||||
|
float scale = this.options.scale;
|
||||||
|
|
||||||
|
int mul, div;
|
||||||
|
|
||||||
|
if (scale < 1) {
|
||||||
|
mul = Math.round(1 / scale);
|
||||||
|
div = 1;
|
||||||
|
} else {
|
||||||
|
mul = 1;
|
||||||
|
div = Math.round(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
float actualScale = (float)mul / div;
|
||||||
|
|
||||||
|
if (mul < 1 || div < 1 || (Math.abs(scale - actualScale) < 0.0001f)) {
|
||||||
|
throw new RuntimeException("assertion failure: scale string generation failure for " + this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mul + ", " + div;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeCLayout(PrintStream ps) {
|
public void writeCLayout(PrintStream ps) {
|
||||||
this.writeCOffsetHeader(ps, this.options.comment, this.options.units);
|
this.writeCOffsetHeader(ps, this.options.comment, this.options.units);
|
||||||
|
@ -92,7 +114,7 @@ public class ScalarLayout extends Layout {
|
||||||
String cTypeName = this.type.cType.replaceAll("^int32_t$", "int");
|
String cTypeName = this.type.cType.replaceAll("^int32_t$", "int");
|
||||||
|
|
||||||
if (this.autoscale) {
|
if (this.autoscale) {
|
||||||
cTypeName = "scaled_channel<" + cTypeName + ", " + Math.round(1 / this.options.scale) + ">";
|
cTypeName = "scaled_channel<" + cTypeName + ", " + makeScaleString() + ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
ps.print("\t" + cTypeName + " " + this.name);
|
ps.print("\t" + cTypeName + " " + this.name);
|
||||||
|
@ -120,7 +142,7 @@ public class ScalarLayout extends Layout {
|
||||||
String cTypeName = this.type.cType.replaceAll("^int32_t$", "int");
|
String cTypeName = this.type.cType.replaceAll("^int32_t$", "int");
|
||||||
|
|
||||||
if (this.autoscale) {
|
if (this.autoscale) {
|
||||||
cTypeName = "scaled_channel<" + cTypeName + ", " + Math.round(1 / this.options.scale) + ">";
|
cTypeName = "scaled_channel<" + cTypeName + ", " + makeScaleString() + ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
ps.println("\t" + cTypeName + " " + this.name + "[" + al + "];");
|
ps.println("\t" + cTypeName + " " + this.name + "[" + al + "];");
|
||||||
|
|
|
@ -12,12 +12,16 @@ public class TsMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
comment = comment.trim();
|
comment = comment.trim();
|
||||||
if (!comment.startsWith("+")) {
|
|
||||||
return;
|
// LEGACY FEATURE: clips off the previously-required +
|
||||||
|
if (comment.startsWith("+")) {
|
||||||
|
// Clip off leading +, and any leading/trailing whitespace
|
||||||
|
comment = comment.substring(1).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clip off leading +, and any leading/trailing whitespace
|
if (comment.length() == 0) {
|
||||||
comment = comment.substring(1).trim();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
comments.add("\t" + name + " = \"" + comment + "\"");
|
comments.add("\t" + name + " = \"" + comment + "\"");
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,6 @@ public class TsWriter {
|
||||||
BufferedReader is = new BufferedReader(new FileReader(inputFile));
|
BufferedReader is = new BufferedReader(new FileReader(inputFile));
|
||||||
PrintStream ps = new PrintStream(new FileOutputStream(outputFile));
|
PrintStream ps = new PrintStream(new FileOutputStream(outputFile));
|
||||||
|
|
||||||
// TODO: handle signature
|
|
||||||
parser.addDefinition("TS_SIGNATURE", "sig", Definition.OverwritePolicy.NotAllowed);
|
|
||||||
|
|
||||||
while (is.ready()) {
|
while (is.ready()) {
|
||||||
String line = is.readLine();
|
String line = is.readLine();
|
||||||
|
|
||||||
|
@ -45,6 +42,9 @@ public class TsWriter {
|
||||||
line = line.replace(match.group(0), "");
|
line = line.replace(match.group(0), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't strip surrounding quotes of the FIRST replace of the line - only do it in nested replacements
|
||||||
|
boolean isNested = false;
|
||||||
|
|
||||||
// While there is a line to replace, do it
|
// While there is a line to replace, do it
|
||||||
while (line.contains("@@")) {
|
while (line.contains("@@")) {
|
||||||
match = VAR.matcher(line);
|
match = VAR.matcher(line);
|
||||||
|
@ -55,7 +55,19 @@ public class TsWriter {
|
||||||
|
|
||||||
String varName = match.group(1);
|
String varName = match.group(1);
|
||||||
Definition def = parser.findDefinition(varName);
|
Definition def = parser.findDefinition(varName);
|
||||||
line = line.replaceAll(match.group(0), def != null ? def.toString() : "MISSING DEFINITION");
|
|
||||||
|
String replacement = def != null ? def.toString() : "MISSING DEFINITION";
|
||||||
|
|
||||||
|
// Strip off any quotes from the resolved string - we may be trying to concatenate inside a string literal where quotes aren't allowed
|
||||||
|
while (isNested && replacement.startsWith("\"") && replacement.endsWith("\"")) {
|
||||||
|
replacement = replacement.substring(1, replacement.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
line = line.replaceAll(match.group(0), replacement);
|
||||||
|
|
||||||
|
if (!isNested) {
|
||||||
|
isNested = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove extra whitespace from the line
|
// TODO: remove extra whitespace from the line
|
||||||
|
|
Loading…
Reference in New Issue