UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

58 lines 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processNamespaceAccess = processNamespaceAccess; const known_call_handling_1 = require("../known-call-handling"); const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call"); const logger_1 = require("../../../../../logger"); const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type"); const identifier_1 = require("../../../../../environments/identifier"); const graph_1 = require("../../../../../graph/graph"); const vertex_1 = require("../../../../../graph/vertex"); const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name"); const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string"); /** * Processes `::` and `:::` when called as a function, e.g., `::`(ggplot2, a). * Constructs a namespaced symbol identical to what tree-sitter produces for `ggplot2::a`. */ function processNamespaceAccess(name, args, rootId, data, config) { if (args.length !== 2 || args[0] === r_function_call_1.EmptyArgument || args[1] === r_function_call_1.EmptyArgument) { logger_1.dataflowLogger.warn(`Namespace access ${identifier_1.Identifier.toString(name.content)} does not have exactly 2 non-empty arguments, falling back`); return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.NamespaceAccess }).information; } const nsNode = args[0].value; const symNode = args[1].value; let namespace; let symbolName; if (nsNode?.type === type_1.RType.Symbol) { namespace = identifier_1.Identifier.getName(nsNode.content); } else if (nsNode && r_string_1.RString.is(nsNode)) { namespace = nsNode.content.str; } if (symNode?.type === type_1.RType.Symbol) { symbolName = identifier_1.Identifier.getName(symNode.content); } else if (symNode && r_string_1.RString.is(symNode)) { symbolName = symNode.content.str; } if (!namespace || !symbolName) { logger_1.dataflowLogger.warn(`Namespace access ${identifier_1.Identifier.toString(name.content)} has non-symbol/string arguments, falling back`); return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.NamespaceAccess }).information; } const id = identifier_1.Identifier.make(symbolName, namespace, config.internal); return { unknownReferences: [{ nodeId: rootId, name: id, cds: data.cds, type: identifier_1.ReferenceType.Unknown }], in: [], out: [], environment: data.environment, graph: new graph_1.DataflowGraph(data.completeAst.idMap).addVertex({ tag: vertex_1.VertexType.Use, id: rootId, cds: data.cds }, data.ctx.env.makeCleanEnv()), entryPoint: rootId, exitPoints: [{ nodeId: rootId, type: 0 /* ExitPointType.Default */, cds: data.cds }], hooks: [] }; } //# sourceMappingURL=built-in-namespace-access.js.map