From f6c1973e67b15e81a325ac89a44d45034971d24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 20 May 2007 15:28:42 +0000 Subject: [PATCH] Building statement list: SWITCH - BREAK --- main.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 14d8a439a..a1f9e59be 100644 --- a/main.cpp +++ b/main.cpp @@ -36,6 +36,7 @@ struct STATEMENT NEWARRAY, DELETEARRAY, LOOP, ENDLOOP, IF, ELSE, ELSEIF, ENDIF, + SWITCH, ENDSWITCH, RETURN, CONTINUE, BREAK}; etype Type; unsigned int VarIndex; @@ -645,7 +646,7 @@ void CreateStatementList() } else if (indentlevel >= 1) { - bool hasif = false, hasloop = false; + bool hasif = false, hasloop = false, hasswitch = false; if (strcmp(tok->str,"if")==0) { @@ -669,6 +670,12 @@ void CreateStatementList() hasloop = true; } + else if (strcmp(tok->str,"switch")==0) + { + AppendStatement(STATEMENT::SWITCH, tok); + hasswitch = true; + } + // Declaring variables.. if (IsName(tok->str) && strcmp(tok->str,"delete") && strcmp(tok->str,"return")) { @@ -829,6 +836,10 @@ void CreateStatementList() { AppendStatement(STATEMENT::ENDLOOP, tok); } + else if (hasswitch) + { + AppendStatement(STATEMENT::ENDSWITCH, tok); + } } } @@ -895,6 +906,15 @@ void CreateStatementList() break; + case STATEMENT::SWITCH: + std::cout << "switch"; + break; + + case STATEMENT::ENDSWITCH: + std::cout << "endswitch"; + break; + + case STATEMENT::IF: std::cout << "if"; break; @@ -1160,6 +1180,11 @@ void CheckMemoryLeak() bool endloop = false; std::vector looplist; + // switch + int switchlevel = 0; + bool endswitch = false; + std::vector switchlist; + // Parse the statement list and locate memory leaks.. int indentlevel = 0; std::list::const_iterator it; @@ -1175,6 +1200,9 @@ void CheckMemoryLeak() looplist.push_back(endloop); if (endloop) looplevel++; + switchlist.push_back(endswitch); + if (endswitch) + switchlevel++; break; case STATEMENT::EBRACE: @@ -1209,6 +1237,11 @@ void CheckMemoryLeak() looplevel--; looplist.pop_back(); + // switch level.. + if (switchlist.back()) + switchlevel--; + switchlist.pop_back(); + // Make sure the varlist is empty.. if (indentlevel <= 1) varlist.clear(); @@ -1339,6 +1372,9 @@ void CheckMemoryLeak() // Find the last loop.. for (int i = looplist.size() - 1; i >= 0; i--) { + if (switchlist[i]) + break; + if (!looplist[i]) continue; @@ -1369,6 +1405,7 @@ void CheckMemoryLeak() endif = (it->Type == STATEMENT::ENDIF); endloop = (it->Type == STATEMENT::ENDLOOP); + endswitch = (it->Type == STATEMENT::ENDSWITCH); } }