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();
BfStaticSearch* staticSearch;
if ((mModule->mCurTypeInstance != NULL) && (mModule->mCurTypeInstance->mStaticSearchMap.TryGetValue(activeTypeDef, &staticSearch)))
for (auto typeInst : staticSearch->mStaticTypes)
{
for (auto typeInst : staticSearch->mStaticTypes)
{
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);
}
}
}
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;
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 typeName = tempTypeDef->mFullName;

View file

@ -1686,6 +1686,8 @@ NoMatch:
{
if (genericArgumentsSubstitute != NULL)
{
for (auto& genericArg : *genericArgumentsSubstitute)
genericArg = mModule->FixIntUnknown(genericArg);
mBestMethodGenericArguments = *genericArgumentsSubstitute;
// #ifdef _DEBUG
// for (auto arg : mBestMethodGenericArguments)
@ -3273,8 +3275,18 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
if ((result) || (mPropDef != NULL))
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;
}
}
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)

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);
BfModuleOptions BfModule::GetModuleOptions()

View file

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

View file

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

View file

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