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

Douglas Gregor dgregor at apple.com
Wed Feb 16 23:58:36 PST 2011


Author: dgregor
Date: Thu Feb 17 01:58:36 2011
New Revision: 125735

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

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/include/clang/AST/DeclObjC.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=125735&r1=125734&r2=125735&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Feb 17 01:58:36 2011
@@ -430,7 +430,7 @@
     getOriginalNamespace()->OrigOrAnonNamespace.setPointer(D);
   }
 
-  virtual NamespaceDecl *getCanonicalDecl() { return getOriginalNamespace(); }
+  NamespaceDecl *getCanonicalDecl() { return getOriginalNamespace(); }
   const NamespaceDecl *getCanonicalDecl() const { 
     return getOriginalNamespace(); 
   }
@@ -779,7 +779,7 @@
     return getKind() != Decl::ParmVar && getDeclContext()->isRecord();
   }
 
-  virtual VarDecl *getCanonicalDecl();
+  VarDecl *getCanonicalDecl();
   const VarDecl *getCanonicalDecl() const {
     return const_cast<VarDecl*>(this)->getCanonicalDecl();
   }
@@ -1467,8 +1467,8 @@
 
   void setPreviousDeclaration(FunctionDecl * PrevDecl);
 
-  virtual const FunctionDecl *getCanonicalDecl() const;
-  virtual FunctionDecl *getCanonicalDecl();
+  const FunctionDecl *getCanonicalDecl() const;
+  FunctionDecl *getCanonicalDecl();
 
   unsigned getBuiltinID() const;
 
@@ -2073,7 +2073,7 @@
   SourceLocation getOuterLocStart() const;
   virtual SourceRange getSourceRange() const;
 
-  virtual TagDecl* getCanonicalDecl();
+  TagDecl* getCanonicalDecl();
   const TagDecl* getCanonicalDecl() const {
     return const_cast<TagDecl*>(this)->getCanonicalDecl();
   }

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=125735&r1=125734&r2=125735&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Feb 17 01:58:36 2011
@@ -477,7 +477,7 @@
   bool isDefinedOutsideFunctionOrMethod() const;
 
   /// \brief Retrieves the "canonical" declaration of the given declaration.
-  virtual Decl *getCanonicalDecl() { return this; }
+  Decl *getCanonicalDecl();
   const Decl *getCanonicalDecl() const {
     return const_cast<Decl*>(this)->getCanonicalDecl();
   }

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=125735&r1=125734&r2=125735&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Feb 17 01:58:36 2011
@@ -472,10 +472,10 @@
   typedef std::reverse_iterator<base_class_const_iterator>
     reverse_base_class_const_iterator;
 
-  virtual CXXRecordDecl *getCanonicalDecl() {
+  CXXRecordDecl *getCanonicalDecl() {
     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
   }
-  virtual const CXXRecordDecl *getCanonicalDecl() const {
+  const CXXRecordDecl *getCanonicalDecl() const {
     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
   }
   

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=125735&r1=125734&r2=125735&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Feb 17 01:58:36 2011
@@ -198,7 +198,7 @@
                                 ImplementationControl impControl = None,
                                 unsigned numSelectorArgs = 0);
 
-  virtual ObjCMethodDecl *getCanonicalDecl();
+  ObjCMethodDecl *getCanonicalDecl();
   const ObjCMethodDecl *getCanonicalDecl() const {
     return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
   }

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=125735&r1=125734&r2=125735&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Feb 17 01:58:36 2011
@@ -143,6 +143,29 @@
   return true;
 }
 
+namespace {
+  template<typename Class, typename Result>
+  inline Result *getSpecificCanonicalDecl(Decl *D, Result *(Class::*Get)()) {
+    return (llvm::cast<Class>(D)->*Get)();
+  }
+  
+  inline Decl *getSpecificCanonicalDecl(Decl *D, Decl *(Decl::*)()) {
+    // No specific implementation.
+    return D;
+  }
+}
+
+Decl *Decl::getCanonicalDecl() {
+  switch (getKind()) {
+#define ABSTRACT_DECL(Type)
+#define DECL(Type, Base) \
+    case Type:           \
+      return getSpecificCanonicalDecl(this, &Type##Decl::getCanonicalDecl);
+#include "clang/AST/DeclNodes.inc"
+  }
+  return this;
+  
+}
 
 //===----------------------------------------------------------------------===//
 // PrettyStackTraceDecl Implementation





More information about the cfe-commits mailing list