Class AbstractCFGVisualizer<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
java.lang.Object
org.checkerframework.dataflow.cfg.visualize.AbstractCFGVisualizer<V,S,T>
- Type Parameters:
V
- the abstract value type to be tracked by the analysisS
- the store type used in the analysisT
- the transfer function type that is used to approximate runtime behavior
- All Implemented Interfaces:
CFGVisualizer<V,
S, T>
- Direct Known Subclasses:
DOTCFGVisualizer
,StringCFGVisualizer
public abstract class AbstractCFGVisualizer<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
extends Object
implements CFGVisualizer<V,S,T>
This abstract class makes implementing a
CFGVisualizer
easier. Some of the methods in
CFGVisualizer
are already implemented in this abstract class, but can be overridden if
necessary.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static enum
Whether to visualize before or after a block. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
The line separator.protected static final String
The indentation for elements of the store.protected boolean
Iftrue
,CFGVisualizer
returns more detailed information. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Checks whether a block exists in the visited blocks list, and, if not, adds it to the visited blocks list and the work list.addBlockContent
(Block bb) Returns the contents of the block.protected abstract String
Format the given object as a String suitable for the output format, i.e.protected String
Get the simple name of a node.protected IdentityHashMap<Block,
List<Integer>> Generate the order of processing blocks.protected String
getProcessOrderSimpleString
(List<Integer> order) Given a list of process orders (integers), returns a string representation.protected void
handleSuccessorsHelper
(Block cur, Set<Block> visited, Queue<Block> workList, StringBuilder sbGraph) Outputs, to sbGraph, a visualization of a block's edges, but not the block itself.void
Initialization method guaranteed to be called once before the first invocation ofCFGVisualizer.visualize(org.checkerframework.dataflow.cfg.ControlFlowGraph, org.checkerframework.dataflow.cfg.block.Block, org.checkerframework.dataflow.analysis.Analysis<V, S, T>)
orCFGVisualizer.visualizeWithAction(org.checkerframework.dataflow.cfg.ControlFlowGraph, org.checkerframework.dataflow.cfg.block.Block, org.checkerframework.dataflow.analysis.Analysis<V, S, T>)
.protected String
Iterates over the block content and visualizes all the nodes in it.protected String
Helper method to visualize a block.Visualize a Node based on the analysis.protected String
visualizeBlockTransferInputHelper
(AbstractCFGVisualizer.VisualizeWhere where, Block bb, Analysis<V, S, T> analysis, String separator) Visualize the transfer input before or after the given block.protected abstract String
visualizeEdge
(Object sId, Object eId, String flowRule) Generate the String representation of an edge.protected String
visualizeGraph
(ControlFlowGraph cfg, Block entry, @Nullable Analysis<V, S, T> analysis) Visualize a control flow graph.protected abstract String
Return the footer of the generated graph.protected abstract String
Return the header of the generated graph.protected String
visualizeGraphWithoutHeaderAndFooter
(ControlFlowGraph cfg, Block entry, @Nullable Analysis<V, S, T> analysis) Helper method to visualize a control flow graph, without outputting a header or footer.protected abstract String
visualizeNodes
(Set<Block> blocks, ControlFlowGraph cfg, @Nullable Analysis<V, S, T> analysis) Generate the String representation of the nodes of a control flow graph.protected String
Visualize a special block.visualizeStore
(S store) Delegate the visualization responsibility to the passedStore
instance, which will call back to this visualizer instance for sub-components.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.checkerframework.dataflow.cfg.visualize.CFGVisualizer
getSeparator, shutdown, visualize, visualizeBlock, visualizeBlockTransferInputAfter, visualizeBlockTransferInputBefore, visualizeConditionalBlock, visualizeSpecialBlock, visualizeStoreArrayVal, visualizeStoreClassVals, visualizeStoreFieldVal, visualizeStoreKeyVal, visualizeStoreLocalVar, visualizeStoreMethodVals, visualizeStoreThisVal, visualizeWithAction
-
Field Details
-
verbose
protected boolean verbose -
lineSeparator
The line separator. -
storeEntryIndent
The indentation for elements of the store.- See Also:
-
-
Constructor Details
-
AbstractCFGVisualizer
public AbstractCFGVisualizer()
-
-
Method Details
-
init
Description copied from interface:CFGVisualizer
Initialization method guaranteed to be called once before the first invocation ofCFGVisualizer.visualize(org.checkerframework.dataflow.cfg.ControlFlowGraph, org.checkerframework.dataflow.cfg.block.Block, org.checkerframework.dataflow.analysis.Analysis<V, S, T>)
orCFGVisualizer.visualizeWithAction(org.checkerframework.dataflow.cfg.ControlFlowGraph, org.checkerframework.dataflow.cfg.block.Block, org.checkerframework.dataflow.analysis.Analysis<V, S, T>)
.- Specified by:
init
in interfaceCFGVisualizer<V extends AbstractValue<V>,
S extends Store<S>, T extends TransferFunction<V, S>> - Parameters:
args
- implementation-dependent options
-
visualizeGraph
protected String visualizeGraph(ControlFlowGraph cfg, Block entry, @Nullable Analysis<V, S, T> analysis) Visualize a control flow graph.- Parameters:
cfg
- the current control flow graphentry
- the entry block of the control flow graphanalysis
- the current analysis- Returns:
- the representation of the control flow graph
-
handleSuccessorsHelper
protected void handleSuccessorsHelper(Block cur, Set<Block> visited, Queue<Block> workList, StringBuilder sbGraph) Outputs, to sbGraph, a visualization of a block's edges, but not the block itself. (The block itself is output elsewhere.) Also adds the successors of the block to the work list and the visited blocks list.- Parameters:
cur
- the current blockvisited
- the set of blocks that have already been visited or are in the work list; side effected by this methodworkList
- the queue of blocks to be processed; side effected by this methodsbGraph
- theStringBuilder
to store the graph; side effected by this method
-
addBlock
Checks whether a block exists in the visited blocks list, and, if not, adds it to the visited blocks list and the work list.- Parameters:
b
- the block to checkvisited
- the set of blocks that have already been visited or are in the work listworkList
- the queue of blocks to be processed
-
visualizeBlockHelper
protected String visualizeBlockHelper(Block bb, @Nullable Analysis<V, S, T> analysis, String separator) Helper method to visualize a block.NOTE: The output ends with a separator, only if an "after" store is visualized. The client
CFGVisualizer.visualizeBlock(org.checkerframework.dataflow.cfg.block.Block, org.checkerframework.dataflow.analysis.Analysis<V, S, T>)
should correct this if needed.- Parameters:
bb
- the blockanalysis
- the current analysisseparator
- the line separator. Examples: "\\l" for left justification inDOTCFGVisualizer
(this is really a terminator, not a separator), "\n" to add a new line inStringCFGVisualizer
- Returns:
- the String representation of the block
-
loopOverBlockContents
protected String loopOverBlockContents(Block bb, @Nullable Analysis<V, S, T> analysis, String separator) Iterates over the block content and visualizes all the nodes in it.- Parameters:
bb
- the blockanalysis
- the current analysisseparator
- the separator between the nodes of the block- Returns:
- the String representation of the contents of the block
-
addBlockContent
Returns the contents of the block.- Parameters:
bb
- the block- Returns:
- the contents of the block, as a list of nodes
-
format
Format the given object as a String suitable for the output format, i.e. with format-specific characters escaped.- Parameters:
obj
- an object- Returns:
- the formatted String from the given object
-
visualizeBlockNode
Description copied from interface:CFGVisualizer
Visualize a Node based on the analysis.- Specified by:
visualizeBlockNode
in interfaceCFGVisualizer<V extends AbstractValue<V>,
S extends Store<S>, T extends TransferFunction<V, S>> - Parameters:
t
- the nodeanalysis
- the current analysis- Returns:
- the String representation of the given node
-
visualizeBlockTransferInputHelper
protected String visualizeBlockTransferInputHelper(AbstractCFGVisualizer.VisualizeWhere where, Block bb, Analysis<V, S, T> analysis, String separator) Visualize the transfer input before or after the given block.- Parameters:
where
- either BEFORE or AFTERbb
- a blockanalysis
- the current analysisseparator
- the line separator. Examples: "\\l" for left justification inDOTCFGVisualizer
(which is actually a line TERMINATOR, not a separator!), "\n" to add a new line inStringCFGVisualizer
- Returns:
- the visualization of the transfer input before or after the given block
-
visualizeSpecialBlockHelper
Visualize a special block.- Parameters:
sbb
- the special block- Returns:
- the String representation of the special block
-
getProcessOrder
Generate the order of processing blocks. Because a block may appear more than once inControlFlowGraph.getDepthFirstOrderedBlocks()
, the orders of each block are stored in a separate array list.- Parameters:
cfg
- the current control flow graph- Returns:
- an IdentityHashMap that maps from blocks to their orders
-
visualizeStore
Description copied from interface:CFGVisualizer
Delegate the visualization responsibility to the passedStore
instance, which will call back to this visualizer instance for sub-components.- Specified by:
visualizeStore
in interfaceCFGVisualizer<V extends AbstractValue<V>,
S extends Store<S>, T extends TransferFunction<V, S>> - Parameters:
store
- the store to visualize- Returns:
- the String representation of the given store
-
visualizeNodes
protected abstract String visualizeNodes(Set<Block> blocks, ControlFlowGraph cfg, @Nullable Analysis<V, S, T> analysis) Generate the String representation of the nodes of a control flow graph.- Parameters:
blocks
- the set of all the blocks in a control flow graphcfg
- the control flow graphanalysis
- the current analysis- Returns:
- the String representation of the nodes
-
visualizeEdge
Generate the String representation of an edge.- Parameters:
sId
- a representation of the current block, such as its IDeId
- a representation of the successor block, such as its IDflowRule
- the content of the edge- Returns:
- the String representation of the edge
-
visualizeGraphHeader
Return the header of the generated graph.- Returns:
- the String representation of the header of the control flow graph
-
getProcessOrderSimpleString
Given a list of process orders (integers), returns a string representation.Examples: "Process order: 23", "Process order: 23,25".
- Parameters:
order
- a list of process orders- Returns:
- a String representation of the given process orders
-
getNodeSimpleName
Get the simple name of a node.- Parameters:
t
- a node- Returns:
- the node's simple name, without "Node"
-