TS enum key-value form #4232

This commit is contained in:
rusefillc 2022-06-02 12:47:39 -04:00
parent 0aab6d10e0
commit b4e3bb63ef
3 changed files with 22 additions and 0 deletions

View File

@ -134,6 +134,7 @@ public class ReaderState {
tsCustomSize.put(name, size);
RawIniFile.Line rawLine = new RawIniFile.Line(tunerStudioLine);
//boolean isKeyValueForm = tunerStudioLine.contains("=\"");
if (rawLine.getTokens()[0].equals("bits")) {
EnumIniField.ParseBitRange bitRange = new EnumIniField.ParseBitRange().invoke(rawLine.getTokens()[3]);
int totalCount = 1 << (bitRange.getBitSize0() + 1);
@ -146,6 +147,7 @@ public class ReaderState {
if (enums.size() <= totalCount / 2)
throw new IllegalStateException("Too many bits allocated for " + enums + " capacity=" + totalCount + "/size=" + enums.size());
*/
// todo: TS enum key-value form #4232?
// this is needed to avoid 'bit Constant engineType, contains fewer options (103) that expected(128)' TS warning
for (int i = enums.size(); i < totalCount; i++)
tunerStudioLine += ", " + PinoutLogic.QUOTED_INVALID;

View File

@ -94,6 +94,25 @@ public class ConfigFieldParserTest {
"; total TS size = 4\n", tsProjectConsumer.getContent());
}
@Test
public void testShortForm() throws IOException {
String test = "struct pid_s\n" +
"#define ego_sensor_e_enum \"BPSX\"\n" +
"custom ego_sensor_e 1 bits, S08, @OFFSET@, [0:1], @@ego_sensor_e_enum@@\n" +
"ego_sensor_e afr_type1;\n" +
"ego_sensor_e afr_type2;\n" +
"int8_t int\n" +
"end_struct\n";
ReaderState state = new ReaderState();
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
assertEquals("afr_type1 = bits, S08, 0, [0:1], \"BPSX\", \"INVALID\", \"INVALID\", \"INVALID\"\n" +
"afr_type2 = bits, S08, 1, [0:1], \"BPSX\", \"INVALID\", \"INVALID\", \"INVALID\"\n" +
"int = scalar, S08, 2, \"\", 1, 0, 0, 100, 0\n" +
"; total TS size = 4\n", tsProjectConsumer.getContent());
}
@Test
public void test2byteCustomEnum() throws IOException {
String test = "struct pid_s\n" +

View File

@ -121,6 +121,7 @@ public class VariableRegistry {
int maxValue = valueNameById.lastKey();
StringBuilder sb = new StringBuilder();
// todo: TS enum key-value form #4232
for (int i = 0; i <= maxValue; i++) {
if (sb.length() > 0)
sb.append(", ");