From: Douglas Gregor Date: Thu, 17 Feb 2011 08:12:32 +0000 (+0000) Subject: Devirtualize Decl::getSourceRange() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=770877fa855d1de462392e503ef08252614b0994;p=clang Devirtualize Decl::getSourceRange() git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125736 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index b762be601e..a90d09061c 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -435,7 +435,7 @@ public: return getOriginalNamespace(); } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getLocation(), RBracLoc); } @@ -691,7 +691,7 @@ public: StorageClass SCAsWritten); virtual SourceLocation getInnerLocStart() const; - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; StorageClass getStorageClass() const { return (StorageClass)SClass; } StorageClass getStorageClassAsWritten() const { @@ -1349,7 +1349,7 @@ public: const PrintingPolicy &Policy, bool Qualified) const; - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getOuterLocStart(), EndRangeLoc); } void setLocEnd(SourceLocation E) { @@ -2071,7 +2071,7 @@ public: /// getOuterLocStart - Return SourceLocation representing start of source /// range taking into account any outer template declarations. SourceLocation getOuterLocStart() const; - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; TagDecl* getCanonicalDecl(); const TagDecl* getCanonicalDecl() const { @@ -2646,7 +2646,7 @@ public: const Capture *end, bool capturesCXXThis); - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 2ce43cb378..8d64cb5089 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -275,9 +275,7 @@ protected: public: /// \brief Source range that this declaration covers. - virtual SourceRange getSourceRange() const { - return SourceRange(getLocation(), getLocation()); - } + SourceRange getSourceRange() const; SourceLocation getLocStart() const { return getSourceRange().getBegin(); } SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 61f71e9865..64bb1cbca3 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -1922,7 +1922,7 @@ public: SourceLocation IdentLoc, NamedDecl *Namespace); - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(NamespaceLoc, IdentLoc); } diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index df89b6f2a1..e46a74f598 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -217,7 +217,7 @@ public: SourceLocation getLocStart() const { return getLocation(); } SourceLocation getLocEnd() const { return EndLoc; } void setEndLoc(SourceLocation Loc) { EndLoc = Loc; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getLocation(), EndLoc); } @@ -393,7 +393,7 @@ public: AtEnd = atEnd; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getLocation(), getAtEndRange().getEnd()); } @@ -883,7 +883,7 @@ public: const SourceLocation *Locs = 0, unsigned nElts = 0); - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; typedef const ObjCClassRef* iterator; iterator begin() const { return ForwardDecls; } @@ -1064,7 +1064,7 @@ public: SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; } void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(AtLoc, getAtEndRange().getEnd()); } @@ -1475,7 +1475,7 @@ public: return PropertyIvarDecl; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(AtLoc, getLocation()); } @@ -1541,7 +1541,7 @@ public: ObjCIvarDecl *ivarDecl, SourceLocation ivarLoc); - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; SourceLocation getLocStart() const { return AtLoc; } void setAtLoc(SourceLocation Loc) { AtLoc = Loc; } 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 + inline SourceRange getSourceRangeImpl(const Decl *D, + SourceRange (Class::*)() const) { + return static_cast(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; } //===----------------------------------------------------------------------===//