]> granicus.if.org Git - clang/commitdiff
Devirtualize Decl::getSourceRange()
authorDouglas Gregor <dgregor@apple.com>
Thu, 17 Feb 2011 08:12:32 +0000 (08:12 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 17 Feb 2011 08:12:32 +0000 (08:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125736 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
include/clang/AST/DeclBase.h
include/clang/AST/DeclCXX.h
include/clang/AST/DeclObjC.h
lib/AST/DeclBase.cpp

index b762be601e63f6d22e90d1f6a834e4c8def999fa..a90d09061cd8fe5ee323d40de944ab0bb11d2e69 100644 (file)
@@ -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()); }
index 2ce43cb378b071c13e5233829c54bf9a2201b648..8d64cb50892901d37327c4ed36429414b46940ba 100644 (file)
@@ -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(); }
 
index 61f71e98659b92f5c3ba1b8cde6934b70d453ffb..64bb1cbca32f8f2d759857bf2b0b35528a23d191 100644 (file)
@@ -1922,7 +1922,7 @@ public:
                                     SourceLocation IdentLoc,
                                     NamedDecl *Namespace);
 
-  virtual SourceRange getSourceRange() const {
+  SourceRange getSourceRange() const {
     return SourceRange(NamespaceLoc, IdentLoc);
   }
   
index df89b6f2a19977e8927ea32dfdbbbfa75433107e..e46a74f598d3644a3ab8c586b94e0b01ba18105a 100644 (file)
@@ -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; }
index d8b7c9b5b00b9aac1eb7de671a41f43e685479be..76bb2d5ddf651639d24da2cde4f33d5796530d4e 100644 (file)
@@ -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;  
 }
 
 //===----------------------------------------------------------------------===//