Skip to content

Commit

Permalink
Use TT_FunctionDeclarationLParen
Browse files Browse the repository at this point in the history
  • Loading branch information
gedare committed Jul 10, 2024
1 parent e367b78 commit 5a5077b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,6 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
tok::kw_switch);
};
// Detecting functions is brittle. It would be better if we could annotate
// the LParen type of functions/calls.
auto IsFunctionDeclParen = [&](const FormatToken &Tok) {
return Tok.is(tok::l_paren) && Tok.Previous &&
(Tok.Previous->is(TT_FunctionDeclarationName) ||
Tok.endsSequence(TT_FunctionDeclarationName, tok::coloncolon));
};
auto IsLambdaParameterList = [](const FormatToken *Tok) {
// adapted from TokenAnnotator.cpp:isLambdaParameterList()
// Skip <...> if present.
Expand Down Expand Up @@ -846,10 +839,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
if (Tok.FakeLParens.size() > 0 && Tok.FakeLParens.back() > prec::Unknown)
return true;
if (Previous &&
(IsFunctionDeclParen(*Previous) || IsFunctionCallParen(*Previous) ||
IsLambdaParameterList(Previous))) {
(Previous->is(TT_FunctionDeclarationLParen) ||
IsFunctionCallParen(*Previous) || IsLambdaParameterList(Previous))) {
return !IsOpeningBracket(Tok) && Next && !Next->isMemberAccess() &&
!IsInTemplateString(Tok) && !IsFunctionDeclParen(*Next) &&
!IsInTemplateString(Tok) &&
!Next->is(TT_FunctionDeclarationLParen) &&
!IsFunctionCallParen(*Next);
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9352,7 +9352,7 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
") const noexcept -> std::vector<of_very_long_type>;",
Style);
verifyFormat(
"aaaaaaaaaaaaaaaaaaa(\n"
"x = aaaaaaaaaaaaaaa(\n"
" \"a aaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaa\"\n"
");",
Style);
Expand Down

0 comments on commit 5a5077b

Please sign in to comment.