UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

66 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFunctionsToConsiderInCallGraph = getFunctionsToConsiderInCallGraph; exports.executeExceptionQuery = executeExceptionQuery; const parse_1 = require("../../../slicing/criterion/parse"); const vertex_1 = require("../../../dataflow/graph/vertex"); const exceptions_of_function_1 = require("../../../dataflow/fn/exceptions-of-function"); /** * Get the functions to consider in the call graph based on the given queries. */ async function getFunctionsToConsiderInCallGraph(queries, analyzer, onlyDefinitions = true) { let filters = undefined; // filter will remain undefined if at least one of the queries wants all functions for (const q of queries) { if (q.filter === undefined) { filters = undefined; break; } else { filters ??= []; filters = filters.concat(q.filter); } } const ast = await analyzer.normalize(); const filterFor = new Set(); if (filters) { for (const f of filters) { const i = parse_1.SlicingCriterion.tryParse(f, ast.idMap); if (i !== undefined) { filterFor.add(i); } } } const cg = await analyzer.callGraph(); let fns = (onlyDefinitions || filterFor.size === 0 ? cg.verticesOfType(vertex_1.VertexType.FunctionDefinition) : cg.vertices(true)); if (filterFor.size > 0) { fns = fns.filter(([id]) => filterFor.has(id)); } return { cg, fns }; } /** * Execute exception function inspection queries on the given analyzer. */ async function executeExceptionQuery({ analyzer }, queries) { const start = Date.now(); const { cg, fns } = await getFunctionsToConsiderInCallGraph(queries, analyzer); const result = {}; for (const [id] of fns) { if (result[id]) { continue; } const res = (0, exceptions_of_function_1.calculateExceptionsOfFunction)(id, cg, result); for (const [k, v] of Object.entries(res)) { if (!result[k]) { result[k] = v; } } } return { '.meta': { timing: Date.now() - start }, exceptions: result }; } //# sourceMappingURL=inspect-exception-query-executor.js.map