Implement Token::findsimplematch und use it for simple patterns
This commit is contained in:
parent
54adb910ec
commit
434fb933a8
|
@ -638,7 +638,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
|
|||
ftok = ftok->next()->link();
|
||||
if (!Token::Match(ftok, ") const| {"))
|
||||
return;
|
||||
ftok = Token::findmatch(ftok, "{");
|
||||
ftok = Token::findsimplematch(ftok, "{");
|
||||
ftok = ftok->next();
|
||||
|
||||
// Check the parameter usage in the function scope..
|
||||
|
@ -731,7 +731,7 @@ void CheckBufferOverrun::checkScopeForBody(const Token *tok, const ArrayInfo &ar
|
|||
{
|
||||
const Token *bodyStart = tok->next()->link()->next();
|
||||
const Token *bodyEnd = bodyStart->link();
|
||||
if (Token::findmatch(bodyStart, "break ;", bodyEnd))
|
||||
if (Token::findsimplematch(bodyStart, "break ;", bodyEnd))
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -530,7 +530,7 @@ void CheckClass::privateFunctions()
|
|||
return;
|
||||
|
||||
// dont check borland classes with properties..
|
||||
if (Token::findmatch(_tokenizer->tokens(), "; __property ;"))
|
||||
if (Token::findsimplematch(_tokenizer->tokens(), "; __property ;"))
|
||||
return;
|
||||
|
||||
createSymbolDatabase();
|
||||
|
|
|
@ -773,11 +773,11 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
|||
|
||||
const char *ret = 0;
|
||||
/** @todo handle "goto" */
|
||||
if (Token::findmatch(func_, "dealloc"))
|
||||
if (Token::findsimplematch(func_, "dealloc"))
|
||||
ret = "dealloc";
|
||||
else if (Token::findmatch(func_, "use"))
|
||||
else if (Token::findsimplematch(func_, "use"))
|
||||
ret = "use";
|
||||
else if (Token::findmatch(func_, "&use"))
|
||||
else if (Token::findsimplematch(func_, "&use"))
|
||||
ret = "&use";
|
||||
|
||||
Tokenizer::deleteTokens(func);
|
||||
|
@ -2058,7 +2058,7 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens)
|
|||
{
|
||||
const Token *result;
|
||||
|
||||
if ((result = Token::findmatch(tokens, "loop alloc ;")) != NULL) {
|
||||
if ((result = Token::findsimplematch(tokens, "loop alloc ;")) != NULL) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2074,16 +2074,16 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens)
|
|||
return result->tokAt(2);
|
||||
}
|
||||
|
||||
if ((result = Token::findmatch(tokens, "; alloc ; if assign ;")) != NULL) {
|
||||
if ((result = Token::findsimplematch(tokens, "; alloc ; if assign ;")) != NULL) {
|
||||
return result->tokAt(4);
|
||||
}
|
||||
|
||||
if (((result = Token::findmatch(tokens, "; alloc ; if dealloc ; }")) != NULL) &&
|
||||
if (((result = Token::findsimplematch(tokens, "; alloc ; if dealloc ; }")) != NULL) &&
|
||||
!result->tokAt(7)) {
|
||||
return result->tokAt(6);
|
||||
}
|
||||
|
||||
if ((result = Token::findmatch(tokens, "alloc ; }")) != NULL) {
|
||||
if ((result = Token::findsimplematch(tokens, "alloc ; }")) != NULL) {
|
||||
if (result->tokAt(3) == NULL)
|
||||
return result->tokAt(2);
|
||||
}
|
||||
|
@ -2151,7 +2151,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
|
|||
}
|
||||
|
||||
// If the variable is not allocated at all => no memory leak
|
||||
if (Token::findmatch(tok, "alloc") == 0) {
|
||||
if (Token::findsimplematch(tok, "alloc") == 0) {
|
||||
Tokenizer::deleteTokens(tok);
|
||||
return;
|
||||
}
|
||||
|
@ -2163,13 +2163,13 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
|
|||
}
|
||||
|
||||
// If the variable is not allocated at all => no memory leak
|
||||
if (Token::findmatch(tok, "alloc") == 0) {
|
||||
if (Token::findsimplematch(tok, "alloc") == 0) {
|
||||
Tokenizer::deleteTokens(tok);
|
||||
return;
|
||||
}
|
||||
|
||||
/** @todo handle "goto" */
|
||||
if (Token::findmatch(tok, "goto")) {
|
||||
if (Token::findsimplematch(tok, "goto")) {
|
||||
Tokenizer::deleteTokens(tok);
|
||||
return;
|
||||
}
|
||||
|
@ -2178,7 +2178,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
|
|||
memoryLeak(result, varname, alloctype);
|
||||
}
|
||||
|
||||
else if ((result = Token::findmatch(tok, "dealloc ; dealloc ;")) != NULL) {
|
||||
else if ((result = Token::findsimplematch(tok, "dealloc ; dealloc ;")) != NULL) {
|
||||
deallocDeallocError(result->tokAt(2), varname);
|
||||
}
|
||||
|
||||
|
|
|
@ -317,7 +317,7 @@ void CheckOther::cstyleCastError(const Token *tok)
|
|||
void CheckOther::checkFflushOnInputStream()
|
||||
{
|
||||
const Token *tok = _tokenizer->tokens();
|
||||
while (tok && ((tok = Token::findmatch(tok, "fflush ( stdin )")) != NULL)) {
|
||||
while (tok && ((tok = Token::findsimplematch(tok, "fflush ( stdin )")) != NULL)) {
|
||||
fflushOnInputStreamError(tok, tok->strAt(2));
|
||||
tok = tok->tokAt(4);
|
||||
}
|
||||
|
@ -603,12 +603,12 @@ void CheckOther::checkSwitchCaseFallThrough()
|
|||
if (loopnest.empty()) {
|
||||
justbreak = true;
|
||||
}
|
||||
tok2 = Token::findmatch(tok2, ";");
|
||||
tok2 = Token::findsimplematch(tok2, ";");
|
||||
} else if (Token::Match(tok2, "case|default")) {
|
||||
if (!justbreak && !firstcase) {
|
||||
switchCaseFallThrough(tok2);
|
||||
}
|
||||
tok2 = Token::findmatch(tok2, ":");
|
||||
tok2 = Token::findsimplematch(tok2, ":");
|
||||
justbreak = true;
|
||||
firstcase = false;
|
||||
} else if (tok2->str() == "{") {
|
||||
|
|
|
@ -262,7 +262,7 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
|
|||
Token::simpleMatch(tok4, "} }") &&
|
||||
Token::simpleMatch(tok4->tokAt(-2), "break ;")) {
|
||||
// Is there a assignment and then a break?
|
||||
const Token *t = Token::findmatch(tok3, ";");
|
||||
const Token *t = Token::findsimplematch(tok3, ";");
|
||||
if (t && t->tokAt(3) == tok4) {
|
||||
for (std::list<ExecutionPath *>::iterator it = checks.begin(); it != checks.end(); ++it) {
|
||||
if ((*it)->varId == tok3->next()->varId()) {
|
||||
|
|
|
@ -2115,7 +2115,7 @@ private:
|
|||
|
||||
// Is there an inner macro..
|
||||
{
|
||||
const Token *tok = Token::findmatch(tokens(), ")");
|
||||
const Token *tok = Token::findsimplematch(tokens(), ")");
|
||||
if (!Token::Match(tok, ") %var% ("))
|
||||
return params1;
|
||||
innerMacroName = tok->strAt(1);
|
||||
|
|
|
@ -721,6 +721,24 @@ const Token* Token::nextArgument() const
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
const Token *Token::findsimplematch(const Token *tok, const char pattern[])
|
||||
{
|
||||
for (; tok; tok = tok->next()) {
|
||||
if (Token::simpleMatch(tok, pattern))
|
||||
return tok;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Token *Token::findsimplematch(const Token *tok, const char pattern[], const Token *end)
|
||||
{
|
||||
for (; tok && tok != end; tok = tok->next()) {
|
||||
if (Token::simpleMatch(tok, pattern))
|
||||
return tok;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Token *Token::findmatch(const Token *tok, const char pattern[], unsigned int varId)
|
||||
{
|
||||
for (; tok; tok = tok->next()) {
|
||||
|
|
|
@ -227,6 +227,8 @@ public:
|
|||
}
|
||||
bool isStandardType() const;
|
||||
|
||||
static const Token *findsimplematch(const Token *tok, const char pattern[]);
|
||||
static const Token *findsimplematch(const Token *tok, const char pattern[], const Token *end);
|
||||
static const Token *findmatch(const Token *tok, const char pattern[], unsigned int varId = 0);
|
||||
static const Token *findmatch(const Token *tok, const char pattern[], const Token *end, unsigned int varId = 0);
|
||||
|
||||
|
|
|
@ -2640,7 +2640,7 @@ std::set<std::string> Tokenizer::simplifyTemplatesExpandSpecialized()
|
|||
expandedtemplates.insert(name);
|
||||
|
||||
// Rename template..
|
||||
Token::eraseTokens(tok2, Token::findmatch(tok2, "("));
|
||||
Token::eraseTokens(tok2, Token::findsimplematch(tok2, "("));
|
||||
tok2->str(name);
|
||||
|
||||
// delete the "template < >"
|
||||
|
@ -2650,7 +2650,7 @@ std::set<std::string> Tokenizer::simplifyTemplatesExpandSpecialized()
|
|||
|
||||
// Use this special template in the code..
|
||||
while (0 != (tok2 = const_cast<Token *>(Token::findmatch(tok2, pattern.c_str())))) {
|
||||
Token::eraseTokens(tok2, Token::findmatch(tok2, "("));
|
||||
Token::eraseTokens(tok2, Token::findsimplematch(tok2, "("));
|
||||
tok2->str(name);
|
||||
}
|
||||
}
|
||||
|
@ -2839,7 +2839,7 @@ static bool simplifyTemplatesInstantiateMatch(const Token *instance, const std::
|
|||
return false;
|
||||
|
||||
if (patternAfter) {
|
||||
const Token *tok = Token::findmatch(instance, ">");
|
||||
const Token *tok = Token::findsimplematch(instance, ">");
|
||||
if (!tok || !Token::Match(tok->next(), patternAfter))
|
||||
return false;
|
||||
}
|
||||
|
@ -6678,7 +6678,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
|||
// Stop if return or break is found ..
|
||||
if (tok3->str() == "break")
|
||||
break;
|
||||
if ((indentlevel3 > 1 || !Token::simpleMatch(Token::findmatch(tok3,";"), "; }")) && tok3->str() == "return")
|
||||
if ((indentlevel3 > 1 || !Token::simpleMatch(Token::findsimplematch(tok3,";"), "; }")) && tok3->str() == "return")
|
||||
ret3 = true;
|
||||
if (ret3 && tok3->str() == ";")
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue