aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/Decl.h10
-rw-r--r--include/clang/AST/DeclBase.h4
-rw-r--r--include/clang/AST/DeclCXX.h2
-rw-r--r--include/clang/AST/DeclObjC.h12
-rw-r--r--lib/AST/DeclBase.cpp26
5 files changed, 38 insertions, 16 deletions
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<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;
}
//===----------------------------------------------------------------------===//