Refactoring: Use Token::isOp
This commit is contained in:
parent
8c6d61ede3
commit
f6d910ab3d
|
@ -707,7 +707,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
|
|||
Token::Match(ftok, "%var% --"))
|
||||
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));
|
||||
if (index >= 0 && arrayInfo.num[0] > 0 && index >= arrayInfo.num[0])
|
||||
|
|
|
@ -1492,7 +1492,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
{
|
||||
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_ ;".
|
||||
// but this use doesn't affect the leak-checking
|
||||
|
|
14
lib/token.h
14
lib/token.h
|
@ -153,12 +153,17 @@ public:
|
|||
{
|
||||
_isNumber = number;
|
||||
}
|
||||
bool isArithmeticalOp() const
|
||||
{
|
||||
return (this && (_str=="<<" || _str==">>" || (_str.size()==1 && _str.find_first_of("+-*/%") != std::string::npos)));
|
||||
}
|
||||
bool isOp() const
|
||||
{
|
||||
if (!this)
|
||||
return false;
|
||||
|
||||
return (_str == "&&" ||
|
||||
return (isArithmeticalOp() ||
|
||||
_str == "&&" ||
|
||||
_str == "||" ||
|
||||
_str == "==" ||
|
||||
_str == "!=" ||
|
||||
|
@ -166,13 +171,12 @@ public:
|
|||
_str == "<=" ||
|
||||
_str == ">" ||
|
||||
_str == ">=" ||
|
||||
_str == "<<" ||
|
||||
_str == ">>" ||
|
||||
Token::Match(this, "[+-*/%&|^~!]"));
|
||||
(_str.size() == 1 && _str.find_first_of("&|^~!") != std::string::npos));
|
||||
}
|
||||
bool isExtendedOp() const
|
||||
{
|
||||
return isOp() || Match(this, "[,[]()?:]");
|
||||
return isOp() ||
|
||||
(this && _str.size() == 1 && _str.find_first_of(",[]()?:") != std::string::npos);
|
||||
}
|
||||
bool isBoolean() const
|
||||
{
|
||||
|
|
|
@ -2075,15 +2075,9 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
// Combine "- %num%" ..
|
||||
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()->deleteNext();
|
||||
}
|
||||
|
||||
if (Token::Match(tok, "return|case - %num%") && tok->strAt(2)[0] != '-')
|
||||
{
|
||||
tok->next()->str(std::string("-") + tok->strAt(2));
|
||||
tok->next()->str("-" + tok->strAt(2));
|
||||
tok->next()->deleteNext();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3772,7 +3772,7 @@ private:
|
|||
|
||||
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 a2 [ N ] [ M ] ; "
|
||||
"int t ; "
|
||||
|
|
Loading…
Reference in New Issue