@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
75 lines • 2.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processVector = processVector;
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
const known_call_handling_1 = require("../known-call-handling");
const config_1 = require("../../../../../../config");
const containers_1 = require("../../../../../../util/containers");
/**
* Process a vector call.
*
* Example:
* ```r
* c(1, 2, 3, 4)
* ```
*/
function processVector(name, args, rootId, data) {
const fnCall = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'builtin:vector' });
if (!(0, config_1.getConfig)().solver.pointerTracking) {
return fnCall.information;
}
let vectorArgs = [];
let argIndex = 1;
for (const arg of args) {
// Skip invalid argument types
if (arg === r_function_call_1.EmptyArgument || arg.type !== type_1.RType.Argument || arg.value === undefined) {
continue;
}
if (isPrimitive(arg.value.type)) {
vectorArgs.push({
identifier: { index: argIndex++ },
nodeId: arg.value.info.id,
});
}
else {
// Check whether argument value can be resolved
let indicesCollection;
if (arg.value.type === type_1.RType.Symbol) {
indicesCollection = (0, containers_1.resolveIndicesByName)(arg.value.lexeme, data.environment);
}
else {
// Check whether argument is nested container
indicesCollection = fnCall.information.graph.getVertex(arg.value.info.id)?.indicesCollection;
}
const flattenedIndices = indicesCollection?.flatMap(indices => indices.indices)
.map(index => {
return {
identifier: { index: argIndex++ },
nodeId: index.nodeId,
};
}) ?? [];
vectorArgs = vectorArgs.concat(flattenedIndices);
}
}
if ((0, config_1.isOverPointerAnalysisThreshold)(vectorArgs.length)) {
return fnCall.information;
}
const indices = {
indices: vectorArgs,
isContainer: true,
};
// Add resolved indices to vertex
const vertex = fnCall.information.graph.getVertex(rootId);
if (vertex) {
vertex.indicesCollection = [indices];
}
return fnCall.information;
}
/**
* Checks whether the passed type is primitive i.e. number, logical or string.
*/
function isPrimitive(type) {
return type === type_1.RType.Number || type === type_1.RType.Logical || type === type_1.RType.String;
}
//# sourceMappingURL=built-in-vector.js.map