[cfe-commits] r58891 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp
Daniel Dunbar
daniel at zuster.org
Fri Nov 7 21:48:37 PST 2008
Author: ddunbar
Date: Fri Nov 7 23:48:37 2008
New Revision: 58891
URL: http://llvm.org/viewvc/llvm-project?rev=58891&view=rev
Log:
Support getTypeInfo, getTypeAlign, getTypeSize on const Type*s.
- Size/align are not effected by CVR qualifiers.
Support getCanonicalType: const Type* -> const Type*.
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=58891&r1=58890&r2=58891&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Nov 7 23:48:37 2008
@@ -343,19 +343,28 @@
/// getTypeInfo - Get the size and alignment of the specified complete type in
/// bits.
- std::pair<uint64_t, unsigned> getTypeInfo(QualType T);
+ std::pair<uint64_t, unsigned> getTypeInfo(const Type *T);
+ std::pair<uint64_t, unsigned> 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 @@
/// 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
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=58891&r1=58890&r2=58891&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Nov 7 23:48:37 2008
@@ -223,7 +223,7 @@
/// getTypeSize - Return the size of the specified type, in bits. This method
/// does not work on incomplete types.
std::pair<uint64_t, unsigned>
-ASTContext::getTypeInfo(QualType T) {
+ASTContext::getTypeInfo(const Type *T) {
T = getCanonicalType(T);
uint64_t Width;
unsigned Align;
@@ -236,7 +236,7 @@
case Type::VariableArray:
assert(0 && "VLAs not implemented yet!");
case Type::ConstantArray: {
- ConstantArrayType *CAT = cast<ConstantArrayType>(T);
+ const ConstantArrayType *CAT = cast<ConstantArrayType>(T);
std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType());
Width = EltInfo.first*CAT->getSize().getZExtValue();
@@ -344,23 +344,25 @@
break;
}
case Type::ObjCInterface: {
- ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T);
+ const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T);
const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl());
Width = Layout.getSize();
Align = Layout.getAlignment();
break;
}
case Type::Tagged: {
- if (cast<TagType>(T)->getDecl()->isInvalidDecl()) {
+ const TagType *TT = cast<TagType>(T);
+
+ if (TT->getDecl()->isInvalidDecl()) {
Width = 1;
Align = 1;
break;
}
- if (EnumType *ET = dyn_cast<EnumType>(cast<TagType>(T)))
+ if (const EnumType *ET = dyn_cast<EnumType>(TT))
return getTypeInfo(ET->getDecl()->getIntegerType());
- RecordType *RT = cast<RecordType>(T);
+ const RecordType *RT = cast<RecordType>(TT);
const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl());
Width = Layout.getSize();
Align = Layout.getAlignment();
More information about the cfe-commits
mailing list