[cfe-commits] r56257 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/AST/StmtNodes.def include/clang/Parse/Action.h lib/AST/Expr.cpp lib/AST/StmtPrinter.cpp lib/Parse/ParseExpr.cpp lib/Sema/Sema.h lib/Sema/SemaExpr.cpp test/Sema/block-literal.c
Steve Naroff
snaroff at apple.com
Tue Sep 16 16:11:46 PDT 2008
Author: snaroff
Date: Tue Sep 16 18:11:46 2008
New Revision: 56257
URL: http://llvm.org/viewvc/llvm-project?rev=56257&view=rev
Log:
Remove support for BlockExprExpr. For example...
^(expression) or ^(int arg1, float arg2)(expression)
..is no longer supported.
All block literals now require a compound statement.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/StmtNodes.def
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/block-literal.c
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=56257&r1=56256&r2=56257&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Sep 16 18:11:46 2008
@@ -1487,6 +1487,7 @@
//===----------------------------------------------------------------------===//
/// BlockExpr - Common base class between BlockStmtExpr and BlockExprExpr.
+/// FIXME: Combine with BlockStmtExpr...no more need for a common base.
class BlockExpr : public Expr {
SourceLocation CaretLocation;
llvm::SmallVector<ParmVarDecl*, 8> Args;
@@ -1508,8 +1509,7 @@
arg_iterator arg_end() const { return Args.end(); }
static bool classof(const Stmt *T) {
- return T->getStmtClass() == BlockStmtExprClass ||
- T->getStmtClass() == BlockExprExprClass;
+ return T->getStmtClass() == BlockStmtExprClass;
}
static bool classof(const BlockExpr *) { return true; }
};
@@ -1544,33 +1544,6 @@
static BlockStmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
};
-/// BlockExprExpr - Represents a block literal with syntax:
-/// ^(expression) or ^(int arg1, float arg2)(expression)
-class BlockExprExpr : public BlockExpr {
- Expr *BodyExpr;
-public:
- BlockExprExpr(SourceLocation CaretLoc, QualType Ty, ParmVarDecl **args,
- unsigned numargs, Expr *body) :
- BlockExpr(BlockExprExprClass, Ty, CaretLoc,
- args, numargs), BodyExpr(body) {}
-
- const Expr *getExpr() const { return BodyExpr; }
- Expr *getExpr() { return BodyExpr; }
-
- virtual SourceRange getSourceRange() const {
- return SourceRange(getCaretLocation(), BodyExpr->getLocEnd());
- }
-
- // Iterators
- virtual child_iterator child_begin();
- virtual child_iterator child_end();
-
- static bool classof(const Stmt *T) {
- return T->getStmtClass() == BlockExprExprClass;
- }
- static bool classof(const BlockExprExpr *) { return true; }
-};
-
/// BlockDeclRefExpr - A reference to a declared variable, function,
/// enum, etc.
class BlockDeclRefExpr : public Expr {
Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=56257&r1=56256&r2=56257&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Tue Sep 16 18:11:46 2008
@@ -111,10 +111,9 @@
STMT(78, ShuffleVectorExpr , Expr)
STMT(79, BlockExpr , Expr)
STMT(80, BlockStmtExpr , BlockExpr)
-STMT(81, BlockExprExpr , BlockExpr)
-STMT(82, BlockDeclRefExpr , Expr)
+STMT(81, BlockDeclRefExpr , Expr)
-LAST_EXPR(82)
+LAST_EXPR(81)
#undef STMT
#undef FIRST_STMT
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=56257&r1=56256&r2=56257&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Sep 16 18:11:46 2008
@@ -549,11 +549,6 @@
virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
Scope *CurScope) { return 0; }
- /// ActOnBlockExprExpr - This is called when the body of a block
- /// expression literal was successfully completed. ^(int x)[foo bar: x]
- virtual ExprResult ActOnBlockExprExpr(SourceLocation CaretLoc, ExprTy *Body,
- Scope *CurScope) { return 0; }
-
//===------------------------- C++ Declarations -------------------------===//
/// ActOnStartNamespaceDef - This is called at the start of a namespace
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=56257&r1=56256&r2=56257&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Sep 16 18:11:46 2008
@@ -1455,12 +1455,6 @@
return reinterpret_cast<Stmt**>(&Body)+1;
}
-Stmt::child_iterator BlockExprExpr::child_begin() {
- return reinterpret_cast<Stmt**>(&BodyExpr);
-}
-Stmt::child_iterator BlockExprExpr::child_end() {
- return reinterpret_cast<Stmt**>(&BodyExpr)+1;
-}
Stmt::child_iterator BlockDeclRefExpr::child_begin(){return child_iterator();}
Stmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator();}
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=56257&r1=56256&r2=56257&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Tue Sep 16 18:11:46 2008
@@ -912,11 +912,6 @@
PrintRawCompoundStmt(Node->getBody());
}
-void StmtPrinter::VisitBlockExprExpr(BlockExprExpr *Node) {
- VisitBlockExpr(Node);
- PrintExpr(Node->getExpr());
-}
-
void StmtPrinter::VisitBlockDeclRefExpr(BlockDeclRefExpr *Node) {
OS << Node->getDecl()->getName();
}
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=56257&r1=56256&r2=56257&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Sep 16 18:11:46 2008
@@ -1077,11 +1077,10 @@
}
/// ParseBlockLiteralExpression - Parse a block literal, which roughly looks
-/// like ^(int x){ return x+1; } or ^(int y)foo(4, y, z)
+/// like ^(int x){ return x+1; }
///
/// block-literal:
/// [clang] '^' block-args[opt] compound-statement
-/// [clang] '^' block-args cast-expression
/// [clang] block-args:
/// [clang] '(' parameter-list ')'
///
@@ -1122,26 +1121,15 @@
// Inform sema that we are starting a block.
Actions.ActOnBlockStart(CaretLoc, CurScope, ParamInfo);
- ExprResult Result;
+ ExprResult Result = true;
if (Tok.is(tok::l_brace)) {
StmtResult Stmt = ParseCompoundStatementBody();
if (!Stmt.isInvalid) {
Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.Val, CurScope);
} else {
Actions.ActOnBlockError(CaretLoc, CurScope);
- Result = true;
- }
- } else {
- ExprResult Expr = ParseCastExpression(false);
- if (!Expr.isInvalid) {
- Result = Actions.ActOnBlockExprExpr(CaretLoc, Expr.Val, CurScope);
- } else {
- Actions.ActOnBlockError(CaretLoc, CurScope);
- Diag(Tok, diag::err_expected_block_lbrace);
- Result = true;
}
}
-
ExitScope();
return Result;
}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=56257&r1=56256&r2=56257&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Sep 16 18:11:46 2008
@@ -574,11 +574,6 @@
virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
Scope *CurScope);
- /// ActOnBlockExprExpr - This is called when the body of a block
- /// expression literal was successfully completed. ^(int x)[foo bar: x]
- virtual ExprResult ActOnBlockExprExpr(SourceLocation CaretLoc, ExprTy *Body,
- Scope *CurScope);
-
// Act on C++ namespaces
virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
IdentifierInfo *Ident,
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=56257&r1=56256&r2=56257&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Sep 16 18:11:46 2008
@@ -2890,40 +2890,6 @@
&BSI->Params[0], BSI->Params.size(), Body.take());
}
-/// ActOnBlockExprExpr - This is called when the body of a block
-/// expression literal was successfully completed. ^(int x)[foo bar: x]
-Sema::ExprResult Sema::ActOnBlockExprExpr(SourceLocation CaretLoc, ExprTy *body,
- Scope *CurScope) {
- // Ensure that CurBlock is deleted.
- llvm::OwningPtr<BlockSemaInfo> BSI(CurBlock);
- llvm::OwningPtr<Expr> Body(static_cast<Expr*>(body));
-
- // Pop off CurBlock, handle nested blocks.
- CurBlock = CurBlock->PrevBlockInfo;
-
- if (BSI->ReturnType) {
- Diag(CaretLoc, diag::err_return_in_block_expression);
- return true;
- }
-
- QualType RetTy = Body->getType();
-
- llvm::SmallVector<QualType, 8> ArgTypes;
- for (unsigned i = 0, e = BSI->Params.size(); i != e; ++i)
- ArgTypes.push_back(BSI->Params[i]->getType());
-
- QualType BlockTy;
- if (!BSI->hasPrototype)
- BlockTy = Context.getFunctionTypeNoProto(RetTy);
- else
- BlockTy = Context.getFunctionType(RetTy, &ArgTypes[0], ArgTypes.size(),
- BSI->isVariadic);
-
- BlockTy = Context.getBlockPointerType(BlockTy);
- return new BlockExprExpr(CaretLoc, BlockTy,
- &BSI->Params[0], BSI->Params.size(), Body.take());
-}
-
/// ExprsMatchFnType - return true if the Exprs in array Args have
/// QualTypes that match the QualTypes of the arguments of the FnType.
/// The number of arguments has already been validated to match the number of
Modified: cfe/trunk/test/Sema/block-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-literal.c?rev=56257&r1=56256&r2=56257&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-literal.c (original)
+++ cfe/trunk/test/Sema/block-literal.c Tue Sep 16 18:11:46 2008
@@ -21,8 +21,6 @@
I(^{ });
- noop = ^noop; // expected-error {{incompatible block pointer types}}
-
return ^{printf("\nClosure\n"); }; // expected-error {{returning block that lives on the local stack}}
}
void test2() {
@@ -42,10 +40,6 @@
foo:
takeclosure(^{ x = 4; }); // expected-error {{expression is not assignable}}
-
- takeclosure(^test2());
- takeclosure(^(void)(void)printf("hello world!\n"));
-
}
@@ -61,17 +55,7 @@
void *X;
void test_arguments() {
- takeintint(^(int x)(x+1));
-
- // Closure expr of statement expr.
- takeintint(^(int x)({ return 42; })); // expected-error {{return not allowed in block expression literal}}
-
int y;
- takeintint(^(int x)(x+y));
-#if 0
- // FIXME: this causes clang to crash.
- X = ^(x+r); // expected-error {{expected ')' in argument list}}
-#endif
int (^c)(char);
(1 ? c : 0)('x');
(1 ? 0 : c)('x');
More information about the cfe-commits
mailing list