diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 3d8fdf409..3b111bb7a 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -43,30 +43,18 @@ CheckClass instance; CheckClass::CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) : Check(tokenizer, settings, errorLogger), - symbolDatabase(NULL), ownSymbolDatabase(false) + symbolDatabase(NULL) { } -CheckClass::~CheckClass() -{ - if (ownSymbolDatabase) - delete symbolDatabase; -} - void CheckClass::createSymbolDatabase() { // Multiple calls => bail out if (symbolDatabase) return; - if (_tokenizer->_symbolDatabase) - symbolDatabase = _tokenizer->_symbolDatabase; - else - { - symbolDatabase = new SymbolDatabase(_tokenizer, _settings, _errorLogger); - ownSymbolDatabase = true; - } + symbolDatabase = _tokenizer->getSymbolDatabase(); } //--------------------------------------------------------------------------- diff --git a/lib/checkclass.h b/lib/checkclass.h index 39cd9e7a6..06178893d 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -36,14 +36,12 @@ class CheckClass : public Check { public: /** @brief This constructor is used when registering the CheckClass */ - CheckClass() : Check(), symbolDatabase(NULL), ownSymbolDatabase(false) + CheckClass() : Check(), symbolDatabase(NULL) { } /** @brief This constructor is used when running checks. */ CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger); - ~CheckClass(); - /** @brief Run checks on the normal token list */ void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { @@ -113,7 +111,6 @@ private: void createSymbolDatabase(); SymbolDatabase *symbolDatabase; - bool ownSymbolDatabase; // Reporting errors.. void noConstructorError(const Token *tok, const std::string &classname, bool isStruct); diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 2f8ae1578..96b60bb3d 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2575,14 +2575,7 @@ void CheckMemoryLeakInFunction::check() void CheckMemoryLeakInClass::check() { - SymbolDatabase * symbolDatabase = _tokenizer->_symbolDatabase; - bool ownSymbolDatabase = false; - - if (symbolDatabase == NULL) - { - symbolDatabase = new SymbolDatabase(_tokenizer, _settings, _errorLogger); - ownSymbolDatabase = true; - } + SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); std::list::iterator i; @@ -2623,9 +2616,6 @@ void CheckMemoryLeakInClass::check() } } } - - if (ownSymbolDatabase) - delete symbolDatabase; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2632ae579..5ff2983e3 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7502,7 +7502,7 @@ void Tokenizer::simplifyStd() const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const { if (_symbolDatabase == NULL) - return NULL; + getSymbolDatabase(); std::list::iterator i; @@ -8759,3 +8759,11 @@ void Tokenizer::simplifyQtSignalsSlots() } } } + +SymbolDatabase *Tokenizer::getSymbolDatabase() const +{ + if (!_symbolDatabase) + _symbolDatabase = new SymbolDatabase(this, _settings, _errorLogger); + + return _symbolDatabase; +} diff --git a/lib/tokenize.h b/lib/tokenize.h index c5fe1012a..c7a46a0f6 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -280,8 +280,6 @@ public: /** Simplify "if else" */ void elseif(); - SymbolDatabase * _symbolDatabase; - void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno, bool split = false); void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno); @@ -540,6 +538,8 @@ public: _settings = settings; } + SymbolDatabase * getSymbolDatabase() const; + private: /** Disable copy constructor, no implementation */ Tokenizer(const Tokenizer &); @@ -562,6 +562,8 @@ private: * removed from the token list */ bool _codeWithTemplates; + + mutable SymbolDatabase *_symbolDatabase; }; /// @}