diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-02-17 07:13:24 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-02-17 07:13:24 +0000 |
| commit | f7b2c93b2f50270fa921c6c90358e92ad3b1c702 (patch) | |
| tree | d6abddc78360b4ac70df6722cb95dbf907b02b14 | |
| parent | a43942a48e585b7b7cd9e638ce6184bbded3ddc1 (diff) | |
| download | bcm5719-llvm-f7b2c93b2f50270fa921c6c90358e92ad3b1c702.tar.gz bcm5719-llvm-f7b2c93b2f50270fa921c6c90358e92ad3b1c702.zip | |
Devirtualize Decl::getBody() and Decl::hasBody().
llvm-svn: 125731
| -rw-r--r-- | clang/include/clang/AST/Decl.h | 4 | ||||
| -rw-r--r-- | clang/include/clang/AST/DeclBase.h | 4 | ||||
| -rw-r--r-- | clang/include/clang/AST/DeclObjC.h | 2 | ||||
| -rw-r--r-- | clang/lib/AST/DeclBase.cpp | 18 |
4 files changed, 23 insertions, 5 deletions
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 7140e808efa..cba71ae8cd6 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -1332,7 +1332,7 @@ public: /// 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 @@ public: /// 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); } diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index 472cb3bb747..3e92c4e6511 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -545,11 +545,11 @@ public: /// 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. diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index 2c784f25546..81f5d39bf24 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -300,7 +300,7 @@ public: return ImplementationControl(DeclImplementation); } - virtual Stmt *getBody() const { + Stmt *getBody() const { return (Stmt*) Body; } CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; } diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index a95ea3f6463..110de64d8cd 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -429,6 +429,24 @@ DeclContext *Decl::castToDeclContext(const Decl *D) { } } +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. |

