aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2021-10-21 16:17:21 +0200
committerRobin Voetter <robin@voetter.nl>2021-10-21 16:24:18 +0200
commit09c7d5aebc4f7fe96a89f93c0cf99cc03977ea5f (patch)
tree7877d79040b38f43aea7fc192546b19d07821bc0 /src/type.zig
parent84876fec582e13707a809c8136bb1eaf92b5da09 (diff)
downloadzig-09c7d5aebc4f7fe96a89f93c0cf99cc03977ea5f.tar.gz
zig-09c7d5aebc4f7fe96a89f93c0cf99cc03977ea5f.zip
stage2: elemPtr for slices
* Restructure elemPtr a bit * New AIR instruction: slice_elem_ptr, which returns a pointer to an element of a slice * Value: adapt elemPtr to work on slices
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index fceb3c4dfd..72347f5adc 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -2520,6 +2520,20 @@ pub const Type = extern union {
};
}
+ /// Returns the type of a pointer to an element.
+ /// Asserts that the type is a pointer, and that the element type is indexable.
+ /// For *[N]T, return *T
+ /// For [*]T, returns *T
+ /// For []T, returns *T
+ /// Handles const-ness and address spaces in particular.
+ pub fn elemPtrType(ptr_ty: Type, arena: *Allocator) !Type {
+ return try Type.ptr(arena, .{
+ .pointee_type = ptr_ty.elemType2(),
+ .mutable = ptr_ty.ptrIsMutable(),
+ .@"addrspace" = ptr_ty.ptrAddressSpace(),
+ });
+ }
+
fn shallowElemType(child_ty: Type) Type {
return switch (child_ty.zigTypeTag()) {
.Array, .Vector => child_ty.childType(),