UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

84 lines 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processList = processList; 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 list call. * * Example: * ```r * list(a = 1, b = 2) * ``` */ function processList(name, args, rootId, data) { const fnCall = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data }); if (!(0, config_1.getConfig)().solver.pointerTracking) { return fnCall.information; } const listArgs = []; for (const arg of args) { // Skip non named arguments if (arg === r_function_call_1.EmptyArgument || arg.type !== type_1.RType.Argument || arg.value === undefined) { continue; } let newIndex; if (arg.name) { // Named argument newIndex = { identifier: { index: arg.info.index, lexeme: arg.name.content }, nodeId: arg.info.id, }; } else { // Unnamed argument newIndex = { identifier: { index: arg.info.index, }, nodeId: arg.value.info.id, }; } // Check whether argument value can be resolved if (arg.value.type === type_1.RType.Symbol) { const indicesCollection = (0, containers_1.resolveIndicesByName)(arg.value.lexeme, data.environment); if (indicesCollection) { newIndex = { ...newIndex, subIndices: indicesCollection, }; } } else { // Check whether argument is nested container const indicesCollection = fnCall.information.graph.getVertex(arg.value.info.id)?.indicesCollection; if (indicesCollection) { newIndex = { ...newIndex, subIndices: indicesCollection, }; } } listArgs.push(newIndex); } if ((0, config_1.isOverPointerAnalysisThreshold)(listArgs.length)) { return fnCall.information; } const indices = { indices: listArgs, isContainer: true, }; // Add resolved indices to vertex const vertex = fnCall.information.graph.getVertex(rootId); if (vertex) { vertex.indicesCollection = [indices]; } return fnCall.information; } //# sourceMappingURL=built-in-list.js.map