Refactoring: Use Token::isOp

This commit is contained in:
Daniel Marjamäki 2011-04-09 15:54:36 +02:00
parent 8c6d61ede3
commit f6d910ab3d
5 changed files with 14 additions and 16 deletions

View File

@ -707,7 +707,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
Token::Match(ftok, "%var% --")) Token::Match(ftok, "%var% --"))
break; break;
if (Token::Match(ftok->previous(), "[=+-*/;{}] %var% [ %num% ]")) if ((Token::Match(ftok->previous(), "[=;{}]") || ftok->previous()->isOp()) && Token::Match(ftok, "%var% [ %num% ]"))
{ {
const MathLib::bigint index = MathLib::toLongNumber(ftok->strAt(2)); const MathLib::bigint index = MathLib::toLongNumber(ftok->strAt(2));
if (index >= 0 && arrayInfo.num[0] > 0 && index >= arrayInfo.num[0]) if (index >= 0 && arrayInfo.num[0] > 0 && index >= arrayInfo.num[0])

View File

@ -1492,7 +1492,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
{ {
addtoken(&rettail, tok, "use"); addtoken(&rettail, tok, "use");
} }
else if (Token::Match(tok->previous(), "[;{}=(,+-*/] %varid% [", varid)) else if ((Token::Match(tok->previous(), "[;{}=(,]") || tok->previous()->isOp()) && Token::Match(tok, "%varid% [", varid))
{ {
// warning is written for "dealloc ; use_ ;". // warning is written for "dealloc ; use_ ;".
// but this use doesn't affect the leak-checking // but this use doesn't affect the leak-checking

View File

@ -153,12 +153,17 @@ public:
{ {
_isNumber = number; _isNumber = number;
} }
bool isArithmeticalOp() const
{
return (this && (_str=="<<" || _str==">>" || (_str.size()==1 && _str.find_first_of("+-*/%") != std::string::npos)));
}
bool isOp() const bool isOp() const
{ {
if (!this) if (!this)
return false; return false;
return (_str == "&&" || return (isArithmeticalOp() ||
_str == "&&" ||
_str == "||" || _str == "||" ||
_str == "==" || _str == "==" ||
_str == "!=" || _str == "!=" ||
@ -166,13 +171,12 @@ public:
_str == "<=" || _str == "<=" ||
_str == ">" || _str == ">" ||
_str == ">=" || _str == ">=" ||
_str == "<<" || (_str.size() == 1 && _str.find_first_of("&|^~!") != std::string::npos));
_str == ">>" ||
Token::Match(this, "[+-*/%&|^~!]"));
} }
bool isExtendedOp() const bool isExtendedOp() const
{ {
return isOp() || Match(this, "[,[]()?:]"); return isOp() ||
(this && _str.size() == 1 && _str.find_first_of(",[]()?:") != std::string::npos);
} }
bool isBoolean() const bool isBoolean() const
{ {

View File

@ -2075,15 +2075,9 @@ bool Tokenizer::tokenize(std::istream &code,
// Combine "- %num%" .. // Combine "- %num%" ..
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (Token::Match(tok, "[([+-*/=,] - %num%") && tok->strAt(2)[0] != '-') if (Token::Match(tok, "%any% - %num%") && (tok->isOp() || Token::Match(tok, "?|:|,|(|[|=|return|case")))
{ {
tok->next()->str(std::string("-") + tok->strAt(2)); tok->next()->str("-" + tok->strAt(2));
tok->next()->deleteNext();
}
if (Token::Match(tok, "return|case - %num%") && tok->strAt(2)[0] != '-')
{
tok->next()->str(std::string("-") + tok->strAt(2));
tok->next()->deleteNext(); tok->next()->deleteNext();
} }
} }

View File

@ -3772,7 +3772,7 @@ private:
const char expected[] = const char expected[] =
"; " "; "
"int a [ ice_or < is_int < int > :: value , is_int < UDT > :: value > :: value ? 1 : - 1 ] ; " "int a [ ice_or < is_int < int > :: value , is_int < UDT > :: value > :: value ? 1 : -1 ] ; "
"int a1 [ N ] ; " "int a1 [ N ] ; "
"int a2 [ N ] [ M ] ; " "int a2 [ N ] [ M ] ; "
"int t ; " "int t ; "