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
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index 00ca3a5..d722025 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -129,13 +129,10 @@
   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 @@
     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 @@
   } 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 &&