[clang] [NFC] Factor out common parts of ArraySections into its own class (PR #89639)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 22 10:56:56 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff dc20a0ea1fd04a2ef95eb5c73e9f88357fc5f694 b95304b22915217ad149c1b22a6517c585067acf -- clang/include/clang/AST/Expr.h clang/include/clang/AST/ExprOpenMP.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 3fc0170d1a..511c722e10 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -6618,50 +6618,49 @@ public:
 // This type does not capture a 'stride', only a lower-bound and length (plus
 // the base expression), but provides room via a template argument to get
 // additional ones.
-template<unsigned NumSubExprs, bool AllowNullExprs>
+template <unsigned NumSubExprs, bool AllowNullExprs>
 class ArraySectionExprBase : public Expr {
-  enum {BASE, LOWER_BOUND, LENGTH, END_EXPR = NumSubExprs};
+  enum { BASE, LOWER_BOUND, LENGTH, END_EXPR = NumSubExprs };
   Stmt *SubExprs[END_EXPR];
   SourceLocation ColonLocFirst;
   SourceLocation RBracketLoc;
 
-  protected:
-    ArraySectionExprBase(StmtClass SC, Expr *Base, Expr *LowerBound,
-                         Expr *Length, QualType Type, ExprValueKind VK,
-                         ExprObjectKind OK, SourceLocation ColonLocFirst,
-                         SourceLocation RBracketLoc)
-        : Expr(SC, Type, VK, OK), ColonLocFirst(ColonLocFirst),
-          RBracketLoc(RBracketLoc) {
-      setBase(Base);
-      setLowerBound(LowerBound);
-      setLength(Length);
-    }
+protected:
+  ArraySectionExprBase(StmtClass SC, Expr *Base, Expr *LowerBound, Expr *Length,
+                       QualType Type, ExprValueKind VK, ExprObjectKind OK,
+                       SourceLocation ColonLocFirst, SourceLocation RBracketLoc)
+      : Expr(SC, Type, VK, OK), ColonLocFirst(ColonLocFirst),
+        RBracketLoc(RBracketLoc) {
+    setBase(Base);
+    setLowerBound(LowerBound);
+    setLength(Length);
+  }
 
-    explicit ArraySectionExprBase(StmtClass SC, EmptyShell Shell)
-        : Expr(SC, Shell) {}
+  explicit ArraySectionExprBase(StmtClass SC, EmptyShell Shell)
+      : Expr(SC, Shell) {}
 
-    void setSubExpr(unsigned Idx, Expr *SubExpr) {
-      assert(Idx > LENGTH &&
-             "setting sub expression owned by ArraySectionExprBase: Should be "
-             "using the direct 'setter' functions");
-      assert((SubExpr || AllowNullExprs) && "Null expression when not allowed");
-      SubExprs[Idx] = SubExpr;
-    }
+  void setSubExpr(unsigned Idx, Expr *SubExpr) {
+    assert(Idx > LENGTH &&
+           "setting sub expression owned by ArraySectionExprBase: Should be "
+           "using the direct 'setter' functions");
+    assert((SubExpr || AllowNullExprs) && "Null expression when not allowed");
+    SubExprs[Idx] = SubExpr;
+  }
 
-    Expr *getSubExpr(unsigned Idx) {
-      assert(Idx > LENGTH &&
-             "getting sub expression owned by ArraySectionExprBase: Should be "
-             "using the direct 'getter' functions");
-      return cast_or_null<Expr>(SubExprs[Idx]);
-    }
-    const Expr *getSubExpr(unsigned Idx) const {
-      assert(Idx > LENGTH &&
-             "getting sub expression owned by ArraySectionExprBase: Should be "
-             "using the direct 'getter' functions");
-      return cast_or_null<Expr>(SubExprs[Idx]);
-    }
+  Expr *getSubExpr(unsigned Idx) {
+    assert(Idx > LENGTH &&
+           "getting sub expression owned by ArraySectionExprBase: Should be "
+           "using the direct 'getter' functions");
+    return cast_or_null<Expr>(SubExprs[Idx]);
+  }
+  const Expr *getSubExpr(unsigned Idx) const {
+    assert(Idx > LENGTH &&
+           "getting sub expression owned by ArraySectionExprBase: Should be "
+           "using the direct 'getter' functions");
+    return cast_or_null<Expr>(SubExprs[Idx]);
+  }
 
-  public:
+public:
   /// Get base of the array section.
   Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
   const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
@@ -6706,13 +6705,13 @@ class ArraySectionExprBase : public Expr {
   SourceLocation getExprLoc() const LLVM_READONLY {
     return getBase()->getExprLoc();
   }
-    child_range children() {
-      return child_range(&SubExprs[BASE], &SubExprs[END_EXPR]);
-    }
+  child_range children() {
+    return child_range(&SubExprs[BASE], &SubExprs[END_EXPR]);
+  }
 
-    const_child_range children() const {
-      return const_child_range(&SubExprs[BASE], &SubExprs[END_EXPR]);
-    }
+  const_child_range children() const {
+    return const_child_range(&SubExprs[BASE], &SubExprs[END_EXPR]);
+  }
 };
 
 /// Frontend produces RecoveryExprs on semantic errors that prevent creating
diff --git a/clang/include/clang/AST/ExprOpenMP.h b/clang/include/clang/AST/ExprOpenMP.h
index c410c82d94..f013f92cca 100644
--- a/clang/include/clang/AST/ExprOpenMP.h
+++ b/clang/include/clang/AST/ExprOpenMP.h
@@ -54,7 +54,7 @@ namespace clang {
 /// where size is the size of the array dimension. When the lower-bound is
 /// absent it defaults to 0.
 namespace OMPArraySectionIndices {
-  enum { BASE, LOWER_BOUND, LENGTH, STRIDE, END_EXPR };
+enum { BASE, LOWER_BOUND, LENGTH, STRIDE, END_EXPR };
 }
 class OMPArraySectionExpr
     : public ArraySectionExprBase<OMPArraySectionIndices::END_EXPR,

``````````

</details>


https://github.com/llvm/llvm-project/pull/89639


More information about the cfe-commits mailing list