@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
30 lines • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.visitCfgInReverseOrder = visitCfgInReverseOrder;
/**
* Visit all nodes reachable from the start node in the control flow graph, traversing the dependencies but ignoring cycles.
* @param graph - The control flow graph.
* @param startNode - The node to start the traversal from.
* @param visitor - The visitor function to call for each node, if you return true the traversal from this node will be stopped.
*/
function visitCfgInReverseOrder(graph, startNode,
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type -- void is used to indicate that the return value is ignored/we never stop
visitor) {
const visited = new Set();
const queue = [startNode];
while (queue.length > 0) {
const current = queue.pop();
if (visited.has(current)) {
continue;
}
visited.add(current);
if (visitor(current)) {
continue;
}
const incoming = graph.outgoing(current) ?? [];
for (const [from] of incoming) {
queue.push(from);
}
}
}
//# sourceMappingURL=visitor.js.map