1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Document formatted

This commit is contained in:
Brian Fiete 2020-03-25 11:57:51 -07:00
parent 19e53801f1
commit 118f819cc3

View file

@ -93,7 +93,7 @@ void BfReducer::AssertCurrentNode(BfAstNode* node)
} }
} }
gAssertCurrentNodeIdx++; gAssertCurrentNodeIdx++;
mAssertCurrentNodeIdx++; mAssertCurrentNodeIdx++;
} }
// For autocomplete we only do a reduce on nodes the cursor is in // For autocomplete we only do a reduce on nodes the cursor is in
@ -116,7 +116,7 @@ bool BfReducer::IsNodeRelevant(BfAstNode* startNode, BfAstNode* endNode)
return true; return true;
int cursorPos = bfParser->mCursorIdx; int cursorPos = bfParser->mCursorIdx;
int lenAdd = 1; int lenAdd = 1;
if ((cursorPos == -1) || if ((cursorPos == -1) ||
((cursorPos >= startNode->GetSrcStart()) && (cursorPos < endNode->GetSrcEnd() + lenAdd))) ((cursorPos >= startNode->GetSrcStart()) && (cursorPos < endNode->GetSrcEnd() + lenAdd)))
return true; return true;
BF_ASSERT(bfParser->mParserData->mRefCount == -1); BF_ASSERT(bfParser->mParserData->mRefCount == -1);
@ -199,8 +199,8 @@ BfAstNode* BfReducer::Fail(const StringImpl& errorMsg, BfAstNode* refNode)
if (mPassInstance->HasLastFailedAt(refNode)) // No duplicate failures if (mPassInstance->HasLastFailedAt(refNode)) // No duplicate failures
return NULL; return NULL;
auto error = mPassInstance->Fail(errorMsg, refNode); auto error = mPassInstance->Fail(errorMsg, refNode);
if ((error != NULL) && (mSource != NULL)) if ((error != NULL) && (mSource != NULL))
error->mProject = mSource->mProject; error->mProject = mSource->mProject;
return NULL; return NULL;
} }
@ -214,7 +214,7 @@ BfAstNode* BfReducer::FailAfter(const StringImpl& errorMsg, BfAstNode* prevNode)
} }
void BfReducer::AddErrorNode(BfAstNode* astNode, bool removeNode) void BfReducer::AddErrorNode(BfAstNode* astNode, bool removeNode)
{ {
if (mSource != NULL) if (mSource != NULL)
mSource->AddErrorNode(astNode); mSource->AddErrorNode(astNode);
if (removeNode) if (removeNode)
@ -250,7 +250,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int*
checkIdx++; checkIdx++;
checkNode = mVisitorPos.Get(checkIdx); checkNode = mVisitorPos.Get(checkIdx);
checkTokenNode = BfNodeDynCast<BfTokenNode>(checkNode); checkTokenNode = BfNodeDynCast<BfTokenNode>(checkNode);
if (outEndNode) if (outEndNode)
*outEndNode = checkIdx; *outEndNode = checkIdx;
@ -390,9 +390,9 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int*
BfToken checkToken = checkTokenNode->GetToken(); BfToken checkToken = checkTokenNode->GetToken();
if (bracketDepth > 0) if (bracketDepth > 0)
{ {
if ((checkToken == BfToken_LBracket) || (checkToken == BfToken_QuestionLBracket)) if ((checkToken == BfToken_LBracket) || (checkToken == BfToken_QuestionLBracket))
{ {
bracketDepth++; bracketDepth++;
} }
else if (checkToken == BfToken_RBracket) else if (checkToken == BfToken_RBracket)
@ -558,7 +558,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int*
tokenStack.Add(BfToken_LChevron); tokenStack.Add(BfToken_LChevron);
} }
else if ((checkToken == BfToken_RChevron) || (checkToken == BfToken_RDblChevron)) else if ((checkToken == BfToken_RChevron) || (checkToken == BfToken_RDblChevron))
{ {
for (int i = 0; i < ((checkToken == BfToken_RDblChevron) ? 2 : 1); i++) for (int i = 0; i < ((checkToken == BfToken_RDblChevron) ? 2 : 1); i++)
{ {
if ((tokenStack.IsEmpty()) || (tokenStack.back() != BfToken_LChevron)) if ((tokenStack.IsEmpty()) || (tokenStack.back() != BfToken_LChevron))
@ -570,8 +570,8 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int*
tokenStack.pop_back(); tokenStack.pop_back();
chevronDepth--; chevronDepth--;
} }
identifierExpected = false; identifierExpected = false;
if (chevronDepth < 0) if (chevronDepth < 0)
{ {
if (outEndNode != NULL) if (outEndNode != NULL)
@ -588,12 +588,12 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int*
else if (checkToken == BfToken_RDblChevron) else if (checkToken == BfToken_RDblChevron)
chevronDepth -= 2; chevronDepth -= 2;
else if (checkToken == BfToken_Comma) else if (checkToken == BfToken_Comma)
{ {
if ((bracketDepth == 0) && (tokenStack.IsEmpty())) if ((bracketDepth == 0) && (tokenStack.IsEmpty()))
{ {
if (outEndNode != NULL) if (outEndNode != NULL)
*outEndNode = checkIdx; *outEndNode = checkIdx;
return false; return false;
} }
if ((!tokenStack.IsEmpty()) && (tokenStack.back() == BfToken_LParen)) if ((!tokenStack.IsEmpty()) && (tokenStack.back() == BfToken_LParen))
@ -924,7 +924,7 @@ bool BfReducer::IsLocalMethod(BfAstNode* nameNode)
} }
else else
{ {
} }
checkIdx++; checkIdx++;
@ -977,7 +977,7 @@ int BfReducer::QualifiedBacktrack(BfAstNode* endNode, int checkIdx, bool* outHad
(checkToken != BfToken_Star) && (checkToken != BfToken_Star) &&
(checkToken != BfToken_Question) && (checkToken != BfToken_Question) &&
(checkToken != BfToken_LBracket)) (checkToken != BfToken_LBracket))
{ {
return -1; return -1;
} }
if (chevronDepth == 0) if (chevronDepth == 0)
@ -1013,7 +1013,7 @@ BfExpression* BfReducer::ApplyToFirstExpression(BfUnaryOperatorExpression* unary
//ReplaceNode(unaryOp, binOpExpression); //ReplaceNode(unaryOp, binOpExpression);
unaryOp->mExpression = condExpression->mConditionExpression; unaryOp->mExpression = condExpression->mConditionExpression;
ReplaceNode(unaryOp, condExpression); ReplaceNode(unaryOp, condExpression);
unaryOp->SetSrcEnd(condExpression->mConditionExpression->GetSrcEnd()); unaryOp->SetSrcEnd(condExpression->mConditionExpression->GetSrcEnd());
condExpression->mConditionExpression = unaryOp; condExpression->mConditionExpression = unaryOp;
} }
condExpression->SetSrcStart(unaryOp->GetSrcStart()); condExpression->SetSrcStart(unaryOp->GetSrcStart());
@ -1028,7 +1028,7 @@ BfExpression* BfReducer::ApplyToFirstExpression(BfUnaryOperatorExpression* unary
{ {
unaryOp->mExpression = binOpExpression->mLeft; unaryOp->mExpression = binOpExpression->mLeft;
unaryOp->SetSrcEnd(binOpExpression->mLeft->GetSrcEnd()); unaryOp->SetSrcEnd(binOpExpression->mLeft->GetSrcEnd());
binOpExpression->mLeft = unaryOp; binOpExpression->mLeft = unaryOp;
} }
binOpExpression->SetSrcStart(unaryOp->GetSrcStart()); binOpExpression->SetSrcStart(unaryOp->GetSrcStart());
return result; return result;
@ -1152,7 +1152,7 @@ BfExpression* BfReducer::CheckBinaryOperatorPrecedence(BfBinaryOperatorExpressio
checkBinOpExpression = nextBinaryOperatorExpression; checkBinOpExpression = nextBinaryOperatorExpression;
continue; continue;
} }
/*auto _CheckLeftBinaryOpearator = [&](BfBinaryOperatorExpression* checkBinOpExpression) /*auto _CheckLeftBinaryOpearator = [&](BfBinaryOperatorExpression* checkBinOpExpression)
{ {
while (auto leftBinOpExpression = BfNodeDynCast<BfBinaryOperatorExpression>(checkBinOpExpression->mLeft)) while (auto leftBinOpExpression = BfNodeDynCast<BfBinaryOperatorExpression>(checkBinOpExpression->mLeft))
@ -1243,8 +1243,8 @@ BfExpression* BfReducer::CheckBinaryOperatorPrecedence(BfBinaryOperatorExpressio
auto binOp = checkBinOpExpression->mOp; auto binOp = checkBinOpExpression->mOp;
checkBinOpExpression->mLeft = leftBinOpExpression; checkBinOpExpression->mLeft = leftBinOpExpression;
checkBinOpExpression->mOp = rightBinOpExpression->mOp; checkBinOpExpression->mOp = rightBinOpExpression->mOp;
checkBinOpExpression->mOpToken = rightBinOpExpression->mOpToken; checkBinOpExpression->mOpToken = rightBinOpExpression->mOpToken;
checkBinOpExpression->mRight = exprC; checkBinOpExpression->mRight = exprC;
leftBinOpExpression->mLeft = exprA; leftBinOpExpression->mLeft = exprA;
leftBinOpExpression->mOp = binOp; leftBinOpExpression->mOp = binOp;
@ -1266,11 +1266,11 @@ BfExpression* BfReducer::CheckBinaryOperatorPrecedence(BfBinaryOperatorExpressio
break; break;
} }
if (auto leftBinaryExpr = BfNodeDynCast<BfBinaryOperatorExpression>(checkBinOpExpression->mLeft)) if (auto leftBinaryExpr = BfNodeDynCast<BfBinaryOperatorExpression>(checkBinOpExpression->mLeft))
{ {
deferredChecks.push_back(leftBinaryExpr); deferredChecks.push_back(leftBinaryExpr);
} }
} }
checkBinOpExpression = nextBinaryOperatorExpression; checkBinOpExpression = nextBinaryOperatorExpression;
} }
@ -1577,7 +1577,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
int endNodeIdx = -1; int endNodeIdx = -1;
if ((IsTypeReference(exprLeft, BfToken_LBracket, &endNodeIdx, NULL))) if ((IsTypeReference(exprLeft, BfToken_LBracket, &endNodeIdx, NULL)))
{ {
if (IsTypeReference(exprLeft, BfToken_LBrace, NULL, NULL)) if (IsTypeReference(exprLeft, BfToken_LBrace, NULL, NULL))
{ {
BfSizedArrayCreateExpression* arrayCreateExpr = mAlloc->Alloc<BfSizedArrayCreateExpression>(); BfSizedArrayCreateExpression* arrayCreateExpr = mAlloc->Alloc<BfSizedArrayCreateExpression>();
@ -1753,7 +1753,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
if (ctorDeclP != NULL) if (ctorDeclP != NULL)
ctorDeclP->mHasAppend = true; ctorDeclP->mHasAppend = true;
#endif #endif
#ifdef BF_AST_HAS_PARENT_MEMBER #ifdef BF_AST_HAS_PARENT_MEMBER
BF_ASSERT(ctorDecl == ctorDeclP); BF_ASSERT(ctorDecl == ctorDeclP);
#endif #endif
@ -1832,7 +1832,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
} }
exprLeft = defaultExpr; exprLeft = defaultExpr;
} }
else if (token == BfToken_Question) else if (token == BfToken_Question)
{ {
auto uninitExpr = mAlloc->Alloc<BfUninitializedExpression>(); auto uninitExpr = mAlloc->Alloc<BfUninitializedExpression>();
@ -2098,15 +2098,15 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
} }
} }
// static int sItrIdx = 0; // static int sItrIdx = 0;
// sItrIdx++; // sItrIdx++;
// int itrIdx = sItrIdx; // int itrIdx = sItrIdx;
// if (itrIdx == 197) // if (itrIdx == 197)
// { // {
// NOP; // NOP;
// } // }
// BfParenthesizedExpression or BfTupleExpression // BfParenthesizedExpression or BfTupleExpression
SetAndRestoreValue<bool> prevInParenExpr(mInParenExpr, true); SetAndRestoreValue<bool> prevInParenExpr(mInParenExpr, true);
auto innerExpr = CreateExpressionAfter(tokenNode, CreateExprFlags_AllowVariableDecl); auto innerExpr = CreateExpressionAfter(tokenNode, CreateExprFlags_AllowVariableDecl);
if (innerExpr == NULL) if (innerExpr == NULL)
@ -2176,7 +2176,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
exprLeft = condExpr; exprLeft = condExpr;
ApplyToFirstExpression(unaryOpExpr, condExpr); ApplyToFirstExpression(unaryOpExpr, condExpr);
} }
if (auto assignmentExpr = BfNodeDynCast<BfAssignmentExpression>(unaryOpExpr->mExpression)) if (auto assignmentExpr = BfNodeDynCast<BfAssignmentExpression>(unaryOpExpr->mExpression))
{ {
// Apply unary operator (likely a dereference) to LHS // Apply unary operator (likely a dereference) to LHS
@ -2531,14 +2531,14 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
/*auto typeRef = CreateTypeRef(tokenNode, true); /*auto typeRef = CreateTypeRef(tokenNode, true);
exprLeft = CreateObjectCreateExpression(typeRef); exprLeft = CreateObjectCreateExpression(typeRef);
return exprLeft;*/ return exprLeft;*/
} }
} }
} }
} }
BfBinaryOp binOp = BfTokenToBinaryOp(tokenNode->GetToken()); BfBinaryOp binOp = BfTokenToBinaryOp(tokenNode->GetToken());
if (binOp != BfBinaryOp_None) if (binOp != BfBinaryOp_None)
{ {
auto binOpExpression = mAlloc->Alloc<BfBinaryOperatorExpression>(); auto binOpExpression = mAlloc->Alloc<BfBinaryOperatorExpression>();
ReplaceNode(exprLeft, binOpExpression); ReplaceNode(exprLeft, binOpExpression);
binOpExpression->mLeft = exprLeft; binOpExpression->mLeft = exprLeft;
@ -2607,7 +2607,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
} }
} }
} }
return assignmentExpression; return assignmentExpression;
} }
@ -2715,11 +2715,11 @@ BfForEachStatement* BfReducer::CreateForEachStatement(BfAstNode* node, bool hasT
return forEachStatement; return forEachStatement;
MEMBER_SET_CHECKED(forEachStatement, mVariableTypeRef, typeRef); MEMBER_SET_CHECKED(forEachStatement, mVariableTypeRef, typeRef);
} }
if (auto nextNode = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext())) if (auto nextNode = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext()))
{ {
if ((nextNode->mToken == BfToken_LParen) || (nextNode->mToken == BfToken_LessEquals)) if ((nextNode->mToken == BfToken_LParen) || (nextNode->mToken == BfToken_LessEquals))
{ {
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
auto tupleNode = CreateTupleExpression(nextNode); auto tupleNode = CreateTupleExpression(nextNode);
MEMBER_SET_CHECKED(forEachStatement, mVariableName, tupleNode); MEMBER_SET_CHECKED(forEachStatement, mVariableName, tupleNode);
@ -2753,7 +2753,7 @@ BfStatement* BfReducer::CreateForStatement(BfAstNode* node)
auto parenToken = ExpectTokenAfter(forToken, BfToken_LParen); auto parenToken = ExpectTokenAfter(forToken, BfToken_LParen);
if (parenToken == NULL) if (parenToken == NULL)
return NULL; return NULL;
int outNodeIdx = -1; int outNodeIdx = -1;
auto nextNode = mVisitorPos.GetNext(); auto nextNode = mVisitorPos.GetNext();
if (auto tokenNode = BfNodeDynCast<BfTokenNode>(nextNode)) if (auto tokenNode = BfNodeDynCast<BfTokenNode>(nextNode))
@ -2806,14 +2806,14 @@ BfStatement* BfReducer::CreateForStatement(BfAstNode* node)
isTupleIn = false; isTupleIn = false;
break; break;
} }
} }
if (isTupleIn) if (isTupleIn)
{ {
mVisitorPos.mReadPos = startReadIdx; mVisitorPos.mReadPos = startReadIdx;
return CreateForEachStatement(node, true); return CreateForEachStatement(node, true);
} }
} }
} }
} }
} }
@ -2822,19 +2822,19 @@ BfStatement* BfReducer::CreateForStatement(BfAstNode* node)
if (auto nextToken = BfNodeDynCast<BfTokenNode>(nextNode)) if (auto nextToken = BfNodeDynCast<BfTokenNode>(nextNode))
{ {
if (nextNode->mToken == BfToken_ReadOnly) if (nextNode->mToken == BfToken_ReadOnly)
{ {
mVisitorPos.mReadPos += 2; mVisitorPos.mReadPos += 2;
isTypeRef = IsTypeReference(mVisitorPos.Get(mVisitorPos.mReadPos), BfToken_None, &outNodeIdx); isTypeRef = IsTypeReference(mVisitorPos.Get(mVisitorPos.mReadPos), BfToken_None, &outNodeIdx);
mVisitorPos.mReadPos -= 2; mVisitorPos.mReadPos -= 2;
} }
} }
if (!isTypeRef) if (!isTypeRef)
{ {
mVisitorPos.mReadPos++; mVisitorPos.mReadPos++;
isTypeRef = IsTypeReference(nextNode, BfToken_None, &outNodeIdx); isTypeRef = IsTypeReference(nextNode, BfToken_None, &outNodeIdx);
mVisitorPos.mReadPos--; mVisitorPos.mReadPos--;
} }
BfAstNode* outNode = mVisitorPos.Get(outNodeIdx); BfAstNode* outNode = mVisitorPos.Get(outNodeIdx);
if (isTypeRef) if (isTypeRef)
{ {
@ -2893,7 +2893,7 @@ BfStatement* BfReducer::CreateForStatement(BfAstNode* node)
auto nextNextNode = mVisitorPos.Get(mVisitorPos.mReadPos + 2); auto nextNextNode = mVisitorPos.Get(mVisitorPos.mReadPos + 2);
if (auto tokenNode = BfNodeDynCast<BfTokenNode>(nextNextNode)) if (auto tokenNode = BfNodeDynCast<BfTokenNode>(nextNextNode))
{ {
if ((tokenNode != NULL) && ((tokenNode->GetToken() == BfToken_LChevron) || (tokenNode->GetToken() == BfToken_In))) if ((tokenNode != NULL) && ((tokenNode->GetToken() == BfToken_LChevron) || (tokenNode->GetToken() == BfToken_In)))
{ {
Fail("Ranged for statement must declare new value variable, consider adding a type name, 'var', or 'let'", tokenNode); Fail("Ranged for statement must declare new value variable, consider adding a type name, 'var', or 'let'", tokenNode);
@ -3228,7 +3228,7 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode)
BfToken token = BfToken_None; BfToken token = BfToken_None;
if (tokenNode != NULL) if (tokenNode != NULL)
token = tokenNode->GetToken(); token = tokenNode->GetToken();
if ((tokenNode == NULL) || if ((tokenNode == NULL) ||
((token != BfToken_Case) && (token != BfToken_When) && (token != BfToken_Default))) ((token != BfToken_Case) && (token != BfToken_When) && (token != BfToken_Default)))
{ {
Fail("Expected 'case'", child); Fail("Expected 'case'", child);
@ -3272,7 +3272,7 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode)
whenToken = NULL; whenToken = NULL;
} }
if (whenToken != NULL) if (whenToken != NULL)
{ {
auto whenExpr = mAlloc->Alloc<BfWhenExpression>(); auto whenExpr = mAlloc->Alloc<BfWhenExpression>();
whenExpr->mWhenToken = whenToken; whenExpr->mWhenToken = whenToken;
ReplaceNode(whenToken, whenExpr); ReplaceNode(whenToken, whenExpr);
@ -3409,7 +3409,7 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode)
if (!codeBlock->IsInitialized()) if (!codeBlock->IsInitialized())
{ {
int srcPos = switchCase->GetSrcEnd(); int srcPos = switchCase->GetSrcEnd();
codeBlock->Init(srcPos, srcPos, srcPos); codeBlock->Init(srcPos, srcPos, srcPos);
} }
isDone = !mVisitorPos.MoveNext(); isDone = !mVisitorPos.MoveNext();
@ -3777,8 +3777,8 @@ BfAstNode* BfReducer::DoCreateStatement(BfAstNode* node, CreateStmtFlags createS
return stmt; return stmt;
} }
} }
Fail(StrFormat("Unexpected '%s' specifier", BfTokenToString(tokenNode->GetToken())), tokenNode); Fail(StrFormat("Unexpected '%s' specifier", BfTokenToString(tokenNode->GetToken())), tokenNode);
return stmt; return stmt;
} }
else if (token == BfToken_Volatile) else if (token == BfToken_Volatile)
@ -3801,7 +3801,7 @@ BfAstNode* BfReducer::DoCreateStatement(BfAstNode* node, CreateStmtFlags createS
auto nameNode = ExpectIdentifierAfter(methodDecl); auto nameNode = ExpectIdentifierAfter(methodDecl);
if (nameNode != NULL) if (nameNode != NULL)
{ {
MEMBER_SET(methodDecl, mNameNode, nameNode); MEMBER_SET(methodDecl, mNameNode, nameNode);
ParseMethod(methodDecl, &params, &commas, true); ParseMethod(methodDecl, &params, &commas, true);
} }
@ -4277,8 +4277,8 @@ BfAstNode* BfReducer::CreateStatement(BfAstNode* node, CreateStmtFlags createStm
if (expr != NULL) if (expr != NULL)
{ {
auto nextNode = mVisitorPos.GetNext(); auto nextNode = mVisitorPos.GetNext();
if (nextNode != NULL) if (nextNode != NULL)
FailAfter("Semicolon expected", expr); FailAfter("Semicolon expected", expr);
} }
return expr; return expr;
} }
@ -4309,7 +4309,7 @@ BfAstNode* BfReducer::CreateStatement(BfAstNode* node, CreateStmtFlags createStm
if (auto stmt = BfNodeDynCast<BfStatement>(stmtNode)) if (auto stmt = BfNodeDynCast<BfStatement>(stmtNode))
{ {
if ((stmt->IsMissingSemicolon()) && ((createStmtFlags & CreateStmtFlags_FindTrailingSemicolon) != 0) && (!stmt->IsA<BfEmptyStatement>())) if ((stmt->IsMissingSemicolon()) && ((createStmtFlags & CreateStmtFlags_FindTrailingSemicolon) != 0) && (!stmt->IsA<BfEmptyStatement>()))
{ {
if (!IsSemicolon(nextNode)) if (!IsSemicolon(nextNode))
{ {
// Why did we have this BfIdentifierNode check? It failed to throw an error on just things like "{ a }" // Why did we have this BfIdentifierNode check? It failed to throw an error on just things like "{ a }"
@ -4459,7 +4459,7 @@ BfTypeReference* BfReducer::DoCreateTypeRef(BfAstNode* firstNode, CreateTypeRefF
ReplaceNode(firstNode, dotTypeRef); ReplaceNode(firstNode, dotTypeRef);
dotTypeRef->mDotToken = tokenNode; dotTypeRef->mDotToken = tokenNode;
firstNode = dotTypeRef; firstNode = dotTypeRef;
isHandled = true; isHandled = true;
} }
else if (token == BfToken_DotDotDot) else if (token == BfToken_DotDotDot)
{ {
@ -4605,9 +4605,9 @@ BfTypeReference* BfReducer::DoCreateTypeRef(BfAstNode* firstNode, CreateTypeRefF
auto closeNode = ParseMethodParams(delegateTypeRef, &params, &commas, BfToken_RParen); auto closeNode = ParseMethodParams(delegateTypeRef, &params, &commas, BfToken_RParen);
if (closeNode == NULL) if (closeNode == NULL)
{ {
if (!params.empty()) if (!params.empty())
delegateTypeRef->AdjustSrcEnd(params.back()); delegateTypeRef->AdjustSrcEnd(params.back());
if (!commas.empty()) if (!commas.empty())
delegateTypeRef->AdjustSrcEnd(commas.back()); delegateTypeRef->AdjustSrcEnd(commas.back());
} }
MEMBER_SET_CHECKED(delegateTypeRef, mCloseParen, closeNode); MEMBER_SET_CHECKED(delegateTypeRef, mCloseParen, closeNode);
@ -4730,7 +4730,7 @@ BfTypeReference* BfReducer::DoCreateTypeRef(BfAstNode* firstNode, CreateTypeRefF
{ {
if (nextTokenNode->mToken == BfToken_Star) if (nextTokenNode->mToken == BfToken_Star)
{ {
auto wildcardTypeRef = mAlloc->Alloc<BfWildcardTypeReference>(); auto wildcardTypeRef = mAlloc->Alloc<BfWildcardTypeReference>();
ReplaceNode(nextTokenNode, wildcardTypeRef); ReplaceNode(nextTokenNode, wildcardTypeRef);
wildcardTypeRef->mWildcardToken = nextTokenNode; wildcardTypeRef->mWildcardToken = nextTokenNode;
typeRef = wildcardTypeRef; typeRef = wildcardTypeRef;
@ -4992,10 +4992,10 @@ BfTypeReference* BfReducer::CreateTypeRef(BfAstNode* firstNode, CreateTypeRefFla
if ((createTypeRefFlags & CreateTypeRefFlags_SafeGenericParse) != 0) if ((createTypeRefFlags & CreateTypeRefFlags_SafeGenericParse) != 0)
{ {
createTypeRefFlags = (CreateTypeRefFlags)(createTypeRefFlags & ~CreateTypeRefFlags_SafeGenericParse); createTypeRefFlags = (CreateTypeRefFlags)(createTypeRefFlags & ~CreateTypeRefFlags_SafeGenericParse);
int outEndNode = -1; int outEndNode = -1;
bool isTypeRef = IsTypeReference(firstNode, BfToken_None, &outEndNode); bool isTypeRef = IsTypeReference(firstNode, BfToken_None, &outEndNode);
if ((!isTypeRef) && (outEndNode != -1)) if ((!isTypeRef) && (outEndNode != -1))
{ {
for (int checkIdx = outEndNode - 1; checkIdx > mVisitorPos.mReadPos; checkIdx--) for (int checkIdx = outEndNode - 1; checkIdx > mVisitorPos.mReadPos; checkIdx--)
@ -5012,7 +5012,7 @@ BfTypeReference* BfReducer::CreateTypeRef(BfAstNode* firstNode, CreateTypeRefFla
} }
} }
} }
} }
} }
if (auto tokenNode = BfNodeDynCast<BfTokenNode>(firstNode)) if (auto tokenNode = BfNodeDynCast<BfTokenNode>(firstNode))
@ -5024,7 +5024,7 @@ BfTypeReference* BfReducer::CreateTypeRef(BfAstNode* firstNode, CreateTypeRefFla
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
auto typeRef = DoCreateTypeRef(nextNode, createTypeRefFlags); auto typeRef = DoCreateTypeRef(nextNode, createTypeRefFlags);
if (typeRef == NULL) if (typeRef == NULL)
{ {
mVisitorPos.mReadPos--; mVisitorPos.mReadPos--;
AddErrorNode(tokenNode); AddErrorNode(tokenNode);
return NULL; return NULL;
@ -5122,7 +5122,7 @@ BfIdentifierNode* BfReducer::CompactQualifiedName(BfAstNode* leftNode)
MEMBER_SET(qualifiedNameNode, mDot, tokenNode); MEMBER_SET(qualifiedNameNode, mDot, tokenNode);
MEMBER_SET(qualifiedNameNode, mRight, rightIdentifier); MEMBER_SET(qualifiedNameNode, mRight, rightIdentifier);
leftIdentifier = qualifiedNameNode; leftIdentifier = qualifiedNameNode;
prevNode = NULL; prevNode = NULL;
} }
@ -5236,7 +5236,7 @@ BfAttributeDirective* BfReducer::CreateAttributeDirective(BfTokenNode* startToke
tokenNode = ExpectTokenAfter(attributeDirective, BfToken_RBracket, BfToken_Comma); tokenNode = ExpectTokenAfter(attributeDirective, BfToken_RBracket, BfToken_Comma);
if (tokenNode == NULL) if (tokenNode == NULL)
return attributeDirective; return attributeDirective;
} }
Do_RBracket: Do_RBracket:
if (tokenNode->GetToken() == BfToken_RBracket) if (tokenNode->GetToken() == BfToken_RBracket)
{ {
@ -5247,7 +5247,7 @@ Do_RBracket:
return attributeDirective; return attributeDirective;
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
} }
// Has another one- chain it // Has another one- chain it
auto nextAttribute = CreateAttributeDirective(tokenNode); auto nextAttribute = CreateAttributeDirective(tokenNode);
if (nextAttribute != NULL) if (nextAttribute != NULL)
@ -5274,7 +5274,7 @@ BfExpression* BfReducer::CreateAttributedExpression(BfTokenNode* tokenNode, bool
auto attrIdentifier = mAlloc->Alloc<BfAttributedIdentifierNode>(); auto attrIdentifier = mAlloc->Alloc<BfAttributedIdentifierNode>();
ReplaceNode(attrib, attrIdentifier); ReplaceNode(attrib, attrIdentifier);
attrIdentifier->mAttributes = attrib; attrIdentifier->mAttributes = attrib;
MEMBER_SET(attrIdentifier, mIdentifier, identifier); MEMBER_SET(attrIdentifier, mIdentifier, identifier);
return attrIdentifier; return attrIdentifier;
} }
@ -5291,13 +5291,13 @@ BfExpression* BfReducer::CreateAttributedExpression(BfTokenNode* tokenNode, bool
} }
Fail("Prefixed attributes can only be used on constructor calls, invocations, or variable declarations", attrib); Fail("Prefixed attributes can only be used on constructor calls, invocations, or variable declarations", attrib);
BfAttributedExpression* attribExpr = mAlloc->Alloc<BfAttributedExpression>(); BfAttributedExpression* attribExpr = mAlloc->Alloc<BfAttributedExpression>();
ReplaceNode(attrib, attribExpr); ReplaceNode(attrib, attribExpr);
attribExpr->mAttributes = attrib; attribExpr->mAttributes = attrib;
if (expr != NULL) if (expr != NULL)
MEMBER_SET(attribExpr, mExpression, expr); MEMBER_SET(attribExpr, mExpression, expr);
return attribExpr; return attribExpr;
} }
auto attrIdentifier = mAlloc->Alloc<BfAttributedIdentifierNode>(); auto attrIdentifier = mAlloc->Alloc<BfAttributedIdentifierNode>();
@ -5305,19 +5305,19 @@ BfExpression* BfReducer::CreateAttributedExpression(BfTokenNode* tokenNode, bool
attrIdentifier->mAttributes = attrib; attrIdentifier->mAttributes = attrib;
auto identifier = ExpectIdentifierAfter(attrib); auto identifier = ExpectIdentifierAfter(attrib);
if (identifier != NULL) if (identifier != NULL)
{ {
MEMBER_SET(attrIdentifier, mIdentifier, identifier); MEMBER_SET(attrIdentifier, mIdentifier, identifier);
} }
return attrIdentifier; return attrIdentifier;
} }
BfTokenNode* BfReducer::ReadArguments(BfAstNode* parentNode, BfAstNode* afterNode, SizedArrayImpl<BfExpression*>* arguments, SizedArrayImpl<BfTokenNode*>* commas, BfToken endToken, bool allowSkippedArgs, CreateExprFlags createExprFlags) BfTokenNode* BfReducer::ReadArguments(BfAstNode* parentNode, BfAstNode* afterNode, SizedArrayImpl<BfExpression*>* arguments, SizedArrayImpl<BfTokenNode*>* commas, BfToken endToken, bool allowSkippedArgs, CreateExprFlags createExprFlags)
{ {
for (int paramIdx = 0; true; paramIdx++) for (int paramIdx = 0; true; paramIdx++)
{ {
auto nextNode = mVisitorPos.GetNext(); auto nextNode = mVisitorPos.GetNext();
if ((nextNode == NULL) && (endToken == BfToken_None)) if ((nextNode == NULL) && (endToken == BfToken_None))
return NULL; return NULL;
BfTokenNode* tokenNode = BfNodeDynCastExact<BfTokenNode>(nextNode); BfTokenNode* tokenNode = BfNodeDynCastExact<BfTokenNode>(nextNode);
if (tokenNode != NULL) if (tokenNode != NULL)
@ -5477,7 +5477,7 @@ BfFieldDeclaration* BfReducer::CreateFieldDeclaration(BfTokenNode* tokenNode, Bf
MEMBER_SET(fieldDeclaration, mPrecedingComma, tokenNode); MEMBER_SET(fieldDeclaration, mPrecedingComma, tokenNode);
MEMBER_SET(fieldDeclaration, mNameNode, nameIdentifier); MEMBER_SET(fieldDeclaration, mNameNode, nameIdentifier);
fieldDeclaration->mDocumentation = prevFieldDeclaration->mDocumentation; fieldDeclaration->mDocumentation = prevFieldDeclaration->mDocumentation;
fieldDeclaration->mAttributes = prevFieldDeclaration->mAttributes; fieldDeclaration->mAttributes = prevFieldDeclaration->mAttributes;
fieldDeclaration->mProtectionSpecifier = prevFieldDeclaration->mProtectionSpecifier; fieldDeclaration->mProtectionSpecifier = prevFieldDeclaration->mProtectionSpecifier;
fieldDeclaration->mStaticSpecifier = prevFieldDeclaration->mStaticSpecifier; fieldDeclaration->mStaticSpecifier = prevFieldDeclaration->mStaticSpecifier;
fieldDeclaration->mTypeRef = prevFieldDeclaration->mTypeRef; fieldDeclaration->mTypeRef = prevFieldDeclaration->mTypeRef;
@ -5493,7 +5493,7 @@ BfFieldDeclaration* BfReducer::CreateFieldDeclaration(BfTokenNode* tokenNode, Bf
} }
else else
{ {
ReplaceNode(typeRef, fieldDeclaration); ReplaceNode(typeRef, fieldDeclaration);
fieldDeclaration->mTypeRef = typeRef; fieldDeclaration->mTypeRef = typeRef;
fieldDeclaration->mNameNode = nameIdentifier; fieldDeclaration->mNameNode = nameIdentifier;
fieldDeclaration->mInitializer = NULL; fieldDeclaration->mInitializer = NULL;
@ -5550,7 +5550,7 @@ BfFieldDeclaration* BfReducer::CreateFieldDeclaration(BfTokenNode* tokenNode, Bf
} }
BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, int depth) BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, int depth)
{ {
BfToken token = tokenNode->GetToken(); BfToken token = tokenNode->GetToken();
if (token == BfToken_Semicolon) if (token == BfToken_Semicolon)
@ -5807,9 +5807,9 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, int depth)
case BfToken_Virtual: case BfToken_Virtual:
case BfToken_Override: case BfToken_Override:
case BfToken_Abstract: case BfToken_Abstract:
case BfToken_Concrete: case BfToken_Concrete:
case BfToken_Extern: case BfToken_Extern:
case BfToken_New: case BfToken_New:
case BfToken_Implicit: case BfToken_Implicit:
case BfToken_Explicit: case BfToken_Explicit:
case BfToken_ReadOnly: case BfToken_ReadOnly:
@ -5823,13 +5823,13 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, int depth)
break; break;
} }
int startNodeIdx = gAssertCurrentNodeIdx; int startNodeIdx = gAssertCurrentNodeIdx;
BfAstNode* typeMember = NULL; BfAstNode* typeMember = NULL;
nextNode = mVisitorPos.GetNext(); nextNode = mVisitorPos.GetNext();
if (nextNode != NULL) if (nextNode != NULL)
{ {
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
typeMember = ReadTypeMember(nextNode, depth + 1); typeMember = ReadTypeMember(nextNode, depth + 1);
} }
auto memberDecl = BfNodeDynCast<BfMemberDeclaration>(typeMember); auto memberDecl = BfNodeDynCast<BfMemberDeclaration>(typeMember);
@ -5881,7 +5881,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, int depth)
MEMBER_SET(memberDecl, mProtectionSpecifier, tokenNode); MEMBER_SET(memberDecl, mProtectionSpecifier, tokenNode);
return memberDecl; return memberDecl;
} }
if (auto methodDecl = BfNodeDynCast<BfMethodDeclaration>(memberDecl)) if (auto methodDecl = BfNodeDynCast<BfMethodDeclaration>(memberDecl))
{ {
if ((token == BfToken_Virtual) || if ((token == BfToken_Virtual) ||
@ -6125,14 +6125,14 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf
} }
if (accessorName == "get") if (accessorName == "get")
{ {
// if (hadGet) // if (hadGet)
// Fail("Only one 'get' method can be specified", accessorIdentifier); // Fail("Only one 'get' method can be specified", accessorIdentifier);
hadGet = true; hadGet = true;
} }
else if (accessorName == "set") else if (accessorName == "set")
{ {
// if (hadSet) // if (hadSet)
// Fail("Only one 'set' method can be specified", accessorIdentifier); // Fail("Only one 'set' method can be specified", accessorIdentifier);
hadSet = true; hadSet = true;
} }
else else
@ -6400,12 +6400,12 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, int depth)
ReplaceNode(typeRef, methodDeclaration); ReplaceNode(typeRef, methodDeclaration);
else else
ReplaceNode(nameIdentifier, methodDeclaration); ReplaceNode(nameIdentifier, methodDeclaration);
methodDeclaration->mDocumentation = FindDocumentation(mTypeMemberNodeStart); methodDeclaration->mDocumentation = FindDocumentation(mTypeMemberNodeStart);
MEMBER_SET(methodDeclaration, mReturnType, typeRef); MEMBER_SET(methodDeclaration, mReturnType, typeRef);
MEMBER_SET(methodDeclaration, mExplicitInterface, explicitInterface); MEMBER_SET(methodDeclaration, mExplicitInterface, explicitInterface);
MEMBER_SET(methodDeclaration, mExplicitInterfaceDotToken, explicitInterfaceDot); MEMBER_SET(methodDeclaration, mExplicitInterfaceDotToken, explicitInterfaceDot);
return methodDeclaration; return methodDeclaration;
} }
} }
} }
} }
@ -6548,7 +6548,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, int depth)
bool isExprBodyProp = (tokenNode != NULL) && (tokenNode->mToken == BfToken_FatArrow); bool isExprBodyProp = (tokenNode != NULL) && (tokenNode->mToken == BfToken_FatArrow);
// Property. // Property.
// If we don't have a token afterwards then still treat it as a property for autocomplete purposes // If we don't have a token afterwards then still treat it as a property for autocomplete purposes
if ((typeRef != NULL) && if ((typeRef != NULL) &&
((block != NULL) || (tokenNode == NULL) || (isExprBodyProp))) ((block != NULL) || (tokenNode == NULL) || (isExprBodyProp)))
{ {
//mVisitorPos.mReadPos = blockAfterIdx; //mVisitorPos.mReadPos = blockAfterIdx;
@ -6556,7 +6556,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, int depth)
if (propertyDeclaration == NULL) if (propertyDeclaration == NULL)
{ {
if ((block == NULL) && (!isExprBodyProp)) if ((block == NULL) && (!isExprBodyProp))
{ {
auto propDecl = mAlloc->Alloc<BfPropertyDeclaration>(); auto propDecl = mAlloc->Alloc<BfPropertyDeclaration>();
ReplaceNode(typeRef, propDecl); ReplaceNode(typeRef, propDecl);
propDecl->mDocumentation = FindDocumentation(mTypeMemberNodeStart); propDecl->mDocumentation = FindDocumentation(mTypeMemberNodeStart);
@ -6570,7 +6570,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, int depth)
// Don't set the name identifier, this could be bogus // Don't set the name identifier, this could be bogus
//mVisitorPos.mReadPos--; //mVisitorPos.mReadPos--;
// WHY did we want to not set this? // WHY did we want to not set this?
// If we don't, then typing a new method name will end up treating the name node as a typeRef // If we don't, then typing a new method name will end up treating the name node as a typeRef
// which can autocomplete incorrectly // which can autocomplete incorrectly
@ -6603,17 +6603,17 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, int depth)
ReadPropertyBlock(propertyDeclaration, block); ReadPropertyBlock(propertyDeclaration, block);
} }
else if (isExprBodyProp) else if (isExprBodyProp)
{ {
BfDeferredAstSizedArray<BfPropertyMethodDeclaration*> methods(propertyDeclaration->mMethods, mAlloc); BfDeferredAstSizedArray<BfPropertyMethodDeclaration*> methods(propertyDeclaration->mMethods, mAlloc);
auto propertyBodyExpr = mAlloc->Alloc<BfPropertyBodyExpression>(); auto propertyBodyExpr = mAlloc->Alloc<BfPropertyBodyExpression>();
ReplaceNode(tokenNode, propertyBodyExpr); ReplaceNode(tokenNode, propertyBodyExpr);
MEMBER_SET(propertyBodyExpr, mFatTokenArrow, tokenNode); MEMBER_SET(propertyBodyExpr, mFatTokenArrow, tokenNode);
auto method = mAlloc->Alloc<BfPropertyMethodDeclaration>(); auto method = mAlloc->Alloc<BfPropertyMethodDeclaration>();
method->mPropertyDeclaration = propertyDeclaration; method->mPropertyDeclaration = propertyDeclaration;
method->mNameNode = propertyDeclaration->mNameNode; method->mNameNode = propertyDeclaration->mNameNode;
auto expr = CreateExpressionAfter(tokenNode); auto expr = CreateExpressionAfter(tokenNode);
if (expr != NULL) if (expr != NULL)
{ {
@ -6871,7 +6871,7 @@ BfLambdaBindExpression* BfReducer::CreateLambdaBindExpression(BfAstNode* allocNo
ReplaceNode(parenToken, lambdaBindExpr); ReplaceNode(parenToken, lambdaBindExpr);
tokenNode = parenToken; tokenNode = parenToken;
} }
if (tokenNode == NULL) if (tokenNode == NULL)
return lambdaBindExpr; return lambdaBindExpr;
@ -7072,7 +7072,7 @@ BfScopedInvocationTarget* BfReducer::CreateScopedInvocationTarget(BfAstNode*& ta
{ {
FailAfter("Expected scope name", scopedInvocationTarget); FailAfter("Expected scope name", scopedInvocationTarget);
} }
return scopedInvocationTarget; return scopedInvocationTarget;
} }
@ -7085,13 +7085,13 @@ BfAstNode* BfReducer::CreateAllocNode(BfTokenNode* allocToken)
return allocToken; return allocToken;
if ((nextToken->mToken != BfToken_Colon) && (nextToken->mToken != BfToken_LBracket)) if ((nextToken->mToken != BfToken_Colon) && (nextToken->mToken != BfToken_LBracket))
return allocToken; return allocToken;
auto scopeNode = mAlloc->Alloc<BfScopeNode>(); auto scopeNode = mAlloc->Alloc<BfScopeNode>();
ReplaceNode(allocToken, scopeNode); ReplaceNode(allocToken, scopeNode);
scopeNode->mScopeToken = allocToken; scopeNode->mScopeToken = allocToken;
if (nextToken->mToken == BfToken_Colon) if (nextToken->mToken == BfToken_Colon)
{ {
MEMBER_SET(scopeNode, mColonToken, nextToken); MEMBER_SET(scopeNode, mColonToken, nextToken);
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
@ -7125,7 +7125,7 @@ BfAstNode* BfReducer::CreateAllocNode(BfTokenNode* allocToken)
auto attributeDirective = CreateAttributeDirective(nextToken); auto attributeDirective = CreateAttributeDirective(nextToken);
MEMBER_SET(scopeNode, mAttributes, attributeDirective); MEMBER_SET(scopeNode, mAttributes, attributeDirective);
return scopeNode; return scopeNode;
} }
if (allocToken->GetToken() == BfToken_New) if (allocToken->GetToken() == BfToken_New)
@ -7142,7 +7142,7 @@ BfAstNode* BfReducer::CreateAllocNode(BfTokenNode* allocToken)
newNode->mNewToken = allocToken; newNode->mNewToken = allocToken;
if (nextToken->mToken == BfToken_Colon) if (nextToken->mToken == BfToken_Colon)
{ {
MEMBER_SET(newNode, mColonToken, nextToken); MEMBER_SET(newNode, mColonToken, nextToken);
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
@ -7219,7 +7219,7 @@ BfAstNode* BfReducer::CreateAllocNode(BfTokenNode* allocToken)
{ {
MEMBER_SET(newNode, mAllocNode, identifier); MEMBER_SET(newNode, mAllocNode, identifier);
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
} }
} }
} }
@ -7335,7 +7335,7 @@ BfExpression* BfReducer::CreateIndexerExpression(BfExpression* target)
{ {
if (tokenNode->mToken == BfToken_LBracket) if (tokenNode->mToken == BfToken_LBracket)
{ {
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
attributeDirective = CreateAttributeDirective(tokenNode); attributeDirective = CreateAttributeDirective(tokenNode);
argAfterNode = attributeDirective; argAfterNode = attributeDirective;
} }
@ -7345,8 +7345,8 @@ BfExpression* BfReducer::CreateIndexerExpression(BfExpression* target)
if (attributeDirective != NULL) if (attributeDirective != NULL)
{ {
BfAttributedExpression* attribExpr = mAlloc->Alloc<BfAttributedExpression>(); BfAttributedExpression* attribExpr = mAlloc->Alloc<BfAttributedExpression>();
attribExpr->mAttributes = attributeDirective; attribExpr->mAttributes = attributeDirective;
MEMBER_SET(attribExpr, mExpression, indexerExpr); MEMBER_SET(attribExpr, mExpression, indexerExpr);
return attribExpr; return attribExpr;
} }
@ -7559,7 +7559,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
{ {
SetAndRestoreValue<BfVisitorPos> prevVisitorPos(mVisitorPos, BfVisitorPos(block)); SetAndRestoreValue<BfVisitorPos> prevVisitorPos(mVisitorPos, BfVisitorPos(block));
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
bool hadIllegal = false; bool hadIllegal = false;
bool inAssignment = false; bool inAssignment = false;
@ -7609,14 +7609,14 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
} }
checkIdx++; checkIdx++;
} }
if (!hadIllegal) if (!hadIllegal)
{ {
isSimpleEnum = true; isSimpleEnum = true;
} }
break; break;
} }
checkReadPos++; checkReadPos++;
@ -7656,7 +7656,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
auto usingDirective = mAlloc->Alloc<BfUsingDirective>(); auto usingDirective = mAlloc->Alloc<BfUsingDirective>();
ReplaceNode(tokenNode, usingDirective); ReplaceNode(tokenNode, usingDirective);
usingDirective->mUsingToken = tokenNode; usingDirective->mUsingToken = tokenNode;
auto identifierNode = ExpectIdentifierAfter(usingDirective); auto identifierNode = ExpectIdentifierAfter(usingDirective);
if (identifierNode != NULL) if (identifierNode != NULL)
{ {
@ -7748,10 +7748,10 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
return typeDeclaration; return typeDeclaration;
} }
break; break;
case BfToken_Sealed: case BfToken_Sealed:
case BfToken_Abstract: case BfToken_Abstract:
case BfToken_Concrete: case BfToken_Concrete:
case BfToken_Public: case BfToken_Public:
case BfToken_Private: case BfToken_Private:
case BfToken_Protected: case BfToken_Protected:
@ -7812,7 +7812,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
} }
MEMBER_SET(typeDeclaration, mProtectionSpecifier, tokenNode); MEMBER_SET(typeDeclaration, mProtectionSpecifier, tokenNode);
} }
if (token == BfToken_Static) if (token == BfToken_Static)
{ {
if (typeDeclaration->mStaticSpecifier != NULL) if (typeDeclaration->mStaticSpecifier != NULL)
@ -7839,7 +7839,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
} }
MEMBER_SET(typeDeclaration, mAbstractSpecifier, tokenNode); MEMBER_SET(typeDeclaration, mAbstractSpecifier, tokenNode);
} }
//TODO: Store type specifiers //TODO: Store type specifiers
return typeDeclaration; return typeDeclaration;
} }
@ -7915,7 +7915,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
auto typeDeclaration = mAlloc->Alloc<BfTypeAliasDeclaration>(); auto typeDeclaration = mAlloc->Alloc<BfTypeAliasDeclaration>();
BfDeferredAstSizedArray<BfTypeReference*> baseClasses(typeDeclaration->mBaseClasses, mAlloc); BfDeferredAstSizedArray<BfTypeReference*> baseClasses(typeDeclaration->mBaseClasses, mAlloc);
BfDeferredAstSizedArray<BfAstNode*> baseClassCommas(typeDeclaration->mBaseClassCommas, mAlloc); BfDeferredAstSizedArray<BfAstNode*> baseClassCommas(typeDeclaration->mBaseClassCommas, mAlloc);
mLastTypeDecl = typeDeclaration; mLastTypeDecl = typeDeclaration;
typeDeclaration->mTypeNode = tokenNode; typeDeclaration->mTypeNode = tokenNode;
typeDeclaration->mNameNode = identifierNode; typeDeclaration->mNameNode = identifierNode;
ReplaceNode(tokenNode, typeDeclaration); ReplaceNode(tokenNode, typeDeclaration);
@ -7977,7 +7977,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
auto typeDeclaration = mAlloc->Alloc<BfTypeDeclaration>(); auto typeDeclaration = mAlloc->Alloc<BfTypeDeclaration>();
BfDeferredAstSizedArray<BfTypeReference*> baseClasses(typeDeclaration->mBaseClasses, mAlloc); BfDeferredAstSizedArray<BfTypeReference*> baseClasses(typeDeclaration->mBaseClasses, mAlloc);
BfDeferredAstSizedArray<BfAstNode*> baseClassCommas(typeDeclaration->mBaseClassCommas, mAlloc); BfDeferredAstSizedArray<BfAstNode*> baseClassCommas(typeDeclaration->mBaseClassCommas, mAlloc);
mLastTypeDecl = typeDeclaration; mLastTypeDecl = typeDeclaration;
typeDeclaration->mTypeNode = tokenNode; typeDeclaration->mTypeNode = tokenNode;
typeDeclaration->mNameNode = identifierNode; typeDeclaration->mNameNode = identifierNode;
ReplaceNode(tokenNode, typeDeclaration); ReplaceNode(tokenNode, typeDeclaration);
@ -8065,9 +8065,9 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
typeDeclaration->mDefineNode = blockNode; typeDeclaration->mDefineNode = blockNode;
MoveNode(blockNode, typeDeclaration); MoveNode(blockNode, typeDeclaration);
HandleTypeDeclaration(typeDeclaration, attributes); HandleTypeDeclaration(typeDeclaration, attributes);
} }
return typeDeclaration; return typeDeclaration;
} }
break; break;
default: break; default: break;
@ -8085,7 +8085,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
auto typeDeclaration = mAlloc->Alloc<BfTypeDeclaration>(); auto typeDeclaration = mAlloc->Alloc<BfTypeDeclaration>();
BfDeferredAstSizedArray<BfTypeReference*> baseClasses(typeDeclaration->mBaseClasses, mAlloc); BfDeferredAstSizedArray<BfTypeReference*> baseClasses(typeDeclaration->mBaseClasses, mAlloc);
auto prevTypeDecl = mCurTypeDecl; auto prevTypeDecl = mCurTypeDecl;
mCurTypeDecl = typeDeclaration; mCurTypeDecl = typeDeclaration;
typeDeclaration->mTypeNode = tokenNode; typeDeclaration->mTypeNode = tokenNode;
typeDeclaration->mNameNode = identifierNode; typeDeclaration->mNameNode = identifierNode;
ReplaceNode(tokenNode, typeDeclaration); ReplaceNode(tokenNode, typeDeclaration);
@ -8147,7 +8147,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
Fail("Enum value name expected", child); Fail("Enum value name expected", child);
break; break;
} }
MEMBER_SET(fieldDecl, mNameNode, valueName); MEMBER_SET(fieldDecl, mNameNode, valueName);
auto nextNode = mVisitorPos.GetCurrent(); auto nextNode = mVisitorPos.GetCurrent();
if (auto equalsToken = BfNodeDynCast<BfTokenNode>(nextNode)) if (auto equalsToken = BfNodeDynCast<BfTokenNode>(nextNode))
{ {
@ -8294,7 +8294,7 @@ BfTokenNode* BfReducer::BreakDoubleChevron(BfTokenNode* tokenNode)
tokenNode->GetSrcPositions(triviaStart, srcStart, srcEnd); tokenNode->GetSrcPositions(triviaStart, srcStart, srcEnd);
firstChevron->Init(triviaStart, srcStart, srcEnd - 1); firstChevron->Init(triviaStart, srcStart, srcEnd - 1);
tokenNode->SetToken(BfToken_RChevron); tokenNode->SetToken(BfToken_RChevron);
tokenNode->SetSrcStart(srcStart + 1); tokenNode->SetSrcStart(srcStart + 1);
tokenNode->SetTriviaStart(srcStart); tokenNode->SetTriviaStart(srcStart);
@ -8321,7 +8321,7 @@ BfTokenNode* BfReducer::BreakQuestionLBracket(BfTokenNode* tokenNode)
} }
BfCommentNode * BfReducer::FindDocumentation(BfAstNode* defNodeHead, BfAstNode* defNodeEnd, bool checkDocAfter) BfCommentNode * BfReducer::FindDocumentation(BfAstNode* defNodeHead, BfAstNode* defNodeEnd, bool checkDocAfter)
{ {
if (defNodeEnd == NULL) if (defNodeEnd == NULL)
defNodeEnd = defNodeHead; defNodeEnd = defNodeHead;
else if (defNodeHead == NULL) else if (defNodeHead == NULL)
@ -8362,12 +8362,12 @@ BfCommentNode * BfReducer::FindDocumentation(BfAstNode* defNodeHead, BfAstNode*
mDocumentCheckIdx++; mDocumentCheckIdx++;
return checkComment; return checkComment;
} }
} }
return NULL; return NULL;
} }
if (checkComment->mCommentKind != BfCommentKind_Documentation_Pre) if (checkComment->mCommentKind != BfCommentKind_Documentation_Pre)
{ {
// Skip this, not used // Skip this, not used
@ -8393,16 +8393,16 @@ BfCommentNode * BfReducer::FindDocumentation(BfAstNode* defNodeHead, BfAstNode*
char c = mSource->mSrc[idx]; char c = mSource->mSrc[idx];
if (!isspace((uint8)c)) if (!isspace((uint8)c))
return NULL; return NULL;
} }
return checkComment; return checkComment;
} }
return NULL; return NULL;
} }
BfTokenNode* BfReducer::ParseMethodParams(BfAstNode* node, SizedArrayImpl<BfParameterDeclaration*>* params, SizedArrayImpl<BfTokenNode*>* commas, BfToken endToken) BfTokenNode* BfReducer::ParseMethodParams(BfAstNode* node, SizedArrayImpl<BfParameterDeclaration*>* params, SizedArrayImpl<BfTokenNode*>* commas, BfToken endToken)
{ {
BfAstNode* nameAfterNode = node; BfAstNode* nameAfterNode = node;
BfAttributeDirective* attributes = NULL; BfAttributeDirective* attributes = NULL;
for (int paramIdx = 0; true; paramIdx++) for (int paramIdx = 0; true; paramIdx++)
{ {
@ -8467,7 +8467,7 @@ BfTokenNode* BfReducer::ParseMethodParams(BfAstNode* node, SizedArrayImpl<BfPara
return NULL; return NULL;
} }
} }
attributes = NULL; attributes = NULL;
BfTokenNode* modTokenNode = NULL; BfTokenNode* modTokenNode = NULL;
nextNode = ReplaceTokenStarter(mVisitorPos.GetNext(), mVisitorPos.mReadPos + 1); nextNode = ReplaceTokenStarter(mVisitorPos.GetNext(), mVisitorPos.mReadPos + 1);
@ -8477,12 +8477,12 @@ BfTokenNode* BfReducer::ParseMethodParams(BfAstNode* node, SizedArrayImpl<BfPara
{ {
mVisitorPos.MoveNext(); mVisitorPos.MoveNext();
attributes = CreateAttributeDirective(tokenNode); attributes = CreateAttributeDirective(tokenNode);
if (attributes != NULL) if (attributes != NULL)
{ {
nameAfterNode = attributes; nameAfterNode = attributes;
auto nextNode = mVisitorPos.GetNext(); auto nextNode = mVisitorPos.GetNext();
tokenNode = BfNodeDynCast<BfTokenNode>(nextNode); tokenNode = BfNodeDynCast<BfTokenNode>(nextNode);
} }
} }
int paramStartReadPos = mVisitorPos.mReadPos; int paramStartReadPos = mVisitorPos.mReadPos;
@ -8822,7 +8822,7 @@ bool BfReducer::ParseMethod(BfMethodDeclaration* methodDeclaration, SizedArrayIm
MEMBER_SET_CHECKED_BOOL(methodDeclaration, mGenericConstraintsDeclaration, genericConstraints); MEMBER_SET_CHECKED_BOOL(methodDeclaration, mGenericConstraintsDeclaration, genericConstraints);
} }
} }
auto ctorDecl = BfNodeDynCast<BfConstructorDeclaration>(methodDeclaration); auto ctorDecl = BfNodeDynCast<BfConstructorDeclaration>(methodDeclaration);
nextNode = mVisitorPos.GetNext(); nextNode = mVisitorPos.GetNext();
@ -8937,7 +8937,7 @@ BfGenericArgumentsNode* BfReducer::CreateGenericArguments(BfTokenNode* tokenNode
genericArgsArray.push_back(genericArg); genericArgsArray.push_back(genericArg);
auto nextNode = mVisitorPos.GetNext(); auto nextNode = mVisitorPos.GetNext();
tokenNode = BfNodeDynCast<BfTokenNode>(nextNode); tokenNode = BfNodeDynCast<BfTokenNode>(nextNode);
if (tokenNode == NULL) if (tokenNode == NULL)
{ {
FailAfter("Expected ',' or '>'", genericArgs); FailAfter("Expected ',' or '>'", genericArgs);
@ -9024,7 +9024,7 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration(
bool isDone = false; bool isDone = false;
for (int constraintIdx = 0; !isDone; constraintIdx++) for (int constraintIdx = 0; !isDone; constraintIdx++)
{ {
BfGenericConstraint* genericConstraint = mAlloc->Alloc<BfGenericConstraint>(); BfGenericConstraint* genericConstraint = mAlloc->Alloc<BfGenericConstraint>();
BfDeferredAstSizedArray<BfAstNode*> constraintTypes(genericConstraint->mConstraintTypes, mAlloc); BfDeferredAstSizedArray<BfAstNode*> constraintTypes(genericConstraint->mConstraintTypes, mAlloc);
BfDeferredAstSizedArray<BfTokenNode*> commas(genericConstraint->mCommas, mAlloc); BfDeferredAstSizedArray<BfTokenNode*> commas(genericConstraint->mCommas, mAlloc);
@ -9097,50 +9097,50 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration(
case BfToken_Delete: case BfToken_Delete:
addToConstraint = true; addToConstraint = true;
break; break;
case BfToken_Operator: case BfToken_Operator:
{
BfGenericOperatorConstraint* opConstraint = mAlloc->Alloc<BfGenericOperatorConstraint>();
constraintNode = opConstraint;
ReplaceNode(constraintToken, opConstraint);
MEMBER_SET(opConstraint, mOperatorToken, constraintToken);
mVisitorPos.MoveNext();
auto opToken = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext());
if (opToken == NULL)
{ {
BfGenericOperatorConstraint* opConstraint = mAlloc->Alloc<BfGenericOperatorConstraint>(); auto typeRef = CreateTypeRefAfter(opConstraint, BfReducer::CreateTypeRefFlags_SafeGenericParse);
constraintNode = opConstraint;
ReplaceNode(constraintToken, opConstraint);
MEMBER_SET(opConstraint, mOperatorToken, constraintToken);
mVisitorPos.MoveNext();
auto opToken = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext());
if (opToken == NULL)
{
auto typeRef = CreateTypeRefAfter(opConstraint, BfReducer::CreateTypeRefFlags_SafeGenericParse);
if (typeRef == NULL)
break;
MEMBER_SET(opConstraint, mLeftType, typeRef);
opToken = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext());
if (opToken == NULL)
{
if (auto pointerTypeRef = BfNodeDynCast<BfPointerTypeRef>(typeRef))
{
MEMBER_SET(opConstraint, mLeftType, pointerTypeRef->mElementType);
opToken = pointerTypeRef->mStarNode;
MEMBER_SET(opConstraint, mOpToken, opToken);
}
}
}
if (opConstraint->mOpToken == NULL)
{
if (opToken == NULL)
break;
MEMBER_SET(opConstraint, mOpToken, opToken);
mVisitorPos.MoveNext();
}
auto typeRef = CreateTypeRefAfter(opConstraint);
if (typeRef == NULL) if (typeRef == NULL)
break; break;
MEMBER_SET(opConstraint, mRightType, typeRef); MEMBER_SET(opConstraint, mLeftType, typeRef);
opToken = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext());
if (opToken == NULL)
{
if (auto pointerTypeRef = BfNodeDynCast<BfPointerTypeRef>(typeRef))
{
MEMBER_SET(opConstraint, mLeftType, pointerTypeRef->mElementType);
opToken = pointerTypeRef->mStarNode;
MEMBER_SET(opConstraint, mOpToken, opToken);
}
}
} }
break;
if (opConstraint->mOpToken == NULL)
{
if (opToken == NULL)
break;
MEMBER_SET(opConstraint, mOpToken, opToken);
mVisitorPos.MoveNext();
}
auto typeRef = CreateTypeRefAfter(opConstraint);
if (typeRef == NULL)
break;
MEMBER_SET(opConstraint, mRightType, typeRef);
}
break;
default: break; default: break;
} }
@ -9185,9 +9185,9 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration(
constraintTypes.push_back(typeRef); constraintTypes.push_back(typeRef);
continue; continue;
} }
} }
if (constraintNode != NULL) if (constraintNode != NULL)
{ {
MoveNode(constraintNode, genericConstraint); MoveNode(constraintNode, genericConstraint);