UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

35 lines (34 loc) 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BuiltinPropertyAccessExpr = void 0; const Expr1_js_1 = require("../Expr1.js"); const ExprKind_js_1 = require("../ExprKind.js"); const ContextObjectValue_js_1 = require("../../value/ContextObjectValue.js"); const ExprEvalResult_js_1 = require("../ExprEvalResult.js"); const BuiltinRuntimeValueConverter_js_1 = require("../../builtin/BuiltinRuntimeValueConverter.js"); class BuiltinPropertyAccessExpr extends Expr1_js_1.Expr1 { constructor(target, memberName, type, targetName) { super(ExprKind_js_1.ExprKind.REF_BUILTIN_MEMBER, target); this.memberName = memberName; this.targetName = targetName; this.type = type; } calculateResult(_ctx, _localCtx, subExpressionResult) { if (!(subExpressionResult instanceof ContextObjectValue_js_1.ContextObjectValue)) { return new ExprEvalResult_js_1.ExprEvalErrorObj(this.getKind(), ExprEvalResult_js_1.ExprEvalStatus.TYPE_ERROR, `Builtin member access '.${this.memberName}' requires a context object target`, this.getTextSpan()); } const rawValue = (0, BuiltinRuntimeValueConverter_js_1.getBuiltinMemberValue)(subExpressionResult, this.memberName); if (rawValue === undefined || rawValue === null) { return new ExprEvalResult_js_1.ExprEvalErrorObj(this.getKind(), ExprEvalResult_js_1.ExprEvalStatus.NOT_FOUND, `No builtin member '${this.memberName}' found on '${this.targetName}'`, this.getTextSpan()); } return (0, BuiltinRuntimeValueConverter_js_1.toExpressionValue)(rawValue, this.type); } buildExprString(builder) { builder.appendExpr(this.sub).appendString(`.${this.memberName}`); } getType() { return this.type; } } exports.BuiltinPropertyAccessExpr = BuiltinPropertyAccessExpr; //# sourceMappingURL=BuiltinPropertyAccessExpr.js.map