UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

41 lines 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pushLocalEnvironment = pushLocalEnvironment; exports.popLocalEnvironment = popLocalEnvironment; exports.padToCommonScope = padToCommonScope; const environment_1 = require("./environment"); const assert_1 = require("../../util/assert"); /** * Add a new local environment scope to the stack, returns the modified variant (shares the original stack, no deep-clone). * @see {@link popLocalEnvironment} - to remove the local scope again */ function pushLocalEnvironment({ level, current }) { return { current: new environment_1.Environment(current), level: level + 1 }; } /** * Remove the top local environment scope from the stack, returns the modified variant (shares the original stack, no deep-clone). * @see {@link pushLocalEnvironment} - to add a local scope */ function popLocalEnvironment({ current, level }) { (0, assert_1.guard)(level > 0, 'cannot remove the global/root environment'); return { current: current.parent, level: level - 1 }; } /** * Pads whichever of `base`/`next` is shallower with empty local scopes until both are at the same lexical {@link REnvironmentInformation#level|level}. */ function padToCommonScope(base, next) { while (next.level < base.level) { next = pushLocalEnvironment(next); } while (next.level > base.level) { base = pushLocalEnvironment(base); } return { base, next }; } //# sourceMappingURL=scoping.js.map