Commit b5c97400 authored by Lulu Luong's avatar Lulu Luong

PlaceholderNode

TODO: Bugfix foreach and closed goals
parent dfa4eeca
Pipeline #26963 passed with stages
in 2 minutes and 52 seconds
...@@ -62,7 +62,7 @@ public class ScriptTreeGraph { ...@@ -62,7 +62,7 @@ public class ScriptTreeGraph {
computeList(); computeList();
compute(); compute();
addGoals(); addGoals();
addParentsAndChildren(); // TODO: replace addParentsAndChildren() with placeholders;
mapping.size(); mapping.size();
...@@ -271,16 +271,16 @@ public class ScriptTreeGraph { ...@@ -271,16 +271,16 @@ public class ScriptTreeGraph {
@Override @Override
public Void visit(CallStatement call) { public Void visit(CallStatement call) {
if (nextPtreeNode.toString().equals("End of Script")) return null; if (nextPtreeNode.toString().equals("End of Script")) return null;
Node n = nextPtreeNode.getStateBeforeStmt().getSelectedGoalNode().getData().getNode(); Node callnode = nextPtreeNode.getStateBeforeStmt().getSelectedGoalNode().getData().getNode();
ScriptTreeNode sn = new ScriptTreeNode(n, nextPtreeNode, nextPtreeNode.getStatement().getStartPosition().getLineNumber()); ScriptTreeNode sn = new ScriptTreeNode(callnode, nextPtreeNode, nextPtreeNode.getStatement().getStartPosition().getLineNumber());
//check if statement was applicable //check if statement was applicable
if (nextPtreeNode.getStateBeforeStmt() == nextPtreeNode.getStateAfterStmt()) { if (nextPtreeNode.getStateBeforeStmt() == nextPtreeNode.getStateAfterStmt()) {
sn.setSucc(false); sn.setSucc(false);
} }
replacePlaceholder(n, sn); replacePlaceholder(callnode, sn);
putIntoMapping(n, sn); putIntoMapping(callnode, sn);
front.remove(n); front.remove(callnode);
List<GoalNode<KeyData>> children = nextPtreeNode.getStateAfterStmt().getGoals(); List<GoalNode<KeyData>> children = nextPtreeNode.getStateAfterStmt().getGoals();
...@@ -288,18 +288,18 @@ public class ScriptTreeGraph { ...@@ -288,18 +288,18 @@ public class ScriptTreeGraph {
switch (children.size()) { switch (children.size()) {
case 0: case 0:
putIntoFront(n); putIntoFront(callnode);
checkIfForeachEnd(n); checkIfForeachEnd(callnode);
break; break;
case 1: case 1:
// putIntoMapping(children.get(0).getData().getNode(), null); // putIntoMapping(children.get(0).getData().getNode(), null);
putIntoFront(children.get(0).getData().getNode()); putIntoFront(children.get(0).getData().getNode());
addPlaceholder(n, children.get(0).getData().getNode()); addPlaceholder(sn, children.get(0).getData().getNode(), false);
break; break;
default: //multiple open goals/children -> branch labels default: //multiple open goals/children -> branch labels
int branchcounter = 1; int branchcounter = 1;
for (GoalNode<KeyData> gn : children) { for (GoalNode<KeyData> gn : children) {
Node node = gn.getData().getNode(); Node childnode = gn.getData().getNode();
List<BranchLabelNode> branchlabel = getBranchLabels(nextPtreeNode.getStateBeforeStmt().getSelectedGoalNode(), gn); List<BranchLabelNode> branchlabel = getBranchLabels(nextPtreeNode.getStateBeforeStmt().getSelectedGoalNode(), gn);
...@@ -309,17 +309,23 @@ public class ScriptTreeGraph { ...@@ -309,17 +309,23 @@ public class ScriptTreeGraph {
System.out.println("_______Branchlabels"); System.out.println("_______Branchlabels");
Lists.reverse(branchlabel).forEach(k -> System.out.println(k.getNode().serialNr() + " " + k.getLabelName())); Lists.reverse(branchlabel).forEach(k -> System.out.println(k.getNode().serialNr() + " " + k.getLabelName()));
insertBranchLabels(n, branchlabel); insertBranchLabels(callnode, branchlabel);
addPlaceholder(branchlabel.get(0).getNode(), gn.getData().getNode()); addPlaceholder(branchlabel.get(0), gn.getData().getNode(), true);
} else { } else {
BranchLabelNode branchNode = new BranchLabelNode(node, "Case " + branchcounter); BranchLabelNode branchNode = new BranchLabelNode(childnode, "Case " + branchcounter);
putIntoMapping(node, branchNode);
addPlaceholder(n, gn.getData().getNode()); // Link Case -Branchnodes to parent
branchNode.setParent(sn);
addToChildren(callnode, branchNode);
if (mapping.get(childnode) != null) putIntoMapping(childnode, branchNode);
addPlaceholder(branchNode, childnode, true);
branchcounter++; branchcounter++;
} }
putIntoFront(node); putIntoFront(childnode);
} }
} }
...@@ -338,14 +344,15 @@ public class ScriptTreeGraph { ...@@ -338,14 +344,15 @@ public class ScriptTreeGraph {
match.setMatchEx(true); match.setMatchEx(true);
// check if match was sucessful
if (nextintoptn == null) { if (nextintoptn == null) {
match.setSucc(false); match.setSucc(false);
return null;
} }
Node n = nextintoptn.getStateBeforeStmt().getSelectedGoalNode().getData().getNode(); Node n = nextPtreeNode.getStateBeforeStmt().getSelectedGoalNode().getData().getNode();
replacePlaceholder(n, match); replacePlaceholder(n, match);
putIntoMapping(n, match); putIntoMapping(n, match);
addPlaceholder(n, n); addPlaceholder(match, n, false);
//front.remove(n); //front.remove(n);
return null; return null;
} }
...@@ -359,7 +366,7 @@ public class ScriptTreeGraph { ...@@ -359,7 +366,7 @@ public class ScriptTreeGraph {
Node n = nextintoptn.getStateBeforeStmt().getSelectedGoalNode().getData().getNode(); Node n = nextintoptn.getStateBeforeStmt().getSelectedGoalNode().getData().getNode();
replacePlaceholder(n, match); replacePlaceholder(n, match);
putIntoMapping(n, match); putIntoMapping(n, match);
addPlaceholder(n, n); addPlaceholder(match, n, false);
//front.remove(n); //front.remove(n);
return null; return null;
} }
...@@ -383,28 +390,37 @@ public class ScriptTreeGraph { ...@@ -383,28 +390,37 @@ public class ScriptTreeGraph {
} }
} }
private void addPlaceholder(Node parent, Node current) { private void addPlaceholder(AbstractTreeNode parent, Node current, boolean isSplit) {
PlaceholderNode phn = new PlaceholderNode(current); PlaceholderNode phn = new PlaceholderNode(current);
phn.setParent(mapping.get(parent)); phn.setParent(parent);
//TODO or addtosubchildren
addToChildren(parent, phn); if(mapping.get(current) == null) {
if(mapping.get(current) == null) putIntoMapping(current, phn); putIntoMapping(current, phn);
addToSubChildren(parent, phn); } else {
addToSubChildren(parent.getNode(), phn);
}
placeholderNodes.add(phn); placeholderNodes.add(phn);
} }
private void replacePlaceholder(Node n, AbstractTreeNode atn) { private void replacePlaceholder(Node n, AbstractTreeNode atn) {
placeholderNodes.forEach(k -> {
if (k.getNode() == n) {
Iterator<PlaceholderNode> iterator = placeholderNodes.iterator();
while (iterator.hasNext()) {
PlaceholderNode next = iterator.next();
if (next.getNode() == n) {
//search for placeholder in mapping //search for placeholder in mapping
AbstractTreeNode current = mapping.get(n); AbstractTreeNode current = mapping.get(n);
if (current instanceof PlaceholderNode ) { if (current instanceof PlaceholderNode ) {
//TODO : atn.setParent(current.getParent()); -> leads to concurretn exception //TODO : atn.setParent(current.getParent()); -> leads to concurretn exception
current.getParent().setChildren(new ArrayList<>(Arrays.asList(atn))); current.getParent().setChildren(new ArrayList<>(Arrays.asList(atn)));
//placeholderNodes.remove(k); TODO: ConcurrentModificationException mapping.put(n, atn);
iterator.remove();
return; return;
} }
...@@ -417,13 +433,13 @@ public class ScriptTreeGraph { ...@@ -417,13 +433,13 @@ public class ScriptTreeGraph {
//TODO: insert a variable instead of using atn? //TODO: insert a variable instead of using atn?
atn.setParent(current.getChildren().get(0).getParent()); atn.setParent(current.getChildren().get(0).getParent());
current.setChildren(new ArrayList<>(Arrays.asList(atn))); current.setChildren(new ArrayList<>(Arrays.asList(atn)));
placeholderNodes.remove(k); iterator.remove();
return; return;
} }
current = current.getChildren().get(0); current = current.getChildren().get(0);
} }
} }
}); };
return; return;
} }
...@@ -579,7 +595,7 @@ public class ScriptTreeGraph { ...@@ -579,7 +595,7 @@ public class ScriptTreeGraph {
} }
private void addGoals() { private void addGoals() {
front.forEach(k -> addToSubChildren(searchParentInMapping(k), new DummyGoalNode(k, k.isClosed()))); front.forEach(k -> replacePlaceholder(k, new DummyGoalNode(k, k.isClosed())));
} }
private String getMappingString (AbstractTreeNode node){ private String getMappingString (AbstractTreeNode node){
......
script full0(){
impRight;
impRight;
impLeft;
cases {
case match `!q ==> p`:
notLeft;
case match `q==>!p`:
notLeft;
}
}
script full(){ script full(){
impRight; impRight;
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