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); SpaceInfo *new_info = new SpaceInfo(this, tok1, *info);
// skip to start of function // skip to start of function
while (tok1->str() != "{") while (tok1 && tok1->str() != "{")
tok1 = tok1->next(); tok1 = tok1->next();
new_info->classStart = tok1; if (tok1)
new_info->classEnd = tok1->link(); {
new_info->classStart = tok1;
new_info->classEnd = tok1->link();
*info = new_info; *info = new_info;
// add space // add space
spaceInfoList.push_back(new_info); spaceInfoList.push_back(new_info);
*tok = tok1; *tok = tok1;
}
} }
void CheckClass::addIfFunction(SpaceInfo **info, const Token **tok) void CheckClass::addIfFunction(SpaceInfo **info, const Token **tok)
@ -459,6 +462,8 @@ void CheckClass::createSymbolDatabase()
{ {
// find the function implementation later // find the function implementation later
tok = end->next(); tok = end->next();
info->functionList.push_back(function);
} }
// inline function // inline function
@ -468,16 +473,14 @@ void CheckClass::createSymbolDatabase()
function.hasBody = true; function.hasBody = true;
function.arg = function.argDef; function.arg = function.argDef;
// skip over function body info->functionList.push_back(function);
tok = end->next();
while (tok && tok->str() != "{")
tok = tok->next();
if (!tok)
return;
tok = tok->link();
}
info->functionList.push_back(function); const Token *tok2 = funcStart;
addNewFunction(&info, &tok2);
tok = tok2;
}
} }
// nested class function? // nested class function?
@ -502,19 +505,7 @@ void CheckClass::createSymbolDatabase()
// not in SpaceInfo // not in SpaceInfo
else 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); addIfFunction(&info, &tok);
}
} }
std::list<SpaceInfo *>::iterator it; std::list<SpaceInfo *>::iterator it;
@ -1417,7 +1408,14 @@ void CheckClass::privateFunctions()
std::list<const Token *> FuncList; std::list<const Token *> FuncList;
/** @todo embedded class have access to private functions */ /** @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) for (func = info->functionList.begin(); func != info->functionList.end(); ++func)
{ {

View File

@ -490,6 +490,51 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); 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() void initvar_chained_assign()