1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fixed 'using static'

This commit is contained in:
Brian Fiete 2020-06-02 05:46:56 -07:00
parent 41629b49d1
commit c1a2bd79e1
7 changed files with 74 additions and 36 deletions

View file

@ -1234,36 +1234,13 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress
} }
} }
////////////////////////////////////////////////////////////////////////// BfStaticSearch* staticSearch = mModule->GetStaticSearch();
if (staticSearch != NULL)
{ {
auto activeTypeDef = mModule->GetActiveTypeDef(); for (auto typeInst : staticSearch->mStaticTypes)
BfStaticSearch* staticSearch;
if ((mModule->mCurTypeInstance != NULL) && (mModule->mCurTypeInstance->mStaticSearchMap.TryGetValue(activeTypeDef, &staticSearch)))
{ {
for (auto typeInst : staticSearch->mStaticTypes) AddTypeMembers(typeInst, true, false, filter, typeInst, true, true);
{ AddInnerTypes(typeInst, filter, false, false);
AddTypeMembers(typeInst, true, false, filter, typeInst, true, true);
AddInnerTypes(typeInst, filter, false, false);
}
}
else if ((activeTypeDef != NULL) && (!activeTypeDef->mStaticSearch.IsEmpty()))
{
BF_ASSERT(mModule->mCompiler->IsAutocomplete());
for (auto typeRef : activeTypeDef->mStaticSearch)
{
auto type = mModule->ResolveTypeRef(typeRef, NULL, BfPopulateType_Declaration);
if (type != NULL)
{
auto typeInst = type->ToTypeInstance();
if (typeInst != NULL)
{
AddTypeMembers(typeInst, true, false, filter, typeInst, true, true);
AddInnerTypes(typeInst, filter, false, false);
}
}
}
} }
} }

View file

@ -3712,6 +3712,21 @@ void BfCompiler::ProcessAutocompleteTempType()
typeState.mCurTypeDef = tempTypeDef; typeState.mCurTypeDef = tempTypeDef;
SetAndRestoreValue<BfTypeState*> prevTypeState(module->mContext->mCurTypeState, &typeState); SetAndRestoreValue<BfTypeState*> prevTypeState(module->mContext->mCurTypeState, &typeState);
BfStaticSearch* staticSearch = NULL;
if (mResolvePassData->mStaticSearchMap.TryAdd(tempTypeDef, NULL, &staticSearch))
{
for (auto typeRef : tempTypeDef->mStaticSearch)
{
auto type = module->ResolveTypeRef(typeRef, NULL, BfPopulateType_Declaration);
if (type != NULL)
{
auto typeInst = type->ToTypeInstance();
if (typeInst != NULL)
staticSearch->mStaticTypes.Add(typeInst);
}
}
}
auto _FindAcutalTypeDef = [&](BfTypeDef* tempTypeDef) auto _FindAcutalTypeDef = [&](BfTypeDef* tempTypeDef)
{ {
auto typeName = tempTypeDef->mFullName; auto typeName = tempTypeDef->mFullName;

View file

@ -1686,6 +1686,8 @@ NoMatch:
{ {
if (genericArgumentsSubstitute != NULL) if (genericArgumentsSubstitute != NULL)
{ {
for (auto& genericArg : *genericArgumentsSubstitute)
genericArg = mModule->FixIntUnknown(genericArg);
mBestMethodGenericArguments = *genericArgumentsSubstitute; mBestMethodGenericArguments = *genericArgumentsSubstitute;
// #ifdef _DEBUG // #ifdef _DEBUG
// for (auto arg : mBestMethodGenericArguments) // for (auto arg : mBestMethodGenericArguments)
@ -3273,8 +3275,18 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
if ((result) || (mPropDef != NULL)) if ((result) || (mPropDef != NULL))
return result; return result;
} }
}
//TODO: Try static search auto staticSearch = mModule->GetStaticSearch();
if (staticSearch != NULL)
{
for (auto typeInst : staticSearch->mStaticTypes)
{
thisValue = BfTypedValue(typeInst);
result = LookupField(identifierNode, thisValue, findName);
if ((result) || (mPropDef != NULL))
return result;
}
} }
} }
@ -7062,6 +7074,25 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
break; break;
} }
} }
if (methodDef == NULL)
{
BfStaticSearch* staticSearch = mModule->GetStaticSearch();
if (staticSearch != NULL)
{
for (auto typeInst : staticSearch->mStaticTypes)
{
methodMatcher.CheckType(typeInst, BfTypedValue(), false);
if (methodMatcher.mBestMethodDef != NULL)
{
isFailurePass = false;
curTypeInst = methodMatcher.mBestMethodTypeInstance;
methodDef = methodMatcher.mBestMethodDef;
break;
}
}
}
}
} }
if (methodDef == NULL) if (methodDef == NULL)

View file

@ -3205,6 +3205,17 @@ void BfModule::PopulateGlobalContainersList(const BfGlobalLookup& globalLookup)
} }
} }
BfStaticSearch* BfModule::GetStaticSearch()
{
auto activeTypeDef = GetActiveTypeDef();
BfStaticSearch* staticSearch = NULL;
if ((mCurTypeInstance != NULL) && (mCurTypeInstance->mStaticSearchMap.TryGetValue(activeTypeDef, &staticSearch)))
return staticSearch;
if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mStaticSearchMap.TryGetValue(activeTypeDef, &staticSearch)))
return staticSearch;
return NULL;
}
void PrintUsers(llvm::MDNode* md); void PrintUsers(llvm::MDNode* md);
BfModuleOptions BfModule::GetModuleOptions() BfModuleOptions BfModule::GetModuleOptions()

View file

@ -1609,6 +1609,7 @@ public:
void TypeFailed(BfTypeInstance* typeInstance); void TypeFailed(BfTypeInstance* typeInstance);
bool IsAttribute(BfTypeInstance* typeInst); bool IsAttribute(BfTypeInstance* typeInst);
void PopulateGlobalContainersList(const BfGlobalLookup& globalLookup); void PopulateGlobalContainersList(const BfGlobalLookup& globalLookup);
BfStaticSearch* GetStaticSearch();
void AddFailType(BfTypeInstance* typeInstance); void AddFailType(BfTypeInstance* typeInstance);
void MarkDerivedDirty(BfTypeInstance* typeInst); void MarkDerivedDirty(BfTypeInstance* typeInst);
void CheckAddFailType(); void CheckAddFailType();

View file

@ -1770,6 +1770,7 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
} }
else else
{ {
staticSearch->mStaticTypes.Add(staticTypeInst);
AddDependency(staticTypeInst, typeInstance, BfDependencyMap::DependencyFlag_StaticValue); AddDependency(staticTypeInst, typeInstance, BfDependencyMap::DependencyFlag_StaticValue);
} }
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "BfSystem.h" #include "BfSystem.h"
#include "BfResolvedTypeUtils.h"
NS_BF_BEGIN NS_BF_BEGIN
@ -46,6 +47,7 @@ public:
BfParser* mParser; BfParser* mParser;
BfAutoComplete* mAutoComplete; BfAutoComplete* mAutoComplete;
Array<BfTypeDef*> mAutoCompleteTempTypes; // Contains multiple values when we have nested types Array<BfTypeDef*> mAutoCompleteTempTypes; // Contains multiple values when we have nested types
Dictionary<BfTypeDef*, BfStaticSearch> mStaticSearchMap;
BfSourceClassifier* mSourceClassifier; BfSourceClassifier* mSourceClassifier;
Array<BfAstNode*> mExteriorAutocompleteCheckNodes; Array<BfAstNode*> mExteriorAutocompleteCheckNodes;