UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

31 lines (30 loc) 1.72 kB
/** * An append-only builder for a {@link ControlFlowGraph}, used while folding the AST. * @module */ import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id'; import type { CfgEdge } from './control-flow-graph'; import { CfgVertex, ControlFlowGraph } from './control-flow-graph'; /** * Records the vertices and edges of a control flow graph instead of building it, as the bottom-up fold would * copy an eager graph once per nesting level. {@link CfgBuilder#mergeWith|mergeWith()} only references the other * builder, {@link CfgBuilder#materialize|materialize()} replays everything once in recording order &mdash; the * order an eager merge produced, which the vertex order of a function definition's children relies on. */ export declare class CfgBuilder { private readonly operations; addVertex(vertex: CfgVertex, rootVertex?: boolean): this; addEdge(from: NodeId, to: NodeId, edge: CfgEdge): this; /** * Record that the other builder is part of this one, it must not be modified afterwards. * @param other - the builder to include * @param forceNested - should its vertices count as nested (e.g., within a function definition) */ mergeWith(other: CfgBuilder, forceNested?: boolean): this; /** The last vertex recorded for the given id, searching the merged builders only if we hold none. */ getVertex(id: NodeId): CfgVertex | undefined; /** The ids of all vertices that are not nested, in insertion order. */ rootIds(collected?: Set<NodeId>): ReadonlySet<NodeId>; /** Replays all recorded operations into a {@link ControlFlowGraph}. */ materialize(graph?: ControlFlowGraph, nested?: boolean): ControlFlowGraph; }