diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -46,6 +46,7 @@ TYPE(DesignatedInitializerLSquare) \ TYPE(DesignatedInitializerPeriod) \ TYPE(DictLiteral) \ + TYPE(FatArrow) \ TYPE(ForEachMacro) \ TYPE(FunctionAnnotationRParen) \ TYPE(FunctionDeclarationName) \ @@ -61,17 +62,12 @@ TYPE(JsComputedPropertyName) \ TYPE(JsExponentiation) \ TYPE(JsExponentiationEqual) \ - TYPE(JsFatArrow) \ - TYPE(JsNonNullAssertion) \ - TYPE(JsNullishCoalescingOperator) \ - TYPE(JsNullPropagatingOperator) \ + TYPE(JsPipePipeEqual) \ TYPE(JsPrivateIdentifier) \ TYPE(JsTypeColon) \ TYPE(JsTypeOperator) \ TYPE(JsTypeOptionalQuestion) \ TYPE(JsAndAndEqual) \ - TYPE(JsPipePipeEqual) \ - TYPE(JsNullishCoalescingEqual) \ TYPE(LambdaArrow) \ TYPE(LambdaLBrace) \ TYPE(LambdaLSquare) \ @@ -80,6 +76,10 @@ TYPE(MacroBlockBegin) \ TYPE(MacroBlockEnd) \ TYPE(NamespaceMacro) \ + TYPE(NonNullAssertion) \ + TYPE(NullCoalescingEqual) \ + TYPE(NullCoalescingOperator) \ + TYPE(NullPropagatingOperator) \ TYPE(ObjCBlockLBrace) \ TYPE(ObjCBlockLParen) \ TYPE(ObjCDecl) \ diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -99,15 +99,14 @@ tok::period}; static const tok::TokenKind FatArrow[] = {tok::equal, tok::greater}; - if (tryMergeTokens(FatArrow, TT_JsFatArrow)) + if (tryMergeTokens(FatArrow, TT_FatArrow)) return; - if (tryMergeTokens(NullishCoalescingOperator, - TT_JsNullishCoalescingOperator)) { + if (tryMergeTokens(NullishCoalescingOperator, TT_NullCoalescingOperator)) { // Treat like the "||" operator (as opposed to the ternary ?). Tokens.back()->Tok.setKind(tok::pipepipe); return; } - if (tryMergeTokens(NullPropagatingOperator, TT_JsNullPropagatingOperator)) { + if (tryMergeTokens(NullPropagatingOperator, TT_NullPropagatingOperator)) { // Treat like a regular "." access. Tokens.back()->Tok.setKind(tok::period); return; @@ -321,7 +320,7 @@ return false; auto &NullishCoalescing = *(Tokens.end() - 2); auto &Equal = *(Tokens.end() - 1); - if (NullishCoalescing->getType() != TT_JsNullishCoalescingOperator || + if (NullishCoalescing->getType() != TT_NullCoalescingOperator || !Equal->is(tok::equal)) return false; NullishCoalescing->Tok.setKind(tok::equal); // no '??=' in clang tokens. @@ -329,7 +328,7 @@ StringRef(NullishCoalescing->TokenText.begin(), Equal->TokenText.end() - NullishCoalescing->TokenText.begin()); NullishCoalescing->ColumnWidth += Equal->ColumnWidth; - NullishCoalescing->setType(TT_JsNullishCoalescingEqual); + NullishCoalescing->setType(TT_NullCoalescingEqual); Tokens.erase(Tokens.end() - 1); return true; } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1365,7 +1365,7 @@ if (!CurrentToken->isOneOf( TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro, TT_ForEachMacro, TT_TypenameMacro, TT_FunctionLBrace, - TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_JsFatArrow, + TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_FatArrow, TT_LambdaArrow, TT_NamespaceMacro, TT_OverloadedOperator, TT_RegexLiteral, TT_TemplateString, TT_ObjCStringLiteral, TT_UntouchableMacroFunc, TT_ConstraintJunctions, @@ -1578,13 +1578,13 @@ tok::kw_false, tok::kw_true, Keywords.kw_type, Keywords.kw_get, Keywords.kw_set) || Current.Previous->Tok.isLiteral()) { - Current.setType(TT_JsNonNullAssertion); + Current.setType(TT_NonNullAssertion); return; } } if (Current.Next && Current.Next->isOneOf(TT_BinaryOperator, Keywords.kw_as)) { - Current.setType(TT_JsNonNullAssertion); + Current.setType(TT_NonNullAssertion); return; } } @@ -2174,7 +2174,7 @@ return prec::Assignment; if (Current->is(TT_LambdaArrow)) return prec::Comma; - if (Current->is(TT_JsFatArrow)) + if (Current->is(TT_FatArrow)) return prec::Assignment; if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName) || (Current->is(tok::comment) && NextNonComment && @@ -3145,7 +3145,7 @@ return true; // Spaces around '=>'. - if (Left.is(TT_JsFatArrow) || Right.is(TT_JsFatArrow)) + if (Left.is(TT_FatArrow) || Right.is(TT_FatArrow)) return true; // No spaces around attribute target colons @@ -3165,7 +3165,7 @@ return false; // No space before null forgiving '!'. - if (Right.is(TT_JsNonNullAssertion)) + if (Right.is(TT_NonNullAssertion)) return false; // No space between consecutive commas '[,,]'. @@ -3193,7 +3193,7 @@ Right.is(tok::l_paren)) return true; } else if (Style.Language == FormatStyle::LK_JavaScript) { - if (Left.is(TT_JsFatArrow)) + if (Left.is(TT_FatArrow)) return true; // for await ( ... if (Right.is(tok::l_paren) && Left.is(Keywords.kw_await) && Left.Previous && @@ -3204,7 +3204,7 @@ const FormatToken *Next = Right.MatchingParen->getNextNonComment(); // An async arrow function, for example: `x = async () => foo();`, // as opposed to calling a function called async: `x = async();` - if (Next && Next->is(TT_JsFatArrow)) + if (Next && Next->is(TT_FatArrow)) return true; } if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) || @@ -3278,9 +3278,9 @@ // locations that should have whitespace following are identified by the // above set of follower tokens. return false; - if (Right.is(TT_JsNonNullAssertion)) + if (Right.is(TT_NonNullAssertion)) return false; - if (Left.is(TT_JsNonNullAssertion) && + if (Left.is(TT_NonNullAssertion) && Right.isOneOf(Keywords.kw_as, Keywords.kw_in)) return true; // "x! as string", "x! in y" } else if (Style.Language == FormatStyle::LK_Java) { @@ -3544,7 +3544,7 @@ // instead of bin-packing. return true; if (Right.is(tok::r_brace) && Left.is(tok::l_brace) && Left.Previous && - Left.Previous->is(TT_JsFatArrow)) { + Left.Previous->is(TT_FatArrow)) { // JS arrow function (=> {...}). switch (Style.AllowShortLambdasOnASingleLine) { case FormatStyle::SLS_All: @@ -3847,7 +3847,7 @@ if (NonComment && NonComment->is(tok::identifier) && NonComment->TokenText == "asserts") return false; - if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace)) + if (Left.is(TT_FatArrow) && Right.is(tok::l_brace)) return false; if (Left.is(TT_JsTypeColon)) return true; @@ -3883,7 +3883,7 @@ } if (Left.is(Keywords.kw_as)) return true; - if (Left.is(TT_JsNonNullAssertion)) + if (Left.is(TT_NonNullAssertion)) return true; if (Left.is(Keywords.kw_declare) && Right.isOneOf(Keywords.kw_module, tok::kw_namespace, diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1480,9 +1480,9 @@ } case tok::equal: // Fat arrows (=>) have tok::TokenKind tok::equal but TokenType - // TT_JsFatArrow. The always start an expression or a child block if + // TT_FatArrow. The always start an expression or a child block if // followed by a curly. - if (FormatTok->is(TT_JsFatArrow)) { + if (FormatTok->is(TT_FatArrow)) { nextToken(); if (FormatTok->is(tok::l_brace)) { // C# may break after => if the next character is a newline. @@ -1588,7 +1588,7 @@ --Line->Level; break; case tok::equal: - if (FormatTok->is(TT_JsFatArrow)) { + if (FormatTok->is(TT_FatArrow)) { ++Line->Level; do { nextToken(); @@ -1791,7 +1791,7 @@ // replace this by using parseAssigmentExpression() inside. do { if (Style.isCSharp()) { - if (FormatTok->is(TT_JsFatArrow)) { + if (FormatTok->is(TT_FatArrow)) { nextToken(); // Fat arrows can be followed by simple expressions or by child blocks // in curly braces. @@ -1807,7 +1807,7 @@ tryToParseJSFunction(); continue; } - if (FormatTok->is(TT_JsFatArrow)) { + if (FormatTok->is(TT_FatArrow)) { nextToken(); // Fat arrows can be followed by simple expressions or by child blocks // in curly braces.