Fix symbol database argsMatch function and its usage so qualified types are handled properly. (#1470)

* Fix symbol database argsMatch function and its usage so qualified types are handled properly.

* Remove assert.
This commit is contained in:
IOBYTE 2018-11-09 00:11:48 -05:00 committed by Daniel Marjamäki
parent 36e663e250
commit 67fe99fcd9
2 changed files with 28 additions and 29 deletions

View File

@ -593,7 +593,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
else if (declEnd && declEnd->str() == ";") { else if (declEnd && declEnd->str() == ";") {
bool newFunc = true; // Is this function already in the database? bool newFunc = true; // Is this function already in the database?
for (std::multimap<std::string, const Function *>::const_iterator i = scope->functionMap.find(tok->str()); i != scope->functionMap.end() && i->first == tok->str(); ++i) { for (std::multimap<std::string, const Function *>::const_iterator i = scope->functionMap.find(tok->str()); i != scope->functionMap.end() && i->first == tok->str(); ++i) {
if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), emptyString, 0)) { if (Function::argsMatch(scope, i->second->argDef, argStart, emptyString, 0)) {
newFunc = false; newFunc = false;
break; break;
} }
@ -1856,24 +1856,26 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
if (!isCPP) // C does not support overloads if (!isCPP) // C does not support overloads
return true; return true;
// skip "struct"
if (first->str() == "struct" || first->str() == "enum")
first = first->next();
if (second->str() == "struct" || second->str() == "enum")
second = second->next();
// skip const on type passed by value
if (Token::Match(first, "const %type% %name%|,|)"))
first = first->next();
if (Token::Match(second, "const %type% %name%|,|)"))
second = second->next();
unsigned int arg_path_length = path_length; unsigned int arg_path_length = path_length;
while (first->str() == second->str() && while (first->str() == second->str() &&
first->isLong() == second->isLong() && first->isLong() == second->isLong() &&
first->isUnsigned() == second->isUnsigned()) { first->isUnsigned() == second->isUnsigned()) {
// skip "struct"
if (first->strAt(1) == "struct" || first->strAt(1) == "enum")
first = first->next();
if (second->strAt(1) == "struct" || second->strAt(1) == "enum")
second = second->next();
// skip const on type passed by value
if (Token::Match(first->next(), "const %type% %name%|,|)") &&
!Token::Match(first->next(), "const %type% %name%| ["))
first = first->next();
if (Token::Match(second->next(), "const %type% %name%|,|)") &&
!Token::Match(second->next(), "const %type% %name%| ["))
second = second->next();
// at end of argument list // at end of argument list
if (first->str() == ")") { if (first->str() == ")") {
return true; return true;
@ -2028,20 +2030,6 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
// reset path length // reset path length
if (first->str() == "," || second->str() == ",") if (first->str() == "," || second->str() == ",")
arg_path_length = path_length; arg_path_length = path_length;
// skip "struct"
if (first->str() == "struct" || first->str() == "enum")
first = first->next();
if (second->str() == "struct" || second->str() == "enum")
second = second->next();
// skip const on type passed by value
if (Token::Match(first, "const %type% %name%|,|)") &&
!Token::Match(first, "const %type% %name%| ["))
first = first->next();
if (Token::Match(second, "const %type% %name%|,|)") &&
!Token::Match(second, "const %type% %name%| ["))
second = second->next();
} }
return false; return false;
@ -2063,7 +2051,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
const Function *f = i->second; const Function *f = i->second;
if (f->hasBody()) if (f->hasBody())
continue; continue;
if (Function::argsMatch(scope, f->argDef->next(), argStart->next(), emptyString, 0)) { if (Function::argsMatch(scope, f->argDef, argStart, emptyString, 0)) {
function = const_cast<Function *>(i->second); function = const_cast<Function *>(i->second);
break; break;
} }
@ -4734,7 +4722,7 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n
for (std::multimap<std::string, const Function *>::const_iterator it = ns->functionMap.find(func->str()); for (std::multimap<std::string, const Function *>::const_iterator it = ns->functionMap.find(func->str());
it != ns->functionMap.end() && it->first == func->str(); ++it) { it != ns->functionMap.end() && it->first == func->str(); ++it) {
if (Function::argsMatch(ns, it->second->argDef->next(), func->tokAt(2), path, path_length) && if (Function::argsMatch(ns, it->second->argDef, func->next(), path, path_length) &&
it->second->isDestructor() == destructor) { it->second->isDestructor() == destructor) {
function = it->second; function = it->second;
break; break;

View File

@ -3103,6 +3103,17 @@ private:
"}"); "}");
ASSERT(db != nullptr); ASSERT(db != nullptr);
ASSERT(db && db->scopeList.size() == 5); ASSERT(db && db->scopeList.size() == 5);
if (db && db->scopeList.size() == 5) {
const Scope *scope = db->findScopeByName("A");
ASSERT(scope != nullptr);
if (scope) {
const Function *function = findFunctionByName("Foo", scope);
ASSERT(function != nullptr);
if (function) {
ASSERT(function->hasBody());
}
}
}
} }
void symboldatabase63() { void symboldatabase63() {