[PATCH] D86930: [clang-format] Handle typename macros inside cast expressions
Alexander Richardson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 1 05:02:40 PDT 2020
arichardson created this revision.
arichardson added reviewers: MyDeveloperDay, JakeMerdichAMD, sammccall, curdeius.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
arichardson requested review of this revision.
Before: x = (STACK_OF(uint64_t)) & a;
After: x = (STACK_OF(uint64_t))&a;
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86930
Files:
clang/lib/Format/FormatToken.h
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
@@ -16550,6 +16550,8 @@
Macros.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("STACK_OF(int)* a;", Macros);
verifyFormat("STACK_OF(int*)* a;", Macros);
+ verifyFormat("x = (STACK_OF(uint64_t))*a;", Macros);
+ verifyFormat("x = (STACK_OF(uint64_t))&a;", Macros);
}
TEST_F(FormatTest, AmbersandInLamda) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -244,6 +244,8 @@
Contexts.back().IsExpression = false;
} else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) {
Left->setType(TT_AttributeParen);
+ } else if (Left->Previous && Left->Previous->is(TT_TypenameMacro)) {
+ Left->setType(TT_TypenameMacroParen);
} else if (Left->Previous && Left->Previous->is(TT_ForEachMacro)) {
// The first argument to a foreach macro is a declaration.
Contexts.back().IsForEachMacro = true;
@@ -335,6 +337,8 @@
if (Left->is(TT_AttributeParen))
CurrentToken->setType(TT_AttributeParen);
+ if (Left->is(TT_TypenameMacroParen))
+ CurrentToken->setType(TT_TypenameMacroParen);
if (Left->Previous && Left->Previous->is(TT_JavaAnnotation))
CurrentToken->setType(TT_JavaAnnotation);
if (Left->Previous && Left->Previous->is(TT_LeadingJavaAnnotation))
@@ -1855,9 +1859,11 @@
}
return T && T->is(TT_PointerOrReference);
};
- bool ParensAreType = !Tok.Previous || Tok.Previous->is(TT_TemplateCloser) ||
- Tok.Previous->isSimpleTypeSpecifier() ||
- IsQualifiedPointerOrReference(Tok.Previous);
+ bool ParensAreType =
+ !Tok.Previous ||
+ Tok.Previous->isOneOf(TT_TemplateCloser, TT_TypenameMacroParen) ||
+ Tok.Previous->isSimpleTypeSpecifier() ||
+ IsQualifiedPointerOrReference(Tok.Previous);
bool ParensCouldEndDecl =
Tok.Next->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater);
if (ParensAreType && !ParensCouldEndDecl)
Index: clang/lib/Format/FormatToken.h
===================================================================
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -102,6 +102,7 @@
TYPE(TrailingReturnArrow) \
TYPE(TrailingUnaryOperator) \
TYPE(TypenameMacro) \
+ TYPE(TypenameMacroParen) \
TYPE(UnaryOperator) \
TYPE(UntouchableMacroFunc) \
TYPE(CSharpStringLiteral) \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86930.289136.patch
Type: text/x-patch
Size: 3089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200901/e133d7b2/attachment-0001.bin>
More information about the cfe-commits
mailing list