A control flow graph either owns its vertices and edges, or is a view on the DataflowGraph that carries them: the dataflow extraction records the control flow while it walks the program, so every vertex of that graph is a vertex here and its flow and control dependency edges are the edges here.
Optionaldfg: DataflowGraph<DataflowGraphVertexInfo, DfEdge>
the dataflow graph to view, or nothing to build a graph of your own
Protected_used as an optimization to avoid unnecessary lookups
Protected Readonlybbthe basic block children map contains a mapping of ids to all vertices that are nested in basic blocks, mapping them to the Id of the block they appear in
Protected Readonlyedgebasic block agnostic edges, in flow order: edgeInfos[a][b] means that b is evaluated after a
Protectedrevreverse edges for bidirectional mapping, derived from edgeInfos on the first ingoing lookup
Protected ReadonlyrootsProtected ReadonlyvtxNesting-Independent vertex information, mapping the id to the vertex
Add a new vertex to the control flow graph.
The dataflow graph this control flow graph is a view of, undefined once it holds a copy of its own.
It knows the ast as well, so a traversal needs nothing but the control flow to reach either.
The constructs whose outcome this vertex decides, e.g. the if a condition belongs to.
Since a construct is reached only once its parts have run, standing on the condition is the moment to ask what that condition is for.
entryOf() - for the way back, from the construct to its condition
Get all edges in the graph, independent of their sources and targets (see ControlFlowGraph for their order). If you are only interested in the edges of a specific node, please use outgoingEdges() or ingoingEdges(). This is the pendant of edges() on a DataflowGraph.
The vertex control flow enters the construct rooted at id at, i.e. the first thing it evaluates.
For if(u) a else b that is the condition, for 2 * 3 the left operand, and for a leaf the leaf itself.
undefined if the construct is not part of the control flow at all.
exitOf() - for where it is over
The vertex a construct is over at, i.e. where its branches join and control flow continues past it.
The control flow is modeled in post-order: everything a construct is made of is evaluated before the
construct itself, so an if is over on the if vertex, a loop on its loop vertex, and 2 * 3 on the
* vertex. There is no separate marker to look for — reaching the vertex is the construct ending.
entryOf() - for where it begins instead
Obtain the basic block associated with the given element id (i.e. if this is an element within a basic block, return the blockit belongs to).
Check if a vertex with the given id exists in the graph.
the id of the vertex to check
if true, the elements of basic block elements are included in the check, otherwise this will only check the basic blocks themselves
This is the pendant of <a href="src_dataflow_graph_graph.DataflowGraph.html#hasvertex" class="tsd-kind-method">hasVertex()</a> on a <a href="src_dataflow_graph_graph.DataflowGraph.html" class="tsd-kind-class">DataflowGraph</a>.
The edges leading into the given vertex, i.e. what may be evaluated before it.
ProtectedmaterializeFill the state of this graph from the dataflow graph it views. Reading a view does not need this — the reads below are answered from the dataflow graph — but modifying one does, and so does asking for every vertex or edge at once.
Returns true if the graph may contain basic blocks and false if we know that it does not. This can be used for optimizations.
This Operation is in-place and modifies the current graph. Merge another control flow graph into this one.
the other control flow graph to merge into this one
should the other graph be assumed to be fully nested (e.g., within a function definition).
This is the pendant of <a href="src_dataflow_graph_graph.DataflowGraph.html#mergewith" class="tsd-kind-method">mergeWith()</a> on a <a href="src_dataflow_graph_graph.DataflowGraph.html" class="tsd-kind-class">DataflowGraph</a>.
The edges leaving the given vertex, i.e. what may be evaluated after it.
The vertices control flow may come from to reach id, i.e. what may have been evaluated before.
successors() - for the other direction
This removes the vertex and all edges to and from it.
the id of the vertex to remove
Get all ids of the root vertices — vertices that are not part of any function definition or basic block and hence part of the "top-level" control flow.
This is the pendant of rootIds() on a DataflowGraph.
The vertices control flow may reach directly from id, i.e. what may be evaluated next.
Prefer this over walking the edges by hand: a graph that is a view on another structure (see ControlFlowGraph) may answer it without projecting itself at all.
predecessors() - for the other direction
Serializing a graph hands out its vertices and edges, never the dataflow graph a view reads them from, so a view and a graph of its own serialize alike.
Provide a view of all vertices in the graph.
if true, the elements of basic block elements are included in the result, otherwise only the basic blocks themselves are included
This class represents the control flow graph of an R program. The control flow may be hierarchical when confronted with function definitions (see CfgVertex and ControlFlowGraph#rootIds|rootIds()).
Edges are in flow order: an edge from
atobmeans thatbis evaluated aftera. Reading them backwards (what leads into a vertex) goes through a reverse index built on the first such read.There are two very simple visitors to traverse a CFG:
If you want to prohibit modification, please refer to the ReadOnlyControlFlowGraph interface.