ifc-expressions
Version:
Parsing and evaluation of IFC expressions
31 lines (30 loc) • 1.53 kB
JavaScript
import { Expr1 } from "../Expr1.js";
import { ExprKind } from "../ExprKind.js";
import { ContextObjectValue } from "../../value/ContextObjectValue.js";
import { ExprEvalErrorObj, ExprEvalStatus } from "../ExprEvalResult.js";
import { getBuiltinMemberValue, toExpressionValue, } from "../../builtin/BuiltinRuntimeValueConverter.js";
export class BuiltinPropertyAccessExpr extends Expr1 {
constructor(target, memberName, type, targetName) {
super(ExprKind.REF_BUILTIN_MEMBER, target);
this.memberName = memberName;
this.targetName = targetName;
this.type = type;
}
calculateResult(_ctx, _localCtx, subExpressionResult) {
if (!(subExpressionResult instanceof ContextObjectValue)) {
return new ExprEvalErrorObj(this.getKind(), ExprEvalStatus.TYPE_ERROR, `Builtin member access '.${this.memberName}' requires a context object target`, this.getTextSpan());
}
const rawValue = getBuiltinMemberValue(subExpressionResult, this.memberName);
if (rawValue === undefined || rawValue === null) {
return new ExprEvalErrorObj(this.getKind(), ExprEvalStatus.NOT_FOUND, `No builtin member '${this.memberName}' found on '${this.targetName}'`, this.getTextSpan());
}
return toExpressionValue(rawValue, this.type);
}
buildExprString(builder) {
builder.appendExpr(this.sub).appendString(`.${this.memberName}`);
}
getType() {
return this.type;
}
}
//# sourceMappingURL=BuiltinPropertyAccessExpr.js.map