Tokenizer: Code cleanups

This commit is contained in:
PKEuS 2011-12-08 17:42:26 +01:00 committed by Daniel Marjamäki
parent 149ff355e2
commit 1bef8d1247
9 changed files with 8 additions and 54 deletions

View File

@ -17,17 +17,15 @@
*/ */
#include "cppcheck.h" #include "cppcheck.h"
#include "preprocessor.h" // preprocessor. #include "preprocessor.h" // Preprocessor
#include "tokenize.h" // <- Tokenizer #include "tokenize.h" // Tokenizer
#include "check.h" #include "check.h"
#include "path.h" #include "path.h"
#include <algorithm> #include <algorithm>
#include <iostream>
#include <fstream> #include <fstream>
#include <stdexcept> #include <stdexcept>
#include <ctime>
#include "timer.h" #include "timer.h"
#ifdef HAVE_RULES #ifdef HAVE_RULES
@ -335,10 +333,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
return; return;
} }
Timer timer2("Tokenizer::fillFunctionList", _settings._showtime, &S_timerResults);
_tokenizer.fillFunctionList();
timer2.Stop();
// call all "runChecks" in all registered Check classes // call all "runChecks" in all registered Check classes
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
if (_settings.terminated()) if (_settings.terminated())
@ -357,10 +351,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
if (!result) if (!result)
return; return;
Timer timer4("Tokenizer::fillFunctionList", _settings._showtime, &S_timerResults);
_tokenizer.fillFunctionList();
timer4.Stop();
// call all "runSimplifiedChecks" in all registered Check classes // call all "runSimplifiedChecks" in all registered Check classes
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
if (_settings.terminated()) if (_settings.terminated())

View File

@ -2587,7 +2587,6 @@ void Tokenizer::labels()
if (Token::Match(tok, ") const| {")) { if (Token::Match(tok, ") const| {")) {
// Simplify labels in the executable scope.. // Simplify labels in the executable scope..
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
unsigned int indentroundbraces = 0;
while (NULL != (tok = tok->next())) { while (NULL != (tok = tok->next())) {
if (tok->str() == "{") if (tok->str() == "{")
++indentlevel; ++indentlevel;
@ -2595,27 +2594,21 @@ void Tokenizer::labels()
--indentlevel; --indentlevel;
if (!indentlevel) if (!indentlevel)
break; break;
} } else if (tok->str() == "(")
tok = tok->link();
if (tok->str() == "(") else if (tok->str() == "case") {
++indentroundbraces;
else if (tok->str() == ")") {
if (!indentroundbraces)
break;
--indentroundbraces;
}
if (!indentroundbraces && tok->str() == "case") {
while (NULL != (tok = tok->next())) { while (NULL != (tok = tok->next())) {
if (tok->str() == ":") if (tok->str() == ":")
break; break;
} }
if (!(tok->next()) || tok->next()->str() != ";") { if (tok && (!(tok->next()) || tok->next()->str() != ";")) {
tok->insertToken(";"); tok->insertToken(";");
tok = tok->next(); tok = tok->next();
} }
} }
// simplify label.. except for unhandled macro // simplify label.. except for unhandled macro
if (!indentroundbraces && Token::Match(tok, "[;{}] %var% :") if (Token::Match(tok, "[;{}] %var% :")
&& !Token::Match(tok->next(), "public|protected|private") && !Token::Match(tok->next(), "public|protected|private")
&& tok->strAt(3) != ";") { && tok->strAt(3) != ";") {
for (Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) { for (Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
@ -7004,7 +6997,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
if (Token::Match(tok3, ("%var% ( " + structname + " %varid% ,").c_str(), varid)) { if (Token::Match(tok3, ("%var% ( " + structname + " %varid% ,").c_str(), varid)) {
const char * const functionName[] = { const char * const functionName[] = {
"memcmp","memcpy","memmove","memset", "memcmp","memcpy","memmove","memset",
"strcmp","strcpy","strncpy","strdup" "strcmp","strcpy","strncmp","strncpy","strdup"
}; };
for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) { for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) {
if (tok3->str() == functionName[i]) { if (tok3->str() == functionName[i]) {
@ -8277,12 +8270,6 @@ const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const
return NULL; return NULL;
} }
void Tokenizer::fillFunctionList()
{
getSymbolDatabase();
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Deallocate lists.. // Deallocate lists..

View File

@ -27,7 +27,6 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <set> #include <set>
#include <iosfwd>
class Token; class Token;
class ErrorLogger; class ErrorLogger;
@ -181,9 +180,6 @@ public:
*/ */
const std::vector<std::string> *getFiles() const; const std::vector<std::string> *getFiles() const;
/** recreate symbol database */
void fillFunctionList();
/** /**
* Get function token by function name * Get function token by function name
* @todo better handling of overloaded functions * @todo better handling of overloaded functions

View File

@ -54,9 +54,6 @@ private:
// Assign variable ids // Assign variable ids
tokenizer.setVarId(); tokenizer.setVarId();
// Fill function list
tokenizer.fillFunctionList();
// Check auto variables // Check auto variables
checkAutoVariables.autoVariables(); checkAutoVariables.autoVariables();
checkAutoVariables.returnPointerToLocalArray(); checkAutoVariables.returnPointerToLocalArray();

View File

@ -54,9 +54,6 @@ private:
// Assign variable ids // Assign variable ids
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Fill function list
tokenizer.fillFunctionList();
// Check for buffer overruns.. // Check for buffer overruns..
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this); CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
checkBufferOverrun.bufferOverrun(); checkBufferOverrun.bufferOverrun();

View File

@ -135,8 +135,6 @@ private:
tokenizer.setVarId(); tokenizer.setVarId();
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
tokenizer.fillFunctionList();
// Check for memory leaks.. // Check for memory leaks..
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.checkReallocUsage(); checkMemoryLeak.checkReallocUsage();
@ -3789,8 +3787,6 @@ private:
tokenizer.setVarId(); tokenizer.setVarId();
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
tokenizer.fillFunctionList();
// Check for memory leaks.. // Check for memory leaks..
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this); CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.check(); checkMemoryLeak.check();

View File

@ -54,9 +54,6 @@ private:
// Assign variable ids // Assign variable ids
tokenizer.setVarId(); tokenizer.setVarId();
// Fill function list
tokenizer.fillFunctionList();
// Check for non reentrant functions.. // Check for non reentrant functions..
CheckNonReentrantFunctions checkNonReentrantFunctions(&tokenizer, &settings, this); CheckNonReentrantFunctions checkNonReentrantFunctions(&tokenizer, &settings, this);
checkNonReentrantFunctions.nonReentrantFunctions(); checkNonReentrantFunctions.nonReentrantFunctions();

View File

@ -86,9 +86,6 @@ private:
// Assign variable ids // Assign variable ids
tokenizer.setVarId(); tokenizer.setVarId();
// Fill function list
tokenizer.fillFunctionList();
// Check for obsolete functions.. // Check for obsolete functions..
CheckObsoleteFunctions checkObsoleteFunctions(&tokenizer, &settings, this); CheckObsoleteFunctions checkObsoleteFunctions(&tokenizer, &settings, this);
checkObsoleteFunctions.obsoleteFunctions(); checkObsoleteFunctions.obsoleteFunctions();

View File

@ -51,9 +51,6 @@ private:
// Assign variable ids // Assign variable ids
tokenizer.setVarId(); tokenizer.setVarId();
// Fill function list
tokenizer.fillFunctionList();
// Check for postfix operators.. // Check for postfix operators..
CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this); CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this);
checkPostfixOperator.postfixOperator(); checkPostfixOperator.postfixOperator();