diff --git a/reusablecfg/src/main/jastadd/CFG.relast b/reusablecfg/src/main/jastadd/CFG.relast index b1e7cbe5349021cc8790f4a6ee2613ee6b1eb168..7a5954271589c595bfb40da49abb70fdcda4b871 100644 --- a/reusablecfg/src/main/jastadd/CFG.relast +++ b/reusablecfg/src/main/jastadd/CFG.relast @@ -28,6 +28,7 @@ CfgMethodCall : CfgNode; /** A conditional branch in the CFG. */ CfgBranch : CfgNode; +rel CfgBranch.hostStatement -> Stmt; /** A branch in the CFG caused by potential thrown exceptions. */ CfgException : CfgNode; diff --git a/reusablecfg/src/main/jastadd/SimpleCFG.jrag b/reusablecfg/src/main/jastadd/SimpleCFG.jrag index bd39ef70271b801e0b1efc9e130a6426c9156321..40c66bc631ddee8defad7591355ab8d4bda61efa 100644 --- a/reusablecfg/src/main/jastadd/SimpleCFG.jrag +++ b/reusablecfg/src/main/jastadd/SimpleCFG.jrag @@ -440,7 +440,11 @@ aspect SimpleCFG { eq Dot.getLeft().follow() = getRight().entry(); /** The branch node for this conditional expression. */ - syn nta CfgBranch ConditionalExpr.branch() = new CfgBranch(); + syn nta CfgBranch ConditionalExpr.branch() { + CfgBranch branch = new CfgBranch(); + branch.setHostStatement(hostStatement()); + return branch; + } /** * The then-end node is a marker node marking the end of a then-branch in a conditional @@ -467,7 +471,11 @@ aspect SimpleCFG { smallSet(getTrueExpr().entry(), getFalseExpr().entry()); /** The branch node for this statement. */ - syn nta CfgBranch IfStmt.branch() = new CfgBranch(); + syn nta CfgBranch IfStmt.branch() { + CfgBranch branch = new CfgBranch(); + branch.setHostStatement(this); + return branch; + } /** The then-end node is a marker node marking the end of a then-branch in an if statement. */ syn nta CfgMarker IfStmt.thenEndMarker() = new CfgMarker(); @@ -491,7 +499,11 @@ aspect SimpleCFG { : smallSet(getThen().entry(), follow()); /** The branch node for this statement. */ - syn nta CfgBranch ForStmt.branch() = new CfgBranch(); + syn nta CfgBranch ForStmt.branch() { + CfgBranch branch = new CfgBranch(); + branch.setHostStatement(this); + return branch; + } /** The CFG end marker for this loop. */ syn nta CfgMarker ForStmt.loopEndMarker() = new CfgMarker(); @@ -536,7 +548,11 @@ aspect SimpleCFG { } /** The branch node for this statement. */ - syn nta CfgBranch EnhancedForStmt.branch() = new CfgBranch(); + syn nta CfgBranch EnhancedForStmt.branch() { + CfgBranch branch = new CfgBranch(); + branch.setHostStatement(this); + return branch; + } /** The CFG end marker for this loop. */ syn nta CfgMarker EnhancedForStmt.loopEndMarker() = new CfgMarker(); @@ -555,7 +571,11 @@ aspect SimpleCFG { eq EnhancedForStmt.loopEndMarker().succ() = Collections.singleton(entry()); /** The branch node for this statement. */ - syn nta CfgBranch WhileStmt.branch() = new CfgBranch(); + syn nta CfgBranch WhileStmt.branch() { + CfgBranch branch = new CfgBranch(); + branch.setHostStatement(this); + return branch; + } /** The CFG end marker for this loop. */ syn nta CfgMarker WhileStmt.loopEndMarker() = new CfgMarker(); @@ -581,7 +601,11 @@ aspect SimpleCFG { } /** The branch node for this statement. */ - syn nta CfgBranch DoStmt.branch() = new CfgBranch(); + syn nta CfgBranch DoStmt.branch() { + CfgBranch branch = new CfgBranch(); + branch.setHostStatement(this); + return branch; + } /** The CFG entry marker for this loop. */ syn nta CfgMarker DoStmt.doEntryMarker() = new CfgMarker(); @@ -607,7 +631,11 @@ aspect SimpleCFG { } } - syn nta CfgBranch SwitchStmt.branch() = new CfgBranch(); + syn nta CfgBranch SwitchStmt.branch() { + CfgBranch branch = new CfgBranch(); + branch.setHostStatement(this); + return branch; + } eq SwitchStmt.entry() = getExpr().entry(); diff --git a/reusablecfg/src/main/jastadd/VariableDeclarationScope.jrag b/reusablecfg/src/main/jastadd/VariableDeclarationScope.jrag index 26be09c12a2ba7feb9c471db0d398c0f9ba60f58..ac411950e7394e69ac6efcc2052d632558091879 100644 --- a/reusablecfg/src/main/jastadd/VariableDeclarationScope.jrag +++ b/reusablecfg/src/main/jastadd/VariableDeclarationScope.jrag @@ -32,7 +32,7 @@ aspect VariableDeclarationScope { || variableDeclaredInsideStatement(var); syn boolean CfgBranch.variableDeclaredInsideStatement(Variable var) { - Stmt stmt = hostStatement(); + Stmt stmt = getHostStatement(); ASTNode node = (ASTNode) var; while (node != stmt && node != null) { node = node.getParent(); @@ -40,22 +40,11 @@ aspect VariableDeclarationScope { return node == stmt; } - /** The statement this branch represents. */ - inh Stmt CfgBranch.hostStatement(); - /** The statement this expression is part of. */ inh Stmt Expr.hostStatement(); eq Stmt.getChild().hostStatement() = this; eq Program.getChild().hostStatement() = null; - eq IfStmt.branch().hostStatement() = this; - eq ConditionalExpr.branch().hostStatement() = hostStatement(); - eq ForStmt.branch().hostStatement() = this; - eq WhileStmt.branch().hostStatement() = this; - eq DoStmt.branch().hostStatement() = this; - eq EnhancedForStmt.branch().hostStatement() = this; - eq SwitchStmt.branch().hostStatement() = this; - /** Test if the CFG node is tied to a statement that declares the variable. */ inh boolean CfgBranch.branchDeclaresVariable(Variable var);