@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
48 lines • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processAttach = processAttach;
const known_call_handling_1 = require("../known-call-handling");
const unpack_argument_1 = require("../argument/unpack-argument");
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 identifier_1 = require("../../../../../environments/identifier");
const define_1 = require("../../../../../environments/define");
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
const edge_1 = require("../../../../../graph/edge");
const built_in_envir_utils_1 = require("./built-in-envir-utils");
/**
* Processes `attach(what, ...)` - when `what` is a variable that holds a tracked
* {@link InGraphIdentifierDefinition#envState}, all statically-known definitions from
* that environment are injected into the current scope so that subsequent reads of
* those names resolve correctly.
*/
function processAttach(name, args, rootId, data) {
const result = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Attach }).information;
const whatArg = args.length >= 1 ? args[0] : undefined;
const whatNode = whatArg && whatArg !== r_function_call_1.EmptyArgument ? (0, unpack_argument_1.unpackArg)(whatArg) : undefined;
if (whatNode?.type !== type_1.RType.Symbol) {
(0, unknown_side_effect_1.handleUnknownSideEffect)(result.graph, result.environment, rootId);
return result;
}
const envirResolution = (0, built_in_envir_utils_1.resolveSymbolToEnvir)(whatNode.content, whatNode.info.id, data);
if (!envirResolution) {
(0, unknown_side_effect_1.handleUnknownSideEffect)(result.graph, result.environment, rootId);
return result;
}
let newEnvironment = result.environment;
for (const [varName, varDefs] of envirResolution.envDef.envState.current.memory) {
for (const varDef of varDefs) {
const inDef = varDef;
const injected = {
...inDef,
name: varName,
type: identifier_1.ReferenceType.Variable,
};
newEnvironment = (0, define_1.define)(injected, false, newEnvironment);
result.graph.addEdge(inDef.nodeId, rootId, edge_1.EdgeType.Reads);
}
}
return { ...result, environment: newEnvironment };
}
//# sourceMappingURL=built-in-attach.js.map