UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

45 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processLibrary = processLibrary; const known_call_handling_1 = require("../known-call-handling"); const logger_1 = require("../../../../../logger"); const unpack_argument_1 = require("../argument/unpack-argument"); const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type"); const make_argument_1 = require("../argument/make-argument"); const identifier_1 = require("../../../../../environments/identifier"); const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name"); /** * Process a library call like `library` or `require` */ function processLibrary(name, args, rootId, data) { /* we do not really know what loading the library does and what side effects it causes, hence we mark it as an unknown side effect */ if (args.length !== 1) { logger_1.dataflowLogger.warn(`Currently only one-arg library-likes are allows (for ${identifier_1.Identifier.toString(name.content)}), skipping`); return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: true, origin: 'default' }).information; } const nameToLoad = (0, unpack_argument_1.unpackNonameArg)(args[0]); if (nameToLoad === undefined || nameToLoad.type !== type_1.RType.Symbol) { logger_1.dataflowLogger.warn('No library name provided, skipping'); return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: true, origin: 'default' }).information; } if (identifier_1.Identifier.getNamespace(nameToLoad.content) !== undefined) { logger_1.dataflowLogger.warn('Namespaced library names are not supported, ignoring namespace'); } // treat as a function call but convert the first argument to a string const newArg = { type: type_1.RType.String, info: nameToLoad.info, lexeme: nameToLoad.lexeme, location: nameToLoad.location, content: { quotes: 'none', str: identifier_1.Identifier.getName(nameToLoad.content) } }; return (0, known_call_handling_1.processKnownFunctionCall)({ name, args: (0, make_argument_1.wrapArgumentsUnnamed)([newArg], data.completeAst.idMap), rootId, data, hasUnknownSideEffect: true, origin: built_in_proc_name_1.BuiltInProcName.Library }).information; } //# sourceMappingURL=built-in-library.js.map