mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Add intrinsics.type_has_field
This commit is contained in:
@@ -139,6 +139,8 @@ type_has_nil :: proc($T: typeid) -> bool ---
|
|||||||
|
|
||||||
type_is_specialization_of :: proc($T, $S: typeid) -> bool ---
|
type_is_specialization_of :: proc($T, $S: typeid) -> bool ---
|
||||||
|
|
||||||
|
type_has_field :: proc($T: typeid, $name: string) -> bool ---
|
||||||
|
|
||||||
type_proc_parameter_count :: proc($T: typeid) -> int where type_is_proc(T) ---
|
type_proc_parameter_count :: proc($T: typeid) -> int where type_is_proc(T) ---
|
||||||
type_proc_return_count :: proc($T: typeid) -> int where type_is_proc(T) ---
|
type_proc_return_count :: proc($T: typeid) -> int where type_is_proc(T) ---
|
||||||
|
|
||||||
|
|||||||
@@ -5702,6 +5702,34 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
|
|||||||
operand->type = t_untyped_bool;
|
operand->type = t_untyped_bool;
|
||||||
break;
|
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:
|
case BuiltinProc_type_is_specialization_of:
|
||||||
{
|
{
|
||||||
if (operand->mode != Addressing_Type) {
|
if (operand->mode != Addressing_Type) {
|
||||||
|
|||||||
@@ -168,6 +168,8 @@ BuiltinProc__type_simple_boolean_begin,
|
|||||||
|
|
||||||
BuiltinProc__type_simple_boolean_end,
|
BuiltinProc__type_simple_boolean_end,
|
||||||
|
|
||||||
|
BuiltinProc_type_has_field,
|
||||||
|
|
||||||
BuiltinProc_type_is_specialization_of,
|
BuiltinProc_type_is_specialization_of,
|
||||||
|
|
||||||
BuiltinProc_type_proc_parameter_count,
|
BuiltinProc_type_proc_parameter_count,
|
||||||
@@ -349,6 +351,8 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
|||||||
{STR_LIT("type_has_nil"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_has_nil"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT(""), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
{STR_LIT(""), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
||||||
|
|
||||||
|
{STR_LIT("type_has_field"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
|
||||||
{STR_LIT("type_is_specialization_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_is_specialization_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT("type_proc_parameter_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_proc_parameter_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT("type_proc_return_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_proc_return_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
|||||||
Reference in New Issue
Block a user