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

wip

parent 6b189adc
No related branches found
No related tags found
No related merge requests found
...@@ -81,12 +81,12 @@ aspect AlreadyClosedAnalysis { ...@@ -81,12 +81,12 @@ aspect AlreadyClosedAnalysis {
/** Test if the CFG node is a call node with the given variable as receiver. */ /** Test if the CFG node is a call node with the given variable as receiver. */
syn boolean CfgNode.isCall(Variable receiver) = false; syn boolean CfgNode.isCall(Variable receiver) = false;
eq CfgMethodCall.isCall(Variable receiver) = methodAccess().hasReceiver(receiver); eq CfgMethodCall.isCall(Variable receiver) = getMethodAccess().hasReceiver(receiver);
/** Test if the CFG node is a call node for receiver.close(). */ /** Test if the CFG node is a call node for receiver.close(). */
syn boolean CfgNode.isCloseCall(Variable receiver) = false; syn boolean CfgNode.isCloseCall(Variable receiver) = false;
eq CfgMethodCall.isCloseCall(Variable receiver) = eq CfgMethodCall.isCloseCall(Variable receiver) =
methodAccess().hasReceiver(receiver) && methodAccess().getID().equals("close"); getMethodAccess().hasReceiver(receiver) && getMethodAccess().getID().equals("close");
/** Check if this is a Reader or Writer. */ /** Check if this is a Reader or Writer. */
syn boolean TypeDecl.isCloseable() = syn boolean TypeDecl.isCloseable() =
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
/** The root of the Control Flow Graph (CFG). */
Cfg ::= CfgNode*;
rel Cfg.entry -> CfgEntry;
/** A node in a Control Flow Graph (CFG). */ /** A node in a Control Flow Graph (CFG). */
abstract CfgNode; abstract CfgNode;
...@@ -25,6 +29,7 @@ CfgExit : CfgNode; ...@@ -25,6 +29,7 @@ CfgExit : CfgNode;
/** A method call in the CFG. */ /** A method call in the CFG. */
CfgMethodCall : CfgNode; CfgMethodCall : CfgNode;
rel CfgMethodCall.methodAccess -> MethodAccess;
/** A conditional branch in the CFG. */ /** A conditional branch in the CFG. */
abstract CfgBranch : CfgNode; abstract CfgBranch : CfgNode;
...@@ -37,4 +42,24 @@ rel CfgExpressionBranch.hostExpression -> ConditionalExpr; ...@@ -37,4 +42,24 @@ rel CfgExpressionBranch.hostExpression -> ConditionalExpr;
CfgException : CfgNode; CfgException : CfgNode;
/** A marker node used to mark try block entry points or the end of if-statement branches. */ /** A marker node used to mark try block entry points or the end of if-statement branches. */
CfgMarker : CfgNode; abstract CfgMarker : CfgNode;
CfgLoopEndMarker:CfgMarker ;
rel CfgLoopEndMarker.loop -> BranchTargetStmt;
abstract CfgThenEndMarker:CfgMarker ;
CfgThenEndExprMarker:CfgThenEndMarker ;
CfgThenEndStmtMarker:CfgThenEndMarker ;
rel CfgThenEndExprMarker.condExpr -> ConditionalExpr;
rel CfgThenEndStmtMarker.ifStmt -> IfStmt;
abstract CfgElseEndMarker:CfgMarker ;
CfgElseEndExprMarker:CfgElseEndMarker ;
CfgElseEndStmtMarker:CfgElseEndMarker ;
rel CfgElseEndExprMarker.condExpr -> ConditionalExpr;
rel CfgElseEndStmtMarker.ifStmt -> IfStmt;
CfgTryEntryMarker:CfgMarker ;
rel CfgTryEntryMarker.tryStmt -> TryStmt;
CfgBreakStmtMarker:CfgMarker ;
rel CfgBreakStmtMarker.breakStmt -> BreakStmt;
CfgContinueStmtMarker:CfgMarker;
rel CfgContinueStmtMarker.continueStmt -> ContinueStmt;
CfgReturnStmtMarker:CfgMarker ;
rel CfgReturnStmtMarker.returnStmt -> ReturnStmt;
...@@ -89,7 +89,8 @@ aspect CfgSearch { ...@@ -89,7 +89,8 @@ aspect CfgSearch {
return null; return null;
} }
inh lazy CfgEntry CfgNode.cfg(); inh lazy Cfg CfgNode.containingCfg();
eq Cfg.getCfgNode().containingCfg() = this;
/** /**
* Performs a Breadth-First Search over the CFG predecessors starting from this node. * Performs a Breadth-First Search over the CFG predecessors starting from this node.
...@@ -100,7 +101,7 @@ aspect CfgSearch { ...@@ -100,7 +101,7 @@ aspect CfgSearch {
public CfgNode CfgNode.reverseBfs(CfgVisitor visitor) { public CfgNode CfgNode.reverseBfs(CfgVisitor visitor) {
Set<CfgNode> visited = Collections.newSetFromMap( Set<CfgNode> visited = Collections.newSetFromMap(
new IdentityHashMap<CfgNode, Boolean>()); new IdentityHashMap<CfgNode, Boolean>());
cfg().initPredecessors(); containingCfg().getEntry().initPredecessors();
Queue<CfgNode> work = new LinkedList<CfgNode>(); Queue<CfgNode> work = new LinkedList<CfgNode>();
work.add(this); work.add(this);
while (!work.isEmpty()) { while (!work.isEmpty()) {
......
...@@ -112,8 +112,7 @@ aspect PrintCfg { ...@@ -112,8 +112,7 @@ aspect PrintCfg {
eq CfgMarker.name() = markerName(); eq CfgMarker.name() = markerName();
eq CfgMethodCall.name() = callLabel(); eq CfgMethodCall.name() = callLabel();
inh String CfgMethodCall.callLabel(); syn String CfgMethodCall.callLabel() = getMethodAccess().name() + "()";
eq MethodAccess.call().callLabel() = name() + "()";
syn String CfgBranch.branchLabel(); syn String CfgBranch.branchLabel();
eq CfgStatementBranch.branchLabel() = getHostStatement().branchLabel(); eq CfgStatementBranch.branchLabel() = getHostStatement().branchLabel();
...@@ -132,19 +131,22 @@ aspect PrintCfg { ...@@ -132,19 +131,22 @@ aspect PrintCfg {
syn String ConditionalExpr.branchLabel() = "if (" + getCondition().prettyPrint() + ")"; syn String ConditionalExpr.branchLabel() = "if (" + getCondition().prettyPrint() + ")";
inh String CfgMarker.markerName(); syn String CfgMarker.markerName() = "marker";
eq BreakStmt.marker().markerName() = "break"; eq CfgBreakStmtMarker.markerName() = "break";
eq ContinueStmt.marker().markerName() = "continue"; eq CfgContinueStmtMarker.markerName() = "continue";
eq ConditionalExpr.thenEndMarker().markerName() = "then-end"; eq CfgThenEndMarker.markerName() = "then-end";
eq ConditionalExpr.elseEndMarker().markerName() = "else-end"; eq CfgElseEndMarker.markerName() = "else-end";
eq IfStmt.thenEndMarker().markerName() = "then-end"; eq CfgReturnStmtMarker.markerName() = "return";
eq IfStmt.elseEndMarker().markerName() = "else-end"; eq CfgTryEntryMarker.markerName() = "try";
eq ReturnStmt.marker().markerName() = "return"; eq CfgLoopEndMarker.markerName() = getLoop.markerName();
eq TryStmt.tryEntryMarker().markerName() = "try";
eq Program.getChild().markerName() = "marker";
// eq Dot.nullableDereferenceMarker().markerName() = "nullable access"; // eq Dot.nullableDereferenceMarker().markerName() = "nullable access";
eq ForStmt.loopEndMarker().markerName() = "for-end";
eq EnhancedForStmt.loopEndMarker().markerName() = "for-end"; syn String BranchTargetStmt.markerName() = "marker";
eq WhileStmt.loopEndMarker().markerName() = "while-end"; eq DoStmt.markerName() = "do-entry";
eq DoStmt.doEntryMarker().markerName() = "do-entry"; eq EnhancedForStmt.markerName() = "for-end";
eq ForStmt.markerName() = "for-end";
eq SwitchStmt.markerName() = "switch-end";
eq WhileStmt.markerName() = "while-end";
} }
...@@ -150,7 +150,7 @@ aspect PrintCfgTest { ...@@ -150,7 +150,7 @@ aspect PrintCfgTest {
eq CfgBranch.varName() = branchKind() + "Branch"; eq CfgBranch.varName() = branchKind() + "Branch";
eq CfgException.varName() = "exception"; eq CfgException.varName() = "exception";
eq CfgMarker.varName() = markerVarName(); eq CfgMarker.varName() = markerVarName();
eq CfgMethodCall.varName() = methodAccess().getID(); eq CfgMethodCall.varName() = getMethodAccess().getID();
syn String CfgBranch.branchKind(); syn String CfgBranch.branchKind();
eq CfgStatementBranch.branchKind() = getHostStatement().branchKind(); eq CfgStatementBranch.branchKind() = getHostStatement().branchKind();
......
...@@ -51,32 +51,49 @@ aspect SimpleCFG { ...@@ -51,32 +51,49 @@ aspect SimpleCFG {
eq CfgExit.successors() = Collections.emptySet(); eq CfgExit.successors() = Collections.emptySet();
eq CfgMethodCall.successors() = succ(); eq CfgMethodCall.successors();
eq CfgBranch.successors() = succ(); eq CfgBranch.successors();
eq CfgException.successors() = succ(); eq CfgException.successors();
eq CfgMarker.successors() = succ(); eq CfgMarker.successors();
/** Successors to this branch node. */ /** Successors to this branch node. */
syn Set<? extends CfgNode> CfgBranch.succ(); syn Set<? extends CfgNode> CfgBranch.succ();
eq CfgStatementBranch.succ() = getHostStatement().branchSucc(); eq CfgStatementBranch.successors() = getHostStatement().branchSuccessors();
eq CfgExpressionBranch.succ() = getHostExpression().branchSucc(); eq CfgExpressionBranch.successors() = getHostExpression().branchSuccessors();
/** Successors of a Stmt */ /** Successors of a Stmt */
syn Set<? extends CfgNode> Stmt.branchSucc() = Collections.emptySet(); syn Set<? extends CfgNode> Stmt.branchSuccessors() = Collections.emptySet();
syn Set<? extends CfgNode> Stmt.loopEndMarkerSucc() = Collections.emptySet();
syn Set<? extends CfgNode> Stmt.thenEndMarkerSucc() = Collections.emptySet();
syn Set<? extends CfgNode> Stmt.elseEndMarkerSucc() = Collections.emptySet();
syn Set<? extends CfgNode> Stmt.doEntryMarkerSucc() = Collections.emptySet();
syn Set<? extends CfgNode> Stmt.markerSucc() = Collections.emptySet();
syn Set<? extends CfgNode> Stmt.tryEntryMarkerSucc() = Collections.emptySet();
/** Successors of a Stmt */ /** Successors of a Stmt */
syn Set<? extends CfgNode> ConditionalExpr.branchSucc(); syn Set<? extends CfgNode> ConditionalExpr.branchSuccessors();
/** Successors to this method call node. */ /** Successors to this method call node. */
inh Set<? extends CfgNode> CfgMethodCall.succ(); syn Set<? extends CfgNode> CfgMethodCall.succ() = getMethodAccess().callSuccessors();
inh Set<? extends CfgNode> CfgException.succ(); /** Successors of a MethodAccess */
syn Set<? extends CfgNode> MethodAccess.callSuccessors();
syn Set<? extends CfgNode> CfgException.succ();
syn Set<? extends CfgNode> CfgMarker.succ();
eq CfgLoopEndMarker.succ() = getLoop().markerSucc();
eq CfgThenEndMarker.succ() = getIfStmt().markerSucc();
eq CfgElseEndMarker.succ() = getIfStmt().markerSucc();
eq CfgTryEntryMarker.succ() = getTryStmt().markerSucc();
eq CfgBreakStmtMarker.succ() = getBreakStmt().markerSucc();
eq CfgContinueStmtMarker.succ() = getContinueStmt().markerSucc();
eq CfgReturnStmtMarker.succ() = getreturnStmt().markerSucc();
inh Set<? extends CfgNode> CfgMarker.succ();
/** Build a small set with two elements. */ /** Build a small set with two elements. */
public <T> Set<T> ASTNode.smallSet(T a, T b) { public <T> Set<T> ASTNode.smallSet(T a, T b) {
...@@ -94,9 +111,7 @@ aspect SimpleCFG { ...@@ -94,9 +111,7 @@ aspect SimpleCFG {
* Find the next CFG node representing the next branch, or the next * Find the next CFG node representing the next branch, or the next
* method access following this statement. * method access following this statement.
*/ */
inh CfgNode Stmt.follow(); syn CfgNode CfgNode.follow();
inh CfgNode Expr.follow();
// Needed for completeness, but never used by anything relevant. // Needed for completeness, but never used by anything relevant.
eq Program.getChild().follow() = new CfgExit(); eq Program.getChild().follow() = new CfgExit();
...@@ -171,9 +186,9 @@ aspect SimpleCFG { ...@@ -171,9 +186,9 @@ aspect SimpleCFG {
* The entry of a try statement has a branch to the block and to each * The entry of a try statement has a branch to the block and to each
* catch clause or finally block. * catch clause or finally block.
*/ */
syn nta CfgMarker TryStmt.tryEntryMarker() = new CfgMarker(); syn lazy CfgMarker TryStmt.tryEntryMarker() = new CfgMarker();
eq TryStmt.tryEntryMarker().succ() = eq TryStmt.tryEntryMarkerSucc() =
joinSets(Collections.singleton(getBlock().entry()), catchBranches()); joinSets(Collections.singleton(getBlock().entry()), catchBranches());
eq MethodAccess.exceptionNode().succ() = exceptionBranches(); eq MethodAccess.exceptionNode().succ() = exceptionBranches();
...@@ -247,14 +262,14 @@ aspect SimpleCFG { ...@@ -247,14 +262,14 @@ aspect SimpleCFG {
: follow(); : follow();
/** The CFG marker for this break statement. */ /** The CFG marker for this break statement. */
syn nta CfgMarker BreakStmt.marker() = new CfgMarker(); syn lazy CfgMarker BreakStmt.marker() = new CfgMarker();
eq BreakStmt.entry() = marker(); eq BreakStmt.entry() = marker();
eq BreakStmt.marker().succ() = eq BreakStmt.markerSucc() =
hasFinally() hasFinally()
? Collections.singleton(getFinally().entry()) ? Collections.singleton(getFinally().entry())
: Collections.singleton(targetStmt().follow()); : Collections.singleton(targetStmt().follow());
eq BreakStmt.marker().follow() = eq BreakStmt.markerFollow() =
hasFinally() hasFinally()
? getFinally().entry() ? getFinally().entry()
: targetStmt().follow(); : targetStmt().follow();
...@@ -262,14 +277,14 @@ aspect SimpleCFG { ...@@ -262,14 +277,14 @@ aspect SimpleCFG {
eq BreakStmt.getFinally().follow() = targetStmt().follow(); eq BreakStmt.getFinally().follow() = targetStmt().follow();
/** The CFG marker for this continue statement. */ /** The CFG marker for this continue statement. */
syn nta CfgMarker ContinueStmt.marker() = new CfgMarker(); syn lazy CfgMarker ContinueStmt.marker() = new CfgMarker();
eq ContinueStmt.entry() = marker(); eq ContinueStmt.entry() = marker();
eq ContinueStmt.marker().succ() = eq ContinueStmt.markerSucc() =
hasFinally() hasFinally()
? Collections.singleton(getFinally().entry()) ? Collections.singleton(getFinally().entry())
: Collections.singleton(targetStmt().entry()); : Collections.singleton(targetStmt().entry());
eq ContinueStmt.marker().follow() = eq ContinueStmt.markerFollow() =
hasFinally() hasFinally()
? getFinally().entry() ? getFinally().entry()
: targetStmt().entry(); : targetStmt().entry();
...@@ -277,14 +292,14 @@ aspect SimpleCFG { ...@@ -277,14 +292,14 @@ aspect SimpleCFG {
eq ContinueStmt.getFinally().follow() = targetStmt().follow(); eq ContinueStmt.getFinally().follow() = targetStmt().follow();
/** The CFG marker for this continue statement. */ /** The CFG marker for this continue statement. */
syn nta CfgMarker ReturnStmt.marker() = new CfgMarker(); syn lazy CfgMarker ReturnStmt.marker() = new CfgMarker();
eq ReturnStmt.entry() = marker(); eq ReturnStmt.entry() = marker();
eq ReturnStmt.marker().succ() = eq ReturnStmt.markerSucc() =
hasResult() hasResult()
? Collections.singleton(getResult().entry()) ? Collections.singleton(getResult().entry())
: Collections.singleton(returnTarget()); : Collections.singleton(returnTarget());
eq ReturnStmt.marker().follow() = eq ReturnStmt.markerFollow() =
hasResult() hasResult()
? getResult().entry() ? getResult().entry()
: returnTarget(); : returnTarget();
...@@ -320,16 +335,16 @@ aspect SimpleCFG { ...@@ -320,16 +335,16 @@ aspect SimpleCFG {
* This node represents the control flow path taken when an exception * This node represents the control flow path taken when an exception
* interrupts the call. * interrupts the call.
*/ */
syn nta CfgException MethodAccess.exceptionNode() = new CfgException(); syn lazy CfgException MethodAccess.exceptionNode() = new CfgException();
/** This node represents the control flow following the exception. */ /** This node represents the control flow following the exception. */
syn nta CfgException ThrowStmt.exceptionNode() = new CfgException(); syn lazy CfgException ThrowStmt.exceptionNode() = new CfgException();
/** /**
* This node represents the control flow path taken if an exception * This node represents the control flow path taken if an exception
* is thrown in the start of a try statement. * is thrown in the start of a try statement.
*/ */
syn nta CfgException TryStmt.exceptionNode() = new CfgException(); syn lazy CfgException TryStmt.exceptionNode() = new CfgException();
eq ExprStmt.entry() = getExpr().entry(); eq ExprStmt.entry() = getExpr().entry();
...@@ -364,9 +379,13 @@ aspect SimpleCFG { ...@@ -364,9 +379,13 @@ aspect SimpleCFG {
eq ExprMethodReference.entry() = getExpr().entry(); eq ExprMethodReference.entry() = getExpr().entry();
/** The method call node for this method access. */ /** The method call node for this method access. */
syn nta CfgMethodCall MethodAccess.call() = new CfgMethodCall(); syn lazy CfgMethodCall MethodAccess.call() {
CfgMethodCall call = new CfgMethodCall();
call.setMethodAccess(this);
return call;
}
eq MethodAccess.call().succ() = eq MethodAccess.callSuccessors() =
isInsideTryBlockOrResource() isInsideTryBlockOrResource()
? smallSet(exceptionNode(), follow()) ? smallSet(exceptionNode(), follow())
: Collections.singleton(follow()); : Collections.singleton(follow());
...@@ -459,24 +478,24 @@ aspect SimpleCFG { ...@@ -459,24 +478,24 @@ aspect SimpleCFG {
* 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
* expression. * expression.
*/ */
syn nta CfgMarker ConditionalExpr.thenEndMarker() = new CfgMarker(); syn lazy CfgMarker ConditionalExpr.thenEndMarker() = new CfgMarker();
/** /**
* The else-end node is a marker node marking the end of a else-branch in a conditional * The else-end node is a marker node marking the end of a else-branch in a conditional
* expression. * expression.
*/ */
syn nta CfgMarker ConditionalExpr.elseEndMarker() = new CfgMarker(); syn lazy CfgMarker ConditionalExpr.elseEndMarker() = new CfgMarker();
eq ConditionalExpr.entry() = getCondition().entry(); eq ConditionalExpr.entry() = getCondition().entry();
eq ConditionalExpr.getCondition().follow() = branch(); eq ConditionalExpr.getCondition().follow() = branch();
eq ConditionalExpr.getTrueExpr().follow() = thenEndMarker(); eq ConditionalExpr.getTrueExpr().follow() = thenEndMarker();
eq ConditionalExpr.getFalseExpr().follow() = elseEndMarker(); eq ConditionalExpr.getFalseExpr().follow() = elseEndMarker();
eq ConditionalExpr.thenEndMarker().follow() = follow(); eq ConditionalExpr.thenEndMarkerFollow() = follow();
eq ConditionalExpr.elseEndMarker().follow() = follow(); eq ConditionalExpr.elseEndMarkerFollow() = follow();
eq ConditionalExpr.thenEndMarker().succ() = Collections.singleton(follow()); eq ConditionalExpr.thenEndMarkerSucc() = Collections.singleton(follow());
eq ConditionalExpr.elseEndMarker().succ() = Collections.singleton(follow()); eq ConditionalExpr.elseEndMarkerSucc() = Collections.singleton(follow());
eq ConditionalExpr.branchSucc() = eq ConditionalExpr.successors() =
smallSet(getTrueExpr().entry(), getFalseExpr().entry()); smallSet(getTrueExpr().entry(), getFalseExpr().entry());
/** The branch node for this statement. */ /** The branch node for this statement. */
...@@ -487,22 +506,22 @@ aspect SimpleCFG { ...@@ -487,22 +506,22 @@ aspect SimpleCFG {
} }
/** 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 lazy CfgMarker IfStmt.thenEndMarker() = new CfgMarker();
/** The else-end node is a marker node marking the end of a else-branch in an if statement. */ /** The else-end node is a marker node marking the end of a else-branch in an if statement. */
syn nta CfgMarker IfStmt.elseEndMarker() = new CfgMarker(); syn lazy CfgMarker IfStmt.elseEndMarker() = new CfgMarker();
eq IfStmt.entry() = getCondition().entry(); eq IfStmt.entry() = getCondition().entry();
eq IfStmt.getCondition().follow() = branch(); eq IfStmt.getCondition().follow() = branch();
eq IfStmt.getThen().follow() = thenEndMarker(); eq IfStmt.getThen().follow() = thenEndMarker();
eq IfStmt.getElse().follow() = elseEndMarker(); eq IfStmt.getElse().follow() = elseEndMarker();
eq IfStmt.thenEndMarker().follow() = follow(); eq IfStmt.thenEndMarkerFollow() = follow();
eq IfStmt.elseEndMarker().follow() = follow(); eq IfStmt.elseEndMarkerFollow() = follow();
eq IfStmt.thenEndMarker().succ() = Collections.singleton(follow()); eq IfStmt.thenEndMarkerSucc() = Collections.singleton(follow());
eq IfStmt.elseEndMarker().succ() = Collections.singleton(follow()); eq IfStmt.elseEndMarkerSucc() = Collections.singleton(follow());
eq IfStmt.branchSucc() = eq IfStmt.successors() =
hasElse() hasElse()
? smallSet(getThen().entry(), getElse().entry()) ? smallSet(getThen().entry(), getElse().entry())
: smallSet(getThen().entry(), follow()); : smallSet(getThen().entry(), follow());
...@@ -515,7 +534,7 @@ aspect SimpleCFG { ...@@ -515,7 +534,7 @@ aspect SimpleCFG {
} }
/** The CFG end marker for this loop. */ /** The CFG end marker for this loop. */
syn nta CfgMarker ForStmt.loopEndMarker() = new CfgMarker(); syn lazy CfgMarker ForStmt.loopEndMarker() = new CfgMarker();
eq ForStmt.entry() = eq ForStmt.entry() =
getNumInitStmt() > 0 getNumInitStmt() > 0
...@@ -536,17 +555,17 @@ aspect SimpleCFG { ...@@ -536,17 +555,17 @@ aspect SimpleCFG {
eq ForStmt.getStmt().follow() = loopEndMarker(); eq ForStmt.getStmt().follow() = loopEndMarker();
eq ForStmt.loopEndMarker().follow() = eq ForStmt.loopEndMarkerFollow() =
getNumUpdateStmt() > 0 getNumUpdateStmt() > 0
? getUpdateStmt(0).entry() ? getUpdateStmt(0).entry()
: getCondition().entry(); : getCondition().entry();
eq ForStmt.loopEndMarker().succ() = eq ForStmt.loopEndMarkerSucc() =
getNumUpdateStmt() > 0 getNumUpdateStmt() > 0
? Collections.singleton(getUpdateStmt(0).entry()) ? Collections.singleton(getUpdateStmt(0).entry())
: Collections.singleton(getCondition().entry()); : Collections.singleton(getCondition().entry());
eq ForStmt.branchSucc() { eq ForStmt.branchSuccessors() {
if (getCondition().isTrue()) { if (getCondition().isTrue()) {
return Collections.singleton(getStmt().entry()); return Collections.singleton(getStmt().entry());
} else if (getCondition().isFalse()) { } else if (getCondition().isFalse()) {
...@@ -564,9 +583,9 @@ aspect SimpleCFG { ...@@ -564,9 +583,9 @@ aspect SimpleCFG {
} }
/** The CFG end marker for this loop. */ /** The CFG end marker for this loop. */
syn nta CfgMarker EnhancedForStmt.loopEndMarker() = new CfgMarker(); syn lazy CfgMarker EnhancedForStmt.loopEndMarker() = new CfgMarker();
eq EnhancedForStmt.branchSucc() = smallSet(getStmt().entry(), follow()); eq EnhancedForStmt.branchSuccessors() = smallSet(getStmt().entry(), follow());
eq EnhancedForStmt.entry() = getExpr().entry(); eq EnhancedForStmt.entry() = getExpr().entry();
...@@ -574,9 +593,9 @@ aspect SimpleCFG { ...@@ -574,9 +593,9 @@ aspect SimpleCFG {
eq EnhancedForStmt.getStmt().follow() = loopEndMarker(); eq EnhancedForStmt.getStmt().follow() = loopEndMarker();
eq EnhancedForStmt.loopEndMarker().follow() = entry(); // Loop back. eq EnhancedForStmt.loopEndMarkerfollow() = entry(); // Loop back.
eq EnhancedForStmt.loopEndMarker().succ() = Collections.singleton(entry()); eq EnhancedForStmt.loopEndMarkerSucc() = Collections.singleton(entry());
/** The branch node for this statement. */ /** The branch node for this statement. */
syn lazy CfgStatementBranch WhileStmt.branch() { syn lazy CfgStatementBranch WhileStmt.branch() {
...@@ -586,7 +605,7 @@ aspect SimpleCFG { ...@@ -586,7 +605,7 @@ aspect SimpleCFG {
} }
/** The CFG end marker for this loop. */ /** The CFG end marker for this loop. */
syn nta CfgMarker WhileStmt.loopEndMarker() = new CfgMarker(); syn lazy CfgMarker WhileStmt.loopEndMarker() = new CfgMarker();
eq WhileStmt.entry() = getCondition().entry(); eq WhileStmt.entry() = getCondition().entry();
...@@ -594,11 +613,11 @@ aspect SimpleCFG { ...@@ -594,11 +613,11 @@ aspect SimpleCFG {
eq WhileStmt.getStmt().follow() = loopEndMarker(); eq WhileStmt.getStmt().follow() = loopEndMarker();
eq WhileStmt.loopEndMarker().follow() = entry(); // Loop back. eq WhileStmt.loopEndMarkerFollow() = entry(); // Loop back.
eq WhileStmt.loopEndMarker().succ() = Collections.singleton(entry()); eq WhileStmt.loopEndMarkerSucc() = Collections.singleton(entry());
eq WhileStmt.branchSucc() { eq WhileStmt.branchSuccessors() {
if (getCondition().isTrue()) { if (getCondition().isTrue()) {
return Collections.singleton(getStmt().entry()); return Collections.singleton(getStmt().entry());
} else if (getCondition().isFalse()) { } else if (getCondition().isFalse()) {
...@@ -616,20 +635,20 @@ aspect SimpleCFG { ...@@ -616,20 +635,20 @@ aspect SimpleCFG {
} }
/** The CFG entry marker for this loop. */ /** The CFG entry marker for this loop. */
syn nta CfgMarker DoStmt.doEntryMarker() = new CfgMarker(); syn lazy CfgMarker DoStmt.doEntryMarker() = new CfgMarker();
eq DoStmt.entry() = doEntryMarker(); eq DoStmt.entry() = doEntryMarker();
eq DoStmt.doEntryMarker().follow() = getStmt().entry(); eq DoStmt.doEntryMarkerFollow() = getStmt().entry();
eq DoStmt.doEntryMarker().succ() = Collections.singleton(getStmt().entry()); eq DoStmt.doEntryMarkerSucc() = Collections.singleton(getStmt().entry());
eq DoStmt.getStmt().follow() = getCondition().entry(); eq DoStmt.getStmt().follow() = getCondition().entry();
eq DoStmt.getCondition().follow() = branch(); eq DoStmt.getCondition().follow() = branch();
// Loop back. // Loop back.
eq DoStmt.branchSucc() { eq DoStmt.branchSuccessors() {
if (getCondition().isTrue()) { if (getCondition().isTrue()) {
return Collections.singleton(entry()); return Collections.singleton(entry());
} else if (getCondition().isFalse()) { } else if (getCondition().isFalse()) {
...@@ -649,7 +668,7 @@ aspect SimpleCFG { ...@@ -649,7 +668,7 @@ aspect SimpleCFG {
eq SwitchStmt.getExpr().follow() = branch(); eq SwitchStmt.getExpr().follow() = branch();
eq SwitchStmt.branchSucc() { eq SwitchStmt.branchSuccessors() {
Set<CfgNode> set = Collections.newSetFromMap( Set<CfgNode> set = Collections.newSetFromMap(
new IdentityHashMap<CfgNode, Boolean>()); new IdentityHashMap<CfgNode, Boolean>());
boolean hasDefault = false; boolean hasDefault = false;
...@@ -683,10 +702,6 @@ aspect SimpleCFG { ...@@ -683,10 +702,6 @@ aspect SimpleCFG {
eq BlockLambdaBody.getBlock().follow() = exit(); eq BlockLambdaBody.getBlock().follow() = exit();
eq ExprLambdaBody.getExpr().follow() = exit(); eq ExprLambdaBody.getExpr().follow() = exit();
/** Find the method access which this call node is associated with. */
inh MethodAccess CfgMethodCall.methodAccess();
eq MethodAccess.call().methodAccess() = this;
/** Find the entry node to the CFG this statement belongs to. */ /** Find the entry node to the CFG this statement belongs to. */
inh lazy CfgEntry Stmt.cfg(); inh lazy CfgEntry Stmt.cfg();
inh lazy CfgEntry Expr.cfg(); inh lazy CfgEntry Expr.cfg();
......
aspect JavaToCfg {
// /**
// * Successor nodes in the CFG.
// */
// syn lazy Set<? extends CfgNode> CfgNode.successors();
//
// eq CfgEntry.successors() = Collections.singleton(getSucc());
//
// eq CfgExit.successors() = Collections.emptySet();
//
// eq CfgMethodCall.successors() = succ();
//
// eq CfgBranch.successors() = succ();
//
// eq CfgException.successors() = succ();
//
// eq CfgMarker.successors() = succ();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment