Moved startOffset/endOffset from Symbol to Scope.

This commit is contained in:
Erik Verbruggen
2010-07-16 16:01:41 +02:00
parent 3bcfa87b90
commit c4b03574ab
7 changed files with 49 additions and 38 deletions

View File

@@ -230,8 +230,6 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
} }
Declaration *symbol = control()->newDeclaration(location, name); Declaration *symbol = control()->newDeclaration(location, name);
symbol->setStartOffset(tokenAt(ast->firstToken()).offset);
symbol->setEndOffset(tokenAt(ast->lastToken() - 1).end());
symbol->setType(declTy); symbol->setType(declTy);
if (declTy.isDeprecated()) if (declTy.isDeprecated())
@@ -321,8 +319,6 @@ bool CheckDeclaration::visit(ExceptionDeclarationAST *ast)
} }
Declaration *symbol = control()->newDeclaration(location, name); Declaration *symbol = control()->newDeclaration(location, name);
symbol->setStartOffset(tokenAt(ast->firstToken()).offset);
symbol->setEndOffset(tokenAt(ast->lastToken() - 1).end());
symbol->setType(declTy); symbol->setType(declTy);
_scope->enterSymbol(symbol); _scope->enterSymbol(symbol);
@@ -444,8 +440,6 @@ bool CheckDeclaration::visit(NamespaceAliasDefinitionAST *ast)
NamespaceAlias *namespaceAlias = control()->newNamespaceAlias(sourceLocation, name); NamespaceAlias *namespaceAlias = control()->newNamespaceAlias(sourceLocation, name);
namespaceAlias->setNamespaceName(namespaceName); namespaceAlias->setNamespaceName(namespaceName);
namespaceAlias->setStartOffset(tokenAt(ast->firstToken()).offset);
namespaceAlias->setEndOffset(tokenAt(ast->lastToken() - 1).end());
//ast->symbol = namespaceAlias; //ast->symbol = namespaceAlias;
_scope->enterSymbol(namespaceAlias); _scope->enterSymbol(namespaceAlias);
@@ -578,8 +572,6 @@ bool CheckDeclaration::visit(ObjCProtocolForwardDeclarationAST *ast)
const Name *protocolName = semantic()->check(it->value, _scope); const Name *protocolName = semantic()->check(it->value, _scope);
ObjCForwardProtocolDeclaration *fwdProtocol = control()->newObjCForwardProtocolDeclaration(sourceLocation, protocolName); ObjCForwardProtocolDeclaration *fwdProtocol = control()->newObjCForwardProtocolDeclaration(sourceLocation, protocolName);
fwdProtocol->setStartOffset(tokenAt(ast->firstToken()).offset);
fwdProtocol->setEndOffset(tokenAt(ast->lastToken() - 1).end());
_scope->enterSymbol(fwdProtocol); _scope->enterSymbol(fwdProtocol);
@@ -639,8 +631,6 @@ bool CheckDeclaration::visit(ObjCClassForwardDeclarationAST *ast)
const Name *className = semantic()->check(it->value, _scope); const Name *className = semantic()->check(it->value, _scope);
ObjCForwardClassDeclaration *fwdClass = control()->newObjCForwardClassDeclaration(sourceLocation, className); ObjCForwardClassDeclaration *fwdClass = control()->newObjCForwardClassDeclaration(sourceLocation, className);
fwdClass->setStartOffset(tokenAt(ast->firstToken()).offset);
fwdClass->setEndOffset(tokenAt(ast->lastToken() - 1).end());
_scope->enterSymbol(fwdClass); _scope->enterSymbol(fwdClass);
@@ -726,6 +716,8 @@ bool CheckDeclaration::visit(ObjCMethodDeclarationAST *ast)
Symbol *symbol; Symbol *symbol;
if (ast->function_body) { if (ast->function_body) {
symbol = methodTy; symbol = methodTy;
methodTy->setStartOffset(tokenAt(ast->firstToken()).offset);
methodTy->setEndOffset(tokenAt(ast->lastToken() - 1).end());
} else { } else {
Declaration *decl = control()->newDeclaration(selector->firstToken(), methodTy->name()); Declaration *decl = control()->newDeclaration(selector->firstToken(), methodTy->name());
decl->setType(methodTy); decl->setType(methodTy);
@@ -733,8 +725,6 @@ bool CheckDeclaration::visit(ObjCMethodDeclarationAST *ast)
symbol->setStorage(methodTy->storage()); symbol->setStorage(methodTy->storage());
} }
symbol->setStartOffset(tokenAt(ast->firstToken()).offset);
symbol->setEndOffset(tokenAt(ast->lastToken() - 1).end());
symbol->setVisibility(semantic()->currentObjCVisibility()); symbol->setVisibility(semantic()->currentObjCVisibility());
if (ty.isDeprecated()) if (ty.isDeprecated())
symbol->setDeprecated(true); symbol->setDeprecated(true);

View File

@@ -61,7 +61,9 @@ Scope::Scope(ScopedSymbol *owner)
_allocatedSymbols(0), _allocatedSymbols(0),
_symbolCount(-1), _symbolCount(-1),
_hash(0), _hash(0),
_hashSize(0) _hashSize(0),
_startOffset(0),
_endOffset(0)
{ } { }
Scope::~Scope() Scope::~Scope()
@@ -333,4 +335,16 @@ Scope::iterator Scope::firstSymbol() const
Scope::iterator Scope::lastSymbol() const Scope::iterator Scope::lastSymbol() const
{ return _symbols + _symbolCount + 1; } { return _symbols + _symbolCount + 1; }
unsigned Scope::startOffset() const
{ return _startOffset; }
void Scope::setStartOffset(unsigned offset)
{ _startOffset = offset; }
unsigned Scope::endOffset() const
{ return _endOffset; }
void Scope::setEndOffset(unsigned offset)
{ _endOffset = offset; }

View File

@@ -142,6 +142,14 @@ public:
Symbol *lookat(const Identifier *id) const; Symbol *lookat(const Identifier *id) const;
Symbol *lookat(int operatorId) const; Symbol *lookat(int operatorId) const;
/// Set the start offset of the scope
unsigned startOffset() const;
void setStartOffset(unsigned offset);
/// Set the end offset of the scope
unsigned endOffset() const;
void setEndOffset(unsigned offset);
private: private:
/// Returns the hash value for the given Symbol. /// Returns the hash value for the given Symbol.
unsigned hashValue(Symbol *symbol) const; unsigned hashValue(Symbol *symbol) const;
@@ -160,6 +168,9 @@ private:
Symbol **_hash; Symbol **_hash;
int _hashSize; int _hashSize;
unsigned _startOffset;
unsigned _endOffset;
}; };
} // end of namespace CPlusPlus } // end of namespace CPlusPlus

View File

@@ -111,9 +111,7 @@ private:
}; };
Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
: _startOffset(0), : _name(0),
_endOffset(0),
_name(0),
_hashCode(0), _hashCode(0),
_storage(Symbol::NoStorage), _storage(Symbol::NoStorage),
_visibility(Symbol::Public), _visibility(Symbol::Public),
@@ -201,18 +199,6 @@ const char *Symbol::fileName() const
unsigned Symbol::fileNameLength() const unsigned Symbol::fileNameLength() const
{ return fileId()->size(); } { return fileId()->size(); }
unsigned Symbol::startOffset() const
{ return _startOffset; }
void Symbol::setStartOffset(unsigned offset)
{ _startOffset = offset; }
unsigned Symbol::endOffset() const
{ return _endOffset; }
void Symbol::setEndOffset(unsigned offset)
{ _endOffset = offset; }
const Name *Symbol::identity() const const Name *Symbol::identity() const
{ {
if (! _name) if (! _name)
@@ -433,8 +419,6 @@ bool Symbol::isObjCPropertyDeclaration() const
void Symbol::copy(Symbol *other) void Symbol::copy(Symbol *other)
{ {
_sourceLocation = other->_sourceLocation; _sourceLocation = other->_sourceLocation;
_startOffset = other->_startOffset;
_endOffset = other->_endOffset;
_name = other->_name; _name = other->_name;
_hashCode = other->_hashCode; _hashCode = other->_hashCode;
_storage = other->_storage; _storage = other->_storage;

View File

@@ -105,12 +105,6 @@ public:
/// Returns this Symbol's file name length. /// Returns this Symbol's file name length.
unsigned fileNameLength() const; unsigned fileNameLength() const;
unsigned startOffset() const;
void setStartOffset(unsigned offset);
unsigned endOffset() const;
void setEndOffset(unsigned offset);
/// Returns this Symbol's name. /// Returns this Symbol's name.
const Name *name() const; const Name *name() const;
@@ -320,8 +314,6 @@ protected:
private: private:
unsigned _sourceLocation; unsigned _sourceLocation;
unsigned _startOffset;
unsigned _endOffset;
const Name *_name; const Name *_name;
unsigned _hashCode; unsigned _hashCode;
int _storage; int _storage;

View File

@@ -427,6 +427,18 @@ Scope *ScopedSymbol::members() const
void ScopedSymbol::addMember(Symbol *member) void ScopedSymbol::addMember(Symbol *member)
{ _members->enterSymbol(member); } { _members->enterSymbol(member); }
unsigned ScopedSymbol::startOffset() const
{ return _members->startOffset(); }
void ScopedSymbol::setStartOffset(unsigned offset)
{ _members->setStartOffset(offset); }
unsigned ScopedSymbol::endOffset() const
{ return _members->endOffset(); }
void ScopedSymbol::setEndOffset(unsigned offset)
{ _members->setEndOffset(offset); }
Block::Block(TranslationUnit *translationUnit, unsigned sourceLocation) Block::Block(TranslationUnit *translationUnit, unsigned sourceLocation)
: ScopedSymbol(translationUnit, sourceLocation, /*name = */ 0) : ScopedSymbol(translationUnit, sourceLocation, /*name = */ 0)
{ } { }

View File

@@ -234,6 +234,14 @@ public:
virtual ScopedSymbol *asScopedSymbol() virtual ScopedSymbol *asScopedSymbol()
{ return this; } { return this; }
/// Set the start offset of the scope for this symbol
unsigned startOffset() const;
void setStartOffset(unsigned offset);
/// Set the end offset of the scope for this symbol
unsigned endOffset() const;
void setEndOffset(unsigned offset);
private: private:
Scope *_members; Scope *_members;
}; };