Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Type.cpp - Type representation and manipulation ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements type-related functionality. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Nuno Lopes | b381aac | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 15 | #include "clang/AST/Type.h" |
Argyrios Kyrtzidis | 49aa7ff | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Steve Naroff | 980e508 | 2007-10-01 19:00:59 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringExtras.h" |
Ted Kremenek | 7360fda | 2008-09-18 23:09:54 +0000 | [diff] [blame] | 20 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 23 | bool QualType::isConstant(ASTContext &Ctx) const { |
Nuno Lopes | b381aac | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 24 | if (isConstQualified()) |
| 25 | return true; |
| 26 | |
| 27 | if (getTypePtr()->isArrayType()) |
| 28 | return Ctx.getAsArrayType(*this)->getElementType().isConstant(Ctx); |
| 29 | |
| 30 | return false; |
| 31 | } |
| 32 | |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame^] | 33 | void Type::Destroy(ASTContext& C) { |
| 34 | this->~Type(); |
| 35 | C.getAllocator().Deallocate(this); |
Ted Kremenek | 4b05b1d | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void VariableArrayType::Destroy(ASTContext& C) { |
| 39 | SizeExpr->Destroy(C); |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame^] | 40 | this->~VariableArrayType(); |
| 41 | C.getAllocator().Deallocate(this); |
Ted Kremenek | 4b05b1d | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 42 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 43 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 44 | void DependentSizedArrayType::Destroy(ASTContext& C) { |
| 45 | SizeExpr->Destroy(C); |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame^] | 46 | this->~DependentSizedArrayType(); |
| 47 | C.getAllocator().Deallocate(this); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 48 | } |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 49 | |
| 50 | /// getArrayElementTypeNoTypeQual - If this is an array type, return the |
| 51 | /// element type of the array, potentially with type qualifiers missing. |
| 52 | /// This method should never be used when type qualifiers are meaningful. |
| 53 | const Type *Type::getArrayElementTypeNoTypeQual() const { |
| 54 | // If this is directly an array type, return it. |
| 55 | if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) |
| 56 | return ATy->getElementType().getTypePtr(); |
| 57 | |
| 58 | // If the canonical form of this type isn't the right kind, reject it. |
| 59 | if (!isa<ArrayType>(CanonicalType)) { |
| 60 | // Look through type qualifiers |
| 61 | if (ArrayType *AT = dyn_cast<ArrayType>(CanonicalType.getUnqualifiedType())) |
| 62 | return AT->getElementType().getTypePtr(); |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | // If this is a typedef for an array type, strip the typedef off without |
| 67 | // losing all typedef information. |
| 68 | return getDesugaredType()->getArrayElementTypeNoTypeQual(); |
| 69 | } |
| 70 | |
| 71 | /// getDesugaredType - Return the specified type with any "sugar" removed from |
| 72 | /// type type. This takes off typedefs, typeof's etc. If the outer level of |
| 73 | /// the type is already concrete, it returns it unmodified. This is similar |
| 74 | /// to getting the canonical type, but it doesn't remove *all* typedefs. For |
| 75 | /// example, it return "T*" as "T*", (not as "int*"), because the pointer is |
| 76 | /// concrete. |
| 77 | QualType Type::getDesugaredType() const { |
| 78 | if (const TypedefType *TDT = dyn_cast<TypedefType>(this)) |
| 79 | return TDT->LookThroughTypedefs(); |
| 80 | if (const TypeOfExpr *TOE = dyn_cast<TypeOfExpr>(this)) |
| 81 | return TOE->getUnderlyingExpr()->getType(); |
| 82 | if (const TypeOfType *TOT = dyn_cast<TypeOfType>(this)) |
| 83 | return TOT->getUnderlyingType(); |
| 84 | // FIXME: remove this cast. |
| 85 | return QualType(const_cast<Type*>(this), 0); |
| 86 | } |
| 87 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 88 | /// isVoidType - Helper method to determine if this is the 'void' type. |
| 89 | bool Type::isVoidType() const { |
| 90 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 91 | return BT->getKind() == BuiltinType::Void; |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 92 | if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType)) |
| 93 | return AS->getBaseType()->isVoidType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 94 | return false; |
| 95 | } |
| 96 | |
| 97 | bool Type::isObjectType() const { |
| 98 | if (isa<FunctionType>(CanonicalType)) |
| 99 | return false; |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 100 | if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType)) |
| 101 | return AS->getBaseType()->isObjectType(); |
| 102 | return !CanonicalType->isIncompleteType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | bool Type::isDerivedType() const { |
| 106 | switch (CanonicalType->getTypeClass()) { |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 107 | case ASQual: |
| 108 | return cast<ASQualType>(CanonicalType)->getBaseType()->isDerivedType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 109 | case Pointer: |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 110 | case VariableArray: |
| 111 | case ConstantArray: |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 112 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 113 | case FunctionProto: |
| 114 | case FunctionNoProto: |
| 115 | case Reference: |
| 116 | return true; |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 117 | case Tagged: |
| 118 | return !cast<TagType>(CanonicalType)->getDecl()->isEnum(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 119 | default: |
| 120 | return false; |
| 121 | } |
| 122 | } |
| 123 | |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 124 | bool Type::isClassType() const { |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 125 | if (const RecordType *RT = getAsRecordType()) |
| 126 | return RT->getDecl()->isClass(); |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 127 | return false; |
| 128 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 129 | bool Type::isStructureType() const { |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 130 | if (const RecordType *RT = getAsRecordType()) |
| 131 | return RT->getDecl()->isStruct(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 132 | return false; |
| 133 | } |
| 134 | bool Type::isUnionType() const { |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 135 | if (const RecordType *RT = getAsRecordType()) |
| 136 | return RT->getDecl()->isUnion(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 137 | return false; |
| 138 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 139 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 140 | bool Type::isComplexType() const { |
Steve Naroff | 02f62a9 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 141 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 142 | return CT->getElementType()->isFloatingType(); |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 143 | if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType)) |
| 144 | return AS->getBaseType()->isComplexType(); |
Steve Naroff | 02f62a9 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 145 | return false; |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 148 | bool Type::isComplexIntegerType() const { |
| 149 | // Check for GCC complex integer extension. |
| 150 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 151 | return CT->getElementType()->isIntegerType(); |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 152 | if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType)) |
| 153 | return AS->getBaseType()->isComplexIntegerType(); |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 154 | return false; |
| 155 | } |
| 156 | |
| 157 | const ComplexType *Type::getAsComplexIntegerType() const { |
| 158 | // Are we directly a complex type? |
| 159 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) { |
| 160 | if (CTy->getElementType()->isIntegerType()) |
| 161 | return CTy; |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 162 | return 0; |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 163 | } |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 164 | |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 165 | // If the canonical form of this type isn't what we want, reject it. |
| 166 | if (!isa<ComplexType>(CanonicalType)) { |
| 167 | // Look through type qualifiers (e.g. ASQualType's). |
| 168 | if (isa<ComplexType>(CanonicalType.getUnqualifiedType())) |
| 169 | return CanonicalType.getUnqualifiedType()->getAsComplexIntegerType(); |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 170 | return 0; |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 173 | // If this is a typedef for a complex type, strip the typedef off without |
| 174 | // losing all typedef information. |
| 175 | return getDesugaredType()->getAsComplexIntegerType(); |
| 176 | } |
| 177 | |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 178 | const BuiltinType *Type::getAsBuiltinType() const { |
| 179 | // If this is directly a builtin type, return it. |
| 180 | if (const BuiltinType *BTy = dyn_cast<BuiltinType>(this)) |
| 181 | return BTy; |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 182 | |
| 183 | // If the canonical form of this type isn't a builtin type, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 184 | if (!isa<BuiltinType>(CanonicalType)) { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 185 | // Look through type qualifiers (e.g. ASQualType's). |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 186 | if (isa<BuiltinType>(CanonicalType.getUnqualifiedType())) |
| 187 | return CanonicalType.getUnqualifiedType()->getAsBuiltinType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 188 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 189 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 190 | |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 191 | // If this is a typedef for a builtin type, strip the typedef off without |
| 192 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 193 | return getDesugaredType()->getAsBuiltinType(); |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 196 | const FunctionType *Type::getAsFunctionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 197 | // If this is directly a function type, return it. |
| 198 | if (const FunctionType *FTy = dyn_cast<FunctionType>(this)) |
| 199 | return FTy; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 200 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 201 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 202 | if (!isa<FunctionType>(CanonicalType)) { |
| 203 | // Look through type qualifiers |
| 204 | if (isa<FunctionType>(CanonicalType.getUnqualifiedType())) |
| 205 | return CanonicalType.getUnqualifiedType()->getAsFunctionType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 206 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 207 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 208 | |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 209 | // If this is a typedef for a function type, strip the typedef off without |
| 210 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 211 | return getDesugaredType()->getAsFunctionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Chris Lattner | b77792e | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 214 | const FunctionTypeProto *Type::getAsFunctionTypeProto() const { |
| 215 | return dyn_cast_or_null<FunctionTypeProto>(getAsFunctionType()); |
| 216 | } |
| 217 | |
| 218 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 219 | const PointerLikeType *Type::getAsPointerLikeType() const { |
| 220 | // If this is directly a pointer-like type, return it. |
| 221 | if (const PointerLikeType *PTy = dyn_cast<PointerLikeType>(this)) |
| 222 | return PTy; |
| 223 | |
| 224 | // If the canonical form of this type isn't the right kind, reject it. |
| 225 | if (!isa<PointerLikeType>(CanonicalType)) { |
| 226 | // Look through type qualifiers |
| 227 | if (isa<PointerLikeType>(CanonicalType.getUnqualifiedType())) |
| 228 | return CanonicalType.getUnqualifiedType()->getAsPointerLikeType(); |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | // If this is a typedef for a pointer type, strip the typedef off without |
| 233 | // losing all typedef information. |
| 234 | return getDesugaredType()->getAsPointerLikeType(); |
| 235 | } |
| 236 | |
Chris Lattner | befee48 | 2007-07-31 16:53:04 +0000 | [diff] [blame] | 237 | const PointerType *Type::getAsPointerType() const { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 238 | // If this is directly a pointer type, return it. |
| 239 | if (const PointerType *PTy = dyn_cast<PointerType>(this)) |
| 240 | return PTy; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 241 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 242 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 243 | if (!isa<PointerType>(CanonicalType)) { |
| 244 | // Look through type qualifiers |
| 245 | if (isa<PointerType>(CanonicalType.getUnqualifiedType())) |
| 246 | return CanonicalType.getUnqualifiedType()->getAsPointerType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 247 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 248 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 249 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 250 | // If this is a typedef for a pointer type, strip the typedef off without |
| 251 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 252 | return getDesugaredType()->getAsPointerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 255 | const BlockPointerType *Type::getAsBlockPointerType() const { |
| 256 | // If this is directly a block pointer type, return it. |
| 257 | if (const BlockPointerType *PTy = dyn_cast<BlockPointerType>(this)) |
| 258 | return PTy; |
| 259 | |
| 260 | // If the canonical form of this type isn't the right kind, reject it. |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 261 | if (!isa<BlockPointerType>(CanonicalType)) { |
| 262 | // Look through type qualifiers |
| 263 | if (isa<BlockPointerType>(CanonicalType.getUnqualifiedType())) |
| 264 | return CanonicalType.getUnqualifiedType()->getAsBlockPointerType(); |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 265 | return 0; |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 266 | } |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 267 | |
| 268 | // If this is a typedef for a block pointer type, strip the typedef off |
| 269 | // without losing all typedef information. |
| 270 | return getDesugaredType()->getAsBlockPointerType(); |
| 271 | } |
| 272 | |
Chris Lattner | a1d9fde | 2007-07-31 16:56:34 +0000 | [diff] [blame] | 273 | const ReferenceType *Type::getAsReferenceType() const { |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +0000 | [diff] [blame] | 274 | // If this is directly a reference type, return it. |
| 275 | if (const ReferenceType *RTy = dyn_cast<ReferenceType>(this)) |
| 276 | return RTy; |
| 277 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 278 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 279 | if (!isa<ReferenceType>(CanonicalType)) { |
| 280 | // Look through type qualifiers |
| 281 | if (isa<ReferenceType>(CanonicalType.getUnqualifiedType())) |
| 282 | return CanonicalType.getUnqualifiedType()->getAsReferenceType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 283 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 284 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 285 | |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +0000 | [diff] [blame] | 286 | // If this is a typedef for a reference type, strip the typedef off without |
| 287 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 288 | return getDesugaredType()->getAsReferenceType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 291 | /// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length |
| 292 | /// array types and types that contain variable array types in their |
| 293 | /// declarator |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 294 | bool Type::isVariablyModifiedType() const { |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 295 | // A VLA is a variably modified type. |
| 296 | if (isVariableArrayType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 297 | return true; |
| 298 | |
| 299 | // An array can contain a variably modified type |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 300 | if (const Type *T = getArrayElementTypeNoTypeQual()) |
| 301 | return T->isVariablyModifiedType(); |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 302 | |
| 303 | // A pointer can point to a variably modified type |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 304 | if (const PointerType *PT = getAsPointerType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 305 | return PT->getPointeeType()->isVariablyModifiedType(); |
| 306 | |
| 307 | // A function can return a variably modified type |
| 308 | // This one isn't completely obvious, but it follows from the |
| 309 | // definition in C99 6.7.5p3. Because of this rule, it's |
| 310 | // illegal to declare a function returning a variably modified type. |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 311 | if (const FunctionType *FT = getAsFunctionType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 312 | return FT->getResultType()->isVariablyModifiedType(); |
| 313 | |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 314 | return false; |
| 315 | } |
| 316 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 317 | const RecordType *Type::getAsRecordType() const { |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 318 | // If this is directly a reference type, return it. |
| 319 | if (const RecordType *RTy = dyn_cast<RecordType>(this)) |
| 320 | return RTy; |
| 321 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 322 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 323 | if (!isa<RecordType>(CanonicalType)) { |
| 324 | // Look through type qualifiers |
| 325 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 326 | return CanonicalType.getUnqualifiedType()->getAsRecordType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 327 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 328 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 329 | |
| 330 | // If this is a typedef for a record type, strip the typedef off without |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 331 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 332 | return getDesugaredType()->getAsRecordType(); |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 335 | const RecordType *Type::getAsStructureType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 336 | // If this is directly a structure type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 337 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 338 | if (RT->getDecl()->isStruct()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 339 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 340 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 341 | |
| 342 | // If the canonical form of this type isn't the right kind, reject it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 343 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 344 | if (!RT->getDecl()->isStruct()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 345 | return 0; |
| 346 | |
| 347 | // If this is a typedef for a structure type, strip the typedef off without |
| 348 | // losing all typedef information. |
| 349 | return getDesugaredType()->getAsStructureType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 350 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 351 | // Look through type qualifiers |
| 352 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 353 | return CanonicalType.getUnqualifiedType()->getAsStructureType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 354 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 357 | const RecordType *Type::getAsUnionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 358 | // If this is directly a union type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 359 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 360 | if (RT->getDecl()->isUnion()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 361 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 362 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 363 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 364 | // If the canonical form of this type isn't the right kind, reject it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 365 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 366 | if (!RT->getDecl()->isUnion()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 367 | return 0; |
| 368 | |
| 369 | // If this is a typedef for a union type, strip the typedef off without |
| 370 | // losing all typedef information. |
| 371 | return getDesugaredType()->getAsUnionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 372 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 373 | |
| 374 | // Look through type qualifiers |
| 375 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 376 | return CanonicalType.getUnqualifiedType()->getAsUnionType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 377 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Eli Friedman | ad74a75 | 2008-06-28 06:23:08 +0000 | [diff] [blame] | 380 | const EnumType *Type::getAsEnumType() const { |
| 381 | // Check the canonicalized unqualified type directly; the more complex |
| 382 | // version is unnecessary because there isn't any typedef information |
| 383 | // to preserve. |
| 384 | return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType()); |
| 385 | } |
| 386 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 387 | const ComplexType *Type::getAsComplexType() const { |
| 388 | // Are we directly a complex type? |
| 389 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) |
| 390 | return CTy; |
| 391 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 392 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 393 | if (!isa<ComplexType>(CanonicalType)) { |
| 394 | // Look through type qualifiers |
| 395 | if (isa<ComplexType>(CanonicalType.getUnqualifiedType())) |
| 396 | return CanonicalType.getUnqualifiedType()->getAsComplexType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 397 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 398 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 399 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 400 | // If this is a typedef for a complex type, strip the typedef off without |
| 401 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 402 | return getDesugaredType()->getAsComplexType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 405 | const VectorType *Type::getAsVectorType() const { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 406 | // Are we directly a vector type? |
| 407 | if (const VectorType *VTy = dyn_cast<VectorType>(this)) |
| 408 | return VTy; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 409 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 410 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 411 | if (!isa<VectorType>(CanonicalType)) { |
| 412 | // Look through type qualifiers |
| 413 | if (isa<VectorType>(CanonicalType.getUnqualifiedType())) |
| 414 | return CanonicalType.getUnqualifiedType()->getAsVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 415 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 416 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 417 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 418 | // If this is a typedef for a vector type, strip the typedef off without |
| 419 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 420 | return getDesugaredType()->getAsVectorType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 423 | const ExtVectorType *Type::getAsExtVectorType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 424 | // Are we directly an OpenCU vector type? |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 425 | if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this)) |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 426 | return VTy; |
| 427 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 428 | // If the canonical form of this type isn't the right kind, reject it. |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 429 | if (!isa<ExtVectorType>(CanonicalType)) { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 430 | // Look through type qualifiers |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 431 | if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType())) |
| 432 | return CanonicalType.getUnqualifiedType()->getAsExtVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 433 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 434 | } |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 435 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 436 | // If this is a typedef for an extended vector type, strip the typedef off |
| 437 | // without losing all typedef information. |
| 438 | return getDesugaredType()->getAsExtVectorType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 441 | const ObjCInterfaceType *Type::getAsObjCInterfaceType() const { |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 442 | // There is no sugar for ObjCInterfaceType's, just return the canonical |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 443 | // type pointer if it is the right class. There is no typedef information to |
| 444 | // return and these cannot be Address-space qualified. |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 445 | return dyn_cast<ObjCInterfaceType>(CanonicalType); |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | const ObjCQualifiedInterfaceType * |
| 449 | Type::getAsObjCQualifiedInterfaceType() const { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 450 | // There is no sugar for ObjCQualifiedInterfaceType's, just return the |
| 451 | // canonical type pointer if it is the right class. |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 452 | return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType); |
| 453 | } |
| 454 | |
| 455 | const ObjCQualifiedIdType *Type::getAsObjCQualifiedIdType() const { |
| 456 | // There is no sugar for ObjCQualifiedIdType's, just return the canonical |
| 457 | // type pointer if it is the right class. |
| 458 | return dyn_cast<ObjCQualifiedIdType>(CanonicalType); |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 461 | const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const { |
| 462 | // There is no sugar for template type parameters, so just return |
| 463 | // the canonical type pointer if it is the right class. |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 464 | // FIXME: can these be address-space qualified? |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 465 | return dyn_cast<TemplateTypeParmType>(CanonicalType); |
| 466 | } |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 467 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 468 | bool Type::isIntegerType() const { |
| 469 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 470 | return BT->getKind() >= BuiltinType::Bool && |
| 471 | BT->getKind() <= BuiltinType::LongLong; |
| 472 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 473 | // Incomplete enum types are not treated as integer types. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 474 | // FIXME: In C++, enum types are never integer types. |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 475 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 476 | return true; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 477 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 478 | return VT->getElementType()->isIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 479 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 480 | return ASQT->getBaseType()->isIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 481 | return false; |
| 482 | } |
| 483 | |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 484 | bool Type::isIntegralType() const { |
| 485 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 486 | return BT->getKind() >= BuiltinType::Bool && |
| 487 | BT->getKind() <= BuiltinType::LongLong; |
| 488 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 489 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
| 490 | return true; // Complete enum types are integral. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 491 | // FIXME: In C++, enum types are never integral. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 492 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 493 | return ASQT->getBaseType()->isIntegralType(); |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 494 | return false; |
| 495 | } |
| 496 | |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 497 | bool Type::isEnumeralType() const { |
| 498 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 499 | return TT->getDecl()->isEnum(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 500 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 501 | return ASQT->getBaseType()->isEnumeralType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 502 | return false; |
| 503 | } |
| 504 | |
| 505 | bool Type::isBooleanType() const { |
| 506 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 507 | return BT->getKind() == BuiltinType::Bool; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 508 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 509 | return ASQT->getBaseType()->isBooleanType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 510 | return false; |
| 511 | } |
| 512 | |
| 513 | bool Type::isCharType() const { |
| 514 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 515 | return BT->getKind() == BuiltinType::Char_U || |
| 516 | BT->getKind() == BuiltinType::UChar || |
Anders Carlsson | c67ad5f | 2007-10-29 02:52:18 +0000 | [diff] [blame] | 517 | BT->getKind() == BuiltinType::Char_S || |
| 518 | BT->getKind() == BuiltinType::SChar; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 519 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 520 | return ASQT->getBaseType()->isCharType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 521 | return false; |
| 522 | } |
| 523 | |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 524 | bool Type::isWideCharType() const { |
| 525 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 526 | return BT->getKind() == BuiltinType::WChar; |
| 527 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 528 | return ASQT->getBaseType()->isWideCharType(); |
| 529 | return false; |
| 530 | } |
| 531 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 532 | /// isSignedIntegerType - Return true if this is an integer type that is |
| 533 | /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], |
| 534 | /// an enum decl which has a signed representation, or a vector of signed |
| 535 | /// integer element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 536 | bool Type::isSignedIntegerType() const { |
| 537 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 538 | return BT->getKind() >= BuiltinType::Char_S && |
| 539 | BT->getKind() <= BuiltinType::LongLong; |
| 540 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 541 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 542 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 543 | return ET->getDecl()->getIntegerType()->isSignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 544 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 545 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 546 | return VT->getElementType()->isSignedIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 547 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 548 | return ASQT->getBaseType()->isSignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 549 | return false; |
| 550 | } |
| 551 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 552 | /// isUnsignedIntegerType - Return true if this is an integer type that is |
| 553 | /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum |
| 554 | /// decl which has an unsigned representation, or a vector of unsigned integer |
| 555 | /// element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 556 | bool Type::isUnsignedIntegerType() const { |
| 557 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 558 | return BT->getKind() >= BuiltinType::Bool && |
| 559 | BT->getKind() <= BuiltinType::ULongLong; |
| 560 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 561 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 562 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 563 | return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 564 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 565 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 566 | return VT->getElementType()->isUnsignedIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 567 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 568 | return ASQT->getBaseType()->isUnsignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 569 | return false; |
| 570 | } |
| 571 | |
| 572 | bool Type::isFloatingType() const { |
| 573 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 574 | return BT->getKind() >= BuiltinType::Float && |
| 575 | BT->getKind() <= BuiltinType::LongDouble; |
| 576 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
Chris Lattner | 729a213 | 2007-08-30 06:19:11 +0000 | [diff] [blame] | 577 | return CT->getElementType()->isFloatingType(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 578 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 579 | return VT->getElementType()->isFloatingType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 580 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 581 | return ASQT->getBaseType()->isFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 582 | return false; |
| 583 | } |
| 584 | |
| 585 | bool Type::isRealFloatingType() const { |
| 586 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 587 | return BT->getKind() >= BuiltinType::Float && |
| 588 | BT->getKind() <= BuiltinType::LongDouble; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 589 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 590 | return VT->getElementType()->isRealFloatingType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 591 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 592 | return ASQT->getBaseType()->isRealFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 593 | return false; |
| 594 | } |
| 595 | |
| 596 | bool Type::isRealType() const { |
| 597 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 598 | return BT->getKind() >= BuiltinType::Bool && |
| 599 | BT->getKind() <= BuiltinType::LongDouble; |
| 600 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 601 | return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 602 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 603 | return VT->getElementType()->isRealType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 604 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 605 | return ASQT->getBaseType()->isRealType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 606 | return false; |
| 607 | } |
| 608 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 609 | bool Type::isArithmeticType() const { |
| 610 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
Douglas Gregor | a7fbf72 | 2008-10-30 13:47:07 +0000 | [diff] [blame] | 611 | return BT->getKind() >= BuiltinType::Bool && |
| 612 | BT->getKind() <= BuiltinType::LongDouble; |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 613 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 614 | // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). |
| 615 | // If a body isn't seen by the time we get here, return false. |
| 616 | return ET->getDecl()->isDefinition(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 617 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 618 | return ASQT->getBaseType()->isArithmeticType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 619 | return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType); |
| 620 | } |
| 621 | |
| 622 | bool Type::isScalarType() const { |
| 623 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 624 | return BT->getKind() != BuiltinType::Void; |
| 625 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 626 | // Enums are scalar types, but only if they are defined. Incomplete enums |
| 627 | // are not treated as scalar types. |
| 628 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 629 | return true; |
| 630 | return false; |
| 631 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 632 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 633 | return ASQT->getBaseType()->isScalarType(); |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 634 | return isa<PointerType>(CanonicalType) || |
| 635 | isa<BlockPointerType>(CanonicalType) || |
| 636 | isa<ComplexType>(CanonicalType) || |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 637 | isa<ObjCQualifiedIdType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | bool Type::isAggregateType() const { |
| 641 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 642 | if (TT->getDecl()->isStruct()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 643 | return true; |
| 644 | return false; |
| 645 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 646 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 647 | return ASQT->getBaseType()->isAggregateType(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 648 | return isa<ArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 651 | /// isConstantSizeType - Return true if this is not a variable sized type, |
| 652 | /// according to the rules of C99 6.7.5p3. It is not legal to call this on |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 653 | /// incomplete types or dependent types. |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 654 | bool Type::isConstantSizeType() const { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 655 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 656 | return ASQT->getBaseType()->isConstantSizeType(); |
Chris Lattner | d52a457 | 2007-12-18 07:03:30 +0000 | [diff] [blame] | 657 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 658 | assert(!isDependentType() && "This doesn't make sense for dependent types"); |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 659 | // The VAT must have a size, as it is known to be complete. |
| 660 | return !isa<VariableArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) |
| 664 | /// - a type that can describe objects, but which lacks information needed to |
| 665 | /// determine its size. |
| 666 | bool Type::isIncompleteType() const { |
| 667 | switch (CanonicalType->getTypeClass()) { |
| 668 | default: return false; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 669 | case ASQual: |
| 670 | return cast<ASQualType>(CanonicalType)->getBaseType()->isIncompleteType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 671 | case Builtin: |
| 672 | // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never |
| 673 | // be completed. |
| 674 | return isVoidType(); |
| 675 | case Tagged: |
| 676 | // A tagged type (struct/union/enum/class) is incomplete if the decl is a |
| 677 | // forward declaration, but not a full definition (C99 6.2.5p22). |
| 678 | return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 679 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 680 | // An array of unknown size is an incomplete type (C99 6.2.5p22). |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 681 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 685 | /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) |
| 686 | bool Type::isPODType() const { |
| 687 | // The compiler shouldn't query this for incomplete types, but the user might. |
| 688 | // We return false for that case. |
| 689 | if (isIncompleteType()) |
| 690 | return false; |
| 691 | |
| 692 | switch (CanonicalType->getTypeClass()) { |
| 693 | // Everything not explicitly mentioned is not POD. |
| 694 | default: return false; |
| 695 | case ASQual: |
| 696 | return cast<ASQualType>(CanonicalType)->getBaseType()->isPODType(); |
| 697 | case VariableArray: |
| 698 | case ConstantArray: |
| 699 | // IncompleteArray is caught by isIncompleteType() above. |
| 700 | return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); |
| 701 | |
| 702 | case Builtin: |
| 703 | case Complex: |
| 704 | case Pointer: |
| 705 | case Vector: |
| 706 | case ExtVector: |
| 707 | // FIXME: pointer-to-member |
| 708 | return true; |
| 709 | |
| 710 | case Tagged: |
| 711 | if (isEnumeralType()) |
| 712 | return true; |
| 713 | if (CXXRecordDecl *RDecl = dyn_cast<CXXRecordDecl>( |
| 714 | cast<TagType>(CanonicalType)->getDecl())) |
| 715 | return RDecl->isPOD(); |
| 716 | // C struct/union is POD. |
| 717 | return true; |
| 718 | } |
| 719 | } |
| 720 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 721 | bool Type::isPromotableIntegerType() const { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 722 | if (const BuiltinType *BT = getAsBuiltinType()) |
| 723 | switch (BT->getKind()) { |
| 724 | case BuiltinType::Bool: |
| 725 | case BuiltinType::Char_S: |
| 726 | case BuiltinType::Char_U: |
| 727 | case BuiltinType::SChar: |
| 728 | case BuiltinType::UChar: |
| 729 | case BuiltinType::Short: |
| 730 | case BuiltinType::UShort: |
| 731 | return true; |
| 732 | default: |
| 733 | return false; |
| 734 | } |
| 735 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | const char *BuiltinType::getName() const { |
| 739 | switch (getKind()) { |
| 740 | default: assert(0 && "Unknown builtin type!"); |
| 741 | case Void: return "void"; |
| 742 | case Bool: return "_Bool"; |
| 743 | case Char_S: return "char"; |
| 744 | case Char_U: return "char"; |
| 745 | case SChar: return "signed char"; |
| 746 | case Short: return "short"; |
| 747 | case Int: return "int"; |
| 748 | case Long: return "long"; |
| 749 | case LongLong: return "long long"; |
| 750 | case UChar: return "unsigned char"; |
| 751 | case UShort: return "unsigned short"; |
| 752 | case UInt: return "unsigned int"; |
| 753 | case ULong: return "unsigned long"; |
| 754 | case ULongLong: return "unsigned long long"; |
| 755 | case Float: return "float"; |
| 756 | case Double: return "double"; |
| 757 | case LongDouble: return "long double"; |
Argyrios Kyrtzidis | 46713ef | 2008-08-09 17:11:33 +0000 | [diff] [blame] | 758 | case WChar: return "wchar_t"; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 759 | case Overload: return "<overloaded function type>"; |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 760 | case Dependent: return "<dependent type>"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 764 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
Chris Lattner | 942cfd3 | 2007-07-20 18:48:28 +0000 | [diff] [blame] | 765 | arg_type_iterator ArgTys, |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 766 | unsigned NumArgs, bool isVariadic, |
| 767 | unsigned TypeQuals) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 768 | ID.AddPointer(Result.getAsOpaquePtr()); |
| 769 | for (unsigned i = 0; i != NumArgs; ++i) |
| 770 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
| 771 | ID.AddInteger(isVariadic); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 772 | ID.AddInteger(TypeQuals); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) { |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 776 | Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), |
| 777 | getTypeQuals()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 780 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 781 | const ObjCInterfaceDecl *Decl, |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 782 | ObjCProtocolDecl **protocols, |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 783 | unsigned NumProtocols) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 784 | ID.AddPointer(Decl); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 785 | for (unsigned i = 0; i != NumProtocols; i++) |
| 786 | ID.AddPointer(protocols[i]); |
| 787 | } |
| 788 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 789 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 790 | Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 793 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 62f5f7f | 2008-07-26 00:46:50 +0000 | [diff] [blame] | 794 | ObjCProtocolDecl **protocols, |
| 795 | unsigned NumProtocols) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 796 | for (unsigned i = 0; i != NumProtocols; i++) |
| 797 | ID.AddPointer(protocols[i]); |
| 798 | } |
| 799 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 800 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 801 | Profile(ID, &Protocols[0], getNumProtocols()); |
| 802 | } |
| 803 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 804 | /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to |
| 805 | /// potentially looking through *all* consequtive typedefs. This returns the |
| 806 | /// sum of the type qualifiers, so if you have: |
| 807 | /// typedef const int A; |
| 808 | /// typedef volatile A B; |
| 809 | /// looking through the typedefs for B will give you "const volatile A". |
| 810 | /// |
| 811 | QualType TypedefType::LookThroughTypedefs() const { |
| 812 | // Usually, there is only a single level of typedefs, be fast in that case. |
| 813 | QualType FirstType = getDecl()->getUnderlyingType(); |
| 814 | if (!isa<TypedefType>(FirstType)) |
| 815 | return FirstType; |
| 816 | |
| 817 | // Otherwise, do the fully general loop. |
| 818 | unsigned TypeQuals = 0; |
| 819 | const TypedefType *TDT = this; |
| 820 | while (1) { |
| 821 | QualType CurType = TDT->getDecl()->getUnderlyingType(); |
Chris Lattner | f46699c | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 822 | |
| 823 | |
| 824 | /// FIXME: |
| 825 | /// FIXME: This is incorrect for ASQuals! |
| 826 | /// FIXME: |
| 827 | TypeQuals |= CurType.getCVRQualifiers(); |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 828 | |
| 829 | TDT = dyn_cast<TypedefType>(CurType); |
| 830 | if (TDT == 0) |
| 831 | return QualType(CurType.getTypePtr(), TypeQuals); |
| 832 | } |
| 833 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 834 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 835 | TypeOfExpr::TypeOfExpr(Expr *E, QualType can) |
| 836 | : Type(TypeOfExp, can, E->isTypeDependent()), TOExpr(E) { |
| 837 | assert(!isa<TypedefType>(can) && "Invalid canonical type"); |
| 838 | } |
| 839 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 840 | bool RecordType::classof(const TagType *TT) { |
| 841 | return isa<RecordDecl>(TT->getDecl()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Argyrios Kyrtzidis | 49aa7ff | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 844 | bool CXXRecordType::classof(const TagType *TT) { |
| 845 | return isa<CXXRecordDecl>(TT->getDecl()); |
| 846 | } |
| 847 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 848 | bool EnumType::classof(const TagType *TT) { |
| 849 | return isa<EnumDecl>(TT->getDecl()); |
Chris Lattner | 5edb8bf | 2008-04-06 21:58:47 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Anders Carlsson | 97e0179 | 2008-12-21 00:16:32 +0000 | [diff] [blame] | 852 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 853 | //===----------------------------------------------------------------------===// |
| 854 | // Type Printing |
| 855 | //===----------------------------------------------------------------------===// |
| 856 | |
| 857 | void QualType::dump(const char *msg) const { |
Chris Lattner | 39caea9 | 2007-12-06 04:20:07 +0000 | [diff] [blame] | 858 | std::string R = "identifier"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 859 | getAsStringInternal(R); |
| 860 | if (msg) |
| 861 | fprintf(stderr, "%s: %s\n", msg, R.c_str()); |
| 862 | else |
| 863 | fprintf(stderr, "%s\n", R.c_str()); |
| 864 | } |
Chris Lattner | c36d405 | 2008-07-27 00:48:22 +0000 | [diff] [blame] | 865 | void QualType::dump() const { |
| 866 | dump(""); |
| 867 | } |
| 868 | |
| 869 | void Type::dump() const { |
| 870 | std::string S = "identifier"; |
| 871 | getAsStringInternal(S); |
| 872 | fprintf(stderr, "%s\n", S.c_str()); |
| 873 | } |
| 874 | |
| 875 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 876 | |
| 877 | static void AppendTypeQualList(std::string &S, unsigned TypeQuals) { |
| 878 | // Note: funkiness to ensure we get a space only between quals. |
| 879 | bool NonePrinted = true; |
| 880 | if (TypeQuals & QualType::Const) |
| 881 | S += "const", NonePrinted = false; |
| 882 | if (TypeQuals & QualType::Volatile) |
| 883 | S += (NonePrinted+" volatile"), NonePrinted = false; |
| 884 | if (TypeQuals & QualType::Restrict) |
| 885 | S += (NonePrinted+" restrict"), NonePrinted = false; |
| 886 | } |
| 887 | |
| 888 | void QualType::getAsStringInternal(std::string &S) const { |
| 889 | if (isNull()) { |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 890 | S += "NULL TYPE"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 891 | return; |
| 892 | } |
| 893 | |
| 894 | // Print qualifiers as appropriate. |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 895 | if (unsigned Tq = getCVRQualifiers()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 896 | std::string TQS; |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 897 | AppendTypeQualList(TQS, Tq); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 898 | if (!S.empty()) |
| 899 | S = TQS + ' ' + S; |
| 900 | else |
| 901 | S = TQS; |
| 902 | } |
| 903 | |
| 904 | getTypePtr()->getAsStringInternal(S); |
| 905 | } |
| 906 | |
| 907 | void BuiltinType::getAsStringInternal(std::string &S) const { |
| 908 | if (S.empty()) { |
| 909 | S = getName(); |
| 910 | } else { |
| 911 | // Prefix the basic type, e.g. 'int X'. |
| 912 | S = ' ' + S; |
| 913 | S = getName() + S; |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | void ComplexType::getAsStringInternal(std::string &S) const { |
| 918 | ElementType->getAsStringInternal(S); |
| 919 | S = "_Complex " + S; |
| 920 | } |
| 921 | |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 922 | void ASQualType::getAsStringInternal(std::string &S) const { |
| 923 | S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S; |
| 924 | BaseType->getAsStringInternal(S); |
| 925 | } |
| 926 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 927 | void PointerType::getAsStringInternal(std::string &S) const { |
| 928 | S = '*' + S; |
| 929 | |
| 930 | // Handle things like 'int (*A)[4];' correctly. |
| 931 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 932 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 933 | S = '(' + S + ')'; |
| 934 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 935 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 938 | void BlockPointerType::getAsStringInternal(std::string &S) const { |
| 939 | S = '^' + S; |
| 940 | PointeeType.getAsStringInternal(S); |
| 941 | } |
| 942 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 943 | void ReferenceType::getAsStringInternal(std::string &S) const { |
| 944 | S = '&' + S; |
| 945 | |
| 946 | // Handle things like 'int (&A)[4];' correctly. |
| 947 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 948 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 949 | S = '(' + S + ')'; |
| 950 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 951 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 954 | void ConstantArrayType::getAsStringInternal(std::string &S) const { |
| 955 | S += '['; |
Steve Naroff | 6b91cd9 | 2007-08-30 18:45:57 +0000 | [diff] [blame] | 956 | S += llvm::utostr(getSize().getZExtValue()); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 957 | S += ']'; |
| 958 | |
| 959 | getElementType().getAsStringInternal(S); |
| 960 | } |
| 961 | |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 962 | void IncompleteArrayType::getAsStringInternal(std::string &S) const { |
| 963 | S += "[]"; |
| 964 | |
| 965 | getElementType().getAsStringInternal(S); |
| 966 | } |
| 967 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 968 | void VariableArrayType::getAsStringInternal(std::string &S) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 969 | S += '['; |
| 970 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 971 | if (getIndexTypeQualifier()) { |
| 972 | AppendTypeQualList(S, getIndexTypeQualifier()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 973 | S += ' '; |
| 974 | } |
| 975 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 976 | if (getSizeModifier() == Static) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 977 | S += "static"; |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 978 | else if (getSizeModifier() == Star) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 979 | S += '*'; |
| 980 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 981 | if (getSizeExpr()) { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 982 | std::string SStr; |
| 983 | llvm::raw_string_ostream s(SStr); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 984 | getSizeExpr()->printPretty(s); |
| 985 | S += s.str(); |
| 986 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 987 | S += ']'; |
| 988 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 989 | getElementType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 992 | void DependentSizedArrayType::getAsStringInternal(std::string &S) const { |
| 993 | S += '['; |
| 994 | |
| 995 | if (getIndexTypeQualifier()) { |
| 996 | AppendTypeQualList(S, getIndexTypeQualifier()); |
| 997 | S += ' '; |
| 998 | } |
| 999 | |
| 1000 | if (getSizeModifier() == Static) |
| 1001 | S += "static"; |
| 1002 | else if (getSizeModifier() == Star) |
| 1003 | S += '*'; |
| 1004 | |
| 1005 | if (getSizeExpr()) { |
| 1006 | std::string SStr; |
| 1007 | llvm::raw_string_ostream s(SStr); |
| 1008 | getSizeExpr()->printPretty(s); |
| 1009 | S += s.str(); |
| 1010 | } |
| 1011 | S += ']'; |
| 1012 | |
| 1013 | getElementType().getAsStringInternal(S); |
| 1014 | } |
| 1015 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1016 | void VectorType::getAsStringInternal(std::string &S) const { |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1017 | // FIXME: We prefer to print the size directly here, but have no way |
| 1018 | // to get the size of the type. |
Chris Lattner | 7ee261c | 2007-11-27 07:28:18 +0000 | [diff] [blame] | 1019 | S += " __attribute__((__vector_size__("; |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1020 | S += llvm::utostr_32(NumElements); // convert back to bytes. |
| 1021 | S += " * sizeof(" + ElementType.getAsString() + "))))"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1024 | void ExtVectorType::getAsStringInternal(std::string &S) const { |
| 1025 | S += " __attribute__((ext_vector_type("; |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1026 | S += llvm::utostr_32(NumElements); |
| 1027 | S += ")))"; |
| 1028 | ElementType.getAsStringInternal(S); |
| 1029 | } |
| 1030 | |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1031 | void TypeOfExpr::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1032 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'. |
| 1033 | InnerString = ' ' + InnerString; |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1034 | std::string Str; |
| 1035 | llvm::raw_string_ostream s(Str); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1036 | getUnderlyingExpr()->printPretty(s); |
Steve Naroff | 1bfd5cc | 2007-08-05 03:24:45 +0000 | [diff] [blame] | 1037 | InnerString = "typeof(" + s.str() + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1040 | void TypeOfType::getAsStringInternal(std::string &InnerString) const { |
| 1041 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'. |
| 1042 | InnerString = ' ' + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1043 | std::string Tmp; |
| 1044 | getUnderlyingType().getAsStringInternal(Tmp); |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1045 | InnerString = "typeof(" + Tmp + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1048 | void FunctionTypeNoProto::getAsStringInternal(std::string &S) const { |
| 1049 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1050 | if (!S.empty()) |
| 1051 | S = "(" + S + ")"; |
| 1052 | |
| 1053 | S += "()"; |
| 1054 | getResultType().getAsStringInternal(S); |
| 1055 | } |
| 1056 | |
| 1057 | void FunctionTypeProto::getAsStringInternal(std::string &S) const { |
| 1058 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1059 | if (!S.empty()) |
| 1060 | S = "(" + S + ")"; |
| 1061 | |
| 1062 | S += "("; |
| 1063 | std::string Tmp; |
| 1064 | for (unsigned i = 0, e = getNumArgs(); i != e; ++i) { |
| 1065 | if (i) S += ", "; |
| 1066 | getArgType(i).getAsStringInternal(Tmp); |
| 1067 | S += Tmp; |
| 1068 | Tmp.clear(); |
| 1069 | } |
| 1070 | |
| 1071 | if (isVariadic()) { |
| 1072 | if (getNumArgs()) |
| 1073 | S += ", "; |
| 1074 | S += "..."; |
| 1075 | } else if (getNumArgs() == 0) { |
| 1076 | // Do not emit int() if we have a proto, emit 'int(void)'. |
| 1077 | S += "void"; |
| 1078 | } |
| 1079 | |
| 1080 | S += ")"; |
| 1081 | getResultType().getAsStringInternal(S); |
| 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | void TypedefType::getAsStringInternal(std::string &InnerString) const { |
| 1086 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1087 | InnerString = ' ' + InnerString; |
| 1088 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1089 | } |
| 1090 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1091 | void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const { |
| 1092 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'. |
| 1093 | InnerString = ' ' + InnerString; |
| 1094 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1095 | } |
| 1096 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1097 | void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1098 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1099 | InnerString = ' ' + InnerString; |
| 1100 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1101 | } |
| 1102 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1103 | void ObjCQualifiedInterfaceType::getAsStringInternal( |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1104 | std::string &InnerString) const { |
Fariborz Jahanian | dfbcce2 | 2007-10-11 18:08:47 +0000 | [diff] [blame] | 1105 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1106 | InnerString = ' ' + InnerString; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1107 | std::string ObjCQIString = getDecl()->getNameAsString(); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1108 | ObjCQIString += '<'; |
Chris Lattner | cdce6d1 | 2008-07-21 05:19:23 +0000 | [diff] [blame] | 1109 | bool isFirst = true; |
| 1110 | for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { |
| 1111 | if (isFirst) |
| 1112 | isFirst = false; |
| 1113 | else |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1114 | ObjCQIString += ','; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1115 | ObjCQIString += (*I)->getNameAsString(); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1116 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1117 | ObjCQIString += '>'; |
| 1118 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
Chris Lattner | e8e4f92 | 2008-07-25 23:07:18 +0000 | [diff] [blame] | 1121 | void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1122 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1123 | InnerString = ' ' + InnerString; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1124 | std::string ObjCQIString = "id"; |
| 1125 | ObjCQIString += '<'; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1126 | int num = getNumProtocols(); |
| 1127 | for (int i = 0; i < num; i++) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1128 | ObjCQIString += getProtocols(i)->getNameAsString(); |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1129 | if (i < num-1) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1130 | ObjCQIString += ','; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1131 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1132 | ObjCQIString += '>'; |
| 1133 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1136 | void TagType::getAsStringInternal(std::string &InnerString) const { |
| 1137 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1138 | InnerString = ' ' + InnerString; |
| 1139 | |
| 1140 | const char *Kind = getDecl()->getKindName(); |
| 1141 | const char *ID; |
| 1142 | if (const IdentifierInfo *II = getDecl()->getIdentifier()) |
| 1143 | ID = II->getName(); |
| 1144 | else |
| 1145 | ID = "<anonymous>"; |
| 1146 | |
| 1147 | InnerString = std::string(Kind) + " " + ID + InnerString; |
| 1148 | } |