UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

68 lines 3.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processPipe = processPipe; const known_call_handling_1 = require("../known-call-handling"); const assert_1 = require("../../../../../../util/assert"); const unpack_argument_1 = require("../argument/unpack-argument"); const logger_1 = require("../../../../../logger"); const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type"); const vertex_1 = require("../../../../../graph/vertex"); const edge_1 = require("../../../../../graph/edge"); const identifier_1 = require("../../../../../environments/identifier"); const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name"); /** * Suport for R's pipe functions like `|>`. */ function processPipe(name, args, rootId, data) { const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Pipe }); if (args.length !== 2) { logger_1.dataflowLogger.warn(`Pipe ${identifier_1.Identifier.toString(name.content)} has something else than 2 arguments, skipping`); return information; } const [lhs, rhs] = args.map(e => (0, unpack_argument_1.unpackNonameArg)(e)); (0, assert_1.guard)(lhs !== undefined && rhs !== undefined, () => `lhs and rhs must be present, but ${JSON.stringify(lhs)} and ${JSON.stringify(rhs)} were found instead.`); if (rhs.type === type_1.RType.FunctionCall) { const functionCallNode = information.graph.getVertex(rhs.info.id); (0, assert_1.guard)(functionCallNode?.tag === vertex_1.VertexType.FunctionCall, () => `Expected function call node with id ${rhs.info.id} to be a function call node, but got ${functionCallNode?.tag} instead.`); // make the lhs an argument node: const argId = lhs.info.id; logger_1.dataflowLogger.trace(`Linking pipe arg ${argId} as first argument of ${rhs.info.id}`); functionCallNode.args.unshift({ name: undefined, nodeId: argId, cds: data.cds, type: identifier_1.ReferenceType.Function }); information.graph.addEdge(functionCallNode.id, argId, edge_1.EdgeType.Argument | edge_1.EdgeType.Reads); } else { logger_1.dataflowLogger.warn(`Expected rhs of pipe to be a function call, but got ${rhs.type} instead.`); } const firstArgument = processedArguments[0]; const uniqueIn = information.in.slice(); for (const ing of (firstArgument?.in ?? [])) { if (!uniqueIn.some(e => e.nodeId === ing.nodeId)) { uniqueIn.push(ing); } } const uniqueOut = information.out.slice(); for (const outg of (firstArgument?.out ?? [])) { if (!uniqueOut.some(e => e.nodeId === outg.nodeId)) { uniqueOut.push(outg); } } const uniqueUnknownReferences = information.unknownReferences.slice(); for (const unknown of (firstArgument?.unknownReferences ?? [])) { if (!uniqueUnknownReferences.some(e => e.nodeId === unknown.nodeId)) { uniqueUnknownReferences.push(unknown); } } return { ...information, in: uniqueIn, out: uniqueOut, unknownReferences: uniqueUnknownReferences, entryPoint: rootId }; } //# sourceMappingURL=built-in-pipe.js.map