From: Anders Carlsson Date: Sat, 28 Mar 2009 22:58:02 +0000 (+0000) Subject: Create AST nodes for namespace aliases. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68771c73f4293620dc1a99154ec02111e6490e28;p=clang Create AST nodes for namespace aliases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67962 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 940d95ca43..5f55947a32 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -953,6 +953,46 @@ public: friend class DeclContext; }; +class NamespaceAliasDecl : public NamedDecl { + SourceLocation AliasLoc; + + /// IdentLoc - Location of namespace identifier. + /// FIXME: We don't store location of scope specifier. + SourceLocation IdentLoc; + + /// Namespace - The Decl that this alias points to. Can either be a + /// NamespaceDecl or a NamespaceAliasDecl. + NamedDecl *Namespace; + + NamespaceAliasDecl(DeclContext *DC, SourceLocation L, + SourceLocation AliasLoc, IdentifierInfo *Alias, + SourceLocation IdentLoc, NamedDecl *Namespace) + : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), + IdentLoc(IdentLoc), Namespace(Namespace) { } + +public: + + NamespaceDecl *getNamespace() { + // FIXME: Namespace can also be an alias decl. + return cast(Namespace); + } + + const NamespaceDecl *getNamespace() const { + return const_cast(this)->getNamespace(); + } + + static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, + SourceLocation L, SourceLocation AliasLoc, + IdentifierInfo *Alias, + SourceLocation IdentLoc, + NamedDecl *Namespace); + + static bool classof(const Decl *D) { + return D->getKind() == Decl::NamespaceAlias; + } + static bool classof(const NamespaceAliasDecl *D) { return true; } +}; + class StaticAssertDecl : public Decl { Expr *AssertExpr; StringLiteral *Message; diff --git a/include/clang/AST/DeclNodes.def b/include/clang/AST/DeclNodes.def index d4c8c5e6ba..bbe36242b1 100644 --- a/include/clang/AST/DeclNodes.def +++ b/include/clang/AST/DeclNodes.def @@ -78,6 +78,7 @@ ABSTRACT_DECL(Named, Decl) DECL(OverloadedFunction, NamedDecl) DECL(Namespace, NamedDecl) DECL(UsingDirective, NamedDecl) + DECL(NamespaceAlias, NamedDecl) ABSTRACT_DECL(Type, NamedDecl) DECL(Typedef, TypeDecl) ABSTRACT_DECL(Tag, TypeDecl) diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 7c5dbced31..2858d479bb 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -361,6 +361,16 @@ UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, Used, CommonAncestor); } +NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, + SourceLocation L, + SourceLocation AliasLoc, + IdentifierInfo *Alias, + SourceLocation IdentLoc, + NamedDecl *Namespace) { + return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, IdentLoc, + Namespace); +} + StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, Expr *AssertExpr, StringLiteral *Message) { diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index c9a2363422..f58125d2e3 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1707,7 +1707,12 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S, return DeclPtrTy(); } - return DeclPtrTy(); + NamespaceAliasDecl *AliasDecl = + NamespaceAliasDecl::Create(Context, CurContext, NamespaceLoc, AliasLoc, Alias, + IdentLoc, R); + + CurContext->addDecl(AliasDecl); + return DeclPtrTy::make(AliasDecl); } /// AddCXXDirectInitializerToDecl - This action is called immediately after