Refactorization: Replaced several Token::findmatch calls by symboldatabase usage

This commit is contained in:
Philipp Kloke 2014-04-12 23:26:13 +02:00
parent 776ad32a0b
commit ddf34440b6
3 changed files with 6 additions and 7 deletions

View File

@ -1537,8 +1537,8 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
var = tok->next()->variable();
nextTok = 8;
} else if (Token::Match(tok, "[;{}] %var% = %str% ;") &&
tok->next()->varId() > 0 &&
nullptr != Token::findmatch(_tokenizer->tokens(), "[;{}] const| %type% * %varid% ;", tok->next()->varId())) {
tok->next()->variable() &&
tok->next()->variable()->isPointer()) {
size = 1 + int(tok->tokAt(3)->strValue().size());
type = "char";
var = tok->next()->variable();

View File

@ -493,8 +493,7 @@ void CheckOther::warningOldStylePointerCast()
continue;
// Is "type" a class?
const std::string pattern("class|struct " + tok->strAt(1));
if (Token::findmatch(_tokenizer->tokens(), pattern.c_str(), tok))
if (_tokenizer->getSymbolDatabase()->isClassOrStruct(tok->strAt(1)))
cstyleCastError(tok);
}
}

View File

@ -533,8 +533,8 @@ void CheckStl::erase()
}
else if (i->type == Scope::eWhile && Token::Match(tok, "while ( %var% !=")) {
const unsigned int varid = tok->tokAt(2)->varId();
if (varid > 0 && Token::findmatch(_tokenizer->tokens(), "> :: iterator %varid%", varid))
const Variable* var = tok->tokAt(2)->variable();
if (var && Token::simpleMatch(var->typeEndToken()->tokAt(-2), "> :: iterator"))
EraseCheckLoop::checkScope(this, tok->tokAt(2));
}
}
@ -1168,7 +1168,7 @@ void CheckStl::string_c_str()
string_c_strError(tok);
} else if (Token::Match(tok, "[;{}] %var% = %var% (") &&
Token::Match(tok->linkAt(4), ") . c_str|data ( ) ;") &&
Token::findmatch(_tokenizer->tokens(), ("std :: string|wstring " + tok->strAt(3) + " (").c_str())) {
tok->tokAt(3)->function() && Token::Match(tok->tokAt(3)->function()->retDef, "std :: string|wstring %var%")) {
const Variable* var = tok->next()->variable();
if (var && var->isPointer())
string_c_strError(tok);