rupprecht created this revision. rupprecht added reviewers: djasper, krasimir. Herald added a subscriber: cfe-commits.
clang-formatting wants to add spaces around items in square braces, e.g. [1, 2] -> [ 1, 2 ]. Based on a quick check [1], it seems like most cases are using the [1, 2] format, so make that the consistent one. [1] in llvm `.td` files, the regex `\[[^ ]` (bracket followed by not-a-space) shows up ~400 times, but `\[\s[^ ]` (bracket followed by one space and one not-a-space) shows up ~40 times => ~90% uses this format. Repository: rC Clang https://reviews.llvm.org/D55964 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTestTableGen.cpp Index: unittests/Format/FormatTestTableGen.cpp =================================================================== --- unittests/Format/FormatTestTableGen.cpp +++ unittests/Format/FormatTestTableGen.cpp @@ -52,5 +52,9 @@ " \"very long help string\">;\n"); } +TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) { + verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;\n"); +} + } // namespace format } // end namespace clang Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -432,6 +432,10 @@ } else if (CurrentToken->is(tok::r_square) && Parent && Parent->is(TT_TemplateCloser)) { Left->Type = TT_ArraySubscriptLSquare; + } else if (Style.Language == FormatStyle::LK_TableGen) { + // TableGen treats '[' as array subscripts to avoid spaces, e.g. + // def foo : Flag<["-", "--"], "foo">; + Left->Type = TT_ArraySubscriptLSquare; } else if (Style.Language == FormatStyle::LK_Proto || Style.Language == FormatStyle::LK_TextProto) { // Square braces in LK_Proto can either be message field attributes:
Index: unittests/Format/FormatTestTableGen.cpp =================================================================== --- unittests/Format/FormatTestTableGen.cpp +++ unittests/Format/FormatTestTableGen.cpp @@ -52,5 +52,9 @@ " \"very long help string\">;\n"); } +TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) { + verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;\n"); +} + } // namespace format } // end namespace clang Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -432,6 +432,10 @@ } else if (CurrentToken->is(tok::r_square) && Parent && Parent->is(TT_TemplateCloser)) { Left->Type = TT_ArraySubscriptLSquare; + } else if (Style.Language == FormatStyle::LK_TableGen) { + // TableGen treats '[' as array subscripts to avoid spaces, e.g. + // def foo : Flag<["-", "--"], "foo">; + Left->Type = TT_ArraySubscriptLSquare; } else if (Style.Language == FormatStyle::LK_Proto || Style.Language == FormatStyle::LK_TextProto) { // Square braces in LK_Proto can either be message field attributes:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits