[cfe-commits] r125736 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h include/clang/AST/DeclCXX.h include/clang/AST/DeclObjC.h lib/AST/DeclBase.cpp
Douglas Gregor
dgregor at apple.com
Thu Feb 17 00:12:32 PST 2011
Author: dgregor
Date: Thu Feb 17 02:12:32 2011
New Revision: 125736
URL: http://llvm.org/viewvc/llvm-project?rev=125736&view=rev
Log:
Devirtualize Decl::getSourceRange()
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/DeclBase.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=125736&r1=125735&r2=125736&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Feb 17 02:12:32 2011
@@ -435,7 +435,7 @@
return getOriginalNamespace();
}
- virtual SourceRange getSourceRange() const {
+ SourceRange getSourceRange() const {
return SourceRange(getLocation(), RBracLoc);
}
@@ -691,7 +691,7 @@
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 @@
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 @@
/// 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 @@
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()); }
Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=125736&r1=125735&r2=125736&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Feb 17 02:12:32 2011
@@ -275,9 +275,7 @@
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(); }
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=125736&r1=125735&r2=125736&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Feb 17 02:12:32 2011
@@ -1922,7 +1922,7 @@
SourceLocation IdentLoc,
NamedDecl *Namespace);
- virtual SourceRange getSourceRange() const {
+ SourceRange getSourceRange() const {
return SourceRange(NamespaceLoc, IdentLoc);
}
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=125736&r1=125735&r2=125736&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Feb 17 02:12:32 2011
@@ -217,7 +217,7 @@
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 @@
AtEnd = atEnd;
}
- virtual SourceRange getSourceRange() const {
+ SourceRange getSourceRange() const {
return SourceRange(getLocation(), getAtEndRange().getEnd());
}
@@ -883,7 +883,7 @@
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 @@
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 @@
return PropertyIvarDecl;
}
- virtual SourceRange getSourceRange() const {
+ SourceRange getSourceRange() const {
return SourceRange(AtLoc, getLocation());
}
@@ -1541,7 +1541,7 @@
ObjCIvarDecl *ivarDecl,
SourceLocation ivarLoc);
- virtual SourceRange getSourceRange() const;
+ SourceRange getSourceRange() const;
SourceLocation getLocStart() const { return AtLoc; }
void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=125736&r1=125735&r2=125736&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Feb 17 02:12:32 2011
@@ -42,6 +42,30 @@
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 @@
return getSpecificCanonicalDecl(this, &Type##Decl::getCanonicalDecl);
#include "clang/AST/DeclNodes.inc"
}
- return this;
+ return this;
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list