diff options
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/Format.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Format/FormatToken.h | 1 | ||||
-rw-r--r-- | clang/lib/Format/FormatTokenLexer.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 18 |
4 files changed, 15 insertions, 7 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 2772db0a110..d775ca14a7c 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -505,6 +505,7 @@ template <> struct MappingTraits<FormatStyle> { IO.mapOptional("Standard", Style.Standard); IO.mapOptional("StatementMacros", Style.StatementMacros); IO.mapOptional("TabWidth", Style.TabWidth); + IO.mapOptional("TypenameMacros", Style.TypenameMacros); IO.mapOptional("UseTab", Style.UseTab); } }; diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index f54ffe9d54c..e8b737f00bd 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -96,6 +96,7 @@ namespace format { TYPE(TrailingAnnotation) \ TYPE(TrailingReturnArrow) \ TYPE(TrailingUnaryOperator) \ + TYPE(TypenameMacro) \ TYPE(UnaryOperator) \ TYPE(CSharpStringLiteral) \ TYPE(CSharpNullCoalescing) \ diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index c12daa7f20e..4438756579a 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -39,6 +39,8 @@ FormatTokenLexer::FormatTokenLexer(const SourceManager &SourceMgr, FileID ID, Macros.insert({&IdentTable.get(ForEachMacro), TT_ForEachMacro}); for (const std::string &StatementMacro : Style.StatementMacros) Macros.insert({&IdentTable.get(StatementMacro), TT_StatementMacro}); + for (const std::string &TypenameMacro : Style.TypenameMacros) + Macros.insert({&IdentTable.get(TypenameMacro), TT_TypenameMacro}); } ArrayRef<FormatToken *> FormatTokenLexer::lex() { diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 4e255700d4d..1dca764eaeb 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1194,11 +1194,12 @@ private: // Reset token type in case we have already looked at it and then // recovered from an error (e.g. failure to find the matching >). - if (!CurrentToken->isOneOf( - TT_LambdaLSquare, TT_LambdaLBrace, TT_ForEachMacro, - TT_FunctionLBrace, TT_ImplicitStringLiteral, TT_InlineASMBrace, - TT_JsFatArrow, TT_LambdaArrow, TT_OverloadedOperator, - TT_RegexLiteral, TT_TemplateString, TT_ObjCStringLiteral)) + if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_LambdaLBrace, + TT_ForEachMacro, TT_TypenameMacro, + TT_FunctionLBrace, TT_ImplicitStringLiteral, + TT_InlineASMBrace, TT_JsFatArrow, TT_LambdaArrow, + TT_OverloadedOperator, TT_RegexLiteral, + TT_TemplateString, TT_ObjCStringLiteral)) CurrentToken->Type = TT_Unknown; CurrentToken->Role.reset(); CurrentToken->MatchingParen = nullptr; @@ -1416,6 +1417,7 @@ private: if (AfterParen->Tok.isNot(tok::caret)) { if (FormatToken *BeforeParen = Current.MatchingParen->Previous) if (BeforeParen->is(tok::identifier) && + !BeforeParen->is(TT_TypenameMacro) && BeforeParen->TokenText == BeforeParen->TokenText.upper() && (!BeforeParen->Previous || BeforeParen->Previous->ClosesTemplateDeclaration)) @@ -1667,7 +1669,8 @@ private: FormatToken *TokenBeforeMatchingParen = PrevToken->MatchingParen->getPreviousNonComment(); if (TokenBeforeMatchingParen && - TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype)) + TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype, + TT_TypenameMacro)) return TT_PointerOrReference; } @@ -2527,7 +2530,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, FormatToken *TokenBeforeMatchingParen = Left.MatchingParen->getPreviousNonComment(); if (!TokenBeforeMatchingParen || - !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype)) + !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype, + TT_TypenameMacro)) return true; } return (Left.Tok.isLiteral() || |