Loading EDG/src/main/java/edg/DotFactory.java +2 −1 Original line number Diff line number Diff line Loading @@ -178,9 +178,10 @@ public class DotFactory { this.edgeFilter = edgeFilter; } //private String getNodeLabel(Node node) { return String.format("Id = %d\n%s", node.getId(), node.getLabel()); } private String getNodeLabel(Node node) { return String.format("Id = %d\n%s", node.getId(), node.getLabel()); return String.format("Id = %d\nSDGId = %d\n%s", node.getId(), node.getSDGId(), node.getLabel()); } private String getEdgeLabel(Edge edge) Loading EDG/src/main/java/edg/EDGFactory.java +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ public class EDGFactory { nodeInfo.getLine(), nodeInfo.getConstruction()); // Result Node final Node result = new Node("result", edg.getNextFictitiousId(), Node.Type.Result, "", ldNodeInfo); final Node result = new Node("result", edg.getNextFictitiousId(), node.getSDGId(), Node.Type.Result, "", ldNodeInfo); final Node parent = last.getParent(node); Loading EDG/src/main/java/edg/LASTBuilder.java +19 −8 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ public class LASTBuilder { public static LAST createLAST(LDASTNodeInfo info) { final LAST last = new LAST(); final Node rootNode = new Node("LAST", last.getNextId(), Node.Type.Root, "LAST", info); final Node rootNode = new Node("LAST", last.getNextId(), last.getNextSDGId(), Node.Type.Root, "LAST", info); last.setRootNode(rootNode); Loading Loading @@ -56,13 +56,21 @@ public class LASTBuilder { throw new RuntimeException("A " + parentType + " cannot contain a clause"); final LDASTNodeInfo expInfo = new LDASTNodeInfo(info, true); last.unlockSDGid(); final Node clause = LASTBuilder.addNode(last, parent, Node.Type.Clause, "clause", expInfo); last.lockSDGid(); LASTBuilder.addNode(last, clause, Node.Type.ParameterIn, "paramIn", null); LASTBuilder.addNode(last, clause, Node.Type.Parameters, "parameters", null); // ADDED info to parameters to obtain the name of the class LASTBuilder.addNode(last, clause, Node.Type.Guard, "guard", null); LASTBuilder.addNode(last, clause, Node.Type.Body, "body", null); LASTBuilder.addNode(last, clause, Node.Type.ParameterOut, "paramOut", null); last.unlockSDGid(); return clause.getId(); } Loading Loading @@ -221,7 +229,9 @@ public class LASTBuilder { public static int addCall(LAST last, int parentId, Where where, LDASTNodeInfo info) { final Node parent = LASTBuilder.getParentNode(last, parentId, where); last.unlockSDGid(); final Node call = LASTBuilder.addNode(last, parent, Node.Type.Call, "call", info); last.lockSDGid(); final Node callee = LASTBuilder.addNode(last, call, Node.Type.Callee, "callee", info); LASTBuilder.addNode(last, callee, Node.Type.Scope, "scope", null); LASTBuilder.addNode(last, callee, Node.Type.Name, "name", null); Loading Loading @@ -362,7 +372,7 @@ public class LASTBuilder { private static Node addVariableNode(LAST last, Node parent, Node.Type type, String name, String varType, String text, LDASTNodeInfo info) { copyFileAndClass(last, parent, info); final Node node = new Variable(last.getNextId(), type, name, varType, info); final Node node = new Variable(last.getNextId(), last.getNextSDGId(), type, name, varType, info); node.setLabel(text); addNode(last, node, parent, Edge.Type.Structural); return node; Loading Loading @@ -985,20 +995,20 @@ public class LASTBuilder { switch(type) { case Variable: return new Variable(last.getNextId(), type, name, info); return new Variable(last.getNextId(), last.getNextSDGId(), type, name, info); case Result: final Node firstSibling = last.getChild(parent, 0); final Node.Type siblingType = firstSibling.getType(); switch(siblingType) { case Variable: return new Variable(last.getNextId(), type, name, info); return new Variable(last.getNextId(), last.getNextSDGId(), type, name, info); case Literal: case DataConstructorAccess: case DataConstructor: case Operation: default: return new Node(last.getNextId(), type, name, info); return new Node(last.getNextId(), last.getNextSDGId(), type, name, info); } case DefaultCase: Loading @@ -1012,19 +1022,20 @@ public class LASTBuilder { return new Node(last.getNextId(), type, name, info); case Callee: case Routine: case Clause: case Module: case Clause: case Return: case Continue: case Break: case Case: case CatchClause: case Callee: case ArgumentIn: case ArgumentOut: case Call: default: return new Node(last.getNextId(), type, name, info); return new Node(last.getNextId(), last.getNextSDGId(), type, name, info); } } Loading EDG/src/main/java/edg/LASTFactory.java +52 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,9 @@ public abstract class LASTFactory { final Branch parent = this.branches.peek(); final int parentId = parent.getNodeId(); boolean previousLockState = this.last.getLockState(); final int clauseId = LASTBuilder.addClause(this.last, parentId, info); final Branch branch = this.branches.push(new Branch(clauseId, Node.Type.Clause, info)); Loading @@ -152,6 +155,8 @@ public abstract class LASTFactory branch.setWhere(Where.Body); this.processElements(expressions); this.branches.pop(); this.last.setLockState(previousLockState); } protected void addVariable(String name, boolean declaration, boolean definition, boolean use, boolean global, LDASTNodeInfo info) Loading Loading @@ -187,10 +192,15 @@ public abstract class LASTFactory final Where where = parent.getWhere(); final int equalityId = LASTBuilder.addEquality(this.last, parentId, where, info); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); this.branches.push(new Branch(equalityId, Node.Type.Equality, info)); this.processElement(left, 1, 2); this.processElement(right, 2, 2); this.branches.pop(); last.setLockState(previousLockState); } protected <R, S> void addEquality(String operator, R left, S right, LDASTNodeInfo info) { Loading @@ -216,9 +226,14 @@ public abstract class LASTFactory final Where where = parent.getWhere(); final int operationId = LASTBuilder.addOperation(this.last, parentId, where, operation, info); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); this.branches.push(new Branch(operationId, Node.Type.Operation, info)); this.processElements(operands); this.branches.pop(); last.setLockState(previousLockState); } protected <R> void addUnaryOperation(String operation, R expression, LDASTNodeInfo info) { Loading Loading @@ -291,9 +306,14 @@ public abstract class LASTFactory final Where where = parent.getWhere(); final int dataConstructorId = LASTBuilder.addDataConstructor(this.last, parentId, where, info); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); this.branches.push(new Branch(dataConstructorId, Node.Type.DataConstructor, info)); this.processElements(elements); this.branches.pop(); last.setLockState(previousLockState); } protected <R> void addList(Iterable<R> elements, LDASTNodeInfo info) { Loading @@ -307,9 +327,14 @@ public abstract class LASTFactory final Where where = parent.getWhere(); final int listId = LASTBuilder.addList(this.last, parentId, where, info); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); this.branches.push(new Branch(listId, Node.Type.List, info)); this.processElements(elements); this.branches.pop(); this.last.setLockState(previousLockState); } protected <R, S> void addDataConstructorAccess(R dataConstructor, S access, LDASTNodeInfo info) { Loading Loading @@ -365,8 +390,11 @@ public abstract class LASTFactory final int ifId = LASTBuilder.addIf(this.last, parentId, where, info); final Branch branch = this.branches.push(new Branch(ifId, Node.Type.If, info)); this.last.lockSDGid(); branch.setWhere(Where.Condition); this.processElement(condition, 1, 1); this.last.unlockSDGid(); branch.setWhere(Where.Then); this.processElements(thenExpressions); branch.setWhere(Where.Else); Loading @@ -386,9 +414,14 @@ public abstract class LASTFactory final int switchId = LASTBuilder.addSwitch(this.last, parentId, where, info); final Branch branch = this.branches.push(new Branch(switchId, Node.Type.Switch, info)); this.last.lockSDGid(); branch.setWhere(Where.Selector); if (selector != null) this.processElement(selector, 1, 1); this.last.unlockSDGid(); branch.setWhere(Where.Cases); this.processElements(cases); this.branches.pop(); Loading Loading @@ -422,12 +455,17 @@ public abstract class LASTFactory final int caseId = LASTBuilder.addCase(this.last, parentId, info); final Branch branch = this.branches.push(new Branch(caseId, Node.Type.Case, info)); this.last.lockSDGid(); branch.setWhere(Where.Selectable); if (selectable != null) this.processElement(selectable, 1, 1); branch.setWhere(Where.Guard); if (guard != null) this.processElement(guard, 1, 1); this.last.unlockSDGid(); branch.setWhere(Where.Body); this.processElements(expressions); this.branches.pop(); Loading Loading @@ -470,6 +508,9 @@ public abstract class LASTFactory final Branch parent = this.branches.peek(); final int parentId = parent.getNodeId(); final Where where = parent.getWhere(); boolean previousLockState = last.getLockState(); final int callId = LASTBuilder.addCall(this.last, parentId, where, info); final Branch branch = this.branches.push(new Branch(callId, Node.Type.Call, info)); Loading @@ -479,12 +520,18 @@ public abstract class LASTFactory branch.setWhere(Where.Name); if (function != null) this.processElement(function, 2, 2); this.last.unlockSDGid(); branch.setWhere(Where.ArgumentIn); branch.setWhere(Where.Arguments); this.processElements(arguments); branch.setWhere(Where.ArgumentOut); this.branches.pop(); this.last.setLockState(previousLockState); } protected <R, S> void addListComprehension(Iterable<R> restrictions, S value, LDASTNodeInfo info) { Loading @@ -499,12 +546,17 @@ public abstract class LASTFactory final int listComprehensionId = LASTBuilder.addListComprehension(this.last, parentId, where, info); final Branch branch = this.branches.push(new Branch(listComprehensionId, Node.Type.ListComprehension, info)); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); branch.setWhere(Where.Restrictions); this.processElements(restrictions); branch.setWhere(Where.Value); if (value != null) this.processElement(value, 1, 1); this.branches.pop(); this.last.setLockState(previousLockState); } protected <R, S> void addGenerator(R left, S right, LDASTNodeInfo info) { Loading EDG/src/main/java/edg/graph/LAST.java +22 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ public class LAST extends GraphWithRoot { protected int nextId = 0; /** Id of the next fictitious node to be inserted */ protected int fictitiousId = -1; /** Id of the next SDG node to be inserted */ protected int nextSDGId = -1; /** Flag to Lock the SDGid when inserting some structures */ protected boolean lockedSDGId = false; /** Map connecting each node to its corresponding result node. */ private Map<Node, Node> resultFromNode = new HashMap<>(); /** Map connecting each result node to its corresponding node. */ Loading Loading @@ -783,6 +787,24 @@ public class LAST extends GraphWithRoot { return fictitiousId--; } /** Returns the id of the next inserted SDG node and update it */ public int getNextSDGId() { if (lockedSDGId) return nextSDGId; return ++nextSDGId; } public void lockSDGid() { lockedSDGId = true; } public void unlockSDGid() { lockedSDGId = false; } public boolean getLockState() { return lockedSDGId; } public void setLockState(boolean value) { lockedSDGId = value; } /** Returns the id of the current SDG node being inserted */ public int getCurrentSDGId() { return nextSDGId; } /** Returns the object variable node, if exists, of the scope of a function call * @implNote Only explicit object variables or casting expressions considered */ public Node getScopeLeaf(Node scopeNode) Loading Loading
EDG/src/main/java/edg/DotFactory.java +2 −1 Original line number Diff line number Diff line Loading @@ -178,9 +178,10 @@ public class DotFactory { this.edgeFilter = edgeFilter; } //private String getNodeLabel(Node node) { return String.format("Id = %d\n%s", node.getId(), node.getLabel()); } private String getNodeLabel(Node node) { return String.format("Id = %d\n%s", node.getId(), node.getLabel()); return String.format("Id = %d\nSDGId = %d\n%s", node.getId(), node.getSDGId(), node.getLabel()); } private String getEdgeLabel(Edge edge) Loading
EDG/src/main/java/edg/EDGFactory.java +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ public class EDGFactory { nodeInfo.getLine(), nodeInfo.getConstruction()); // Result Node final Node result = new Node("result", edg.getNextFictitiousId(), Node.Type.Result, "", ldNodeInfo); final Node result = new Node("result", edg.getNextFictitiousId(), node.getSDGId(), Node.Type.Result, "", ldNodeInfo); final Node parent = last.getParent(node); Loading
EDG/src/main/java/edg/LASTBuilder.java +19 −8 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ public class LASTBuilder { public static LAST createLAST(LDASTNodeInfo info) { final LAST last = new LAST(); final Node rootNode = new Node("LAST", last.getNextId(), Node.Type.Root, "LAST", info); final Node rootNode = new Node("LAST", last.getNextId(), last.getNextSDGId(), Node.Type.Root, "LAST", info); last.setRootNode(rootNode); Loading Loading @@ -56,13 +56,21 @@ public class LASTBuilder { throw new RuntimeException("A " + parentType + " cannot contain a clause"); final LDASTNodeInfo expInfo = new LDASTNodeInfo(info, true); last.unlockSDGid(); final Node clause = LASTBuilder.addNode(last, parent, Node.Type.Clause, "clause", expInfo); last.lockSDGid(); LASTBuilder.addNode(last, clause, Node.Type.ParameterIn, "paramIn", null); LASTBuilder.addNode(last, clause, Node.Type.Parameters, "parameters", null); // ADDED info to parameters to obtain the name of the class LASTBuilder.addNode(last, clause, Node.Type.Guard, "guard", null); LASTBuilder.addNode(last, clause, Node.Type.Body, "body", null); LASTBuilder.addNode(last, clause, Node.Type.ParameterOut, "paramOut", null); last.unlockSDGid(); return clause.getId(); } Loading Loading @@ -221,7 +229,9 @@ public class LASTBuilder { public static int addCall(LAST last, int parentId, Where where, LDASTNodeInfo info) { final Node parent = LASTBuilder.getParentNode(last, parentId, where); last.unlockSDGid(); final Node call = LASTBuilder.addNode(last, parent, Node.Type.Call, "call", info); last.lockSDGid(); final Node callee = LASTBuilder.addNode(last, call, Node.Type.Callee, "callee", info); LASTBuilder.addNode(last, callee, Node.Type.Scope, "scope", null); LASTBuilder.addNode(last, callee, Node.Type.Name, "name", null); Loading Loading @@ -362,7 +372,7 @@ public class LASTBuilder { private static Node addVariableNode(LAST last, Node parent, Node.Type type, String name, String varType, String text, LDASTNodeInfo info) { copyFileAndClass(last, parent, info); final Node node = new Variable(last.getNextId(), type, name, varType, info); final Node node = new Variable(last.getNextId(), last.getNextSDGId(), type, name, varType, info); node.setLabel(text); addNode(last, node, parent, Edge.Type.Structural); return node; Loading Loading @@ -985,20 +995,20 @@ public class LASTBuilder { switch(type) { case Variable: return new Variable(last.getNextId(), type, name, info); return new Variable(last.getNextId(), last.getNextSDGId(), type, name, info); case Result: final Node firstSibling = last.getChild(parent, 0); final Node.Type siblingType = firstSibling.getType(); switch(siblingType) { case Variable: return new Variable(last.getNextId(), type, name, info); return new Variable(last.getNextId(), last.getNextSDGId(), type, name, info); case Literal: case DataConstructorAccess: case DataConstructor: case Operation: default: return new Node(last.getNextId(), type, name, info); return new Node(last.getNextId(), last.getNextSDGId(), type, name, info); } case DefaultCase: Loading @@ -1012,19 +1022,20 @@ public class LASTBuilder { return new Node(last.getNextId(), type, name, info); case Callee: case Routine: case Clause: case Module: case Clause: case Return: case Continue: case Break: case Case: case CatchClause: case Callee: case ArgumentIn: case ArgumentOut: case Call: default: return new Node(last.getNextId(), type, name, info); return new Node(last.getNextId(), last.getNextSDGId(), type, name, info); } } Loading
EDG/src/main/java/edg/LASTFactory.java +52 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,9 @@ public abstract class LASTFactory { final Branch parent = this.branches.peek(); final int parentId = parent.getNodeId(); boolean previousLockState = this.last.getLockState(); final int clauseId = LASTBuilder.addClause(this.last, parentId, info); final Branch branch = this.branches.push(new Branch(clauseId, Node.Type.Clause, info)); Loading @@ -152,6 +155,8 @@ public abstract class LASTFactory branch.setWhere(Where.Body); this.processElements(expressions); this.branches.pop(); this.last.setLockState(previousLockState); } protected void addVariable(String name, boolean declaration, boolean definition, boolean use, boolean global, LDASTNodeInfo info) Loading Loading @@ -187,10 +192,15 @@ public abstract class LASTFactory final Where where = parent.getWhere(); final int equalityId = LASTBuilder.addEquality(this.last, parentId, where, info); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); this.branches.push(new Branch(equalityId, Node.Type.Equality, info)); this.processElement(left, 1, 2); this.processElement(right, 2, 2); this.branches.pop(); last.setLockState(previousLockState); } protected <R, S> void addEquality(String operator, R left, S right, LDASTNodeInfo info) { Loading @@ -216,9 +226,14 @@ public abstract class LASTFactory final Where where = parent.getWhere(); final int operationId = LASTBuilder.addOperation(this.last, parentId, where, operation, info); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); this.branches.push(new Branch(operationId, Node.Type.Operation, info)); this.processElements(operands); this.branches.pop(); last.setLockState(previousLockState); } protected <R> void addUnaryOperation(String operation, R expression, LDASTNodeInfo info) { Loading Loading @@ -291,9 +306,14 @@ public abstract class LASTFactory final Where where = parent.getWhere(); final int dataConstructorId = LASTBuilder.addDataConstructor(this.last, parentId, where, info); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); this.branches.push(new Branch(dataConstructorId, Node.Type.DataConstructor, info)); this.processElements(elements); this.branches.pop(); last.setLockState(previousLockState); } protected <R> void addList(Iterable<R> elements, LDASTNodeInfo info) { Loading @@ -307,9 +327,14 @@ public abstract class LASTFactory final Where where = parent.getWhere(); final int listId = LASTBuilder.addList(this.last, parentId, where, info); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); this.branches.push(new Branch(listId, Node.Type.List, info)); this.processElements(elements); this.branches.pop(); this.last.setLockState(previousLockState); } protected <R, S> void addDataConstructorAccess(R dataConstructor, S access, LDASTNodeInfo info) { Loading Loading @@ -365,8 +390,11 @@ public abstract class LASTFactory final int ifId = LASTBuilder.addIf(this.last, parentId, where, info); final Branch branch = this.branches.push(new Branch(ifId, Node.Type.If, info)); this.last.lockSDGid(); branch.setWhere(Where.Condition); this.processElement(condition, 1, 1); this.last.unlockSDGid(); branch.setWhere(Where.Then); this.processElements(thenExpressions); branch.setWhere(Where.Else); Loading @@ -386,9 +414,14 @@ public abstract class LASTFactory final int switchId = LASTBuilder.addSwitch(this.last, parentId, where, info); final Branch branch = this.branches.push(new Branch(switchId, Node.Type.Switch, info)); this.last.lockSDGid(); branch.setWhere(Where.Selector); if (selector != null) this.processElement(selector, 1, 1); this.last.unlockSDGid(); branch.setWhere(Where.Cases); this.processElements(cases); this.branches.pop(); Loading Loading @@ -422,12 +455,17 @@ public abstract class LASTFactory final int caseId = LASTBuilder.addCase(this.last, parentId, info); final Branch branch = this.branches.push(new Branch(caseId, Node.Type.Case, info)); this.last.lockSDGid(); branch.setWhere(Where.Selectable); if (selectable != null) this.processElement(selectable, 1, 1); branch.setWhere(Where.Guard); if (guard != null) this.processElement(guard, 1, 1); this.last.unlockSDGid(); branch.setWhere(Where.Body); this.processElements(expressions); this.branches.pop(); Loading Loading @@ -470,6 +508,9 @@ public abstract class LASTFactory final Branch parent = this.branches.peek(); final int parentId = parent.getNodeId(); final Where where = parent.getWhere(); boolean previousLockState = last.getLockState(); final int callId = LASTBuilder.addCall(this.last, parentId, where, info); final Branch branch = this.branches.push(new Branch(callId, Node.Type.Call, info)); Loading @@ -479,12 +520,18 @@ public abstract class LASTFactory branch.setWhere(Where.Name); if (function != null) this.processElement(function, 2, 2); this.last.unlockSDGid(); branch.setWhere(Where.ArgumentIn); branch.setWhere(Where.Arguments); this.processElements(arguments); branch.setWhere(Where.ArgumentOut); this.branches.pop(); this.last.setLockState(previousLockState); } protected <R, S> void addListComprehension(Iterable<R> restrictions, S value, LDASTNodeInfo info) { Loading @@ -499,12 +546,17 @@ public abstract class LASTFactory final int listComprehensionId = LASTBuilder.addListComprehension(this.last, parentId, where, info); final Branch branch = this.branches.push(new Branch(listComprehensionId, Node.Type.ListComprehension, info)); boolean previousLockState = last.getLockState(); this.last.lockSDGid(); branch.setWhere(Where.Restrictions); this.processElements(restrictions); branch.setWhere(Where.Value); if (value != null) this.processElement(value, 1, 1); this.branches.pop(); this.last.setLockState(previousLockState); } protected <R, S> void addGenerator(R left, S right, LDASTNodeInfo info) { Loading
EDG/src/main/java/edg/graph/LAST.java +22 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ public class LAST extends GraphWithRoot { protected int nextId = 0; /** Id of the next fictitious node to be inserted */ protected int fictitiousId = -1; /** Id of the next SDG node to be inserted */ protected int nextSDGId = -1; /** Flag to Lock the SDGid when inserting some structures */ protected boolean lockedSDGId = false; /** Map connecting each node to its corresponding result node. */ private Map<Node, Node> resultFromNode = new HashMap<>(); /** Map connecting each result node to its corresponding node. */ Loading Loading @@ -783,6 +787,24 @@ public class LAST extends GraphWithRoot { return fictitiousId--; } /** Returns the id of the next inserted SDG node and update it */ public int getNextSDGId() { if (lockedSDGId) return nextSDGId; return ++nextSDGId; } public void lockSDGid() { lockedSDGId = true; } public void unlockSDGid() { lockedSDGId = false; } public boolean getLockState() { return lockedSDGId; } public void setLockState(boolean value) { lockedSDGId = value; } /** Returns the id of the current SDG node being inserted */ public int getCurrentSDGId() { return nextSDGId; } /** Returns the object variable node, if exists, of the scope of a function call * @implNote Only explicit object variables or casting expressions considered */ public Node getScopeLeaf(Node scopeNode) Loading