UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

46 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.appendEnvironment = appendEnvironment; const assert_1 = require("../../util/assert"); const environment_1 = require("./environment"); function uniqueMergeValues(old, value) { const result = old; for (const v of value) { const find = result.findIndex(o => o.nodeId === v.nodeId && o.definedAt === v.definedAt); if (find < 0) { result.push(v); } } return result; } function appendIEnvironmentWith(base, next) { (0, assert_1.guard)(base !== undefined && next !== undefined, 'can not append environments with undefined'); const map = new Map(base.memory); for (const [key, value] of next.memory) { const old = map.get(key); if (old) { map.set(key, uniqueMergeValues(old, value)); } else { map.set(key, value); } } const parent = base.parent === environment_1.BuiltInEnvironment ? environment_1.BuiltInEnvironment : appendIEnvironmentWith(base.parent, next.parent); const out = new environment_1.Environment(parent); out.memory = map; return out; } function appendEnvironment(base, next) { if (base === undefined) { return next; } else if (next === undefined) { return base; } (0, assert_1.guard)(base.level === next.level, 'environments must have the same level to be handled, it is up to the caller to ensure that'); return { current: appendIEnvironmentWith(base.current, next.current), level: base.level, }; } //# sourceMappingURL=append.js.map