This commit is contained in:
Alexandros Naskos 2018-04-26 13:27:16 +03:00
parent bc160821d3
commit dd88d7deda

View File

@ -15775,17 +15775,20 @@ static void ir_type_info_struct_set_parent(ConstExprValue *struct_val, ConstExpr
static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_name) static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_name)
{ {
ConstExprValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); static ConstExprValue *type_info_var = nullptr;
assert(type_info_var->type->id == TypeTableEntryIdMetaType); static TypeTableEntry *type_info_type = nullptr;
if (type_info_var == nullptr)
{
type_info_var = get_builtin_value(ira->codegen, "TypeInfo");
assert(type_info_var->type->id == TypeTableEntryIdMetaType);
TypeTableEntry *type_info_type = type_info_var->data.x_type; type_info_type = type_info_var->data.x_type;
assert(type_info_type->id == TypeTableEntryIdUnion); assert(type_info_type->id == TypeTableEntryIdUnion);
}
if (type_name == nullptr) if (type_name == nullptr)
return type_info_type; return type_info_type;
// @TODO
ScopeDecls *type_info_scope = get_container_scope(type_info_type); ScopeDecls *type_info_scope = get_container_scope(type_info_type);
assert(type_info_scope != nullptr); assert(type_info_scope != nullptr);
@ -15898,15 +15901,16 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
bigint_init_unsigned(&fields[2].data.x_bigint, type_entry->data.pointer.alignment); bigint_init_unsigned(&fields[2].data.x_bigint, type_entry->data.pointer.alignment);
// child: &TypeInfo // child: &TypeInfo
ensure_field_index(payload->type, "child", 3); ensure_field_index(payload->type, "child", 3);
ConstExprValue *type_info_type = get_builtin_value(ira->codegen, "TypeInfo");
assert(type_info_type->type->id == TypeTableEntryIdMetaType); TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr);
fields[3].special = ConstValSpecialStatic; fields[3].special = ConstValSpecialStatic;
fields[3].type = get_pointer_to_type(ira->codegen, type_info_type->data.x_type, false); fields[3].type = get_pointer_to_type(ira->codegen, type_info_type, false);
fields[3].data.x_ptr.special = ConstPtrSpecialRef; fields[3].data.x_ptr.special = ConstPtrSpecialRef;
fields[3].data.x_ptr.mut = ConstPtrMutComptimeVar; fields[3].data.x_ptr.mut = ConstPtrMutComptimeVar;
ConstExprValue *union_val = create_const_vals(1); ConstExprValue *union_val = create_const_vals(1);
union_val->special = ConstValSpecialStatic; union_val->special = ConstValSpecialStatic;
union_val->type = type_info_type->data.x_type; union_val->type = type_info_type;
bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.pointer.child_type->id)); bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.pointer.child_type->id));
union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1,
@ -15933,15 +15937,16 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len); bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len);
// child: &TypeInfo // child: &TypeInfo
ensure_field_index(payload->type, "child", 1); ensure_field_index(payload->type, "child", 1);
ConstExprValue *type_info_type = get_builtin_value(ira->codegen, "TypeInfo");
assert(type_info_type->type->id == TypeTableEntryIdMetaType); TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr);
fields[1].special = ConstValSpecialStatic; fields[1].special = ConstValSpecialStatic;
fields[1].type = get_pointer_to_type(ira->codegen, type_info_type->data.x_type, false); fields[1].type = get_pointer_to_type(ira->codegen, type_info_type, false);
fields[1].data.x_ptr.special = ConstPtrSpecialRef; fields[1].data.x_ptr.special = ConstPtrSpecialRef;
fields[1].data.x_ptr.mut = ConstPtrMutComptimeVar; fields[1].data.x_ptr.mut = ConstPtrMutComptimeVar;
ConstExprValue *union_val = create_const_vals(1); ConstExprValue *union_val = create_const_vals(1);
union_val->special = ConstValSpecialStatic; union_val->special = ConstValSpecialStatic;
union_val->type = type_info_type->data.x_type; union_val->type = type_info_type;
bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.array.child_type->id)); bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.array.child_type->id));
union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1,
@ -15963,15 +15968,16 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
// child: &TypeInfo // child: &TypeInfo
ensure_field_index(payload->type, "child", 0); ensure_field_index(payload->type, "child", 0);
ConstExprValue *type_info_type = get_builtin_value(ira->codegen, "TypeInfo");
assert(type_info_type->type->id == TypeTableEntryIdMetaType); TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr);
fields[0].special = ConstValSpecialStatic; fields[0].special = ConstValSpecialStatic;
fields[0].type = get_pointer_to_type(ira->codegen, type_info_type->data.x_type, false); fields[0].type = get_pointer_to_type(ira->codegen, type_info_type, false);
fields[0].data.x_ptr.special = ConstPtrSpecialRef; fields[0].data.x_ptr.special = ConstPtrSpecialRef;
fields[0].data.x_ptr.mut = ConstPtrMutComptimeVar; fields[0].data.x_ptr.mut = ConstPtrMutComptimeVar;
ConstExprValue *union_val = create_const_vals(1); ConstExprValue *union_val = create_const_vals(1);
union_val->special = ConstValSpecialStatic; union_val->special = ConstValSpecialStatic;
union_val->type = type_info_type->data.x_type; union_val->type = type_info_type;
bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.maybe.child_type->id)); bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.maybe.child_type->id));
union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1,
@ -15993,10 +15999,9 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
// child: ?&TypeInfo // child: ?&TypeInfo
ensure_field_index(payload->type, "child", 0); ensure_field_index(payload->type, "child", 0);
ConstExprValue *type_info_type = get_builtin_value(ira->codegen, "TypeInfo");
assert(type_info_type->type->id == TypeTableEntryIdMetaType);
TypeTableEntry *type_info_ptr_type = get_pointer_to_type(ira->codegen, type_info_type->data.x_type, false); TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr);
TypeTableEntry *type_info_ptr_type = get_pointer_to_type(ira->codegen, type_info_type, false);
fields[0].special = ConstValSpecialStatic; fields[0].special = ConstValSpecialStatic;
fields[0].type = get_maybe_type(ira->codegen, type_info_ptr_type); fields[0].type = get_maybe_type(ira->codegen, type_info_ptr_type);
@ -16016,7 +16021,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
ConstExprValue *union_val = create_const_vals(1); ConstExprValue *union_val = create_const_vals(1);
union_val->special = ConstValSpecialStatic; union_val->special = ConstValSpecialStatic;
union_val->type = type_info_type->data.x_type; union_val->type = type_info_type;
bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.promise.result_type->id)); bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.promise.result_type->id));
union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1,
type_entry->data.promise.result_type); type_entry->data.promise.result_type);