diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-07-07 11:31:19 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-07-07 11:31:19 +0000 |
commit | 06a54a38be5054c910ffc92db60edab23f9ea105 (patch) | |
tree | c642601a2175dfa53f514de088777aae1d4b00ee /include | |
parent | bc56d1f6e2288aea9546b2380c71288939d688ca (diff) |
Introduce Decl::hasBody() and FunctionDecl::hasBody() and use them instead of getBody() when we are just checking the existence of a body, to avoid de-serialization of the body from PCH.
Makes de-serialization of the function body even more "lazier".
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107768 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/AST/Decl.h | 14 | ||||
-rw-r--r-- | include/clang/AST/DeclBase.h | 4 |
2 files changed, 18 insertions, 0 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 940f1b9187..d5a7ec029d 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1227,11 +1227,25 @@ public: EndRangeLoc = E; } + /// \brief Returns true if the function has a body (definition). The + /// function body might be in any of the (re-)declarations of this + /// function. The variant that accepts a FunctionDecl pointer will + /// set that function declaration to the actual declaration + /// containing the body (if there is one). + bool hasBody(const FunctionDecl *&Definition) const; + + virtual bool hasBody() const { + const FunctionDecl* Definition; + return hasBody(Definition); + } + /// getBody - Retrieve the body (definition) of the function. The /// function body might be in any of the (re-)declarations of this /// function. The variant that accepts a FunctionDecl pointer will /// set that function declaration to the actual declaration /// containing the body (if there is one). + /// NOTE: For checking if there is a body, use hasBody() instead, to avoid + /// unnecessary PCH de-serialization of the body. Stmt *getBody(const FunctionDecl *&Definition) const; virtual Stmt *getBody() const { diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index f4d76f5241..317db014a6 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -488,6 +488,10 @@ public: /// top-level Stmt* of that body. Otherwise this method returns null. virtual Stmt* getBody() const { return 0; } + /// \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; } + /// getCompoundBody - Returns getBody(), dyn_casted to a CompoundStmt. CompoundStmt* getCompoundBody() const; |