ifc-expressions
Version:
Parsing and evaluation of IFC expressions
78 lines (77 loc) • 3.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeManager = void 0;
const Types_js_1 = require("../type/Types.js");
const ExpressionTypeError_js_1 = require("../error/ExpressionTypeError.js");
class TypeManager {
constructor() {
this.types = new Map();
}
setType(parserRuleContext, type) {
this.types.set(parserRuleContext, type);
}
getType(parserRuleContext) {
return this.types.get(parserRuleContext);
}
copyTypeFrom(ctx, from) {
const theType = this.types.get(from);
this.types.set(ctx, theType);
}
requireString(ctx) {
const actualType = this.types.get(ctx);
Types_js_1.Types.requireWeakIsAssignableFrom(Types_js_1.Type.STRING, this.types.get(ctx), () => new ExpressionTypeError_js_1.ExpressionTypeError(`expected type string, actual type is ${actualType.getName()}`, ctx));
}
requireBoolean(ctx) {
const actualType = this.types.get(ctx);
Types_js_1.Types.requireWeakIsAssignableFrom(Types_js_1.Type.BOOLEAN, this.types.get(ctx), () => new ExpressionTypeError_js_1.ExpressionTypeError(`expected type boolean, actual type is ${actualType.getName()}`, ctx));
}
requireLogicalOrBoolean(ctx) {
return this.requireOneOf(ctx, Types_js_1.Type.BOOLEAN, Types_js_1.Type.LOGICAL);
}
requireOneOf(ctx, ...types) {
const requiredType = Types_js_1.Types.or(...types);
const actualType = this.types.get(ctx);
Types_js_1.Types.requireWeakIsAssignableFrom(requiredType, this.types.get(ctx), () => new ExpressionTypeError_js_1.ExpressionTypeError(`expected type ${requiredType}, actual type is ${actualType.getName()}`, ctx));
}
requireNumeric(ctx) {
const actualType = this.types.get(ctx);
Types_js_1.Types.requireWeakIsAssignableFrom(Types_js_1.Type.NUMERIC, actualType, () => new ExpressionTypeError_js_1.ExpressionTypeError(`expected type numeric, actual type is ${actualType.getName()}`, ctx));
}
requireTypesOverlap(ctxA, ctxB) {
Types_js_1.Types.requireTypesOverlap(this.types.get(ctxA), this.types.get(ctxB), () => new ExpressionTypeError_js_1.ExpressionTypeError(`Types ${this.types.get(ctxA).getName()} and ${this.types
.get(ctxB)
.getName()} are required to overlap but they don't.`, ctxA));
}
isType(type, ...ctxs) {
return ctxs.every((ctx) => Types_js_1.Types.isType(this.types.get(ctx), type));
}
overlapsWith(type, ...ctxs) {
return ctxs.every((ctx) => type.overlapsWith(this.types.get(ctx)));
}
isString(...ctxs) {
return this.isType(Types_js_1.Type.STRING, ...ctxs);
}
overlapsWithString(...ctxs) {
return this.overlapsWith(Types_js_1.Type.STRING, ...ctxs);
}
isBoolean(...ctxs) {
return this.isType(Types_js_1.Type.BOOLEAN, ...ctxs);
}
isLogical(...ctxs) {
return this.isType(Types_js_1.Type.LOGICAL, ...ctxs);
}
overlapsWithBoolean(...ctxs) {
return this.overlapsWith(Types_js_1.Type.BOOLEAN, ...ctxs);
}
overlapsWithLogical(...ctxs) {
return this.overlapsWith(Types_js_1.Type.LOGICAL, ...ctxs);
}
isNumeric(...ctxs) {
return this.isType(Types_js_1.Type.NUMERIC, ...ctxs);
}
overlapsWithNumeric(...ctxs) {
return this.overlapsWith(Types_js_1.Type.NUMERIC, ...ctxs);
}
}
exports.TypeManager = TypeManager;
//# sourceMappingURL=TypeManager.js.map