@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
39 lines • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.uniqueMergeValuesInDefinitions = uniqueMergeValuesInDefinitions;
exports.appendEnvironment = appendEnvironment;
const scoping_1 = require("./scoping");
/**
* Merges two arrays of identifier definitions, ensuring uniqueness based on `nodeId` and `definedAt`.
*/
function uniqueMergeValuesInDefinitions(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 appendEnvironment(base, next) {
if (base === undefined) {
return next;
}
else if (next === undefined) {
return base;
}
if (base.level !== next.level) {
while (next.level < base.level) {
next = (0, scoping_1.pushLocalEnvironment)(next);
}
while (next.level > base.level) {
base = (0, scoping_1.pushLocalEnvironment)(base);
}
}
return {
current: base.current.append(next.current),
level: base.level,
};
}
//# sourceMappingURL=append.js.map