diff options
| author | gingerBill <bill@gingerbill.org> | 2020-09-16 20:08:45 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-09-16 20:08:45 +0100 |
| commit | 59d9821bd90dd89f521759ab03bd7798ceaee4f2 (patch) | |
| tree | accfe9ab9cb943d3140d65ac40e452b8d37f3b5f /src/check_expr.cpp | |
| parent | f530c80216c648a19d97ccb5b7c431dd5c5e0072 (diff) | |
Add `intrinsics.type_has_field`
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 3e5dd58f5..aea72c9b3 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -5702,6 +5702,34 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 operand->type = t_untyped_bool; break; + case BuiltinProc_type_has_field: + { + Operand op = {}; + Type *bt = check_type(c, ce->args[0]); + Type *type = base_type(bt); + if (type == nullptr || type == t_invalid) { + error(ce->args[0], "Expected a type for '%.*s'", LIT(builtin_name)); + return false; + } + Operand x = {}; + check_expr(c, &x, ce->args[1]); + + if (!is_type_string(x.type) || x.mode != Addressing_Constant || x.value.kind != ExactValue_String) { + error(ce->args[1], "Expected a const string for field argument"); + return false; + } + + String field_name = x.value.value_string; + + Selection sel = lookup_field(type, field_name, false); + operand->mode = Addressing_Constant; + operand->value = exact_value_bool(sel.index.count != 0); + operand->type = t_untyped_bool; + + break; + } + break; + case BuiltinProc_type_is_specialization_of: { if (operand->mode != Addressing_Type) { |