[cfe-commits] [PATCH] Clang-format error recovery part 1

Manuel Klimek klimek at google.com
Tue Dec 4 07:26:48 PST 2012


lg


On Tue, Dec 4, 2012 at 4:26 PM, Alexander Kornienko <alexfh at google.com>wrote:

> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121204/a54ab29f/attachment.html>


More information about the cfe-commits mailing list