UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

77 lines 3.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processLocal = processLocal; const processor_1 = require("../../../../../processor"); const info_1 = require("../../../../../info"); const known_call_handling_1 = require("../known-call-handling"); const linker_1 = require("../../../../linker"); const common_1 = require("../common"); const unpack_argument_1 = require("../argument/unpack-argument"); const scoping_1 = require("../../../../../environments/scoping"); const identifier_1 = require("../../../../../environments/identifier"); const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument"); const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name"); const built_in_envir_utils_1 = require("./built-in-envir-utils"); /** * Processes a built-in 'local' function call. */ function processLocal(name, args, rootId, data, config) { if (args.length === 0) { return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information; } const params = { [config.args.expr]: 'expr', [config.args.env]: 'env', '...': '...' }; const argMaps = (0, linker_1.pMatch)((0, common_1.convertFnArguments)(args), params); const env = (0, unpack_argument_1.unpackArg)(r_argument_1.RArgument.getWithId(args, argMaps.get('env')?.[0])); const expr = (0, unpack_argument_1.unpackArg)(r_argument_1.RArgument.getWithId(args, argMaps.get('expr')?.[0])); if (!expr) { return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information; } /* when envir resolves to a tracked environment, evaluate expr inside it */ const envirResolution = env ? (0, built_in_envir_utils_1.resolveEnvirArg)(args, data, config.args.env) : undefined; const dfEnv = env ? (0, processor_1.processDataflowFor)(env, data) : info_1.DataflowInformation.initialize(rootId, data); if ((0, info_1.alwaysExits)(dfEnv)) { (0, common_1.patchFunctionCall)({ nextGraph: dfEnv.graph, rootId, name, data, argumentProcessResult: [dfEnv], origin: built_in_proc_name_1.BuiltInProcName.Local }); return dfEnv; } const baseEnvironment = envirResolution ? envirResolution.envirData.environment // evaluate in the tracked custom env : (0, scoping_1.pushLocalEnvironment)(data.environment); // normal new local scope const dfExpr = (0, processor_1.processDataflowFor)(expr, { ...data, environment: baseEnvironment }); (0, common_1.patchFunctionCall)({ nextGraph: dfEnv.graph, rootId, name, data, argumentProcessResult: [dfExpr, dfEnv], origin: built_in_proc_name_1.BuiltInProcName.Local }); const ingoing = dfEnv.in.concat(dfExpr.in, dfEnv.unknownReferences, dfExpr.unknownReferences); ingoing.push({ nodeId: rootId, name: name.content, cds: data.cds, type: identifier_1.ReferenceType.Function }); const baseResult = { hooks: dfExpr.hooks.concat(dfEnv.hooks), environment: envirResolution ? data.environment : (0, scoping_1.popLocalEnvironment)(dfExpr.environment), exitPoints: dfEnv.exitPoints.concat(dfExpr.exitPoints), graph: dfEnv.graph.mergeWith(dfExpr.graph), entryPoint: rootId, in: ingoing, out: dfExpr.out.concat(dfEnv.out), unknownReferences: [] }; /* move all definitions made inside the body into the custom env's tracked state */ if (envirResolution) { return (0, built_in_envir_utils_1.routeWrittenToCustomEnv)(baseResult, envirResolution.envDef, rootId); } return baseResult; } //# sourceMappingURL=built-in-local.js.map