From: Daniel Dunbar Date: Sat, 8 Nov 2008 05:48:37 +0000 (+0000) Subject: Support getTypeInfo, getTypeAlign, getTypeSize on const Type*s. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d75118af76cae2bfc06389cde410e14bd0a19fc;p=clang Support getTypeInfo, getTypeAlign, getTypeSize on const Type*s. - Size/align are not effected by CVR qualifiers. Support getCanonicalType: const Type* -> const Type*. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58891 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 4f30e82ec4..b5adffdcb0 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -343,19 +343,28 @@ public: /// getTypeInfo - Get the size and alignment of the specified complete type in /// bits. - std::pair getTypeInfo(QualType T); + std::pair getTypeInfo(const Type *T); + std::pair getTypeInfo(QualType T) { + return getTypeInfo(T.getTypePtr()); + } /// getTypeSize - Return the size of the specified type, in bits. This method /// does not work on incomplete types. uint64_t getTypeSize(QualType T) { return getTypeInfo(T).first; } + uint64_t getTypeSize(const Type *T) { + return getTypeInfo(T).first; + } /// getTypeAlign - Return the alignment of the specified type, in bits. This /// method does not work on incomplete types. unsigned getTypeAlign(QualType T) { return getTypeInfo(T).second; } + unsigned getTypeAlign(const Type *T) { + return getTypeInfo(T).second; + } /// getASTRecordLayout - Get or compute information about the layout of the /// specified record (struct/union/class), which indicates its size and field @@ -374,6 +383,9 @@ public: /// to be free of any of these, allowing two canonical types to be compared /// for exact equality with a simple pointer comparison. QualType getCanonicalType(QualType T); + const Type *getCanonicalType(const Type *T) { + return T->getCanonicalTypeInternal().getTypePtr(); + } /// Type Query functions. If the type is an instance of the specified class, /// return the Type pointer for the underlying maximally pretty type. This diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 1aea5b5c69..52abf43a0e 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -223,7 +223,7 @@ const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { /// getTypeSize - Return the size of the specified type, in bits. This method /// does not work on incomplete types. std::pair -ASTContext::getTypeInfo(QualType T) { +ASTContext::getTypeInfo(const Type *T) { T = getCanonicalType(T); uint64_t Width; unsigned Align; @@ -236,7 +236,7 @@ ASTContext::getTypeInfo(QualType T) { case Type::VariableArray: assert(0 && "VLAs not implemented yet!"); case Type::ConstantArray: { - ConstantArrayType *CAT = cast(T); + const ConstantArrayType *CAT = cast(T); std::pair EltInfo = getTypeInfo(CAT->getElementType()); Width = EltInfo.first*CAT->getSize().getZExtValue(); @@ -344,23 +344,25 @@ ASTContext::getTypeInfo(QualType T) { break; } case Type::ObjCInterface: { - ObjCInterfaceType *ObjCI = cast(T); + const ObjCInterfaceType *ObjCI = cast(T); const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); Width = Layout.getSize(); Align = Layout.getAlignment(); break; } case Type::Tagged: { - if (cast(T)->getDecl()->isInvalidDecl()) { + const TagType *TT = cast(T); + + if (TT->getDecl()->isInvalidDecl()) { Width = 1; Align = 1; break; } - if (EnumType *ET = dyn_cast(cast(T))) + if (const EnumType *ET = dyn_cast(TT)) return getTypeInfo(ET->getDecl()->getIntegerType()); - RecordType *RT = cast(T); + const RecordType *RT = cast(TT); const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); Width = Layout.getSize(); Align = Layout.getAlignment();