From e302e6e7a1f37f256f8bc6ff8cd28969294342db Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Fri, 9 Nov 2018 09:54:17 -0500 Subject: [PATCH] Fix symbol database argsMatch to skip all redundant type information (class, struct, union, enum) (#1472) --- lib/symboldatabase.cpp | 6 +- test/testsymboldatabase.cpp | 117 ++++++++++++++++++++++++++++++------ 2 files changed, 100 insertions(+), 23 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 6b64cc111..28763ad40 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1862,10 +1862,10 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se first->isLong() == second->isLong() && first->isUnsigned() == second->isUnsigned()) { - // skip "struct" - if (first->strAt(1) == "struct" || first->strAt(1) == "enum") + // skip optional type information + if (Token::Match(first->next(), "struct|enum|union|class")) first = first->next(); - if (second->strAt(1) == "struct" || second->strAt(1) == "enum") + if (Token::Match(second->next(), "struct|enum|union|class")) second = second->next(); // skip const on type passed by value diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 7e9352afc..663670794 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3091,26 +3091,103 @@ private: } void symboldatabase62() { - GET_SYMBOL_DB("struct A {\n" - "public:\n" - " struct X { int a; };\n" - " void Foo(const std::vector &includes);\n" - "};\n" - "void A::Foo(const std::vector &includes) {\n" - " for (std::vector::const_iterator it = includes.begin(); it != includes.end(); ++it) {\n" - " const struct 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" + " struct X { int a; };\n" + " void Foo(const std::vector &includes);\n" + "};\n" + "void A::Foo(const std::vector &includes) {\n" + " for (std::vector::const_iterator it = includes.begin(); it != includes.end(); ++it) {\n" + " const struct 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("class A {\n" + "public:\n" + " class X { public: int a; };\n" + " void Foo(const std::vector &includes);\n" + "};\n" + "void A::Foo(const std::vector &includes) {\n" + " for (std::vector::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 &includes);\n" + "};\n" + "void A::Foo(const std::vector &includes) {\n" + " for (std::vector::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 &includes);\n" + "};\n" + "void A::Foo(const std::vector &includes) {\n" + " for (std::vector::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()); + } } } }