17
17
#include " clang/Basic/SourceManager.h"
18
18
#include " clang/Basic/TokenKinds.h"
19
19
#include " llvm/ADT/SmallPtrSet.h"
20
+ #include " llvm/ADT/SmallVector.h"
21
+ #include " llvm/ADT/StringRef.h"
20
22
#include " llvm/Support/Debug.h"
21
23
22
24
#define DEBUG_TYPE " format-token-annotator"
@@ -38,6 +40,10 @@ static bool mustBreakAfterAttributes(const FormatToken &Tok,
38
40
39
41
namespace {
40
42
43
+ // TODO: Add new Type modifiers
44
+ llvm::SmallVector<llvm::StringRef> castIdentifiers{" __type_identity_t" ,
45
+ " remove_reference_t" };
46
+
41
47
// / Returns \c true if the line starts with a token that can start a statement
42
48
// / with an initializer.
43
49
static bool startsWithInitStatement (const AnnotatedLine &Line) {
@@ -2474,6 +2480,11 @@ class AnnotatingParser {
2474
2480
Current.getNextNonComment ()->isOneOf (tok::comma, tok::r_brace)) {
2475
2481
Current.setType (TT_StringInConcatenation);
2476
2482
}
2483
+ } else if (Style.isCpp () && Current.is (tok::kw_using)) {
2484
+ if (Current.Next && Current.Next ->Next && Current.Next ->Next ->Next ) {
2485
+ if (Current.Next ->Next ->Next ->isTypeName (LangOpts))
2486
+ castIdentifiers.push_back (Current.Next ->TokenText );
2487
+ }
2477
2488
} else if (Current.is (tok::l_paren)) {
2478
2489
if (lParenStartsCppCast (Current))
2479
2490
Current.setType (TT_CppCastLParen);
@@ -2831,8 +2842,21 @@ class AnnotatingParser {
2831
2842
IsQualifiedPointerOrReference (BeforeRParen, LangOpts);
2832
2843
bool ParensCouldEndDecl =
2833
2844
AfterRParen->isOneOf (tok::equal, tok::semi, tok::l_brace, tok::greater);
2834
- if (ParensAreType && !ParensCouldEndDecl)
2845
+ if (ParensAreType && !ParensCouldEndDecl) {
2846
+ if (BeforeRParen->is (TT_TemplateCloser)) {
2847
+ if (determineUnaryOperatorByUsage (*AfterRParen))
2848
+ return true ;
2849
+ if (AfterRParen->isOneOf (tok::plus, tok::minus, tok::star, tok::exclaim,
2850
+ tok::amp)) {
2851
+ auto *Prev = BeforeRParen->MatchingParen ->getPreviousNonComment ();
2852
+ for (auto &name : castIdentifiers)
2853
+ if (Prev->TokenText == name)
2854
+ return true ;
2855
+ return false ;
2856
+ }
2857
+ }
2835
2858
return true ;
2859
+ }
2836
2860
2837
2861
// At this point, we heuristically assume that there are no casts at the
2838
2862
// start of the line. We assume that we have found most cases where there
0 commit comments