UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

60 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MultiValueDomain = exports.MultiValueStateDomain = void 0; const lattice_1 = require("./lattice"); const partial_product_domain_1 = require("./partial-product-domain"); const state_abstract_domain_1 = require("./state-abstract-domain"); /** * A multi-value state abstract domain that maps AST node IDs to multiple abstract values from different abstract domains. * @template Product - Type of the abstract product of the multi-value domain combining multiple abstract values * @see {@link NodeId} for the node IDs of the AST nodes */ class MultiValueStateDomain extends state_abstract_domain_1.StateAbstractDomain { constructor(value, domain, reductions = []) { super(value, new MultiValueDomain(domain, domain, reductions)); } create(value) { return new MultiValueStateDomain(value, this.domain.domain, this.domain.reductions); } getValue(node, property) { if (this.value === lattice_1.Bottom) { return this.domain.value[property]?.bottom(); } return this.value.get(node)?.value[property]; } hasValue(node, property) { return this.value !== lattice_1.Bottom && this.value.get(node)?.value[property] !== undefined; } setValue(node, property, value) { if (this.value !== lattice_1.Bottom) { const oldValue = this.get(node); const newValue = { ...oldValue?.value ?? {}, [property]: value }; this._value.set(node, new MultiValueDomain(newValue, this.domain.domain, this.domain.reductions)); } } } exports.MultiValueStateDomain = MultiValueStateDomain; /** * A multi-value abstract domain as a (partial) product domain that combines multiple abstract domains. * The Bottom element is defined as mapping every sub abstract domain to Bottom and the Top element is defined as having no sub abstract domain value. * @template Product - Type of the abstract product of the multi-value domain combining multiple abstract values * @see {@link MultiValueStateDomain} for a state abstract domain of a multi-value domain */ class MultiValueDomain extends partial_product_domain_1.PartialProductDomain { reductions; constructor(value, domain, reductions = []) { super(value, domain); this.reductions = reductions; } create(value) { return new MultiValueDomain(value, this.domain, this.reductions); } static top(domain, reductions = []) { return new MultiValueDomain({}, domain, reductions); } reduce(value) { return this.reductions.reduce((current, reduction) => reduction(current), value); } } exports.MultiValueDomain = MultiValueDomain; //# sourceMappingURL=multi-value-state-domain.js.map