@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
32 lines • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.happensBefore = happensBefore;
const logic_1 = require("../logic");
/**
* Determines if node `a` happens before node `b` in the control flow graph.
*/
function happensBefore(cfg, a, b) {
const visited = new Set();
/* the first is the id we are currently at, the second one the exit marker of the current largest cd scope */
const stack = [[b, undefined]];
while (stack.length > 0) {
const [current, cd] = stack.pop();
let useCd = cd;
if (current === a) {
return cd ? logic_1.Ternary.Maybe : logic_1.Ternary.Always;
}
else if (visited.has(current)) {
continue;
}
else if (cd && (current === cd || visited.has(cd))) {
useCd = undefined;
}
visited.add(current);
for (const [id, t] of cfg.outgoing(current) ?? []) {
const marker = t.label === 'CD' ? `${t.caused}-exit` : useCd;
stack.push([id, useCd ?? marker]);
}
}
return logic_1.Ternary.Never;
}
//# sourceMappingURL=happens-before.js.map