refactoring: minor refactorings and added some doxygen comments

This commit is contained in:
Daniel Marjamäki 2009-07-08 17:14:34 +02:00
parent 91a8dbd7b9
commit bd68837866
7 changed files with 34 additions and 26 deletions

View File

@ -26,6 +26,10 @@
#include <list>
#include <iostream>
/**
* @brief Interface class that cppcheck uses to communicate with the checks.
* All checking classes must inherit from this class
*/
class Check
{
public:
@ -114,8 +118,8 @@ protected:
}
private:
// compare the names of Check classes
bool operator<(const Check *other)
/** compare the names of Check classes */
bool operator<(const Check *other) const
{
return (name() < other->name());
}

View File

@ -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..
struct VAR *varlist = NULL;
Var *varlist = NULL;
unsigned int indentlevel = 0;
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 (varname)
{
struct VAR *var = new VAR(varname, false, varlist);
Var *var = new Var(varname, false, varlist);
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)
{
@ -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;
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..
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;
break;
}
@ -219,7 +219,7 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, struct
// Clearing all variables..
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;
break;
}
@ -331,7 +331,7 @@ void CheckClass::constructors()
if (ErrorLogger::noConstructor(*_settings))
{
// If the class has member variables there should be an constructor
struct VAR *varlist = getVarList(tok1, false);
Var *varlist = getVarList(tok1, false);
if (varlist)
{
noConstructorError(tok1, classNameToken->str());
@ -339,7 +339,7 @@ void CheckClass::constructors()
// Delete the varlist..
while (varlist)
{
struct VAR *nextvar = varlist->next;
Var *nextvar = varlist->next;
delete varlist;
varlist = nextvar;
}
@ -365,7 +365,7 @@ void CheckClass::checkConstructors(const Token *tok1, const char funcname[])
// Check that all member variables are initialized..
bool withClasses = bool(_settings->_showAll && std::string(funcname) == "operator =");
struct VAR *varlist = getVarList(tok1, withClasses);
Var *varlist = getVarList(tok1, withClasses);
int indentlevel = 0;
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)
{
// 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)
continue;
@ -412,7 +412,7 @@ void CheckClass::checkConstructors(const Token *tok1, const char funcname[])
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;
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..
while (varlist)
{
struct VAR *nextvar = varlist->next;
Var *nextvar = varlist->next;
delete varlist;
varlist = nextvar;
}

View File

@ -76,9 +76,10 @@ public:
void virtualDestructor();
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->init = init;
@ -87,12 +88,12 @@ private:
const char *name;
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 initVar(struct VAR *varlist, const char varname[]);
struct VAR *getVarList(const Token *tok1, bool withClasses);
void initializeVarList(const Token *tok1, const Token *ftok, Var *varlist, const char classname[], std::list<std::string> &callstack);
void initVar(Var *varlist, const char varname[]);
Var *getVarList(const Token *tok1, bool withClasses);
// Check constructors for a specified class
void checkConstructors(const Token *tok1, const char funcname[]);

View File

@ -24,6 +24,7 @@
#include "check.h"
/** @brief Experimental class for detecting input validation problems */
class CheckSecurity : public Check
{
public:

View File

@ -26,6 +26,7 @@
class Token;
/** @brief %Check STL usage */
class CheckStl : public Check
{
public:

View File

@ -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:
Tokenizer tokenizer;
@ -969,7 +970,7 @@ private:
bool _nopar;
public:
Macro(const std::string &macro)
PreprocessorMacro(const std::string &macro)
: _macro(macro)
{
// 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"
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);
// No macro name => continue

View File

@ -27,7 +27,7 @@
#include <list>
#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
{
public: