zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit fa9fcab620ada24d9bb7c51a86a1a8944056da02 (tree)
parent 0a8a7a57e7a6b4b5a0d1523bde57b2a4b93fa50a
Author: Sahnvour <sahnvour@pm.me>
Date:   Sun, 10 Mar 2019 14:43:35 +0100

translate-c: add support for integer suffixes on 0 (zero) litteral inside macro definitions

Diffstat:
Msrc/c_tokenizer.cpp | 7+++++++
Mtest/translate_c.zig | 42++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/src/c_tokenizer.cpp b/src/c_tokenizer.cpp @@ -362,6 +362,13 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) { ctok->cur_tok->id = CTokIdNumLitFloat; buf_append_char(&ctok->buf, '.'); break; + case 'l': + case 'L': + case 'u': + case 'U': + c -= 1; + ctok->state = CTokStateDecimal; + continue; default: c -= 1; ctok->state = CTokStateOctal; diff --git a/test/translate_c.zig b/test/translate_c.zig @@ -1425,6 +1425,48 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn bar() void {} ); + cases.addC("u integer suffix after 0 (zero) in macro definition", + "#define ZERO 0U" + , + "pub const ZERO = c_uint(0);" + ); + + cases.addC("l integer suffix after 0 (zero) in macro definition", + "#define ZERO 0L" + , + "pub const ZERO = c_long(0);" + ); + + cases.addC("ul integer suffix after 0 (zero) in macro definition", + "#define ZERO 0UL" + , + "pub const ZERO = c_ulong(0);" + ); + + cases.addC("lu integer suffix after 0 (zero) in macro definition", + "#define ZERO 0LU" + , + "pub const ZERO = c_ulong(0);" + ); + + cases.addC("ll integer suffix after 0 (zero) in macro definition", + "#define ZERO 0LL" + , + "pub const ZERO = c_longlong(0);" + ); + + cases.addC("ull integer suffix after 0 (zero) in macro definition", + "#define ZERO 0ULL" + , + "pub const ZERO = c_ulonglong(0);" + ); + + cases.addC("llu integer suffix after 0 (zero) in macro definition", + "#define ZERO 0LLU" + , + "pub const ZERO = c_ulonglong(0);" + ); + // cases.add("empty array with initializer", // "int a[4] = {};" // ,