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

Alexander Kornienko alexfh at google.com
Tue Dec 4 07:40:36 PST 2012


Author: alexfh
Date: Tue Dec  4 09:40:36 2012
New Revision: 169278

URL: http://llvm.org/viewvc/llvm-project?rev=169278&view=rev
Log:
Clang-format error recovery part 1

Reviewers: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D163

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    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=169278&r1=169277&r2=169278&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Dec  4 09:40:36 2012
@@ -72,7 +72,10 @@
   parseLevel();
   if (!IsNamespace)
     --Line.Level;
-  assert(FormatTok.Tok.is(tok::r_brace) && "expected '}'");
+  // FIXME: Add error handling.
+  if (!FormatTok.Tok.is(tok::r_brace))
+    return;
+
   nextToken();
   if (FormatTok.Tok.is(tok::semi))
     nextToken();
@@ -218,7 +221,12 @@
     --Line.Level;
   }
 
-  assert(FormatTok.Tok.is(tok::kw_while) && "'while' expected");
+  // FIXME: Add error handling.
+  if (!FormatTok.Tok.is(tok::kw_while)) {
+    addUnwrappedLine();
+    return;
+  }
+
   nextToken();
   parseStatement();
 }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=169278&r1=169277&r2=169278&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Dec  4 09:40:36 2012
@@ -363,5 +363,23 @@
 //               "};");
 //}
 
+TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
+  verifyFormat("{");
+}
+
+TEST_F(FormatTest, IncorrectCodeDoNoWhile) {
+  verifyFormat("do {\n"
+               "};");
+  verifyFormat("do {\n"
+               "};\n"
+               "f();");
+  verifyFormat("do {\n"
+               "}\n"
+               "wheeee(fun);");
+  verifyFormat("do {\n"
+               "  f();\n"
+               "};");
+}
+
 }  // end namespace tooling
 }  // end namespace clang





More information about the cfe-commits mailing list