refactoring: minor refactorings and added some doxygen comments
This commit is contained in:
parent
91a8dbd7b9
commit
bd68837866
|
@ -26,6 +26,10 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Interface class that cppcheck uses to communicate with the checks.
|
||||||
|
* All checking classes must inherit from this class
|
||||||
|
*/
|
||||||
class Check
|
class Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -114,8 +118,8 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// compare the names of Check classes
|
/** compare the names of Check classes */
|
||||||
bool operator<(const Check *other)
|
bool operator<(const Check *other) const
|
||||||
{
|
{
|
||||||
return (name() < other->name());
|
return (name() < other->name());
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,10 +41,10 @@ CheckClass instance;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
struct CheckClass::VAR *CheckClass::getVarList(const Token *tok1, bool withClasses)
|
CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses)
|
||||||
{
|
{
|
||||||
// Get variable list..
|
// Get variable list..
|
||||||
struct VAR *varlist = NULL;
|
Var *varlist = NULL;
|
||||||
unsigned int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
for (const Token *tok = tok1; tok; tok = tok->next())
|
for (const Token *tok = tok1; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
|
@ -127,7 +127,7 @@ struct CheckClass::VAR *CheckClass::getVarList(const Token *tok1, bool withClass
|
||||||
// If the varname was set in one of the two if-block above, create a entry for this variable..
|
// If the varname was set in one of the two if-block above, create a entry for this variable..
|
||||||
if (varname)
|
if (varname)
|
||||||
{
|
{
|
||||||
struct VAR *var = new VAR(varname, false, varlist);
|
Var *var = new Var(varname, false, varlist);
|
||||||
varlist = var;
|
varlist = var;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,9 +136,9 @@ struct CheckClass::VAR *CheckClass::getVarList(const Token *tok1, bool withClass
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void CheckClass::initVar(struct VAR *varlist, const char varname[])
|
void CheckClass::initVar(Var *varlist, const char varname[])
|
||||||
{
|
{
|
||||||
for (struct VAR *var = varlist; var; var = var->next)
|
for (Var *var = varlist; var; var = var->next)
|
||||||
{
|
{
|
||||||
if (strcmp(var->name, varname) == 0)
|
if (strcmp(var->name, varname) == 0)
|
||||||
{
|
{
|
||||||
|
@ -149,7 +149,7 @@ void CheckClass::initVar(struct VAR *varlist, const char varname[])
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, struct VAR *varlist, const char classname[], std::list<std::string> &callstack)
|
void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *varlist, const char classname[], std::list<std::string> &callstack)
|
||||||
{
|
{
|
||||||
bool Assign = false;
|
bool Assign = false;
|
||||||
unsigned int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
|
@ -201,7 +201,7 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, struct
|
||||||
// Using the operator= function to initialize all variables..
|
// Using the operator= function to initialize all variables..
|
||||||
if (Token::simpleMatch(ftok->next(), "* this = "))
|
if (Token::simpleMatch(ftok->next(), "* this = "))
|
||||||
{
|
{
|
||||||
for (struct VAR *var = varlist; var; var = var->next)
|
for (Var *var = varlist; var; var = var->next)
|
||||||
var->init = true;
|
var->init = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, struct
|
||||||
// Clearing all variables..
|
// Clearing all variables..
|
||||||
if (Token::simpleMatch(ftok, "memset ( this ,"))
|
if (Token::simpleMatch(ftok, "memset ( this ,"))
|
||||||
{
|
{
|
||||||
for (struct VAR *var = varlist; var; var = var->next)
|
for (Var *var = varlist; var; var = var->next)
|
||||||
var->init = true;
|
var->init = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ void CheckClass::constructors()
|
||||||
if (ErrorLogger::noConstructor(*_settings))
|
if (ErrorLogger::noConstructor(*_settings))
|
||||||
{
|
{
|
||||||
// If the class has member variables there should be an constructor
|
// If the class has member variables there should be an constructor
|
||||||
struct VAR *varlist = getVarList(tok1, false);
|
Var *varlist = getVarList(tok1, false);
|
||||||
if (varlist)
|
if (varlist)
|
||||||
{
|
{
|
||||||
noConstructorError(tok1, classNameToken->str());
|
noConstructorError(tok1, classNameToken->str());
|
||||||
|
@ -339,7 +339,7 @@ void CheckClass::constructors()
|
||||||
// Delete the varlist..
|
// Delete the varlist..
|
||||||
while (varlist)
|
while (varlist)
|
||||||
{
|
{
|
||||||
struct VAR *nextvar = varlist->next;
|
Var *nextvar = varlist->next;
|
||||||
delete varlist;
|
delete varlist;
|
||||||
varlist = nextvar;
|
varlist = nextvar;
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ void CheckClass::checkConstructors(const Token *tok1, const char funcname[])
|
||||||
|
|
||||||
// Check that all member variables are initialized..
|
// Check that all member variables are initialized..
|
||||||
bool withClasses = bool(_settings->_showAll && std::string(funcname) == "operator =");
|
bool withClasses = bool(_settings->_showAll && std::string(funcname) == "operator =");
|
||||||
struct VAR *varlist = getVarList(tok1, withClasses);
|
Var *varlist = getVarList(tok1, withClasses);
|
||||||
|
|
||||||
int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
const Token *constructor_token = Tokenizer::findClassFunction(tok1, className, funcname, indentlevel);
|
const Token *constructor_token = Tokenizer::findClassFunction(tok1, className, funcname, indentlevel);
|
||||||
|
@ -374,7 +374,7 @@ void CheckClass::checkConstructors(const Token *tok1, const char funcname[])
|
||||||
while (constructor_token)
|
while (constructor_token)
|
||||||
{
|
{
|
||||||
// Check if any variables are uninitialized
|
// Check if any variables are uninitialized
|
||||||
for (struct VAR *var = varlist; var; var = var->next)
|
for (Var *var = varlist; var; var = var->next)
|
||||||
{
|
{
|
||||||
if (var->init)
|
if (var->init)
|
||||||
continue;
|
continue;
|
||||||
|
@ -412,7 +412,7 @@ void CheckClass::checkConstructors(const Token *tok1, const char funcname[])
|
||||||
uninitVarError(constructor_token, className, var->name);
|
uninitVarError(constructor_token, className, var->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (struct VAR *var = varlist; var; var = var->next)
|
for (Var *var = varlist; var; var = var->next)
|
||||||
var->init = false;
|
var->init = false;
|
||||||
|
|
||||||
constructor_token = Tokenizer::findClassFunction(constructor_token->next(), className, funcname, indentlevel);
|
constructor_token = Tokenizer::findClassFunction(constructor_token->next(), className, funcname, indentlevel);
|
||||||
|
@ -423,7 +423,7 @@ void CheckClass::checkConstructors(const Token *tok1, const char funcname[])
|
||||||
// Delete the varlist..
|
// Delete the varlist..
|
||||||
while (varlist)
|
while (varlist)
|
||||||
{
|
{
|
||||||
struct VAR *nextvar = varlist->next;
|
Var *nextvar = varlist->next;
|
||||||
delete varlist;
|
delete varlist;
|
||||||
varlist = nextvar;
|
varlist = nextvar;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,9 +76,10 @@ public:
|
||||||
void virtualDestructor();
|
void virtualDestructor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct VAR
|
class Var
|
||||||
{
|
{
|
||||||
VAR(const char *name = 0, bool init = false, struct VAR *next = 0)
|
public:
|
||||||
|
Var(const char *name = 0, bool init = false, Var *next = 0)
|
||||||
{
|
{
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->init = init;
|
this->init = init;
|
||||||
|
@ -87,12 +88,12 @@ private:
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
bool init;
|
bool init;
|
||||||
struct VAR *next;
|
Var *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
void initializeVarList(const Token *tok1, const Token *ftok, struct VAR *varlist, const char classname[], std::list<std::string> &callstack);
|
void initializeVarList(const Token *tok1, const Token *ftok, Var *varlist, const char classname[], std::list<std::string> &callstack);
|
||||||
void initVar(struct VAR *varlist, const char varname[]);
|
void initVar(Var *varlist, const char varname[]);
|
||||||
struct VAR *getVarList(const Token *tok1, bool withClasses);
|
Var *getVarList(const Token *tok1, bool withClasses);
|
||||||
|
|
||||||
// Check constructors for a specified class
|
// Check constructors for a specified class
|
||||||
void checkConstructors(const Token *tok1, const char funcname[]);
|
void checkConstructors(const Token *tok1, const char funcname[]);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
/** @brief Experimental class for detecting input validation problems */
|
||||||
class CheckSecurity : public Check
|
class CheckSecurity : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
class Token;
|
class Token;
|
||||||
|
|
||||||
|
/** @brief %Check STL usage */
|
||||||
class CheckStl : public Check
|
class CheckStl : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -956,7 +956,8 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Macro
|
/** @brief Class that the preprocessor uses when it expands macros. This class represents a preprocessor macro */
|
||||||
|
class PreprocessorMacro
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Tokenizer tokenizer;
|
Tokenizer tokenizer;
|
||||||
|
@ -969,7 +970,7 @@ private:
|
||||||
bool _nopar;
|
bool _nopar;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Macro(const std::string ¯o)
|
PreprocessorMacro(const std::string ¯o)
|
||||||
: _macro(macro)
|
: _macro(macro)
|
||||||
{
|
{
|
||||||
// Tokenize the macro to make it easier to handle
|
// Tokenize the macro to make it easier to handle
|
||||||
|
@ -1183,7 +1184,7 @@ std::string Preprocessor::expandMacros(std::string code, const std::string &file
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the whole macro into a separate variable "macro" and then erase it from "code"
|
// Extract the whole macro into a separate variable "macro" and then erase it from "code"
|
||||||
const Macro macro(code.substr(defpos + 8, endpos - defpos - 7));
|
const PreprocessorMacro macro(code.substr(defpos + 8, endpos - defpos - 7));
|
||||||
code.erase(defpos, endpos - defpos);
|
code.erase(defpos, endpos - defpos);
|
||||||
|
|
||||||
// No macro name => continue
|
// No macro name => continue
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "errorlogger.h"
|
#include "errorlogger.h"
|
||||||
|
|
||||||
|
/** @brief The cppcheck preprocessor. It has special functionality for extracting the various ifdef configurations that exist in a source file. */
|
||||||
class Preprocessor
|
class Preprocessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue