]> granicus.if.org Git - clang/commitdiff
Devirtualize Decl::getNextRedeclaration().
authorDouglas Gregor <dgregor@apple.com>
Thu, 17 Feb 2011 08:47:29 +0000 (08:47 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 17 Feb 2011 08:47:29 +0000 (08:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125740 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
include/clang/AST/DeclBase.h
include/clang/AST/DeclObjC.h
include/clang/AST/DeclTemplate.h
lib/AST/DeclBase.cpp

index a90d09061cd8fe5ee323d40de944ab0bb11d2e69..68d20510ea9fe4ab05164237030647ade7ace778 100644 (file)
@@ -674,8 +674,9 @@ protected:
   }
 
   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 @@ protected:
       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 @@ class TypedefDecl : public TypeDecl, public Redeclarable<TypedefDecl> {
 
 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 @@ protected:
   }
 
   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;
index 8d64cb50892901d37327c4ed36429414b46940ba..c67391653a8e8ee03a98d811825e3d45c1049fd5 100644 (file)
@@ -271,7 +271,7 @@ protected:
   }
 
   virtual ~Decl();
-
+  
 public:
 
   /// \brief Source range that this declaration covers.
@@ -488,7 +488,7 @@ protected:
   ///
   /// 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.
index e46a74f598d3644a3ab8c586b94e0b01ba18105a..2ddb68482f91653bdb40cf7693853a13cda9a51b 100644 (file)
@@ -182,8 +182,9 @@ private:
   /// \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,
index 176c6badae16fc2f4077792dc9f950160e359d6d..774258711ca6c8535722bc85d09fd1e33e4df9d2 100644 (file)
@@ -651,7 +651,7 @@ public:
     return getInstantiatedFromMemberTemplateImpl();
   }
 
-  virtual RedeclarableTemplateDecl *getNextRedeclaration();
+  RedeclarableTemplateDecl *getNextRedeclaration();
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
index 5a117ebbf2f803be84ad2539971ff5fe62801a79..437089a415f26af02a7e51bc3079c949fd9394d1 100644 (file)
@@ -191,6 +191,78 @@ Decl *Decl::getCanonicalDecl() {
   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
 //===----------------------------------------------------------------------===//