Tokenizer: Code cleanups
This commit is contained in:
parent
149ff355e2
commit
1bef8d1247
|
@ -17,17 +17,15 @@
|
|||
*/
|
||||
#include "cppcheck.h"
|
||||
|
||||
#include "preprocessor.h" // preprocessor.
|
||||
#include "tokenize.h" // <- Tokenizer
|
||||
#include "preprocessor.h" // Preprocessor
|
||||
#include "tokenize.h" // Tokenizer
|
||||
|
||||
#include "check.h"
|
||||
#include "path.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <ctime>
|
||||
#include "timer.h"
|
||||
|
||||
#ifdef HAVE_RULES
|
||||
|
@ -335,10 +333,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
return;
|
||||
}
|
||||
|
||||
Timer timer2("Tokenizer::fillFunctionList", _settings._showtime, &S_timerResults);
|
||||
_tokenizer.fillFunctionList();
|
||||
timer2.Stop();
|
||||
|
||||
// call all "runChecks" in all registered Check classes
|
||||
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
|
||||
if (_settings.terminated())
|
||||
|
@ -357,10 +351,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
if (!result)
|
||||
return;
|
||||
|
||||
Timer timer4("Tokenizer::fillFunctionList", _settings._showtime, &S_timerResults);
|
||||
_tokenizer.fillFunctionList();
|
||||
timer4.Stop();
|
||||
|
||||
// call all "runSimplifiedChecks" in all registered Check classes
|
||||
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
|
||||
if (_settings.terminated())
|
||||
|
|
|
@ -2587,7 +2587,6 @@ void Tokenizer::labels()
|
|||
if (Token::Match(tok, ") const| {")) {
|
||||
// Simplify labels in the executable scope..
|
||||
unsigned int indentlevel = 0;
|
||||
unsigned int indentroundbraces = 0;
|
||||
while (NULL != (tok = tok->next())) {
|
||||
if (tok->str() == "{")
|
||||
++indentlevel;
|
||||
|
@ -2595,27 +2594,21 @@ void Tokenizer::labels()
|
|||
--indentlevel;
|
||||
if (!indentlevel)
|
||||
break;
|
||||
}
|
||||
} else if (tok->str() == "(")
|
||||
tok = tok->link();
|
||||
|
||||
if (tok->str() == "(")
|
||||
++indentroundbraces;
|
||||
else if (tok->str() == ")") {
|
||||
if (!indentroundbraces)
|
||||
break;
|
||||
--indentroundbraces;
|
||||
}
|
||||
if (!indentroundbraces && tok->str() == "case") {
|
||||
else if (tok->str() == "case") {
|
||||
while (NULL != (tok = tok->next())) {
|
||||
if (tok->str() == ":")
|
||||
break;
|
||||
}
|
||||
if (!(tok->next()) || tok->next()->str() != ";") {
|
||||
if (tok && (!(tok->next()) || tok->next()->str() != ";")) {
|
||||
tok->insertToken(";");
|
||||
tok = tok->next();
|
||||
}
|
||||
}
|
||||
// simplify label.. except for unhandled macro
|
||||
if (!indentroundbraces && Token::Match(tok, "[;{}] %var% :")
|
||||
if (Token::Match(tok, "[;{}] %var% :")
|
||||
&& !Token::Match(tok->next(), "public|protected|private")
|
||||
&& tok->strAt(3) != ";") {
|
||||
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)) {
|
||||
const char * const functionName[] = {
|
||||
"memcmp","memcpy","memmove","memset",
|
||||
"strcmp","strcpy","strncpy","strdup"
|
||||
"strcmp","strcpy","strncmp","strncpy","strdup"
|
||||
};
|
||||
for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) {
|
||||
if (tok3->str() == functionName[i]) {
|
||||
|
@ -8277,12 +8270,6 @@ const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void Tokenizer::fillFunctionList()
|
||||
{
|
||||
getSymbolDatabase();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Deallocate lists..
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <list>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <iosfwd>
|
||||
|
||||
class Token;
|
||||
class ErrorLogger;
|
||||
|
@ -181,9 +180,6 @@ public:
|
|||
*/
|
||||
const std::vector<std::string> *getFiles() const;
|
||||
|
||||
/** recreate symbol database */
|
||||
void fillFunctionList();
|
||||
|
||||
/**
|
||||
* Get function token by function name
|
||||
* @todo better handling of overloaded functions
|
||||
|
|
|
@ -54,9 +54,6 @@ private:
|
|||
// Assign variable ids
|
||||
tokenizer.setVarId();
|
||||
|
||||
// Fill function list
|
||||
tokenizer.fillFunctionList();
|
||||
|
||||
// Check auto variables
|
||||
checkAutoVariables.autoVariables();
|
||||
checkAutoVariables.returnPointerToLocalArray();
|
||||
|
|
|
@ -54,9 +54,6 @@ private:
|
|||
// Assign variable ids
|
||||
tokenizer.simplifyTokenList();
|
||||
|
||||
// Fill function list
|
||||
tokenizer.fillFunctionList();
|
||||
|
||||
// Check for buffer overruns..
|
||||
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
|
||||
checkBufferOverrun.bufferOverrun();
|
||||
|
|
|
@ -135,8 +135,6 @@ private:
|
|||
tokenizer.setVarId();
|
||||
tokenizer.simplifyTokenList();
|
||||
|
||||
tokenizer.fillFunctionList();
|
||||
|
||||
// Check for memory leaks..
|
||||
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
|
||||
checkMemoryLeak.checkReallocUsage();
|
||||
|
@ -3789,8 +3787,6 @@ private:
|
|||
tokenizer.setVarId();
|
||||
tokenizer.simplifyTokenList();
|
||||
|
||||
tokenizer.fillFunctionList();
|
||||
|
||||
// Check for memory leaks..
|
||||
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
|
||||
checkMemoryLeak.check();
|
||||
|
|
|
@ -54,9 +54,6 @@ private:
|
|||
// Assign variable ids
|
||||
tokenizer.setVarId();
|
||||
|
||||
// Fill function list
|
||||
tokenizer.fillFunctionList();
|
||||
|
||||
// Check for non reentrant functions..
|
||||
CheckNonReentrantFunctions checkNonReentrantFunctions(&tokenizer, &settings, this);
|
||||
checkNonReentrantFunctions.nonReentrantFunctions();
|
||||
|
|
|
@ -86,9 +86,6 @@ private:
|
|||
// Assign variable ids
|
||||
tokenizer.setVarId();
|
||||
|
||||
// Fill function list
|
||||
tokenizer.fillFunctionList();
|
||||
|
||||
// Check for obsolete functions..
|
||||
CheckObsoleteFunctions checkObsoleteFunctions(&tokenizer, &settings, this);
|
||||
checkObsoleteFunctions.obsoleteFunctions();
|
||||
|
|
|
@ -51,9 +51,6 @@ private:
|
|||
// Assign variable ids
|
||||
tokenizer.setVarId();
|
||||
|
||||
// Fill function list
|
||||
tokenizer.fillFunctionList();
|
||||
|
||||
// Check for postfix operators..
|
||||
CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this);
|
||||
checkPostfixOperator.postfixOperator();
|
||||
|
|
Loading…
Reference in New Issue