@@ -16222,8 +16222,7 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
16222
16222
return true;
16223
16223
}
16224
16224
16225
- static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry)
16226
- {
16225
+ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry) {
16227
16226
assert(type_entry != nullptr);
16228
16227
assert(!type_is_invalid(type_entry));
16229
16228
@@ -16248,38 +16247,67 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16248
16247
enum_field_val->data.x_struct.fields = inner_fields;
16249
16248
};
16250
16249
16251
- const auto create_ptr_like_type_info = [ira](const char *name, TypeTableEntry *ptr_type_entry) {
16250
+ const auto create_ptr_like_type_info = [ira](TypeTableEntry *ptr_type_entry) {
16251
+ TypeTableEntry *attrs_type;
16252
+ uint32_t size_enum_index;
16253
+ if (is_slice(ptr_type_entry)) {
16254
+ attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry;
16255
+ size_enum_index = 2;
16256
+ } else if (ptr_type_entry->id == TypeTableEntryIdPointer) {
16257
+ attrs_type = ptr_type_entry;
16258
+ size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1;
16259
+ } else {
16260
+ zig_unreachable();
16261
+ }
16262
+
16263
+ TypeTableEntry *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer");
16264
+ ensure_complete_type(ira->codegen, type_info_pointer_type);
16265
+ assert(!type_is_invalid(type_info_pointer_type));
16266
+
16252
16267
ConstExprValue *result = create_const_vals(1);
16253
16268
result->special = ConstValSpecialStatic;
16254
- result->type = ir_type_info_get_type(ira, name) ;
16269
+ result->type = type_info_pointer_type ;
16255
16270
16256
- ConstExprValue *fields = create_const_vals(4 );
16271
+ ConstExprValue *fields = create_const_vals(5 );
16257
16272
result->data.x_struct.fields = fields;
16258
16273
16259
- // is_const: bool
16260
- ensure_field_index(result->type, "is_const", 0);
16274
+ // size: Size
16275
+ ensure_field_index(result->type, "size", 0);
16276
+ TypeTableEntry *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);
16277
+ ensure_complete_type(ira->codegen, type_info_pointer_size_type);
16278
+ assert(!type_is_invalid(type_info_pointer_size_type));
16261
16279
fields[0].special = ConstValSpecialStatic;
16262
- fields[0].type = ira->codegen->builtin_types.entry_bool;
16263
- fields[0].data.x_bool = ptr_type_entry->data.pointer.is_const;
16264
- // is_volatile: bool
16265
- ensure_field_index(result->type, "is_volatile", 1);
16280
+ fields[0].type = type_info_pointer_size_type;
16281
+ bigint_init_unsigned(&fields[0].data.x_enum_tag, size_enum_index);
16282
+
16283
+ // is_const: bool
16284
+ ensure_field_index(result->type, "is_const", 1);
16266
16285
fields[1].special = ConstValSpecialStatic;
16267
16286
fields[1].type = ira->codegen->builtin_types.entry_bool;
16268
- fields[1].data.x_bool = ptr_type_entry ->data.pointer.is_volatile ;
16269
- // alignment: u32
16270
- ensure_field_index(result->type, "alignment ", 2);
16287
+ fields[1].data.x_bool = attrs_type ->data.pointer.is_const ;
16288
+ // is_volatile: bool
16289
+ ensure_field_index(result->type, "is_volatile ", 2);
16271
16290
fields[2].special = ConstValSpecialStatic;
16272
- fields[2].type = ira->codegen->builtin_types.entry_u32 ;
16273
- bigint_init_unsigned(& fields[2].data.x_bigint, ptr_type_entry ->data.pointer.alignment) ;
16274
- // child: type
16275
- ensure_field_index(result->type, "child ", 3);
16291
+ fields[2].type = ira->codegen->builtin_types.entry_bool ;
16292
+ fields[2].data.x_bool = attrs_type ->data.pointer.is_volatile ;
16293
+ // alignment: u32
16294
+ ensure_field_index(result->type, "alignment ", 3);
16276
16295
fields[3].special = ConstValSpecialStatic;
16277
- fields[3].type = ira->codegen->builtin_types.entry_type;
16278
- fields[3].data.x_type = ptr_type_entry->data.pointer.child_type;
16296
+ fields[3].type = ira->codegen->builtin_types.entry_u32;
16297
+ bigint_init_unsigned(&fields[3].data.x_bigint, attrs_type->data.pointer.alignment);
16298
+ // child: type
16299
+ ensure_field_index(result->type, "child", 4);
16300
+ fields[4].special = ConstValSpecialStatic;
16301
+ fields[4].type = ira->codegen->builtin_types.entry_type;
16302
+ fields[4].data.x_type = attrs_type->data.pointer.child_type;
16279
16303
16280
16304
return result;
16281
16305
};
16282
16306
16307
+ if (type_entry == ira->codegen->builtin_types.entry_global_error_set) {
16308
+ zig_panic("TODO implement @typeInfo for global error set");
16309
+ }
16310
+
16283
16311
ConstExprValue *result = nullptr;
16284
16312
switch (type_entry->id)
16285
16313
{
@@ -16348,7 +16376,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16348
16376
}
16349
16377
case TypeTableEntryIdPointer:
16350
16378
{
16351
- result = create_ptr_like_type_info("Pointer", type_entry);
16379
+ result = create_ptr_like_type_info(type_entry);
16352
16380
break;
16353
16381
}
16354
16382
case TypeTableEntryIdArray:
@@ -16621,15 +16649,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16621
16649
case TypeTableEntryIdStruct:
16622
16650
{
16623
16651
if (type_entry->data.structure.is_slice) {
16624
- Buf ptr_field_name = BUF_INIT;
16625
- buf_init_from_str(&ptr_field_name, "ptr");
16626
- TypeTableEntry *ptr_type = type_entry->data.structure.fields_by_name.get(&ptr_field_name)->type_entry;
16627
- ensure_complete_type(ira->codegen, ptr_type);
16628
- if (type_is_invalid(ptr_type))
16629
- return nullptr;
16630
- buf_deinit(&ptr_field_name);
16631
-
16632
- result = create_ptr_like_type_info("Slice", ptr_type);
16652
+ result = create_ptr_like_type_info(type_entry);
16633
16653
break;
16634
16654
}
16635
16655
0 commit comments