diff --git a/BeefLibs/corlib/src/Compiler.bf b/BeefLibs/corlib/src/Compiler.bf index 9a97cd26..b0785400 100644 --- a/BeefLibs/corlib/src/Compiler.bf +++ b/BeefLibs/corlib/src/Compiler.bf @@ -8,6 +8,32 @@ namespace System { static class Compiler { + public class Identifier + { + public static HashSet sReservedNameSet = new .() ~ delete _; + + const String[?] cReservedNames = .("abstract", "alignof", "alloctype", "append", "as", "asm", "base", "break", + "case", "catch", "checked", "class", "comptype", "const", "continue", "decltype", "default", "defer", "delegate", + "delete", "do", "else", "enum", "explicit", "extension", "extern", "false", "finally", "fixed", "for", "function", + "if", "implicit", "in", "interface", "internal", "is", "isconst", "mixin", "namespace", "new", "null", "nullable", + "offsetof", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", + "rettype", "return", "scope", "sealed", "sizeof", "static", "strideof", "struct", "switch", "this", "true", "try", + "typealias", "typeof", "unchecked", "using", "var", "virtual", "volatile", "where", "while"); + + public static this() + { + for (var name in cReservedNames) + sReservedNameSet.Add(name); + } + + public static void GetSourceName(StringView name, String outStr) + { + if (sReservedNameSet.ContainsAlt(name)) + outStr.Append('@'); + outStr.Append(name); + } + } + public abstract class Generator { public enum Flags diff --git a/BeefLibs/corlib/src/Enum.bf b/BeefLibs/corlib/src/Enum.bf index 9ac0286d..c6bbb655 100644 --- a/BeefLibs/corlib/src/Enum.bf +++ b/BeefLibs/corlib/src/Enum.bf @@ -609,7 +609,7 @@ namespace System entryTableCode.Append(", \""); entryTableCode.Append(fieldName); entryTableCode.Append("\", ."); - entryTableCode.Append(fieldInfo.Name); + fieldInfo.GetSourceName(entryTableCode); entryTableCode.Append(", "); entryTableCode.Append((nextCases[caseIdx] == -1) ? "false" : "true"); entryTableCode.Append(")"); @@ -622,7 +622,11 @@ namespace System if (caseHasPayload) code.AppendF($"\t\t\t\tmatchIdx = {caseIdx};\n"); else - code.AppendF($"\t\t\t\treturn .Ok(.{fieldInfo.Name});\n"); + { + code.Append("\t\t\t\treturn .Ok(."); + fieldInfo.GetSourceName(code); + code.Append(");\n"); + } } else { diff --git a/BeefLibs/corlib/src/Reflection/FieldInfo.bf b/BeefLibs/corlib/src/Reflection/FieldInfo.bf index bdd92491..7ce4b5d2 100644 --- a/BeefLibs/corlib/src/Reflection/FieldInfo.bf +++ b/BeefLibs/corlib/src/Reflection/FieldInfo.bf @@ -38,6 +38,11 @@ namespace System.Reflection mFieldData.mCustomAttributesIdx : -1; + public void GetSourceName(String outStr) + { + Compiler.Identifier.GetSourceName(Name, outStr); + } + public Result SetValue(Object obj, Object value) { void* dataAddr = ((uint8*)Internal.UnsafeCastToPtr(obj));