Class CFGBuilder
java.lang.Object
org.checkerframework.dataflow.cfg.builder.CFGBuilder
- Direct Known Subclasses:
CFCFGBuilder
Builds the control flow graph of some Java code (either a method, or an arbitrary statement).
The translation of the AST to the CFG is split into three phases:
- Phase one. In the first phase, the AST is translated into a sequence of
ExtendedNode
s. An extended node can either be aNode
, or one of several meta elements such as a conditional or unconditional jump or a node with additional information about exceptions. Some of the extended nodes contain labels (e.g., for the jump target), and phase one additionally creates a mapping from labels to extended nodes. Finally, the list of leaders is computed: A leader is an extended node which will give rise to a basic block in phase two. - Phase two. In this phase, the sequence of extended nodes is translated to a graph of control flow blocks that contain nodes. The meta elements from phase one are translated into the correct edges.
- Phase three. The control flow graph generated in phase two can contain degenerate basic blocks such as empty regular basic blocks or conditional basic blocks that have the same block as both 'then' and 'else' successor. This phase removes these cases while preserving the control flow structure.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ControlFlowGraph
build
(CompilationUnitTree root, MethodTree tree, ClassTree classTree, ProcessingEnvironment env) Build the control flow graph of a method.static ControlFlowGraph
build
(CompilationUnitTree root, UnderlyingAST underlyingAST, boolean assumeAssertionsEnabled, boolean assumeAssertionsDisabled, ProcessingEnvironment env) Build the control flow graph of some code.static ControlFlowGraph
build
(CompilationUnitTree root, UnderlyingAST underlyingAST, ProcessingEnvironment env) Build the control flow graph of some code.static ControlFlowGraph
build
(TreePath bodyPath, UnderlyingAST underlyingAST, boolean assumeAssertionsEnabled, boolean assumeAssertionsDisabled, ProcessingEnvironment env) Build the control flow graph of some code (method, initializer block, ...).static String
extendedNodeCollectionToStringDebug
(Collection<? extends ExtendedNode> nodes) Return a printed representation of a collection of extended nodes.protected static void
printBlocks
(Set<Block> blocks) Print a set ofBlock
s and the edges between them.
-
Constructor Details
-
CFGBuilder
protected CFGBuilder()This class should never be instantiated. Protected to still allow subclasses.
-
-
Method Details
-
build
public static ControlFlowGraph build(CompilationUnitTree root, UnderlyingAST underlyingAST, boolean assumeAssertionsEnabled, boolean assumeAssertionsDisabled, ProcessingEnvironment env) Build the control flow graph of some code.- Parameters:
root
- the compilation unitunderlyingAST
- the AST that underlies the control frow graphassumeAssertionsDisabled
- can assertions be assumed to be disabled?assumeAssertionsEnabled
- can assertions be assumed to be enabled?env
- annotation processing environment containing type utilities- Returns:
- a control flow graph
-
build
public static ControlFlowGraph build(TreePath bodyPath, UnderlyingAST underlyingAST, boolean assumeAssertionsEnabled, boolean assumeAssertionsDisabled, ProcessingEnvironment env) Build the control flow graph of some code (method, initializer block, ...). bodyPath is the TreePath to the body of that code. -
build
public static ControlFlowGraph build(CompilationUnitTree root, UnderlyingAST underlyingAST, ProcessingEnvironment env) Build the control flow graph of some code. -
build
public static ControlFlowGraph build(CompilationUnitTree root, MethodTree tree, ClassTree classTree, ProcessingEnvironment env) Build the control flow graph of a method. -
extendedNodeCollectionToStringDebug
Return a printed representation of a collection of extended nodes.- Parameters:
nodes
- a collection of extended nodes to format- Returns:
- a printed representation of the given collection
-
printBlocks
Print a set ofBlock
s and the edges between them. This is useful for examining the results of phase two.- Parameters:
blocks
- the blocks to print
-