aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-07-03 22:00:52 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-07-03 22:00:52 +0000
commita1eec4bd198b96ef40a7c15cd0e131ca94511ad8 (patch)
treef5c4c2cf278b9fe9297cb7cf0697e9bfa5efdd29 /lib/Sema
parent11d3f4cc27e6b923fc32481dc1bb5ec46c7d1f4b (diff)
objective-c: Refactor parse/sema portion of
objective-c's fast enumeration statement, for more work to come. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159689 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/SemaStmt.cpp38
-rw-r--r--lib/Sema/TreeTransform.h25
2 files changed, 36 insertions, 27 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 62cd0d0d60..31d368043e 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -1385,9 +1385,10 @@ StmtResult Sema::ActOnForEachLValueExpr(Expr *E) {
}
ExprResult
-Sema::ActOnObjCForCollectionOperand(SourceLocation forLoc, Expr *collection) {
- assert(collection);
-
+Sema::CheckObjCForCollectionOperand(SourceLocation forLoc, Expr *collection) {
+ if (!collection)
+ return ExprError();
+
// Bail out early if we've got a type-dependent expression.
if (collection->isTypeDependent()) return Owned(collection);
@@ -1457,8 +1458,12 @@ Sema::ActOnObjCForCollectionOperand(SourceLocation forLoc, Expr *collection) {
StmtResult
Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
SourceLocation LParenLoc,
- Stmt *First, Expr *Second,
- SourceLocation RParenLoc, Stmt *Body) {
+ Stmt *First, Expr *collection,
+ SourceLocation RParenLoc) {
+
+ ExprResult CollectionExprResult =
+ CheckObjCForCollectionOperand(ForLoc, collection);
+
if (First) {
QualType FirstType;
if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
@@ -1486,11 +1491,15 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
if (!FirstType->isDependentType() &&
!FirstType->isObjCObjectPointerType() &&
!FirstType->isBlockPointerType())
- Diag(ForLoc, diag::err_selector_element_type)
- << FirstType << First->getSourceRange();
+ return StmtError(Diag(ForLoc, diag::err_selector_element_type)
+ << FirstType << First->getSourceRange());
}
-
- return Owned(new (Context) ObjCForCollectionStmt(First, Second, Body,
+
+ if (CollectionExprResult.isInvalid())
+ return StmtError();
+
+ return Owned(new (Context) ObjCForCollectionStmt(First,
+ CollectionExprResult.take(), 0,
ForLoc, RParenLoc));
}
@@ -1900,6 +1909,17 @@ Sema::BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation ColonLoc,
ColonLoc, RParenLoc));
}
+/// FinishObjCForCollectionStmt - Attach the body to a objective-C foreach
+/// statement.
+StmtResult Sema::FinishObjCForCollectionStmt(Stmt *S, Stmt *B) {
+ if (!S || !B)
+ return StmtError();
+ ObjCForCollectionStmt * ForStmt = cast<ObjCForCollectionStmt>(S);
+
+ ForStmt->setBody(B);
+ return S;
+}
+
/// FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
/// This is a separate step from ActOnCXXForRangeStmt because analysis of the
/// body cannot be performed until after the type of the range variable is
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index ec02661218..3b41f758d9 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -1267,16 +1267,6 @@ public:
return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
}
- /// \brief Build the collection operand to a new Objective-C fast
- /// enumeration statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
- Expr *collection) {
- return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
- }
-
/// \brief Build a new Objective-C fast enumeration statement.
///
/// By default, performs semantic analysis to build the new statement.
@@ -1287,11 +1277,14 @@ public:
Expr *Collection,
SourceLocation RParenLoc,
Stmt *Body) {
- return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
- Element,
+ StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
+ Element,
Collection,
- RParenLoc,
- Body);
+ RParenLoc);
+ if (ForEachStmt.isInvalid())
+ return StmtError();
+
+ return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
}
/// \brief Build a new C++ exception declaration.
@@ -5791,10 +5784,6 @@ TreeTransform<Derived>::TransformObjCForCollectionStmt(
ExprResult Collection = getDerived().TransformExpr(S->getCollection());
if (Collection.isInvalid())
return StmtError();
- Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
- Collection.take());
- if (Collection.isInvalid())
- return StmtError();
// Transform the body.
StmtResult Body = getDerived().TransformStmt(S->getBody());