UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

101 lines (100 loc) 3.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TupleType = void 0; const ArrayType_js_1 = require("./ArrayType.js"); const TypeDisjunction_js_1 = require("./TypeDisjunction.js"); class TupleType { constructor(...types) { this.types = types; Object.freeze(types); } getTypes() { return this.types; } toArrayType() { return new ArrayType_js_1.ArrayType(new TypeDisjunction_js_1.TypeDisjunction(...this.getTypes())); } getName() { return "<" + this.types.map((t) => t.getName()).join(", ") + ">"; } isAssignableFrom(other) { if (other instanceof TupleType) { return this.compareToOtherTuple(other, (t, to) => t.isAssignableFrom(to)); } return false; } isSameTypeAs(other) { if (other instanceof TupleType) { return this.compareToOtherTuple(other, (t, to) => t.isSameTypeAs(to)); } return false; } isSubTypeOf(other) { if (other instanceof TupleType) { return this.compareToOtherTuple(other, (t, to) => t.isSubTypeOf(to)); } else if (other instanceof ArrayType_js_1.ArrayType) { for (const t of this.types) { if (!(t.isSubTypeOf(other.getElementType()) || t.isSameTypeAs(other.getElementType()))) { return false; } } return true; } else if (other instanceof TypeDisjunction_js_1.TypeDisjunction) { return other.isSuperTypeOf(this); } return false; } compareToOtherTuple(other, cmp) { const n = this.types.length; if (other.types.length !== n) { return false; } for (let i = 0; i < n; i++) { const t = this.types[i]; const to = other.types[i]; if (!cmp(t, to)) { return false; } } return true; } isSuperTypeOf(other) { if (other instanceof TupleType) { return this.compareToOtherTuple(other, (t, to) => t.isSuperTypeOf(to)); } else if (other instanceof ArrayType_js_1.ArrayType) { for (const t of this.types) { if (!t.isSuperTypeOf(other.getElementType())) { return false; } } return true; } else if (other instanceof TypeDisjunction_js_1.TypeDisjunction) { return other.isSubTypeOf(this); } return false; } overlapsWith(other) { if (other instanceof TupleType) { return this.compareToOtherTuple(other, (t, to) => t.overlapsWith(to)); } else if (other instanceof ArrayType_js_1.ArrayType) { for (const t of this.types) { if (!t.overlapsWith(other.getElementType())) { return false; } } return true; } else if (other instanceof TypeDisjunction_js_1.TypeDisjunction) { return other.overlapsWith(this); } return false; } } exports.TupleType = TupleType; //# sourceMappingURL=TupleType.js.map