mirror of
https://github.com/intel/llvm.git
synced 2026-02-02 02:00:03 +08:00
Remove BlockStmtExpr.
Block literals are now represented by the concrete BlockExpr class. This is cleanup (removes a FIXME). No functionality change. llvm-svn: 56288
This commit is contained in:
@@ -94,7 +94,7 @@ public:
|
||||
void InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD);
|
||||
|
||||
// Block specific rewrite rules.
|
||||
void RewriteBlockStmtExpr(BlockStmtExpr *Exp);
|
||||
void RewriteBlockExpr(BlockExpr *Exp);
|
||||
|
||||
void RewriteBlockCall(CallExpr *Exp);
|
||||
void RewriteBlockPointerDecl(NamedDecl *VD);
|
||||
@@ -349,7 +349,7 @@ std::string RewriteBlocks::SynthesizeBlockFunc(BlockExpr *CE, int i,
|
||||
// first add the implicit argument.
|
||||
S += Tag + " *__cself, ";
|
||||
std::string ParamStr;
|
||||
for (BlockStmtExpr::arg_iterator AI = CE->arg_begin(),
|
||||
for (BlockExpr::arg_iterator AI = CE->arg_begin(),
|
||||
E = CE->arg_end(); AI != E; ++AI) {
|
||||
if (AI != CE->arg_begin()) S += ", ";
|
||||
ParamStr = (*AI)->getName();
|
||||
@@ -398,7 +398,7 @@ std::string RewriteBlocks::SynthesizeBlockFunc(BlockExpr *CE, int i,
|
||||
(*I)->getType().getAsStringInternal(Name);
|
||||
S += Name + " = __cself->" + (*I)->getName() + "; // bound by copy\n";
|
||||
}
|
||||
if (BlockStmtExpr *CBE = dyn_cast<BlockStmtExpr>(CE)) {
|
||||
if (BlockExpr *CBE = dyn_cast<BlockExpr>(CE)) {
|
||||
std::string BodyBuf;
|
||||
|
||||
SourceLocation BodyLocStart = CBE->getBody()->getLocStart();
|
||||
@@ -635,10 +635,10 @@ Stmt *RewriteBlocks::RewriteFunctionBody(Stmt *S) {
|
||||
for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end();
|
||||
CI != E; ++CI)
|
||||
if (*CI) {
|
||||
if (BlockStmtExpr *CBE = dyn_cast<BlockStmtExpr>(*CI)) {
|
||||
if (BlockExpr *CBE = dyn_cast<BlockExpr>(*CI)) {
|
||||
// We intentionally avoid rewritting the contents of a closure block
|
||||
// expr. InsertBlockLiteralsWithinFunction() will rewrite the body.
|
||||
RewriteBlockStmtExpr(CBE);
|
||||
RewriteBlockExpr(CBE);
|
||||
} else {
|
||||
Stmt *newStmt = RewriteFunctionBody(*CI);
|
||||
if (newStmt)
|
||||
@@ -831,7 +831,7 @@ void RewriteBlocks::RewriteBlockPointerDecl(NamedDecl *ND) {
|
||||
return;
|
||||
}
|
||||
|
||||
void RewriteBlocks::RewriteBlockStmtExpr(BlockStmtExpr *Exp) {
|
||||
void RewriteBlocks::RewriteBlockExpr(BlockExpr *Exp) {
|
||||
Blocks.push_back(Exp);
|
||||
bool haveByRefDecls = false;
|
||||
|
||||
|
||||
@@ -1486,21 +1486,29 @@ private:
|
||||
// Clang Extensions
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// BlockExpr - Common base class between BlockStmtExpr and BlockExprExpr.
|
||||
/// FIXME: Combine with BlockStmtExpr...no more need for a common base.
|
||||
/// BlockExpr - Represent a block literal with a syntax:
|
||||
/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
|
||||
class BlockExpr : public Expr {
|
||||
SourceLocation CaretLocation;
|
||||
llvm::SmallVector<ParmVarDecl*, 8> Args;
|
||||
protected:
|
||||
BlockExpr(StmtClass SC, QualType ty, SourceLocation caretloc,
|
||||
ParmVarDecl **args, unsigned numargs)
|
||||
: Expr(SC, ty), CaretLocation(caretloc), Args(args, args+numargs) {}
|
||||
CompoundStmt *Body;
|
||||
public:
|
||||
BlockExpr(SourceLocation caretloc, QualType ty, ParmVarDecl **args,
|
||||
unsigned numargs, CompoundStmt *body) : Expr(BlockExprClass, ty),
|
||||
CaretLocation(caretloc), Args(args, args+numargs), Body(body) {}
|
||||
|
||||
SourceLocation getCaretLocation() const { return CaretLocation; }
|
||||
|
||||
/// getFunctionType - Return the underlying function type for this block.
|
||||
const FunctionType *getFunctionType() const;
|
||||
|
||||
|
||||
const CompoundStmt *getBody() const { return Body; }
|
||||
CompoundStmt *getBody() { return Body; }
|
||||
|
||||
virtual SourceRange getSourceRange() const {
|
||||
return SourceRange(getCaretLocation(), Body->getLocEnd());
|
||||
}
|
||||
|
||||
/// arg_iterator - Iterate over the ParmVarDecl's for the arguments to this
|
||||
/// block.
|
||||
typedef llvm::SmallVector<ParmVarDecl*, 8>::const_iterator arg_iterator;
|
||||
@@ -1509,41 +1517,18 @@ public:
|
||||
arg_iterator arg_end() const { return Args.end(); }
|
||||
|
||||
static bool classof(const Stmt *T) {
|
||||
return T->getStmtClass() == BlockStmtExprClass;
|
||||
return T->getStmtClass() == BlockExprClass;
|
||||
}
|
||||
static bool classof(const BlockExpr *) { return true; }
|
||||
};
|
||||
|
||||
/// BlockStmtExpr - Represent a block literal with a syntax:
|
||||
/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
|
||||
class BlockStmtExpr : public BlockExpr {
|
||||
CompoundStmt *Body;
|
||||
public:
|
||||
BlockStmtExpr(SourceLocation CaretLoc, QualType Ty, ParmVarDecl **args,
|
||||
unsigned numargs, CompoundStmt *body) :
|
||||
BlockExpr(BlockStmtExprClass, Ty, CaretLoc,
|
||||
args, numargs), Body(body) {}
|
||||
|
||||
const CompoundStmt *getBody() const { return Body; }
|
||||
CompoundStmt *getBody() { return Body; }
|
||||
|
||||
virtual SourceRange getSourceRange() const {
|
||||
return SourceRange(getCaretLocation(), Body->getLocEnd());
|
||||
}
|
||||
|
||||
static bool classof(const Stmt *T) {
|
||||
return T->getStmtClass() == BlockStmtExprClass;
|
||||
}
|
||||
static bool classof(const BlockStmtExpr *) { return true; }
|
||||
|
||||
// Iterators
|
||||
virtual child_iterator child_begin();
|
||||
virtual child_iterator child_end();
|
||||
|
||||
virtual void EmitImpl(llvm::Serializer& S) const;
|
||||
static BlockStmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
|
||||
static BlockExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
|
||||
};
|
||||
|
||||
|
||||
/// BlockDeclRefExpr - A reference to a declared variable, function,
|
||||
/// enum, etc.
|
||||
class BlockDeclRefExpr : public Expr {
|
||||
|
||||
@@ -110,10 +110,9 @@ STMT(76, ObjCPropertyRefExpr , Expr)
|
||||
STMT(77, OverloadExpr , Expr)
|
||||
STMT(78, ShuffleVectorExpr , Expr)
|
||||
STMT(79, BlockExpr , Expr)
|
||||
STMT(80, BlockStmtExpr , BlockExpr)
|
||||
STMT(81, BlockDeclRefExpr , Expr)
|
||||
STMT(80, BlockDeclRefExpr , Expr)
|
||||
|
||||
LAST_EXPR(81)
|
||||
LAST_EXPR(80)
|
||||
|
||||
#undef STMT
|
||||
#undef FIRST_STMT
|
||||
|
||||
@@ -1448,10 +1448,10 @@ Stmt::child_iterator ObjCMessageExpr::child_end() {
|
||||
}
|
||||
|
||||
// Blocks
|
||||
Stmt::child_iterator BlockStmtExpr::child_begin() {
|
||||
Stmt::child_iterator BlockExpr::child_begin() {
|
||||
return reinterpret_cast<Stmt**>(&Body);
|
||||
}
|
||||
Stmt::child_iterator BlockStmtExpr::child_end() {
|
||||
Stmt::child_iterator BlockExpr::child_end() {
|
||||
return reinterpret_cast<Stmt**>(&Body)+1;
|
||||
}
|
||||
|
||||
|
||||
@@ -891,7 +891,7 @@ void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
|
||||
const FunctionTypeProto *FT = cast<FunctionTypeProto>(AFT);
|
||||
OS << '(';
|
||||
std::string ParamStr;
|
||||
for (BlockStmtExpr::arg_iterator AI = Node->arg_begin(),
|
||||
for (BlockExpr::arg_iterator AI = Node->arg_begin(),
|
||||
E = Node->arg_end(); AI != E; ++AI) {
|
||||
if (AI != Node->arg_begin()) OS << ", ";
|
||||
ParamStr = (*AI)->getName();
|
||||
@@ -907,11 +907,6 @@ void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
|
||||
}
|
||||
}
|
||||
|
||||
void StmtPrinter::VisitBlockStmtExpr(BlockStmtExpr *Node) {
|
||||
VisitBlockExpr(Node);
|
||||
PrintRawCompoundStmt(Node->getBody());
|
||||
}
|
||||
|
||||
void StmtPrinter::VisitBlockDeclRefExpr(BlockDeclRefExpr *Node) {
|
||||
OS << Node->getDecl()->getName();
|
||||
}
|
||||
|
||||
@@ -1112,13 +1112,13 @@ ObjCStringLiteral* ObjCStringLiteral::CreateImpl(Deserializer& D, ASTContext& C)
|
||||
// Serialization for Clang Extensions.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void BlockStmtExpr::EmitImpl(Serializer& S) const {
|
||||
void BlockExpr::EmitImpl(Serializer& S) const {
|
||||
S.Emit(getType());
|
||||
S.Emit(getCaretLocation());
|
||||
S.EmitOwnedPtr(Body);
|
||||
}
|
||||
|
||||
BlockStmtExpr* BlockStmtExpr::CreateImpl(Deserializer& D, ASTContext& C) {
|
||||
BlockExpr* BlockExpr::CreateImpl(Deserializer& D, ASTContext& C) {
|
||||
QualType Q = QualType::ReadVal(D);
|
||||
SourceLocation L = SourceLocation::ReadVal(D);
|
||||
/*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/;
|
||||
|
||||
@@ -2886,8 +2886,8 @@ Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body,
|
||||
BSI->isVariadic);
|
||||
|
||||
BlockTy = Context.getBlockPointerType(BlockTy);
|
||||
return new BlockStmtExpr(CaretLoc, BlockTy,
|
||||
&BSI->Params[0], BSI->Params.size(), Body.take());
|
||||
return new BlockExpr(CaretLoc, BlockTy, &BSI->Params[0], BSI->Params.size(),
|
||||
Body.take());
|
||||
}
|
||||
|
||||
/// ExprsMatchFnType - return true if the Exprs in array Args have
|
||||
|
||||
Reference in New Issue
Block a user