21
21
#include " clang/Basic/SourceManager.h"
22
22
#include " clang/Lex/Lexer.h"
23
23
24
+ #include < string>
25
+
24
26
namespace clang {
25
27
namespace format {
26
28
@@ -486,13 +488,11 @@ class TokenAnnotator {
486
488
Annotation.SpaceRequiredBefore = false ;
487
489
} else if (Annotation.Type == TokenAnnotation::TT_UnaryOperator) {
488
490
Annotation.SpaceRequiredBefore =
489
- Line.Tokens [i - 1 ].Tok .isNot (tok::l_paren);
491
+ Line.Tokens [i - 1 ].Tok .isNot (tok::l_paren) &&
492
+ Line.Tokens [i - 1 ].Tok .isNot (tok::l_square);
490
493
} else if (Line.Tokens [i - 1 ].Tok .is (tok::greater) &&
491
494
Line.Tokens [i].Tok .is (tok::greater)) {
492
- if (Annotation.Type == TokenAnnotation::TT_TemplateOpener &&
493
- Annotations[i - 1 ].Type == TokenAnnotation::TT_TemplateOpener)
494
- Annotation.SpaceRequiredBefore = Style.SplitTemplateClosingGreater ;
495
- else if (Annotation.Type == TokenAnnotation::TT_TemplateCloser &&
495
+ if (Annotation.Type == TokenAnnotation::TT_TemplateCloser &&
496
496
Annotations[i - 1 ].Type == TokenAnnotation::TT_TemplateCloser)
497
497
Annotation.SpaceRequiredBefore = Style.SplitTemplateClosingGreater ;
498
498
else
@@ -505,6 +505,9 @@ class TokenAnnotator {
505
505
Annotations[i - 1 ].Type == TokenAnnotation::TT_TemplateCloser &&
506
506
Line.Tokens [i].Tok .is (tok::l_paren)) {
507
507
Annotation.SpaceRequiredBefore = false ;
508
+ } else if (Line.Tokens [i].Tok .is (tok::less) &&
509
+ Line.Tokens [0 ].Tok .is (tok::hash)) {
510
+ Annotation.SpaceRequiredBefore = true ;
508
511
} else {
509
512
Annotation.SpaceRequiredBefore =
510
513
spaceRequiredBetween (Line.Tokens [i - 1 ].Tok , Line.Tokens [i].Tok );
@@ -533,7 +536,7 @@ class TokenAnnotator {
533
536
534
537
if (Tok.Tok .is (tok::star) || Tok.Tok .is (tok::amp))
535
538
Annotation.Type = determineStarAmpUsage (i);
536
- else if (Tok. Tok . is (tok::minus) && Line. Tokens [i - 1 ]. Tok . is (tok::equal ))
539
+ else if (isUnaryOperator (i ))
537
540
Annotation.Type = TokenAnnotation::TT_UnaryOperator;
538
541
else if (isBinaryOperator (Line.Tokens [i]))
539
542
Annotation.Type = TokenAnnotation::TT_BinaryOperator;
@@ -548,6 +551,17 @@ class TokenAnnotator {
548
551
}
549
552
}
550
553
554
+ bool isUnaryOperator (unsigned Index) {
555
+ const Token &Tok = Line.Tokens [Index].Tok ;
556
+ if (Tok.isNot (tok::minus) && Tok.isNot (tok::plus))
557
+ return false ;
558
+ const Token &PreviousTok = Line.Tokens [Index - 1 ].Tok ;
559
+ if (PreviousTok.is (tok::equal) || PreviousTok.is (tok::l_paren) ||
560
+ PreviousTok.is (tok::comma) || PreviousTok.is (tok::l_square))
561
+ return true ;
562
+ return Annotations[Index - 1 ].Type == TokenAnnotation::TT_BinaryOperator;
563
+ }
564
+
551
565
bool isBinaryOperator (const FormatToken &Tok) {
552
566
switch (Tok.Tok .getKind ()) {
553
567
case tok::equal:
0 commit comments