[PATCH] D86721: [clang-format] Parse double-square attributes as pointer qualifiers
Alexander Richardson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 27 08:47:32 PDT 2020
arichardson created this revision.
arichardson added reviewers: MyDeveloperDay, JakeMerdichAMD, sammccall, curdeius, aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
arichardson requested review of this revision.
Before: x = (foo *[[clang::attr]] const) * v;
After: x = (foo *[[clang::attr]] const)*v;
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86721
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8068,6 +8068,7 @@
verifyIndependentOfContext("MACRO(A *_Null_unspecified a);");
verifyIndependentOfContext("MACRO(A *__attribute__((foo)) a);");
verifyIndependentOfContext("MACRO(A *__attribute((foo)) a);");
+ verifyIndependentOfContext("MACRO(A *[[clang::attr]] a);");
verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
verifyFormat("void f() { f(float{1}, a * a); }");
// FIXME: Is there a way to make this work?
@@ -8137,14 +8138,16 @@
verifyFormat("x = (foo *_Nullable)*v;");
verifyFormat("x = (foo *_Null_unspecified)*v;");
verifyFormat("x = (foo *_Nonnull const)*v;");
+ verifyFormat("x = (foo *[[clang::attr]] const)*v;");
// Check that we handle multiple trailing qualifiers and skip them all to
// determine that the expression is a cast to a pointer type.
FormatStyle LongPointerRight = getLLVMStyleWithColumns(999);
FormatStyle LongPointerLeft = getLLVMStyleWithColumns(999);
LongPointerLeft.PointerAlignment = FormatStyle::PAS_Left;
- StringRef AllQualifiers = "const volatile restrict __attribute__((foo)) "
- "_Nonnull _Null_unspecified _Nonnull";
+ StringRef AllQualifiers =
+ "const volatile restrict __attribute__((foo)) _Nonnull _Null_unspecified "
+ "_Nonnull [[clang::attr]]";
verifyFormat(("x = (foo *" + AllQualifiers + ")*v;").str(), LongPointerRight);
verifyFormat(("x = (foo* " + AllQualifiers + ")*v;").str(), LongPointerLeft);
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1840,6 +1840,12 @@
T = T->MatchingParen->Previous->Previous;
continue;
}
+ } else if (T->is(TT_AttributeSquare)) {
+ // Handle `x = (foo *[[clang::foo]])&v;`:
+ if (T->MatchingParen && T->MatchingParen->Previous) {
+ T = T->MatchingParen->Previous;
+ continue;
+ }
} else if (T->canBePointerOrReferenceQualifier()) {
T = T->Previous;
continue;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86721.288355.patch
Type: text/x-patch
Size: 2320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200827/10f72aec/attachment.bin>
More information about the cfe-commits
mailing list