UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

59 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transitiveLibraryCallees = transitiveLibraryCallees; exports.expandCallGraphLibraryInternals = expandCallGraphLibraryInternals; const node_id_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/node-id"); const graph_1 = require("../../../dataflow/graph/graph"); const edge_1 = require("../../../dataflow/graph/edge"); /** * The transitive internal callees of a library/built-in leaf call `id` (a `built-in:pkg:fn` node id), resolved * from the project's loaded signature-database sources. */ function transitiveLibraryCallees(id, deps) { const pkgFn = node_id_1.NodeId.toPkgFn(id); if (pkgFn === undefined) { return undefined; } const [pkg, fn] = pkgFn; const version = deps.getDependency(pkg)?.resolvedVersion; for (const src of deps.signatureSources()) { if (!src.has(pkg)) { continue; } const callees = (version !== undefined ? src.transitiveCallees(pkg, fn, version) : undefined) ?? src.transitiveCallees(pkg, fn); if (callees !== undefined) { return { pkg, callees }; } } return undefined; } /** * Expands every library/built-in leaf call reachable in `graph` into its internal callees (see * {@link transitiveLibraryCallees}), adding one synthetic `pkg:calleeName` edge per expanded callee straight off * the leaf. Returns a fresh copy of `graph`. */ function expandCallGraphLibraryInternals(graph, deps) { const augmented = new graph_1.DataflowGraph(graph.idMap); augmented.mergeVertices(graph); const cache = new Map(); for (const [from, tos] of graph.edges()) { for (const [to, edge] of tos.entries()) { augmented.addEdge(from, to, edge.types); if (!node_id_1.NodeId.isBuiltIn(to)) { continue; } if (!cache.has(to)) { cache.set(to, transitiveLibraryCallees(to, deps)); } const expansion = cache.get(to); if (expansion === undefined) { continue; } for (const callee of expansion.callees) { augmented.addEdge(to, node_id_1.NodeId.fromPkgFn(expansion.pkg, callee), edge_1.EdgeType.Calls); } } } return augmented; } //# sourceMappingURL=expand-library-internals.js.map