[cfe-commits] r114889 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclBase.cpp lib/AST/DeclCXX.cpp lib/Sema/SemaDeclCXX.cpp

Douglas Gregor dgregor at apple.com
Mon Sep 27 14:17:54 PDT 2010


Author: dgregor
Date: Mon Sep 27 16:17:54 2010
New Revision: 114889

URL: http://llvm.org/viewvc/llvm-project?rev=114889&view=rev
Log:
Clean up the handling of the DeclaredDefaultConstructor and
DeclaredCopyConstructor bits in CXXRecordDecl's DefinitionData
structure. Rather than having Sema call addedConstructor or set the
bits directly at semi-random places, move all of the logic for
managing these bits into CXXRecordDecl itself and tie the
addedConstructor call into DeclContext::addDecl().

This makes it easier for AST-building clients to get the right bits
set in DefinitionData, and is one small part of <rdar://problem/8459981>.


Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/AST/DeclBase.cpp
    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=114889&r1=114888&r2=114889&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Sep 27 16:17:54 2010
@@ -404,6 +404,16 @@
   void CheckConversionFunction(NamedDecl *D);
 #endif
   
+  friend class DeclContext;
+  
+  /// \brief Notify the class that another constructor has
+  /// been added. 
+  ///
+  /// This routine helps maintain information about the class based on which 
+  /// constructors have been added. It will be invoked by DeclContext::addDecl()
+  /// whenever a constructor is added to this record.
+  void addedConstructor(CXXConstructorDecl *ConDecl);  
+  
 protected:
   CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
                 SourceLocation L, IdentifierInfo *Id,
@@ -558,12 +568,6 @@
     return data().DeclaredDefaultConstructor;
   }
   
-  /// \brief Note whether this class has already had its default constructor 
-  /// implicitly declared or doesn't need one.
-  void setDeclaredDefaultConstructor(bool DDC) {
-    data().DeclaredDefaultConstructor = DDC;
-  }
-  
   /// hasConstCopyConstructor - Determines whether this class has a
   /// copy constructor that accepts a const-qualified argument.
   bool hasConstCopyConstructor(ASTContext &Context) const;
@@ -584,11 +588,6 @@
   /// a unique copy-assignment operator could not be found.
   CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const;
   
-  /// addedConstructor - Notify the class that another constructor has
-  /// been added. This routine helps maintain information about the
-  /// class based on which constructors have been added.
-  void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
-
   /// hasUserDeclaredConstructor - Whether this class has any
   /// user-declared constructors. When true, a default constructor
   /// will not be implicitly declared.
@@ -611,12 +610,6 @@
     return data().DeclaredCopyConstructor;
   }
   
-  /// \brief Note whether this class has already had its copy constructor 
-  /// declared.
-  void setDeclaredCopyConstructor(bool DCC) {
-    data().DeclaredCopyConstructor = DCC;
-  }
-  
   /// addedAssignmentOperator - Notify the class that another assignment
   /// operator has been added. This routine helps maintain information about the
   /// class based on which operators have been added.

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=114889&r1=114888&r2=114889&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Mon Sep 27 16:17:54 2010
@@ -778,6 +778,14 @@
   } else {
     FirstDecl = LastDecl = D;
   }
+  
+  if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this)) {
+    Decl *InnerD = D;
+    if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
+      InnerD = FunTmpl->getTemplatedDecl();
+    if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(InnerD))
+      Record->addedConstructor(Constructor);
+  }
 }
 
 void DeclContext::addDecl(Decl *D) {

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=114889&r1=114888&r2=114889&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Mon Sep 27 16:17:54 2010
@@ -259,9 +259,25 @@
 }
 
 void
-CXXRecordDecl::addedConstructor(ASTContext &Context,
-                                CXXConstructorDecl *ConDecl) {
-  assert(!ConDecl->isImplicit() && "addedConstructor - not for implicit decl");
+CXXRecordDecl::addedConstructor(CXXConstructorDecl *Constructor) {
+  // Ignore friends.
+  if (Constructor->getFriendObjectKind())
+    return;
+  
+  if (Constructor->isImplicit()) {
+    // If this is the implicit default constructor, note that we have now
+    // declared it.
+    if (Constructor->isDefaultConstructor())
+      data().DeclaredDefaultConstructor = true;
+    // If this is the implicit copy constructor, note that we have now
+    // declared it.
+    else if (Constructor->isCopyConstructor())
+      data().DeclaredCopyConstructor = true;
+    
+    // Nothing else to do for implicitly-declared constructors.
+    return;
+  }
+  
   // Note that we have a user-declared constructor.
   data().UserDeclaredConstructor = true;
 
@@ -285,7 +301,8 @@
 
   // Note when we have a user-declared copy constructor, which will
   // suppress the implicit declaration of a copy constructor.
-  if (ConDecl->isCopyConstructor()) {
+  if (!Constructor->getDescribedFunctionTemplate() &&
+      Constructor->isCopyConstructor()) {
     data().UserDeclaredCopyConstructor = true;
     data().DeclaredCopyConstructor = true;
     
@@ -293,7 +310,6 @@
     //   A copy constructor is trivial if it is implicitly declared.
     // FIXME: C++0x: don't do this for "= default" copy constructors.
     data().HasTrivialCopyConstructor = false;
-    
   }
 }
 

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=114889&r1=114888&r2=114889&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Sep 27 16:17:54 2010
@@ -2985,13 +2985,6 @@
       Constructor->setInvalidDecl();
     }
   }
-
-  // Notify the class that we've added a constructor.  In principle we
-  // don't need to do this for out-of-line declarations; in practice
-  // we only instantiate the most recent declaration of a method, so
-  // we have to call this for everything but friends.
-  if (!Constructor->getFriendObjectKind())
-    ClassDecl->addedConstructor(Context, Constructor);
 }
 
 /// CheckDestructor - Checks a fully-formed destructor definition for
@@ -4441,7 +4434,6 @@
   DefaultCon->setTrivial(ClassDecl->hasTrivialConstructor());
   
   // Note that we have declared this constructor.
-  ClassDecl->setDeclaredDefaultConstructor(true);
   ++ASTContext::NumImplicitDefaultConstructorsDeclared;
   
   if (Scope *S = getScopeForContext(ClassDecl))
@@ -5412,7 +5404,6 @@
   CopyConstructor->setTrivial(ClassDecl->hasTrivialCopyConstructor());
   
   // Note that we have declared this constructor.
-  ClassDecl->setDeclaredCopyConstructor(true);
   ++ASTContext::NumImplicitCopyConstructorsDeclared;
   
   // Add the parameter to the constructor.





More information about the cfe-commits mailing list