add C pointer type to @typeInfo

See #1059
This commit is contained in:
Andrew Kelley
2019-02-11 16:07:40 -05:00
parent 342bca7f46
commit 90b8cd4a45
7 changed files with 41 additions and 6 deletions

View File

@@ -236,6 +236,9 @@ pub fn formatType(
const casted_value = ([]const u8)(value);
return output(context, casted_value);
},
builtin.TypeInfo.Pointer.Size.C => {
return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
},
},
builtin.TypeId.Array => |info| {
if (info.child == u8) {

View File

@@ -463,13 +463,16 @@ pub fn eql(a: var, b: @typeOf(a)) bool {
builtin.TypeId.Pointer => {
const info = @typeInfo(T).Pointer;
switch (info.size) {
builtin.TypeInfo.Pointer.Size.One, builtin.TypeInfo.Pointer.Size.Many => return a == b,
builtin.TypeInfo.Pointer.Size.One,
builtin.TypeInfo.Pointer.Size.Many,
builtin.TypeInfo.Pointer.Size.C,
=> return a == b,
builtin.TypeInfo.Pointer.Size.Slice => return a.ptr == b.ptr and a.len == b.len,
}
},
builtin.TypeId.Optional => {
if(a == null and b == null) return true;
if(a == null or b == null) return false;
if (a == null and b == null) return true;
if (a == null or b == null) return false;
return eql(a.?, b.?);
},
else => return a == b,

View File

@@ -69,7 +69,7 @@ pub fn expectEqual(expected: var, actual: var) void {
}
},
builtin.TypeInfo.Pointer.Size.Slice => {
builtin.TypeInfo.Pointer.Size.Slice => {
if (actual.ptr != expected.ptr) {
std.debug.panic("expected slice ptr {}, found {}", expected.ptr, actual.ptr);
}
@@ -122,7 +122,6 @@ pub fn expectEqual(expected: var, actual: var) void {
}
}
},
}
}