console crash #3772
This commit is contained in:
parent
0fcf3c3f0b
commit
54d77a62f6
|
@ -28,7 +28,7 @@ public enum StateDictionary {
|
|||
register(live_data_e.LDS_trigger_state, TriggerState.VALUES, "trigger_decoder.cpp"); // 11
|
||||
register(live_data_e.LDS_ac_control, AcControl.VALUES, "ac_control.cpp"); // 12
|
||||
register(live_data_e.LDS_fan_control, FuelPump.VALUES, "fan_control.cpp");
|
||||
register(live_data_e.LDS_injector_model, InjectorModel.VALUES, "injector_model");
|
||||
register(live_data_e.LDS_injector_model, InjectorModel.VALUES, "injector_model.cpp");
|
||||
register(live_data_e.LDS_idle_state, IdleState.VALUES, "idle_thread.cpp");
|
||||
register(live_data_e.LDS_fuel_pump, FuelPump.VALUES, "fuel_pump.cpp");
|
||||
register(live_data_e.LDS_wall_fuel_state, WallFuelState.VALUES, "wall_fuel.cpp");
|
||||
|
|
|
@ -150,7 +150,11 @@ public class CodeWalkthrough {
|
|||
color = isAlive == BranchingState.TRUE ? ACTIVE_STATEMENT : PASSIVE_CODE;
|
||||
}
|
||||
}
|
||||
Range range = new Range(ctx);
|
||||
Range range = Range.create(ctx.start, ctx.stop);
|
||||
if (range == null) {
|
||||
// parsing error sorry we have to bail out
|
||||
return;
|
||||
}
|
||||
if (log.debugEnabled())
|
||||
log.info(color + " for " + sourceCode.substring(range.getStart(), range.getStop()));
|
||||
painter.paintBackground(color, range);
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.rusefi.ui.livedocs.RefreshActions;
|
|||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
|
@ -103,10 +104,19 @@ public class LiveDataParserPanel {
|
|||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getContent(Class<?> clazz, String fileName) throws IOException, URISyntaxException {
|
||||
String contentOrNull = getContentOrNull(clazz, fileName);
|
||||
if (contentOrNull == null)
|
||||
return fileName + " getResourceAsStream not found";
|
||||
return contentOrNull;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getContentOrNull(Class<?> clazz, String fileName) throws IOException {
|
||||
InputStream cpp = clazz.getResourceAsStream("/c_sources/" + fileName);
|
||||
if (cpp == null)
|
||||
return fileName + " getResourceAsStream not found";
|
||||
return null;
|
||||
String line;
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
See https://github.com/antlr/grammars-v4/tree/master/cpp
|
|
@ -30,8 +30,11 @@ public class Range {
|
|||
public static Range create(Token startToken, Token stopToken) {
|
||||
int start = startToken.getStartIndex();
|
||||
int stop = stopToken.getStopIndex() + 1;
|
||||
if (stop < start)
|
||||
throw new IllegalStateException("Order issue " + startToken + "/" + stopToken);
|
||||
if (stop < start) {
|
||||
// this happens in case of parsing error
|
||||
// we are using CPP14 parser while we are using fancier version of C++ maybe that's a contributing factor?
|
||||
return null;
|
||||
}
|
||||
return new Range(startToken, stopToken);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.rusefi.ui.livedata;
|
||||
|
||||
import com.rusefi.CodeWalkthrough;
|
||||
import com.rusefi.enums.live_data_e;
|
||||
import com.rusefi.ldmp.StateDictionary;
|
||||
import com.rusefi.livedata.LiveDataParserPanel;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static com.rusefi.livedata.LiveDataParserPanel.getContentOrNull;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class LiveDataColorTest {
|
||||
@Test
|
||||
public void testAllFiles() throws IOException, URISyntaxException {
|
||||
int counter = 0;
|
||||
for (live_data_e view : live_data_e.values()) {
|
||||
String fileName = StateDictionary.INSTANCE.getFileName(view);
|
||||
|
||||
try {
|
||||
testSpecificFile(fileName);
|
||||
} catch (RuntimeException e) {
|
||||
throw new IllegalStateException("During " + fileName, e);
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
assertTrue(counter > 4);
|
||||
|
||||
}
|
||||
|
||||
private void testSpecificFile(String fileName) throws IOException {
|
||||
String sourceCode = getContentOrNull(getClass(), fileName);
|
||||
assertNotNull("sourceCode for " + fileName, sourceCode);
|
||||
|
||||
ParseTree tree = LiveDataParserPanel.getParseTree(sourceCode);
|
||||
|
||||
CodeWalkthrough.applyVariables(VariableValueSource.VOID, sourceCode, new SourceCodePainter() {
|
||||
@Override
|
||||
public void paintBackground(Color color, Range range) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintForeground(Color color, Range range) {
|
||||
}
|
||||
}, tree);
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ public class LiveDataParserTest {
|
|||
"\tbool isEnabled = getAcState();\n" +
|
||||
"\n" +
|
||||
"\tm_acEnabled = isEnabled;\n" +
|
||||
"auto [cltValid, clt] = Sensor::get(SensorType::Clt);\n" +
|
||||
"\n" +
|
||||
"\tenginePins.acRelay.setValue(isEnabled);\n" +
|
||||
"\n" +
|
||||
|
@ -37,7 +38,7 @@ public class LiveDataParserTest {
|
|||
"}\n";
|
||||
|
||||
SourceCodePainter painter = run(name -> null, sourceCode);
|
||||
verify(painter, times(4)).paintBackground(eq(CodeWalkthrough.ACTIVE_STATEMENT), any());
|
||||
verify(painter, times(7)).paintBackground(eq(CodeWalkthrough.ACTIVE_STATEMENT), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue