UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

52 lines 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processList = processList; exports.resolveListToEnvState = resolveListToEnvState; 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 built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name"); const identifier_1 = require("../../../../../environments/identifier"); const define_1 = require("../../../../../environments/define"); const scoping_1 = require("../../../../../environments/scoping"); const resolve_helper_1 = require("../../../../../environments/resolve-helper"); /** * Process a list call. * * Example: * ```r * list(a = 1, b = 2) * ``` */ function processList(name, args, rootId, data) { return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.List }).information; } /** Records a `list(...)`'s named function entries as a resolvable pseudo-env, so `d$foo(...)`/`d[["foo"]](...)` link to them; `undefined` if none. */ function resolveListToEnvState(source, data) { if (!r_function_call_1.RFunctionCall.isNamed(source)) { return undefined; } let envState = (0, scoping_1.pushLocalEnvironment)(data.environment); let found = false; for (const arg of source.arguments) { if (arg === r_function_call_1.EmptyArgument || arg.name === undefined || arg.value === undefined) { continue; } const value = arg.value; const isFn = value.type === type_1.RType.FunctionDefinition || (value.type === type_1.RType.Symbol && (resolve_helper_1.Resolve.byNameAndType(value.content, data.environment, identifier_1.ReferenceType.Function)?.length ?? 0) > 0); if (!isFn) { continue; } envState = (0, define_1.define)({ type: identifier_1.ReferenceType.Function, name: arg.name.content, nodeId: value.info.id, definedAt: value.info.id, cds: undefined }, false, envState); found = true; } return found ? envState : undefined; } //# sourceMappingURL=built-in-list.js.map