UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

54 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RFunctionCall = exports.EmptyArgument = void 0; const model_1 = require("../model"); const type_1 = require("../type"); const arg_matching_1 = require("../../../../../util/arg-matching"); exports.EmptyArgument = '<>'; /** * Helper for working with {@link RFunctionCall} AST nodes. */ exports.RFunctionCall = { ...model_1.RNode, name: 'RFunctionCall', /** * Type guard for {@link RFunctionCall} nodes. */ is(node) { return node?.type === type_1.RType.FunctionCall; }, /** * Type guard for {@link RNamedFunctionCall} nodes. */ isNamed(node) { return exports.RFunctionCall.is(node) && node.named === true; }, /** * Type guard for {@link RUnnamedFunctionCall} nodes. */ isUnnamed(node) { return exports.RFunctionCall.is(node) && !node.named; }, /** * Bind a call's `arguments` to the formal `paramNames` with {@link matchArgumentsToParameters}, R's argument * matching. Returns a map from parameter name to the argument bound to it, so * `matchArgsToParams(call.arguments, names).get('X')` answers "which argument is mapped to parameter `X`". * An empty argument (`f(1, ,3)`) takes its formal but never appears in the map, as there is nothing to bind. */ matchArgsToParams(args, paramNames) { const matched = (0, arg_matching_1.matchArgumentsToParameters)(args.map(a => a === exports.EmptyArgument ? undefined : a.name?.content), paramNames); const bound = new Map(); for (let i = 0; i < args.length; i++) { const arg = args[i], param = matched[i]; if (arg !== exports.EmptyArgument && param !== undefined) { bound.set(paramNames[param], arg); } } return bound; }, /** The one argument a call was given, `undefined` unless there is exactly one and it is not empty. */ soleArgument(args) { return args.length === 1 && args[0] !== exports.EmptyArgument ? args[0] : undefined; } }; //# sourceMappingURL=r-function-call.js.map