Refactoring: there was almost duplicate functions 'isOp'. Created a new Token::isOp function instead.

This commit is contained in:
Daniel Marjamäki 2011-04-08 19:40:22 +02:00
parent 3c8644fcf8
commit 8e711b7925
3 changed files with 24 additions and 34 deletions

View File

@ -962,21 +962,6 @@ void CheckOther::checkMemsetZeroBytes()
// Usage of function variables
//---------------------------------------------------------------------------
static bool isOp(const Token *tok)
{
return bool(tok &&
(tok->str() == "&&" ||
tok->str() == "||" ||
tok->str() == "==" ||
tok->str() == "!=" ||
tok->str() == "<" ||
tok->str() == "<=" ||
tok->str() == ">" ||
tok->str() == ">=" ||
tok->str() == "<<" ||
Token::Match(tok, "[+-*/%&!~|^,[])?:]")));
}
/**
* @brief This class is used to capture the control flow within a function.
*/
@ -2223,11 +2208,11 @@ void CheckOther::functionVariableUsage()
else if (Token::Match(tok, "%var% ."))
variables.use(tok->varId()); // use = read + write
else if ((Token::Match(tok, "[(=&!]") || isOp(tok)) &&
else if ((Token::Match(tok, "[(=&!]") || tok->isExtendedOp()) &&
(Token::Match(tok->next(), "%var%") && !Token::Match(tok->next(), "true|false|new")))
variables.readAll(tok->next()->varId());
else if (Token::Match(tok, "%var%") && (tok->next()->str() == ")" || isOp(tok->next())))
else if (Token::Match(tok, "%var%") && (tok->next()->str() == ")" || tok->next()->isExtendedOp()))
variables.readAll(tok->varId());
else if (Token::Match(tok, "; %var% ;"))

View File

@ -153,6 +153,27 @@ public:
{
_isNumber = number;
}
bool isOp() const
{
if (!this)
return false;
return (_str == "&&" ||
_str == "||" ||
_str == "==" ||
_str == "!=" ||
_str == "<" ||
_str == "<=" ||
_str == ">" ||
_str == ">=" ||
_str == "<<" ||
_str == ">>" ||
Token::Match(this, "[+-*/%&|^~!]"));
}
bool isExtendedOp() const
{
return isOp() || Token::Match(this, "[,[]()?:]");
}
bool isBoolean() const
{
return _isBoolean;

View File

@ -6363,22 +6363,6 @@ void Tokenizer::simplifyInitVar()
}
}
static bool isOp(const Token *tok)
{
return bool(tok &&
(tok->str() == "&&" ||
tok->str() == "||" ||
tok->str() == "==" ||
tok->str() == "!=" ||
tok->str() == "<" ||
tok->str() == "<=" ||
tok->str() == ">" ||
tok->str() == ">=" ||
tok->str() == "<<" ||
tok->str() == ">>" ||
Token::Match(tok, "[;+-*/%&|^]")));
}
Token * Tokenizer::initVar(Token * tok)
{
// call constructor of class => no simplification
@ -7052,7 +7036,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
// return variable..
if (Token::Match(tok3, "return %varid% %any%", varid) &&
isOp(tok3->tokAt(2)) &&
(tok3->tokAt(2)->isExtendedOp() || tok3->strAt(2) == ";") &&
value[0] != '\"')
{
tok3->next()->str(value);