aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/type.zig b/src/type.zig
index b0da997de1..8c2fd4e733 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -2845,22 +2845,40 @@ pub const Type = struct {
};
}
+ /// Asserts that the type can have a namespace.
+ pub fn getNamespaceIndex(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex {
+ return ty.getNamespace(zcu).?;
+ }
+
/// Returns null if the type has no namespace.
- pub fn getNamespaceIndex(ty: Type, mod: *Module) InternPool.OptionalNamespaceIndex {
- const ip = &mod.intern_pool;
+ pub fn getNamespace(ty: Type, zcu: *Zcu) ?InternPool.OptionalNamespaceIndex {
+ const ip = &zcu.intern_pool;
return switch (ip.indexToKey(ty.toIntern())) {
.opaque_type => ip.loadOpaqueType(ty.toIntern()).namespace,
.struct_type => ip.loadStructType(ty.toIntern()).namespace,
.union_type => ip.loadUnionType(ty.toIntern()).namespace,
.enum_type => ip.loadEnumType(ty.toIntern()).namespace,
- else => .none,
- };
- }
+ .anon_struct_type => .none,
+ .simple_type => |s| switch (s) {
+ .anyopaque,
+ .atomic_order,
+ .atomic_rmw_op,
+ .calling_convention,
+ .address_space,
+ .float_mode,
+ .reduce_op,
+ .call_modifier,
+ .prefetch_options,
+ .export_options,
+ .extern_options,
+ .type_info,
+ => .none,
+ else => null,
+ },
- /// Returns null if the type has no namespace.
- pub fn getNamespace(ty: Type, mod: *Module) ?*Module.Namespace {
- return if (getNamespaceIndex(ty, mod).unwrap()) |i| mod.namespacePtr(i) else null;
+ else => null,
+ };
}
// Works for vectors and vectors of integers.