Added Pointer to enclosing scope to class Token (Only available when symboldatabase is created).
This commit is contained in:
parent
45bad7d1b2
commit
2ab33ef21b
|
@ -33,6 +33,7 @@ Token::Token(Token **t) :
|
||||||
_next(0),
|
_next(0),
|
||||||
_previous(0),
|
_previous(0),
|
||||||
_link(0),
|
_link(0),
|
||||||
|
_scope(0),
|
||||||
_str(""),
|
_str(""),
|
||||||
_varId(0),
|
_varId(0),
|
||||||
_fileIndex(0),
|
_fileIndex(0),
|
||||||
|
@ -193,6 +194,7 @@ void Token::deleteThis()
|
||||||
_fileIndex = _next->_fileIndex;
|
_fileIndex = _next->_fileIndex;
|
||||||
_linenr = _next->_linenr;
|
_linenr = _next->_linenr;
|
||||||
_link = _next->_link;
|
_link = _next->_link;
|
||||||
|
_scope = _next->_scope;
|
||||||
if (_link)
|
if (_link)
|
||||||
_link->link(this);
|
_link->link(this);
|
||||||
|
|
||||||
|
@ -211,6 +213,7 @@ void Token::deleteThis()
|
||||||
_fileIndex = _previous->_fileIndex;
|
_fileIndex = _previous->_fileIndex;
|
||||||
_linenr = _previous->_linenr;
|
_linenr = _previous->_linenr;
|
||||||
_link = _previous->_link;
|
_link = _previous->_link;
|
||||||
|
_scope = _previous->_scope;
|
||||||
if (_link)
|
if (_link)
|
||||||
_link->link(this);
|
_link->link(this);
|
||||||
|
|
||||||
|
|
20
lib/token.h
20
lib/token.h
|
@ -24,6 +24,8 @@
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
class Scope;
|
||||||
|
|
||||||
/// @addtogroup Core
|
/// @addtogroup Core
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
@ -383,6 +385,21 @@ public:
|
||||||
return _link;
|
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.
|
* Links two elements against each other.
|
||||||
**/
|
**/
|
||||||
|
@ -473,6 +490,9 @@ private:
|
||||||
Token *_next;
|
Token *_next;
|
||||||
Token *_previous;
|
Token *_previous;
|
||||||
Token *_link;
|
Token *_link;
|
||||||
|
|
||||||
|
Scope* _scope;
|
||||||
|
|
||||||
std::string _str;
|
std::string _str;
|
||||||
unsigned int _varId;
|
unsigned int _varId;
|
||||||
unsigned int _fileIndex;
|
unsigned int _fileIndex;
|
||||||
|
|
|
@ -3233,8 +3233,7 @@ void Tokenizer::simplifySizeof()
|
||||||
bool Tokenizer::simplifyTokenList()
|
bool Tokenizer::simplifyTokenList()
|
||||||
{
|
{
|
||||||
// clear the _functionList so it can't contain dead pointers
|
// clear the _functionList so it can't contain dead pointers
|
||||||
delete _symbolDatabase;
|
deleteSymbolDatabase();
|
||||||
_symbolDatabase = NULL;
|
|
||||||
|
|
||||||
// simplify references
|
// simplify references
|
||||||
simplifyReference();
|
simplifyReference();
|
||||||
|
@ -8874,12 +8873,59 @@ void Tokenizer::simplifyQtSignalsSlots()
|
||||||
|
|
||||||
const SymbolDatabase *Tokenizer::getSymbolDatabase() const
|
const SymbolDatabase *Tokenizer::getSymbolDatabase() const
|
||||||
{
|
{
|
||||||
if (!_symbolDatabase)
|
if (!_symbolDatabase) {
|
||||||
_symbolDatabase = new SymbolDatabase(this, _settings, _errorLogger);
|
_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;
|
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()
|
void Tokenizer::simplifyOperatorName()
|
||||||
{
|
{
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
|
|
@ -695,6 +695,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
const SymbolDatabase *getSymbolDatabase() const;
|
const SymbolDatabase *getSymbolDatabase() const;
|
||||||
|
void deleteSymbolDatabase();
|
||||||
|
|
||||||
Token *deleteInvalidTypedef(Token *typeDef);
|
Token *deleteInvalidTypedef(Token *typeDef);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue