Building statement list: SWITCH - BREAK
This commit is contained in:
parent
c7cc0d0f9c
commit
f6c1973e67
39
main.cpp
39
main.cpp
|
@ -36,6 +36,7 @@ struct STATEMENT
|
||||||
NEWARRAY, DELETEARRAY,
|
NEWARRAY, DELETEARRAY,
|
||||||
LOOP, ENDLOOP,
|
LOOP, ENDLOOP,
|
||||||
IF, ELSE, ELSEIF, ENDIF,
|
IF, ELSE, ELSEIF, ENDIF,
|
||||||
|
SWITCH, ENDSWITCH,
|
||||||
RETURN, CONTINUE, BREAK};
|
RETURN, CONTINUE, BREAK};
|
||||||
etype Type;
|
etype Type;
|
||||||
unsigned int VarIndex;
|
unsigned int VarIndex;
|
||||||
|
@ -645,7 +646,7 @@ void CreateStatementList()
|
||||||
}
|
}
|
||||||
else if (indentlevel >= 1)
|
else if (indentlevel >= 1)
|
||||||
{
|
{
|
||||||
bool hasif = false, hasloop = false;
|
bool hasif = false, hasloop = false, hasswitch = false;
|
||||||
|
|
||||||
if (strcmp(tok->str,"if")==0)
|
if (strcmp(tok->str,"if")==0)
|
||||||
{
|
{
|
||||||
|
@ -669,6 +670,12 @@ void CreateStatementList()
|
||||||
hasloop = true;
|
hasloop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (strcmp(tok->str,"switch")==0)
|
||||||
|
{
|
||||||
|
AppendStatement(STATEMENT::SWITCH, tok);
|
||||||
|
hasswitch = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Declaring variables..
|
// Declaring variables..
|
||||||
if (IsName(tok->str) && strcmp(tok->str,"delete") && strcmp(tok->str,"return"))
|
if (IsName(tok->str) && strcmp(tok->str,"delete") && strcmp(tok->str,"return"))
|
||||||
{
|
{
|
||||||
|
@ -829,6 +836,10 @@ void CreateStatementList()
|
||||||
{
|
{
|
||||||
AppendStatement(STATEMENT::ENDLOOP, tok);
|
AppendStatement(STATEMENT::ENDLOOP, tok);
|
||||||
}
|
}
|
||||||
|
else if (hasswitch)
|
||||||
|
{
|
||||||
|
AppendStatement(STATEMENT::ENDSWITCH, tok);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -895,6 +906,15 @@ void CreateStatementList()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case STATEMENT::SWITCH:
|
||||||
|
std::cout << "switch";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATEMENT::ENDSWITCH:
|
||||||
|
std::cout << "endswitch";
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
case STATEMENT::IF:
|
case STATEMENT::IF:
|
||||||
std::cout << "if";
|
std::cout << "if";
|
||||||
break;
|
break;
|
||||||
|
@ -1160,6 +1180,11 @@ void CheckMemoryLeak()
|
||||||
bool endloop = false;
|
bool endloop = false;
|
||||||
std::vector<bool> looplist;
|
std::vector<bool> looplist;
|
||||||
|
|
||||||
|
// switch
|
||||||
|
int switchlevel = 0;
|
||||||
|
bool endswitch = false;
|
||||||
|
std::vector<bool> switchlist;
|
||||||
|
|
||||||
// Parse the statement list and locate memory leaks..
|
// Parse the statement list and locate memory leaks..
|
||||||
int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
std::list<STATEMENT>::const_iterator it;
|
std::list<STATEMENT>::const_iterator it;
|
||||||
|
@ -1175,6 +1200,9 @@ void CheckMemoryLeak()
|
||||||
looplist.push_back(endloop);
|
looplist.push_back(endloop);
|
||||||
if (endloop)
|
if (endloop)
|
||||||
looplevel++;
|
looplevel++;
|
||||||
|
switchlist.push_back(endswitch);
|
||||||
|
if (endswitch)
|
||||||
|
switchlevel++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATEMENT::EBRACE:
|
case STATEMENT::EBRACE:
|
||||||
|
@ -1209,6 +1237,11 @@ void CheckMemoryLeak()
|
||||||
looplevel--;
|
looplevel--;
|
||||||
looplist.pop_back();
|
looplist.pop_back();
|
||||||
|
|
||||||
|
// switch level..
|
||||||
|
if (switchlist.back())
|
||||||
|
switchlevel--;
|
||||||
|
switchlist.pop_back();
|
||||||
|
|
||||||
// Make sure the varlist is empty..
|
// Make sure the varlist is empty..
|
||||||
if (indentlevel <= 1)
|
if (indentlevel <= 1)
|
||||||
varlist.clear();
|
varlist.clear();
|
||||||
|
@ -1339,6 +1372,9 @@ void CheckMemoryLeak()
|
||||||
// Find the last loop..
|
// Find the last loop..
|
||||||
for (int i = looplist.size() - 1; i >= 0; i--)
|
for (int i = looplist.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
|
if (switchlist[i])
|
||||||
|
break;
|
||||||
|
|
||||||
if (!looplist[i])
|
if (!looplist[i])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -1369,6 +1405,7 @@ void CheckMemoryLeak()
|
||||||
|
|
||||||
endif = (it->Type == STATEMENT::ENDIF);
|
endif = (it->Type == STATEMENT::ENDIF);
|
||||||
endloop = (it->Type == STATEMENT::ENDLOOP);
|
endloop = (it->Type == STATEMENT::ENDLOOP);
|
||||||
|
endswitch = (it->Type == STATEMENT::ENDSWITCH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue