From df7d6d263e4ad6adb302856235641ae9ceb142b6 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 13 Oct 2021 17:53:28 -0700 Subject: stage2: implement opaque declarations * Module: implement opaque type namespace lookup * Add `Type.type` for convenience * Sema: fix `validateVarType` for pointer-to-opaque * x86_64 ABI: implement support for pointers * LLVM backend: fix lowering of opaque types * Type: implement equality checking for opaques --- src/Module.zig | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index ee9b3e50bc..c200c83c10 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -708,7 +708,9 @@ pub const Decl = struct { return ty.castTag(.empty_struct).?.data; }, .@"opaque" => { - @panic("TODO opaque types"); + const opaque_obj = ty.cast(Type.Payload.Opaque).?.data; + assert(opaque_obj.owner_decl == decl); + return &opaque_obj.namespace; }, .@"union", .union_tagged => { const union_obj = ty.cast(Type.Payload.Union).?.data; @@ -1080,6 +1082,27 @@ pub const Union = struct { } }; +pub const Opaque = struct { + /// The Decl that corresponds to the opaque itself. + owner_decl: *Decl, + /// Represents the declarations inside this opaque. + namespace: Namespace, + /// Offset from `owner_decl`, points to the opaque decl AST node. + node_offset: i32, + + pub fn srcLoc(self: Opaque) SrcLoc { + return .{ + .file_scope = self.owner_decl.getFileScope(), + .parent_decl_node = self.owner_decl.src_node, + .lazy = .{ .node_offset = self.node_offset }, + }; + } + + pub fn getFullyQualifiedName(s: *Opaque, gpa: *Allocator) ![:0]u8 { + return s.owner_decl.getFullyQualifiedName(gpa); + } +}; + /// Some Fn struct memory is owned by the Decl's TypedValue.Managed arena allocator. /// Extern functions do not have this data structure; they are represented by /// the `Decl` only, with a `Value` tag of `extern_fn`. -- cgit v1.2.3