1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +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

@ -1233,40 +1233,17 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress
AddTypeMembers(globalContainer.mTypeInst, true, false, filter, globalContainer.mTypeInst, true, true);
}
}
//////////////////////////////////////////////////////////////////////////
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);
}
}
//////////////////////////////////////////////////////////////////////////
BfMethodInstance* curMethodInstance = mModule->mCurMethodInstance;

View file

@ -3692,7 +3692,7 @@ void BfCompiler::ProcessAutocompleteTempType()
mContext->HandleChangedTypeDef(tempTypeDef, true);
}
}
if (tempTypeDef == NULL)
{
GenerateAutocompleteInfo();
@ -3705,13 +3705,28 @@ void BfCompiler::ProcessAutocompleteTempType()
BfLogSysM("ProcessAutocompleteTempType - project disabled\n");
return;
}
SetAndRestoreValue<BfMethodState*> prevMethodState(module->mCurMethodState, NULL);
BfTypeState typeState;
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

@ -1680,12 +1680,14 @@ NoMatch:
}
if (hadMatch)
{
{
mBestMethodTypeInstance = typeInstance;
if (genericArgumentsSubstitute != &mBestMethodGenericArguments)
{
if (genericArgumentsSubstitute != NULL)
{
for (auto& genericArg : *genericArgumentsSubstitute)
genericArg = mModule->FixIntUnknown(genericArg);
mBestMethodGenericArguments = *genericArgumentsSubstitute;
// #ifdef _DEBUG
// for (auto arg : mBestMethodGenericArguments)
@ -3272,9 +3274,19 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
result = LookupField(identifierNode, thisValue, findName);
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,9 +1770,10 @@ 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;