| ... | @@ -8,6 +8,7 @@ const ctok = std.c.tokenizer; | ... | @@ -8,6 +8,7 @@ const ctok = std.c.tokenizer; |
| 8 | const CToken = std.c.Token; | 8 | const CToken = std.c.Token; |
| 9 | const mem = std.mem; | 9 | const mem = std.mem; |
| 10 | const math = std.math; | 10 | const math = std.math; |
| | 11 | const meta = std.meta; |
| 11 | const ast = @import("translate_c/ast.zig"); | 12 | const ast = @import("translate_c/ast.zig"); |
| 12 | const Node = ast.Node; | 13 | const Node = ast.Node; |
| 13 | const Tag = Node.Tag; | 14 | const Tag = Node.Tag; |
| ... | @@ -1741,7 +1742,7 @@ fn transImplicitCastExpr( | ... | @@ -1741,7 +1742,7 @@ fn transImplicitCastExpr( |
| 1741 | } | 1742 | } |
| 1742 | | 1743 | |
| 1743 | fn isBuiltinDefined(name: []const u8) bool { | 1744 | fn isBuiltinDefined(name: []const u8) bool { |
| 1744 | inline for (std.meta.declarations(c_builtins)) |decl| { | 1745 | inline for (meta.declarations(c_builtins)) |decl| { |
| 1745 | if (std.mem.eql(u8, name, decl.name)) return true; | 1746 | if (std.mem.eql(u8, name, decl.name)) return true; |
| 1746 | } | 1747 | } |
| 1747 | return false; | 1748 | return false; |
| ... | @@ -3157,7 +3158,7 @@ const ClangFunctionType = union(enum) { | ... | @@ -3157,7 +3158,7 @@ const ClangFunctionType = union(enum) { |
| 3157 | NoProto: *const clang.FunctionType, | 3158 | NoProto: *const clang.FunctionType, |
| 3158 | | 3159 | |
| 3159 | fn getReturnType(self: @This()) clang.QualType { | 3160 | fn getReturnType(self: @This()) clang.QualType { |
| 3160 | switch (@as(std.meta.Tag(@This()), self)) { | 3161 | switch (@as(meta.Tag(@This()), self)) { |
| 3161 | .Proto => return self.Proto.getReturnType(), | 3162 | .Proto => return self.Proto.getReturnType(), |
| 3162 | .NoProto => return self.NoProto.getReturnType(), | 3163 | .NoProto => return self.NoProto.getReturnType(), |
| 3163 | } | 3164 | } |
| ... | @@ -4106,7 +4107,7 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node { | ... | @@ -4106,7 +4107,7 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node { |
| 4106 | } | 4107 | } |
| 4107 | | 4108 | |
| 4108 | fn transCreateNodeNumber(c: *Context, num: anytype, num_kind: enum { int, float }) !Node { | 4109 | fn transCreateNodeNumber(c: *Context, num: anytype, num_kind: enum { int, float }) !Node { |
| 4109 | const fmt_s = if (comptime std.meta.trait.isNumber(@TypeOf(num))) "{d}" else "{s}"; | 4110 | const fmt_s = if (comptime meta.trait.isNumber(@TypeOf(num))) "{d}" else "{s}"; |
| 4110 | const str = try std.fmt.allocPrint(c.arena, fmt_s, .{num}); | 4111 | const str = try std.fmt.allocPrint(c.arena, fmt_s, .{num}); |
| 4111 | if (num_kind == .float) | 4112 | if (num_kind == .float) |
| 4112 | return Tag.float_literal.create(c.arena, str) | 4113 | return Tag.float_literal.create(c.arena, str) |
| ... | @@ -4861,12 +4862,12 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node { | ... | @@ -4861,12 +4862,12 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node { |
| 4861 | // make the output less noisy by skipping promoteIntLiteral where | 4862 | // make the output less noisy by skipping promoteIntLiteral where |
| 4862 | // it's guaranteed to not be required because of C standard type constraints | 4863 | // it's guaranteed to not be required because of C standard type constraints |
| 4863 | const guaranteed_to_fit = switch (suffix) { | 4864 | const guaranteed_to_fit = switch (suffix) { |
| 4864 | .none => if (math.cast(i16, value)) |_| true else |_| false, | 4865 | .none => !meta.isError(math.cast(i16, value)), |
| 4865 | .u => if (math.cast(u16, value)) |_| true else |_| false, | 4866 | .u => !meta.isError(math.cast(u16, value)), |
| 4866 | .l => if (math.cast(i32, value)) |_| true else |_| false, | 4867 | .l => !meta.isError(math.cast(i32, value)), |
| 4867 | .lu => if (math.cast(u32, value)) |_| true else |_| false, | 4868 | .lu => !meta.isError(math.cast(u32, value)), |
| 4868 | .ll => if (math.cast(i64, value)) |_| true else |_| false, | 4869 | .ll => !meta.isError(math.cast(i64, value)), |
| 4869 | .llu => if (math.cast(u64, value)) |_| true else |_| false, | 4870 | .llu => !meta.isError(math.cast(u64, value)), |
| 4870 | .f => unreachable, | 4871 | .f => unreachable, |
| 4871 | }; | 4872 | }; |
| 4872 | | 4873 | |