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(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 35 | C.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(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 41 | C.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(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 47 | C.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 | |
Douglas Gregor | d7eb846 | 2009-01-30 17:31:00 +0000 | [diff] [blame^] | 664 | /// \brief Determines whether the type is a C++ aggregate type or C |
| 665 | /// aggregate or union type. |
| 666 | /// |
| 667 | /// An aggregate type is an array or a class type (struct, union, or |
| 668 | /// class) that has no user-declared constructors, no private or |
| 669 | /// protected non-static data members, no base classes, and no virtual |
| 670 | /// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type |
| 671 | /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also |
| 672 | /// includes union types. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 673 | bool Type::isAggregateType() const { |
Douglas Gregor | d7eb846 | 2009-01-30 17:31:00 +0000 | [diff] [blame^] | 674 | if (const CXXRecordType *CXXClassType = dyn_cast<CXXRecordType>(CanonicalType)) |
| 675 | return CXXClassType->getDecl()->isAggregate(); |
| 676 | if (isa<RecordType>(CanonicalType)) |
| 677 | return true; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 678 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 679 | return ASQT->getBaseType()->isAggregateType(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 680 | return isa<ArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 681 | } |
| 682 | |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 683 | /// isConstantSizeType - Return true if this is not a variable sized type, |
| 684 | /// 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] | 685 | /// incomplete types or dependent types. |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 686 | bool Type::isConstantSizeType() const { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 687 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 688 | return ASQT->getBaseType()->isConstantSizeType(); |
Chris Lattner | d52a457 | 2007-12-18 07:03:30 +0000 | [diff] [blame] | 689 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 690 | assert(!isDependentType() && "This doesn't make sense for dependent types"); |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 691 | // The VAT must have a size, as it is known to be complete. |
| 692 | return !isa<VariableArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) |
| 696 | /// - a type that can describe objects, but which lacks information needed to |
| 697 | /// determine its size. |
| 698 | bool Type::isIncompleteType() const { |
| 699 | switch (CanonicalType->getTypeClass()) { |
| 700 | default: return false; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 701 | case ASQual: |
| 702 | return cast<ASQualType>(CanonicalType)->getBaseType()->isIncompleteType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 703 | case Builtin: |
| 704 | // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never |
| 705 | // be completed. |
| 706 | return isVoidType(); |
| 707 | case Tagged: |
| 708 | // A tagged type (struct/union/enum/class) is incomplete if the decl is a |
| 709 | // forward declaration, but not a full definition (C99 6.2.5p22). |
| 710 | return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 711 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 712 | // 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] | 713 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 717 | /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) |
| 718 | bool Type::isPODType() const { |
| 719 | // The compiler shouldn't query this for incomplete types, but the user might. |
| 720 | // We return false for that case. |
| 721 | if (isIncompleteType()) |
| 722 | return false; |
| 723 | |
| 724 | switch (CanonicalType->getTypeClass()) { |
| 725 | // Everything not explicitly mentioned is not POD. |
| 726 | default: return false; |
| 727 | case ASQual: |
| 728 | return cast<ASQualType>(CanonicalType)->getBaseType()->isPODType(); |
| 729 | case VariableArray: |
| 730 | case ConstantArray: |
| 731 | // IncompleteArray is caught by isIncompleteType() above. |
| 732 | return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); |
| 733 | |
| 734 | case Builtin: |
| 735 | case Complex: |
| 736 | case Pointer: |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 737 | case MemberPointer: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 738 | case Vector: |
| 739 | case ExtVector: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 740 | return true; |
| 741 | |
| 742 | case Tagged: |
| 743 | if (isEnumeralType()) |
| 744 | return true; |
| 745 | if (CXXRecordDecl *RDecl = dyn_cast<CXXRecordDecl>( |
| 746 | cast<TagType>(CanonicalType)->getDecl())) |
| 747 | return RDecl->isPOD(); |
| 748 | // C struct/union is POD. |
| 749 | return true; |
| 750 | } |
| 751 | } |
| 752 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 753 | bool Type::isPromotableIntegerType() const { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 754 | if (const BuiltinType *BT = getAsBuiltinType()) |
| 755 | switch (BT->getKind()) { |
| 756 | case BuiltinType::Bool: |
| 757 | case BuiltinType::Char_S: |
| 758 | case BuiltinType::Char_U: |
| 759 | case BuiltinType::SChar: |
| 760 | case BuiltinType::UChar: |
| 761 | case BuiltinType::Short: |
| 762 | case BuiltinType::UShort: |
| 763 | return true; |
| 764 | default: |
| 765 | return false; |
| 766 | } |
| 767 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | const char *BuiltinType::getName() const { |
| 771 | switch (getKind()) { |
| 772 | default: assert(0 && "Unknown builtin type!"); |
| 773 | case Void: return "void"; |
| 774 | case Bool: return "_Bool"; |
| 775 | case Char_S: return "char"; |
| 776 | case Char_U: return "char"; |
| 777 | case SChar: return "signed char"; |
| 778 | case Short: return "short"; |
| 779 | case Int: return "int"; |
| 780 | case Long: return "long"; |
| 781 | case LongLong: return "long long"; |
| 782 | case UChar: return "unsigned char"; |
| 783 | case UShort: return "unsigned short"; |
| 784 | case UInt: return "unsigned int"; |
| 785 | case ULong: return "unsigned long"; |
| 786 | case ULongLong: return "unsigned long long"; |
| 787 | case Float: return "float"; |
| 788 | case Double: return "double"; |
| 789 | case LongDouble: return "long double"; |
Argyrios Kyrtzidis | 46713ef | 2008-08-09 17:11:33 +0000 | [diff] [blame] | 790 | case WChar: return "wchar_t"; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 791 | case Overload: return "<overloaded function type>"; |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 792 | case Dependent: return "<dependent type>"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 796 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
Chris Lattner | 942cfd3 | 2007-07-20 18:48:28 +0000 | [diff] [blame] | 797 | arg_type_iterator ArgTys, |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 798 | unsigned NumArgs, bool isVariadic, |
| 799 | unsigned TypeQuals) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 800 | ID.AddPointer(Result.getAsOpaquePtr()); |
| 801 | for (unsigned i = 0; i != NumArgs; ++i) |
| 802 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
| 803 | ID.AddInteger(isVariadic); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 804 | ID.AddInteger(TypeQuals); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) { |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 808 | Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), |
| 809 | getTypeQuals()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 812 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 813 | const ObjCInterfaceDecl *Decl, |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 814 | ObjCProtocolDecl **protocols, |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 815 | unsigned NumProtocols) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 816 | ID.AddPointer(Decl); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 817 | for (unsigned i = 0; i != NumProtocols; i++) |
| 818 | ID.AddPointer(protocols[i]); |
| 819 | } |
| 820 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 821 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 822 | Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 825 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 62f5f7f | 2008-07-26 00:46:50 +0000 | [diff] [blame] | 826 | ObjCProtocolDecl **protocols, |
| 827 | unsigned NumProtocols) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 828 | for (unsigned i = 0; i != NumProtocols; i++) |
| 829 | ID.AddPointer(protocols[i]); |
| 830 | } |
| 831 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 832 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 833 | Profile(ID, &Protocols[0], getNumProtocols()); |
| 834 | } |
| 835 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 836 | /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to |
| 837 | /// potentially looking through *all* consequtive typedefs. This returns the |
| 838 | /// sum of the type qualifiers, so if you have: |
| 839 | /// typedef const int A; |
| 840 | /// typedef volatile A B; |
| 841 | /// looking through the typedefs for B will give you "const volatile A". |
| 842 | /// |
| 843 | QualType TypedefType::LookThroughTypedefs() const { |
| 844 | // Usually, there is only a single level of typedefs, be fast in that case. |
| 845 | QualType FirstType = getDecl()->getUnderlyingType(); |
| 846 | if (!isa<TypedefType>(FirstType)) |
| 847 | return FirstType; |
| 848 | |
| 849 | // Otherwise, do the fully general loop. |
| 850 | unsigned TypeQuals = 0; |
| 851 | const TypedefType *TDT = this; |
| 852 | while (1) { |
| 853 | QualType CurType = TDT->getDecl()->getUnderlyingType(); |
Chris Lattner | f46699c | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 854 | |
| 855 | |
| 856 | /// FIXME: |
| 857 | /// FIXME: This is incorrect for ASQuals! |
| 858 | /// FIXME: |
| 859 | TypeQuals |= CurType.getCVRQualifiers(); |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 860 | |
| 861 | TDT = dyn_cast<TypedefType>(CurType); |
| 862 | if (TDT == 0) |
| 863 | return QualType(CurType.getTypePtr(), TypeQuals); |
| 864 | } |
| 865 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 866 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 867 | TypeOfExpr::TypeOfExpr(Expr *E, QualType can) |
| 868 | : Type(TypeOfExp, can, E->isTypeDependent()), TOExpr(E) { |
| 869 | assert(!isa<TypedefType>(can) && "Invalid canonical type"); |
| 870 | } |
| 871 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 872 | bool RecordType::classof(const TagType *TT) { |
| 873 | return isa<RecordDecl>(TT->getDecl()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Argyrios Kyrtzidis | 49aa7ff | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 876 | bool CXXRecordType::classof(const TagType *TT) { |
| 877 | return isa<CXXRecordDecl>(TT->getDecl()); |
| 878 | } |
| 879 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 880 | bool EnumType::classof(const TagType *TT) { |
| 881 | return isa<EnumDecl>(TT->getDecl()); |
Chris Lattner | 5edb8bf | 2008-04-06 21:58:47 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Anders Carlsson | 97e0179 | 2008-12-21 00:16:32 +0000 | [diff] [blame] | 884 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 885 | //===----------------------------------------------------------------------===// |
| 886 | // Type Printing |
| 887 | //===----------------------------------------------------------------------===// |
| 888 | |
| 889 | void QualType::dump(const char *msg) const { |
Chris Lattner | 39caea9 | 2007-12-06 04:20:07 +0000 | [diff] [blame] | 890 | std::string R = "identifier"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 891 | getAsStringInternal(R); |
| 892 | if (msg) |
| 893 | fprintf(stderr, "%s: %s\n", msg, R.c_str()); |
| 894 | else |
| 895 | fprintf(stderr, "%s\n", R.c_str()); |
| 896 | } |
Chris Lattner | c36d405 | 2008-07-27 00:48:22 +0000 | [diff] [blame] | 897 | void QualType::dump() const { |
| 898 | dump(""); |
| 899 | } |
| 900 | |
| 901 | void Type::dump() const { |
| 902 | std::string S = "identifier"; |
| 903 | getAsStringInternal(S); |
| 904 | fprintf(stderr, "%s\n", S.c_str()); |
| 905 | } |
| 906 | |
| 907 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 908 | |
| 909 | static void AppendTypeQualList(std::string &S, unsigned TypeQuals) { |
| 910 | // Note: funkiness to ensure we get a space only between quals. |
| 911 | bool NonePrinted = true; |
| 912 | if (TypeQuals & QualType::Const) |
| 913 | S += "const", NonePrinted = false; |
| 914 | if (TypeQuals & QualType::Volatile) |
| 915 | S += (NonePrinted+" volatile"), NonePrinted = false; |
| 916 | if (TypeQuals & QualType::Restrict) |
| 917 | S += (NonePrinted+" restrict"), NonePrinted = false; |
| 918 | } |
| 919 | |
| 920 | void QualType::getAsStringInternal(std::string &S) const { |
| 921 | if (isNull()) { |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 922 | S += "NULL TYPE"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 923 | return; |
| 924 | } |
| 925 | |
| 926 | // Print qualifiers as appropriate. |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 927 | if (unsigned Tq = getCVRQualifiers()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 928 | std::string TQS; |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 929 | AppendTypeQualList(TQS, Tq); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 930 | if (!S.empty()) |
| 931 | S = TQS + ' ' + S; |
| 932 | else |
| 933 | S = TQS; |
| 934 | } |
| 935 | |
| 936 | getTypePtr()->getAsStringInternal(S); |
| 937 | } |
| 938 | |
| 939 | void BuiltinType::getAsStringInternal(std::string &S) const { |
| 940 | if (S.empty()) { |
| 941 | S = getName(); |
| 942 | } else { |
| 943 | // Prefix the basic type, e.g. 'int X'. |
| 944 | S = ' ' + S; |
| 945 | S = getName() + S; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | void ComplexType::getAsStringInternal(std::string &S) const { |
| 950 | ElementType->getAsStringInternal(S); |
| 951 | S = "_Complex " + S; |
| 952 | } |
| 953 | |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 954 | void ASQualType::getAsStringInternal(std::string &S) const { |
| 955 | S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S; |
| 956 | BaseType->getAsStringInternal(S); |
| 957 | } |
| 958 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 959 | void PointerType::getAsStringInternal(std::string &S) const { |
| 960 | S = '*' + S; |
| 961 | |
| 962 | // Handle things like 'int (*A)[4];' correctly. |
| 963 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 964 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 965 | S = '(' + S + ')'; |
| 966 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 967 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 970 | void BlockPointerType::getAsStringInternal(std::string &S) const { |
| 971 | S = '^' + S; |
| 972 | PointeeType.getAsStringInternal(S); |
| 973 | } |
| 974 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 975 | void ReferenceType::getAsStringInternal(std::string &S) const { |
| 976 | S = '&' + S; |
| 977 | |
| 978 | // Handle things like 'int (&A)[4];' correctly. |
| 979 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 980 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 981 | S = '(' + S + ')'; |
| 982 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 983 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 986 | void MemberPointerType::getAsStringInternal(std::string &S) const { |
| 987 | std::string C; |
| 988 | Class->getAsStringInternal(C); |
| 989 | C += "::*"; |
| 990 | S = C + S; |
| 991 | |
| 992 | // Handle things like 'int (&A)[4];' correctly. |
| 993 | // FIXME: this should include vectors, but vectors use attributes I guess. |
| 994 | if (isa<ArrayType>(getPointeeType())) |
| 995 | S = '(' + S + ')'; |
| 996 | |
| 997 | getPointeeType().getAsStringInternal(S); |
| 998 | } |
| 999 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1000 | void ConstantArrayType::getAsStringInternal(std::string &S) const { |
| 1001 | S += '['; |
Steve Naroff | 6b91cd9 | 2007-08-30 18:45:57 +0000 | [diff] [blame] | 1002 | S += llvm::utostr(getSize().getZExtValue()); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1003 | S += ']'; |
| 1004 | |
| 1005 | getElementType().getAsStringInternal(S); |
| 1006 | } |
| 1007 | |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 1008 | void IncompleteArrayType::getAsStringInternal(std::string &S) const { |
| 1009 | S += "[]"; |
| 1010 | |
| 1011 | getElementType().getAsStringInternal(S); |
| 1012 | } |
| 1013 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1014 | void VariableArrayType::getAsStringInternal(std::string &S) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1015 | S += '['; |
| 1016 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1017 | if (getIndexTypeQualifier()) { |
| 1018 | AppendTypeQualList(S, getIndexTypeQualifier()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1019 | S += ' '; |
| 1020 | } |
| 1021 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1022 | if (getSizeModifier() == Static) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1023 | S += "static"; |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1024 | else if (getSizeModifier() == Star) |
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 | if (getSizeExpr()) { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1028 | std::string SStr; |
| 1029 | llvm::raw_string_ostream s(SStr); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1030 | getSizeExpr()->printPretty(s); |
| 1031 | S += s.str(); |
| 1032 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1033 | S += ']'; |
| 1034 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1035 | getElementType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1038 | void DependentSizedArrayType::getAsStringInternal(std::string &S) const { |
| 1039 | S += '['; |
| 1040 | |
| 1041 | if (getIndexTypeQualifier()) { |
| 1042 | AppendTypeQualList(S, getIndexTypeQualifier()); |
| 1043 | S += ' '; |
| 1044 | } |
| 1045 | |
| 1046 | if (getSizeModifier() == Static) |
| 1047 | S += "static"; |
| 1048 | else if (getSizeModifier() == Star) |
| 1049 | S += '*'; |
| 1050 | |
| 1051 | if (getSizeExpr()) { |
| 1052 | std::string SStr; |
| 1053 | llvm::raw_string_ostream s(SStr); |
| 1054 | getSizeExpr()->printPretty(s); |
| 1055 | S += s.str(); |
| 1056 | } |
| 1057 | S += ']'; |
| 1058 | |
| 1059 | getElementType().getAsStringInternal(S); |
| 1060 | } |
| 1061 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1062 | void VectorType::getAsStringInternal(std::string &S) const { |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1063 | // FIXME: We prefer to print the size directly here, but have no way |
| 1064 | // to get the size of the type. |
Chris Lattner | 7ee261c | 2007-11-27 07:28:18 +0000 | [diff] [blame] | 1065 | S += " __attribute__((__vector_size__("; |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1066 | S += llvm::utostr_32(NumElements); // convert back to bytes. |
| 1067 | S += " * sizeof(" + ElementType.getAsString() + "))))"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1070 | void ExtVectorType::getAsStringInternal(std::string &S) const { |
| 1071 | S += " __attribute__((ext_vector_type("; |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1072 | S += llvm::utostr_32(NumElements); |
| 1073 | S += ")))"; |
| 1074 | ElementType.getAsStringInternal(S); |
| 1075 | } |
| 1076 | |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1077 | void TypeOfExpr::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1078 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'. |
| 1079 | InnerString = ' ' + InnerString; |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1080 | std::string Str; |
| 1081 | llvm::raw_string_ostream s(Str); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1082 | getUnderlyingExpr()->printPretty(s); |
Steve Naroff | 1bfd5cc | 2007-08-05 03:24:45 +0000 | [diff] [blame] | 1083 | InnerString = "typeof(" + s.str() + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1086 | void TypeOfType::getAsStringInternal(std::string &InnerString) const { |
| 1087 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'. |
| 1088 | InnerString = ' ' + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1089 | std::string Tmp; |
| 1090 | getUnderlyingType().getAsStringInternal(Tmp); |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1091 | InnerString = "typeof(" + Tmp + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1094 | void FunctionTypeNoProto::getAsStringInternal(std::string &S) const { |
| 1095 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1096 | if (!S.empty()) |
| 1097 | S = "(" + S + ")"; |
| 1098 | |
| 1099 | S += "()"; |
| 1100 | getResultType().getAsStringInternal(S); |
| 1101 | } |
| 1102 | |
| 1103 | void FunctionTypeProto::getAsStringInternal(std::string &S) const { |
| 1104 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1105 | if (!S.empty()) |
| 1106 | S = "(" + S + ")"; |
| 1107 | |
| 1108 | S += "("; |
| 1109 | std::string Tmp; |
| 1110 | for (unsigned i = 0, e = getNumArgs(); i != e; ++i) { |
| 1111 | if (i) S += ", "; |
| 1112 | getArgType(i).getAsStringInternal(Tmp); |
| 1113 | S += Tmp; |
| 1114 | Tmp.clear(); |
| 1115 | } |
| 1116 | |
| 1117 | if (isVariadic()) { |
| 1118 | if (getNumArgs()) |
| 1119 | S += ", "; |
| 1120 | S += "..."; |
| 1121 | } else if (getNumArgs() == 0) { |
| 1122 | // Do not emit int() if we have a proto, emit 'int(void)'. |
| 1123 | S += "void"; |
| 1124 | } |
| 1125 | |
| 1126 | S += ")"; |
| 1127 | getResultType().getAsStringInternal(S); |
| 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | void TypedefType::getAsStringInternal(std::string &InnerString) const { |
| 1132 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1133 | InnerString = ' ' + InnerString; |
| 1134 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1135 | } |
| 1136 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1137 | void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const { |
| 1138 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'. |
| 1139 | InnerString = ' ' + InnerString; |
| 1140 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1141 | } |
| 1142 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1143 | void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1144 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1145 | InnerString = ' ' + InnerString; |
| 1146 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1147 | } |
| 1148 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1149 | void ObjCQualifiedInterfaceType::getAsStringInternal( |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1150 | std::string &InnerString) const { |
Fariborz Jahanian | dfbcce2 | 2007-10-11 18:08:47 +0000 | [diff] [blame] | 1151 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1152 | InnerString = ' ' + InnerString; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1153 | std::string ObjCQIString = getDecl()->getNameAsString(); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1154 | ObjCQIString += '<'; |
Chris Lattner | cdce6d1 | 2008-07-21 05:19:23 +0000 | [diff] [blame] | 1155 | bool isFirst = true; |
| 1156 | for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { |
| 1157 | if (isFirst) |
| 1158 | isFirst = false; |
| 1159 | else |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1160 | ObjCQIString += ','; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1161 | ObjCQIString += (*I)->getNameAsString(); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1162 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1163 | ObjCQIString += '>'; |
| 1164 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
Chris Lattner | e8e4f92 | 2008-07-25 23:07:18 +0000 | [diff] [blame] | 1167 | void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1168 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1169 | InnerString = ' ' + InnerString; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1170 | std::string ObjCQIString = "id"; |
| 1171 | ObjCQIString += '<'; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1172 | int num = getNumProtocols(); |
| 1173 | for (int i = 0; i < num; i++) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1174 | ObjCQIString += getProtocols(i)->getNameAsString(); |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1175 | if (i < num-1) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1176 | ObjCQIString += ','; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1177 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1178 | ObjCQIString += '>'; |
| 1179 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1182 | void TagType::getAsStringInternal(std::string &InnerString) const { |
| 1183 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1184 | InnerString = ' ' + InnerString; |
| 1185 | |
| 1186 | const char *Kind = getDecl()->getKindName(); |
| 1187 | const char *ID; |
| 1188 | if (const IdentifierInfo *II = getDecl()->getIdentifier()) |
| 1189 | ID = II->getName(); |
| 1190 | else |
| 1191 | ID = "<anonymous>"; |
| 1192 | |
| 1193 | InnerString = std::string(Kind) + " " + ID + InnerString; |
| 1194 | } |