aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-28 15:59:14 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-28 15:59:14 -0700
commitd2f9646d98615d85589d2c46237559d1249f2765 (patch)
tree87c2297912251993970a282703f688c72932e228 /src/type.zig
parent234d94e42b832dd17eb9144f5523e03ef4fa8eb3 (diff)
downloadzig-d2f9646d98615d85589d2c46237559d1249f2765.tar.gz
zig-d2f9646d98615d85589d2c46237559d1249f2765.zip
C backend: fix enough that zig test works
* test_functions: properly add dependencies of the array on test functions and test names so that the order comes out correctly. * fix lowering of struct literals to add parentheses around the type name. * omit const qualifier in slices because otherwise slices cannot be reassigned even when they are local variables. * special case pointer to functions and double pointer to functions in renderTypeAndName. This code will need to be cleaned up but for now it helps us make progress on other C backend stuff. * fix slice element access to lower to `.ptr[` instead of `[`. * airSliceElemVal: respect volatile slices
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index e1a407011b..a43c80cb2e 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -252,6 +252,14 @@ pub const Type = extern union {
};
}
+ /// If it is a function pointer, returns the function type. Otherwise returns null.
+ pub fn castPtrToFn(ty: Type) ?Type {
+ if (ty.zigTypeTag() != .Pointer) return null;
+ const elem_ty = ty.childType();
+ if (elem_ty.zigTypeTag() != .Fn) return null;
+ return elem_ty;
+ }
+
pub fn ptrIsMutable(ty: Type) bool {
return switch (ty.tag()) {
.single_const_pointer_to_comptime_int,