Commit 4197f43b authored by Sarah Grebing's avatar Sarah Grebing

interim state for stategraphwrapper and cfg

parent 2577adfe
Pipeline #14968 failed with stage
in 1 minute and 55 seconds
...@@ -25,6 +25,7 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -25,6 +25,7 @@ package edu.kit.iti.formal.psdbg.parser.ast;
import edu.kit.iti.formal.psdbg.parser.Visitable; import edu.kit.iti.formal.psdbg.parser.Visitable;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;
...@@ -32,6 +33,7 @@ import org.antlr.v4.runtime.ParserRuleContext; ...@@ -32,6 +33,7 @@ import org.antlr.v4.runtime.ParserRuleContext;
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (27.04.17) * @version 1 (27.04.17)
*/ */
@EqualsAndHashCode
public abstract class ASTNode<T extends ParserRuleContext> public abstract class ASTNode<T extends ParserRuleContext>
implements Visitable, Copyable<ASTNode<T>> { implements Visitable, Copyable<ASTNode<T>> {
/** /**
......
...@@ -36,11 +36,13 @@ import lombok.*; ...@@ -36,11 +36,13 @@ import lombok.*;
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (28.04.17) * @version 1 (28.04.17)
*/ */
@Data
@ToString(includeFieldNames = true) @ToString(includeFieldNames = true)
@NoArgsConstructor @NoArgsConstructor
@RequiredArgsConstructor() @RequiredArgsConstructor()
@AllArgsConstructor @AllArgsConstructor
@Getter
@Setter
public class AssignmentStatement public class AssignmentStatement
extends Statement<ScriptLanguageParser.AssignmentContext> { extends Statement<ScriptLanguageParser.AssignmentContext> {
@NonNull @NonNull
......
...@@ -34,7 +34,8 @@ import lombok.*; ...@@ -34,7 +34,8 @@ import lombok.*;
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (28.04.17) * @version 1 (28.04.17)
*/ */
@Data @Getter
@Setter
@NoArgsConstructor @NoArgsConstructor
@RequiredArgsConstructor @RequiredArgsConstructor
@AllArgsConstructor @AllArgsConstructor
......
...@@ -23,19 +23,20 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -23,19 +23,20 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/ */
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser; import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter;
/** /**
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (28.04.17) * @version 1 (28.04.17)
*/ */
@Data @Getter
@NoArgsConstructor @Setter
@RequiredArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class CaseStatement extends Statement<ScriptLanguageParser.CasesListContext> { public class CaseStatement extends Statement<ScriptLanguageParser.CasesListContext> {
public boolean isClosedStmt; public boolean isClosedStmt;
......
...@@ -23,11 +23,12 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -23,11 +23,12 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/ */
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser; import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -36,7 +37,9 @@ import java.util.List; ...@@ -36,7 +37,9 @@ import java.util.List;
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (28.04.17) * @version 1 (28.04.17)
*/ */
@Data @Setter
@Getter
@RequiredArgsConstructor
public class CasesStatement extends Statement<ScriptLanguageParser.CasesStmtContext> { public class CasesStatement extends Statement<ScriptLanguageParser.CasesStmtContext> {
@NonNull private final List<CaseStatement> cases = new ArrayList<>(); @NonNull private final List<CaseStatement> cases = new ArrayList<>();
// @NonNull private Statements defaultCase = new Statements(); // @NonNull private Statements defaultCase = new Statements();
......
...@@ -2,9 +2,11 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -2,9 +2,11 @@ package edu.kit.iti.formal.psdbg.parser.ast;
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser; import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data; import lombok.Getter;
import lombok.Setter;
@Data @Getter
@Setter
public class DefaultCaseStatement extends Statement<ScriptLanguageParser.StmtListContext> { public class DefaultCaseStatement extends Statement<ScriptLanguageParser.StmtListContext> {
protected Statements body; protected Statements body;
......
...@@ -23,16 +23,17 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -23,16 +23,17 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/ */
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser; import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data; import lombok.Getter;
import lombok.Setter;
/** /**
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (29.04.17) * @version 1 (29.04.17)
*/ */
@Data @Getter
@Setter
public class ForeachStatement extends GoalSelector<ScriptLanguageParser.ForEachStmtContext> { public class ForeachStatement extends GoalSelector<ScriptLanguageParser.ForEachStmtContext> {
public ForeachStatement() { public ForeachStatement() {
} }
......
...@@ -31,7 +31,13 @@ import org.antlr.v4.runtime.ParserRuleContext; ...@@ -31,7 +31,13 @@ import org.antlr.v4.runtime.ParserRuleContext;
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (29.04.17) * @version 1 (29.04.17)
*/ */
@Data @AllArgsConstructor @NoArgsConstructor public abstract class GoalSelector<T extends ParserRuleContext> @Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public abstract class GoalSelector<T extends ParserRuleContext>
extends Statement<T> { extends Statement<T> {
@Getter
@Setter
@NonNull private Statements body = new Statements(); @NonNull private Statements body = new Statements();
} }
...@@ -23,16 +23,17 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -23,16 +23,17 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/ */
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser; import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data; import lombok.Getter;
import lombok.Setter;
/** /**
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (29.04.17) * @version 1 (29.04.17)
*/ */
@Data @Getter
@Setter
public class RepeatStatement extends GoalSelector<ScriptLanguageParser.RepeatStmtContext> { public class RepeatStatement extends GoalSelector<ScriptLanguageParser.RepeatStmtContext> {
public RepeatStatement() { public RepeatStatement() {
} }
......
...@@ -23,11 +23,9 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -23,11 +23,9 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/ */
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser; import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitable; import edu.kit.iti.formal.psdbg.parser.Visitable;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import java.util.*; import java.util.*;
...@@ -40,7 +38,6 @@ import java.util.stream.Stream; ...@@ -40,7 +38,6 @@ import java.util.stream.Stream;
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (27.04.17) * @version 1 (27.04.17)
*/ */
@EqualsAndHashCode
@ToString @ToString
public class Statements extends ASTNode<ScriptLanguageParser.StmtListContext> public class Statements extends ASTNode<ScriptLanguageParser.StmtListContext>
implements Visitable, Iterable<Statement> { implements Visitable, Iterable<Statement> {
...@@ -182,4 +179,5 @@ public class Statements extends ASTNode<ScriptLanguageParser.StmtListContext> ...@@ -182,4 +179,5 @@ public class Statements extends ASTNode<ScriptLanguageParser.StmtListContext>
s.setRuleContext(this.getRuleContext()); s.setRuleContext(this.getRuleContext());
return s; return s;
} }
} }
...@@ -23,16 +23,17 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -23,16 +23,17 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/ */
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser; import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data; import lombok.Getter;
import lombok.Setter;
/** /**
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (29.04.17) * @version 1 (29.04.17)
*/ */
@Data @Getter
@Setter
public class TheOnlyStatement extends GoalSelector<ScriptLanguageParser.TheOnlyStmtContext> { public class TheOnlyStatement extends GoalSelector<ScriptLanguageParser.TheOnlyStmtContext> {
public TheOnlyStatement() { public TheOnlyStatement() {
} }
......
...@@ -7,6 +7,7 @@ import edu.kit.iti.formal.psdbg.interpreter.funchdl.CommandLookup; ...@@ -7,6 +7,7 @@ import edu.kit.iti.formal.psdbg.interpreter.funchdl.CommandLookup;
import edu.kit.iti.formal.psdbg.interpreter.funchdl.ProofScriptHandler; import edu.kit.iti.formal.psdbg.interpreter.funchdl.ProofScriptHandler;
import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor; import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor;
import edu.kit.iti.formal.psdbg.parser.ast.*; import edu.kit.iti.formal.psdbg.parser.ast.*;
import javafx.util.Pair;
import java.util.*; import java.util.*;
...@@ -44,6 +45,12 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -44,6 +45,12 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
mappingOfNodes = new HashMap<>(); mappingOfNodes = new HashMap<>();
} }
/**
* Return all nodes that have the parameter node as target in the graph
*
* @param node
* @return
*/
public Set<EndpointPair<ControlFlowNode>> getAllEdgesForNodeAsTarget(ASTNode node) { public Set<EndpointPair<ControlFlowNode>> getAllEdgesForNodeAsTarget(ASTNode node) {
...@@ -55,9 +62,9 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -55,9 +62,9 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
if (e.target().equals(assocNode)) { if (e.target().equals(assocNode)) {
edges.add(e); edges.add(e);
System.out.println(e.target()); //System.out.println(e.target());
System.out.println(e.source()); //System.out.println(e.source());
System.out.println(graph.edgeValue(e.target(), e.source())); //System.out.println(graph.edgeValue(e.target(), e.source()));
} }
}); });
return edges; return edges;
...@@ -66,6 +73,54 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -66,6 +73,54 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
} }
} }
public Collection<Pair<ControlFlowNode, EdgeTypes>> getPredecessorsAndTheirEdges(ASTNode node) {
ControlFlowNode assocNode = getCorrespondingNode(node);
List<Pair<ControlFlowNode, EdgeTypes>> allPreds = new LinkedList<>();
if (assocNode != null) {
graph.edges().forEach(edge -> {
if (edge.target().equals(assocNode)) {
allPreds.add(new Pair(edge.source(), edge));
}
});
return allPreds;
} else {
return Collections.EMPTY_LIST;
}
}
public ControlFlowNode getCorrespondingNode(ASTNode node) {
ControlFlowNode ctrl = null;
for (ASTNode astNode : mappingOfNodes.keySet()) {
if (astNode.getStartPosition().equals(node.getStartPosition())
&& astNode.getEndPosition().equals(node.getEndPosition())) {
ctrl = mappingOfNodes.get(astNode);
break;
}
}
return ctrl;
}
public Collection<Pair<ControlFlowNode, EdgeTypes>> getPredecessorsAsTarget(ASTNode node) {
ControlFlowNode assocNode = getCorrespondingNode(node);
List<Pair<ControlFlowNode, EdgeTypes>> allPreds = new LinkedList<>();
if (assocNode != null) {
graph.edges().forEach(edge -> {
if (edge.source().equals(assocNode)) {
allPreds.add(new Pair(edge.target(), edge));
}
});
return allPreds;
} else {
return Collections.EMPTY_LIST;
}
}
@Override @Override
public Void visit(ProofScript proofScript) { public Void visit(ProofScript proofScript) {
...@@ -111,6 +166,7 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> { ...@@ -111,6 +166,7 @@ public class ControlFlowVisitor extends DefaultASTVisitor<Void> {
} }
mappingOfNodes.put(call, currentNode); mappingOfNodes.put(call, currentNode);
graph.addNode(currentNode); graph.addNode(currentNode);
graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER); graph.putEdgeValue(lastNode, currentNode, EdgeTypes.STEP_OVER);
graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK); graph.putEdgeValue(currentNode, lastNode, EdgeTypes.STEP_BACK);
......
...@@ -14,6 +14,7 @@ import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor; ...@@ -14,6 +14,7 @@ import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor;
import edu.kit.iti.formal.psdbg.parser.ast.*; import edu.kit.iti.formal.psdbg.parser.ast.*;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.util.Pair;
import lombok.Getter; import lombok.Getter;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -260,7 +261,8 @@ public class StateGraphWrapper<T> { ...@@ -260,7 +261,8 @@ public class StateGraphWrapper<T> {
}); });
extState.setMappingOfCaseToStates(mappingOfCaseToStates); extState.setMappingOfCaseToStates(mappingOfCaseToStates);
//TODO default case //TODO default case: missing datastructure of supertype CaseStatement at the moment
newStateNode.setState(lastState.copy()); newStateNode.setState(lastState.copy());
} else { } else {
...@@ -278,9 +280,25 @@ public class StateGraphWrapper<T> { ...@@ -278,9 +280,25 @@ public class StateGraphWrapper<T> {
} }
newStateNode.setExtendedState(extState); newStateNode.setExtendedState(extState);
stateGraph.addNode(newStateNode); stateGraph.addNode(newStateNode);
Collection<Pair<ControlFlowNode, EdgeTypes>> predecessorsAndTheirEdges = cfgVisitor.getPredecessorsAndTheirEdges(newStateNode.getScriptstmt());
for (Pair<ControlFlowNode, EdgeTypes> predecessorsAndTheirEdge : predecessorsAndTheirEdges) {
if (predecessorsAndTheirEdge.getKey().equals(lastNode.getScriptstmt())) {
stateGraph.putEdgeValue(lastNode, newStateNode, predecessorsAndTheirEdge.getValue());
}
}
Collection<Pair<ControlFlowNode, EdgeTypes>> predecessorsAsTarget = cfgVisitor.getPredecessorsAsTarget(node);
for (Pair<ControlFlowNode, EdgeTypes> predecessorAsTarget : predecessorsAsTarget) {
if (predecessorAsTarget.getKey().equals(lastNode.getScriptstmt())) {
stateGraph.putEdgeValue(newStateNode, lastNode, predecessorAsTarget.getValue());
}
}
stateGraph.putEdgeValue(lastNode, newStateNode, EdgeTypes.STATE_FLOW); stateGraph.putEdgeValue(lastNode, newStateNode, EdgeTypes.STATE_FLOW);
//inform listeners about a new node in the graph //inform listeners about a new node in the graph
...@@ -324,18 +342,17 @@ public class StateGraphWrapper<T> { ...@@ -324,18 +342,17 @@ public class StateGraphWrapper<T> {
return null; return null;
} }
private void fireStateAdded(StateAddedEvent stateAddedEvent) { private void fireNodeAdded(NodeAddedEvent nodeAddedEvent) {
changeListeners.forEach(list -> Platform.runLater(() -> { changeListeners.forEach(list -> Platform.runLater(() -> {
list.graphChanged(stateAddedEvent); list.graphChanged(nodeAddedEvent);
// LOGGER.debug("New StateGraphChange " + this.asdot()); LOGGER.info("New StateGraphChange \n" + this.asdot() + "\n");
})); }));
} }
private void fireNodeAdded(NodeAddedEvent nodeAddedEvent) { private void fireStateAdded(StateAddedEvent stateAddedEvent) {
changeListeners.forEach(list -> Platform.runLater(() -> { changeListeners.forEach(list -> Platform.runLater(() -> {
list.graphChanged(nodeAddedEvent); list.graphChanged(stateAddedEvent);
//TODO LOGGER.debug("New StateGraphChange " + this.asdot());
// LOGGER.info("New StateGraphChange \n%%%%%%" + this.asdot() + "\n%%%%%%%");
})); }));
} }
......
...@@ -7,10 +7,15 @@ cases{ ...@@ -7,10 +7,15 @@ cases{
case match `q==>`: case match `q==>`:
impRight; impRight;
notRight; notRight;
case match `==>`: case match `==>`:
impRight; impRight;
notRight; notRight;
close;
} }
auto;
} }
...@@ -31,7 +36,7 @@ cases{ ...@@ -31,7 +36,7 @@ cases{
impRight; impRight;
} }
}
script test2(){ script test2(){
impRight; impRight;
......
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