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

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

index e0ffa627ac211d48dd3fa333072ed931f044700a..b762be601e63f6d22e90d1f6a834e4c8def999fa 100644 (file)
@@ -430,7 +430,7 @@ public:
     getOriginalNamespace()->OrigOrAnonNamespace.setPointer(D);
   }
 
-  virtual NamespaceDecl *getCanonicalDecl() { return getOriginalNamespace(); }
+  NamespaceDecl *getCanonicalDecl() { return getOriginalNamespace(); }
   const NamespaceDecl *getCanonicalDecl() const { 
     return getOriginalNamespace(); 
   }
@@ -779,7 +779,7 @@ public:
     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 @@ public:
 
   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 @@ public:
   SourceLocation getOuterLocStart() const;
   virtual SourceRange getSourceRange() const;
 
-  virtual TagDecl* getCanonicalDecl();
+  TagDecl* getCanonicalDecl();
   const TagDecl* getCanonicalDecl() const {
     return const_cast<TagDecl*>(this)->getCanonicalDecl();
   }
index 1407dadd16cfdb984de2e097e73e0dc4c2261f2e..2ce43cb378b071c13e5233829c54bf9a2201b648 100644 (file)
@@ -477,7 +477,7 @@ public:
   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();
   }
index d11ee8f7fd64866bf85979679968507c62af1ae0..61f71e98659b92f5c3ba1b8cde6934b70d453ffb 100644 (file)
@@ -472,10 +472,10 @@ public:
   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());
   }
   
index 81f5d39bf24cd232ec703336f987d3d7e8b9ad56..df89b6f2a19977e8927ea32dfdbbbfa75433107e 100644 (file)
@@ -198,7 +198,7 @@ public:
                                 ImplementationControl impControl = None,
                                 unsigned numSelectorArgs = 0);
 
-  virtual ObjCMethodDecl *getCanonicalDecl();
+  ObjCMethodDecl *getCanonicalDecl();
   const ObjCMethodDecl *getCanonicalDecl() const {
     return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
   }
index dfc5a6ae5d314d4386d9e8dcc61647df9f859e4e..d8b7c9b5b00b9aac1eb7de671a41f43e685479be 100644 (file)
@@ -143,6 +143,29 @@ bool Decl::isDefinedOutsideFunctionOrMethod() const {
   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