diff options
author | Steve Naroff <snaroff@apple.com> | 2008-10-08 17:01:13 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-10-08 17:01:13 +0000 |
commit | 56ee6896f2efebffb4a2cce5a7610cdf1eddbbbe (patch) | |
tree | 27e5894e15c4faaea557fd1f88702f626aea2fed /include/clang/AST/Decl.h | |
parent | 178927517fa09ddbb04dc8ef725b5716c18aae21 (diff) |
- Add BlockDecl AST node.
- Modify BlockExpr to reference the BlockDecl.
This is "cleanup" necessary to improve our lookup semantics for blocks (to fix <rdar://problem/6272905> clang block rewriter: parameter to function not imported into block?).
Still some follow-up work to finish this (forthcoming).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57298 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/AST/Decl.h')
-rw-r--r-- | include/clang/AST/Decl.h | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index b0acc4c1b7..88cbe85421 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -16,10 +16,12 @@ #include "clang/AST/DeclBase.h" #include "clang/Parse/AccessSpecifier.h" +#include "llvm/ADT/SmallVector.h" namespace clang { class Expr; class Stmt; +class CompoundStmt; class StringLiteral; class IdentifierInfo; @@ -981,6 +983,51 @@ protected: void ReadInRec(llvm::Deserializer& D, ASTContext& C); }; -} // end namespace clang +/// BlockDecl - This represents a block literal declaration, which is like an +/// unnamed FunctionDecl. For example: +/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } +/// +class BlockDecl : public Decl, public DeclContext { + llvm::SmallVector<ParmVarDecl*, 8> Args; + Stmt *Body; +protected: + BlockDecl(DeclContext *DC, SourceLocation CaretLoc, + ParmVarDecl **args, unsigned numargs, Stmt *body) + : Decl(Block, CaretLoc), DeclContext(Block), + Args(args, args+numargs), Body(body) {} + virtual ~BlockDecl(); + virtual void Destroy(ASTContext& C); + +public: + static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, + ParmVarDecl **args, unsigned numargs, + CompoundStmt *body); + + SourceLocation getCaretLocation() const { return getLocation(); } + + Stmt *getBody() const { return Body; } + + /// arg_iterator - Iterate over the ParmVarDecl's for this block. + typedef llvm::SmallVector<ParmVarDecl*, 8>::const_iterator param_iterator; + bool param_empty() const { return Args.empty(); } + param_iterator param_begin() const { return Args.begin(); } + param_iterator param_end() const { return Args.end(); } + + // Implement isa/cast/dyncast/etc. + static bool classof(const Decl *D) { return D->getKind() == Block; } + static bool classof(const TranslationUnitDecl *D) { return true; } + +protected: + /// EmitImpl - Serialize this BlockDecl. Called by Decl::Emit. + virtual void EmitImpl(llvm::Serializer& S) const; + + /// CreateImpl - Deserialize a BlockDecl. Called by Decl::Create. + static BlockDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C); + + friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C); +}; + +} // end namespace clang + #endif |