@@ -115,6 +115,13 @@ static bool isCppAttribute(bool IsCpp, const FormatToken &Tok) {
115115 return AttrTok && AttrTok->startsSequence (tok::r_square, tok::r_square);
116116}
117117
118+ static bool isParametersKeyword (
119+ const FormatToken &Tok,
120+ const FormatStyle::KeywordedFunctionLikeMacro &declaration) {
121+ return std::find (declaration.Keywords .begin (), declaration.Keywords .end (),
122+ Tok.TokenText ) != declaration.Keywords .end ();
123+ }
124+
118125// / A parser that gathers additional information about tokens.
119126// /
120127// / The \c TokenAnnotator tries to match parenthesis and square brakets and
@@ -146,6 +153,25 @@ class AnnotatingParser {
146153 }
147154 }
148155
156+ const FormatStyle::KeywordedFunctionLikeMacro *
157+ findKeywordedFunctionLikeMacro (const FormatToken &LParen) {
158+ const FormatToken *TokBeforeFirstLParent = LParen.getPreviousNonComment ();
159+ // Unknown if line ends with ';', FunctionLikeOrFreestandingMacro otherwise.
160+ if (!TokBeforeFirstLParent ||
161+ !TokBeforeFirstLParent->isOneOf (TT_FunctionLikeOrFreestandingMacro,
162+ TT_Unknown)) {
163+ return nullptr ;
164+ }
165+ auto I = std::find_if (
166+ Style.KeywordedFunctionLikeMacros .begin (),
167+ Style.KeywordedFunctionLikeMacros .end (),
168+ [TokBeforeFirstLParent](
169+ const FormatStyle::KeywordedFunctionLikeMacro &Declaration) {
170+ return TokBeforeFirstLParent->TokenText == Declaration.Name ;
171+ });
172+ return I != Style.KeywordedFunctionLikeMacros .end () ? &*I : nullptr ;
173+ }
174+
149175 bool parseAngle () {
150176 if (!CurrentToken)
151177 return false ;
@@ -406,6 +432,10 @@ class AnnotatingParser {
406432 OpeningParen.Previous &&
407433 OpeningParen.Previous ->isOneOf (tok::kw_for, tok::kw_catch);
408434 Contexts.back ().IsExpression = !IsForOrCatch;
435+ } else if (const FormatStyle::KeywordedFunctionLikeMacro *macroStyle =
436+ findKeywordedFunctionLikeMacro (OpeningParen)) {
437+ Contexts.back ().ContextType = Context::KeywordedFunctionLikeMacro;
438+ Contexts.back ().KeywordedFunctionLikeMacroStyle = macroStyle;
409439 }
410440
411441 if (Style.isTableGen ()) {
@@ -2141,6 +2171,8 @@ class AnnotatingParser {
21412171 bool ColonIsObjCMethodExpr = false ;
21422172 FormatToken *FirstObjCSelectorName = nullptr ;
21432173 FormatToken *FirstStartOfName = nullptr ;
2174+ const FormatStyle::KeywordedFunctionLikeMacro
2175+ *KeywordedFunctionLikeMacroStyle = nullptr ;
21442176 bool CanBeExpression = true ;
21452177 bool CaretFound = false ;
21462178 bool InCpp11AttributeSpecifier = false ;
@@ -2171,6 +2203,8 @@ class AnnotatingParser {
21712203 C11GenericSelection,
21722204 // Like in the outer parentheses in `ffnand ff1(.q());`.
21732205 VerilogInstancePortList,
2206+ // Like in Q_PROPERTY(...)
2207+ KeywordedFunctionLikeMacro,
21742208 } ContextType = Unknown;
21752209 };
21762210
@@ -2409,8 +2443,14 @@ class AnnotatingParser {
24092443 Current.setType (TT_BinaryOperator);
24102444 } else if (isStartOfName (Current) &&
24112445 (!Line.MightBeFunctionDecl || Current.NestingLevel != 0 )) {
2412- Contexts.back ().FirstStartOfName = &Current;
2413- Current.setType (TT_StartOfName);
2446+ if (Contexts.back ().ContextType == Context::KeywordedFunctionLikeMacro &&
2447+ isParametersKeyword (
2448+ Current, *Contexts.back ().KeywordedFunctionLikeMacroStyle )) {
2449+ Current.setType (TT_FunctionParameterKeyword);
2450+ } else {
2451+ Contexts.back ().FirstStartOfName = &Current;
2452+ Current.setType (TT_StartOfName);
2453+ }
24142454 } else if (Current.is (tok::semi)) {
24152455 // Reset FirstStartOfName after finding a semicolon so that a for loop
24162456 // with multiple increment statements is not confused with a for loop
@@ -6254,7 +6294,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
62546294 Right.Next ->isOneOf (TT_FunctionDeclarationName, tok::kw_const)));
62556295 }
62566296 if (Right.isOneOf (TT_StartOfName, TT_FunctionDeclarationName,
6257- TT_ClassHeadName, tok::kw_operator)) {
6297+ TT_FunctionParameterKeyword, TT_ClassHeadName,
6298+ tok::kw_operator)) {
62586299 return true ;
62596300 }
62606301 if (Left.is (TT_PointerOrReference))
0 commit comments