code generator: better handing of array size 1
This commit is contained in:
parent
50cf213163
commit
9fbf16ce08
|
@ -1937,4 +1937,3 @@ end_struct
|
|||
#define show_Frankenso_presets true
|
||||
#define show_microRusEFI_presets true
|
||||
#define show_Proteus_presets true
|
||||
|
||||
|
|
Binary file not shown.
|
@ -81,6 +81,10 @@ public class ConfigField {
|
|||
this.isIterate = isIterate;
|
||||
}
|
||||
|
||||
public boolean isArray() {
|
||||
return arraySizeVariableName != null || arraySize != 1;
|
||||
}
|
||||
|
||||
public String getTrueName() {
|
||||
return trueName;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class CHeaderConsumer implements ConfigurationConsumer {
|
|||
|
||||
String cEntry = ConfigDefinition.getComment(configField.getCommentContent(), currentOffset);
|
||||
|
||||
if (configField.getArraySize() == 1) {
|
||||
if (!configField.isArray()) {
|
||||
// not an array
|
||||
cEntry += "\t" + configField.getType() + " " + configField.getName();
|
||||
if (ConfigDefinition.needZeroInit && TypesHelper.isPrimitive(configField.getType())) {
|
||||
|
@ -94,4 +94,8 @@ public class CHeaderConsumer implements ConfigurationConsumer {
|
|||
cHeader.write("// this section " + ConfigDefinition.MESSAGE + EOL);
|
||||
cHeader.close();
|
||||
}
|
||||
|
||||
public StringBuilder getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.rusefi.ConfigField;
|
|||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TypesHelper;
|
||||
import com.rusefi.VariableRegistry;
|
||||
import com.rusefi.output.CHeaderConsumer;
|
||||
import com.rusefi.output.FsioSettingsConsumer;
|
||||
import com.rusefi.output.JavaFieldsConsumer;
|
||||
import com.rusefi.output.TSProjectConsumer;
|
||||
|
@ -293,6 +294,30 @@ public class ConfigFieldParserTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOfOne() throws IOException {
|
||||
String test = "struct pid_s\n" +
|
||||
"#define ERROR_BUFFER_SIZE 1\n" +
|
||||
"int[ERROR_BUFFER_SIZE iterate] field\n" +
|
||||
"end_struct\n" +
|
||||
"";
|
||||
VariableRegistry.INSTANCE.clear();
|
||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
||||
CHeaderConsumer consumer = new CHeaderConsumer("d");
|
||||
new ReaderState().readBufferedReader(reader, Collections.singletonList(consumer));
|
||||
assertEquals("// start of pid_s\n" +
|
||||
"struct pid_s {\n" +
|
||||
"\t/**\n" +
|
||||
"\t * offset 0\n" +
|
||||
"\t */\n" +
|
||||
"\tint field[ERROR_BUFFER_SIZE];\n" +
|
||||
"\t/** total size 4*/\n" +
|
||||
"};\n" +
|
||||
"\n" +
|
||||
"typedef struct pid_s pid_s;\n" +
|
||||
"\n", consumer.getContent().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseLine() {
|
||||
ReaderState state = new ReaderState();
|
||||
|
|
Loading…
Reference in New Issue