Author: Timm Baeder Date: 2026-08-25T15:30:28+02:00 New Revision: b3ab190f4ce5364328413855614bed93d790e6d2
URL: https://github.com/llvm/llvm-project/commit/b3ab190f4ce5364328413855614bed93d790e6d2 DIFF: https://github.com/llvm/llvm-project/commit/b3ab190f4ce5364328413855614bed93d790e6d2.diff LOG: [clang][AST] Clean up AST element count functions (#215456) Make them static and clarify documentation. Added: Modified: clang/include/clang/AST/ASTContext.h clang/lib/AST/ASTContext.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 802f1ebf755b7..013bc68a00a06 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -3267,12 +3267,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 2be9d9430e1ec..335d58ff2c9c8 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -8232,20 +8232,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; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
