]> granicus.if.org Git - clang/commitdiff
Create AST nodes for namespace aliases.
authorAnders Carlsson <andersca@mac.com>
Sat, 28 Mar 2009 22:58:02 +0000 (22:58 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 28 Mar 2009 22:58:02 +0000 (22:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67962 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclCXX.h
include/clang/AST/DeclNodes.def
lib/AST/DeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp

index 940d95ca439c7e1901781872b2768472a720b79a..5f55947a3202c8053d9b893980f6516b878ae207 100644 (file)
@@ -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;
index d4c8c5e6ba5642fd34c4f768333856d39ebfe6d0..bbe36242b1c3ef47bbaa97567b84f913298fa8f2 100644 (file)
@@ -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)
index 7c5dbced3117984b0c0f53af671980ce8ca06a76..2858d479bbbb31164b5768e1572bc6d875990a71 100644 (file)
@@ -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) {
index c9a236342248da7a217c675df530f9c9c33d38fe..f58125d2e355999d79cb298af087736f65c2dcfa 100644 (file)
@@ -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