translate-c: translate valueless macros as empty strings

This commit is contained in:
Evan Haas 2021-08-31 20:14:30 -07:00 committed by Andrew Kelley
parent 0932b0d9b3
commit c0e84e3ee0
2 changed files with 11 additions and 2 deletions

View File

@ -401,7 +401,7 @@ pub fn translate(
.name = decl.name,
.init = try Tag.import_builtin.create(context.arena, decl.name),
});
try context.global_scope.nodes.append(builtin);
try addTopLevelDecl(&context, decl.name, builtin);
}
}
@ -5347,7 +5347,10 @@ fn transPreprocessorEntities(c: *Context, unit: *clang.ASTUnit) Error!void {
},
.Nl, .Eof => {
// this means it is a macro without a value
// we don't care about such things
// We define it as an empty string so that it can still be used with ++
const str_node = try Tag.string_literal.create(c.arena, "\"\"");
const var_decl = try Tag.pub_var_simple.create(c.arena, .{ .name = name, .init = str_node });
try c.global_scope.macro_table.put(name, var_decl);
continue;
},
.LParen => {

View File

@ -3678,4 +3678,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
, &[_][]const u8{
\\pub const FOO = @compileError("unable to translate macro: undefined identifier `std`");
});
cases.add("Macro without a value",
\\#define FOO
, &[_][]const u8{
\\pub const FOO = "";
});
}