[clang] 064da42 - [clang-format][NFC] Remove unneeded ST_ChildBlock in annotator

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 7 00:51:36 PST 2025


Author: Owen Pan
Date: 2025-01-07T00:51:29-08:00
New Revision: 064da423c3b46907f5011a4537a88fbae9ac03d4

URL: https://github.com/llvm/llvm-project/commit/064da423c3b46907f5011a4537a88fbae9ac03d4
DIFF: https://github.com/llvm/llvm-project/commit/064da423c3b46907f5011a4537a88fbae9ac03d4.diff

LOG: [clang-format][NFC] Remove unneeded ST_ChildBlock in annotator

Also, remove redundant llvm:: in the annotator and return early for globstar
in matchFilePath().

Added: 
    

Modified: 
    clang/lib/Format/MatchFilePath.cpp
    clang/lib/Format/TokenAnnotator.cpp
    clang/lib/Format/TokenAnnotator.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/MatchFilePath.cpp b/clang/lib/Format/MatchFilePath.cpp
index 3d8614838e5356..1f1e4bfac1e309 100644
--- a/clang/lib/Format/MatchFilePath.cpp
+++ b/clang/lib/Format/MatchFilePath.cpp
@@ -63,10 +63,10 @@ bool matchFilePath(StringRef Pattern, StringRef FilePath) {
       if (I == EOP) // `Pattern` ends with a star.
         return Globstar || NoMoreSeparatorsInFilePath;
       if (Pattern[I] != Separator) {
-        Globstar = false;
         // `Pattern` ends with a lone backslash.
         if (Pattern[I] == '\\' && ++I == EOP)
           return false;
+        Globstar = false;
       }
       // The star is followed by a (possibly escaped) `Separator`.
       if (Pattern[I] == Separator) {

diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index e18e9a6fcd074b..bf5ee281c43119 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -137,8 +137,6 @@ class AnnotatingParser {
 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:
@@ -3395,13 +3393,13 @@ class ExpressionParser {
   /// 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);
     }
@@ -3579,7 +3577,7 @@ class ExpressionParser {
 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
@@ -3700,7 +3698,7 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
   Line.Type = Parser.parseLine();
 
   if (!Line.Children.empty()) {
-    ScopeStack.push_back(ST_ChildBlock);
+    ScopeStack.push_back(ST_Other);
     const bool InRequiresExpression = Line.Type == LT_RequiresExpression;
     for (auto &Child : Line.Children) {
       if (InRequiresExpression &&

diff  --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h
index fa15517042f250..16e920e8ad8a29 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -38,13 +38,11 @@ enum LineType {
 };
 
 enum ScopeType {
-  // Contained in child block.
-  ST_ChildBlock,
   // Contained in class declaration/definition.
   ST_Class,
   // Contained in compound requirement.
   ST_CompoundRequirement,
-  // Contained within other scope block (function, loop, if/else, etc).
+  // Contained in other blocks (function, lambda, loop, if/else, child, etc).
   ST_Other,
 };
 


        


More information about the cfe-commits mailing list