diff --git a/src/shared/cplusplus/CheckDeclaration.cpp b/src/shared/cplusplus/CheckDeclaration.cpp index c6de2cf4aa0d412e408dcbe08b7c3e6dc8190180..c508110167753e72bf53e85958506997e28e6da3 100644 --- a/src/shared/cplusplus/CheckDeclaration.cpp +++ b/src/shared/cplusplus/CheckDeclaration.cpp @@ -55,6 +55,7 @@ #include "CoreTypes.h" #include "Symbols.h" #include "Control.h" +#include "Literals.h" #include <cassert> CPLUSPLUS_BEGIN_NAMESPACE @@ -186,6 +187,9 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast) } Declaration *symbol = control()->newDeclaration(location, name); + symbol->setStartOffset(tokenAt(ast->firstToken()).offset); + symbol->setEndOffset(tokenAt(ast->lastToken()).offset); + symbol->setType(control()->integerType(IntegerType::Int)); symbol->setType(declTy); @@ -259,6 +263,8 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast) } Function *fun = funTy->asFunctionType(); + fun->setStartOffset(tokenAt(ast->firstToken()).offset); + fun->setEndOffset(tokenAt(ast->lastToken()).offset); if (ast->declarator) fun->setSourceLocation(ast->declarator->firstToken()); fun->setName(name); @@ -335,6 +341,8 @@ bool CheckDeclaration::visit(NamespaceAST *ast) sourceLocation = ast->identifier_token; Namespace *ns = control()->newNamespace(sourceLocation, namespaceName); + ns->setStartOffset(tokenAt(ast->firstToken()).offset); + ns->setEndOffset(tokenAt(ast->lastToken()).offset); ast->symbol = ns; _scope->enterSymbol(ns); semantic()->check(ast->linkage_body, ns->members()); // ### we'll do the merge later. diff --git a/src/shared/cplusplus/CheckSpecifier.cpp b/src/shared/cplusplus/CheckSpecifier.cpp index e79f6aa0ba642976b112f5c9882eab7e57fc4617..935c74affcb6b620e5045770091c4fd901c6a33c 100644 --- a/src/shared/cplusplus/CheckSpecifier.cpp +++ b/src/shared/cplusplus/CheckSpecifier.cpp @@ -303,6 +303,8 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast) Name *className = semantic()->check(ast->name, _scope); Class *klass = control()->newClass(sourceLocation, className); + klass->setStartOffset(tokenAt(ast->firstToken()).offset); + klass->setEndOffset(tokenAt(ast->lastToken()).offset); ast->symbol = klass; unsigned classKey = tokenKind(ast->classkey_token); if (classKey == T_CLASS) @@ -369,6 +371,8 @@ bool CheckSpecifier::visit(EnumSpecifierAST *ast) Name *name = semantic()->check(ast->name, _scope); Enum *e = control()->newEnum(sourceLocation, name); + e->setStartOffset(tokenAt(ast->firstToken()).offset); + e->setEndOffset(tokenAt(ast->lastToken()).offset); e->setVisibility(semantic()->currentVisibility()); _scope->enterSymbol(e); _fullySpecifiedType.setType(e); diff --git a/src/shared/cplusplus/CheckStatement.cpp b/src/shared/cplusplus/CheckStatement.cpp index d65bd88dea409074fc3c7271405a4c255a9cd059..7d8bde823b6dc4d14570b4b9ab01e0fecbf88e81 100644 --- a/src/shared/cplusplus/CheckStatement.cpp +++ b/src/shared/cplusplus/CheckStatement.cpp @@ -99,6 +99,8 @@ bool CheckStatement::visit(CaseStatementAST *ast) bool CheckStatement::visit(CompoundStatementAST *ast) { Block *block = control()->newBlock(ast->lbrace_token); + block->setStartOffset(tokenAt(ast->firstToken()).offset); + block->setEndOffset(tokenAt(ast->lastToken()).offset); ast->symbol = block; _scope->enterSymbol(block); Scope *previousScope = switchScope(block->members()); diff --git a/src/shared/cplusplus/Symbol.cpp b/src/shared/cplusplus/Symbol.cpp index 8f5dc3b4921281323be419ec192e25979ab8abeb..c02a10f318bca7d3c6306a2a7e62219d748f2e6f 100644 --- a/src/shared/cplusplus/Symbol.cpp +++ b/src/shared/cplusplus/Symbol.cpp @@ -158,6 +158,8 @@ Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, Name * : _control(translationUnit->control()), _sourceLocation(sourceLocation), _sourceOffset(0), + _startOffset(0), + _endOffset(0), _name(0), _hashCode(0), _storage(Symbol::NoStorage), @@ -245,12 +247,33 @@ StringLiteral *Symbol::fileId() const return fileId; } +void Symbol::getPosition(unsigned *line, unsigned *column, StringLiteral **fileId) +{ translationUnit()->getPosition(_sourceOffset, line, column, fileId); } + +void Symbol::getStartPosition(unsigned *line, unsigned *column, StringLiteral **fileId) +{ translationUnit()->getPosition(_startOffset, line, column, fileId); } + +void Symbol::getEndPosition(unsigned *line, unsigned *column, StringLiteral **fileId) +{ translationUnit()->getPosition(_endOffset, line, column, fileId); } + const char *Symbol::fileName() const { return fileId()->chars(); } unsigned Symbol::fileNameLength() const { 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; } + Name *Symbol::identity() const { IdentityForName id; diff --git a/src/shared/cplusplus/Symbol.h b/src/shared/cplusplus/Symbol.h index d7c70c38ae73a4682b147066dc45993dfc6866da..ac8f0b11cab03026bf7f63bd44643196a99ac318 100644 --- a/src/shared/cplusplus/Symbol.h +++ b/src/shared/cplusplus/Symbol.h @@ -109,6 +109,16 @@ public: /// Returns this Symbol's file name length. unsigned fileNameLength() const; + unsigned startOffset() const; + void setStartOffset(unsigned offset); + + unsigned endOffset() const; + void setEndOffset(unsigned offset); + + void getPosition(unsigned *line, unsigned *column = 0, StringLiteral **fileId = 0); + void getStartPosition(unsigned *line, unsigned *column = 0, StringLiteral **fileId = 0); + void getEndPosition(unsigned *line, unsigned *column = 0, StringLiteral **fileId = 0); + /// Returns this Symbol's name. Name *name() const; @@ -250,6 +260,8 @@ private: Control *_control; unsigned _sourceLocation; unsigned _sourceOffset; + unsigned _startOffset; + unsigned _endOffset; Name *_name; unsigned _hashCode; int _storage;