Commit f372e991 authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Adding warning for non reachable states

parent fa4a7a8a
This diff is collapsed.
......@@ -58,7 +58,8 @@ public class AvatarError {
"No signal of that name in block",
"State machine must terminate with a (stop) state",
"ASM operator has not next operator",
"Empty state machine"
"Empty state machine",
"Unused elements in state machine"
};
......
......@@ -2199,4 +2199,50 @@ public class AvatarStateMachine extends AvatarElement {
return;
}
// Returns the list of elements non reachabable from the start state
public List<AvatarStateMachineElement> getUnusedElements() {
if (startState == null) {
return null;
}
List<AvatarStateMachineElement> elts = new LinkedList<>();
HashSet<AvatarStateMachineElement> found = new HashSet<>();
findAvatarElements(startState, found);
for(AvatarStateMachineElement asme: elements) {
if (!(found.contains(asme))) {
elts.add(asme);
}
}
return elts;
}
private void findAvatarElements(AvatarStateMachineElement first, HashSet<AvatarStateMachineElement> found) {
if (found.contains(first)) {
return;
}
found.add(first);
if (first instanceof AvatarState) {
// Find all internal start states of this state
for(AvatarStateMachineElement internal: elements) {
if (internal instanceof AvatarStartState) {
if (internal.getState() == first) {
findAvatarElements(internal, found);
}
}
}
}
for(AvatarStateMachineElement asme: first.getNexts()) {
findAvatarElements(asme, found);
}
}
}
......@@ -40,6 +40,7 @@ package avatartranslator;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import compiler.tmlparser.ParseException;
......@@ -61,11 +62,13 @@ import myutil.TraceManager;
*/
public class AvatarSyntaxChecker {
private final static int UNUSED_ELEMENT = 10;
public AvatarSyntaxChecker() {
}
public static ArrayList<AvatarError> checkSyntax(AvatarSpecification avspec) {
public static ArrayList<AvatarError> checkSyntaxErrors(AvatarSpecification avspec) {
ArrayList<AvatarError> errors = new ArrayList<>();
errors.addAll(checkNextASMSpec(avspec));
......@@ -75,6 +78,47 @@ public class AvatarSyntaxChecker {
return errors;
}
public static ArrayList<AvatarError> checkSyntaxWarnings(AvatarSpecification avspec) {
ArrayList<AvatarError> warnings = new ArrayList<>();
warnings.addAll(checkIsolatedElements(avspec));
return warnings;
}
public static ArrayList<AvatarError> checkIsolatedElements(AvatarSpecification avspec) {
ArrayList<AvatarError> warnings = new ArrayList<>();
for(AvatarBlock ab: avspec.getListOfBlocks()) {
warnings.addAll(checkIsolatedElements(avspec, ab));
}
return warnings;
}
public static ArrayList<AvatarError> checkIsolatedElements(AvatarSpecification avspec, AvatarBlock ab) {
ArrayList<AvatarError> warnings = new ArrayList<>();
AvatarStateMachine asm = ab.getStateMachine();
if (asm == null) {
return warnings;
}
List<AvatarStateMachineElement> unused = asm.getUnusedElements();
if (unused != null) {
for(AvatarStateMachineElement asme: unused) {
AvatarError warning = new AvatarError(avspec);
warning.firstAvatarElement = asme;
warning.secondAvatarElement = ab;
warning.error = UNUSED_ELEMENT;
warnings.add(warning);
}
}
return warnings;
}
public static ArrayList<AvatarError> checkNextASMSpec(AvatarSpecification avspec) {
ArrayList<AvatarError> errors = new ArrayList<>();
......
......@@ -38,7 +38,6 @@
package ui;
import attacktrees.Attack;
import attacktrees.AttackTree;
import attacktrees.AttackerPopulation;
import avatartranslator.*;
......@@ -9026,7 +9025,7 @@ public class GTURTLEModeling {
// Check Errors in AVSPEC
TraceManager.addDev("Checking syntax of avatar spec.");
ArrayList<AvatarError> list = AvatarSyntaxChecker.checkSyntax(avspec);
ArrayList<AvatarError> list = AvatarSyntaxChecker.checkSyntaxErrors(avspec);
for (AvatarError error : list) {
TraceManager.addDev("Error: " + error.toString());
}
......@@ -9239,7 +9238,7 @@ public class GTURTLEModeling {
// Check Errors in AVSPEC
TraceManager.addDev("Checking syntax of avatar spec.");
ArrayList<AvatarError> list = AvatarSyntaxChecker.checkSyntax(avspec);
ArrayList<AvatarError> list = AvatarSyntaxChecker.checkSyntaxErrors(avspec);
for (AvatarError error : list) {
TraceManager.addDev("Error: " + error.toString());
}
......
......@@ -679,7 +679,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
sb.append(tgc.saveInXML());
sb.append("\n");
sb.append(getXMLCloneTail());
TraceManager.addDev("sb=\n" + sb);
//TraceManager.addDev("sb=\n" + sb);
return sb;
}
......@@ -714,7 +714,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
cpt ++;
}
if (cloneEvenIfNonNullFather) {
TraceManager.addDev("sb=\n" + sb);
//TraceManager.addDev("sb=\n" + sb);
}
return sb;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment