diff --git a/src/check.h b/src/check.h index 47ec993f6..1d94e60ff 100644 --- a/src/check.h +++ b/src/check.h @@ -26,6 +26,10 @@ #include #include +/** + * @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()); } diff --git a/src/checkclass.cpp b/src/checkclass.cpp index 20100c4fc..6249e3898 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -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 &callstack) +void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *varlist, const char classname[], std::list &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; } diff --git a/src/checkclass.h b/src/checkclass.h index 7b9429385..02d56a0e0 100644 --- a/src/checkclass.h +++ b/src/checkclass.h @@ -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 &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 &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[]); diff --git a/src/checksecurity.h b/src/checksecurity.h index 000c4b0be..2b5bf83c4 100644 --- a/src/checksecurity.h +++ b/src/checksecurity.h @@ -24,6 +24,7 @@ #include "check.h" +/** @brief Experimental class for detecting input validation problems */ class CheckSecurity : public Check { public: diff --git a/src/checkstl.h b/src/checkstl.h index 7cde0e086..df7b36c7c 100644 --- a/src/checkstl.h +++ b/src/checkstl.h @@ -26,6 +26,7 @@ class Token; +/** @brief %Check STL usage */ class CheckStl : public Check { public: diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index c611eea2f..3b98a7121 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -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 ¯o) + PreprocessorMacro(const std::string ¯o) : _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 diff --git a/src/preprocessor.h b/src/preprocessor.h index c6c4dc750..122284e66 100644 --- a/src/preprocessor.h +++ b/src/preprocessor.h @@ -27,7 +27,7 @@ #include #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: