UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

58 lines 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VisitingQueue = void 0; const fingerprint_1 = require("./fingerprint"); const static_slicer_1 = require("./static-slicer"); const assert_1 = require("../../util/assert"); class VisitingQueue { threshold; timesHitThreshold = 0; seen = new Map(); idThreshold = new Map(); queue = []; // the set of potential additions holds nodes which may be added if a second edge deems them relevant (e.g., found with the `defined-by-on-call` edge) // additionally it holds which node id added the addition so we can separate their inclusion on the structure potentialAdditions = new Map(); constructor(threshold) { this.threshold = threshold; } /** * Adds a node to the queue if it has not been seen before. * @param target - the node to add * @param env - the environment the node is traversed in * @param envFingerprint - the fingerprint of the environment * @param onlyForSideEffects - whether the node is only used for its side effects */ add(target, env, envFingerprint, onlyForSideEffects) { const idCounter = this.idThreshold.get(target) ?? 0; if (idCounter > this.threshold) { static_slicer_1.slicerLogger.warn(`id: ${target} has been visited ${idCounter} times, skipping`); this.timesHitThreshold++; return; } /* we do not include the in call part in the fingerprint as it is 'deterministic' from the source position */ const print = (0, fingerprint_1.fingerprint)(target, envFingerprint, onlyForSideEffects); if (!this.seen.has(print)) { this.idThreshold.set(target, idCounter + 1); this.seen.set(print, target); this.queue.push({ id: target, baseEnvironment: env, onlyForSideEffects }); } } next() { return this.queue.pop(); } nonEmpty() { return this.queue.length > 0; } hasId(id) { return this.idThreshold.has(id); } status() { return { timesHitThreshold: this.timesHitThreshold, result: new Set([...this.seen.values()].filter(assert_1.isNotUndefined)) }; } } exports.VisitingQueue = VisitingQueue; //# sourceMappingURL=visiting-queue.js.map