[PATCH] D110359: [clang-format] ensure clang-format command-line argument sets up the default left/right qualifier ordering
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 23 13:58:41 PDT 2021
MyDeveloperDay updated this revision to Diff 374660.
MyDeveloperDay added a comment.
Rename the ConstAlignment variable
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110359/new/
https://reviews.llvm.org/D110359
Files:
clang/tools/clang-format/ClangFormat.cpp
Index: clang/tools/clang-format/ClangFormat.cpp
===================================================================
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -106,9 +106,9 @@
cl::cat(ClangFormatCategory));
static cl::opt<std::string> QualifierAlignment(
- "qualifier-aligment",
+ "qualifier-alignment",
cl::desc(
- "If set, overrides the cvqualifier style behavior determined by the "
+ "If set, overrides the qualifier alignment style determined by the "
"QualifierAlignment style flag"),
cl::init(""), cl::cat(ClangFormatCategory));
@@ -410,14 +410,25 @@
return true;
}
- StringRef ConstAlignment = QualifierAlignment;
+ StringRef QualifierAlignmentOrder = QualifierAlignment;
FormatStyle->QualifierAlignment =
- StringSwitch<FormatStyle::QualifierAlignmentStyle>(ConstAlignment.lower())
+ StringSwitch<FormatStyle::QualifierAlignmentStyle>(QualifierAlignmentOrder.lower())
.Case("right", FormatStyle::QAS_Right)
.Case("left", FormatStyle::QAS_Left)
.Default(FormatStyle->QualifierAlignment);
+ if (FormatStyle->QualifierAlignment == FormatStyle::QAS_Left)
+ FormatStyle->QualifierOrder = {"const", "volatile", "type"};
+ else if (FormatStyle->QualifierAlignment == FormatStyle::QAS_Right)
+ FormatStyle->QualifierOrder = {"type", "const", "volatile"};
+ else if (QualifierAlignmentOrder.contains("type")) {
+ FormatStyle->QualifierAlignment = FormatStyle::QAS_Custom;
+ SmallVector<StringRef> Qualifiers;
+ QualifierAlignmentOrder.split(Qualifiers, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+ FormatStyle->QualifierOrder = {Qualifiers.begin(), Qualifiers.end()};
+ }
+
if (SortIncludes.getNumOccurrences() != 0) {
if (SortIncludes)
FormatStyle->SortIncludes = FormatStyle::SI_CaseSensitive;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110359.374660.patch
Type: text/x-patch
Size: 1895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210923/b8e252c6/attachment.bin>
More information about the cfe-commits
mailing list