This revision was automatically updated to reflect the committed changes. Closed by commit rG8aa3b8da5db2: [clang-format] Handle typename macros inside cast expressions (authored by arichardson).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86930/new/ 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 @@ -16557,6 +16557,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) \
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -16557,6 +16557,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) \
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits