diff --git a/BeefLibs/Beefy2D/src/BFWindow.bf b/BeefLibs/Beefy2D/src/BFWindow.bf index 02778bc1..482ee9ab 100644 --- a/BeefLibs/Beefy2D/src/BFWindow.bf +++ b/BeefLibs/Beefy2D/src/BFWindow.bf @@ -49,6 +49,7 @@ namespace Beefy ShowMaximized = 0x0400'0000, }; + [AllowDuplicates] public enum HitTestResult { NotHandled = -3, diff --git a/BeefLibs/Beefy2D/src/widgets/KeyCode.bf b/BeefLibs/Beefy2D/src/widgets/KeyCode.bf index 734cf6d6..c531c727 100644 --- a/BeefLibs/Beefy2D/src/widgets/KeyCode.bf +++ b/BeefLibs/Beefy2D/src/widgets/KeyCode.bf @@ -18,14 +18,17 @@ namespace Beefy.widgets Shift = 0x10, Control = 0x11, Alt = 0x12, +#unwarn Menu = 0x12, Pause = 0x13, Capital = 0x14, Kana = 0x15, +#unwarn Hangul = 0x15, Junja = 0x17, Final = 0x18, Hanja = 0x19, +#unwarn Kanji = 0x19, Escape = 0x1B, Convert = 0x1C, diff --git a/BeefLibs/SDL2/src/SDL2.bf b/BeefLibs/SDL2/src/SDL2.bf index cf6ddf0b..c61d910f 100644 --- a/BeefLibs/SDL2/src/SDL2.bf +++ b/BeefLibs/SDL2/src/SDL2.bf @@ -1521,6 +1521,7 @@ namespace SDL2 ArrayF32 } + [AllowDuplicates] public enum SDL_PIXELORDER_ENUM : uint32 { /* BITMAPORDER */ @@ -2967,6 +2968,7 @@ namespace SDL2 void* userdata ); + [AllowDuplicates] enum EventState : int32 { Query = -1, @@ -3272,6 +3274,7 @@ namespace SDL2 * and all of the names are in an anonymous enum. Yeah... * that's not going to cut it for C#. We'll just put them in an * enum for now? */ + [AllowDuplicates] public enum Keycode : uint32 { UNKNOWN = 0, diff --git a/BeefLibs/corlib/src/Attribute.bf b/BeefLibs/corlib/src/Attribute.bf index 8269f27c..72dcdf2f 100644 --- a/BeefLibs/corlib/src/Attribute.bf +++ b/BeefLibs/corlib/src/Attribute.bf @@ -237,6 +237,12 @@ namespace System } } + [AttributeUsage(.Enum)] + public struct AllowDuplicatesAttribute : Attribute + { + + } + [AttributeUsage(.Class | .Struct)] public struct UnionAttribute : Attribute { diff --git a/IDE/mintest/minlib/src/System/Attribute.bf b/IDE/mintest/minlib/src/System/Attribute.bf index 6892b9fe..b448f6ca 100644 --- a/IDE/mintest/minlib/src/System/Attribute.bf +++ b/IDE/mintest/minlib/src/System/Attribute.bf @@ -251,6 +251,12 @@ namespace System } } + [AttributeUsage(.Enum)] + public struct AllowDuplicatesAttribute : Attribute + { + + } + [AttributeUsage(.Class | .Struct)] public struct UnionAttribute : Attribute { diff --git a/IDE/mintest/minlib/src/System/Type.bf b/IDE/mintest/minlib/src/System/Type.bf index ad1daa7e..4e28cedf 100644 --- a/IDE/mintest/minlib/src/System/Type.bf +++ b/IDE/mintest/minlib/src/System/Type.bf @@ -848,6 +848,7 @@ namespace System.Reflection EnumDiscriminator = 0x0200 } + [AllowDuplicates] public enum MethodFlags : int16 { MethodAccessMask = 0x0007, @@ -869,6 +870,7 @@ namespace System.Reflection // vtable layout mask - Use this mask to retrieve vtable attributes. VtableLayoutMask = 0x0100, + ReuseSlot = 0x0000, // The default. NewSlot = 0x0100, // Method always gets a new slot in the vtable. // end vtable layout mask diff --git a/IDE/mintest/src/main3.bf b/IDE/mintest/src/main3.bf index 9cb29869..f0585e42 100644 --- a/IDE/mintest/src/main3.bf +++ b/IDE/mintest/src/main3.bf @@ -8,11 +8,14 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading; +[AllowDuplicates] enum EnumA { Abo = 1, Boop = _*2, Croop = _*2, + + Zoop = 1 } struct Blurg diff --git a/IDEHelper/Compiler/BfAst.cpp b/IDEHelper/Compiler/BfAst.cpp index 0918d2af..1dd0b7b6 100644 --- a/IDEHelper/Compiler/BfAst.cpp +++ b/IDEHelper/Compiler/BfAst.cpp @@ -762,6 +762,15 @@ bool BfAstNode::IsExpression() return IsA(); } +bool BfAstNode::WantsWarning(int warningNumber) +{ + auto parserData = GetParserData(); + if (parserData == NULL) + return true; + int srcStart = GetSrcStart(); + return (!parserData->IsUnwarnedAt(this)) && (parserData->IsWarningEnabledAtSrcIndex(warningNumber, GetSrcStart())); +} + bool BfAstNode::LocationEquals(BfAstNode* otherNode) { return (GetSourceData() == otherNode->GetSourceData()) && diff --git a/IDEHelper/Compiler/BfAst.h b/IDEHelper/Compiler/BfAst.h index 4b4e15d0..5b6572da 100644 --- a/IDEHelper/Compiler/BfAst.h +++ b/IDEHelper/Compiler/BfAst.h @@ -1040,6 +1040,7 @@ public: void Add(BfAstNode* bfAstNode); bool IsMissingSemicolon(); bool IsExpression(); + bool WantsWarning(int warningNumber); template bool IsA() diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index c690f9fc..41706047 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -382,6 +382,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) mImportAttributeTypeDef = NULL; mCReprAttributeTypeDef = NULL; mAlignAttributeTypeDef = NULL; + mAllowDuplicatesAttributeTypeDef = NULL; mNoDiscardAttributeTypeDef = NULL; mDisableChecksAttributeTypeDef = NULL; mDisableObjectAccessChecksAttributeTypeDef = NULL; @@ -5856,6 +5857,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mImportAttributeTypeDef = _GetRequiredType("System.ImportAttribute"); mCReprAttributeTypeDef = _GetRequiredType("System.CReprAttribute"); mAlignAttributeTypeDef = _GetRequiredType("System.AlignAttribute"); + mAllowDuplicatesAttributeTypeDef = _GetRequiredType("System.AllowDuplicatesAttribute"); mNoDiscardAttributeTypeDef = _GetRequiredType("System.NoDiscardAttribute"); mDisableChecksAttributeTypeDef = _GetRequiredType("System.DisableChecksAttribute"); mDisableObjectAccessChecksAttributeTypeDef = _GetRequiredType("System.DisableObjectAccessChecksAttribute"); diff --git a/IDEHelper/Compiler/BfCompiler.h b/IDEHelper/Compiler/BfCompiler.h index 949a0345..896426df 100644 --- a/IDEHelper/Compiler/BfCompiler.h +++ b/IDEHelper/Compiler/BfCompiler.h @@ -380,6 +380,7 @@ public: BfTypeDef* mImportAttributeTypeDef; BfTypeDef* mCReprAttributeTypeDef; BfTypeDef* mAlignAttributeTypeDef; + BfTypeDef* mAllowDuplicatesAttributeTypeDef; BfTypeDef* mNoDiscardAttributeTypeDef; BfTypeDef* mDisableChecksAttributeTypeDef; BfTypeDef* mDisableObjectAccessChecksAttributeTypeDef; diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index dbbf6884..62b5112b 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -2940,7 +2940,7 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI } } - if ((mModule->mCurMethodInstance == NULL) && (mModule->mCurTypeInstance->IsEnum())) + if ((mModule->mCurMethodInstance == NULL) && (mModule->mCurTypeInstance != NULL) && (mModule->mCurTypeInstance->IsEnum())) { if (findName == "_") { diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 6b65f424..00600c48 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -2990,7 +2990,7 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy { *fieldDefPtr = fieldDef; } - else + else if ((typeInstance->mCustomAttributes == NULL) || (typeInstance->mCustomAttributes->Get(mCompiler->mAllowDuplicatesAttributeTypeDef) == NULL)) { auto error = Warn(0, StrFormat("Enum value '%lld' for field '%s' is not unique", foreignConst->mInt64, fieldDef->mName.c_str()), fieldDef->GetRefNode(), true); if (error != NULL)