Symbol database: add support for class inline functions with classes

This commit is contained in:
Daniel Marjamäki 2010-11-09 17:06:07 +01:00
parent 36b03bdd3e
commit 508c171945
2 changed files with 72 additions and 29 deletions

View File

@ -232,18 +232,21 @@ void CheckClass::addNewFunction(SpaceInfo **info, const Token **tok)
SpaceInfo *new_info = new SpaceInfo(this, tok1, *info);
// skip to start of function
while (tok1->str() != "{")
while (tok1 && tok1->str() != "{")
tok1 = tok1->next();
new_info->classStart = tok1;
new_info->classEnd = tok1->link();
if (tok1)
{
new_info->classStart = tok1;
new_info->classEnd = tok1->link();
*info = new_info;
*info = new_info;
// add space
spaceInfoList.push_back(new_info);
// add space
spaceInfoList.push_back(new_info);
*tok = tok1;
*tok = tok1;
}
}
void CheckClass::addIfFunction(SpaceInfo **info, const Token **tok)
@ -459,6 +462,8 @@ void CheckClass::createSymbolDatabase()
{
// find the function implementation later
tok = end->next();
info->functionList.push_back(function);
}
// inline function
@ -468,16 +473,14 @@ void CheckClass::createSymbolDatabase()
function.hasBody = true;
function.arg = function.argDef;
// skip over function body
tok = end->next();
while (tok && tok->str() != "{")
tok = tok->next();
if (!tok)
return;
tok = tok->link();
}
info->functionList.push_back(function);
info->functionList.push_back(function);
const Token *tok2 = funcStart;
addNewFunction(&info, &tok2);
tok = tok2;
}
}
// nested class function?
@ -502,19 +505,7 @@ void CheckClass::createSymbolDatabase()
// not in SpaceInfo
else
{
// found a "?" skip until the end of statement is found to avoid detecting
// false functions..
if (tok->str() == "?")
{
while (tok && !Token::Match(tok, "[;{}]"))
tok = tok->next();
if (!tok)
break;
}
addIfFunction(&info, &tok);
}
}
std::list<SpaceInfo *>::iterator it;
@ -1417,7 +1408,14 @@ void CheckClass::privateFunctions()
std::list<const Token *> FuncList;
/** @todo embedded class have access to private functions */
if (info->nestedList.empty())
int nested = 0;
std::list<SpaceInfo *>::const_iterator ni;
for (ni = info->nestedList.begin(); ni != info->nestedList.end(); ++ni)
{
if ((*ni)->type != SpaceInfo::Function)
nested++;
}
if (!nested)
{
for (func = info->functionList.begin(); func != info->functionList.end(); ++func)
{

View File

@ -490,6 +490,51 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("class Foo {\n"
" void func1()\n"
" {\n"
" struct Fred\n"
" {\n"
" int a;\n"
" Fred() { a = 0; }\n"
" };\n"
" }\n"
"\n"
" void func2()\n"
" {\n"
" struct Fred\n"
" {\n"
" int b;\n"
" Fred() { b = 0; }\n"
" };\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
check("class Foo {\n"
" void func1()\n"
" {\n"
" struct Fred\n"
" {\n"
" int a;\n"
" Fred() { }\n"
" };\n"
" }\n"
"\n"
" void func2()\n"
" {\n"
" struct Fred\n"
" {\n"
" int b;\n"
" Fred() { }\n"
" };\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable not initialized in the constructor 'Fred::a'\n"
"[test.cpp:16]: (warning) Member variable not initialized in the constructor 'Fred::b'\n", errout.str());
}
void initvar_chained_assign()