Skip to content
Snippets Groups Projects
Commit 8f84f81e authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Introduced startOffset(), endOffset(), getPosition(), getStartPosition(), and getEndPosition().

parent 3b042476
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
......@@ -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);
......
......@@ -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());
......
......@@ -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;
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment