diff --git a/IDEHelper/Compiler/BfAst.cpp b/IDEHelper/Compiler/BfAst.cpp index 2b7a57c8..752fa5c3 100644 --- a/IDEHelper/Compiler/BfAst.cpp +++ b/IDEHelper/Compiler/BfAst.cpp @@ -1195,6 +1195,23 @@ bool BfTypeReference::IsTypeDefTypeReference() return IsA() || IsA() || IsA(); } +String BfTypeReference::ToCleanAttributeString() +{ + // ToString might return something like "System.InlineAttribute", which we want to clean before we test for "Inline" + auto typeRefName = ToString(); + if (typeRefName.EndsWith("Attribute")) + { + int attribNameStart = (int)typeRefName.LastIndexOf('.'); + if (attribNameStart != -1) + typeRefName.Remove(0, attribNameStart + 1); + + if (typeRefName.EndsWith("Attribute")) + typeRefName.RemoveFromEnd(9); + } + + return typeRefName; +} + ////////////////////////////////////////////////////////////////////////// BfPropertyMethodDeclaration* BfPropertyDeclaration::GetMethod(const StringImpl& findName) @@ -1262,6 +1279,10 @@ bool BfAttributeDirective::Contains(const StringImpl& findName) return true; if (name.EndsWith("Attribute")) { + int attribNameStart = (int)name.LastIndexOf('.'); + if (attribNameStart != -1) + name.Remove(0, attribNameStart + 1); + name.RemoveToEnd(name.length() - 9); if (findName == name) return true; diff --git a/IDEHelper/Compiler/BfAst.h b/IDEHelper/Compiler/BfAst.h index d103fac7..111b1786 100644 --- a/IDEHelper/Compiler/BfAst.h +++ b/IDEHelper/Compiler/BfAst.h @@ -2329,6 +2329,7 @@ public: bool IsNamedTypeReference(); bool IsTypeDefTypeReference(); + String ToCleanAttributeString(); }; BF_AST_DECL(BfTypeReference, BfAstNode); diff --git a/IDEHelper/Compiler/BfDefBuilder.cpp b/IDEHelper/Compiler/BfDefBuilder.cpp index 3e34d58d..2e14cac0 100644 --- a/IDEHelper/Compiler/BfDefBuilder.cpp +++ b/IDEHelper/Compiler/BfDefBuilder.cpp @@ -555,7 +555,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio { if (attributes->mAttributeTypeRef != NULL) { - auto typeRefName = attributes->mAttributeTypeRef->ToString(); + auto typeRefName = attributes->mAttributeTypeRef->ToCleanAttributeString(); if (typeRefName == "StdCall") methodDef->mCallingConvention = BfCallingConvention_Stdcall; @@ -788,7 +788,7 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef { if (attributes->mAttributeTypeRef != NULL) { - auto typeRefName = attributes->mAttributeTypeRef->ToString(); + auto typeRefName = attributes->mAttributeTypeRef->ToCleanAttributeString(); if (typeRefName == "CLink") methodDef->mCLink = true; @@ -874,7 +874,7 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfTypeDef* { if (attributes->mAttributeTypeRef != NULL) { - auto typeRefName = attributes->mAttributeTypeRef->ToString(); + auto typeRefName = attributes->mAttributeTypeRef->ToCleanAttributeString(); if (typeRefName == "AlwaysInclude") typeDef->mIsAlwaysInclude = true; @@ -2098,7 +2098,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) { if (attributes->mAttributeTypeRef != NULL) { - auto typeRefName = attributes->mAttributeTypeRef->ToString(); + auto typeRefName = attributes->mAttributeTypeRef->ToCleanAttributeString(); if (typeRefName == "ThreadStatic") hasThreadStatics = true; diff --git a/IDEHelper/Compiler/BfMangler.cpp b/IDEHelper/Compiler/BfMangler.cpp index 989bb87f..c52dac95 100644 --- a/IDEHelper/Compiler/BfMangler.cpp +++ b/IDEHelper/Compiler/BfMangler.cpp @@ -2367,7 +2367,7 @@ void BfMangler::HandleParamCustomAttributes(BfAttributeDirective* attributes, bo { if (attributes->mAttributeTypeRef != NULL) { - auto typeRefName = attributes->mAttributeTypeRef->ToString(); + auto typeRefName = attributes->mAttributeTypeRef->ToCleanAttributeString(); if (typeRefName == "MangleConst") isConst = true; } diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 80396048..6898766b 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -11367,7 +11367,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri { if (prevCustomAttribute.mType == attrTypeInst) { - Fail(StrFormat("Duplicate '%s' attribute", attributesDirective->mAttributeTypeRef->ToString().c_str()), attributesDirective->mAttributeTypeRef); // CS0579 + Fail(StrFormat("Duplicate '%s' attribute", attributesDirective->mAttributeTypeRef->ToCleanAttributeString().c_str()), attributesDirective->mAttributeTypeRef); // CS0579 } } } diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index df4515c3..853f43a9 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -5158,7 +5158,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) { if (attributes->mAttributeTypeRef != NULL) { - auto typeRefName = attributes->mAttributeTypeRef->ToString(); + auto typeRefName = attributes->mAttributeTypeRef->ToCleanAttributeString(); if (typeRefName == "AlwaysInclude") implRequired = true; diff --git a/IDEHelper/Tests/src/Program.bf b/IDEHelper/Tests/src/Program.bf index fa66b2d0..1b54c3f5 100644 --- a/IDEHelper/Tests/src/Program.bf +++ b/IDEHelper/Tests/src/Program.bf @@ -1,10 +1,19 @@ namespace Tests { + typealias DDDDAttribute = System.InlineAttribute; + class Program { + public static void Main() { + A(); + } + [DDDD] + public static void A() + { + int i = 1 + 2; } } }