Fixed #5621 and slightly simplified symboldatabase code.

This commit is contained in:
PKEuS 2014-03-30 11:06:44 +02:00
parent 5fc89656c0
commit 345a80f4d5
2 changed files with 190 additions and 174 deletions

View File

@ -330,7 +330,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
}
// class function?
else if (tok->previous()->str() != "::" && isFunction(tok, scope, &funcStart, &argStart)) {
else if (isFunction(tok, scope, &funcStart, &argStart)) {
if (tok->previous()->str() != "::") {
Function function;
// save the function definition argument start '('
@ -451,11 +452,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
function.arg = function.argDef;
// out of line function
if (Token::Match(end, ") const| ;")) {
if (Token::simpleMatch(end, ") ;")) {
// find the function implementation later
tok = end->next();
if (tok->str() != ";")
tok = tok->next();
scope->functionList.push_back(function);
}
@ -484,10 +483,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
scope->functionList.push_back(function);
}
// unknown macro (#5197)
// 'const' or unknown macro (#5197)
else if (Token::Match(end, ") %any% ;")) {
tok = end->tokAt(3);
tok = end->tokAt(2);
scope->functionList.push_back(function);
}
@ -519,7 +517,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
}
// nested class or friend function?
else if (tok->previous()->str() == "::" && isFunction(tok, scope, &funcStart, &argStart)) {
else {
/** @todo check entire qualification for match */
Scope * nested = scope->findInNestedListRecursive(tok->strAt(-2));
@ -529,6 +527,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
/** @todo handle friend functions */
}
}
}
// friend class declaration?
else if (Token::Match(tok, "friend class| ::| %any% ;|::")) {

View File

@ -140,6 +140,7 @@ private:
TEST_CASE(testConstructors);
TEST_CASE(functionDeclarationTemplate);
TEST_CASE(functionDeclarations);
TEST_CASE(memberFunctionOfUnknownClassMacro);
TEST_CASE(classWithFriend);
@ -955,6 +956,22 @@ private:
}
}
void memberFunctionOfUnknownClassMacro() {
GET_SYMBOL_DB("class ScVbaFormatCondition { OUString getServiceImplName() SAL_OVERRIDE; };\n"
"void ScVbaValidation::getFormula1() {\n"
" sal_uInt16 nFlags = 0;\n"
" if (pDocSh && !getCellRangesForAddress(nFlags)) ;\n"
"}");
ASSERT(db && errout.str() == "");
if (db) {
const Scope *scope = db->findScopeByName("getFormula1");
ASSERT(scope != nullptr);
ASSERT(scope && scope->nestedIn == &db->scopeList.front());
}
}
void classWithFriend() {
GET_SYMBOL_DB("class Foo {}; class Bar1 { friend class Foo; }; class Bar2 { friend Foo; };")
// 3 scopes: Global, 3 classes