r355158 - [clang-format][TableGen] Don't add spaces around items in square braces.
Jordan Rupprecht via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 28 16:12:19 PST 2019
Author: rupprecht
Date: Thu Feb 28 16:12:18 2019
New Revision: 355158
URL: http://llvm.org/viewvc/llvm-project?rev=355158&view=rev
Log:
[clang-format][TableGen] Don't add spaces around items in square braces.
Summary:
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.
Reviewers: djasper, krasimir, MyDeveloperDay
Reviewed By: MyDeveloperDay
Subscribers: MyDeveloperDay, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D55964
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestTableGen.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=355158&r1=355157&r2=355158&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Feb 28 16:12:18 2019
@@ -718,6 +718,11 @@ FormatStyle getLLVMStyle(FormatStyle::La
LLVMStyle.StatementMacros.push_back("Q_UNUSED");
LLVMStyle.StatementMacros.push_back("QT_REQUIRE_VERSION");
+ // Defaults that differ when not C++.
+ if (Language == FormatStyle::LK_TableGen) {
+ LLVMStyle.SpacesInContainerLiterals = false;
+ }
+
return LLVMStyle;
}
Modified: cfe/trunk/unittests/Format/FormatTestTableGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestTableGen.cpp?rev=355158&r1=355157&r2=355158&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestTableGen.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestTableGen.cpp Thu Feb 28 16:12:18 2019
@@ -51,5 +51,9 @@ TEST_F(FormatTestTableGen, FormatStringB
" \"very long help string\">;\n");
}
+TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) {
+ verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;\n");
+}
+
} // namespace format
} // end namespace clang
More information about the cfe-commits
mailing list