@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
71 lines • 2.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PosIntervalDomain = exports.PosIntervalTop = void 0;
const abstract_domain_1 = require("./abstract-domain");
const interval_domain_1 = require("./interval-domain");
const lattice_1 = require("./lattice");
/** The Top element of the positive interval domain as interval [0, +∞] */
exports.PosIntervalTop = [0, +Infinity];
/**
* The positive interval abstract domain as positive intervals with possibly zero lower bounds and infinite upper bounds representing possible numeric values.
* The Bottom element is defined as {@link Bottom} symbol and the Top element is defined as the interval [0, +∞].
* @template Value - Type of the constraint in the abstract domain (Top, Bottom, or an actual value)
*/
class PosIntervalDomain extends interval_domain_1.IntervalDomain {
constructor(value) {
if (Array.isArray(value) && value[0] < 0) {
super(lattice_1.Bottom);
}
else {
super(value);
}
}
create(value) {
return new PosIntervalDomain(value);
}
static top() {
return new this(exports.PosIntervalTop);
}
static bottom() {
return new this(lattice_1.Bottom);
}
top() {
return this.create(exports.PosIntervalTop);
}
widenValue(other) {
return this.create([
this.lower <= other.lower ? this.lower : 0,
this.upper >= other.upper ? this.upper : +Infinity
]);
}
narrowValue(other) {
if (Math.max(this.lower, other.lower) > Math.min(this.upper, other.upper)) {
return this.bottom();
}
return this.create([
this.lower === 0 ? other.lower : this.lower,
this.upper === +Infinity ? other.upper : this.upper
]);
}
subtract(other) {
const otherValue = other instanceof abstract_domain_1.AbstractDomain ? other.value : other;
if (this.isValue() && otherValue !== lattice_1.Bottom) {
return this.create([Math.max(this.lower - otherValue[0], 0), Math.max(this.upper - otherValue[1], 0)]);
}
return this.bottom();
}
/**
* Extends the lower bound of the current abstract value down to 0.
*/
widenDown() {
if (this.isValue()) {
return this.create([0, this.upper]);
}
return this.bottom();
}
isTop() {
return this.value !== lattice_1.Bottom && this.lower === 0 && this.upper === +Infinity;
}
}
exports.PosIntervalDomain = PosIntervalDomain;
//# sourceMappingURL=positive-interval-domain.js.map