From 2fdf87c7a2edb76c688f93baf31905d58e6e8a8c Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 25 Jan 2022 10:41:18 -0500 Subject: [PATCH] Fixes for global ctor/dtor/mark --- IDEHelper/Compiler/BfMangler.cpp | 18 ++++++---- IDEHelper/Compiler/BfSystem.cpp | 59 +++++++++++++++++--------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/IDEHelper/Compiler/BfMangler.cpp b/IDEHelper/Compiler/BfMangler.cpp index 2f0905e2..3dc75548 100644 --- a/IDEHelper/Compiler/BfMangler.cpp +++ b/IDEHelper/Compiler/BfMangler.cpp @@ -916,9 +916,11 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) if (methodDef->mHasComptime) name += "`COMPTIME"; - if ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (methodInst->mMethodDef->mDeclaringType->IsExtension()) && - (!methodInst->mIsForeignMethodDef) && (!methodInst->mMethodDef->mIsExtern) && - ((!methodInst->mMethodDef->mIsOverride) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS) || (methodDef->mMethodType == BfMethodType_Dtor))) + if (((methodInst->GetOwner()->mTypeDef->IsGlobalsContainer()) && + ((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_Dtor) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS_STATIC))) || + ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (methodInst->mMethodDef->mDeclaringType->IsExtension()) && + (!methodInst->mIsForeignMethodDef) && (!methodInst->mMethodDef->mIsExtern) && + ((!methodInst->mMethodDef->mIsOverride) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS) || (methodDef->mMethodType == BfMethodType_Dtor)))) { auto declType = methodInst->mMethodDef->mDeclaringType; BF_ASSERT(methodInst->GetOwner()->mTypeDef->mIsCombinedPartial); @@ -2073,10 +2075,12 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho else AddStr(mangleContext, name, methodDef->mName); } - - if ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (methodInst->mMethodDef->mDeclaringType->IsExtension()) && - (!methodInst->mIsForeignMethodDef) && (!methodInst->mMethodDef->mIsExtern) && - ((!methodInst->mMethodDef->mIsOverride) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS) || (methodDef->mMethodType == BfMethodType_Dtor))) + + if (((methodInst->GetOwner()->mTypeDef->IsGlobalsContainer()) && + ((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_Dtor) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS_STATIC))) || + ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (methodInst->mMethodDef->mDeclaringType->IsExtension()) && + (!methodInst->mIsForeignMethodDef) && (!methodInst->mMethodDef->mIsExtern) && + ((!methodInst->mMethodDef->mIsOverride) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS) || (methodDef->mMethodType == BfMethodType_Dtor)))) { auto declType = methodInst->mMethodDef->mDeclaringType; BF_ASSERT(methodInst->GetOwner()->mTypeDef->mIsCombinedPartial); diff --git a/IDEHelper/Compiler/BfSystem.cpp b/IDEHelper/Compiler/BfSystem.cpp index 80728e79..5b6c7f62 100644 --- a/IDEHelper/Compiler/BfSystem.cpp +++ b/IDEHelper/Compiler/BfSystem.cpp @@ -3139,7 +3139,7 @@ void BfSystem::FinishCompositePartial(BfTypeDef* compositeTypeDef) _HasMethods allHasMethods[2][2] = { 0 }; auto primaryDef = nextRevision->mPartials[0]; - + //Dictionary projectCount; bool hasCtorNoBody = false; @@ -3151,6 +3151,8 @@ void BfSystem::FinishCompositePartial(BfTypeDef* compositeTypeDef) for (auto partialTypeDef : nextRevision->mPartials) { bool isExtension = partialTypeDef->mTypeDeclaration != nextRevision->mTypeDeclaration; + if (!isExtension) + primaryDef = partialTypeDef; bool hasInitializers = false; for (auto methodDef : partialTypeDef->mMethods) @@ -3218,37 +3220,40 @@ void BfSystem::FinishCompositePartial(BfTypeDef* compositeTypeDef) // methodDef->mIsMutating = true; // } - // Static ctor - if ((allHasMethods[0][1].mCtor == 0) && (allHasMethods[1][1].mCtor > 1)) + if (!primaryDef->IsGlobalsContainer()) { - auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Ctor, BfProtection_Public, true, ""); - methodDef->mDeclaringType = primaryDef; - } + // Static ctor + if ((allHasMethods[0][1].mCtor == 0) && (allHasMethods[1][1].mCtor > 1)) + { + auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Ctor, BfProtection_Public, true, ""); + methodDef->mDeclaringType = primaryDef; + } - if ((allHasMethods[0][0].mDtor == 0) && (allHasMethods[1][0].mDtor > 1)) - { - auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Dtor, BfProtection_Public, false, ""); - methodDef->mDeclaringType = primaryDef; - } + if ((allHasMethods[0][0].mDtor == 0) && (allHasMethods[1][0].mDtor > 1)) + { + auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Dtor, BfProtection_Public, false, ""); + methodDef->mDeclaringType = primaryDef; + } - if ((allHasMethods[0][1].mDtor == 0) && (allHasMethods[1][1].mDtor > 1)) - { - auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Dtor, BfProtection_Public, true, ""); - methodDef->mDeclaringType = primaryDef; - } + if ((allHasMethods[0][1].mDtor == 0) && (allHasMethods[1][1].mDtor > 1)) + { + auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Dtor, BfProtection_Public, true, ""); + methodDef->mDeclaringType = primaryDef; + } - if ((allHasMethods[0][0].mMark == 0) && (allHasMethods[1][0].mMark > 1)) - { - auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Normal, BfProtection_Public, false, BF_METHODNAME_MARKMEMBERS); - methodDef->mDeclaringType = primaryDef; - methodDef->mIsVirtual = true; - methodDef->mIsOverride = true; - } + if ((allHasMethods[0][0].mMark == 0) && (allHasMethods[1][0].mMark > 1)) + { + auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Normal, BfProtection_Public, false, BF_METHODNAME_MARKMEMBERS); + methodDef->mDeclaringType = primaryDef; + methodDef->mIsVirtual = true; + methodDef->mIsOverride = true; + } - if ((allHasMethods[0][1].mMark == 0) && (allHasMethods[1][1].mMark > 1)) - { - auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Normal, BfProtection_Public, true, BF_METHODNAME_MARKMEMBERS_STATIC); - methodDef->mDeclaringType = primaryDef; + if ((allHasMethods[0][1].mMark == 0) && (allHasMethods[1][1].mMark > 1)) + { + auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Normal, BfProtection_Public, true, BF_METHODNAME_MARKMEMBERS_STATIC); + methodDef->mDeclaringType = primaryDef; + } } // If this fails, it's probably because there were no actual composite pieces to put into it