[clang] [clang][AST] Clean up AST element count functions (PR #215456)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 10 22:07:44 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Make them static and clarify documentation.
---
Full diff: https://github.com/llvm/llvm-project/pull/215456.diff
2 Files Affected:
- (modified) clang/include/clang/AST/ASTContext.h (+8-6)
- (modified) clang/lib/AST/ASTContext.cpp (+5-7)
``````````diff
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index bd4dd2ad06aac..43099d546159f 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3229,12 +3229,14 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// actually be an array type).
QualType getBaseElementType(QualType QT) const;
- /// Return number of constant array elements.
- uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
-
- /// Return number of elements initialized in an ArrayInitLoopExpr.
- uint64_t
- getArrayInitLoopExprElementCount(const ArrayInitLoopExpr *AILE) const;
+ /// Return number of (potentially nested) constant array elements.
+ static uint64_t getConstantArrayElementCount(const ConstantArrayType *CA);
+
+ /// Return number of elements initialized in a (potentially nested)
+ /// ArrayInitLoopExpr.
+ /// \c AILE may be null, in which case 0 is returned.
+ static uint64_t
+ getArrayInitLoopExprElementCount(const ArrayInitLoopExpr *AILE);
/// Perform adjustment on the parameter type of a function.
///
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5539a39d6edaf..4838fbba1100e 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -8228,20 +8228,18 @@ QualType ASTContext::getBaseElementType(QualType type) const {
return getQualifiedType(type, qs);
}
-/// getConstantArrayElementCount - Returns number of constant array elements.
-uint64_t
-ASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) const {
+uint64_t ASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) {
uint64_t ElementCount = 1;
do {
ElementCount *= CA->getZExtSize();
- CA = dyn_cast_or_null<ConstantArrayType>(
- CA->getElementType()->getAsArrayTypeUnsafe());
+ CA = dyn_cast_if_present<ConstantArrayType>(
+ CA->getElementType()->getAsArrayTypeUnsafe());
} while (CA);
return ElementCount;
}
-uint64_t ASTContext::getArrayInitLoopExprElementCount(
- const ArrayInitLoopExpr *AILE) const {
+uint64_t
+ASTContext::getArrayInitLoopExprElementCount(const ArrayInitLoopExpr *AILE) {
if (!AILE)
return 0;
``````````
</details>
https://github.com/llvm/llvm-project/pull/215456
More information about the cfe-commits
mailing list