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 | |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame^] | 291 | const MemberPointerType *Type::getAsMemberPointerType() const { |
| 292 | // If this is directly a member pointer type, return it. |
| 293 | if (const MemberPointerType *MTy = dyn_cast<MemberPointerType>(this)) |
| 294 | return MTy; |
| 295 | |
| 296 | // If the canonical form of this type isn't the right kind, reject it. |
| 297 | if (!isa<MemberPointerType>(CanonicalType)) { |
| 298 | // Look through type qualifiers |
| 299 | if (isa<MemberPointerType>(CanonicalType.getUnqualifiedType())) |
| 300 | return CanonicalType.getUnqualifiedType()->getAsMemberPointerType(); |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | // If this is a typedef for a member pointer type, strip the typedef off |
| 305 | // without losing all typedef information. |
| 306 | return getDesugaredType()->getAsMemberPointerType(); |
| 307 | } |
| 308 | |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 309 | /// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length |
| 310 | /// array types and types that contain variable array types in their |
| 311 | /// declarator |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 312 | bool Type::isVariablyModifiedType() const { |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 313 | // A VLA is a variably modified type. |
| 314 | if (isVariableArrayType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 315 | return true; |
| 316 | |
| 317 | // An array can contain a variably modified type |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 318 | if (const Type *T = getArrayElementTypeNoTypeQual()) |
| 319 | return T->isVariablyModifiedType(); |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 320 | |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame^] | 321 | // A pointer can point to a variably modified type. |
| 322 | // Also, C++ references and member pointers can point to a variably modified |
| 323 | // type, where VLAs appear as an extension to C++, and should be treated |
| 324 | // correctly. |
| 325 | if (const PointerLikeType *PT = getAsPointerLikeType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 326 | return PT->getPointeeType()->isVariablyModifiedType(); |
| 327 | |
| 328 | // A function can return a variably modified type |
| 329 | // This one isn't completely obvious, but it follows from the |
| 330 | // definition in C99 6.7.5p3. Because of this rule, it's |
| 331 | // illegal to declare a function returning a variably modified type. |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 332 | if (const FunctionType *FT = getAsFunctionType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 333 | return FT->getResultType()->isVariablyModifiedType(); |
| 334 | |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 335 | return false; |
| 336 | } |
| 337 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 338 | const RecordType *Type::getAsRecordType() const { |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 339 | // If this is directly a reference type, return it. |
| 340 | if (const RecordType *RTy = dyn_cast<RecordType>(this)) |
| 341 | return RTy; |
| 342 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 343 | // 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] | 344 | if (!isa<RecordType>(CanonicalType)) { |
| 345 | // Look through type qualifiers |
| 346 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 347 | return CanonicalType.getUnqualifiedType()->getAsRecordType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 348 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 349 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 350 | |
| 351 | // 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] | 352 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 353 | return getDesugaredType()->getAsRecordType(); |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 356 | const RecordType *Type::getAsStructureType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 357 | // If this is directly a structure type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 358 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 359 | if (RT->getDecl()->isStruct()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 360 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 361 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 362 | |
| 363 | // 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] | 364 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 365 | if (!RT->getDecl()->isStruct()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 366 | return 0; |
| 367 | |
| 368 | // If this is a typedef for a structure type, strip the typedef off without |
| 369 | // losing all typedef information. |
| 370 | return getDesugaredType()->getAsStructureType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 371 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 372 | // Look through type qualifiers |
| 373 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 374 | return CanonicalType.getUnqualifiedType()->getAsStructureType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 375 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 378 | const RecordType *Type::getAsUnionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 379 | // If this is directly a union type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 380 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 381 | if (RT->getDecl()->isUnion()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 382 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 383 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 384 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 385 | // 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] | 386 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 387 | if (!RT->getDecl()->isUnion()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 388 | return 0; |
| 389 | |
| 390 | // If this is a typedef for a union type, strip the typedef off without |
| 391 | // losing all typedef information. |
| 392 | return getDesugaredType()->getAsUnionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 393 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 394 | |
| 395 | // Look through type qualifiers |
| 396 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 397 | return CanonicalType.getUnqualifiedType()->getAsUnionType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 398 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Eli Friedman | ad74a75 | 2008-06-28 06:23:08 +0000 | [diff] [blame] | 401 | const EnumType *Type::getAsEnumType() const { |
| 402 | // Check the canonicalized unqualified type directly; the more complex |
| 403 | // version is unnecessary because there isn't any typedef information |
| 404 | // to preserve. |
| 405 | return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType()); |
| 406 | } |
| 407 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 408 | const ComplexType *Type::getAsComplexType() const { |
| 409 | // Are we directly a complex type? |
| 410 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) |
| 411 | return CTy; |
| 412 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 413 | // 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] | 414 | if (!isa<ComplexType>(CanonicalType)) { |
| 415 | // Look through type qualifiers |
| 416 | if (isa<ComplexType>(CanonicalType.getUnqualifiedType())) |
| 417 | return CanonicalType.getUnqualifiedType()->getAsComplexType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 418 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 419 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 420 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 421 | // If this is a typedef for a complex type, strip the typedef off without |
| 422 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 423 | return getDesugaredType()->getAsComplexType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 426 | const VectorType *Type::getAsVectorType() const { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 427 | // Are we directly a vector type? |
| 428 | if (const VectorType *VTy = dyn_cast<VectorType>(this)) |
| 429 | return VTy; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 430 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 431 | // 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] | 432 | if (!isa<VectorType>(CanonicalType)) { |
| 433 | // Look through type qualifiers |
| 434 | if (isa<VectorType>(CanonicalType.getUnqualifiedType())) |
| 435 | return CanonicalType.getUnqualifiedType()->getAsVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 436 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 437 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 438 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 439 | // If this is a typedef for a vector type, strip the typedef off without |
| 440 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 441 | return getDesugaredType()->getAsVectorType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 444 | const ExtVectorType *Type::getAsExtVectorType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 445 | // Are we directly an OpenCU vector type? |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 446 | if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this)) |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 447 | return VTy; |
| 448 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 449 | // 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] | 450 | if (!isa<ExtVectorType>(CanonicalType)) { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 451 | // Look through type qualifiers |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 452 | if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType())) |
| 453 | return CanonicalType.getUnqualifiedType()->getAsExtVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 454 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 455 | } |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 456 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 457 | // If this is a typedef for an extended vector type, strip the typedef off |
| 458 | // without losing all typedef information. |
| 459 | return getDesugaredType()->getAsExtVectorType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 462 | const ObjCInterfaceType *Type::getAsObjCInterfaceType() const { |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 463 | // There is no sugar for ObjCInterfaceType's, just return the canonical |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 464 | // type pointer if it is the right class. There is no typedef information to |
| 465 | // return and these cannot be Address-space qualified. |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 466 | return dyn_cast<ObjCInterfaceType>(CanonicalType); |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | const ObjCQualifiedInterfaceType * |
| 470 | Type::getAsObjCQualifiedInterfaceType() const { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 471 | // There is no sugar for ObjCQualifiedInterfaceType's, just return the |
| 472 | // canonical type pointer if it is the right class. |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 473 | return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType); |
| 474 | } |
| 475 | |
| 476 | const ObjCQualifiedIdType *Type::getAsObjCQualifiedIdType() const { |
| 477 | // There is no sugar for ObjCQualifiedIdType's, just return the canonical |
| 478 | // type pointer if it is the right class. |
| 479 | return dyn_cast<ObjCQualifiedIdType>(CanonicalType); |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 482 | const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const { |
| 483 | // There is no sugar for template type parameters, so just return |
| 484 | // the canonical type pointer if it is the right class. |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 485 | // FIXME: can these be address-space qualified? |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 486 | return dyn_cast<TemplateTypeParmType>(CanonicalType); |
| 487 | } |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 488 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 489 | bool Type::isIntegerType() const { |
| 490 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 491 | return BT->getKind() >= BuiltinType::Bool && |
| 492 | BT->getKind() <= BuiltinType::LongLong; |
| 493 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 494 | // Incomplete enum types are not treated as integer types. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 495 | // FIXME: In C++, enum types are never integer types. |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 496 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 497 | return true; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 498 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 499 | return VT->getElementType()->isIntegerType(); |
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()->isIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 502 | return false; |
| 503 | } |
| 504 | |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 505 | bool Type::isIntegralType() const { |
| 506 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 507 | return BT->getKind() >= BuiltinType::Bool && |
| 508 | BT->getKind() <= BuiltinType::LongLong; |
| 509 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 510 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
| 511 | return true; // Complete enum types are integral. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 512 | // FIXME: In C++, enum types are never integral. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 513 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 514 | return ASQT->getBaseType()->isIntegralType(); |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 515 | return false; |
| 516 | } |
| 517 | |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 518 | bool Type::isEnumeralType() const { |
| 519 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 520 | return TT->getDecl()->isEnum(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 521 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 522 | return ASQT->getBaseType()->isEnumeralType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 523 | return false; |
| 524 | } |
| 525 | |
| 526 | bool Type::isBooleanType() const { |
| 527 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 528 | return BT->getKind() == BuiltinType::Bool; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 529 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 530 | return ASQT->getBaseType()->isBooleanType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 531 | return false; |
| 532 | } |
| 533 | |
| 534 | bool Type::isCharType() const { |
| 535 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 536 | return BT->getKind() == BuiltinType::Char_U || |
| 537 | BT->getKind() == BuiltinType::UChar || |
Anders Carlsson | c67ad5f | 2007-10-29 02:52:18 +0000 | [diff] [blame] | 538 | BT->getKind() == BuiltinType::Char_S || |
| 539 | BT->getKind() == BuiltinType::SChar; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 540 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 541 | return ASQT->getBaseType()->isCharType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 542 | return false; |
| 543 | } |
| 544 | |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 545 | bool Type::isWideCharType() const { |
| 546 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 547 | return BT->getKind() == BuiltinType::WChar; |
| 548 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 549 | return ASQT->getBaseType()->isWideCharType(); |
| 550 | return false; |
| 551 | } |
| 552 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 553 | /// isSignedIntegerType - Return true if this is an integer type that is |
| 554 | /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], |
| 555 | /// an enum decl which has a signed representation, or a vector of signed |
| 556 | /// integer element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 557 | bool Type::isSignedIntegerType() const { |
| 558 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 559 | return BT->getKind() >= BuiltinType::Char_S && |
| 560 | BT->getKind() <= BuiltinType::LongLong; |
| 561 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 562 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 563 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 564 | return ET->getDecl()->getIntegerType()->isSignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 565 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 566 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 567 | return VT->getElementType()->isSignedIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 568 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 569 | return ASQT->getBaseType()->isSignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 570 | return false; |
| 571 | } |
| 572 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 573 | /// isUnsignedIntegerType - Return true if this is an integer type that is |
| 574 | /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum |
| 575 | /// decl which has an unsigned representation, or a vector of unsigned integer |
| 576 | /// element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 577 | bool Type::isUnsignedIntegerType() const { |
| 578 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 579 | return BT->getKind() >= BuiltinType::Bool && |
| 580 | BT->getKind() <= BuiltinType::ULongLong; |
| 581 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 582 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 583 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 584 | return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 585 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 586 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 587 | return VT->getElementType()->isUnsignedIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 588 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 589 | return ASQT->getBaseType()->isUnsignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 590 | return false; |
| 591 | } |
| 592 | |
| 593 | bool Type::isFloatingType() const { |
| 594 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 595 | return BT->getKind() >= BuiltinType::Float && |
| 596 | BT->getKind() <= BuiltinType::LongDouble; |
| 597 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
Chris Lattner | 729a213 | 2007-08-30 06:19:11 +0000 | [diff] [blame] | 598 | return CT->getElementType()->isFloatingType(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 599 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 600 | return VT->getElementType()->isFloatingType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 601 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 602 | return ASQT->getBaseType()->isFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 603 | return false; |
| 604 | } |
| 605 | |
| 606 | bool Type::isRealFloatingType() const { |
| 607 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 608 | return BT->getKind() >= BuiltinType::Float && |
| 609 | BT->getKind() <= BuiltinType::LongDouble; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 610 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 611 | return VT->getElementType()->isRealFloatingType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 612 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 613 | return ASQT->getBaseType()->isRealFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 614 | return false; |
| 615 | } |
| 616 | |
| 617 | bool Type::isRealType() const { |
| 618 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 619 | return BT->getKind() >= BuiltinType::Bool && |
| 620 | BT->getKind() <= BuiltinType::LongDouble; |
| 621 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 622 | return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 623 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 624 | return VT->getElementType()->isRealType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 625 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 626 | return ASQT->getBaseType()->isRealType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 627 | return false; |
| 628 | } |
| 629 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 630 | bool Type::isArithmeticType() const { |
| 631 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
Douglas Gregor | a7fbf72 | 2008-10-30 13:47:07 +0000 | [diff] [blame] | 632 | return BT->getKind() >= BuiltinType::Bool && |
| 633 | BT->getKind() <= BuiltinType::LongDouble; |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 634 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 635 | // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). |
| 636 | // If a body isn't seen by the time we get here, return false. |
| 637 | return ET->getDecl()->isDefinition(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 638 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 639 | return ASQT->getBaseType()->isArithmeticType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 640 | return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType); |
| 641 | } |
| 642 | |
| 643 | bool Type::isScalarType() const { |
| 644 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 645 | return BT->getKind() != BuiltinType::Void; |
| 646 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 647 | // Enums are scalar types, but only if they are defined. Incomplete enums |
| 648 | // are not treated as scalar types. |
| 649 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 650 | return true; |
| 651 | return false; |
| 652 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 653 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 654 | return ASQT->getBaseType()->isScalarType(); |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 655 | return isa<PointerType>(CanonicalType) || |
| 656 | isa<BlockPointerType>(CanonicalType) || |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame^] | 657 | isa<MemberPointerType>(CanonicalType) || |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 658 | isa<ComplexType>(CanonicalType) || |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 659 | isa<ObjCQualifiedIdType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | bool Type::isAggregateType() const { |
| 663 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 664 | if (TT->getDecl()->isStruct()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 665 | return true; |
| 666 | return false; |
| 667 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 668 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 669 | return ASQT->getBaseType()->isAggregateType(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 670 | return isa<ArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 673 | /// isConstantSizeType - Return true if this is not a variable sized type, |
| 674 | /// 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] | 675 | /// incomplete types or dependent types. |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 676 | bool Type::isConstantSizeType() const { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 677 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 678 | return ASQT->getBaseType()->isConstantSizeType(); |
Chris Lattner | d52a457 | 2007-12-18 07:03:30 +0000 | [diff] [blame] | 679 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 680 | assert(!isDependentType() && "This doesn't make sense for dependent types"); |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 681 | // The VAT must have a size, as it is known to be complete. |
| 682 | return !isa<VariableArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) |
| 686 | /// - a type that can describe objects, but which lacks information needed to |
| 687 | /// determine its size. |
| 688 | bool Type::isIncompleteType() const { |
| 689 | switch (CanonicalType->getTypeClass()) { |
| 690 | default: return false; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 691 | case ASQual: |
| 692 | return cast<ASQualType>(CanonicalType)->getBaseType()->isIncompleteType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 693 | case Builtin: |
| 694 | // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never |
| 695 | // be completed. |
| 696 | return isVoidType(); |
| 697 | case Tagged: |
| 698 | // A tagged type (struct/union/enum/class) is incomplete if the decl is a |
| 699 | // forward declaration, but not a full definition (C99 6.2.5p22). |
| 700 | return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 701 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 702 | // 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] | 703 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 707 | /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) |
| 708 | bool Type::isPODType() const { |
| 709 | // The compiler shouldn't query this for incomplete types, but the user might. |
| 710 | // We return false for that case. |
| 711 | if (isIncompleteType()) |
| 712 | return false; |
| 713 | |
| 714 | switch (CanonicalType->getTypeClass()) { |
| 715 | // Everything not explicitly mentioned is not POD. |
| 716 | default: return false; |
| 717 | case ASQual: |
| 718 | return cast<ASQualType>(CanonicalType)->getBaseType()->isPODType(); |
| 719 | case VariableArray: |
| 720 | case ConstantArray: |
| 721 | // IncompleteArray is caught by isIncompleteType() above. |
| 722 | return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); |
| 723 | |
| 724 | case Builtin: |
| 725 | case Complex: |
| 726 | case Pointer: |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame^] | 727 | case MemberPointer: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 728 | case Vector: |
| 729 | case ExtVector: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 730 | return true; |
| 731 | |
| 732 | case Tagged: |
| 733 | if (isEnumeralType()) |
| 734 | return true; |
| 735 | if (CXXRecordDecl *RDecl = dyn_cast<CXXRecordDecl>( |
| 736 | cast<TagType>(CanonicalType)->getDecl())) |
| 737 | return RDecl->isPOD(); |
| 738 | // C struct/union is POD. |
| 739 | return true; |
| 740 | } |
| 741 | } |
| 742 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 743 | bool Type::isPromotableIntegerType() const { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 744 | if (const BuiltinType *BT = getAsBuiltinType()) |
| 745 | switch (BT->getKind()) { |
| 746 | case BuiltinType::Bool: |
| 747 | case BuiltinType::Char_S: |
| 748 | case BuiltinType::Char_U: |
| 749 | case BuiltinType::SChar: |
| 750 | case BuiltinType::UChar: |
| 751 | case BuiltinType::Short: |
| 752 | case BuiltinType::UShort: |
| 753 | return true; |
| 754 | default: |
| 755 | return false; |
| 756 | } |
| 757 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | const char *BuiltinType::getName() const { |
| 761 | switch (getKind()) { |
| 762 | default: assert(0 && "Unknown builtin type!"); |
| 763 | case Void: return "void"; |
| 764 | case Bool: return "_Bool"; |
| 765 | case Char_S: return "char"; |
| 766 | case Char_U: return "char"; |
| 767 | case SChar: return "signed char"; |
| 768 | case Short: return "short"; |
| 769 | case Int: return "int"; |
| 770 | case Long: return "long"; |
| 771 | case LongLong: return "long long"; |
| 772 | case UChar: return "unsigned char"; |
| 773 | case UShort: return "unsigned short"; |
| 774 | case UInt: return "unsigned int"; |
| 775 | case ULong: return "unsigned long"; |
| 776 | case ULongLong: return "unsigned long long"; |
| 777 | case Float: return "float"; |
| 778 | case Double: return "double"; |
| 779 | case LongDouble: return "long double"; |
Argyrios Kyrtzidis | 46713ef | 2008-08-09 17:11:33 +0000 | [diff] [blame] | 780 | case WChar: return "wchar_t"; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 781 | case Overload: return "<overloaded function type>"; |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 782 | case Dependent: return "<dependent type>"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 786 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
Chris Lattner | 942cfd3 | 2007-07-20 18:48:28 +0000 | [diff] [blame] | 787 | arg_type_iterator ArgTys, |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 788 | unsigned NumArgs, bool isVariadic, |
| 789 | unsigned TypeQuals) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 790 | ID.AddPointer(Result.getAsOpaquePtr()); |
| 791 | for (unsigned i = 0; i != NumArgs; ++i) |
| 792 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
| 793 | ID.AddInteger(isVariadic); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 794 | ID.AddInteger(TypeQuals); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) { |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 798 | Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), |
| 799 | getTypeQuals()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 802 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 803 | const ObjCInterfaceDecl *Decl, |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 804 | ObjCProtocolDecl **protocols, |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 805 | unsigned NumProtocols) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 806 | ID.AddPointer(Decl); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 807 | for (unsigned i = 0; i != NumProtocols; i++) |
| 808 | ID.AddPointer(protocols[i]); |
| 809 | } |
| 810 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 811 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 812 | Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 815 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 62f5f7f | 2008-07-26 00:46:50 +0000 | [diff] [blame] | 816 | ObjCProtocolDecl **protocols, |
| 817 | unsigned NumProtocols) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 818 | for (unsigned i = 0; i != NumProtocols; i++) |
| 819 | ID.AddPointer(protocols[i]); |
| 820 | } |
| 821 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 822 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 823 | Profile(ID, &Protocols[0], getNumProtocols()); |
| 824 | } |
| 825 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 826 | /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to |
| 827 | /// potentially looking through *all* consequtive typedefs. This returns the |
| 828 | /// sum of the type qualifiers, so if you have: |
| 829 | /// typedef const int A; |
| 830 | /// typedef volatile A B; |
| 831 | /// looking through the typedefs for B will give you "const volatile A". |
| 832 | /// |
| 833 | QualType TypedefType::LookThroughTypedefs() const { |
| 834 | // Usually, there is only a single level of typedefs, be fast in that case. |
| 835 | QualType FirstType = getDecl()->getUnderlyingType(); |
| 836 | if (!isa<TypedefType>(FirstType)) |
| 837 | return FirstType; |
| 838 | |
| 839 | // Otherwise, do the fully general loop. |
| 840 | unsigned TypeQuals = 0; |
| 841 | const TypedefType *TDT = this; |
| 842 | while (1) { |
| 843 | QualType CurType = TDT->getDecl()->getUnderlyingType(); |
Chris Lattner | f46699c | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 844 | |
| 845 | |
| 846 | /// FIXME: |
| 847 | /// FIXME: This is incorrect for ASQuals! |
| 848 | /// FIXME: |
| 849 | TypeQuals |= CurType.getCVRQualifiers(); |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 850 | |
| 851 | TDT = dyn_cast<TypedefType>(CurType); |
| 852 | if (TDT == 0) |
| 853 | return QualType(CurType.getTypePtr(), TypeQuals); |
| 854 | } |
| 855 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 856 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 857 | TypeOfExpr::TypeOfExpr(Expr *E, QualType can) |
| 858 | : Type(TypeOfExp, can, E->isTypeDependent()), TOExpr(E) { |
| 859 | assert(!isa<TypedefType>(can) && "Invalid canonical type"); |
| 860 | } |
| 861 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 862 | bool RecordType::classof(const TagType *TT) { |
| 863 | return isa<RecordDecl>(TT->getDecl()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Argyrios Kyrtzidis | 49aa7ff | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 866 | bool CXXRecordType::classof(const TagType *TT) { |
| 867 | return isa<CXXRecordDecl>(TT->getDecl()); |
| 868 | } |
| 869 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 870 | bool EnumType::classof(const TagType *TT) { |
| 871 | return isa<EnumDecl>(TT->getDecl()); |
Chris Lattner | 5edb8bf | 2008-04-06 21:58:47 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Anders Carlsson | 97e0179 | 2008-12-21 00:16:32 +0000 | [diff] [blame] | 874 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 875 | //===----------------------------------------------------------------------===// |
| 876 | // Type Printing |
| 877 | //===----------------------------------------------------------------------===// |
| 878 | |
| 879 | void QualType::dump(const char *msg) const { |
Chris Lattner | 39caea9 | 2007-12-06 04:20:07 +0000 | [diff] [blame] | 880 | std::string R = "identifier"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 881 | getAsStringInternal(R); |
| 882 | if (msg) |
| 883 | fprintf(stderr, "%s: %s\n", msg, R.c_str()); |
| 884 | else |
| 885 | fprintf(stderr, "%s\n", R.c_str()); |
| 886 | } |
Chris Lattner | c36d405 | 2008-07-27 00:48:22 +0000 | [diff] [blame] | 887 | void QualType::dump() const { |
| 888 | dump(""); |
| 889 | } |
| 890 | |
| 891 | void Type::dump() const { |
| 892 | std::string S = "identifier"; |
| 893 | getAsStringInternal(S); |
| 894 | fprintf(stderr, "%s\n", S.c_str()); |
| 895 | } |
| 896 | |
| 897 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 898 | |
| 899 | static void AppendTypeQualList(std::string &S, unsigned TypeQuals) { |
| 900 | // Note: funkiness to ensure we get a space only between quals. |
| 901 | bool NonePrinted = true; |
| 902 | if (TypeQuals & QualType::Const) |
| 903 | S += "const", NonePrinted = false; |
| 904 | if (TypeQuals & QualType::Volatile) |
| 905 | S += (NonePrinted+" volatile"), NonePrinted = false; |
| 906 | if (TypeQuals & QualType::Restrict) |
| 907 | S += (NonePrinted+" restrict"), NonePrinted = false; |
| 908 | } |
| 909 | |
| 910 | void QualType::getAsStringInternal(std::string &S) const { |
| 911 | if (isNull()) { |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 912 | S += "NULL TYPE"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 913 | return; |
| 914 | } |
| 915 | |
| 916 | // Print qualifiers as appropriate. |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 917 | if (unsigned Tq = getCVRQualifiers()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 918 | std::string TQS; |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 919 | AppendTypeQualList(TQS, Tq); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 920 | if (!S.empty()) |
| 921 | S = TQS + ' ' + S; |
| 922 | else |
| 923 | S = TQS; |
| 924 | } |
| 925 | |
| 926 | getTypePtr()->getAsStringInternal(S); |
| 927 | } |
| 928 | |
| 929 | void BuiltinType::getAsStringInternal(std::string &S) const { |
| 930 | if (S.empty()) { |
| 931 | S = getName(); |
| 932 | } else { |
| 933 | // Prefix the basic type, e.g. 'int X'. |
| 934 | S = ' ' + S; |
| 935 | S = getName() + S; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | void ComplexType::getAsStringInternal(std::string &S) const { |
| 940 | ElementType->getAsStringInternal(S); |
| 941 | S = "_Complex " + S; |
| 942 | } |
| 943 | |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 944 | void ASQualType::getAsStringInternal(std::string &S) const { |
| 945 | S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S; |
| 946 | BaseType->getAsStringInternal(S); |
| 947 | } |
| 948 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 949 | void PointerType::getAsStringInternal(std::string &S) const { |
| 950 | S = '*' + S; |
| 951 | |
| 952 | // Handle things like 'int (*A)[4];' correctly. |
| 953 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 954 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 955 | S = '(' + S + ')'; |
| 956 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 957 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 960 | void BlockPointerType::getAsStringInternal(std::string &S) const { |
| 961 | S = '^' + S; |
| 962 | PointeeType.getAsStringInternal(S); |
| 963 | } |
| 964 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 965 | void ReferenceType::getAsStringInternal(std::string &S) const { |
| 966 | S = '&' + S; |
| 967 | |
| 968 | // Handle things like 'int (&A)[4];' correctly. |
| 969 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 970 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 971 | S = '(' + S + ')'; |
| 972 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 973 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame^] | 976 | void MemberPointerType::getAsStringInternal(std::string &S) const { |
| 977 | std::string C; |
| 978 | Class->getAsStringInternal(C); |
| 979 | C += "::*"; |
| 980 | S = C + S; |
| 981 | |
| 982 | // Handle things like 'int (&A)[4];' correctly. |
| 983 | // FIXME: this should include vectors, but vectors use attributes I guess. |
| 984 | if (isa<ArrayType>(getPointeeType())) |
| 985 | S = '(' + S + ')'; |
| 986 | |
| 987 | getPointeeType().getAsStringInternal(S); |
| 988 | } |
| 989 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 990 | void ConstantArrayType::getAsStringInternal(std::string &S) const { |
| 991 | S += '['; |
Steve Naroff | 6b91cd9 | 2007-08-30 18:45:57 +0000 | [diff] [blame] | 992 | S += llvm::utostr(getSize().getZExtValue()); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 993 | S += ']'; |
| 994 | |
| 995 | getElementType().getAsStringInternal(S); |
| 996 | } |
| 997 | |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 998 | void IncompleteArrayType::getAsStringInternal(std::string &S) const { |
| 999 | S += "[]"; |
| 1000 | |
| 1001 | getElementType().getAsStringInternal(S); |
| 1002 | } |
| 1003 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1004 | void VariableArrayType::getAsStringInternal(std::string &S) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1005 | S += '['; |
| 1006 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1007 | if (getIndexTypeQualifier()) { |
| 1008 | AppendTypeQualList(S, getIndexTypeQualifier()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1009 | S += ' '; |
| 1010 | } |
| 1011 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1012 | if (getSizeModifier() == Static) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1013 | S += "static"; |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1014 | else if (getSizeModifier() == Star) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1015 | S += '*'; |
| 1016 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1017 | if (getSizeExpr()) { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1018 | std::string SStr; |
| 1019 | llvm::raw_string_ostream s(SStr); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1020 | getSizeExpr()->printPretty(s); |
| 1021 | S += s.str(); |
| 1022 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1023 | S += ']'; |
| 1024 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1025 | getElementType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1028 | void DependentSizedArrayType::getAsStringInternal(std::string &S) const { |
| 1029 | S += '['; |
| 1030 | |
| 1031 | if (getIndexTypeQualifier()) { |
| 1032 | AppendTypeQualList(S, getIndexTypeQualifier()); |
| 1033 | S += ' '; |
| 1034 | } |
| 1035 | |
| 1036 | if (getSizeModifier() == Static) |
| 1037 | S += "static"; |
| 1038 | else if (getSizeModifier() == Star) |
| 1039 | S += '*'; |
| 1040 | |
| 1041 | if (getSizeExpr()) { |
| 1042 | std::string SStr; |
| 1043 | llvm::raw_string_ostream s(SStr); |
| 1044 | getSizeExpr()->printPretty(s); |
| 1045 | S += s.str(); |
| 1046 | } |
| 1047 | S += ']'; |
| 1048 | |
| 1049 | getElementType().getAsStringInternal(S); |
| 1050 | } |
| 1051 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1052 | void VectorType::getAsStringInternal(std::string &S) const { |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1053 | // FIXME: We prefer to print the size directly here, but have no way |
| 1054 | // to get the size of the type. |
Chris Lattner | 7ee261c | 2007-11-27 07:28:18 +0000 | [diff] [blame] | 1055 | S += " __attribute__((__vector_size__("; |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1056 | S += llvm::utostr_32(NumElements); // convert back to bytes. |
| 1057 | S += " * sizeof(" + ElementType.getAsString() + "))))"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1060 | void ExtVectorType::getAsStringInternal(std::string &S) const { |
| 1061 | S += " __attribute__((ext_vector_type("; |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1062 | S += llvm::utostr_32(NumElements); |
| 1063 | S += ")))"; |
| 1064 | ElementType.getAsStringInternal(S); |
| 1065 | } |
| 1066 | |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1067 | void TypeOfExpr::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1068 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'. |
| 1069 | InnerString = ' ' + InnerString; |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1070 | std::string Str; |
| 1071 | llvm::raw_string_ostream s(Str); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1072 | getUnderlyingExpr()->printPretty(s); |
Steve Naroff | 1bfd5cc | 2007-08-05 03:24:45 +0000 | [diff] [blame] | 1073 | InnerString = "typeof(" + s.str() + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1076 | void TypeOfType::getAsStringInternal(std::string &InnerString) const { |
| 1077 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'. |
| 1078 | InnerString = ' ' + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1079 | std::string Tmp; |
| 1080 | getUnderlyingType().getAsStringInternal(Tmp); |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1081 | InnerString = "typeof(" + Tmp + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1084 | void FunctionTypeNoProto::getAsStringInternal(std::string &S) const { |
| 1085 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1086 | if (!S.empty()) |
| 1087 | S = "(" + S + ")"; |
| 1088 | |
| 1089 | S += "()"; |
| 1090 | getResultType().getAsStringInternal(S); |
| 1091 | } |
| 1092 | |
| 1093 | void FunctionTypeProto::getAsStringInternal(std::string &S) const { |
| 1094 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1095 | if (!S.empty()) |
| 1096 | S = "(" + S + ")"; |
| 1097 | |
| 1098 | S += "("; |
| 1099 | std::string Tmp; |
| 1100 | for (unsigned i = 0, e = getNumArgs(); i != e; ++i) { |
| 1101 | if (i) S += ", "; |
| 1102 | getArgType(i).getAsStringInternal(Tmp); |
| 1103 | S += Tmp; |
| 1104 | Tmp.clear(); |
| 1105 | } |
| 1106 | |
| 1107 | if (isVariadic()) { |
| 1108 | if (getNumArgs()) |
| 1109 | S += ", "; |
| 1110 | S += "..."; |
| 1111 | } else if (getNumArgs() == 0) { |
| 1112 | // Do not emit int() if we have a proto, emit 'int(void)'. |
| 1113 | S += "void"; |
| 1114 | } |
| 1115 | |
| 1116 | S += ")"; |
| 1117 | getResultType().getAsStringInternal(S); |
| 1118 | } |
| 1119 | |
| 1120 | |
| 1121 | void TypedefType::getAsStringInternal(std::string &InnerString) const { |
| 1122 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1123 | InnerString = ' ' + InnerString; |
| 1124 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1125 | } |
| 1126 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1127 | void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const { |
| 1128 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'. |
| 1129 | InnerString = ' ' + InnerString; |
| 1130 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1131 | } |
| 1132 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1133 | void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1134 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1135 | InnerString = ' ' + InnerString; |
| 1136 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1137 | } |
| 1138 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1139 | void ObjCQualifiedInterfaceType::getAsStringInternal( |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1140 | std::string &InnerString) const { |
Fariborz Jahanian | dfbcce2 | 2007-10-11 18:08:47 +0000 | [diff] [blame] | 1141 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1142 | InnerString = ' ' + InnerString; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1143 | std::string ObjCQIString = getDecl()->getNameAsString(); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1144 | ObjCQIString += '<'; |
Chris Lattner | cdce6d1 | 2008-07-21 05:19:23 +0000 | [diff] [blame] | 1145 | bool isFirst = true; |
| 1146 | for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { |
| 1147 | if (isFirst) |
| 1148 | isFirst = false; |
| 1149 | else |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1150 | ObjCQIString += ','; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1151 | ObjCQIString += (*I)->getNameAsString(); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1152 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1153 | ObjCQIString += '>'; |
| 1154 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Chris Lattner | e8e4f92 | 2008-07-25 23:07:18 +0000 | [diff] [blame] | 1157 | void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1158 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1159 | InnerString = ' ' + InnerString; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1160 | std::string ObjCQIString = "id"; |
| 1161 | ObjCQIString += '<'; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1162 | int num = getNumProtocols(); |
| 1163 | for (int i = 0; i < num; i++) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1164 | ObjCQIString += getProtocols(i)->getNameAsString(); |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1165 | if (i < num-1) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1166 | ObjCQIString += ','; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1167 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1168 | ObjCQIString += '>'; |
| 1169 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1172 | void TagType::getAsStringInternal(std::string &InnerString) const { |
| 1173 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1174 | InnerString = ' ' + InnerString; |
| 1175 | |
| 1176 | const char *Kind = getDecl()->getKindName(); |
| 1177 | const char *ID; |
| 1178 | if (const IdentifierInfo *II = getDecl()->getIdentifier()) |
| 1179 | ID = II->getName(); |
| 1180 | else |
| 1181 | ID = "<anonymous>"; |
| 1182 | |
| 1183 | InnerString = std::string(Kind) + " " + ID + InnerString; |
| 1184 | } |