@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
37 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toUnnamedArgument = toUnnamedArgument;
exports.wrapArgumentsUnnamed = wrapArgumentsUnnamed;
const range_1 = require("../../../../../../util/range");
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
const graph_1 = require("../../../../../graph/graph");
/**
* Converts a normalized node into an unnamed argument (wraps it with an argument node).
*/
function toUnnamedArgument(node, idMap) {
if (node === undefined) {
return r_function_call_1.EmptyArgument;
}
const arg = {
type: type_1.RType.Argument,
lexeme: node.lexeme ?? '',
location: node.location ?? range_1.SourceRange.invalid(),
info: {
...node.info,
id: node.info.id + '-arg'
},
name: undefined,
value: node
};
idMap.set(arg.info.id, node);
return arg;
}
/**
* Wraps the given nodes as unnamed arguments where necessary.
*/
function wrapArgumentsUnnamed(nodes, idMap) {
return nodes.map(n => graph_1.FunctionArgument.isEmpty(n) || r_argument_1.RArgument.is(n) ? n : toUnnamedArgument(n, idMap));
}
//# sourceMappingURL=make-argument.js.map