| ... | @@ -137,26 +137,6 @@ const Scope = struct { | ... | @@ -137,26 +137,6 @@ const Scope = struct { |
| 137 | }; | 137 | }; |
| 138 | } | 138 | } |
| 139 | | 139 | |
| 140 | /// Given the desired name, return a name that does not shadow anything from outer scopes. | | |
| 141 | /// Does not insert the returned name into the scope. | | |
| 142 | /// Will allow `name` to be one of the preprocessed decl or macro names, but will not | | |
| 143 | /// choose a mangled name that matches one of those. | | |
| 144 | fn makeMangledName(scope: *Root, name: []const u8) ![]const u8 { | | |
| 145 | if (!scope.containsNow(name)) { | | |
| 146 | _ = try scope.context.global_names.put(name, {}); | | |
| 147 | return name; | | |
| 148 | } | | |
| 149 | var proposed_name = name; | | |
| 150 | while (scope.contains(proposed_name)) { | | |
| 151 | proposed_name = try std.fmt.allocPrint(scope.context.a(), "{}_{}", .{ | | |
| 152 | name, | | |
| 153 | scope.context.getMangle(), | | |
| 154 | }); | | |
| 155 | } | | |
| 156 | _ = try scope.context.global_names.put(proposed_name, {}); | | |
| 157 | return proposed_name; | | |
| 158 | } | | |
| 159 | | | |
| 160 | /// Check if the global scope contains this name, without looking into the "future", e.g. | 140 | /// Check if the global scope contains this name, without looking into the "future", e.g. |
| 161 | /// ignore the preprocessed decl and macro names. | 141 | /// ignore the preprocessed decl and macro names. |
| 162 | fn containsNow(scope: *Root, name: []const u8) bool { | 142 | fn containsNow(scope: *Root, name: []const u8) bool { |
| ... | @@ -4330,7 +4310,10 @@ fn transPreprocessorEntities(c: *Context, unit: *ZigClangASTUnit) Error!void { | ... | @@ -4330,7 +4310,10 @@ fn transPreprocessorEntities(c: *Context, unit: *ZigClangASTUnit) Error!void { |
| 4330 | const name = try c.str(raw_name); | 4310 | const name = try c.str(raw_name); |
| 4331 | // TODO https://github.com/ziglang/zig/issues/3756 | 4311 | // TODO https://github.com/ziglang/zig/issues/3756 |
| 4332 | // TODO https://github.com/ziglang/zig/issues/1802 | 4312 | // TODO https://github.com/ziglang/zig/issues/1802 |
| 4333 | const mangled_name = try scope.makeMangledName(name); | 4313 | const mangled_name = if (isZigPrimitiveType(name)) try std.fmt.allocPrint(c.a(), "_{}", .{name}) else name; |
| | 4314 | if (scope.containsNow(mangled_name)) { |
| | 4315 | continue; |
| | 4316 | } |
| 4334 | | 4317 | |
| 4335 | const begin_c = ZigClangSourceManager_getCharacterData(c.source_manager, begin_loc); | 4318 | const begin_c = ZigClangSourceManager_getCharacterData(c.source_manager, begin_loc); |
| 4336 | ctok.tokenizeCMacro(c, begin_loc, mangled_name, &tok_list, begin_c) catch |err| switch (err) { | 4319 | ctok.tokenizeCMacro(c, begin_loc, mangled_name, &tok_list, begin_c) catch |err| switch (err) { |