From b048cafcfd6dd8b4f3c1856b57b7324a7468104e Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Fri, 14 Jan 2022 07:30:26 -0500 Subject: [PATCH] Fixed internal access in type aliases --- IDEHelper/Compiler/BfModule.h | 3 +- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 189 ++++++++++++----------- 2 files changed, 103 insertions(+), 89 deletions(-) diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index f55304a7..6f296daf 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -1761,9 +1761,10 @@ public: void DoCEEmit(BfTypeInstance* typeInstance, bool& hadNewMembers, bool underlyingTypeDeferred); void DoCEEmit(BfMethodInstance* methodInstance); void DoPopulateType_TypeAlias(BfTypeInstance* typeAlias); + void DoPopulateType_InitSearches(BfTypeInstance* typeInstance); void DoPopulateType_SetGenericDependencies(BfTypeInstance* genericTypeInstance); void DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType); - void DoPopulateType_CeCheckEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred); + void DoPopulateType_CeCheckEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred); void DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateType = BfPopulateType_Data); static BfModule* GetModuleFor(BfType* type); void DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance); diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 2c2a5f2b..fe316aba 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -2589,6 +2589,13 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeInstance* typeAlias) SetAndRestoreValue prevTypeInstance(mCurTypeInstance, typeAlias); SetAndRestoreValue prevMethodInstance(mCurMethodInstance, NULL); SetAndRestoreValue prevMethodState(mCurMethodState, NULL); + + if (typeAlias->mDefineState < BfTypeDefineState_Declaring) + { + typeAlias->mDefineState = BfTypeDefineState_Declaring; + DoPopulateType_InitSearches(typeAlias); + } + BF_ASSERT(mCurMethodInstance == NULL); auto typeDef = typeAlias->mTypeDef; auto typeAliasDecl = (BfTypeAliasDeclaration*)typeDef->mTypeDeclaration; @@ -2666,6 +2673,99 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeInstance* typeAlias) } } +void BfModule::DoPopulateType_InitSearches(BfTypeInstance* typeInstance) +{ + auto typeDef = typeInstance->mTypeDef; + + 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; + BF_ASSERT(!typeDef->IsEmitted()); + 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); +} + void BfModule::DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType) { if (typeInstance->IsEnum()) @@ -2966,94 +3066,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy 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; - BF_ASSERT(!typeDef->IsEmitted()); - 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); + DoPopulateType_InitSearches(typeInstance); } bool underlyingTypeDeferred = false;