diff --git a/IDEHelper/Compiler/BfReducer.cpp b/IDEHelper/Compiler/BfReducer.cpp index 990baa47..2de66d6b 100644 --- a/IDEHelper/Compiler/BfReducer.cpp +++ b/IDEHelper/Compiler/BfReducer.cpp @@ -238,7 +238,7 @@ void BfReducer::AddErrorNode(BfAstNode* astNode, bool removeNode) mSource->AddErrorNode(astNode); if (removeNode) astNode->RemoveSelf(); - mLastErrorSrcEnd = astNode->mSrcEnd; + mLastErrorSrcEnd = BF_MAX(mLastErrorSrcEnd, astNode->mSrcEnd); } bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int endNode, int* retryNode, int* outEndNode, bool* couldBeExpr, bool* isGenericType, bool* isTuple) @@ -5837,13 +5837,20 @@ BfTypeReference* BfReducer::CreateTypeRefAfter(BfAstNode* astNode, CreateTypeRef { if (mLastErrorSrcEnd > startPos) { - // We added an error node and made progress + // We added an error node and made progress + for (int checkIdx = mVisitorPos.mReadPos - 1; checkIdx >= startPos - 1; checkIdx--) + { + auto checkNode = mVisitorPos.Get(checkIdx); + if (checkNode->mSrcEnd <= mLastErrorSrcEnd) + break; + mVisitorPos.mReadPos = checkIdx; + } } else { BF_ASSERT(mVisitorPos.mReadPos == startPos); - } - mVisitorPos.mReadPos--; + mVisitorPos.mReadPos = startPos - 1; + } } return typeRef; } @@ -6055,9 +6062,19 @@ BfAttributeDirective* BfReducer::CreateAttributeDirective(BfTokenNode* startToke if (!isHandled) { + int prevReadPos = mVisitorPos.mReadPos; auto typeRef = CreateTypeRefAfter(attributeDirective); if (typeRef == NULL) { + if (mVisitorPos.mReadPos != prevReadPos) + { + AddErrorNode(attributeDirective); + auto curNode = mVisitorPos.GetCurrent(); + if ((mSource != NULL) && (!mSource->HasPendingError(curNode))) + mSource->AddErrorNode(curNode); + return NULL; + } + auto nextNode = mVisitorPos.GetNext(); if (BfTokenNode* endToken = BfNodeDynCast(nextNode)) { @@ -6067,7 +6084,7 @@ BfAttributeDirective* BfReducer::CreateAttributeDirective(BfTokenNode* startToke MEMBER_SET(attributeDirective, mCtorCloseParen, endToken); return attributeDirective; } - } + } return attributeDirective; } @@ -11118,7 +11135,7 @@ void BfReducer::HandleBlock(BfBlock* block, bool allowEndingExpression) flags = (CreateStmtFlags)(flags | CreateStmtFlags_AllowUnterminatedExpression); auto statement = CreateStatement(node, flags); - if ((statement == NULL) && (mSource != NULL)) + if ((statement == NULL) && (mSource != NULL) && (!mSource->HasPendingError(node))) statement = mSource->CreateErrorNode(node); isDone = !mVisitorPos.MoveNext(); diff --git a/IDEHelper/Compiler/BfSource.cpp b/IDEHelper/Compiler/BfSource.cpp index ce731961..44803b3f 100644 --- a/IDEHelper/Compiler/BfSource.cpp +++ b/IDEHelper/Compiler/BfSource.cpp @@ -64,6 +64,17 @@ BfErrorNode* BfSource::CreateErrorNode(BfAstNode* astNode) return errorNode; } +bool BfSource::HasPendingError(BfAstNode* astNode) +{ + for (auto errorNode : mPendingErrorNodes) + { + if ((astNode->mSrcStart >= errorNode->mSrcStart) && (astNode->mSrcEnd <= errorNode->mSrcEnd)) + return true; + } + + return false; +} + void BfSource::AddErrorNode(BfAstNode* astNode) { mPendingErrorNodes.push_back(CreateErrorNode(astNode)); diff --git a/IDEHelper/Compiler/BfSource.h b/IDEHelper/Compiler/BfSource.h index 9f1d221b..623ec7d1 100644 --- a/IDEHelper/Compiler/BfSource.h +++ b/IDEHelper/Compiler/BfSource.h @@ -104,6 +104,7 @@ public: virtual void HadSrcRealloc() {} BfErrorNode* CreateErrorNode(BfAstNode* astNode); + bool HasPendingError(BfAstNode* astNode); void AddErrorNode(BfAstNode* astNode); int AllocChars(int charCount); void FinishSideNodes();