aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-17 07:58:36 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-17 07:58:36 +0000
commit0eccdcac47f0ee1d2081244ca714088779b09b98 (patch)
tree36ca836123135c1b4521fd5ac372bad7729fb082 /lib/AST/DeclBase.cpp
parentad8dcf4a9df0e24051dc31bf9e6f3cd138a34298 (diff)
Devirtualize Decl::getCanonicalDecl().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125735 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r--lib/AST/DeclBase.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index dfc5a6ae5d..d8b7c9b5b0 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -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