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 analysis
S - the store type used in the analysis
T - the transfer function type that is used to approximate run-time 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:
  • Field Details

    • verbose

      protected boolean verbose
      If true, CFGVisualizer returns more detailed information.

      Initialized in init(Map).

    • lineSeparator

      protected static final String lineSeparator
      The line separator.
    • storeEntryIndent

      protected static final String storeEntryIndent
      The indentation for elements of the store.
      See Also:
  • Constructor Details

    • AbstractCFGVisualizer

      public AbstractCFGVisualizer()
  • Method Details

    • init

      public void init(Map<String,Object> args)
      Description copied from interface: CFGVisualizer
      Specified by:
      init in interface CFGVisualizer<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 graph
      entry - the entry block of the control flow graph
      analysis - the current analysis
      Returns:
      the representation of the control flow graph
    • visualizeGraphWithoutHeaderAndFooter

      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.
      Parameters:
      cfg - the control flow graph
      entry - the entry block of the control flow graph
      analysis - the current analysis
      Returns:
      the String 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 block
      visited - the set of blocks that have already been visited or are in the work list; side effected by this method
      workList - the queue of blocks to be processed; side effected by this method
      sbGraph - the StringBuilder to store the graph; side effected by this method
    • addBlock

      protected void addBlock(Block b, Set<Block> visited, 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 check
      visited - the set of blocks that have already been visited or are in the work list
      workList - the queue of blocks to be processed
    • visualizeBlockWithSeparator

      protected String visualizeBlockWithSeparator(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 block
      analysis - the current analysis
      separator - the line separator. Examples: "\\l" for left justification in DOTCFGVisualizer (this is really a terminator, not a separator), "\n" or System.lineSeparator() to add a new line in StringCFGVisualizer
      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 block
      analysis - the current analysis
      separator - the separator between the nodes of the block
      Returns:
      the String representation of the contents of the block
    • addBlockContent

      protected 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
    • escapeString

      protected String escapeString(String str)
      Make the string suitable for the output format, i.e. with format-specific characters escaped.
      Parameters:
      str - a string
      Returns:
      the escaped string
    • escapeString

      protected final String escapeString(Object obj)
      Make the object's string representation suitable for the output format, i.e. with format-specific characters escaped.
      Parameters:
      obj - an object
      Returns:
      the object's string representation, escaped
    • visualizeBlockNode

      public String visualizeBlockNode(Node n, @Nullable Analysis<V,S,T> analysis)
      Description copied from interface: CFGVisualizer
      Visualize a Node based on the analysis.
      Specified by:
      visualizeBlockNode in interface CFGVisualizer<V extends AbstractValue<V>,S extends Store<S>,T extends TransferFunction<V,S>>
      Parameters:
      n - the node
      analysis - 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 the transfer result after, the given block. The transfer input and the transfer result contain stores and other information.
      Parameters:
      where - either BEFORE or AFTER
      bb - a block
      analysis - the current analysis
      separator - the line separator. Examples: "\\l" for left justification in DOTCFGVisualizer (which is actually a line TERMINATOR, not a separator!), "\n" or System.lineSeparator() to add a new line in StringCFGVisualizer
      Returns:
      the visualization of the transfer input before or after the given block
    • visualizeSpecialBlockHelper

      protected String visualizeSpecialBlockHelper(SpecialBlock sbb)
      Visualize a special block.
      Parameters:
      sbb - the special block
      Returns:
      the String representation of the special block
    • getProcessOrder

      protected IdentityHashMap<Block,List<Integer>> getProcessOrder(ControlFlowGraph cfg)
      Generate the order of processing blocks. Because a block may appear more than once in ControlFlowGraph.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 String visualizeStore(S store)
      Description copied from interface: CFGVisualizer
      Delegate the visualization responsibility to the passed Store instance, which will call back to this visualizer instance for sub-components.
      Specified by:
      visualizeStore in interface CFGVisualizer<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 graph
      cfg - the control flow graph
      analysis - the current analysis
      Returns:
      the String representation of the nodes
    • visualizeEdge

      protected abstract String visualizeEdge(Object sId, Object eId, String flowRule)
      Generate the String representation of an edge.
      Parameters:
      sId - a representation of the current block, such as its ID
      eId - a representation of the successor block, such as its ID
      flowRule - the content of the edge
      Returns:
      the String representation of the edge
    • visualizeGraphHeader

      protected abstract String visualizeGraphHeader()
      Return the header of the generated graph.
      Returns:
      the String representation of the header of the control flow graph
    • visualizeGraphFooter

      protected abstract String visualizeGraphFooter()
      Return the footer of the generated graph.
      Returns:
      the String representation of the footer of the control flow graph
    • getProcessOrderSimpleString

      protected String getProcessOrderSimpleString(List<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 String getNodeSimpleName(Node n)
      Get the simple name of a node.
      Parameters:
      n - a node
      Returns:
      the node's simple name, without "Node"