[PATCH] D93938: [clang-format] Fixed AfterEnum handling
Ally Tiritoglu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 15 00:52:38 PDT 2021
atirit updated this revision to Diff 330568.
atirit added a comment.
Added comments for the previous commit's changes and cleaned up those changes
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93938/new/
https://reviews.llvm.org/D93938
Files:
clang/lib/Format/TokenAnnotator.cpp
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3663,8 +3663,11 @@
}
if (isAllmanBrace(Left) || isAllmanBrace(Right)) {
+ // The tokens that could force an enum to not be on a single line are a
+ // trailing comment and a trailing comma on the last case. This checks for
+ // those.
bool lineContainsBreakingTokens = false;
- FormatToken *breakingSearchToken = Right.Previous;
+ const FormatToken *breakingSearchToken = &Right;
while ((breakingSearchToken = breakingSearchToken->Next)) {
bool hasBreakingComma = breakingSearchToken->is(tok::comma) &&
breakingSearchToken->Next->is(tok::r_brace);
@@ -3674,15 +3677,16 @@
}
}
bool isAllowedByAfterEnum =
- (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
- (Line.startsWith(tok::kw_typedef, tok::kw_enum) &&
- Style.BraceWrapping.AfterEnum);
+ (Line.startsWith(tok::kw_enum) ||
+ Line.startsWith(tok::kw_typedef, tok::kw_enum)) &&
+ Style.BraceWrapping.AfterEnum;
bool isLineTooBig = (strlen(Right.TokenText.data()) +
Right.OriginalColumn) > Style.ColumnLimit;
- bool isAllowedByShortEnums = !Style.AllowShortEnumsOnASingleLine ||
- isLineTooBig || lineContainsBreakingTokens;
- return (isAllowedByAfterEnum &&
- (isAllowedByShortEnums || lineContainsBreakingTokens)) ||
+ // AllowShortEnumsOnASingleLine is ignored if the line is too long or
+ // contains breaking tokens.
+ bool isAllowedByShortEnums = isLineTooBig || lineContainsBreakingTokens ||
+ !Style.AllowShortEnumsOnASingleLine;
+ return (isAllowedByAfterEnum && isAllowedByShortEnums) ||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) ||
(Line.startsWith(tok::kw_struct) && Style.BraceWrapping.AfterStruct);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93938.330568.patch
Type: text/x-patch
Size: 2089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210315/aff48ae3/attachment.bin>
More information about the cfe-commits
mailing list