[cfe-commits] r125731 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h include/clang/AST/DeclObjC.h lib/AST/DeclBase.cpp

Douglas Gregor dgregor at apple.com
Wed Feb 16 23:13:24 PST 2011


Author: dgregor
Date: Thu Feb 17 01:13:24 2011
New Revision: 125731

URL: http://llvm.org/viewvc/llvm-project?rev=125731&view=rev
Log:
Devirtualize Decl::getBody() and Decl::hasBody().

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclBase.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=125731&r1=125730&r2=125731&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Feb 17 01:13:24 2011
@@ -1332,7 +1332,7 @@
   /// containing the body (if there is one).
   bool hasBody(const FunctionDecl *&Definition) const;
 
-  virtual bool hasBody() const {
+  bool hasBody() const {
     const FunctionDecl* Definition;
     return hasBody(Definition);
   }
@@ -1346,7 +1346,7 @@
   /// unnecessary AST de-serialization of the body.
   Stmt *getBody(const FunctionDecl *&Definition) const;
 
-  virtual Stmt *getBody() const {
+  Stmt *getBody() const {
     const FunctionDecl* Definition;
     return getBody(Definition);
   }

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=125731&r1=125730&r2=125731&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Feb 17 01:13:24 2011
@@ -545,11 +545,11 @@
   /// getBody - If this Decl represents a declaration for a body of code,
   ///  such as a function or method definition, this method returns the
   ///  top-level Stmt* of that body.  Otherwise this method returns null.
-  virtual Stmt* getBody() const { return 0; }
+  Stmt* getBody() const;
 
   /// \brief Returns true if this Decl represents a declaration for a body of
   /// code, such as a function or method definition.
-  virtual bool hasBody() const { return getBody() != 0; }
+  bool hasBody() const;
 
   /// getBodyRBrace - Gets the right brace of the body, if a body exists.
   /// This works whether the body is a CompoundStmt or a CXXTryStmt.

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=125731&r1=125730&r2=125731&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Feb 17 01:13:24 2011
@@ -300,7 +300,7 @@
     return ImplementationControl(DeclImplementation);
   }
 
-  virtual Stmt *getBody() const {
+  Stmt *getBody() const {
     return (Stmt*) Body;
   }
   CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=125731&r1=125730&r2=125731&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Feb 17 01:13:24 2011
@@ -429,6 +429,24 @@
   }
 }
 
+Stmt *Decl::getBody() const {
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this))
+    return FD->getBody();
+  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(this))
+    return MD->getBody();
+  if (const BlockDecl *BD = dyn_cast<BlockDecl>(this))
+    return BD->getBody();
+  
+  return 0;
+}
+
+bool Decl::hasBody() const {
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this))
+    return FD->hasBody();
+  
+  return getBody() != 0;
+}
+
 SourceLocation Decl::getBodyRBrace() const {
   // Special handling of FunctionDecl to avoid de-serializing the body from PCH.
   // FunctionDecl stores EndRangeLoc for this purpose.





More information about the cfe-commits mailing list