[cfe-commits] r172229 - in /cfe/trunk: lib/Format/UnwrappedLineParser.cpp lib/Format/UnwrappedLineParser.h unittests/Format/FormatTest.cpp

Manuel Klimek klimek at google.com
Fri Jan 11 10:13:04 PST 2013


Author: klimek
Date: Fri Jan 11 12:13:04 2013
New Revision: 172229

URL: http://llvm.org/viewvc/llvm-project?rev=172229&view=rev
Log:
Fix parsing of initializer lists with elaborated type specifier.

Now we correctly parse and format:
verifyFormat("struct foo a = { bar };
int n;

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/lib/Format/UnwrappedLineParser.h
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=172229&r1=172228&r2=172229&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Jan 11 12:13:04 2013
@@ -319,7 +319,7 @@
       return;
     case tok::kw_struct:  // fallthrough
     case tok::kw_class:
-      parseStructOrClass();
+      parseStructClassOrBracedList();
       return;
     case tok::semi:
       nextToken();
@@ -565,7 +565,7 @@
   } while (!eof());
 }
 
-void UnwrappedLineParser::parseStructOrClass() {
+void UnwrappedLineParser::parseStructClassOrBracedList() {
   nextToken();
   do {
     switch (FormatTok.Tok.getKind()) {
@@ -578,6 +578,12 @@
       nextToken();
       addUnwrappedLine();
       return;
+    case tok::equal:
+      nextToken();
+      if (FormatTok.Tok.is(tok::l_brace)) {
+        parseBracedList();
+      }
+      break;
     default:
       nextToken();
       break;

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=172229&r1=172228&r2=172229&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Fri Jan 11 12:13:04 2013
@@ -146,7 +146,7 @@
   void parseNamespace();
   void parseAccessSpecifier();
   void parseEnum();
-  void parseStructOrClass();
+  void parseStructClassOrBracedList();
   void parseObjCProtocolList();
   void parseObjCUntilAtEnd();
   void parseObjCInterfaceOrImplementation();

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172229&r1=172228&r2=172229&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 11 12:13:04 2013
@@ -1163,6 +1163,10 @@
                "}");
 }
 
+TEST_F(FormatTest, BracedInitListWithElaboratedTypeSpecifier) {
+  verifyFormat("struct foo a = { bar };\nint n;");
+}
+
 // FIXME: This breaks the order of the unwrapped lines:
 // TEST_F(FormatTest, OrderUnwrappedLines) {
 //   verifyFormat("{\n"





More information about the cfe-commits mailing list