diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-09 18:31:57 +0900 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-09 18:33:27 +0900 |
commit | df025ebf872052c0761d44a3ef9b65e9675af8a8 (patch) | |
tree | 9b4e94583e2536546d6606270bcdf846c95e1ba2 /clang/lib/Format/TokenAnnotator.cpp | |
parent | 4428c9d0b1344179f85a72e183a44796976521e3 (diff) | |
parent | bdcf47e4bcb92889665825654bb80a8bbe30379e (diff) | |
download | llvm-users/chapuni/cov/single/loop.zip llvm-users/chapuni/cov/single/loop.tar.gz llvm-users/chapuni/cov/single/loop.tar.bz2 |
Merge branch 'users/chapuni/cov/single/base' into users/chapuni/cov/single/loopusers/chapuni/cov/single/loop
Conflicts:
clang/lib/CodeGen/CoverageMappingGen.cpp
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f2cfa7f..bf5ee28 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -137,12 +137,12 @@ public: private: ScopeType getScopeType(const FormatToken &Token) const { switch (Token.getType()) { - case TT_LambdaLBrace: - return ST_ChildBlock; case TT_ClassLBrace: case TT_StructLBrace: case TT_UnionLBrace: return ST_Class; + case TT_CompoundRequirementLBrace: + return ST_CompoundRequirement; default: return ST_Other; } @@ -1580,7 +1580,10 @@ private: return false; break; case tok::l_brace: - if (Style.Language == FormatStyle::LK_TextProto) { + if (IsCpp) { + if (Tok->is(TT_RequiresExpressionLBrace)) + Line.Type = LT_RequiresExpression; + } else if (Style.Language == FormatStyle::LK_TextProto) { FormatToken *Previous = Tok->getPreviousNonComment(); if (Previous && Previous->isNot(TT_DictLiteral)) Previous->setType(TT_SelectorName); @@ -2022,8 +2025,11 @@ public: if (!consumeToken()) return LT_Invalid; } - if (Line.Type == LT_AccessModifier) - return LT_AccessModifier; + if (const auto Type = Line.Type; Type == LT_AccessModifier || + Type == LT_RequiresExpression || + Type == LT_SimpleRequirement) { + return Type; + } if (KeywordVirtualFound) return LT_VirtualFunctionDecl; if (ImportStatement) @@ -2076,7 +2082,7 @@ private: TT_RecordLBrace, TT_StructLBrace, TT_UnionLBrace, TT_RequiresClause, TT_RequiresClauseInARequiresExpression, TT_RequiresExpression, TT_RequiresExpressionLParen, TT_RequiresExpressionLBrace, - TT_BracedListLBrace)) { + TT_CompoundRequirementLBrace, TT_BracedListLBrace)) { CurrentToken->setType(TT_Unknown); } CurrentToken->Role.reset(); @@ -2792,6 +2798,16 @@ private: return true; } + auto IsNonVariableTemplate = [](const FormatToken &Tok) { + if (Tok.isNot(TT_TemplateCloser)) + return false; + const auto *Less = Tok.MatchingParen; + if (!Less) + return false; + const auto *BeforeLess = Less->getPreviousNonComment(); + return BeforeLess && BeforeLess->isNot(TT_VariableTemplate); + }; + // Heuristically try to determine whether the parentheses contain a type. auto IsQualifiedPointerOrReference = [](const FormatToken *T, const LangOptions &LangOpts) { @@ -2825,10 +2841,11 @@ private: } return T && T->is(TT_PointerOrReference); }; - bool ParensAreType = - BeforeRParen->isOneOf(TT_TemplateCloser, TT_TypeDeclarationParen) || - BeforeRParen->isTypeName(LangOpts) || - IsQualifiedPointerOrReference(BeforeRParen, LangOpts); + + bool ParensAreType = IsNonVariableTemplate(*BeforeRParen) || + BeforeRParen->is(TT_TypeDeclarationParen) || + BeforeRParen->isTypeName(LangOpts) || + IsQualifiedPointerOrReference(BeforeRParen, LangOpts); bool ParensCouldEndDecl = AfterRParen->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater); if (ParensAreType && !ParensCouldEndDecl) @@ -3089,6 +3106,11 @@ private: } } + if (Line.Type == LT_SimpleRequirement || + (!Scopes.empty() && Scopes.back() == ST_CompoundRequirement)) { + return TT_BinaryOperator; + } + return TT_PointerOrReference; } @@ -3371,13 +3393,13 @@ private: /// Parse unary operator expressions and surround them with fake /// parentheses if appropriate. void parseUnaryOperator() { - llvm::SmallVector<FormatToken *, 2> Tokens; + SmallVector<FormatToken *, 2> Tokens; while (Current && Current->is(TT_UnaryOperator)) { Tokens.push_back(Current); next(); } parse(PrecedenceArrowAndPeriod); - for (FormatToken *Token : llvm::reverse(Tokens)) { + for (FormatToken *Token : reverse(Tokens)) { // The actual precedence doesn't matter. addFakeParenthesis(Token, prec::Unknown); } @@ -3555,7 +3577,7 @@ private: void TokenAnnotator::setCommentLineLevels( SmallVectorImpl<AnnotatedLine *> &Lines) const { const AnnotatedLine *NextNonCommentLine = nullptr; - for (AnnotatedLine *Line : llvm::reverse(Lines)) { + for (AnnotatedLine *Line : reverse(Lines)) { assert(Line->First); // If the comment is currently aligned with the line immediately following @@ -3676,9 +3698,16 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) { Line.Type = Parser.parseLine(); if (!Line.Children.empty()) { - ScopeStack.push_back(ST_ChildBlock); - for (auto &Child : Line.Children) + ScopeStack.push_back(ST_Other); + const bool InRequiresExpression = Line.Type == LT_RequiresExpression; + for (auto &Child : Line.Children) { + if (InRequiresExpression && + !Child->First->isOneOf(tok::kw_typename, tok::kw_requires, + TT_CompoundRequirementLBrace)) { + Child->Type = LT_SimpleRequirement; + } annotate(*Child); + } // ScopeStack can become empty if Child has an unmatched `}`. if (!ScopeStack.empty()) ScopeStack.pop_back(); @@ -4930,6 +4959,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, Right.is(TT_ModulePartitionColon)) { return true; } + + if (Right.is(TT_AfterPPDirective)) + return true; + // No space between import foo:bar but keep a space between import :bar; if (Left.is(tok::identifier) && Right.is(TT_ModulePartitionColon)) return false; |