UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

48 lines 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllRefsToSymbol = getAllRefsToSymbol; const edge_1 = require("../graph/edge"); const info_1 = require("../info"); const df_helper_1 = require("../graph/df-helper"); /** * Finds the definition of a variable and all other uses from that point on * * For example, for the following code * ```ts * y <- 5 * f <- function() { * y <- 8 * print(y) * } * ``` * @example getAllRefsToSymbol('3\@y') returns ['3\@y', '4\@y'] * @param graph - Dataflow Graph * @param nodeId - NodeId of Symbol to resolve * @returns List including the Definitions and References to that definition */ function getAllRefsToSymbol(graph, nodeId) { // Get all origins and filter for ones that happen for sure const origins = df_helper_1.Dataflow.origin(graph, nodeId); if (origins === undefined) { return undefined; } const definitiveOrigins = origins.filter(o => (0, info_1.happensInEveryBranch)(graph.getVertex(o.id)?.cds)); if (definitiveOrigins.length === 0) { return undefined; } // Gather all the references const res = new Set(); for (const { id } of definitiveOrigins) { res.add(id); graph.ingoingEdges(id) ?.entries() .filter(([_, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) .forEach(([node, _]) => res.add(node)); graph.outgoingEdges(id) ?.entries() .filter(([_, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedByOnCall)) .forEach(([node, _]) => res.add(node)); } return [...res]; } //# sourceMappingURL=dfg-get-symbol-refs.js.map