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

Improved static indexer support

This commit is contained in:
Brian Fiete 2020-12-05 04:29:27 -08:00
parent 5096e65fc7
commit b5064536e0
4 changed files with 27 additions and 12 deletions

View file

@ -3768,7 +3768,8 @@ void BfExprEvaluator::Visit(BfIdentifierNode* identifierNode)
} }
} }
mModule->Fail("Identifier not found", identifierNode); if ((mBfEvalExprFlags & BfEvalExprFlags_NoLookupError) == 0)
mModule->Fail("Identifier not found", identifierNode);
} }
} }
@ -4173,7 +4174,7 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
return retVal; return retVal;
} }
else if (!target) else if (!target)
{ {
if ((flags & BfLookupFieldFlag_CheckingOuter) != 0) if ((flags & BfLookupFieldFlag_CheckingOuter) != 0)
mModule->Fail(StrFormat("An instance reference is required to reference non-static outer field '%s.%s'", mModule->TypeToString(curCheckType).c_str(), field->mName.c_str()), mModule->Fail(StrFormat("An instance reference is required to reference non-static outer field '%s.%s'", mModule->TypeToString(curCheckType).c_str(), field->mName.c_str()),
targetSrc); targetSrc);
@ -8722,7 +8723,8 @@ void BfExprEvaluator::LookupQualifiedStaticField(BfQualifiedNameNode* nameNode,
} }
} }
mModule->Fail("Field not found", nameNode->mRight); if ((mBfEvalExprFlags & BfEvalExprFlags_NoLookupError) == 0)
mModule->Fail("Field not found", nameNode->mRight);
return; return;
} }
} }
@ -8825,7 +8827,8 @@ void BfExprEvaluator::LookupQualifiedStaticField(BfAstNode* nameNode, BfIdentifi
} }
} }
mModule->Fail("Field not found", nameRight); if ((mBfEvalExprFlags & BfEvalExprFlags_NoLookupError) == 0)
mModule->Fail("Field not found", nameRight);
return; return;
} }
} }
@ -17885,8 +17888,14 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
// Try first as a non-static indexer, then as a static indexer // Try first as a non-static indexer, then as a static indexer
for (int pass = 0; pass < 2; pass++) for (int pass = 0; pass < 2; pass++)
{ {
SetAndRestoreValue<bool> ignoreErrors(mModule->mIgnoreErrors, (mModule->mIgnoreErrors) || (pass == 0)); // SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, (mModule->mIgnoreErrors) || (pass == 0));
VisitChild(indexerExpr->mTarget); // SetAndRestoreValue<bool> prevHadIgnoredError(mModule->mHadIgnoredError, false);
{
SetAndRestoreValue<BfEvalExprFlags> prevFlags(mBfEvalExprFlags, (BfEvalExprFlags)(mBfEvalExprFlags | BfEvalExprFlags_NoLookupError));
VisitChild(indexerExpr->mTarget);
}
ResolveGenericType(); ResolveGenericType();
target = GetResult(true); target = GetResult(true);
if (target) if (target)
@ -17894,6 +17903,7 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
if (pass == 0) if (pass == 0)
{ {
SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, (mModule->mIgnoreErrors) || (pass == 0));
auto staticType = mModule->ResolveTypeRef(indexerExpr->mTarget, {}); auto staticType = mModule->ResolveTypeRef(indexerExpr->mTarget, {});
if (staticType != NULL) if (staticType != NULL)
{ {

View file

@ -833,6 +833,7 @@ BfModule::BfModule(BfContext* context, const StringImpl& moduleName)
mHadBuildError = false; mHadBuildError = false;
mHadBuildWarning = false; mHadBuildWarning = false;
mIgnoreErrors = false; mIgnoreErrors = false;
mHadIgnoredError = false;
mIgnoreWarnings = false; mIgnoreWarnings = false;
mReportErrors = true; mReportErrors = true;
mIsInsideAutoComplete = false; mIsInsideAutoComplete = false;
@ -2672,7 +2673,8 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers
BP_ZONE("BfModule::Fail"); BP_ZONE("BfModule::Fail");
if (mIgnoreErrors) if (mIgnoreErrors)
{ {
mHadIgnoredError = true;
if (mAttributeState != NULL) if (mAttributeState != NULL)
mAttributeState->mFlags = (BfAttributeState::Flags)(mAttributeState->mFlags | BfAttributeState::Flag_HadError); mAttributeState->mFlags = (BfAttributeState::Flags)(mAttributeState->mFlags | BfAttributeState::Flag_HadError);
return NULL; return NULL;

View file

@ -67,7 +67,8 @@ enum BfEvalExprFlags
BfEvalExprFlags_VariableDeclaration = 0x4000, BfEvalExprFlags_VariableDeclaration = 0x4000,
BfEvalExprFlags_NoAutoComplete = 0x8000, BfEvalExprFlags_NoAutoComplete = 0x8000,
BfEvalExprFlags_AllowNonConst = 0x10000, BfEvalExprFlags_AllowNonConst = 0x10000,
BfEvalExprFlags_StringInterpolateFormat = 0x20000 BfEvalExprFlags_StringInterpolateFormat = 0x20000,
BfEvalExprFlags_NoLookupError = 0x40000,
}; };
enum BfCastFlags enum BfCastFlags
@ -994,6 +995,7 @@ public:
bool mAllowUinitReads; bool mAllowUinitReads;
bool mCancelledDeferredCall; bool mCancelledDeferredCall;
bool mNoObjectAccessChecks; bool mNoObjectAccessChecks;
bool mHadIgnoredError;
int mCurLocalVarId; // Can also refer to a label int mCurLocalVarId; // Can also refer to a label
int mCurAccessId; // For checking to see if a block reads from or writes to a local int mCurAccessId; // For checking to see if a block reads from or writes to a local
@ -1031,7 +1033,7 @@ public:
mAllowUinitReads = false; mAllowUinitReads = false;
mCancelledDeferredCall = false; mCancelledDeferredCall = false;
mNoObjectAccessChecks = false; mNoObjectAccessChecks = false;
mInDeferredBlock = false; mInDeferredBlock = false;
mDeferredLocalAssignData = NULL; mDeferredLocalAssignData = NULL;
mCurLocalVarId = 0; mCurLocalVarId = 0;
mCurAccessId = 1; mCurAccessId = 1;
@ -1445,7 +1447,8 @@ public:
bool mWroteToLib; bool mWroteToLib;
bool mHadBuildError; bool mHadBuildError;
bool mHadBuildWarning; bool mHadBuildWarning;
bool mIgnoreErrors; bool mIgnoreErrors;
bool mHadIgnoredError;
bool mIgnoreWarnings; bool mIgnoreWarnings;
bool mSetIllegalSrcPosition; bool mSetIllegalSrcPosition;
bool mReportErrors; // Still puts system in error state when set to false bool mReportErrors; // Still puts system in error state when set to false

View file

@ -9566,8 +9566,8 @@ BfType* BfModule::ResolveInnerType(BfType* outerType, BfIdentifierNode* identifi
{ {
BfDirectStrTypeReference typeRef; BfDirectStrTypeReference typeRef;
typeRef.Init(identifier->ToString()); typeRef.Init(identifier->ToString());
// There is no ref node so we ignore errors
auto type = ResolveInnerType(outerType, &typeRef, populateType, ignoreErrors); auto type = ResolveInnerType(outerType, &typeRef, populateType, /*ignoreErrors*/true);
return type; return type;
} }