aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-13 17:53:28 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-13 17:53:28 -0700
commitdf7d6d263e4ad6adb302856235641ae9ceb142b6 (patch)
tree186182733c89cec8fa990a681ab8e6f915d15908 /src/Module.zig
parentda7fcfd1586fa93c3d00815f60030e00ea583701 (diff)
downloadzig-df7d6d263e4ad6adb302856235641ae9ceb142b6.tar.gz
zig-df7d6d263e4ad6adb302856235641ae9ceb142b6.zip
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
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig25
1 files changed, 24 insertions, 1 deletions
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`.