Refactoring CheckClass::initializeVarList. Ticket #1811

This commit is contained in:
Robert Reif 2010-07-18 20:58:16 +02:00 committed by Daniel Marjamäki
parent e7690836fd
commit 7842658cb4
2 changed files with 7 additions and 7 deletions

View File

@ -226,8 +226,10 @@ void CheckClass::initVar(Var *varlist, const std::string &varname)
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *varlist, const std::string &classname, std::list<std::string> &callstack, bool isStruct) void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *varlist, std::list<std::string> &callstack)
{ {
const std::string &classname = tok1->next()->str();
bool isStruct = tok1->str() == "struct";
bool Assign = false; bool Assign = false;
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
@ -361,13 +363,13 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
if (ftok2) if (ftok2)
{ {
callstack.push_back(ftok->str()); callstack.push_back(ftok->str());
initializeVarList(tok1, ftok2, varlist, classname, callstack, isStruct); initializeVarList(tok1, ftok2, varlist, callstack);
callstack.pop_back(); callstack.pop_back();
} }
else // there is a called member function, but it is not defined where we can find it, so we assume it initializes everything else // there is a called member function, but it is not defined where we can find it, so we assume it initializes everything
{ {
// check if the function is part of this class.. // check if the function is part of this class..
const Token *tok = Token::findmatch(_tokenizer->tokens(), ((isStruct ? std::string("struct ") : std::string("class ")) + classname + " {|:").c_str()); const Token *tok = Token::findmatch(_tokenizer->tokens(), (tok1->str() + " " + classname + " {|:").c_str());
bool derived = false; bool derived = false;
while (tok && tok->str() != "{") while (tok && tok->str() != "{")
{ {
@ -761,7 +763,7 @@ void CheckClass::constructors()
continue; continue;
std::list<std::string> callstack; std::list<std::string> callstack;
initializeVarList(tok1, it->token, varlist, className, callstack, isStruct); initializeVarList(tok1, it->token, varlist, callstack);
// Check if any variables are uninitialized // Check if any variables are uninitialized
for (Var *var = varlist; var; var = var->next) for (Var *var = varlist; var; var = var->next)

View File

@ -150,11 +150,9 @@ private:
* @param tok1 pointer to class declaration * @param tok1 pointer to class declaration
* @param ftok pointer to the function that should be checked * @param ftok pointer to the function that should be checked
* @param varlist variable list (the "init" flag will be set in these variables) * @param varlist variable list (the "init" flag will be set in these variables)
* @param classname name of class
* @param callstack the function doesn't look into recursive function calls. * @param callstack the function doesn't look into recursive function calls.
* @param isStruct if this is a struct instead of a class
*/ */
void initializeVarList(const Token *tok1, const Token *ftok, Var *varlist, const std::string &classname, std::list<std::string> &callstack, bool isStruct); void initializeVarList(const Token *tok1, const Token *ftok, Var *varlist, std::list<std::string> &callstack);
/** @brief initialize a variable in the varlist */ /** @brief initialize a variable in the varlist */
void initVar(Var *varlist, const std::string &varname); void initVar(Var *varlist, const std::string &varname);