@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
55 lines • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultAllVariablesFilter = void 0;
const assert_1 = require("../../../util/assert");
const fold_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/fold");
const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
exports.DefaultAllVariablesFilter = {
minimumSize: 1,
maximumSize: 1,
collectAll: defaultAllVariablesCollector
};
const onLeaf = () => [];
const onBinary = (_, lhs, rhs) => [...lhs, ...rhs];
const defaultAllVariablesCollectorFolds = {
foldNumber: onLeaf,
foldString: onLeaf,
foldLogical: onLeaf,
foldSymbol: (symbol) => (0, r_symbol_1.isSpecialSymbol)(symbol) ? [] : [symbol.info.id],
foldAccess: (_, name, access) => [...name, ...access.filter(assert_1.isNotNull).flat()],
foldBinaryOp: onBinary,
foldPipe: onBinary,
foldUnaryOp: (_, operator) => operator,
loop: {
foldFor: (_, a, b, c) => [...a, ...b, ...c],
foldWhile: (_, a, b) => [...a, ...b],
foldRepeat: (_, a) => a,
foldNext: onLeaf,
foldBreak: onLeaf
},
other: {
foldComment: onLeaf,
foldLineDirective: onLeaf
},
foldIfThenElse: (_, a, b, c) => [...a, ...b, ...(c ?? [])],
foldExprList: (_, _grouping, a) => a.flat(),
functions: {
foldFunctionDefinition: (_, a, b) => [...a.flat(), ...b],
foldFunctionCall: (c, a, b) => {
const args = b.flatMap(b => b !== r_function_call_1.EmptyArgument ? b.flat() : []);
if (c.named) {
return c.functionName.content === 'library' ? args.slice(1) : args;
}
else {
return [...a.filter(x => x !== r_function_call_1.EmptyArgument), ...args];
}
},
foldArgument: (_, _a, b) => b ?? [],
foldParameter: (_, _a, b) => b ?? []
}
};
function defaultAllVariablesCollector(ast) {
return (0, fold_1.foldAst)(ast, defaultAllVariablesCollectorFolds);
}
//# sourceMappingURL=all-variables.js.map