diff options
| author | Anders Carlsson <andersca@mac.com> | 2009-03-28 22:58:02 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2009-03-28 22:58:02 +0000 |
| commit | ff25fdf2fbffdb6e5ac173bc84ecde0add9336e6 (patch) | |
| tree | a1f8a0dae08501be9f8128d0fd1f839e5ac5b41d /clang | |
| parent | 47952aec09c0995120da415c506c8e25242c0f35 (diff) | |
| download | bcm5719-llvm-ff25fdf2fbffdb6e5ac173bc84ecde0add9336e6.tar.gz bcm5719-llvm-ff25fdf2fbffdb6e5ac173bc84ecde0add9336e6.zip | |
Create AST nodes for namespace aliases.
llvm-svn: 67962
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/DeclCXX.h | 40 | ||||
| -rw-r--r-- | clang/include/clang/AST/DeclNodes.def | 1 | ||||
| -rw-r--r-- | clang/lib/AST/DeclCXX.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 7 |
4 files changed, 57 insertions, 1 deletions
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 940d95ca439..5f55947a320 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/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<NamespaceDecl>(Namespace); + } + + const NamespaceDecl *getNamespace() const { + return const_cast<NamespaceAliasDecl*>(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/clang/include/clang/AST/DeclNodes.def b/clang/include/clang/AST/DeclNodes.def index d4c8c5e6ba5..bbe36242b1c 100644 --- a/clang/include/clang/AST/DeclNodes.def +++ b/clang/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/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 7c5dbced311..2858d479bbb 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/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/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index c9a23634224..f58125d2e35 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/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 |

