diff options
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/FormatTokenLexer.cpp | 13 | ||||
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 23 | ||||
| -rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 3 |
3 files changed, 29 insertions, 10 deletions
diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index ab32938..a9ea5ec 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -318,14 +318,21 @@ void FormatTokenLexer::tryMergePreviousTokens() { {tok::equal, tok::greater}, {tok::star, tok::greater}, {tok::pipeequal, tok::greater}, - {tok::pipe, tok::arrow}, - {tok::hash, tok::minus, tok::hash}, - {tok::hash, tok::equal, tok::hash}}, + {tok::pipe, tok::arrow}}, TT_BinaryOperator) || Tokens.back()->is(tok::arrow)) { Tokens.back()->ForcedPrecedence = prec::Comma; return; } + if (Tokens.size() >= 3 && + Tokens[Tokens.size() - 3]->is(Keywords.kw_verilogHash) && + Tokens[Tokens.size() - 2]->isOneOf(tok::minus, tok::equal) && + Tokens[Tokens.size() - 1]->is(Keywords.kw_verilogHash) && + tryMergeTokens(3, TT_BinaryOperator)) { + Tokens.back()->setFinalizedType(TT_BinaryOperator); + Tokens.back()->ForcedPrecedence = prec::Comma; + return; + } } else if (Style.isTableGen()) { // TableGen's Multi line string starts with [{ if (tryMergeTokens({tok::l_square, tok::l_brace}, diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8e227da..cb41756c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -358,11 +358,11 @@ private: Contexts.back().IsExpression = false; } else if (OpeningParen.Previous && (OpeningParen.Previous->isOneOf( - tok::kw_static_assert, tok::kw_noexcept, tok::kw_explicit, - tok::kw_while, tok::l_paren, tok::comma, TT_CastRParen, + tok::kw_noexcept, tok::kw_explicit, tok::kw_while, + tok::l_paren, tok::comma, TT_CastRParen, TT_BinaryOperator) || OpeningParen.Previous->isIf())) { - // static_assert, if and while usually contain expressions. + // if and while usually contain expressions. Contexts.back().IsExpression = true; } else if (Style.isJavaScript() && OpeningParen.Previous && (OpeningParen.Previous->is(Keywords.kw_function) || @@ -454,6 +454,11 @@ private: if (StartsObjCSelector) OpeningParen.setType(TT_ObjCSelector); + const bool IsStaticAssert = + PrevNonComment && PrevNonComment->is(tok::kw_static_assert); + if (IsStaticAssert) + Contexts.back().InStaticAssertFirstArgument = true; + // MightBeFunctionType and ProbablyFunctionType are used for // function pointer and reference types as well as Objective-C // block types: @@ -583,8 +588,12 @@ private: } // When we discover a 'new', we set CanBeExpression to 'false' in order to // parse the type correctly. Reset that after a comma. - if (CurrentToken->is(tok::comma)) - Contexts.back().CanBeExpression = true; + if (CurrentToken->is(tok::comma)) { + if (IsStaticAssert) + Contexts.back().InStaticAssertFirstArgument = false; + else + Contexts.back().CanBeExpression = true; + } if (Style.isTableGen()) { if (CurrentToken->is(tok::comma)) { @@ -2144,6 +2153,7 @@ private: bool CaretFound = false; bool InCpp11AttributeSpecifier = false; bool InCSharpAttributeSpecifier = false; + bool InStaticAssertFirstArgument = false; bool VerilogAssignmentFound = false; // Whether the braces may mean concatenation instead of structure or array // literal. @@ -2440,7 +2450,8 @@ private: } else if (Current.isPointerOrReference()) { Current.setType(determineStarAmpUsage( Current, - Contexts.back().CanBeExpression && Contexts.back().IsExpression, + (Contexts.back().CanBeExpression && Contexts.back().IsExpression) || + Contexts.back().InStaticAssertFirstArgument, Contexts.back().ContextType == Context::TemplateArgument)); } else if (Current.isOneOf(tok::minus, tok::plus, tok::caret) || (Style.isVerilog() && Current.is(tok::pipe))) { diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index f24b8ab..406c77c 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -591,7 +591,8 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches, CurrentChangeWidthRight = CurrentChange.TokenLength; const FormatToken *MatchingParenToEncounter = nullptr; for (unsigned J = I + 1; - J != E && (Changes[J].NewlinesBefore == 0 || MatchingParenToEncounter); + J != E && (Changes[J].NewlinesBefore == 0 || + MatchingParenToEncounter || Changes[J].IsAligned); ++J) { const auto &Change = Changes[J]; const auto *Tok = Change.Tok; |
