summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/clang/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2020-08-09 15:51:07 +0000
committerpatrick <patrick@openbsd.org>2020-08-09 15:51:07 +0000
commit389bb291c0c8961ca40ac7a2636e1ca69ca7653c (patch)
treee027d0b3ed5ed27fe08d1bcaa20e3c191232a53b /gnu/llvm/clang/lib/Format/TokenAnnotator.cpp
parentImport LLVM 10.0.1 including clang, lld and lldb. (diff)
downloadwireguard-openbsd-389bb291c0c8961ca40ac7a2636e1ca69ca7653c.tar.xz
wireguard-openbsd-389bb291c0c8961ca40ac7a2636e1ca69ca7653c.zip
Import LLVM 10.0.1 including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r--gnu/llvm/clang/lib/Format/TokenAnnotator.cpp52
1 files changed, 38 insertions, 14 deletions
diff --git a/gnu/llvm/clang/lib/Format/TokenAnnotator.cpp b/gnu/llvm/clang/lib/Format/TokenAnnotator.cpp
index 70bcd7048c5..8cb786a4d34 100644
--- a/gnu/llvm/clang/lib/Format/TokenAnnotator.cpp
+++ b/gnu/llvm/clang/lib/Format/TokenAnnotator.cpp
@@ -2176,6 +2176,10 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
Next = Next->Next;
continue;
}
+ if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
+ Next = Next->MatchingParen;
+ continue;
+ }
break;
}
@@ -2705,20 +2709,40 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
tok::l_square));
if (Right.is(tok::star) && Left.is(tok::l_paren))
return false;
- if (Right.isOneOf(tok::star, tok::amp, tok::ampamp) &&
- (Left.is(tok::identifier) || Left.isSimpleTypeSpecifier()) &&
- // Space between the type and the * in:
- // operator void*()
- // operator char*()
- // operator /*comment*/ const char*()
- // operator volatile /*comment*/ char*()
- // operator Foo*()
- // dependent on PointerAlignment style.
- Left.Previous &&
- (Left.Previous->endsSequence(tok::kw_operator) ||
- Left.Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
- Left.Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
- return (Style.PointerAlignment != FormatStyle::PAS_Left);
+ if (Right.is(tok::star) && Left.is(tok::star))
+ return false;
+ if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+ const FormatToken *Previous = &Left;
+ while (Previous && !Previous->is(tok::kw_operator)) {
+ if (Previous->is(tok::identifier) || Previous->isSimpleTypeSpecifier()) {
+ Previous = Previous->getPreviousNonComment();
+ continue;
+ }
+ if (Previous->is(TT_TemplateCloser) && Previous->MatchingParen) {
+ Previous = Previous->MatchingParen->getPreviousNonComment();
+ continue;
+ }
+ if (Previous->is(tok::coloncolon)) {
+ Previous = Previous->getPreviousNonComment();
+ continue;
+ }
+ break;
+ }
+ // Space between the type and the * in:
+ // operator void*()
+ // operator char*()
+ // operator /*comment*/ const char*()
+ // operator volatile /*comment*/ char*()
+ // operator Foo*()
+ // operator C<T>*()
+ // operator std::Foo*()
+ // operator C<T>::D<U>*()
+ // dependent on PointerAlignment style.
+ if (Previous && (Previous->endsSequence(tok::kw_operator) ||
+ Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
+ Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
+ return (Style.PointerAlignment != FormatStyle::PAS_Left);
+ }
const auto SpaceRequiredForArrayInitializerLSquare =
[](const FormatToken &LSquareTok, const FormatStyle &Style) {
return Style.SpacesInContainerLiterals ||