Added Pointer to enclosing scope to class Token (Only available when symboldatabase is created).

This commit is contained in:
PKEuS 2012-08-11 11:47:11 -07:00
parent 45bad7d1b2
commit 2ab33ef21b
4 changed files with 73 additions and 3 deletions

View File

@ -33,6 +33,7 @@ Token::Token(Token **t) :
_next(0),
_previous(0),
_link(0),
_scope(0),
_str(""),
_varId(0),
_fileIndex(0),
@ -193,6 +194,7 @@ void Token::deleteThis()
_fileIndex = _next->_fileIndex;
_linenr = _next->_linenr;
_link = _next->_link;
_scope = _next->_scope;
if (_link)
_link->link(this);
@ -211,6 +213,7 @@ void Token::deleteThis()
_fileIndex = _previous->_fileIndex;
_linenr = _previous->_linenr;
_link = _previous->_link;
_scope = _previous->_scope;
if (_link)
_link->link(this);

View File

@ -24,6 +24,8 @@
#include <ostream>
#include "config.h"
class Scope;
/// @addtogroup Core
/// @{
@ -383,6 +385,21 @@ public:
return _link;
}
/**
* Associate this token with given scope
* @param scope Scope to be associated
*/
void scope(Scope* scope) {
_scope = scope;
}
/**
* Returns a pointer to the scope containing this token.
*/
Scope* scope() const {
return _scope;
}
/**
* Links two elements against each other.
**/
@ -473,6 +490,9 @@ private:
Token *_next;
Token *_previous;
Token *_link;
Scope* _scope;
std::string _str;
unsigned int _varId;
unsigned int _fileIndex;

View File

@ -3233,8 +3233,7 @@ void Tokenizer::simplifySizeof()
bool Tokenizer::simplifyTokenList()
{
// clear the _functionList so it can't contain dead pointers
delete _symbolDatabase;
_symbolDatabase = NULL;
deleteSymbolDatabase();
// simplify references
simplifyReference();
@ -8874,12 +8873,59 @@ void Tokenizer::simplifyQtSignalsSlots()
const SymbolDatabase *Tokenizer::getSymbolDatabase() const
{
if (!_symbolDatabase)
if (!_symbolDatabase) {
_symbolDatabase = new SymbolDatabase(this, _settings, _errorLogger);
// Set scope pointers
for (std::list<Scope>::iterator scope = _symbolDatabase->scopeList.begin(); scope != _symbolDatabase->scopeList.end(); ++scope) {
Token* start = const_cast<Token*>(scope->classStart);
Token* end = const_cast<Token*>(scope->classEnd);
if (scope->type == Scope::eGlobal) {
start = const_cast<Token*>(list.front());
end = const_cast<Token*>(list.back());
}
if (start && end) {
start->scope(&*scope);
end->scope(&*scope);
}
if (start != end && start->next() != end) {
for (Token* tok = start->next(); tok != end; tok = tok->next()) {
if (tok->str() == "{") {
bool break2 = false;
for (std::list<Scope*>::const_iterator innerScope = scope->nestedList.begin(); innerScope != scope->nestedList.end(); ++innerScope) {
if (tok == (*innerScope)->classStart) { // Is begin of inner scope
tok = tok->link();
if (!tok || tok->next() == end || !tok->next()) {
break2 = true;
break;
}
tok = tok->next();
break;
}
}
if (break2)
break;
}
tok->scope(&*scope);
}
}
}
}
return _symbolDatabase;
}
void Tokenizer::deleteSymbolDatabase()
{
// Clear scope pointers
for (Token* tok = list.front(); tok != list.back(); tok = tok->next()) {
tok->scope(0);
}
delete _symbolDatabase;
_symbolDatabase = 0;
}
void Tokenizer::simplifyOperatorName()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {

View File

@ -695,6 +695,7 @@ public:
}
const SymbolDatabase *getSymbolDatabase() const;
void deleteSymbolDatabase();
Token *deleteInvalidTypedef(Token *typeDef);