CheckMemoryLeak: add '?1:0' to clarify the value of the argument to 'deleteNext'; Tokenize.cpp: in simplifyCompoundAssignment(), remove ':' odd code used to fix a weird test case ('case' code not inside a function body), remove useless 'tok->next() != NULL' check (already true by previous condition); in simplifyConditionOperator(), handle better the parenthesis skipping code and remove useless ')'check; in simplifyQuestionMark(), remove useless 'tok->tokAt(-2)' check (Token::Match returns false if the token is NULL), add more patterns to Token::Match to handle more test cases; in simplifyBitFields(), add 'const' to 'offset' bool. RedirectOutputError: style nitpick change to declaration of a pointer.

This commit is contained in:
Edoardo Prezioso 2012-10-19 13:34:44 +02:00
parent e44e6837c2
commit 4ddcde1e6f
4 changed files with 10 additions and 20 deletions

View File

@ -1834,7 +1834,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) const
// use; if| use; => use;
while (Token::Match(tok2, "[;{}] use ; if| use ;")) {
Token *t = tok2->tokAt(2);
t->deleteNext(2+(t->str()=="if"));
t->deleteNext(2+(t->str()=="if" ? 1 : 0));
done = false;
}

View File

@ -4040,16 +4040,11 @@ void Tokenizer::simplifyCompoundAssignment()
// Simplify compound assignments:
// "a+=b" => "a = a + b"
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "[;{}] (") || Token::Match(tok, "[;{}:] *| (| %var%")) {
if (tok->str() == ":") {
if (tok->strAt(-2) != "case")
continue;
}
if (Token::Match(tok, "[;{}] (| *| (| %var%")) {
// backup current token..
Token * const tok1 = tok;
if (tok->next() && tok->next()->str() == "*")
if (tok->next()->str() == "*")
tok = tok->next();
if (tok->next() && tok->next()->str() == "(") {
@ -4177,10 +4172,9 @@ void Tokenizer::simplifyConditionOperator()
}
}
if (tok->str() == "(")
if (tok->str() == "(" || tok->str() == "[" ||
(tok->str() == "{" && tok->previous() && tok->previous()->str() == "="))
tok = tok->link();
else if (tok->str() == ")")
break;
if (Token::Match(tok, "[{};] *| %var% = %any% ? %any% : %any% ;") ||
Token::Match(tok, "[{};] return %any% ? %any% : %any% ;")) {
@ -4429,14 +4423,10 @@ bool Tokenizer::simplifyQuestionMark()
if (tok->str() != "?")
continue;
if (!tok->tokAt(-2))
if (!Token::Match(tok->tokAt(-2), "=|,|(|[|{|}|;|case|return"))
continue;
if (!Token::Match(tok->tokAt(-2), "=|,|(|case"))
continue;
if (!tok->previous()->isBoolean() &&
!tok->previous()->isNumber())
if (!tok->previous()->isBoolean() && !tok->previous()->isNumber())
continue;
// Find the ":" token..
@ -8649,7 +8639,7 @@ void Tokenizer::simplifyBitfields()
}
} else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %any% ;") &&
tok->next()->str() != "default") {
bool offset = (tok->next()->str() == "const");
const bool offset = (tok->next()->str() == "const");
if (tok->strAt(3 + (offset ? 1 : 0)) != "{") {
tok->deleteNext(4 + (offset ? 1 : 0));

View File

@ -64,7 +64,7 @@ public:
private:
std::ostringstream _out;
std::ostringstream _err;
std::streambuf* _oldCout;
std::streambuf *_oldCout;
std::streambuf *_oldCerr;
};

View File

@ -6797,7 +6797,7 @@ private:
ASSERT_EQUALS("; ( * p ) = ( * p ) + y ;", tokenizeAndStringify("; (*p) += y;"));
ASSERT_EQUALS("; * ( p [ 0 ] ) = * ( p [ 0 ] ) + y ;", tokenizeAndStringify("; *(p[0]) += y;"));
ASSERT_EQUALS("case 0 : x = x + y ; break ;", tokenizeAndStringify("case 0: x += y; break;"));
ASSERT_EQUALS("void foo ( ) { switch ( n ) { case 0 : ; x = x + y ; break ; } }", tokenizeAndStringify("void foo() { switch (n) { case 0: x += y; break; } }"));
ASSERT_EQUALS("; x . y = x . y + 1 ;", tokenizeAndStringify("; x.y += 1;"));