Skip to content
Snippets Groups Projects
Commit 7b25d235 authored by Johannes Mey's avatar Johannes Mey
Browse files

make attribute hostStatement() a relation

parent 735b53ed
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ CfgMethodCall : CfgNode; ...@@ -28,6 +28,7 @@ CfgMethodCall : CfgNode;
/** A conditional branch in the CFG. */ /** A conditional branch in the CFG. */
CfgBranch : CfgNode; CfgBranch : CfgNode;
rel CfgBranch.hostStatement -> Stmt;
/** A branch in the CFG caused by potential thrown exceptions. */ /** A branch in the CFG caused by potential thrown exceptions. */
CfgException : CfgNode; CfgException : CfgNode;
......
...@@ -440,7 +440,11 @@ aspect SimpleCFG { ...@@ -440,7 +440,11 @@ aspect SimpleCFG {
eq Dot.getLeft().follow() = getRight().entry(); eq Dot.getLeft().follow() = getRight().entry();
/** The branch node for this conditional expression. */ /** 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 * The then-end node is a marker node marking the end of a then-branch in a conditional
...@@ -467,7 +471,11 @@ aspect SimpleCFG { ...@@ -467,7 +471,11 @@ aspect SimpleCFG {
smallSet(getTrueExpr().entry(), getFalseExpr().entry()); smallSet(getTrueExpr().entry(), getFalseExpr().entry());
/** The branch node for this statement. */ /** 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. */ /** 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(); syn nta CfgMarker IfStmt.thenEndMarker() = new CfgMarker();
...@@ -491,7 +499,11 @@ aspect SimpleCFG { ...@@ -491,7 +499,11 @@ aspect SimpleCFG {
: smallSet(getThen().entry(), follow()); : smallSet(getThen().entry(), follow());
/** The branch node for this statement. */ /** 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. */ /** The CFG end marker for this loop. */
syn nta CfgMarker ForStmt.loopEndMarker() = new CfgMarker(); syn nta CfgMarker ForStmt.loopEndMarker() = new CfgMarker();
...@@ -536,7 +548,11 @@ aspect SimpleCFG { ...@@ -536,7 +548,11 @@ aspect SimpleCFG {
} }
/** The branch node for this statement. */ /** 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. */ /** The CFG end marker for this loop. */
syn nta CfgMarker EnhancedForStmt.loopEndMarker() = new CfgMarker(); syn nta CfgMarker EnhancedForStmt.loopEndMarker() = new CfgMarker();
...@@ -555,7 +571,11 @@ aspect SimpleCFG { ...@@ -555,7 +571,11 @@ aspect SimpleCFG {
eq EnhancedForStmt.loopEndMarker().succ() = Collections.singleton(entry()); eq EnhancedForStmt.loopEndMarker().succ() = Collections.singleton(entry());
/** The branch node for this statement. */ /** 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. */ /** The CFG end marker for this loop. */
syn nta CfgMarker WhileStmt.loopEndMarker() = new CfgMarker(); syn nta CfgMarker WhileStmt.loopEndMarker() = new CfgMarker();
...@@ -581,7 +601,11 @@ aspect SimpleCFG { ...@@ -581,7 +601,11 @@ aspect SimpleCFG {
} }
/** The branch node for this statement. */ /** 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. */ /** The CFG entry marker for this loop. */
syn nta CfgMarker DoStmt.doEntryMarker() = new CfgMarker(); syn nta CfgMarker DoStmt.doEntryMarker() = new CfgMarker();
...@@ -607,7 +631,11 @@ aspect SimpleCFG { ...@@ -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(); eq SwitchStmt.entry() = getExpr().entry();
......
...@@ -32,7 +32,7 @@ aspect VariableDeclarationScope { ...@@ -32,7 +32,7 @@ aspect VariableDeclarationScope {
|| variableDeclaredInsideStatement(var); || variableDeclaredInsideStatement(var);
syn boolean CfgBranch.variableDeclaredInsideStatement(Variable var) { syn boolean CfgBranch.variableDeclaredInsideStatement(Variable var) {
Stmt stmt = hostStatement(); Stmt stmt = getHostStatement();
ASTNode node = (ASTNode) var; ASTNode node = (ASTNode) var;
while (node != stmt && node != null) { while (node != stmt && node != null) {
node = node.getParent(); node = node.getParent();
...@@ -40,22 +40,11 @@ aspect VariableDeclarationScope { ...@@ -40,22 +40,11 @@ aspect VariableDeclarationScope {
return node == stmt; return node == stmt;
} }
/** The statement this branch represents. */
inh Stmt CfgBranch.hostStatement();
/** The statement this expression is part of. */ /** The statement this expression is part of. */
inh Stmt Expr.hostStatement(); inh Stmt Expr.hostStatement();
eq Stmt.getChild().hostStatement() = this; eq Stmt.getChild().hostStatement() = this;
eq Program.getChild().hostStatement() = null; 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. */ /** Test if the CFG node is tied to a statement that declares the variable. */
inh boolean CfgBranch.branchDeclaresVariable(Variable var); inh boolean CfgBranch.branchDeclaresVariable(Variable var);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment