diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-07 18:10:23 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-07 18:10:23 +0000 |
commit | de7685487c5d628dd9fe64c4f861cd1888f50fc7 (patch) | |
tree | 53a21aaf4c9eebde9af749c584608db3410c69d3 /lib/Format/UnwrappedLineParser.cpp | |
parent | c3cd2b0d538e4db78f1bcbedd0085e2005ce5c51 (diff) |
Fix parsing of variable declarations directly after a class / struct.
Previous indent:
class A {
}
a;
void f() {
};
With this patch:
class A {
} a;
void f() {
}
;
The patch introduces a production for classes and structs, and parses
the rest of the line to the semicolon after the class scope.
This allowed us to remove a long-standing wart in the parser that would
just much the semicolon after any block.
Due to this suboptimal formating some tests were broken.
Some unrelated formatting tests broke; those hit a bug in the ast
printing, and need to be fixed separately.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171761 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | lib/Format/UnwrappedLineParser.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 00ca3a5334..d7220259b7 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -129,13 +129,10 @@ bool UnwrappedLineParser::parseBlock(unsigned AddLevels) { parseLevel(/*HasOpeningBrace=*/true); Line.Level -= AddLevels; - // FIXME: Add error handling. if (!FormatTok.Tok.is(tok::r_brace)) return true; - nextToken(); - if (FormatTok.Tok.is(tok::semi)) - nextToken(); + nextToken(); // Munch the closing brace. return false; } @@ -246,6 +243,10 @@ void UnwrappedLineParser::parseStructuralElement() { case tok::kw_enum: parseEnum(); return; + case tok::kw_struct: // fallthrough + case tok::kw_class: + parseStructOrClass(); + return; case tok::semi: nextToken(); addUnwrappedLine(); @@ -459,6 +460,26 @@ void UnwrappedLineParser::parseEnum() { } while (!eof()); } +void UnwrappedLineParser::parseStructOrClass() { + nextToken(); + do { + switch (FormatTok.Tok.getKind()) { + case tok::l_brace: + // FIXME: Think about how to resolve the error handling here. + parseBlock(); + parseStructuralElement(); + return; + case tok::semi: + nextToken(); + addUnwrappedLine(); + return; + default: + nextToken(); + break; + } + } while (!eof()); +} + void UnwrappedLineParser::addUnwrappedLine() { // Consume trailing comments. while (!eof() && FormatTok.NewlinesBefore == 0 && |