From df6855c216e3332984294f18dc26674b4e2a110b Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sun, 2 Nov 2014 10:36:52 +0100 Subject: [PATCH] SymbolDatabase: reintroduce test, move symboldatabase cleanup code to SymbolDatabase destructor --- lib/symboldatabase.cpp | 10 ++++++++++ lib/symboldatabase.h | 1 + lib/tokenize.cpp | 7 ------- test/testsymboldatabase.cpp | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 230ed7c73..59d577ce2 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1185,6 +1185,16 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti } } +SymbolDatabase::~SymbolDatabase() +{ + // Clear scope, function, and variable pointers + for (const Token* tok = _tokenizer->list.front(); tok != _tokenizer->list.back(); tok = tok->next()) { + const_cast(tok)->scope(0); + const_cast(tok)->function(0); + const_cast(tok)->variable(0); + } +} + bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart) { if (tok->varId()) diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 079e809b2..d1f9eaa41 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -801,6 +801,7 @@ private: class CPPCHECKLIB SymbolDatabase { public: SymbolDatabase(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger); + ~SymbolDatabase(); /** @brief Information about all namespaces/classes/structrues */ std::list scopeList; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4b18645b5..93ee530b5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10081,13 +10081,6 @@ void Tokenizer::createSymbolDatabase() void Tokenizer::deleteSymbolDatabase() { - // Clear scope, function, and variable pointers - for (Token* tok = list.front(); tok != list.back(); tok = tok->next()) { - tok->scope(0); - tok->function(0); - tok->variable(0); - } - delete _symbolDatabase; _symbolDatabase = 0; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 39d926c00..08a52753a 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -223,6 +223,8 @@ private: TEST_CASE(isImplicitlyVirtual); TEST_CASE(isFunction); // UNKNOWN_MACRO(a,b) { .. } + + TEST_CASE(findFunction1); TEST_CASE(findFunction2); // mismatch: parameter passed by address => reference argument TEST_CASE(findFunction3);