Class ControlFlowGraph
- java.lang.Object
-
- org.checkerframework.dataflow.cfg.ControlFlowGraph
-
- All Implemented Interfaces:
org.plumelib.util.UniqueId
public class ControlFlowGraph extends java.lang.Object implements org.plumelib.util.UniqueIdA control flow graph (CFG for short) of a single method.The graph is represented by the successors (methods
SingleSuccessorBlock.getSuccessor(),ConditionalBlock.getThenSuccessor(),ConditionalBlock.getElseSuccessor(),ExceptionBlock.getExceptionalSuccessors(),RegularBlock.getRegularSuccessor()) and predecessors (methodBlock.getPredecessors()) of the entry and exit blocks.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>>convertedTreeLookupMap from ASTTrees to post-conversion sets ofNodes.protected java.util.List<com.sun.source.tree.ClassTree>declaredClassesClass declarations that have been encountered when building the control-flow graph for a method.protected java.util.List<com.sun.source.tree.LambdaExpressionTree>declaredLambdasLambdas encountered when building the control-flow graph for a method, variable initializer, or initializer.protected SpecialBlockentryBlockThe entry block of the control flow graph.protected SpecialBlockexceptionalExitBlockThe exceptional exit block of the control flow graph.protected java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree>postfixNodeLookupMap from postfix increment or decrement trees that are ASTUnaryTrees to the synthetic tree that isv + 1orv - 1.protected SpecialBlockregularExitBlockThe regular exit block of the control flow graph.protected java.util.List<ReturnNode>returnNodesAll return nodes (if any) encountered.protected java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>>treeLookupMaps from ASTTrees to sets ofNodes.UnderlyingASTunderlyingASTThe AST this CFG corresponds to.
-
Constructor Summary
Constructors Constructor Description ControlFlowGraph(SpecialBlock entryBlock, SpecialBlockImpl regularExitBlock, SpecialBlockImpl exceptionalExitBlock, UnderlyingAST underlyingAST, java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup, java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> convertedTreeLookup, java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree> postfixNodeLookup, java.util.List<ReturnNode> returnNodes, java.util.List<com.sun.source.tree.ClassTree> declaredClasses, java.util.List<com.sun.source.tree.LambdaExpressionTree> declaredLambdas)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<Block>getAllBlocks()Returns the set of all basic blocks in this control flow graph.java.util.List<Node>getAllNodes()Returns all nodes in this control flow graph.@Nullable com.sun.source.tree.ClassTreegetContainingClass(com.sun.source.tree.Tree t)@Nullable com.sun.source.tree.MethodTreegetContainingMethod(com.sun.source.tree.Tree t)java.util.List<com.sun.source.tree.ClassTree>getDeclaredClasses()java.util.List<com.sun.source.tree.LambdaExpressionTree>getDeclaredLambdas()java.util.List<Block>getDepthFirstOrderedBlocks()Returns all basic blocks in this control flow graph, in reversed depth-first postorder.SpecialBlockgetEntryBlock()Returns the entry block of the control flow graph.SpecialBlockgetExceptionalExitBlock()@Nullable java.util.Set<Node>getNodesCorrespondingToTree(com.sun.source.tree.Tree t)Returns the set ofNodes to which theTreetcorresponds, or null for trees that don't produce a value.org.plumelib.util.UnmodifiableIdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree>getPostfixNodeLookup()Returns an unmodifiable view of the lookup-map of the binary tree for a postfix expression.SpecialBlockgetRegularExitBlock()java.util.List<ReturnNode>getReturnNodes()org.plumelib.util.UnmodifiableIdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>>getTreeLookup()Returns an unmodifiable view of the tree-lookup map.longgetUid()UnderlyingASTgetUnderlyingAST()Returns the AST this CFG corresponds to.java.lang.StringtoString()java.lang.StringtoStringDebug()Returns a verbose string representation of this, useful for debugging.
-
-
-
Field Detail
-
entryBlock
protected final SpecialBlock entryBlock
The entry block of the control flow graph.
-
regularExitBlock
protected final SpecialBlock regularExitBlock
The regular exit block of the control flow graph.
-
exceptionalExitBlock
protected final SpecialBlock exceptionalExitBlock
The exceptional exit block of the control flow graph.
-
underlyingAST
public final UnderlyingAST underlyingAST
The AST this CFG corresponds to.
-
treeLookup
protected final java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup
Maps from ASTTrees to sets ofNodes.- Most Trees that produce a value will have at least one corresponding Node.
- Trees that undergo conversions, such as boxing or unboxing, can map to two distinct
Nodes. The Node for the pre-conversion value is stored in
treeLookup, while the Node for the post-conversion value is stored inconvertedTreeLookup.
treeLookupandconvertedTreeLookup) do not appear ingetAllNodes()because their blocks are not reachable in the control flow graph. Dataflow will not compute abstract values for these nodes.
-
convertedTreeLookup
protected final java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> convertedTreeLookup
Map from ASTTrees to post-conversion sets ofNodes.
-
postfixNodeLookup
protected final java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree> postfixNodeLookup
Map from postfix increment or decrement trees that are ASTUnaryTrees to the synthetic tree that isv + 1orv - 1.
-
returnNodes
protected final java.util.List<ReturnNode> returnNodes
All return nodes (if any) encountered. Only includes return statements that actually return something
-
declaredClasses
protected final java.util.List<com.sun.source.tree.ClassTree> declaredClasses
Class declarations that have been encountered when building the control-flow graph for a method.
-
declaredLambdas
protected final java.util.List<com.sun.source.tree.LambdaExpressionTree> declaredLambdas
Lambdas encountered when building the control-flow graph for a method, variable initializer, or initializer.
-
-
Constructor Detail
-
ControlFlowGraph
public ControlFlowGraph(SpecialBlock entryBlock, SpecialBlockImpl regularExitBlock, SpecialBlockImpl exceptionalExitBlock, UnderlyingAST underlyingAST, java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> treeLookup, java.util.IdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> convertedTreeLookup, java.util.IdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree> postfixNodeLookup, java.util.List<ReturnNode> returnNodes, java.util.List<com.sun.source.tree.ClassTree> declaredClasses, java.util.List<com.sun.source.tree.LambdaExpressionTree> declaredLambdas)
-
-
Method Detail
-
getUid
public long getUid(@UnknownInitialization ControlFlowGraph this)
- Specified by:
getUidin interfaceorg.plumelib.util.UniqueId
-
getNodesCorrespondingToTree
public @Nullable java.util.Set<Node> getNodesCorrespondingToTree(com.sun.source.tree.Tree t)
Returns the set ofNodes to which theTreetcorresponds, or null for trees that don't produce a value.- Parameters:
t- a tree- Returns:
- the set of
Nodes to which theTreetcorresponds, or null for trees that don't produce a value
-
getEntryBlock
public SpecialBlock getEntryBlock()
Returns the entry block of the control flow graph.- Returns:
- the entry block of the control flow graph
-
getReturnNodes
public java.util.List<ReturnNode> getReturnNodes()
-
getRegularExitBlock
public SpecialBlock getRegularExitBlock()
-
getExceptionalExitBlock
public SpecialBlock getExceptionalExitBlock()
-
getUnderlyingAST
public UnderlyingAST getUnderlyingAST()
Returns the AST this CFG corresponds to.- Returns:
- the AST this CFG corresponds to
-
getAllBlocks
public java.util.Set<Block> getAllBlocks(@UnknownInitialization(ControlFlowGraph.class) ControlFlowGraph this)
Returns the set of all basic blocks in this control flow graph.- Returns:
- the set of all basic blocks in this control flow graph
-
getAllNodes
public java.util.List<Node> getAllNodes(@UnknownInitialization(ControlFlowGraph.class) ControlFlowGraph this)
Returns all nodes in this control flow graph.- Returns:
- all nodes in this control flow graph
-
getDepthFirstOrderedBlocks
public java.util.List<Block> getDepthFirstOrderedBlocks()
Returns all basic blocks in this control flow graph, in reversed depth-first postorder. Blocks may appear more than once in the sequence.- Returns:
- the list of all basic block in this control flow graph in reversed depth-first postorder sequence
-
getTreeLookup
public org.plumelib.util.UnmodifiableIdentityHashMap<com.sun.source.tree.Tree,java.util.Set<Node>> getTreeLookup()
Returns an unmodifiable view of the tree-lookup map. Ignores convertedTreeLookup, thoughgetNodesCorrespondingToTree(com.sun.source.tree.Tree)uses that field.- Returns:
- the unmodifiable tree-lookup map
-
getPostfixNodeLookup
public org.plumelib.util.UnmodifiableIdentityHashMap<com.sun.source.tree.UnaryTree,com.sun.source.tree.BinaryTree> getPostfixNodeLookup()
Returns an unmodifiable view of the lookup-map of the binary tree for a postfix expression.- Returns:
- the unmodifiable lookup-map of the binary tree for a postfix expression
-
getContainingMethod
public @Nullable com.sun.source.tree.MethodTree getContainingMethod(com.sun.source.tree.Tree t)
- Parameters:
t- a tree that might correspond to a node in the CFG- Returns:
- the method that contains
t's Node, or null
-
getContainingClass
public @Nullable com.sun.source.tree.ClassTree getContainingClass(com.sun.source.tree.Tree t)
- Parameters:
t- a tree that might be within a class- Returns:
- the class that contains the given tree, or null
-
getDeclaredClasses
public java.util.List<com.sun.source.tree.ClassTree> getDeclaredClasses()
-
getDeclaredLambdas
public java.util.List<com.sun.source.tree.LambdaExpressionTree> getDeclaredLambdas()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toStringDebug
public java.lang.String toStringDebug()
Returns a verbose string representation of this, useful for debugging.- Returns:
- a string representation of this
-
-