CBE: add windows-specific reserved identifiers

This commit is contained in:
Jacob Young 2022-12-06 00:37:36 -05:00 committed by Andrew Kelley
parent c4dc8515b6
commit 3686787f67

View file

@ -120,6 +120,7 @@ pub fn typeToCIdentifier(ty: Type, mod: *Module) std.fmt.Formatter(formatTypeAsC
} }
const reserved_idents = std.ComptimeStringMap(void, .{ const reserved_idents = std.ComptimeStringMap(void, .{
// C language
.{ "alignas", { .{ "alignas", {
@setEvalBranchQuota(4000); @setEvalBranchQuota(4000);
} }, } },
@ -215,14 +216,22 @@ const reserved_idents = std.ComptimeStringMap(void, .{
.{ "void", {} }, .{ "void", {} },
.{ "volatile", {} }, .{ "volatile", {} },
.{ "while ", {} }, .{ "while ", {} },
// windows.h
.{ "max", {} },
.{ "min", {} },
}); });
fn isReservedIdent(ident: []const u8) bool { fn isReservedIdent(ident: []const u8) bool {
if (ident.len >= 2 and ident[0] == '_') { if (ident.len >= 2 and ident[0] == '_') { // C language
switch (ident[1]) { switch (ident[1]) {
'A'...'Z', '_' => return true, 'A'...'Z', '_' => return true,
else => return false, else => return false,
} }
} else if (std.mem.startsWith(u8, ident, "DUMMYSTRUCTNAME") or
std.mem.startsWith(u8, ident, "DUMMYUNIONNAME"))
{ // windows.h
return true;
} else return reserved_idents.has(ident); } else return reserved_idents.has(ident);
} }