Commit c35bb422 authored by Roberto Raggi's avatar Roberto Raggi

Introduce Namespace aliases and store the TranslationUnit instead of the Control.

parent c8f03b46
......@@ -119,6 +119,7 @@ class Argument;
class TypenameArgument;
class Function;
class Namespace;
class NamespaceAlias;
class BaseClass;
class Block;
class Class;
......
......@@ -409,8 +409,27 @@ bool CheckDeclaration::visit(NamespaceAST *ast)
return false;
}
bool CheckDeclaration::visit(NamespaceAliasDefinitionAST *)
bool CheckDeclaration::visit(NamespaceAliasDefinitionAST *ast)
{
const Name *name = 0;
if (const Identifier *id = identifier(ast->namespace_name_token))
name = control()->nameId(id);
unsigned sourceLocation = ast->firstToken();
if (ast->namespace_name_token)
sourceLocation = ast->namespace_name_token;
const Name *namespaceName = semantic()->check(ast->name, _scope);
NamespaceAlias *namespaceAlias = control()->newNamespaceAlias(sourceLocation, name);
namespaceAlias->setNamespaceName(namespaceName);
namespaceAlias->setStartOffset(tokenAt(ast->firstToken()).offset);
namespaceAlias->setEndOffset(tokenAt(ast->lastToken()).offset);
//ast->symbol = namespaceAlias;
_scope->enterSymbol(namespaceAlias);
return false;
}
......
......@@ -385,6 +385,14 @@ public:
return ns;
}
NamespaceAlias *newNamespaceAlias(unsigned sourceLocation, const Name *name)
{
NamespaceAlias *ns = new NamespaceAlias(translationUnit,
sourceLocation, name);
symbols.push_back(ns);
return ns;
}
UsingNamespaceDirective *newUsingNamespaceDirective(unsigned sourceLocation, const Name *name)
{
UsingNamespaceDirective *u = new UsingNamespaceDirective(translationUnit,
......@@ -672,6 +680,9 @@ Function *Control::newFunction(unsigned sourceLocation, const Name *name)
Namespace *Control::newNamespace(unsigned sourceLocation, const Name *name)
{ return d->newNamespace(sourceLocation, name); }
NamespaceAlias *Control::newNamespaceAlias(unsigned sourceLocation, const Name *name)
{ return d->newNamespaceAlias(sourceLocation, name); }
BaseClass *Control::newBaseClass(unsigned sourceLocation, const Name *name)
{ return d->newBaseClass(sourceLocation, name); }
......
......@@ -131,6 +131,9 @@ public:
/// Creates a new Namespace symbol.
Namespace *newNamespace(unsigned sourceLocation, const Name *name = 0);
/// Creates a new Namespace symbol.
NamespaceAlias *newNamespaceAlias(unsigned sourceLocation, const Name *name = 0);
/// Creates a new BaseClass symbol.
BaseClass *newBaseClass(unsigned sourceLocation, const Name *name = 0);
......
......@@ -179,6 +179,13 @@ bool Scope::isObjCClassScope() const
return false;
}
bool Scope::isObjCProtocolScope() const
{
if (_owner)
return _owner->isObjCProtocol();
return false;
}
bool Scope::isFunctionScope() const
{
Function *f = 0;
......
......@@ -114,6 +114,9 @@ public:
/// Returns true if this scope's owner is an ObjCClass Symbol.
bool isObjCClassScope() const;
/// Returns true if this scope's owner is an ObjCProtocol Symbol.
bool isObjCProtocolScope() const;
/// Returns true if this scope's owner is an ObjCMethod symbol.
bool isObjCMethodScope() const;
......
......@@ -161,7 +161,7 @@ private:
};
Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
: _control(translationUnit->control()),
: _translationUnit(translationUnit),
_sourceLocation(sourceLocation),
_sourceOffset(0),
_startOffset(0),
......@@ -183,10 +183,15 @@ Symbol::~Symbol()
{ }
Control *Symbol::control() const
{ return _control; }
{
if (_translationUnit)
return _translationUnit->control();
return 0;
}
TranslationUnit *Symbol::translationUnit() const
{ return _control->translationUnit(); }
{ return _translationUnit; }
void Symbol::visitSymbol(SymbolVisitor *visitor)
{
......
......@@ -239,6 +239,7 @@ public:
virtual const Enum *asEnum() const { return 0; }
virtual const Function *asFunction() const { return 0; }
virtual const Namespace *asNamespace() const { return 0; }
virtual const NamespaceAlias *asNamespaceAlias() const { return 0; }
virtual const Class *asClass() const { return 0; }
virtual const Block *asBlock() const { return 0; }
virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const { return 0; }
......@@ -261,6 +262,7 @@ public:
virtual Enum *asEnum() { return 0; }
virtual Function *asFunction() { return 0; }
virtual Namespace *asNamespace() { return 0; }
virtual NamespaceAlias *asNamespaceAlias() { return 0; }
virtual Class *asClass() { return 0; }
virtual Block *asBlock() { return 0; }
virtual UsingNamespaceDirective *asUsingNamespaceDirective() { return 0; }
......@@ -324,7 +326,7 @@ protected:
TranslationUnit *translationUnit() const;
private:
Control *_control;
TranslationUnit *_translationUnit;
unsigned _sourceLocation;
unsigned _sourceOffset;
unsigned _startOffset;
......
......@@ -70,6 +70,7 @@ public:
virtual bool visit(UsingNamespaceDirective *) { return true; }
virtual bool visit(UsingDeclaration *) { return true; }
virtual bool visit(NamespaceAlias *) { return true; }
virtual bool visit(Declaration *) { return true; }
virtual bool visit(Argument *) { return true; }
virtual bool visit(TypenameArgument *) { return true; }
......
......@@ -89,6 +89,27 @@ FullySpecifiedType UsingNamespaceDirective::type() const
void UsingNamespaceDirective::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
NamespaceAlias::NamespaceAlias(TranslationUnit *translationUnit,
unsigned sourceLocation, const Name *name)
: Symbol(translationUnit, sourceLocation, name), _namespaceName(0)
{ }
NamespaceAlias::~NamespaceAlias()
{ }
const Name *NamespaceAlias::namespaceName() const
{ return _namespaceName; }
void NamespaceAlias::setNamespaceName(const Name *namespaceName)
{ _namespaceName = namespaceName; }
FullySpecifiedType NamespaceAlias::type() const
{ return FullySpecifiedType(); }
void NamespaceAlias::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
UsingDeclaration::UsingDeclaration(TranslationUnit *translationUnit,
unsigned sourceLocation, const Name *name)
: Symbol(translationUnit, sourceLocation, name)
......
......@@ -110,6 +110,31 @@ protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
};
class CPLUSPLUS_EXPORT NamespaceAlias: public Symbol
{
public:
NamespaceAlias(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
virtual ~NamespaceAlias();
const Name *namespaceName() const;
void setNamespaceName(const Name *namespaceName);
// Symbol's interface
virtual FullySpecifiedType type() const;
virtual const NamespaceAlias *asNamespaceAlias() const
{ return this; }
virtual NamespaceAlias *asNamespaceAlias()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
private:
const Name *_namespaceName;
};
class CPLUSPLUS_EXPORT Declaration: public Symbol
{
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment