Symbol database: creates a single symbol database within Tokenizer on demand and changes all checks to use it

This commit is contained in:
Robert Reif 2010-12-07 07:08:49 +01:00 committed by Daniel Marjamäki
parent 399cc63d2d
commit b6acfa809b
5 changed files with 17 additions and 32 deletions

View File

@ -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();
}
//---------------------------------------------------------------------------

View File

@ -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);

View File

@ -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<SymbolDatabase::SpaceInfo *>::iterator i;
@ -2623,9 +2616,6 @@ void CheckMemoryLeakInClass::check()
}
}
}
if (ownSymbolDatabase)
delete symbolDatabase;
}

View File

@ -7502,7 +7502,7 @@ void Tokenizer::simplifyStd()
const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const
{
if (_symbolDatabase == NULL)
return NULL;
getSymbolDatabase();
std::list<SymbolDatabase::SpaceInfo *>::iterator i;
@ -8759,3 +8759,11 @@ void Tokenizer::simplifyQtSignalsSlots()
}
}
}
SymbolDatabase *Tokenizer::getSymbolDatabase() const
{
if (!_symbolDatabase)
_symbolDatabase = new SymbolDatabase(this, _settings, _errorLogger);
return _symbolDatabase;
}

View File

@ -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;
};
/// @}