diff options
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/AST/Decl.h | 33 | ||||
-rw-r--r-- | include/clang/AST/Expr.h | 10 | ||||
-rw-r--r-- | include/clang/Sema/ScopeInfo.h | 13 |
3 files changed, 41 insertions, 15 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index a34a2ef535..485883e18b 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -2495,6 +2495,7 @@ public: class BlockDecl : public Decl, public DeclContext { // FIXME: This can be packed into the bitfields in Decl. bool IsVariadic : 1; + bool CapturesCXXThis : 1; /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal /// parameters of this function. This is null if a prototype or if there are /// no formals. @@ -2504,11 +2505,15 @@ class BlockDecl : public Decl, public DeclContext { Stmt *Body; TypeSourceInfo *SignatureAsWritten; + VarDecl **CapturedDecls; + unsigned NumCapturedDecls; + protected: BlockDecl(DeclContext *DC, SourceLocation CaretLoc) : Decl(Block, DC, CaretLoc), DeclContext(Block), - IsVariadic(false), ParamInfo(0), NumParams(0), Body(0), - SignatureAsWritten(0) {} + IsVariadic(false), CapturesCXXThis(false), + ParamInfo(0), NumParams(0), Body(0), + SignatureAsWritten(0), CapturedDecls(0), NumCapturedDecls(0) {} public: static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); @@ -2537,7 +2542,7 @@ public: param_const_iterator param_begin() const { return ParamInfo; } param_const_iterator param_end() const { return ParamInfo+param_size(); } - unsigned getNumParams() const; + unsigned getNumParams() const { return NumParams; } const ParmVarDecl *getParamDecl(unsigned i) const { assert(i < getNumParams() && "Illegal param #"); return ParamInfo[i]; @@ -2548,6 +2553,28 @@ public: } void setParams(ParmVarDecl **NewParamInfo, unsigned NumParams); + /// hasCaptures - True if this block (or its nested blocks) captures + /// anything of local storage from its enclosing scopes. + bool hasCaptures() const { return NumCapturedDecls != 0 || CapturesCXXThis; } + + unsigned getNumCapturedDecls() const { return NumCapturedDecls; } + + typedef VarDecl * const *capture_iterator; + typedef VarDecl const * const *capture_const_iterator; + capture_iterator capture_begin() { return CapturedDecls; } + capture_iterator capture_end() { return CapturedDecls + NumCapturedDecls; } + capture_const_iterator capture_begin() const { return CapturedDecls; } + capture_const_iterator capture_end() const { + return CapturedDecls + NumCapturedDecls; + } + + bool capturesCXXThis() const { return CapturesCXXThis; } + + void setCapturedDecls(ASTContext &Context, + VarDecl * const *begin, + VarDecl * const *end, + bool capturesCXXThis); + virtual SourceRange getSourceRange() const; // Implement isa/cast/dyncast/etc. diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 9fb74d5410..e718961866 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -3528,12 +3528,11 @@ public: class BlockExpr : public Expr { protected: BlockDecl *TheBlock; - bool HasBlockDeclRefExprs; public: - BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) + BlockExpr(BlockDecl *BD, QualType ty) : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, ty->isDependentType(), false, false), - TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} + TheBlock(BD) {} /// \brief Build an empty block expression. explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } @@ -3554,11 +3553,6 @@ public: /// getFunctionType - Return the underlying function type for this block. const FunctionType *getFunctionType() const; - /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr - /// inside of the block that reference values outside the block. - bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } - void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; } - static bool classof(const Stmt *T) { return T->getStmtClass() == BlockExprClass; } diff --git a/include/clang/Sema/ScopeInfo.h b/include/clang/Sema/ScopeInfo.h index 15d17306c9..0ba61b34eb 100644 --- a/include/clang/Sema/ScopeInfo.h +++ b/include/clang/Sema/ScopeInfo.h @@ -17,6 +17,7 @@ #include "clang/AST/Type.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/SetVector.h" namespace clang { @@ -101,8 +102,6 @@ public: /// \brief Retains information about a block that is currently being parsed. class BlockScopeInfo : public FunctionScopeInfo { public: - bool hasBlockDeclRefExprs; - BlockDecl *TheDecl; /// TheScope - This is the scope for the block itself, which contains @@ -117,9 +116,15 @@ public: /// Its return type may be BuiltinType::Dependent. QualType FunctionType; + /// Captures - The set of variables captured by this block. + llvm::SmallSetVector<VarDecl*, 4> Captures; + + /// CapturesCXXThis - Whether this block captures 'this'. + bool CapturesCXXThis; + BlockScopeInfo(Diagnostic &Diag, Scope *BlockScope, BlockDecl *Block) - : FunctionScopeInfo(Diag), hasBlockDeclRefExprs(false), - TheDecl(Block), TheScope(BlockScope) + : FunctionScopeInfo(Diag), TheDecl(Block), TheScope(BlockScope), + CapturesCXXThis(false) { IsBlockInfo = true; } |