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