@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
58 lines • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeDfShapeQuery = executeDfShapeQuery;
const shape_inference_1 = require("../../../abstract-interpretation/data-frame/shape-inference");
const cfg_kind_1 = require("../../../project/cfg-kind");
const parse_1 = require("../../../slicing/criterion/parse");
const log_1 = require("../../../util/log");
/**
* Executes the given data frame shape queries using the provided analyzer.
*/
async function executeDfShapeQuery({ analyzer }, queries) {
if (queries.length !== 1 && queries.some(query => query.criterion === undefined)) {
log_1.log.warn('The dataframe shape query expects only up to one query without slicing criterion, but got', queries.length);
queries = [{ type: 'df-shape' }];
}
const ast = await analyzer.normalize();
const dfg = (await analyzer.dataflow()).graph;
const cfg = await analyzer.controlflow(undefined, cfg_kind_1.CfgKind.NoFunctionDefs);
const start = Date.now();
const inference = new shape_inference_1.DataFrameShapeInferenceVisitor({ controlFlow: cfg, dfg, normalizedAst: ast, ctx: analyzer.inspectContext() });
inference.start();
const domains = inference.getEndState();
if (queries.length === 1 && queries[0].criterion === undefined) {
return {
'.meta': {
timing: Date.now() - start
},
domains: domains
};
}
const result = new Map();
for (const query of queries) {
if (query.criterion === undefined) {
log_1.log.warn('Missing criterion in dataframe shape query');
continue;
}
else if (result.has(query.criterion)) {
log_1.log.warn('Duplicate criterion in dataframe shape query:', query.criterion);
continue;
}
try {
const nodeId = parse_1.SlicingCriterion.parse(query.criterion, ast.idMap);
const node = ast.idMap.get(nodeId);
const value = inference.getAbstractValue(node?.info.id);
result.set(query.criterion, value);
}
catch (e) {
console.error(e instanceof Error ? e.message : e);
}
}
return {
'.meta': {
timing: Date.now() - start
},
domains: result
};
}
//# sourceMappingURL=df-shape-query-executor.js.map