diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 20 | ||||
-rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 14 |
2 files changed, 19 insertions, 15 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 5de4dd4a7c6..f80afe3f4b1 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -257,7 +257,11 @@ Parser::DeclGroupPtrTy Parser::ParseDeclaration(unsigned Context) { /// declaration-specifiers init-declarator-list[opt] ';' ///[C90/C++]init-declarator-list ';' [TODO] /// [OMP] threadprivate-directive [TODO] -Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(unsigned Context) { +/// +/// If RequireSemi is false, this does not check for a ';' at the end of the +/// declaration. +Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(unsigned Context, + bool RequireSemi) { // Parse the common declaration-specifiers piece. DeclSpec DS; ParseDeclarationSpecifiers(DS); @@ -275,22 +279,16 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(unsigned Context) { DeclGroupPtrTy DG = ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo); + + // If the client wants to check what comes after the declaration, just return + // immediately without checking anything! + if (!RequireSemi) return DG; if (Tok.is(tok::semi)) { ConsumeToken(); - // for(is key; in keys) is error. - if (Context == Declarator::ForContext && isTokIdentifier_in()) - Diag(Tok, diag::err_parse_error); - return DG; } - // If this is an ObjC2 for-each loop, this is a successful declarator - // parse. The syntax for these looks like: - // 'for' '(' declaration 'in' expr ')' statement - if (Context == Declarator::ForContext && isTokIdentifier_in()) - return DG; - Diag(Tok, diag::err_expected_semi_declation); // Skip to end of block or statement SkipUntil(tok::r_brace, true, true); diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index b1a32decffc..3ca2f02b52b 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -912,12 +912,18 @@ Parser::OwningStmtResult Parser::ParseForStatement() { Diag(Tok, diag::ext_c99_variable_decl_in_for_loop); SourceLocation DeclStart = Tok.getLocation(); - DeclGroupPtrTy VarDecls = ParseSimpleDeclaration(Declarator::ForContext); - // FIXME: Pass in the right location for the end of the declstmt. - FirstPart = Actions.ActOnDeclStmt(VarDecls, DeclStart, DeclStart); - if ((ForEach = isTokIdentifier_in())) { + DeclGroupPtrTy DG = ParseSimpleDeclaration(Declarator::ForContext, false); + FirstPart = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation()); + + if (Tok.is(tok::semi)) { // for (int x = 4; + ConsumeToken(); + } else if ((ForEach = isTokIdentifier_in())) { + // ObjC: for (id x in expr) ConsumeToken(); // consume 'in' SecondPart = ParseExpression(); + } else { + Diag(Tok, diag::err_expected_semi_for); + SkipUntil(tok::semi); } } else { Value = ParseExpression(); |