[cfe-commits] r125740 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h include/clang/AST/DeclObjC.h include/clang/AST/DeclTemplate.h lib/AST/DeclBase.cpp

Douglas Gregor dgregor at apple.com
Thu Feb 17 00:47:29 PST 2011


Author: dgregor
Date: Thu Feb 17 02:47:29 2011
New Revision: 125740

URL: http://llvm.org/viewvc/llvm-project?rev=125740&view=rev
Log:
Devirtualize Decl::getNextRedeclaration().

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/AST/DeclTemplate.h
    cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=125740&r1=125739&r2=125740&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Feb 17 02:47:29 2011
@@ -674,8 +674,9 @@
   }
 
   typedef Redeclarable<VarDecl> redeclarable_base;
-  virtual VarDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
-
+  VarDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
+  friend class Decl;
+  
 public:
   typedef redeclarable_base::redecl_iterator redecl_iterator;
   redecl_iterator redecls_begin() const {
@@ -1310,9 +1311,12 @@
       DNLoc(NameInfo.getInfo()) {}
 
   typedef Redeclarable<FunctionDecl> redeclarable_base;
-  virtual FunctionDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
+  FunctionDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
 
+  friend class Decl;
+                       
 public:
+                       
   typedef redeclarable_base::redecl_iterator redecl_iterator;
   redecl_iterator redecls_begin() const {
     return redeclarable_base::redecls_begin();
@@ -1921,8 +1925,10 @@
 
 protected:
   typedef Redeclarable<TypedefDecl> redeclarable_base;
-  virtual TypedefDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
+  TypedefDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
 
+  friend class Decl;
+  
 public:
   typedef redeclarable_base::redecl_iterator redecl_iterator;
   redecl_iterator redecls_begin() const {
@@ -2042,12 +2048,14 @@
   }
 
   typedef Redeclarable<TagDecl> redeclarable_base;
-  virtual TagDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
+  TagDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
 
   /// @brief Completes the definition of this tag declaration.
   ///
   /// This is a helper function for derived classes.
   void completeDefinition();    
+  
+  friend class Decl;
     
 public:
   typedef redeclarable_base::redecl_iterator redecl_iterator;

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=125740&r1=125739&r2=125740&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Feb 17 02:47:29 2011
@@ -271,7 +271,7 @@
   }
 
   virtual ~Decl();
-
+  
 public:
 
   /// \brief Source range that this declaration covers.
@@ -488,7 +488,7 @@
   ///
   /// Decl subclasses that can be redeclared should override this method so that
   /// Decl::redecl_iterator can iterate over them.
-  virtual Decl *getNextRedeclaration() { return this; }
+  Decl *getNextRedeclaration();
 
 public:
   /// \brief Iterates through all the redeclarations of the same decl.

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=125740&r1=125739&r2=125740&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Feb 17 02:47:29 2011
@@ -182,8 +182,9 @@
   /// \brief A definition will return its interface declaration.
   /// An interface declaration will return its definition.
   /// Otherwise it will return itself.
-  virtual ObjCMethodDecl *getNextRedeclaration();
-
+  ObjCMethodDecl *getNextRedeclaration();
+  friend class Decl;
+  
 public:
   static ObjCMethodDecl *Create(ASTContext &C,
                                 SourceLocation beginLoc,

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=125740&r1=125739&r2=125740&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Thu Feb 17 02:47:29 2011
@@ -651,7 +651,7 @@
     return getInstantiatedFromMemberTemplateImpl();
   }
 
-  virtual RedeclarableTemplateDecl *getNextRedeclaration();
+  RedeclarableTemplateDecl *getNextRedeclaration();
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=125740&r1=125739&r2=125740&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Feb 17 02:47:29 2011
@@ -191,6 +191,78 @@
   return this;  
 }
 
+Decl *Decl::getNextRedeclaration() {
+  switch (getKind()) {
+  case Var: 
+    return static_cast<VarDecl *>(this)->getNextRedeclaration();
+      
+  case Function:
+  case CXXMethod:
+  case CXXConstructor:
+  case CXXDestructor:
+  case CXXConversion:
+    return static_cast<FunctionDecl *>(this)->getNextRedeclaration();
+     
+  case Typedef:
+    return static_cast<TypedefDecl *>(this)->getNextRedeclaration();
+      
+  case Enum:
+  case Record:
+  case CXXRecord:
+  case ClassTemplateSpecialization:
+  case ClassTemplatePartialSpecialization:
+    return static_cast<TagDecl *>(this)->getNextRedeclaration();
+
+  case ObjCMethod:
+    return static_cast<ObjCMethodDecl *>(this)->getNextRedeclaration();
+      
+  case FunctionTemplate:
+  case ClassTemplate:
+    return static_cast<RedeclarableTemplateDecl *>(this)
+                                                      ->getNextRedeclaration();
+      
+  case Namespace:
+  case UsingDirective:
+  case NamespaceAlias:
+  case Label:
+  case UnresolvedUsingTypename:
+  case TemplateTypeParm:
+  case EnumConstant:
+  case UnresolvedUsingValue:
+  case IndirectField:
+  case Field:
+  case ObjCIvar:
+  case ObjCAtDefsField:
+  case ImplicitParam:
+  case ParmVar:
+  case NonTypeTemplateParm:
+  case TemplateTemplateParm:
+  case Using:
+  case UsingShadow:
+  case ObjCCategory:
+  case ObjCProtocol:
+  case ObjCInterface:
+  case ObjCCategoryImpl:
+  case ObjCImplementation:
+  case ObjCProperty:
+  case ObjCCompatibleAlias:
+  case LinkageSpec:
+  case ObjCPropertyImpl:
+  case ObjCForwardProtocol:
+  case ObjCClass:
+  case FileScopeAsm:
+  case AccessSpec:
+  case Friend:
+  case FriendTemplate:
+  case StaticAssert:
+  case Block:
+  case TranslationUnit:
+    return this;
+  }
+  
+  return this;  
+}
+
 //===----------------------------------------------------------------------===//
 // PrettyStackTraceDecl Implementation
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list