dk.brics.xact.analysis.soot
Class ControlFlowBuilder

java.lang.Object
  extended by dk.brics.xact.analysis.soot.ControlFlowBuilder

public class ControlFlowBuilder
extends Object

Utility class assisting in the construction of method bodies.

The control-flow builder acts as a cursor in the control-flow graph. When a new statement is added, it becomes the successor of the statement under the cursor, and the cursor then moves to the new statement. As a result, successive calls to addStatement(dk.brics.xact.analysis.flowgraph.Statement) creates a chain of statement nodes.

The control-flow graph can be split with startBranch(). After calling, one or more calls to useBranch() must be made at points where the branches should join. Finally endBranch() should be called after the last useBranch(). For example, to create the following control-flow,

     A
   / | \
  B  C  D
  |  |  |
  E  |  |
   \ | /
     F
 
one could add the statements in this fashion:
 A
 startBranch()
 B
 E
 useBranch()
 C
 useBranch()
 D
 useBranch()
 endBranch()
 F
 


Constructor Summary
ControlFlowBuilder(FlowGraph g, Origin origin)
          Creates a builder for inserting statements in the specified method's body.
 
Method Summary
 void addEdgeFrom(Statement s, VariableFilter filter)
           
 void addEdgeTo(Statement s, VariableFilter filter)
           
 void addFilter(VariableFilter filter)
           
 void addStatement(Statement s)
          Adds a statement at the current position in the control flow graph being built.
 void addStatement(Statement s, VariableFilter filter)
          Adds a statement at the current position in the control flow graph being built.
 Statement currentStatement()
           
 void endBranch()
          Ends the current branching.
 StatementPair finish()
          Finishes the subgraph created by the builder, and returns the first and last statement in the subgraph.
 void moveToIsolation()
          Removes the cursor from the control-flow graph, so statements will be placed in an isolated subgraph of their own.
 void moveToStatement(Statement to)
          Moves the cursor to the specified statement, so new statements will be successors of the specified statement.
 void setOrigin(Origin origin)
          Sets the origin assigned to nop nodes that are generated by the control-flow builder.
 void startBranch()
          Starts a new branching and opens one branch in it.
 void useBranch()
          Ends the current branch and starts a new one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ControlFlowBuilder

public ControlFlowBuilder(FlowGraph g,
                          Origin origin)
Creates a builder for inserting statements in the specified method's body. The builder's cursor will initially be in isolation, so added statements will not be reachable.

Method Detail

addEdgeFrom

public void addEdgeFrom(Statement s,
                        VariableFilter filter)

addEdgeTo

public void addEdgeTo(Statement s,
                      VariableFilter filter)

addFilter

public void addFilter(VariableFilter filter)

addStatement

public void addStatement(Statement s)
Adds a statement at the current position in the control flow graph being built. The statement will be added to the method, set as successor to the previous "cursor" statement, and then made the "cursor" statement itself.

Parameters:
s - a statement to add.

addStatement

public void addStatement(Statement s,
                         VariableFilter filter)
Adds a statement at the current position in the control flow graph being built. The statement will be added to the method, set as successor to the previous "cursor" statement, and then made the "cursor" statement itself.

Parameters:
s - a statement to add.

currentStatement

public Statement currentStatement()

endBranch

public void endBranch()
Ends the current branching. Must be called directly after useBranch(). See ControlFlowBuilder for a description of the branching methods.


finish

public StatementPair finish()
Finishes the subgraph created by the builder, and returns the first and last statement in the subgraph. The first statement will be either: The last statement will either be the last statement added with addStatement(dk.brics.xact.analysis.flowgraph.Statement), or a NopStm succeeding it.


moveToIsolation

public void moveToIsolation()
Removes the cursor from the control-flow graph, so statements will be placed in an isolated subgraph of their own. The statements can later be connected with the of the graph.


moveToStatement

public void moveToStatement(Statement to)
Moves the cursor to the specified statement, so new statements will be successors of the specified statement.

Parameters:
to - statement to add from.
Throws:
IllegalStateException - if a branch is currently unclosed.
IllegalArgumentException - if the specified statement belongs to a different method than the builder

setOrigin

public void setOrigin(Origin origin)
Sets the origin assigned to nop nodes that are generated by the control-flow builder.

Parameters:
origin -

startBranch

public void startBranch()
Starts a new branching and opens one branch in it. Multiple levels of branching can open at once. See ControlFlowBuilder for a description of the branching methods.


useBranch

public void useBranch()
Ends the current branch and starts a new one. See ControlFlowBuilder for a description of the branching methods.



Copyright © 2005-2011 Aarhus University.