diff --git a/internaltesting.bat b/internaltesting.bat index 5efee2bcb..b9d132628 100644 --- a/internaltesting.bat +++ b/internaltesting.bat @@ -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 diff --git a/internaltesting/testif.cpp b/internaltesting/testif.cpp new file mode 100644 index 000000000..1cc014f95 --- /dev/null +++ b/internaltesting/testif.cpp @@ -0,0 +1,17 @@ + + +void f() +{ + if (ab) + { + + } + else if (cd) + { + + } + else + { + + } +} \ No newline at end of file diff --git a/internaltesting/testif.out b/internaltesting/testif.out new file mode 100644 index 000000000..9f0fa1b56 --- /dev/null +++ b/internaltesting/testif.out @@ -0,0 +1,13 @@ +4 : { +5 : if +5 : use ab +6 : { +8 : } +9 : elseif +9 : use cd +10 : { +12 : } +13 : else +14 : { +16 : } +17 : } diff --git a/main.cpp b/main.cpp index 71fff5ea4..ccb304098 100644 --- a/main.cpp +++ b/main.cpp @@ -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;