From 5618718e8dd8b0bfe97085101914f6167abeaed0 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 23 Oct 2021 08:46:17 -0700 Subject: [PATCH] Fixed base type with 'static using' typeref lookup --- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 189 ++++++++++++----------- IDEHelper/Compiler/BfResolvedTypeUtils.h | 1 + 2 files changed, 98 insertions(+), 92 deletions(-) diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 4efe1eb4..f618c3b1 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -2679,6 +2679,98 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (!typeInstance->mTypeFailed) CheckCircularDataError(); + if (typeInstance->mDefineState < BfTypeDefineState_Declaring) + { + typeInstance->mDefineState = BfTypeDefineState_Declaring; + + if (typeInstance->IsGenericTypeInstance()) + { + DoPopulateType_SetGenericDependencies(typeInstance); + } + + auto _AddStaticSearch = [&](BfTypeDef* typeDef) + { + if (!typeDef->mStaticSearch.IsEmpty()) + { + BfStaticSearch* staticSearch; + if (typeInstance->mStaticSearchMap.TryAdd(typeDef, NULL, &staticSearch)) + { + SetAndRestoreValue prevTypeDef(mContext->mCurTypeState->mCurTypeDef, typeDef); + for (auto typeRef : typeDef->mStaticSearch) + { + auto staticType = ResolveTypeRef(typeRef, NULL, BfPopulateType_Identity); + if (staticType != NULL) + { + auto staticTypeInst = staticType->ToTypeInstance(); + if (staticTypeInst == NULL) + { + Fail(StrFormat("Type '%s' cannot be used in a 'using static' declaration", TypeToString(staticType).c_str()), typeRef); + } + else + { + staticSearch->mStaticTypes.Add(staticTypeInst); + AddDependency(staticTypeInst, typeInstance, BfDependencyMap::DependencyFlag_StaticValue); + } + } + } + } + } + if (!typeDef->mInternalAccessSet.IsEmpty()) + { + BfInternalAccessSet* internalAccessSet; + if (typeInstance->mInternalAccessMap.TryAdd(typeDef, NULL, &internalAccessSet)) + { + for (auto typeRef : typeDef->mInternalAccessSet) + { + if ((typeRef->IsA()) || + (typeRef->IsA())) + { + String checkNamespaceStr; + typeRef->ToString(checkNamespaceStr); + BfAtomComposite checkNamespace; + if (mSystem->ParseAtomComposite(checkNamespaceStr, checkNamespace)) + { + if (mSystem->ContainsNamespace(checkNamespace, typeDef->mProject)) + { + mSystem->RefAtomComposite(checkNamespace); + internalAccessSet->mNamespaces.Add(checkNamespace); + continue; + } + } + } + + BfType* internalType = NULL; + if (auto genericTypeRef = BfNodeDynCast(typeRef)) + internalType = mContext->mScratchModule->ResolveTypeRefAllowUnboundGenerics(typeRef, BfPopulateType_Identity); + else + internalType = ResolveTypeRef(typeRef, NULL, BfPopulateType_Identity); + if (internalType != NULL) + { + auto internalTypeInst = internalType->ToTypeInstance(); + if (internalTypeInst == NULL) + { + Fail(StrFormat("Type '%s' cannot be used in a 'using internal' declaration", TypeToString(internalType).c_str()), typeRef); + } + else + { + internalAccessSet->mTypes.Add(internalTypeInst); + AddDependency(internalTypeInst, typeInstance, BfDependencyMap::DependencyFlag_StaticValue); + } + } + } + } + } + }; + + if (typeDef->mIsCombinedPartial) + { + for (auto partialTypeDef : typeDef->mPartials) + _AddStaticSearch(partialTypeDef); + } + else + _AddStaticSearch(typeDef); + } + bool underlyingTypeDeferred = false; BfType* underlyingType = NULL; if (typeInstance->mBaseType != NULL) @@ -2734,7 +2826,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy else { AssertErrorState(); - typeInstance->mTypeFailed = true; + TypeFailed(typeInstance); } } @@ -2782,7 +2874,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy else { AssertErrorState(); - typeInstance->mTypeFailed = true; + TypeFailed(typeInstance); } if (_CheckTypeDone()) @@ -2824,97 +2916,10 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } // Partial population break out point - if (typeInstance->mDefineState < BfTypeDefineState_Declared) - { + + if (typeInstance->mDefineState < BfTypeDefineState_Declared) typeInstance->mDefineState = BfTypeDefineState_Declared; - - if (typeInstance->IsGenericTypeInstance()) - { - DoPopulateType_SetGenericDependencies(typeInstance); - } - - auto _AddStaticSearch = [&](BfTypeDef* typeDef) - { - if (!typeDef->mStaticSearch.IsEmpty()) - { - BfStaticSearch* staticSearch; - if (typeInstance->mStaticSearchMap.TryAdd(typeDef, NULL, &staticSearch)) - { - SetAndRestoreValue prevTypeDef(mContext->mCurTypeState->mCurTypeDef, typeDef); - for (auto typeRef : typeDef->mStaticSearch) - { - auto staticType = ResolveTypeRef(typeRef, NULL, BfPopulateType_Identity); - if (staticType != NULL) - { - auto staticTypeInst = staticType->ToTypeInstance(); - if (staticTypeInst == NULL) - { - Fail(StrFormat("Type '%s' cannot be used in a 'using static' declaration", TypeToString(staticType).c_str()), typeRef); - } - else - { - staticSearch->mStaticTypes.Add(staticTypeInst); - AddDependency(staticTypeInst, typeInstance, BfDependencyMap::DependencyFlag_StaticValue); - } - } - } - } - } - if (!typeDef->mInternalAccessSet.IsEmpty()) - { - BfInternalAccessSet* internalAccessSet; - if (typeInstance->mInternalAccessMap.TryAdd(typeDef, NULL, &internalAccessSet)) - { - for (auto typeRef : typeDef->mInternalAccessSet) - { - if ((typeRef->IsA()) || - (typeRef->IsA())) - { - String checkNamespaceStr; - typeRef->ToString(checkNamespaceStr); - BfAtomComposite checkNamespace; - if (mSystem->ParseAtomComposite(checkNamespaceStr, checkNamespace)) - { - if (mSystem->ContainsNamespace(checkNamespace, typeDef->mProject)) - { - mSystem->RefAtomComposite(checkNamespace); - internalAccessSet->mNamespaces.Add(checkNamespace); - continue; - } - } - } - - BfType* internalType = NULL; - if (auto genericTypeRef = BfNodeDynCast(typeRef)) - internalType = mContext->mScratchModule->ResolveTypeRefAllowUnboundGenerics(typeRef, BfPopulateType_Identity); - else - internalType = ResolveTypeRef(typeRef, NULL, BfPopulateType_Identity); - if (internalType != NULL) - { - auto internalTypeInst = internalType->ToTypeInstance(); - if (internalTypeInst == NULL) - { - Fail(StrFormat("Type '%s' cannot be used in a 'using internal' declaration", TypeToString(internalType).c_str()), typeRef); - } - else - { - internalAccessSet->mTypes.Add(internalTypeInst); - AddDependency(internalTypeInst, typeInstance, BfDependencyMap::DependencyFlag_StaticValue); - } - } - } - } - } - }; - - if (typeDef->mIsCombinedPartial) - { - for (auto partialTypeDef : typeDef->mPartials) - _AddStaticSearch(partialTypeDef); - } - else - _AddStaticSearch(typeDef); - } + if (populateType == BfPopulateType_Declaration) { return; diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.h b/IDEHelper/Compiler/BfResolvedTypeUtils.h index c83f85f0..467cdb47 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.h +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.h @@ -430,6 +430,7 @@ class BfTypeDIReplaceCallback; enum BfTypeDefineState : uint8 { BfTypeDefineState_Undefined, + BfTypeDefineState_Declaring, BfTypeDefineState_Declared, BfTypeDefineState_ResolvingBaseType, BfTypeDefineState_HasInterfaces,