Fix symbol database argsMatch to skip all redundant type information (class, struct, union, enum) (#1472)

This commit is contained in:
IOBYTE 2018-11-09 09:54:17 -05:00 committed by amai2012
parent c07cb64f2f
commit e302e6e7a1
2 changed files with 100 additions and 23 deletions

View File

@ -1862,10 +1862,10 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
first->isLong() == second->isLong() && first->isLong() == second->isLong() &&
first->isUnsigned() == second->isUnsigned()) { first->isUnsigned() == second->isUnsigned()) {
// skip "struct" // skip optional type information
if (first->strAt(1) == "struct" || first->strAt(1) == "enum") if (Token::Match(first->next(), "struct|enum|union|class"))
first = first->next(); first = first->next();
if (second->strAt(1) == "struct" || second->strAt(1) == "enum") if (Token::Match(second->next(), "struct|enum|union|class"))
second = second->next(); second = second->next();
// skip const on type passed by value // skip const on type passed by value

View File

@ -3091,26 +3091,103 @@ private:
} }
void symboldatabase62() { void symboldatabase62() {
GET_SYMBOL_DB("struct A {\n" {
"public:\n" GET_SYMBOL_DB("struct A {\n"
" struct X { int a; };\n" "public:\n"
" void Foo(const std::vector<struct X> &includes);\n" " struct X { int a; };\n"
"};\n" " void Foo(const std::vector<struct X> &includes);\n"
"void A::Foo(const std::vector<struct A::X> &includes) {\n" "};\n"
" for (std::vector<struct A::X>::const_iterator it = includes.begin(); it != includes.end(); ++it) {\n" "void A::Foo(const std::vector<struct A::X> &includes) {\n"
" const struct A::X currentIncList = *it;\n" " for (std::vector<struct A::X>::const_iterator it = includes.begin(); it != includes.end(); ++it) {\n"
" }\n" " const struct A::X currentIncList = *it;\n"
"}"); " }\n"
ASSERT(db != nullptr); "}");
ASSERT(db && db->scopeList.size() == 5); ASSERT(db != nullptr);
if (db && db->scopeList.size() == 5) { ASSERT(db && db->scopeList.size() == 5);
const Scope *scope = db->findScopeByName("A"); if (db && db->scopeList.size() == 5) {
ASSERT(scope != nullptr); const Scope *scope = db->findScopeByName("A");
if (scope) { ASSERT(scope != nullptr);
const Function *function = findFunctionByName("Foo", scope); if (scope) {
ASSERT(function != nullptr); const Function *function = findFunctionByName("Foo", scope);
if (function) { ASSERT(function != nullptr);
ASSERT(function->hasBody()); if (function) {
ASSERT(function->hasBody());
}
}
}
}
{
GET_SYMBOL_DB("class A {\n"
"public:\n"
" class X { public: int a; };\n"
" void Foo(const std::vector<class X> &includes);\n"
"};\n"
"void A::Foo(const std::vector<class A::X> &includes) {\n"
" for (std::vector<class A::X>::const_iterator it = includes.begin(); it != includes.end(); ++it) {\n"
" const class A::X currentIncList = *it;\n"
" }\n"
"}");
ASSERT(db != nullptr);
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());
}
}
}
}
{
GET_SYMBOL_DB("struct A {\n"
"public:\n"
" union X { int a; float b; };\n"
" void Foo(const std::vector<union X> &includes);\n"
"};\n"
"void A::Foo(const std::vector<union A::X> &includes) {\n"
" for (std::vector<union A::X>::const_iterator it = includes.begin(); it != includes.end(); ++it) {\n"
" const union A::X currentIncList = *it;\n"
" }\n"
"}");
ASSERT(db != nullptr);
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());
}
}
}
}
{
GET_SYMBOL_DB("struct A {\n"
"public:\n"
" enum X { a, b };\n"
" void Foo(const std::vector<enum X> &includes);\n"
"};\n"
"void A::Foo(const std::vector<enum A::X> &includes) {\n"
" for (std::vector<enum A::X>::const_iterator it = includes.begin(); it != includes.end(); ++it) {\n"
" const enum A::X currentIncList = *it;\n"
" }\n"
"}");
ASSERT(db != nullptr);
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());
}
} }
} }
} }