internaltesting: IF

This commit is contained in:
Daniel Marjamäki 2007-05-18 18:40:44 +00:00
parent 7f98039631
commit a21ca7e6f6
4 changed files with 59 additions and 5 deletions

View File

@ -12,3 +12,6 @@ hydfc internaltesting\testnew.out internaltesting\testnew.msg
cppcheck --debug internaltesting\testuse.cpp > internaltesting\testuse.msg
hydfc internaltesting\testuse.out internaltesting\testuse.msg
cppcheck --debug internaltesting\testif.cpp > internaltesting\testif.msg
hydfc internaltesting\testif.out internaltesting\testif.msg

View File

@ -0,0 +1,17 @@
void f()
{
if (ab)
{
}
else if (cd)
{
}
else
{
}
}

View File

@ -0,0 +1,13 @@
4 : {
5 : if
5 : use ab
6 : {
8 : }
9 : elseif
9 : use cd
10 : {
12 : }
13 : else
14 : {
16 : }
17 : }

View File

@ -649,7 +649,7 @@ void CreateStatementList()
bool decl = IsName(str1) || str1[0]=='*';
for (TOKEN *tok2 = decl ? tok->next : NULL; tok2; tok2 = tok2->next)
{
if (tok2->str[0] == ';' || tok2->str[0] == '.')
if (strchr("{};.", tok2->str[0]))
break;
const char *str1 = getstr(tok2, 1);
@ -668,7 +668,7 @@ void CreateStatementList()
// Assign..
for (TOKEN *tok2 = tok; tok2; tok2 = tok2->next)
{
if (tok2->str[0]==';')
if (strchr("{};", tok2->str[0]))
break;
TOKEN *eq = tok2;
@ -712,7 +712,7 @@ void CreateStatementList()
// Delete..
for (TOKEN *tok2 = tok; tok2; tok2 = tok2->next)
{
if (tok2->str[0]==';')
if (strchr("{};", tok2->str[0]))
break;
if (match(tok2, "free ( var ) ;"))
@ -730,7 +730,7 @@ void CreateStatementList()
int parlevel = 0;
for (TOKEN *tok2 = tok; tok2; tok2 = tok2->next)
{
if (tok2->str[0]==';')
if (strchr("{};", tok2->str[0]))
break;
if (tok2->str[0] == '(')
@ -758,7 +758,7 @@ void CreateStatementList()
// Return..
for (TOKEN *tok2 = tok; tok2; tok2 = tok2->next)
{
if (strcmp(tok2->str,";")==0)
if (strchr("{};", tok2->str[0]))
break;
if (strcmp(tok2->str,"return")==0 &&
@ -796,6 +796,14 @@ void CreateStatementList()
std::cout << "assign " << VariableNames[s.VarIndex];
break;
case STATEMENT::MALLOC:
std::cout << "malloc " << VariableNames[s.VarIndex];
break;
case STATEMENT::FREE:
std::cout << "free " << VariableNames[s.VarIndex];
break;
case STATEMENT::NEW:
std::cout << "new " << VariableNames[s.VarIndex];
break;
@ -820,6 +828,19 @@ void CreateStatementList()
std::cout << "return " << VariableNames[s.VarIndex];
break;
case STATEMENT::IF:
std::cout << "if";
break;
case STATEMENT::ELSEIF:
std::cout << "elseif";
break;
case STATEMENT::ELSE:
std::cout << "else";
break;
default:
std::cout << "ERROR. Unknown code!!";
break;