UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

65 lines (64 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TypeDisjunction = void 0; class TypeDisjunction { constructor(...types) { this.types = types.reduce((prev, t) => { if (!prev.some((p) => p.isSameTypeAs(t))) { prev.push(t); } return prev; }, []); Object.freeze(types); } getName() { return "{" + this.types.map((t) => t.getName()).join(" or ") + "}"; } isSameTypeAs(other) { return (other instanceof TypeDisjunction && this.types.every((t) => other.types.includes(t))); } getTypes() { return this.types; } isSuperTypeOf(other) { if (other instanceof TypeDisjunction) { let moreGeneral = false; for (const to of other.types) { let matchFound = false; for (const t of this.types) { if (t.isSuperTypeOf(to)) { moreGeneral = true; matchFound = true; break; } if (t.isSameTypeAs(to)) { matchFound = true; } } if (!matchFound) { return false; } } return moreGeneral || this.types.length > other.types.length; } return this.types.some((t) => t.isSameTypeAs(other) || t.isSuperTypeOf(other)); } isSubTypeOf(other) { if (other instanceof TypeDisjunction) { return other.isSuperTypeOf(this); } return this.types.every((t) => t.isSubTypeOf(other)); } overlapsWith(other) { if (other instanceof TypeDisjunction) { return this.types.some((t) => other.types.some((to) => t.overlapsWith(to))); } return this.types.some((t) => t.overlapsWith(other)); } isAssignableFrom(other) { return this.isSameTypeAs(other) || this.isSuperTypeOf(other); } } exports.TypeDisjunction = TypeDisjunction; //# sourceMappingURL=TypeDisjunction.js.map