Merge pull request #7001 from Vexu/translate-c

Translate-c: fix macro functions with no arguments
This commit is contained in:
Alexandros Naskos 2020-11-06 19:22:56 +02:00 committed by GitHub
commit a1a16a941e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -5437,9 +5437,8 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void {
defer fn_params.deinit(); defer fn_params.deinit();
while (true) { while (true) {
if (m.next().? != .Identifier) { if (m.peek().? != .Identifier) break;
return m.fail(c, "unable to translate C expr: expected identifier", .{}); _ = m.next();
}
const mangled_name = try block_scope.makeMangledName(c, m.slice()); const mangled_name = try block_scope.makeMangledName(c, m.slice());
const param_name_tok = try appendIdentifier(c, mangled_name); const param_name_tok = try appendIdentifier(c, mangled_name);
@ -5459,8 +5458,7 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void {
.param_type = .{ .any_type = &any_type.base }, .param_type = .{ .any_type = &any_type.base },
}; };
if (m.peek().? != .Comma) if (m.peek().? != .Comma) break;
break;
_ = m.next(); _ = m.next();
_ = try appendToken(c, .Comma, ","); _ = try appendToken(c, .Comma, ",");
} }

View File

@ -1589,6 +1589,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\extern int c; \\extern int c;
\\#define BASIC(c) (c*2) \\#define BASIC(c) (c*2)
\\#define FOO(L,b) (L + b) \\#define FOO(L,b) (L + b)
\\#define BAR() (c*c)
, &[_][]const u8{ , &[_][]const u8{
\\pub extern var c: c_int; \\pub extern var c: c_int;
, ,
@ -1599,6 +1600,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) {
\\ return L + b; \\ return L + b;
\\} \\}
,
\\pub inline fn BAR() @TypeOf(c * c) {
\\ return c * c;
\\}
}); });
cases.add("macro defines string literal with hex", cases.add("macro defines string literal with hex",