add "child" field to pointer type

This commit is contained in:
Andrew Kelley 2017-08-30 00:17:11 -04:00
parent b35dad88b4
commit c2357830b4
2 changed files with 18 additions and 0 deletions

View File

@ -11416,6 +11416,20 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_ptr(&child_type->name), buf_ptr(field_name)));
return ira->codegen->builtin_types.entry_invalid;
}
} else if (child_type->id == TypeTableEntryIdPointer) {
if (buf_eql_str(field_name, "child")) {
bool ptr_is_const = true;
bool ptr_is_volatile = false;
return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
create_const_type(ira->codegen, child_type->data.pointer.child_type),
ira->codegen->builtin_types.entry_type,
ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
} else {
ir_add_error(ira, &field_ptr_instruction->base,
buf_sprintf("type '%s' has no member called '%s'",
buf_ptr(&child_type->name), buf_ptr(field_name)));
return ira->codegen->builtin_types.entry_invalid;
}
} else {
ir_add_error(ira, &field_ptr_instruction->base,
buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));

View File

@ -534,3 +534,7 @@ const vram = @intToPtr(&volatile u8, 0x20000000)[0..0x8000];
export fn writeToVRam() {
vram[0] = 'X';
}
test "pointer child field" {
assert((&u32).child == u32);
}