From ddf34440b6f92dc8ce87ab41b2e9120f6123994b Mon Sep 17 00:00:00 2001 From: Philipp Kloke Date: Sat, 12 Apr 2014 23:26:13 +0200 Subject: [PATCH] Refactorization: Replaced several Token::findmatch calls by symboldatabase usage --- lib/checkbufferoverrun.cpp | 4 ++-- lib/checkother.cpp | 3 +-- lib/checkstl.cpp | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 23e0faee5..9ff4eab1c 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -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(); diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d58694b57..62ddb5e01 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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); } } diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 5cf42970c..6f434e441 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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);