Symbol database: creates a single symbol database within Tokenizer on demand and changes all checks to use it
This commit is contained in:
parent
399cc63d2d
commit
b6acfa809b
|
@ -43,30 +43,18 @@ CheckClass instance;
|
||||||
|
|
||||||
CheckClass::CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
CheckClass::CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(tokenizer, settings, errorLogger),
|
: Check(tokenizer, settings, errorLogger),
|
||||||
symbolDatabase(NULL), ownSymbolDatabase(false)
|
symbolDatabase(NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckClass::~CheckClass()
|
|
||||||
{
|
|
||||||
if (ownSymbolDatabase)
|
|
||||||
delete symbolDatabase;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckClass::createSymbolDatabase()
|
void CheckClass::createSymbolDatabase()
|
||||||
{
|
{
|
||||||
// Multiple calls => bail out
|
// Multiple calls => bail out
|
||||||
if (symbolDatabase)
|
if (symbolDatabase)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_tokenizer->_symbolDatabase)
|
symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
symbolDatabase = _tokenizer->_symbolDatabase;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
symbolDatabase = new SymbolDatabase(_tokenizer, _settings, _errorLogger);
|
|
||||||
ownSymbolDatabase = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -36,14 +36,12 @@ class CheckClass : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** @brief This constructor is used when registering the CheckClass */
|
/** @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. */
|
/** @brief This constructor is used when running checks. */
|
||||||
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);
|
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);
|
||||||
|
|
||||||
~CheckClass();
|
|
||||||
|
|
||||||
/** @brief Run checks on the normal token list */
|
/** @brief Run checks on the normal token list */
|
||||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
|
@ -113,7 +111,6 @@ private:
|
||||||
void createSymbolDatabase();
|
void createSymbolDatabase();
|
||||||
|
|
||||||
SymbolDatabase *symbolDatabase;
|
SymbolDatabase *symbolDatabase;
|
||||||
bool ownSymbolDatabase;
|
|
||||||
|
|
||||||
// Reporting errors..
|
// Reporting errors..
|
||||||
void noConstructorError(const Token *tok, const std::string &classname, bool isStruct);
|
void noConstructorError(const Token *tok, const std::string &classname, bool isStruct);
|
||||||
|
|
|
@ -2575,14 +2575,7 @@ void CheckMemoryLeakInFunction::check()
|
||||||
|
|
||||||
void CheckMemoryLeakInClass::check()
|
void CheckMemoryLeakInClass::check()
|
||||||
{
|
{
|
||||||
SymbolDatabase * symbolDatabase = _tokenizer->_symbolDatabase;
|
SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
bool ownSymbolDatabase = false;
|
|
||||||
|
|
||||||
if (symbolDatabase == NULL)
|
|
||||||
{
|
|
||||||
symbolDatabase = new SymbolDatabase(_tokenizer, _settings, _errorLogger);
|
|
||||||
ownSymbolDatabase = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<SymbolDatabase::SpaceInfo *>::iterator i;
|
std::list<SymbolDatabase::SpaceInfo *>::iterator i;
|
||||||
|
|
||||||
|
@ -2623,9 +2616,6 @@ void CheckMemoryLeakInClass::check()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ownSymbolDatabase)
|
|
||||||
delete symbolDatabase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7502,7 +7502,7 @@ void Tokenizer::simplifyStd()
|
||||||
const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const
|
const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const
|
||||||
{
|
{
|
||||||
if (_symbolDatabase == NULL)
|
if (_symbolDatabase == NULL)
|
||||||
return NULL;
|
getSymbolDatabase();
|
||||||
|
|
||||||
std::list<SymbolDatabase::SpaceInfo *>::iterator i;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -280,8 +280,6 @@ public:
|
||||||
/** Simplify "if else" */
|
/** Simplify "if else" */
|
||||||
void elseif();
|
void elseif();
|
||||||
|
|
||||||
SymbolDatabase * _symbolDatabase;
|
|
||||||
|
|
||||||
void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno, bool split = false);
|
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);
|
void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno);
|
||||||
|
|
||||||
|
@ -540,6 +538,8 @@ public:
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SymbolDatabase * getSymbolDatabase() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Disable copy constructor, no implementation */
|
/** Disable copy constructor, no implementation */
|
||||||
Tokenizer(const Tokenizer &);
|
Tokenizer(const Tokenizer &);
|
||||||
|
@ -562,6 +562,8 @@ private:
|
||||||
* removed from the token list
|
* removed from the token list
|
||||||
*/
|
*/
|
||||||
bool _codeWithTemplates;
|
bool _codeWithTemplates;
|
||||||
|
|
||||||
|
mutable SymbolDatabase *_symbolDatabase;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
Loading…
Reference in New Issue