From 732b8c2dc5facdd529a7c6856a89b52fb3d2638d Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 3 Jan 2008 17:55:25 +0000 Subject: Patch to parse/build AST ObjC2's foreach statement. llvm-svn: 45539 --- clang/Sema/SemaStmt.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'clang/Sema/SemaStmt.cpp') diff --git a/clang/Sema/SemaStmt.cpp b/clang/Sema/SemaStmt.cpp index f83ff4b32de..cbb01bdb3c5 100644 --- a/clang/Sema/SemaStmt.cpp +++ b/clang/Sema/SemaStmt.cpp @@ -530,6 +530,39 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, return new ForStmt(First, Second, Third, Body, ForLoc); } +Action::StmtResult +Sema::ActOnObjcForCollectionStmt(SourceLocation ForColLoc, + SourceLocation LParenLoc, + StmtTy *first, ExprTy *second, + SourceLocation RParenLoc, StmtTy *body) { + Stmt *First = static_cast(first); + Expr *Second = static_cast(second); + Stmt *Body = static_cast(body); + + if (DeclStmt *DS = dyn_cast_or_null(First)) { + // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare + // identifiers for objects having storage class 'auto' or 'register'. + for (ScopedDecl *D = DS->getDecl(); D; D = D->getNextDeclarator()) { + BlockVarDecl *BVD = dyn_cast(D); + if (BVD && !BVD->hasLocalStorage()) + BVD = 0; + if (BVD == 0) + Diag(dyn_cast(D)->getLocation(), + diag::err_non_variable_decl_in_for); + // FIXME: mark decl erroneous! + } + } + if (Second) { + DefaultFunctionArrayConversion(Second); + QualType SecondType = Second->getType(); +#if 0 + if (!SecondType->isScalarType()) // C99 6.8.5p2 + return Diag(ForColLoc, diag::err_typecheck_statement_requires_scalar, + SecondType.getAsString(), Second->getSourceRange()); +#endif + } + return new ObjcForCollectionStmt(First, Second, Body, ForColLoc); +} Action::StmtResult Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, -- cgit v1.2.3