Skip to content

Commit

Permalink
Offside rule (Python-like indentation) part 3: loops
Browse files Browse the repository at this point in the history
  • Loading branch information
andyarvanitis committed Feb 11, 2012
1 parent 21203bc commit 5d9e484
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lib/Parse/ParseStmt.cpp
Expand Up @@ -757,7 +757,12 @@ bool Parser::IsValidIndentation(unsigned short column) {
StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
const bool Eero = getLang().Eero && !InSystemHeader(Tok.getLocation());
if (Eero) {
InsertToken(tok::l_brace);
if (Tok.isAtStartOfLine()) {
InsertToken(tok::l_brace);
} else {
Diag(Tok, diag::err_expected) << "newline";
return ParseStatement(); // TODO: flush the rest of the line instead?
}
}
PrettyStackTraceLoc CrashInfo(PP.getSourceManager(),
Tok.getLocation(),
Expand Down Expand Up @@ -1025,13 +1030,8 @@ StmtResult Parser::ParseIfStatement(ParsedAttributes &attrs) {
StmtResult ThenStmt;
if (!Eero)
ThenStmt = ParseStatement();
else if (Tok.isAtStartOfLine())
else
ThenStmt = ParseCompoundStatement(attrs);
else {
Diag(Tok, diag::err_expected) << "newline";
Diag(IfLoc, diag::note_using);
ThenStmt = ParseStatement();
}

// Pop the 'if' scope if needed.
InnerScope.Exit();
Expand Down Expand Up @@ -1267,7 +1267,11 @@ StmtResult Parser::ParseWhileStatement(ParsedAttributes &attrs) {
C99orCXX && Tok.isNot(tok::l_brace));

// Read the body statement.
StmtResult Body(ParseStatement());
StmtResult Body;
if (!getLang().Eero || InSystemHeader(WhileLoc))
Body = ParseStatement();
else
Body = ParseCompoundStatement(attrs);

// Pop the body scope if needed.
InnerScope.Exit();
Expand Down Expand Up @@ -1312,7 +1316,11 @@ StmtResult Parser::ParseDoStatement(ParsedAttributes &attrs) {
Tok.isNot(tok::l_brace));

// Read the body statement.
StmtResult Body(ParseStatement());
StmtResult Body;
if (!getLang().Eero || InSystemHeader(DoLoc))
Body = ParseStatement();
else
Body = ParseCompoundStatement(attrs);

// Pop the body scope if needed.
InnerScope.Exit();
Expand Down Expand Up @@ -1583,7 +1591,11 @@ StmtResult Parser::ParseForStatement(ParsedAttributes &attrs) {
C99orCXXorObjC && Tok.isNot(tok::l_brace));

// Read the body statement.
StmtResult Body(ParseStatement());
StmtResult Body;
if (!getLang().Eero || InSystemHeader(ForLoc))
Body = ParseStatement();
else
Body = ParseCompoundStatement(attrs);

// Pop the body scope if needed.
InnerScope.Exit();
Expand Down

0 comments on commit 5d9e484

Please sign in to comment.