This revision was automatically updated to reflect the committed changes. Closed by commit rL302658: clang-format: refine calculating brace types. (authored by mprobst).
Changed prior to commit: https://reviews.llvm.org/D33006?vs=98309&id=98448#toc Repository: rL LLVM https://reviews.llvm.org/D33006 Files: cfe/trunk/lib/Format/UnwrappedLineParser.cpp cfe/trunk/unittests/Format/FormatTestJS.cpp Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp =================================================================== --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp @@ -368,9 +368,10 @@ (Style.Language == FormatStyle::LK_JavaScript && NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in, Keywords.kw_as)) || + (Style.isCpp() && NextTok->is(tok::l_paren)) || NextTok->isOneOf(tok::comma, tok::period, tok::colon, tok::r_paren, tok::r_square, tok::l_brace, - tok::l_square, tok::l_paren, tok::ellipsis) || + tok::l_square, tok::ellipsis) || (NextTok->is(tok::identifier) && !PrevTok->isOneOf(tok::semi, tok::r_brace, tok::l_brace)) || (NextTok->is(tok::semi) && Index: cfe/trunk/unittests/Format/FormatTestJS.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp +++ cfe/trunk/unittests/Format/FormatTestJS.cpp @@ -470,6 +470,16 @@ " inner2(a, b);\n" "}"); verifyFormat("function f() {}"); + verifyFormat("function aFunction() {}\n" + "(function f() {\n" + " var x = 1;\n" + "}());\n"); + // Known issue: this should wrap after {}, but calculateBraceTypes + // misclassifies the first braces as a BK_BracedInit. + verifyFormat("function aFunction(){} {\n" + " let x = 1;\n" + " console.log(x);\n" + "}\n"); } TEST_F(FormatTestJS, GeneratorFunctions) {
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp =================================================================== --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp @@ -368,9 +368,10 @@ (Style.Language == FormatStyle::LK_JavaScript && NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in, Keywords.kw_as)) || + (Style.isCpp() && NextTok->is(tok::l_paren)) || NextTok->isOneOf(tok::comma, tok::period, tok::colon, tok::r_paren, tok::r_square, tok::l_brace, - tok::l_square, tok::l_paren, tok::ellipsis) || + tok::l_square, tok::ellipsis) || (NextTok->is(tok::identifier) && !PrevTok->isOneOf(tok::semi, tok::r_brace, tok::l_brace)) || (NextTok->is(tok::semi) && Index: cfe/trunk/unittests/Format/FormatTestJS.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp +++ cfe/trunk/unittests/Format/FormatTestJS.cpp @@ -470,6 +470,16 @@ " inner2(a, b);\n" "}"); verifyFormat("function f() {}"); + verifyFormat("function aFunction() {}\n" + "(function f() {\n" + " var x = 1;\n" + "}());\n"); + // Known issue: this should wrap after {}, but calculateBraceTypes + // misclassifies the first braces as a BK_BracedInit. + verifyFormat("function aFunction(){} {\n" + " let x = 1;\n" + " console.log(x);\n" + "}\n"); } TEST_F(FormatTestJS, GeneratorFunctions) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits