UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

52 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.remove = remove; exports.removeAll = removeAll; const info_1 = require("../info"); const clone_1 = require("./clone"); /** * Removes all definitions of a given name from the environment. */ function remove(name, environment, defaultEnvironment) { let current = environment.current; do { const definition = current.memory.get(name); if (definition !== undefined) { current.memory.delete(name); if (definition.every(d => (0, info_1.happensInEveryBranch)(d.controlDependencies))) { break; } } current = current.parent; } while (current.id !== defaultEnvironment.id); // we never remove built ins return environment; } /** Creates a copy of the original environment but without the definitions of the given ids */ function removeAll(definitions, environment) { environment = (0, clone_1.cloneEnvironmentInformation)(environment, true); let current = environment.current; do { for (const { nodeId, name } of definitions) { if (name) { current.memory.delete(name); } else { // remove all definitions for the node id for (const [key, values] of current.memory) { const res = values.filter(v => v.nodeId === nodeId); if (res.length > 0) { current.memory.set(key, values); } else { current.memory.delete(key); } } } } current = current.parent; } while (!current.builtInEnv); // we never remove built ins so we can stop one early return environment; } //# sourceMappingURL=remove.js.map