[cfe-commits] r81571 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseCXXInlineMethods.cpp lib/Parse/ParseDeclCXX.cpp lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp

John McCall rjmccall at apple.com
Fri Sep 11 14:02:39 PDT 2009


Author: rjmccall
Date: Fri Sep 11 16:02:39 2009
New Revision: 81571

URL: http://llvm.org/viewvc/llvm-project?rev=81571&view=rev
Log:
Alter Action's friend interface to prepare for templated friend declarations and
to stop making promises we can't currently keep.


Modified:
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=81571&r1=81570&r2=81571&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Sep 11 16:02:39 2009
@@ -1202,11 +1202,19 @@
     return DeclPtrTy();
   }
 
-  /// ActOnFriendDecl - This action is called when a friend declaration is
-  /// encountered.
-  virtual DeclPtrTy ActOnFriendDecl(Scope *S,
-                        llvm::PointerUnion<const DeclSpec*,Declarator*> D,
-                                    bool IsDefinition) {
+  /// ActOnFriendFunctionDecl - Parsed a friend function declarator.
+  /// The name is actually a slight misnomer, because the declarator
+  /// is not necessarily a function declarator.
+  virtual DeclPtrTy ActOnFriendFunctionDecl(Scope *S,
+                                            Declarator &D,
+                                            bool IsDefinition,
+                                            MultiTemplateParamsArg TParams) {
+    return DeclPtrTy();
+  }
+
+  /// ActOnFriendTypeDecl - Parsed a friend type declaration.
+  virtual DeclPtrTy ActOnFriendTypeDecl(Scope *S,
+                                        const DeclSpec &DS) {
     return DeclPtrTy();
   }
 

Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=81571&r1=81570&r2=81571&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Fri Sep 11 16:02:39 2009
@@ -34,7 +34,7 @@
   DeclPtrTy FnD;
   if (D.getDeclSpec().isFriendSpecified())
     // FIXME: Friend templates
-    FnD = Actions.ActOnFriendDecl(CurScope, &D, /*IsDefinition*/ true);
+    FnD = Actions.ActOnFriendFunctionDecl(CurScope, D, true, move(TemplateParams));
   else // FIXME: pass template information through
     FnD = Actions.ActOnCXXMemberDeclarator(CurScope, AS, D,
                                            move(TemplateParams), 0, 0);

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=81571&r1=81570&r2=81571&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri Sep 11 16:02:39 2009
@@ -1019,7 +1019,7 @@
       if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
         return;
       
-      Actions.ActOnFriendDecl(CurScope, &DS, /*IsDefinition*/ false);
+      Actions.ActOnFriendTypeDecl(CurScope, DS);
     } else
       Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
 
@@ -1122,15 +1122,17 @@
     // this call will *not* return the created decl; It will return null.
     // See Sema::ActOnCXXMemberDeclarator for details.
 
+    Action::MultiTemplateParamsArg TemplateParams(Actions,
+        TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0,
+        TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0);
+
     DeclPtrTy ThisDecl;
     if (DS.isFriendSpecified()) {
-      // TODO: handle initializers, bitfields, 'delete', friend templates
-      ThisDecl = Actions.ActOnFriendDecl(CurScope, &DeclaratorInfo,
-                                         /*IsDefinition*/ false);
+      // TODO: handle initializers, bitfields, 'delete'
+      ThisDecl = Actions.ActOnFriendFunctionDecl(CurScope, DeclaratorInfo,
+                                                 /*IsDefinition*/ false,
+                                                 move(TemplateParams));
     } else {
-      Action::MultiTemplateParamsArg TemplateParams(Actions,
-          TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0,
-          TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0);
       ThisDecl = Actions.ActOnCXXMemberDeclarator(CurScope, AS,
                                                   DeclaratorInfo,
                                                   move(TemplateParams),

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=81571&r1=81570&r2=81571&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Sep 11 16:02:39 2009
@@ -2245,12 +2245,9 @@
                                                  ExprArg AssertExpr,
                                                  ExprArg AssertMessageExpr);
 
-  virtual DeclPtrTy ActOnFriendDecl(Scope *S,
-                          llvm::PointerUnion<const DeclSpec*,Declarator*> D,
-                                    bool IsDefinition);
-  DeclPtrTy ActOnFriendTypeDecl(Scope *S, const DeclSpec& DS,
-                                bool IsDefinition);
-  DeclPtrTy ActOnFriendFunctionDecl(Scope *S, Declarator& D, bool IsDefinition);
+  DeclPtrTy ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS);
+  DeclPtrTy ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition,
+                                    MultiTemplateParamsArg TemplateParams);
 
   QualType CheckConstructorDeclarator(Declarator &D, QualType R,
                                       FunctionDecl::StorageClass& SC);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Sep 11 16:02:39 2009
@@ -4008,18 +4008,8 @@
   return DeclPtrTy::make(Decl);
 }
 
-Sema::DeclPtrTy Sema::ActOnFriendDecl(Scope *S,
-                       llvm::PointerUnion<const DeclSpec*,Declarator*> DU,
-                                      bool IsDefinition) {
-  if (DU.is<Declarator*>())
-    return ActOnFriendFunctionDecl(S, *DU.get<Declarator*>(), IsDefinition);
-  else
-    return ActOnFriendTypeDecl(S, *DU.get<const DeclSpec*>(), IsDefinition);
-}
-
 Sema::DeclPtrTy Sema::ActOnFriendTypeDecl(Scope *S,
-                                          const DeclSpec &DS,
-                                          bool IsDefinition) {
+                                          const DeclSpec &DS) {
   SourceLocation Loc = DS.getSourceRange().getBegin();
 
   assert(DS.isFriendSpecified());
@@ -4056,17 +4046,13 @@
     }
   }
 
+  bool IsDefinition = false;
   FriendDecl::FriendUnion FU = T.getTypePtr();
 
-  // The parser doesn't quite handle
-  //   friend class A { ... }
-  // optimally, because it might have been the (valid) prefix of
-  //   friend class A { ... } foo();
-  // So in a very particular set of circumstances, we need to adjust
-  // IsDefinition.
-  //
-  // Also, if we made a RecordDecl in ActOnTag, we want that to be the
-  // object of our friend declaration.
+  // We want to do a few things differently if the type was declared with
+  // a tag:  specifically, we want to use the associated RecordDecl as
+  // the object of our friend declaration, and we want to disallow
+  // class definitions.
   switch (DS.getTypeSpecType()) {
   default: break;
   case DeclSpec::TST_class:
@@ -4106,9 +4092,13 @@
   return DeclPtrTy::make(FD);
 }
 
-Sema::DeclPtrTy Sema::ActOnFriendFunctionDecl(Scope *S,
-                                              Declarator &D,
-                                              bool IsDefinition) {
+Sema::DeclPtrTy
+Sema::ActOnFriendFunctionDecl(Scope *S,
+                              Declarator &D,
+                              bool IsDefinition,
+                              MultiTemplateParamsArg TemplateParams) {
+  // FIXME: do something with template parameters
+
   const DeclSpec &DS = D.getDeclSpec();
 
   assert(DS.isFriendSpecified());





More information about the cfe-commits mailing list