translate-c: fix regression from previous commit

This made macros which had an error being processed emit multiple times,
causing the self-hosted compiler to fail to build.
This commit is contained in:
Andrew Kelley 2020-01-01 19:57:27 -05:00
parent ec09b9e5f0
commit 365a6124d9
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -138,7 +138,7 @@ const Scope = struct {
}
/// Given the desired name, return a name that does not shadow anything from outer scopes.
/// Inserts the returned name into the scope.
/// Does not insert the returned name into the scope.
/// Will allow `name` to be one of the preprocessed decl or macro names, but will not
/// choose a mangled name that matches one of those.
fn makeMangledName(scope: *Root, name: []const u8) ![]const u8 {
@ -4328,9 +4328,12 @@ fn transPreprocessorEntities(c: *Context, unit: *ZigClangASTUnit) Error!void {
const begin_loc = ZigClangMacroDefinitionRecord_getSourceRange_getBegin(macro);
const name = try c.str(raw_name);
// TODO https://github.com/ziglang/zig/issues/3756
// TODO https://github.com/ziglang/zig/issues/1802
const mangled_name = try scope.makeMangledName(name);
const begin_c = ZigClangSourceManager_getCharacterData(c.source_manager, begin_loc);
ctok.tokenizeCMacro(c, begin_loc, name, &tok_list, begin_c) catch |err| switch (err) {
ctok.tokenizeCMacro(c, begin_loc, mangled_name, &tok_list, begin_c) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
else => {
continue;
@ -4357,9 +4360,6 @@ fn transPreprocessorEntities(c: *Context, unit: *ZigClangASTUnit) Error!void {
else => {},
}
// TODO https://github.com/ziglang/zig/issues/3756
// TODO https://github.com/ziglang/zig/issues/1802
const mangled_name = try scope.makeMangledName(name);
const macro_fn = if (tok_it.peek().?.id == .Fn) blk: {
_ = tok_it.next();
break :blk true;