mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 01:44:36 +00:00
Add intrinsics.type_has_field
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user