@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
42 lines • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeDataflowLensQuery = executeDataflowLensQuery;
const log_1 = require("../../../util/log");
const dfg_view_1 = require("../../../util/simple-df/dfg-view");
const vertex_1 = require("../../../dataflow/graph/vertex");
const arguments_1 = require("../../../abstract-interpretation/data-frame/mappers/arguments");
const operators_1 = require("../../../r-bridge/lang-4.x/ast/model/operators");
/**
* The lens hides syntax: every operator R has, the native pipe (which {@link OperatorDatabase} does not list), and the
* control-flow keywords. None of them names anything, unlike the built-in *functions* (`print`, `ifelse`) it keeps.
* Anchored and escaped, as most of these are regex syntax themselves and an unanchored alternative would also drop
* every lexeme merely *containing* one (`if` in `identifier`).
*/
const HiddenLexemes = `^(${[...Object.keys(operators_1.OperatorDatabase), '|>', 'function', 'repeat', 'if', 'next', 'break']
.map(name => (0, arguments_1.escapeRegExp)(name)).join('|')})$`;
/**
* Executes the given dataflow lens queries using the provided analyzer.
*/
async function executeDataflowLensQuery({ analyzer }, queries) {
if (queries.length !== 1) {
log_1.log.warn('Dataflow query expects only up to one query, but got', queries.length);
}
const now = Date.now();
const simplifiedGraph = (0, dfg_view_1.reduceDfg)((await analyzer.dataflow()).graph, {
vertices: {
keepEnv: false,
keepCd: true,
tags: [vertex_1.VertexType.Use, vertex_1.VertexType.VariableDefinition, vertex_1.VertexType.FunctionDefinition, vertex_1.VertexType.FunctionCall],
nameRegex: HiddenLexemes,
blacklistWithName: true
}
}, analyzer.inspectContext().env.makeCleanEnv());
const timing = Date.now() - now;
return {
'.meta': {
timing
},
simplifiedGraph
};
}
//# sourceMappingURL=dataflow-lens-query-executor.js.map