mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Add intrinsics.type_field_index_of
This commit is contained in:
@@ -149,3 +149,6 @@ type_proc_return_type :: proc($T: typeid, index: int) -> typeid where type_i
|
|||||||
|
|
||||||
type_polymorphic_record_parameter_count :: proc($T: typeid) -> typeid ---
|
type_polymorphic_record_parameter_count :: proc($T: typeid) -> typeid ---
|
||||||
type_polymorphic_record_parameter_value :: proc($T: typeid, index: int) -> $V ---
|
type_polymorphic_record_parameter_value :: proc($T: typeid, index: int) -> $V ---
|
||||||
|
|
||||||
|
|
||||||
|
type_field_index_of :: proc($T: typeid, $name: string) -> uintptr ---
|
||||||
|
|||||||
@@ -323,9 +323,6 @@ Context :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@thread_local global_default_temp_allocator_data: Default_Temp_Allocator;
|
|
||||||
|
|
||||||
Raw_String :: struct {
|
Raw_String :: struct {
|
||||||
data: ^byte,
|
data: ^byte,
|
||||||
len: int,
|
len: int,
|
||||||
@@ -524,6 +521,8 @@ __init_context :: proc "contextless" (c: ^Context) {
|
|||||||
c.logger.data = nil;
|
c.logger.data = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@thread_local global_default_temp_allocator_data: Default_Temp_Allocator;
|
||||||
|
|
||||||
@builtin
|
@builtin
|
||||||
init_global_temporary_allocator :: proc(size: int, backup_allocator := context.allocator) {
|
init_global_temporary_allocator :: proc(size: int, backup_allocator := context.allocator) {
|
||||||
default_temp_allocator_init(&global_default_temp_allocator_data, size, backup_allocator);
|
default_temp_allocator_init(&global_default_temp_allocator_data, size, backup_allocator);
|
||||||
|
|||||||
@@ -5997,6 +5997,48 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case BuiltinProc_type_field_index_of:
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
if (sel.entity == nullptr) {
|
||||||
|
gbString type_str = type_to_string(bt);
|
||||||
|
error(ce->args[0],
|
||||||
|
"'%s' has no field named '%.*s'", type_str, LIT(field_name));
|
||||||
|
gb_string_free(type_str);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (sel.indirect) {
|
||||||
|
gbString type_str = type_to_string(bt);
|
||||||
|
error(ce->args[0],
|
||||||
|
"Field '%.*s' is embedded via a pointer in '%s'", LIT(field_name), type_str);
|
||||||
|
gb_string_free(type_str);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
operand->mode = Addressing_Constant;
|
||||||
|
operand->value = exact_value_u64(sel.index[0]);
|
||||||
|
operand->type = t_uintptr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -181,6 +181,8 @@ BuiltinProc__type_simple_boolean_end,
|
|||||||
BuiltinProc_type_polymorphic_record_parameter_count,
|
BuiltinProc_type_polymorphic_record_parameter_count,
|
||||||
BuiltinProc_type_polymorphic_record_parameter_value,
|
BuiltinProc_type_polymorphic_record_parameter_value,
|
||||||
|
|
||||||
|
BuiltinProc_type_field_index_of,
|
||||||
|
|
||||||
BuiltinProc__type_end,
|
BuiltinProc__type_end,
|
||||||
|
|
||||||
|
|
||||||
@@ -363,5 +365,7 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
|||||||
{STR_LIT("type_polymorphic_record_parameter_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_polymorphic_record_parameter_count"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT("type_polymorphic_record_parameter_value"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("type_polymorphic_record_parameter_value"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
|
||||||
|
{STR_LIT("type_field_index_of"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
|
||||||
{STR_LIT(""), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
{STR_LIT(""), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user