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

Fixed multi var decl in switch case

This commit is contained in:
Brian Fiete 2020-01-31 16:10:06 -08:00
parent 9c2f95e1cd
commit d91483ed83
2 changed files with 10 additions and 2 deletions

View file

@ -31,6 +31,7 @@ BfReducer::BfReducer()
mCurTypeDecl = NULL; mCurTypeDecl = NULL;
mLastTypeDecl = NULL; mLastTypeDecl = NULL;
mCurMethodDecl = NULL; mCurMethodDecl = NULL;
mLastBlockNode = NULL;
mSource = NULL; mSource = NULL;
mClassDepth = 0; mClassDepth = 0;
mAlloc = NULL; mAlloc = NULL;
@ -3365,6 +3366,7 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode)
//switchCase->Add(codeBlock); //switchCase->Add(codeBlock);
BfDeferredAstSizedArray<BfAstNode*> codeBlockChildArr(codeBlock->mChildArr, mAlloc); BfDeferredAstSizedArray<BfAstNode*> codeBlockChildArr(codeBlock->mChildArr, mAlloc);
SetAndRestoreValue<BfAstNode*> prevLastBlockNode(mLastBlockNode, NULL);
while (true) while (true)
{ {
@ -3395,6 +3397,8 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode)
MoveNode(stmt, codeBlock); MoveNode(stmt, codeBlock);
codeBlockChildArr.push_back(stmt); codeBlockChildArr.push_back(stmt);
} }
mLastBlockNode = stmt;
} }
MoveNode(switchCase, switchStatement); MoveNode(switchCase, switchStatement);
if (!codeBlock->IsInitialized()) if (!codeBlock->IsInitialized())
@ -3734,7 +3738,10 @@ BfAstNode* BfReducer::DoCreateStatement(BfAstNode* node, CreateStmtFlags createS
} }
else if (token == BfToken_Comma) else if (token == BfToken_Comma)
{ {
auto prevVarDecl = mVisitorPos.Get(mVisitorPos.mWritePos - 1); BfAstNode* prevVarDecl = mVisitorPos.Get(mVisitorPos.mWritePos - 1);
if (mLastBlockNode != NULL)
prevVarDecl = mLastBlockNode;
if (auto exprStmt = BfNodeDynCast<BfExpressionStatement>(prevVarDecl)) if (auto exprStmt = BfNodeDynCast<BfExpressionStatement>(prevVarDecl))
{ {
continuingVariable = BfNodeDynCast<BfVariableDeclaration>(exprStmt->mExpression); continuingVariable = BfNodeDynCast<BfVariableDeclaration>(exprStmt->mExpression);

View file

@ -135,6 +135,7 @@ public:
BfTypeDeclaration* mCurTypeDecl; BfTypeDeclaration* mCurTypeDecl;
BfTypeDeclaration* mLastTypeDecl; BfTypeDeclaration* mLastTypeDecl;
BfMethodDeclaration* mCurMethodDecl; BfMethodDeclaration* mCurMethodDecl;
BfAstNode* mLastBlockNode;
bool mStmtHasError; bool mStmtHasError;
bool mPrevStmtHadError; bool mPrevStmtHadError;
bool mCompatMode; // Does C++ compatible parsing bool mCompatMode; // Does C++ compatible parsing
@ -144,7 +145,7 @@ public:
bool mSkipCurrentNodeAssert; bool mSkipCurrentNodeAssert;
BfVisitorPos mVisitorPos; BfVisitorPos mVisitorPos;
int mDocumentCheckIdx; int mDocumentCheckIdx;
SizedArray<BfAstNode*, 4> mExteriorNodes; SizedArray<BfAstNode*, 4> mExteriorNodes;
int mAssertCurrentNodeIdx; int mAssertCurrentNodeIdx;