[PATCH] D78982: [clang-format] Fix Microsoft style for enums
Aaron Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 27 22:05:04 PDT 2020
asmith updated this revision to Diff 260542.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78982/new/
https://reviews.llvm.org/D78982
Files:
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/UnwrappedLineParser.cpp
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2280,9 +2280,17 @@
return true;
}
+ if (!Style.AllowEnumsOnASingleLine)
+ addUnwrappedLine();
// Parse enum body.
nextToken();
+ if (!Style.AllowEnumsOnASingleLine) {
+ addUnwrappedLine();
+ Line->Level += 1;
+ }
bool HasError = !parseBracedList(/*ContinueOnSemicolons=*/true);
+ if (!Style.AllowEnumsOnASingleLine)
+ Line->Level -= 1;
if (HasError) {
if (FormatTok->is(tok::semi))
nextToken();
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -397,6 +397,8 @@
Style.AllowAllConstructorInitializersOnNextLine);
IO.mapOptional("AllowAllParametersOfDeclarationOnNextLine",
Style.AllowAllParametersOfDeclarationOnNextLine);
+ IO.mapOptional("AllowEnumsOnASingleLine",
+ Style.AllowEnumsOnASingleLine);
IO.mapOptional("AllowShortBlocksOnASingleLine",
Style.AllowShortBlocksOnASingleLine);
IO.mapOptional("AllowShortCaseLabelsOnASingleLine",
@@ -752,6 +754,7 @@
LLVMStyle.AllowAllArgumentsOnNextLine = true;
LLVMStyle.AllowAllConstructorInitializersOnNextLine = true;
LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
+ LLVMStyle.AllowEnumsOnASingleLine = true;
LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
LLVMStyle.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
LLVMStyle.AllowShortCaseLabelsOnASingleLine = false;
@@ -1137,6 +1140,7 @@
Style.BraceWrapping.BeforeCatch = true;
Style.BraceWrapping.BeforeElse = true;
Style.PenaltyReturnTypeOnItsOwnLine = 1000;
+ Style.AllowEnumsOnASingleLine = false;
Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
Style.AllowShortCaseLabelsOnASingleLine = false;
Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
Index: clang/include/clang/Format/Format.h
===================================================================
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -221,6 +221,20 @@
/// \endcode
bool AllowAllParametersOfDeclarationOnNextLine;
+ /// Allow enums on a single line.
+ /// \code
+ /// true:
+ /// enum { A, B } myEnum;
+ ///
+ /// false:
+ /// enum
+ /// {
+ /// A,
+ /// B,
+ /// } myEnum;
+ /// \endcode
+ bool AllowEnumsOnASingleLine;
+
/// Different styles for merging short blocks containing at most one
/// statement.
enum ShortBlockStyle {
@@ -2160,6 +2174,7 @@
R.AllowAllConstructorInitializersOnNextLine &&
AllowAllParametersOfDeclarationOnNextLine ==
R.AllowAllParametersOfDeclarationOnNextLine &&
+ AllowEnumsOnASingleLine == R.AllowEnumsOnASingleLine &&
AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
AllowShortCaseLabelsOnASingleLine ==
R.AllowShortCaseLabelsOnASingleLine &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78982.260542.patch
Type: text/x-patch
Size: 3233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200428/6f46b3ef/attachment-0001.bin>
More information about the cfe-commits
mailing list