Commit c2357830b4

Andrew Kelley <superjoe30@gmail.com>
2017-08-30 06:17:11
add "child" field to pointer type
1 parent b35dad8
Changed files (2)
src
test
cases
src/ir.cpp
@@ -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)));
test/cases/misc.zig
@@ -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);
+}