@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
91 lines • 2.76 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SingletonDomain = void 0;
const logic_1 = require("../../util/logic");
const abstract_domain_1 = require("./abstract-domain");
const lattice_1 = require("./lattice");
/**
* The singleton abstract domain as a single possible value.
* The Bottom element is defined as {@link Bottom} symbol and the Top element is defined as {@link Top} symbol.
* @template T - Type of the value in the abstract domain
* @template Value - Type of the constraint in the abstract domain (Top, Bottom, or an actual value)
*/
class SingletonDomain extends abstract_domain_1.AbstractDomain {
create(value) {
return new SingletonDomain(value);
}
from(...values) {
if (values.length === 0) {
return this.bottom();
}
else if (values.length > 1) {
return this.top();
}
return this.create(values[0]);
}
static top() {
return new this(lattice_1.Top);
}
static bottom() {
return new this(lattice_1.Bottom);
}
static from(...values) {
if (values.length === 0) {
return this.bottom();
}
else if (values.length > 1) {
return this.top();
}
return new this(values[0]);
}
top() {
return this.create(lattice_1.Top);
}
bottom() {
return this.create(lattice_1.Bottom);
}
equalsValue(other) {
return this.value === other.value;
}
leqValue(other) {
return this.value <= other.value;
}
joinValue(other) {
return this.equals(other) ? this.create(this.value) : this.top();
}
meetValue(other) {
return this.equals(other) ? this.create(this.value) : this.bottom();
}
widenValue(other) {
return this.joinValue(other); // Using join for widening as the lattice is finite
}
narrowValue(other) {
return this.meetValue(other); // Using meet for narrowing as the lattice is finite
}
satisfies(value) {
if (this.equals(this.from(value))) {
return logic_1.Ternary.Always;
}
else if (this.isTop()) {
return logic_1.Ternary.Maybe;
}
return logic_1.Ternary.Never;
}
jsonify() {
return this.value;
}
stringify() {
return abstract_domain_1.AbstractDomain.toString(this.value);
}
isTop() {
return this.value === lattice_1.Top;
}
isBottom() {
return this.value === lattice_1.Bottom;
}
isValue() {
return this.value !== lattice_1.Top && this.value !== lattice_1.Bottom;
}
}
exports.SingletonDomain = SingletonDomain;
//# sourceMappingURL=singleton-domain.js.map