[cfe-commits] r41715 - in /cfe/trunk: Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Type.h
Chris Lattner
clattner at apple.com
Tue Sep 25 18:03:15 PDT 2007
On Sep 4, 2007, at 2:13 PM, Steve Naroff wrote:
> Simplified initializer semantic analysis by adding the following 2
> methods:
> - ArrayType::getBaseType(), and
> - ConstantArrayType::getMaximumElements().
> Wanted to do this cleanup before adding structure support, which
> will add more complexity.
A blast from the past,
> ======================================================================
> ========
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Tue Sep 4 16:13:33 2007
> @@ -471,6 +471,14 @@
> ArraySizeModifier getSizeModifier() const { return SizeModifier; }
> unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
>
> + QualType getBaseType() const {
> + const ArrayType *AT;
> + QualType ElmtType = getElementType();
> + // If we have a multi-dimensional array, navigate to the base
> type.
> + while ((AT = ElmtType->getAsArrayType()))
> + ElmtType = AT->getElementType();
> + return ElmtType;
> + }
Please add a comment above this method and above getMaximumElements,
describing what it does for doxygen output and for other readers. In
both of these functions, you can slightly simplify them by doing:
> + QualType getBaseType() const {
> + QualType ElmtType = getElementType();
> + // If we have a multi-dimensional array, navigate to the base
> type.
> + while (const ArrayType *AT = ElmtType->getAsArrayType())
> + ElmtType = AT->getElementType();
> + return ElmtType;
> + }
Which eliminates an explicit var definition, shrinks a scope, and
gets rid of extra parens, likewise in getMaximumElements.
-Chris
> + int getMaximumElements() const {
> + QualType ElmtType = getElementType();
> + int maxElements = getSize().getZExtValue();
> +
> + const ConstantArrayType *CAT;
> + // If we have a multi-dimensional array, include it's elements.
> + while ((CAT = ElmtType->getAsConstantArrayType())) {
> + ElmtType = CAT->getElementType();
> + maxElements *= CAT->getSize().getZExtValue();
> + }
> + return maxElements;
> + }
> virtual void getAsStringInternal(std::string &InnerString) const;
>
> void Profile(llvm::FoldingSetNodeID &ID) {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list