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 java.lang.Object implements CFGVisualizer<V,S,T>
This abstract class makes implementing aCFGVisualizer
easier. Some of the methods inCFGVisualizer
are already implemented in this abstract class, but can be overridden if necessary.- See Also:
DOTCFGVisualizer
,StringCFGVisualizer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractCFGVisualizer.VisualizeWhere
Whether to visualize before or after a block.
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
lineSeparator
The line separator.protected static java.lang.String
storeEntryIndent
The indentation for elements of the store.protected boolean
verbose
Iftrue
,CFGVisualizer
returns more detailed information.
-
Constructor Summary
Constructors Constructor Description AbstractCFGVisualizer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addBlock(Block b, java.util.Set<Block> visited, java.util.Queue<Block> workList)
Checks whether a block exists in the visited blocks list, and, if not, adds it to the visited blocks list and the work list.protected java.util.List<Node>
addBlockContent(Block bb)
Returns the contents of the block.protected abstract java.lang.String
format(java.lang.Object obj)
Format the given object as a String suitable for the output format, i.e.protected java.lang.String
getNodeSimpleName(Node t)
Get the simple name of a node.protected java.util.IdentityHashMap<Block,java.util.List<java.lang.Integer>>
getProcessOrder(ControlFlowGraph cfg)
Generate the order of processing blocks.protected java.lang.String
getProcessOrderSimpleString(java.util.List<java.lang.Integer> order)
Given a list of process orders (integers), returns a string representation.protected void
handleSuccessorsHelper(Block cur, java.util.Set<Block> visited, java.util.Queue<Block> workList, java.lang.StringBuilder sbGraph)
Outputs, to sbGraph, a visualization of a block's edges, but not the block itself.void
init(java.util.Map<java.lang.String,java.lang.Object> args)
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 java.lang.String
loopOverBlockContents(Block bb, @Nullable Analysis<V,S,T> analysis, java.lang.String separator)
Iterates over the block content and visualizes all the nodes in it.protected java.lang.String
visualizeBlockHelper(Block bb, @Nullable Analysis<V,S,T> analysis, java.lang.String separator)
Helper method to visualize a block.java.lang.String
visualizeBlockNode(Node t, @Nullable Analysis<V,S,T> analysis)
Visualize a Node based on the analysis.protected java.lang.String
visualizeBlockTransferInputHelper(AbstractCFGVisualizer.VisualizeWhere where, Block bb, Analysis<V,S,T> analysis, java.lang.String separator)
Visualize the transfer input before or after the given block.protected abstract java.lang.String
visualizeEdge(java.lang.Object sId, java.lang.Object eId, java.lang.String flowRule)
Generate the String representation of an edge.protected java.lang.String
visualizeGraph(ControlFlowGraph cfg, Block entry, @Nullable Analysis<V,S,T> analysis)
Visualize a control flow graph.protected abstract java.lang.String
visualizeGraphFooter()
Return the footer of the generated graph.protected abstract java.lang.String
visualizeGraphHeader()
Return the header of the generated graph.protected java.lang.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 java.lang.String
visualizeNodes(java.util.Set<Block> blocks, ControlFlowGraph cfg, @Nullable Analysis<V,S,T> analysis)
Generate the String representation of the nodes of a control flow graph.protected java.lang.String
visualizeSpecialBlockHelper(SpecialBlock sbb)
Visualize a special block.java.lang.String
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 Detail
-
verbose
protected boolean verbose
-
lineSeparator
protected static final java.lang.String lineSeparator
The line separator.
-
storeEntryIndent
protected static final java.lang.String storeEntryIndent
The indentation for elements of the store.- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(java.util.Map<java.lang.String,java.lang.Object> args)
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 java.lang.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
-
visualizeGraphWithoutHeaderAndFooter
protected java.lang.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.- Parameters:
cfg
- the control flow graphentry
- the entry block of the control flow graphanalysis
- the current analysis- Returns:
- the String representation of the control flow graph
-
handleSuccessorsHelper
protected void handleSuccessorsHelper(Block cur, java.util.Set<Block> visited, java.util.Queue<Block> workList, java.lang.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
protected void addBlock(Block b, java.util.Set<Block> visited, java.util.Queue<Block> workList)
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 java.lang.String visualizeBlockHelper(Block bb, @Nullable Analysis<V,S,T> analysis, java.lang.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 java.lang.String loopOverBlockContents(Block bb, @Nullable Analysis<V,S,T> analysis, java.lang.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
protected java.util.List<Node> addBlockContent(Block bb)
Returns the contents of the block.- Parameters:
bb
- the block- Returns:
- the contents of the block, as a list of nodes
-
format
protected abstract java.lang.String format(java.lang.Object obj)
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
public java.lang.String visualizeBlockNode(Node t, @Nullable Analysis<V,S,T> analysis)
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 java.lang.String visualizeBlockTransferInputHelper(AbstractCFGVisualizer.VisualizeWhere where, Block bb, Analysis<V,S,T> analysis, java.lang.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
protected java.lang.String visualizeSpecialBlockHelper(SpecialBlock sbb)
Visualize a special block.- Parameters:
sbb
- the special block- Returns:
- the String representation of the special block
-
getProcessOrder
protected java.util.IdentityHashMap<Block,java.util.List<java.lang.Integer>> getProcessOrder(ControlFlowGraph cfg)
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
public java.lang.String visualizeStore(S store)
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 java.lang.String visualizeNodes(java.util.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
protected abstract java.lang.String visualizeEdge(java.lang.Object sId, java.lang.Object eId, java.lang.String flowRule)
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
protected abstract java.lang.String visualizeGraphHeader()
Return the header of the generated graph.- Returns:
- the String representation of the header of the control flow graph
-
visualizeGraphFooter
protected abstract java.lang.String visualizeGraphFooter()
Return the footer of the generated graph.- Returns:
- the String representation of the footer of the control flow graph
-
getProcessOrderSimpleString
protected java.lang.String getProcessOrderSimpleString(java.util.List<java.lang.Integer> order)
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
protected java.lang.String getNodeSimpleName(Node t)
Get the simple name of a node.- Parameters:
t
- a node- Returns:
- the node's simple name, without "Node"
-
-