[cfe-commits] [PATCH] Clang-format error recovery part 1
Alexander Kornienko
alexfh at google.com
Tue Dec 4 07:26:27 PST 2012
Hi klimek,
http://llvm-reviews.chandlerc.com/D163
Files:
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -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();
}
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D163.1.patch
Type: text/x-patch
Size: 1452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121204/0ab37652/attachment.bin>
More information about the cfe-commits
mailing list