From d91483ed830422517889a0a20d4f8540ca954c20 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Fri, 31 Jan 2020 16:10:06 -0800 Subject: [PATCH] Fixed multi var decl in switch case --- IDEHelper/Compiler/BfReducer.cpp | 9 ++++++++- IDEHelper/Compiler/BfReducer.h | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/IDEHelper/Compiler/BfReducer.cpp b/IDEHelper/Compiler/BfReducer.cpp index a449a5a1..9b4c0587 100644 --- a/IDEHelper/Compiler/BfReducer.cpp +++ b/IDEHelper/Compiler/BfReducer.cpp @@ -31,6 +31,7 @@ BfReducer::BfReducer() mCurTypeDecl = NULL; mLastTypeDecl = NULL; mCurMethodDecl = NULL; + mLastBlockNode = NULL; mSource = NULL; mClassDepth = 0; mAlloc = NULL; @@ -3365,6 +3366,7 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode) //switchCase->Add(codeBlock); BfDeferredAstSizedArray codeBlockChildArr(codeBlock->mChildArr, mAlloc); + SetAndRestoreValue prevLastBlockNode(mLastBlockNode, NULL); while (true) { @@ -3395,6 +3397,8 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode) MoveNode(stmt, codeBlock); codeBlockChildArr.push_back(stmt); } + + mLastBlockNode = stmt; } MoveNode(switchCase, switchStatement); if (!codeBlock->IsInitialized()) @@ -3734,7 +3738,10 @@ BfAstNode* BfReducer::DoCreateStatement(BfAstNode* node, CreateStmtFlags createS } 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(prevVarDecl)) { continuingVariable = BfNodeDynCast(exprStmt->mExpression); diff --git a/IDEHelper/Compiler/BfReducer.h b/IDEHelper/Compiler/BfReducer.h index 5c25ed11..68e1846f 100644 --- a/IDEHelper/Compiler/BfReducer.h +++ b/IDEHelper/Compiler/BfReducer.h @@ -135,6 +135,7 @@ public: BfTypeDeclaration* mCurTypeDecl; BfTypeDeclaration* mLastTypeDecl; BfMethodDeclaration* mCurMethodDecl; + BfAstNode* mLastBlockNode; bool mStmtHasError; bool mPrevStmtHadError; bool mCompatMode; // Does C++ compatible parsing @@ -144,7 +145,7 @@ public: bool mSkipCurrentNodeAssert; BfVisitorPos mVisitorPos; int mDocumentCheckIdx; - SizedArray mExteriorNodes; + SizedArray mExteriorNodes; int mAssertCurrentNodeIdx;