diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-02-17 08:12:32 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-02-17 08:12:32 +0000 |
commit | 770877fa855d1de462392e503ef08252614b0994 (patch) | |
tree | 514f986ba5a53cfd468726168a03be45e0df24b8 /lib/AST/DeclBase.cpp | |
parent | 0eccdcac47f0ee1d2081244ca714088779b09b98 (diff) |
Devirtualize Decl::getSourceRange()
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125736 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r-- | lib/AST/DeclBase.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index d8b7c9b5b0..76bb2d5ddf 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -42,6 +42,30 @@ using namespace clang; static bool StatSwitch = false; +namespace { + template<typename Class> + inline SourceRange getSourceRangeImpl(const Decl *D, + SourceRange (Class::*)() const) { + return static_cast<const Class *>(D)->getSourceRange(); + } + + inline SourceRange getSourceRangeImpl(const Decl *D, + SourceRange (Decl::*)() const) { + return D->getLocation(); + } +} + +SourceRange Decl::getSourceRange() const { + switch (getKind()) { +#define ABSTRACT_DECL(Type) +#define DECL(Type, Base) \ + case Type: return getSourceRangeImpl(this, &Type##Decl::getSourceRange); +#include "clang/AST/DeclNodes.inc" + } + + return getLocation(); +} + const char *Decl::getDeclKindName() const { switch (DeclKind) { default: assert(0 && "Declaration not in DeclNodes.inc!"); @@ -163,8 +187,8 @@ Decl *Decl::getCanonicalDecl() { return getSpecificCanonicalDecl(this, &Type##Decl::getCanonicalDecl); #include "clang/AST/DeclNodes.inc" } - return this; + return this; } //===----------------------------------------------------------------------===// |