@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
130 lines • 4.17 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);
}
static top() {
return new SingletonDomain(lattice_1.Top);
}
static bottom() {
return new SingletonDomain(lattice_1.Bottom);
}
static abstract(concrete) {
if (concrete === lattice_1.Top || concrete.size > 1) {
return SingletonDomain.top();
}
else if (concrete.size === 0) {
return SingletonDomain.bottom();
}
return new SingletonDomain([...concrete][0]);
}
top() {
return SingletonDomain.top();
}
bottom() {
return SingletonDomain.bottom();
}
equals(other) {
return this.value === other.value;
}
leq(other) {
return this.value === lattice_1.Bottom || other.value === lattice_1.Top || (this.isValue() && other.isValue() && this.value <= other.value);
}
join(other) {
const otherValue = other instanceof SingletonDomain ? other.value : other;
if (this.value === lattice_1.Bottom) {
return this.create(otherValue);
}
else if (otherValue === lattice_1.Bottom) {
return this.create(this.value);
}
else if (this.value !== otherValue) {
return this.top();
}
else {
return this.create(this.value);
}
}
meet(other) {
const otherValue = other instanceof SingletonDomain ? other.value : other;
if (this.value === lattice_1.Top) {
return this.create(otherValue);
}
else if (otherValue === lattice_1.Top) {
return this.create(this.value);
}
else if (this.value !== otherValue) {
return this.bottom();
}
else {
return this.create(this.value);
}
}
widen(other) {
return this.join(other); // Using join for widening as the lattice is finite
}
narrow(other) {
return this.meet(other); // Using meet for narrowing as the lattice is finite
}
concretize() {
if (this.value === lattice_1.Top) {
return lattice_1.Top;
}
else if (this.value === lattice_1.Bottom) {
return new Set();
}
return new Set([this.value]);
}
abstract(concrete) {
return SingletonDomain.abstract(concrete);
}
satisfies(value) {
if (this.isValue() && this.value === value) {
return logic_1.Ternary.Always;
}
else if (this.isTop()) {
return logic_1.Ternary.Maybe;
}
return logic_1.Ternary.Never;
}
toJson() {
if (this.value === lattice_1.Top) {
return lattice_1.Top.description;
}
else if (this.value === lattice_1.Bottom) {
return lattice_1.Bottom.description;
}
return this.value;
}
toString() {
if (this.value === lattice_1.Top) {
return lattice_1.TopSymbol;
}
else if (this.value === lattice_1.Bottom) {
return lattice_1.BottomSymbol;
}
return (0, abstract_domain_1.domainElementToString)(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