| ... | @@ -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; |
| ... | @@ -1737,7 +1738,7 @@ fn transImplicitCastExpr( | ... | @@ -1737,7 +1738,7 @@ fn transImplicitCastExpr( |
| 1737 | } | 1738 | } |
| 1738 | | 1739 | |
| 1739 | fn isBuiltinDefined(name: []const u8) bool { | 1740 | fn isBuiltinDefined(name: []const u8) bool { |
| 1740 | inline for (std.meta.declarations(c_builtins)) |decl| { | 1741 | inline for (meta.declarations(c_builtins)) |decl| { |
| 1741 | if (std.mem.eql(u8, name, decl.name)) return true; | 1742 | if (std.mem.eql(u8, name, decl.name)) return true; |
| 1742 | } | 1743 | } |
| 1743 | return false; | 1744 | return false; |
| ... | @@ -3136,7 +3137,7 @@ const ClangFunctionType = union(enum) { | ... | @@ -3136,7 +3137,7 @@ const ClangFunctionType = union(enum) { |
| 3136 | NoProto: *const clang.FunctionType, | 3137 | NoProto: *const clang.FunctionType, |
| 3137 | | 3138 | |
| 3138 | fn getReturnType(self: @This()) clang.QualType { | 3139 | fn getReturnType(self: @This()) clang.QualType { |
| 3139 | switch (@as(std.meta.Tag(@This()), self)) { | 3140 | switch (@as(meta.Tag(@This()), self)) { |
| 3140 | .Proto => return self.Proto.getReturnType(), | 3141 | .Proto => return self.Proto.getReturnType(), |
| 3141 | .NoProto => return self.NoProto.getReturnType(), | 3142 | .NoProto => return self.NoProto.getReturnType(), |
| 3142 | } | 3143 | } |
| ... | @@ -4072,7 +4073,7 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node { | ... | @@ -4072,7 +4073,7 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node { |
| 4072 | } | 4073 | } |
| 4073 | | 4074 | |
| 4074 | fn transCreateNodeNumber(c: *Context, num: anytype, num_kind: enum { int, float }) !Node { | 4075 | fn transCreateNodeNumber(c: *Context, num: anytype, num_kind: enum { int, float }) !Node { |
| 4075 | const fmt_s = if (comptime std.meta.trait.isNumber(@TypeOf(num))) "{d}" else "{s}"; | 4076 | const fmt_s = if (comptime meta.trait.isNumber(@TypeOf(num))) "{d}" else "{s}"; |
| 4076 | const str = try std.fmt.allocPrint(c.arena, fmt_s, .{num}); | 4077 | const str = try std.fmt.allocPrint(c.arena, fmt_s, .{num}); |
| 4077 | if (num_kind == .float) | 4078 | if (num_kind == .float) |
| 4078 | return Tag.float_literal.create(c.arena, str) | 4079 | return Tag.float_literal.create(c.arena, str) |
| ... | @@ -4827,12 +4828,12 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node { | ... | @@ -4827,12 +4828,12 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node { |
| 4827 | // make the output less noisy by skipping promoteIntLiteral where | 4828 | // make the output less noisy by skipping promoteIntLiteral where |
| 4828 | // it's guaranteed to not be required because of C standard type constraints | 4829 | // it's guaranteed to not be required because of C standard type constraints |
| 4829 | const guaranteed_to_fit = switch (suffix) { | 4830 | const guaranteed_to_fit = switch (suffix) { |
| 4830 | .none => if (math.cast(i16, value)) |_| true else |_| false, | 4831 | .none => !meta.isError(math.cast(i16, value)), |
| 4831 | .u => if (math.cast(u16, value)) |_| true else |_| false, | 4832 | .u => !meta.isError(math.cast(u16, value)), |
| 4832 | .l => if (math.cast(i32, value)) |_| true else |_| false, | 4833 | .l => !meta.isError(math.cast(i32, value)), |
| 4833 | .lu => if (math.cast(u32, value)) |_| true else |_| false, | 4834 | .lu => !meta.isError(math.cast(u32, value)), |
| 4834 | .ll => if (math.cast(i64, value)) |_| true else |_| false, | 4835 | .ll => !meta.isError(math.cast(i64, value)), |
| 4835 | .llu => if (math.cast(u64, value)) |_| true else |_| false, | 4836 | .llu => !meta.isError(math.cast(u64, value)), |
| 4836 | .f => unreachable, | 4837 | .f => unreachable, |
| 4837 | }; | 4838 | }; |
| 4838 | | 4839 | |