[cfe-commits] r98249 - in /cfe/trunk: include/clang/AST/DeclCXX.h include/clang/AST/DeclFriend.h include/clang/AST/DeclVisitor.h lib/AST/CMakeLists.txt lib/AST/DeclBase.cpp lib/AST/DeclCXX.cpp lib/AST/DeclFriend.cpp lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaTemplate.cpp

John McCall rjmccall at apple.com
Wed Mar 10 23:50:04 PST 2010


Author: rjmccall
Date: Thu Mar 11 01:50:04 2010
New Revision: 98249

URL: http://llvm.org/viewvc/llvm-project?rev=98249&view=rev
Log:
Split C++ friend declarations into their own header/implementation file.
I'm expecting this portion of the AST to grow and change, and I'd like to
be able to do that with minimal recompilation.  If this proves unnecessary
when access control is fully-implemented, I'll fold the classes back into
DeclCXX.h.


Added:
    cfe/trunk/include/clang/AST/DeclFriend.h
    cfe/trunk/lib/AST/DeclFriend.cpp
Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/include/clang/AST/DeclVisitor.h
    cfe/trunk/lib/AST/CMakeLists.txt
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=98249&r1=98248&r2=98249&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Mar 11 01:50:04 2010
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  This file defines the C++ Decl subclasses.
+//  This file defines the C++ Decl subclasses, other than those for
+//  templates (in DeclTemplate.h) and friends (in DeclFriend.h).
 //
 //===----------------------------------------------------------------------===//
 
@@ -1385,77 +1386,6 @@
   static bool classofKind(Kind K) { return K == CXXConversion; }
 };
 
-/// FriendDecl - Represents the declaration of a friend entity,
-/// which can be a function, a type, or a templated function or type.
-//  For example:
-///
-/// @code
-/// template <typename T> class A {
-///   friend int foo(T);
-///   friend class B;
-///   friend T; // only in C++0x
-///   template <typename U> friend class C;
-///   template <typename U> friend A& operator+=(A&, const U&) { ... }
-/// };
-/// @endcode
-///
-/// The semantic context of a friend decl is its declaring class.
-class FriendDecl : public Decl {
-public:
-  typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion;
-
-private:
-  // The declaration that's a friend of this class.
-  FriendUnion Friend;
-
-  // Location of the 'friend' specifier.
-  SourceLocation FriendLoc;
-
-  // FIXME: Hack to keep track of whether this was a friend function
-  // template specialization.
-  bool WasSpecialization;
-
-  FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend,
-             SourceLocation FriendL)
-    : Decl(Decl::Friend, DC, L),
-      Friend(Friend),
-      FriendLoc(FriendL),
-      WasSpecialization(false) {
-  }
-
-public:
-  static FriendDecl *Create(ASTContext &C, DeclContext *DC,
-                            SourceLocation L, FriendUnion Friend_,
-                            SourceLocation FriendL);
-
-  /// If this friend declaration names an (untemplated but
-  /// possibly dependent) type, return the type;  otherwise
-  /// return null.  This is used only for C++0x's unelaborated
-  /// friend type declarations.
-  Type *getFriendType() const {
-    return Friend.dyn_cast<Type*>();
-  }
-
-  /// If this friend declaration doesn't name an unelaborated
-  /// type, return the inner declaration.
-  NamedDecl *getFriendDecl() const {
-    return Friend.dyn_cast<NamedDecl*>();
-  }
-
-  /// Retrieves the location of the 'friend' keyword.
-  SourceLocation getFriendLoc() const {
-    return FriendLoc;
-  }
-
-  bool wasSpecialization() const { return WasSpecialization; }
-  void setSpecialization(bool WS) { WasSpecialization = WS; }
-
-  // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
-  static bool classof(const FriendDecl *D) { return true; }
-  static bool classofKind(Kind K) { return K == Decl::Friend; }
-};
-
 /// LinkageSpecDecl - This represents a linkage specification.  For example:
 ///   extern "C" void foo();
 ///

Added: cfe/trunk/include/clang/AST/DeclFriend.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclFriend.h?rev=98249&view=auto
==============================================================================
--- cfe/trunk/include/clang/AST/DeclFriend.h (added)
+++ cfe/trunk/include/clang/AST/DeclFriend.h Thu Mar 11 01:50:04 2010
@@ -0,0 +1,95 @@
+//===-- DeclFriend.h - Classes for C++ friend declarations -*- C++ -*------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the section of the AST representing C++ friend
+// declarations.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_DECLFRIEND_H
+#define LLVM_CLANG_AST_DECLFRIEND_H
+
+#include "clang/AST/DeclCXX.h"
+
+namespace clang {
+
+/// FriendDecl - Represents the declaration of a friend entity,
+/// which can be a function, a type, or a templated function or type.
+//  For example:
+///
+/// @code
+/// template <typename T> class A {
+///   friend int foo(T);
+///   friend class B;
+///   friend T; // only in C++0x
+///   template <typename U> friend class C;
+///   template <typename U> friend A& operator+=(A&, const U&) { ... }
+/// };
+/// @endcode
+///
+/// The semantic context of a friend decl is its declaring class.
+class FriendDecl : public Decl {
+public:
+  typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion;
+
+private:
+  // The declaration that's a friend of this class.
+  FriendUnion Friend;
+
+  // Location of the 'friend' specifier.
+  SourceLocation FriendLoc;
+
+  // FIXME: Hack to keep track of whether this was a friend function
+  // template specialization.
+  bool WasSpecialization;
+
+  FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend,
+             SourceLocation FriendL)
+    : Decl(Decl::Friend, DC, L),
+      Friend(Friend),
+      FriendLoc(FriendL),
+      WasSpecialization(false) {
+  }
+
+public:
+  static FriendDecl *Create(ASTContext &C, DeclContext *DC,
+                            SourceLocation L, FriendUnion Friend_,
+                            SourceLocation FriendL);
+
+  /// If this friend declaration names an (untemplated but
+  /// possibly dependent) type, return the type;  otherwise
+  /// return null.  This is used only for C++0x's unelaborated
+  /// friend type declarations.
+  Type *getFriendType() const {
+    return Friend.dyn_cast<Type*>();
+  }
+
+  /// If this friend declaration doesn't name an unelaborated
+  /// type, return the inner declaration.
+  NamedDecl *getFriendDecl() const {
+    return Friend.dyn_cast<NamedDecl*>();
+  }
+
+  /// Retrieves the location of the 'friend' keyword.
+  SourceLocation getFriendLoc() const {
+    return FriendLoc;
+  }
+
+  bool wasSpecialization() const { return WasSpecialization; }
+  void setSpecialization(bool WS) { WasSpecialization = WS; }
+
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classof(const FriendDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Decl::Friend; }
+};
+  
+}
+
+#endif

Modified: cfe/trunk/include/clang/AST/DeclVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclVisitor.h?rev=98249&r1=98248&r2=98249&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclVisitor.h (original)
+++ cfe/trunk/include/clang/AST/DeclVisitor.h Thu Mar 11 01:50:04 2010
@@ -16,6 +16,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclTemplate.h"
 
 namespace clang {

Modified: cfe/trunk/lib/AST/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CMakeLists.txt?rev=98249&r1=98248&r2=98249&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CMakeLists.txt (original)
+++ cfe/trunk/lib/AST/CMakeLists.txt Thu Mar 11 01:50:04 2010
@@ -11,6 +11,7 @@
   Decl.cpp
   DeclBase.cpp
   DeclCXX.cpp
+  DeclFriend.cpp
   DeclGroup.cpp
   DeclObjC.cpp
   DeclPrinter.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=98249&r1=98248&r2=98249&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Mar 11 01:50:04 2010
@@ -15,6 +15,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclContextInternals.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExternalASTSource.h"

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=98249&r1=98248&r2=98249&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Thu Mar 11 01:50:04 2010
@@ -846,28 +846,6 @@
   return new (C) CXXConversionDecl(RD, L, N, T, TInfo, isInline, isExplicit);
 }
 
-FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
-                               SourceLocation L,
-                               FriendUnion Friend,
-                               SourceLocation FriendL) {
-#ifndef NDEBUG
-  if (Friend.is<NamedDecl*>()) {
-    NamedDecl *D = Friend.get<NamedDecl*>();
-    assert(isa<FunctionDecl>(D) ||
-           isa<CXXRecordDecl>(D) ||
-           isa<FunctionTemplateDecl>(D) ||
-           isa<ClassTemplateDecl>(D));
-
-    // As a temporary hack, we permit template instantiation to point
-    // to the original declaration when instantiating members.
-    assert(D->getFriendObjectKind() ||
-           (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
-  }
-#endif
-
-  return new (C) FriendDecl(DC, L, Friend, FriendL);
-}
-
 LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
                                          DeclContext *DC,
                                          SourceLocation L,

Added: cfe/trunk/lib/AST/DeclFriend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclFriend.cpp?rev=98249&view=auto
==============================================================================
--- cfe/trunk/lib/AST/DeclFriend.cpp (added)
+++ cfe/trunk/lib/AST/DeclFriend.cpp Thu Mar 11 01:50:04 2010
@@ -0,0 +1,39 @@
+//===--- DeclFriend.cpp - C++ Friend Declaration AST Node Implementation --===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the AST classes related to C++ friend
+// declarations.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/DeclFriend.h"
+#include "clang/AST/DeclTemplate.h"
+using namespace clang;
+
+FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
+                               SourceLocation L,
+                               FriendUnion Friend,
+                               SourceLocation FriendL) {
+#ifndef NDEBUG
+  if (Friend.is<NamedDecl*>()) {
+    NamedDecl *D = Friend.get<NamedDecl*>();
+    assert(isa<FunctionDecl>(D) ||
+           isa<CXXRecordDecl>(D) ||
+           isa<FunctionTemplateDecl>(D) ||
+           isa<ClassTemplateDecl>(D));
+
+    // As a temporary hack, we permit template instantiation to point
+    // to the original declaration when instantiating members.
+    assert(D->getFriendObjectKind() ||
+           (cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
+  }
+#endif
+
+  return new (C) FriendDecl(DC, L, Friend, FriendL);
+}

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=98249&r1=98248&r2=98249&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Mar 11 01:50:04 2010
@@ -365,8 +365,7 @@
   
   // Friend declarations and declarations introduced due to friends are never
   // added as results.
-  if (isa<FriendDecl>(ND) || 
-      (IDNS & (Decl::IDNS_OrdinaryFriend | Decl::IDNS_TagFriend)))
+  if (IDNS & (Decl::IDNS_OrdinaryFriend | Decl::IDNS_TagFriend))
     return false;
   
   // Class template (partial) specializations are never added as results.

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=98249&r1=98248&r2=98249&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Mar 11 01:50:04 2010
@@ -15,6 +15,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Parse/DeclSpec.h"
 #include "clang/Parse/Template.h"





More information about the cfe-commits mailing list