Technical debt: ENUM_32_BITS #3874

This commit is contained in:
rusefillc 2022-05-02 00:22:45 -04:00
parent fb5bfab6f9
commit 3ef4508f1f
7 changed files with 20 additions and 6 deletions

Binary file not shown.

View File

@ -72,7 +72,7 @@ public class ParseState {
if (stringValueMap == null)
return null;
for (Value value : stringValueMap.values()) {
if (value.getValue().contains("ENUM_32_BITS"))
if (value.isForceSize())
continue;
if (isNumeric(value.getValue())) {

View File

@ -9,6 +9,7 @@ import java.io.FileReader;
import java.io.IOException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ConfigDefinitionTest {
private static final String FIRMWARE = "../../firmware";
@ -27,5 +28,6 @@ public class ConfigDefinitionTest {
System.out.println(sb);
assertNotNull(sb);
assertTrue("Seems too long" + sb, sb.length() < 100000);
}
}

View File

@ -21,6 +21,7 @@ public class EnumAsTsVariable {
"\n" +
"\t// 2 cylinder\n" +
"\tFO_1_2 = 8,\n" +
"Force_2b_firing_order = ENUM_16_BITS,\n" +
"Force_4b_firing_order = ENUM_32_BITS,\n" +
"} firing_order_e;")));

View File

@ -12,6 +12,10 @@ import java.util.List;
import java.util.Map;
public class ToJavaEnum {
public static final String FORCE_2_BYTES_SIZE = "Force_2_bytes_size";
public static final String FORCE_4_BYTES_SIZE = "Force_4_bytes_size";
public static void main(String[] args) throws IOException {
InvokeReader invokeReader = new InvokeReader(args).invoke();
String outputPath = invokeReader.getOutputPath();
@ -50,8 +54,8 @@ public class ToJavaEnum {
for (Value value : sorted) {
int numericValue = value.getIntValueMaybeResolve(registry);
if (index != numericValue
&& !value.getName().startsWith("Force_2_bytes_size")
&& !value.getName().startsWith("Force_4_bytes_size"))
&& !value.getName().startsWith(FORCE_2_BYTES_SIZE)
&& !value.getName().startsWith(FORCE_4_BYTES_SIZE))
throw new IllegalStateException("Got explicit ordinal " + numericValue + " instead of ordinal " + index + " in " + value);
sb.append("\t" + value.getName() + ",\n");
index++;

View File

@ -2,7 +2,6 @@ package com.rusefi;
import com.devexperts.logging.Logging;
import com.rusefi.enum_reader.Value;
import com.rusefi.util.SystemOut;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
@ -94,7 +93,7 @@ public class VariableRegistry {
if (stringValueMap == null)
return null;
for (Value value : stringValueMap.values()) {
if (value.getValue().contains("ENUM_32_BITS"))
if (value.isForceSize())
continue;
if (isNumeric(value.getValue())) {
@ -131,6 +130,7 @@ public class VariableRegistry {
/**
* This method replaces variables references like @@var@@ with actual values
* An exception is thrown if we do not have such variable
*
* @return string with variable values inlined
*/
public String applyVariables(String line) {

View File

@ -4,6 +4,9 @@ import com.rusefi.VariableRegistry;
import java.util.Objects;
import static com.rusefi.ToJavaEnum.FORCE_2_BYTES_SIZE;
import static com.rusefi.ToJavaEnum.FORCE_4_BYTES_SIZE;
public class Value implements Comparable<Value> {
private final String name;
private final String value;
@ -13,6 +16,10 @@ public class Value implements Comparable<Value> {
this.value = value;
}
public boolean isForceSize() {
return getName().startsWith(FORCE_2_BYTES_SIZE) || getName().startsWith(FORCE_4_BYTES_SIZE);
}
public String getName() {
return name;
}