1414
1515#include " UnwrappedLineParser.h"
1616#include " FormatToken.h"
17- #include " clang/Basic/TokenKinds.h"
1817#include " llvm/ADT/STLExtras.h"
1918#include " llvm/Support/Debug.h"
2019#include " llvm/Support/raw_ostream.h"
@@ -995,6 +994,13 @@ static bool isJSDeclOrStmt(const AdditionalKeywords &Keywords,
995994 Keywords.kw_import , tok::kw_export);
996995}
997996
997+ // Checks whether a token is a type in K&R C (aka C78).
998+ static bool isC78Type (const FormatToken &Tok) {
999+ return Tok.isOneOf (tok::kw_char, tok::kw_short, tok::kw_int, tok::kw_long,
1000+ tok::kw_unsigned, tok::kw_float, tok::kw_double,
1001+ tok::identifier);
1002+ }
1003+
9981004// This function checks whether a token starts the first parameter declaration
9991005// in a K&R C (aka C78) function definition, e.g.:
10001006// int f(a, b)
@@ -1006,9 +1012,8 @@ static bool isC78ParameterDecl(const FormatToken *Tok) {
10061012 if (!Tok)
10071013 return false ;
10081014
1009- if (!Tok->isOneOf (tok::kw_int, tok::kw_char, tok::kw_float, tok::kw_double,
1010- tok::kw_struct, tok::kw_union, tok::kw_long, tok::kw_short,
1011- tok::kw_unsigned, tok::kw_register))
1015+ if (!isC78Type (*Tok) &&
1016+ !Tok->isOneOf (tok::kw_register, tok::kw_struct, tok::kw_union))
10121017 return false ;
10131018
10141019 Tok = Tok->Previous ;
@@ -1369,22 +1374,26 @@ void UnwrappedLineParser::parseStructuralElement(bool IsTopLevel) {
13691374 case tok::r_brace:
13701375 addUnwrappedLine ();
13711376 return ;
1372- case tok::l_paren:
1377+ case tok::l_paren: {
13731378 parseParens ();
13741379 // Break the unwrapped line if a K&R C function definition has a parameter
13751380 // declaration.
13761381 if (!IsTopLevel || !Style.isCpp ())
13771382 break ;
13781383 if (!Previous || Previous->isNot (tok::identifier))
13791384 break ;
1380- if (Previous->Previous && Previous->Previous ->is (tok::at))
1385+ const FormatToken *PrevPrev = Previous->Previous ;
1386+ if (!PrevPrev || (!isC78Type (*PrevPrev) && PrevPrev->isNot (tok::star)))
13811387 break ;
1382- if (!Line->Tokens .begin ()->Tok ->is (tok::kw_typedef) &&
1383- isC78ParameterDecl (FormatTok)) {
1388+ const FormatToken *Next = AllTokens[Tokens->getPosition () + 1 ];
1389+ if (Next && Next->isOneOf (tok::l_paren, tok::semi))
1390+ break ;
1391+ if (isC78ParameterDecl (FormatTok)) {
13841392 addUnwrappedLine ();
13851393 return ;
13861394 }
13871395 break ;
1396+ }
13881397 case tok::kw_operator:
13891398 nextToken ();
13901399 if (FormatTok->isBinaryOperator ())
0 commit comments