diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-02-17 03:38:46 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-02-17 03:38:46 +0000 |
commit | b72c77855473379c4c47e701005f7818946f659b (patch) | |
tree | e24bdd087107c0b5099658a91c1be781c4e4d136 /lib/Parse/ParseStmt.cpp | |
parent | 6204159b21d88b356015ba3f3e42d40f1887acd6 (diff) |
Improve parser recovery in "for" statements, from Richard Smith!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125722 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseStmt.cpp')
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 5f932919b9..3e7ec533bd 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -1039,7 +1039,6 @@ StmtResult Parser::ParseForStatement(ParsedAttributes &attrs) { Collection = ParseExpression(); } else { Diag(Tok, diag::err_expected_semi_for); - SkipUntil(tok::semi); } } else { Value = ParseExpression(); @@ -1065,8 +1064,14 @@ StmtResult Parser::ParseForStatement(ParsedAttributes &attrs) { } Collection = ParseExpression(); } else { - if (!Value.isInvalid()) Diag(Tok, diag::err_expected_semi_for); - SkipUntil(tok::semi); + if (!Value.isInvalid()) { + Diag(Tok, diag::err_expected_semi_for); + } else { + // Skip until semicolon or rparen, don't consume it. + SkipUntil(tok::r_paren, true, true); + if (Tok.is(tok::semi)) + ConsumeToken(); + } } } if (!ForEach) { @@ -1074,6 +1079,8 @@ StmtResult Parser::ParseForStatement(ParsedAttributes &attrs) { // Parse the second part of the for specifier. if (Tok.is(tok::semi)) { // for (...;; // no second part. + } else if (Tok.is(tok::r_paren)) { + // missing both semicolons. } else { ExprResult Second; if (getLang().CPlusPlus) @@ -1088,12 +1095,16 @@ StmtResult Parser::ParseForStatement(ParsedAttributes &attrs) { SecondPart = Actions.MakeFullExpr(Second.get()); } + if (Tok.isNot(tok::semi)) { + if (!SecondPartIsInvalid || SecondVar) + Diag(Tok, diag::err_expected_semi_for); + else + // Skip until semicolon or rparen, don't consume it. + SkipUntil(tok::r_paren, true, true); + } + if (Tok.is(tok::semi)) { ConsumeToken(); - } else { - if (!SecondPartIsInvalid || SecondVar) - Diag(Tok, diag::err_expected_semi_for); - SkipUntil(tok::semi); } // Parse the third part of the for specifier. |