random clean-up and more explicit handing of 33 bits in a row
This commit is contained in:
parent
4d03ff9751
commit
c0b30287e7
|
@ -17,7 +17,7 @@ public class BitState {
|
|||
|
||||
public void incrementBitIndex(ConfigField cf) {
|
||||
if (bitIndex == 32)
|
||||
throw new IllegalStateException("Too many bits: " + cf.getName());
|
||||
throw new TooManyBitsInARow("Too many bits in a row: " + cf.getName());
|
||||
bitIndex++;
|
||||
}
|
||||
|
||||
|
@ -28,4 +28,10 @@ public class BitState {
|
|||
public int get() {
|
||||
return bitIndex;
|
||||
}
|
||||
|
||||
public static class TooManyBitsInARow extends RuntimeException {
|
||||
public TooManyBitsInARow(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.output.JavaFieldsConsumer;
|
||||
import com.rusefi.util.SystemOut;
|
||||
import com.rusefi.test.ConfigFieldParserTest;
|
||||
|
||||
|
@ -43,8 +44,6 @@ public class ConfigField {
|
|||
private final ReaderState state;
|
||||
private final boolean fsioVisible;
|
||||
private final boolean hasAutoscale;
|
||||
private final String individualName;
|
||||
private final int indexWithinArray;
|
||||
private final String trueName;
|
||||
private final String falseName;
|
||||
|
||||
|
@ -62,11 +61,11 @@ public class ConfigField {
|
|||
boolean fsioVisible,
|
||||
boolean hasAutoscale,
|
||||
String individualName,
|
||||
int indexWithinArray, String trueName, String falseName) {
|
||||
int indexWithinArray,
|
||||
String trueName,
|
||||
String falseName) {
|
||||
this.fsioVisible = fsioVisible;
|
||||
this.hasAutoscale = hasAutoscale;
|
||||
this.individualName = individualName;
|
||||
this.indexWithinArray = indexWithinArray;
|
||||
this.trueName = trueName == null ? "true" : trueName;
|
||||
this.falseName = falseName == null ? "false" : falseName;
|
||||
Objects.requireNonNull(name, comment + " " + type);
|
||||
|
@ -99,19 +98,6 @@ public class ConfigField {
|
|||
return falseName;
|
||||
}
|
||||
|
||||
public String getCFieldName() {
|
||||
return getIndividualName() == null ? getName() : getIndividualName() + "["
|
||||
+ (getIndexWithinArray() - 1) + "]";
|
||||
}
|
||||
|
||||
public String getIndividualName() {
|
||||
return individualName;
|
||||
}
|
||||
|
||||
public int getIndexWithinArray() {
|
||||
return indexWithinArray;
|
||||
}
|
||||
|
||||
public boolean isBit() {
|
||||
return BOOLEAN_T.equalsIgnoreCase(type);
|
||||
}
|
||||
|
@ -182,14 +168,16 @@ public class ConfigField {
|
|||
return field;
|
||||
}
|
||||
|
||||
public static boolean isPreprocessorDirective(ReaderState state, String line) {
|
||||
public static boolean isPreprocessorDirective(String line) {
|
||||
Matcher matcher = DIRECTIVE.matcher(line);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
public int getSize(ConfigField next) {
|
||||
if (isBit() && next.isBit())
|
||||
if (isBit() && next.isBit()) {
|
||||
// we have a protection from 33+ bits in a row in BitState, see BitState.TooManyBitsInARow
|
||||
return 0;
|
||||
}
|
||||
if (isBit())
|
||||
return 4;
|
||||
int size = getElementSize();
|
||||
|
@ -265,7 +253,7 @@ public class ConfigField {
|
|||
}
|
||||
if (tsInfo == null)
|
||||
throw new IllegalArgumentException("tsInfo expected with autoscale");
|
||||
String[] tokens = tsInfo.split("\\,");
|
||||
String[] tokens = tsInfo.split(",");
|
||||
if (tokens.length < 2)
|
||||
throw new IllegalArgumentException("Second comma-separated token expected in [" + tsInfo + "] for " + name);
|
||||
|
||||
|
@ -303,7 +291,7 @@ public class ConfigField {
|
|||
private String[] getTokens() {
|
||||
if (tsInfo == null)
|
||||
return new String[0];
|
||||
return tsInfo.split("\\,");
|
||||
return tsInfo.split(",");
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
|
|
|
@ -240,7 +240,7 @@ public class ReaderState {
|
|||
ConfigField cf = ConfigField.parse(state, line);
|
||||
|
||||
if (cf == null) {
|
||||
if (ConfigField.isPreprocessorDirective(state, line)) {
|
||||
if (ConfigField.isPreprocessorDirective(line)) {
|
||||
cf = new ConfigField(state, "", line, null,
|
||||
ConfigField.DIRECTIVE_T, new int[0], null, false, false, false, null, 0,
|
||||
null, null);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import com.rusefi.BitState;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.output.DataLogConsumer;
|
||||
import com.rusefi.output.GaugeConsumer;
|
||||
|
@ -65,6 +66,20 @@ public class OutputsTest {
|
|||
|
||||
}
|
||||
|
||||
@Test(expected = BitState.TooManyBitsInARow.class)
|
||||
public void tooManyBits() throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 40; i++)
|
||||
sb.append("bit b" + i + "\n");
|
||||
String test = "struct total\n" +
|
||||
sb +
|
||||
"end_struct\n";
|
||||
ReaderState state = new ReaderState();
|
||||
|
||||
OutputsSectionConsumer tsProjectConsumer = new OutputsSectionConsumer(null, state);
|
||||
state.readBufferedReader(test, Collections.singletonList(tsProjectConsumer));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateDataLog() throws IOException {
|
||||
String test = "struct total\n" +
|
||||
|
|
Loading…
Reference in New Issue