simplifyIfAddBraces: Remove restriction for jumping opening parenthesis '(' as a fix to #2873, because even without this the original test case doesn't crash anymore. Add more jumping patterns.

simplifyFunctionParameters: Add more jumping patterns and an observation related to error message for equal parameter names, help needed.
Fix grammar mistake in comment.
This commit is contained in:
Edoardo Prezioso 2011-12-11 13:01:16 +01:00
parent ffb5d107be
commit 3c098839d1
2 changed files with 13 additions and 10 deletions

View File

@ -4841,8 +4841,9 @@ void Tokenizer::removeRedundantSemicolons()
bool Tokenizer::simplifyIfAddBraces()
{
for (Token *tok = _tokens; tok; tok = tok ? tok->next() : NULL) {
if (tok->str() == "(" && !Token::Match(tok->previous(), "[;{}]")) {
for (Token *tok = _tokens; tok; tok = tok->next()) {
if (tok->str() == "(" || tok->str() == "[" ||
(tok->str() == "{" && tok->previous() && tok->previous()->str() == "=")) {
tok = tok->link();
continue;
}
@ -4861,7 +4862,7 @@ bool Tokenizer::simplifyIfAddBraces()
tok = tok->next()->link();
// ')' should be followed by '{'
if (!tok || Token::simpleMatch(tok, ") {"))
if (Token::simpleMatch(tok, ") {"))
continue;
}
@ -4878,7 +4879,7 @@ bool Tokenizer::simplifyIfAddBraces()
// If there is no code after the if(), abort
if (!tok->next()) {
// This is a syntax error and we should call syntaxError() and return false but
// many tokenizer tests are written with this syntax error so just ingore it.
// many tokenizer tests are written with this syntax error so just ignore it.
return true;
}
@ -5523,7 +5524,11 @@ void Tokenizer::simplifyFunctionParameters()
if (argumentNames.find(tok->str()) != argumentNames.end()) {
// Invalid code, two arguments with the same name.
// TODO, print error perhaps?
// syntaxError(tok);
// If you uncomment it, testrunner will fail:
// testclass.cpp:3910
// because of void Fred::foo5(int, int).
// how should this be handled?
bailOut = true;
break;
}
@ -5537,8 +5542,6 @@ void Tokenizer::simplifyFunctionParameters()
if (bailOut) {
tok = tok1->link();
if (!tok)
return;
continue;
}

View File

@ -5986,12 +5986,12 @@ private:
tokenizeAndStringify("if()x");
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
// ticket #2873
// ticket #2873 - the fix is not needed anymore.
{
const char code[] = "void f() { "
"( { if(*p) (*p) = x(); } ) "
"(void) ( { if(*p) (*p) = x(); } ) "
"}";
ASSERT_EQUALS("void f ( ) { ( { if ( * p ) { ( * p ) = x ( ) ; } } ) }",
ASSERT_EQUALS("void f ( ) { ( void ) ( { if ( * p ) { ( * p ) = x ( ) ; } } ) }",
tokenizeAndStringify(code));
}
}