diff options
author | Francois Ferrand <thetypz@gmail.com> | 2019-05-29 16:30:47 +0000 |
---|---|---|
committer | Francois Ferrand <thetypz@gmail.com> | 2019-05-29 16:30:47 +0000 |
commit | c5227a1f53103d6c0cbcb5a59da84356208df0dd (patch) | |
tree | 025607de43508ca352e0d14c6b10a36c4b51d09d /clang/lib/Format/TokenAnnotator.cpp | |
parent | 308b7139b1d8e2374014c37f170b30197271e958 (diff) | |
download | bcm5719-llvm-c5227a1f53103d6c0cbcb5a59da84356208df0dd.tar.gz bcm5719-llvm-c5227a1f53103d6c0cbcb5a59da84356208df0dd.zip |
[clang-format] Allow configuring list of function-like macros that resolve to a type
Summary:
Adds a `TypenameMacros` configuration option that causes certain identifiers to be handled in a way similar to `typeof()`.
This is enough to:
- Prevent misinterpreting declarations of pointers to such types as expressions (`STACK_OF(int) * foo` -> `STACK_OF(int) *foo`),
- Avoid surprising line breaks in variable/struct field declarations (`STACK_OF(int)\nfoo;` -> `STACK_OF(int) foo;`, see https://bugs.llvm.org/show_bug.cgi?id=30353).
Reviewers: Typz, krasimir, djasper
Reviewed By: Typz
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D57184
llvm-svn: 361986
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
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() || |