aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
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