From 7b25d235542add222fed68463b3c692ab9d7a54d Mon Sep 17 00:00:00 2001
From: Johannes Mey <johannes.mey@tu-dresden.de>
Date: Tue, 17 Dec 2019 14:05:20 +0100
Subject: [PATCH] make attribute hostStatement() a relation

---
 reusablecfg/src/main/jastadd/CFG.relast       |  1 +
 reusablecfg/src/main/jastadd/SimpleCFG.jrag   | 42 +++++++++++++++----
 .../jastadd/VariableDeclarationScope.jrag     | 13 +-----
 3 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/reusablecfg/src/main/jastadd/CFG.relast b/reusablecfg/src/main/jastadd/CFG.relast
index b1e7cbe..7a59542 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 bd39ef7..40c66bc 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 26be09c..ac41195 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);
 
-- 
GitLab