[cfe-commits] r67962 - in /cfe/trunk: include/clang/AST/DeclCXX.h include/clang/AST/DeclNodes.def lib/AST/DeclCXX.cpp lib/Sema/SemaDeclCXX.cpp

Anders Carlsson andersca at mac.com
Sat Mar 28 15:58:02 PDT 2009


Author: andersca
Date: Sat Mar 28 17:58:02 2009
New Revision: 67962

URL: http://llvm.org/viewvc/llvm-project?rev=67962&view=rev
Log:
Create AST nodes for namespace aliases.

Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/include/clang/AST/DeclNodes.def
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=67962&r1=67961&r2=67962&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sat Mar 28 17:58:02 2009
@@ -953,6 +953,46 @@
   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;

Modified: cfe/trunk/include/clang/AST/DeclNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclNodes.def?rev=67962&r1=67961&r2=67962&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclNodes.def (original)
+++ cfe/trunk/include/clang/AST/DeclNodes.def Sat Mar 28 17:58:02 2009
@@ -78,6 +78,7 @@
   DECL(OverloadedFunction, NamedDecl)
   DECL(Namespace, NamedDecl)
   DECL(UsingDirective, NamedDecl)
+  DECL(NamespaceAlias, NamedDecl)
   ABSTRACT_DECL(Type, NamedDecl)
     DECL(Typedef, TypeDecl)
     ABSTRACT_DECL(Tag, TypeDecl)

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=67962&r1=67961&r2=67962&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Sat Mar 28 17:58:02 2009
@@ -361,6 +361,16 @@
                                     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) {

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=67962&r1=67961&r2=67962&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Mar 28 17:58:02 2009
@@ -1707,7 +1707,12 @@
     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 





More information about the cfe-commits mailing list