blob: 5d3478b2eabaf98b879e261ff569d1ac4ad47644 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Type.cpp - Type representation and manipulation ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements type-related functionality.
11//
12//===----------------------------------------------------------------------===//
13
Nuno Lopesb381aac2008-09-01 11:33:04 +000014#include "clang/AST/ASTContext.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000015#include "clang/AST/Type.h"
Argyrios Kyrtzidis49aa7ff2008-08-07 20:55:28 +000016#include "clang/AST/DeclCXX.h"
Steve Naroff980e5082007-10-01 19:00:59 +000017#include "clang/AST/DeclObjC.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000018#include "clang/AST/Expr.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000019#include "llvm/ADT/StringExtras.h"
Ted Kremenek7360fda2008-09-18 23:09:54 +000020
Reid Spencer5f016e22007-07-11 17:01:13 +000021using namespace clang;
22
Chris Lattner4bbce992009-01-12 00:10:42 +000023bool QualType::isConstant(ASTContext &Ctx) const {
Nuno Lopesb381aac2008-09-01 11:33:04 +000024 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 Kremenek566c2ba2009-01-19 21:31:22 +000033void Type::Destroy(ASTContext& C) {
34 this->~Type();
Steve Naroff3e970492009-01-27 21:25:57 +000035 C.Deallocate(this);
Ted Kremenek4b05b1d2008-05-21 16:38:54 +000036}
37
38void VariableArrayType::Destroy(ASTContext& C) {
39 SizeExpr->Destroy(C);
Ted Kremenek566c2ba2009-01-19 21:31:22 +000040 this->~VariableArrayType();
Steve Naroff3e970492009-01-27 21:25:57 +000041 C.Deallocate(this);
Ted Kremenek4b05b1d2008-05-21 16:38:54 +000042}
Reid Spencer5f016e22007-07-11 17:01:13 +000043
Douglas Gregor898574e2008-12-05 23:32:09 +000044void DependentSizedArrayType::Destroy(ASTContext& C) {
45 SizeExpr->Destroy(C);
Ted Kremenek566c2ba2009-01-19 21:31:22 +000046 this->~DependentSizedArrayType();
Steve Naroff3e970492009-01-27 21:25:57 +000047 C.Deallocate(this);
Douglas Gregor898574e2008-12-05 23:32:09 +000048}
Chris Lattnerc63a1f22008-08-04 07:31:14 +000049
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.
53const 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.
77QualType 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 Spencer5f016e22007-07-11 17:01:13 +000088/// isVoidType - Helper method to determine if this is the 'void' type.
89bool Type::isVoidType() const {
90 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
91 return BT->getKind() == BuiltinType::Void;
Chris Lattner4bbce992009-01-12 00:10:42 +000092 if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType))
93 return AS->getBaseType()->isVoidType();
Reid Spencer5f016e22007-07-11 17:01:13 +000094 return false;
95}
96
97bool Type::isObjectType() const {
98 if (isa<FunctionType>(CanonicalType))
99 return false;
Chris Lattner4bbce992009-01-12 00:10:42 +0000100 if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType))
101 return AS->getBaseType()->isObjectType();
102 return !CanonicalType->isIncompleteType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000103}
104
105bool Type::isDerivedType() const {
106 switch (CanonicalType->getTypeClass()) {
Chris Lattner4bbce992009-01-12 00:10:42 +0000107 case ASQual:
108 return cast<ASQualType>(CanonicalType)->getBaseType()->isDerivedType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000109 case Pointer:
Steve Narofffb22d962007-08-30 01:06:46 +0000110 case VariableArray:
111 case ConstantArray:
Eli Friedmanc5773c42008-02-15 18:16:39 +0000112 case IncompleteArray:
Reid Spencer5f016e22007-07-11 17:01:13 +0000113 case FunctionProto:
114 case FunctionNoProto:
115 case Reference:
116 return true;
Chris Lattner4bbce992009-01-12 00:10:42 +0000117 case Tagged:
118 return !cast<TagType>(CanonicalType)->getDecl()->isEnum();
Reid Spencer5f016e22007-07-11 17:01:13 +0000119 default:
120 return false;
121 }
122}
123
Chris Lattner99dc9142008-04-13 18:59:07 +0000124bool Type::isClassType() const {
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000125 if (const RecordType *RT = getAsRecordType())
126 return RT->getDecl()->isClass();
Chris Lattner99dc9142008-04-13 18:59:07 +0000127 return false;
128}
Chris Lattnerc8629632007-07-31 19:29:30 +0000129bool Type::isStructureType() const {
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000130 if (const RecordType *RT = getAsRecordType())
131 return RT->getDecl()->isStruct();
Chris Lattnerc8629632007-07-31 19:29:30 +0000132 return false;
133}
134bool Type::isUnionType() const {
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000135 if (const RecordType *RT = getAsRecordType())
136 return RT->getDecl()->isUnion();
Chris Lattnerc8629632007-07-31 19:29:30 +0000137 return false;
138}
Chris Lattnerc8629632007-07-31 19:29:30 +0000139
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000140bool Type::isComplexType() const {
Steve Naroff02f62a92008-01-15 19:36:10 +0000141 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
142 return CT->getElementType()->isFloatingType();
Chris Lattner4bbce992009-01-12 00:10:42 +0000143 if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType))
144 return AS->getBaseType()->isComplexType();
Steve Naroff02f62a92008-01-15 19:36:10 +0000145 return false;
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000146}
147
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000148bool 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 Lattner4bbce992009-01-12 00:10:42 +0000152 if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType))
153 return AS->getBaseType()->isComplexIntegerType();
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000154 return false;
155}
156
157const 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 Lattner4bbce992009-01-12 00:10:42 +0000162 return 0;
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000163 }
Chris Lattner4bbce992009-01-12 00:10:42 +0000164
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000165 // 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 Naroff4cdec1c2008-01-15 01:41:59 +0000170 return 0;
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000171 }
172
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000173 // 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 Naroff77878cc2007-08-27 04:08:11 +0000178const 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 Lattnerdea61462007-10-29 03:41:11 +0000182
183 // If the canonical form of this type isn't a builtin type, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000184 if (!isa<BuiltinType>(CanonicalType)) {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000185 // Look through type qualifiers (e.g. ASQualType's).
Christopher Lambebb97e92008-02-04 02:31:56 +0000186 if (isa<BuiltinType>(CanonicalType.getUnqualifiedType()))
187 return CanonicalType.getUnqualifiedType()->getAsBuiltinType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000188 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000189 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000190
Steve Naroff77878cc2007-08-27 04:08:11 +0000191 // If this is a typedef for a builtin type, strip the typedef off without
192 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000193 return getDesugaredType()->getAsBuiltinType();
Steve Naroff77878cc2007-08-27 04:08:11 +0000194}
195
Chris Lattnerc8629632007-07-31 19:29:30 +0000196const FunctionType *Type::getAsFunctionType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000197 // If this is directly a function type, return it.
198 if (const FunctionType *FTy = dyn_cast<FunctionType>(this))
199 return FTy;
Christopher Lambebb97e92008-02-04 02:31:56 +0000200
Chris Lattnerdea61462007-10-29 03:41:11 +0000201 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000202 if (!isa<FunctionType>(CanonicalType)) {
203 // Look through type qualifiers
204 if (isa<FunctionType>(CanonicalType.getUnqualifiedType()))
205 return CanonicalType.getUnqualifiedType()->getAsFunctionType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000206 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000207 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000208
Steve Naroff7064f5c2007-07-26 18:32:01 +0000209 // If this is a typedef for a function type, strip the typedef off without
210 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000211 return getDesugaredType()->getAsFunctionType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000212}
213
Chris Lattnerb77792e2008-07-26 22:17:49 +0000214const FunctionTypeProto *Type::getAsFunctionTypeProto() const {
215 return dyn_cast_or_null<FunctionTypeProto>(getAsFunctionType());
216}
217
218
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000219const 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 Lattnerbefee482007-07-31 16:53:04 +0000237const PointerType *Type::getAsPointerType() const {
Chris Lattner7a2e0472007-07-16 00:23:25 +0000238 // If this is directly a pointer type, return it.
239 if (const PointerType *PTy = dyn_cast<PointerType>(this))
240 return PTy;
Chris Lattnera2c77672007-07-16 22:05:22 +0000241
Chris Lattnerdea61462007-10-29 03:41:11 +0000242 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000243 if (!isa<PointerType>(CanonicalType)) {
244 // Look through type qualifiers
245 if (isa<PointerType>(CanonicalType.getUnqualifiedType()))
246 return CanonicalType.getUnqualifiedType()->getAsPointerType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000247 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000248 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000249
Chris Lattnera2c77672007-07-16 22:05:22 +0000250 // If this is a typedef for a pointer type, strip the typedef off without
251 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000252 return getDesugaredType()->getAsPointerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000253}
254
Steve Naroff5618bd42008-08-27 16:04:49 +0000255const 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 Lattner2a18dfe2009-01-12 00:21:19 +0000261 if (!isa<BlockPointerType>(CanonicalType)) {
262 // Look through type qualifiers
263 if (isa<BlockPointerType>(CanonicalType.getUnqualifiedType()))
264 return CanonicalType.getUnqualifiedType()->getAsBlockPointerType();
Steve Naroff5618bd42008-08-27 16:04:49 +0000265 return 0;
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000266 }
Steve Naroff5618bd42008-08-27 16:04:49 +0000267
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 Lattnera1d9fde2007-07-31 16:56:34 +0000273const ReferenceType *Type::getAsReferenceType() const {
Bill Wendlingea5e79f2007-07-17 04:16:47 +0000274 // If this is directly a reference type, return it.
275 if (const ReferenceType *RTy = dyn_cast<ReferenceType>(this))
276 return RTy;
277
Chris Lattnerdea61462007-10-29 03:41:11 +0000278 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000279 if (!isa<ReferenceType>(CanonicalType)) {
280 // Look through type qualifiers
281 if (isa<ReferenceType>(CanonicalType.getUnqualifiedType()))
282 return CanonicalType.getUnqualifiedType()->getAsReferenceType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000283 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000284 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000285
Bill Wendlingea5e79f2007-07-17 04:16:47 +0000286 // If this is a typedef for a reference type, strip the typedef off without
287 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000288 return getDesugaredType()->getAsReferenceType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000289}
290
Sebastian Redlf30208a2009-01-24 21:16:55 +0000291const 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 Friedmand3f2f792008-02-17 00:59:11 +0000309/// 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 Naroffd7444aa2007-08-31 17:20:07 +0000312bool Type::isVariablyModifiedType() const {
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000313 // A VLA is a variably modified type.
314 if (isVariableArrayType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000315 return true;
316
317 // An array can contain a variably modified type
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000318 if (const Type *T = getArrayElementTypeNoTypeQual())
319 return T->isVariablyModifiedType();
Eli Friedmand3f2f792008-02-17 00:59:11 +0000320
Sebastian Redlf30208a2009-01-24 21:16:55 +0000321 // 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 Friedmand3f2f792008-02-17 00:59:11 +0000326 return PT->getPointeeType()->isVariablyModifiedType();
Sebastian Redl8edef7c2009-01-24 23:29:36 +0000327 if (const MemberPointerType *PT = getAsMemberPointerType())
328 return PT->getPointeeType()->isVariablyModifiedType();
Eli Friedmand3f2f792008-02-17 00:59:11 +0000329
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 Lattner2a18dfe2009-01-12 00:21:19 +0000334 if (const FunctionType *FT = getAsFunctionType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000335 return FT->getResultType()->isVariablyModifiedType();
336
Steve Naroffd7444aa2007-08-31 17:20:07 +0000337 return false;
338}
339
Chris Lattnerc8629632007-07-31 19:29:30 +0000340const RecordType *Type::getAsRecordType() const {
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000341 // If this is directly a reference type, return it.
342 if (const RecordType *RTy = dyn_cast<RecordType>(this))
343 return RTy;
344
Chris Lattnerdea61462007-10-29 03:41:11 +0000345 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000346 if (!isa<RecordType>(CanonicalType)) {
347 // Look through type qualifiers
348 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
349 return CanonicalType.getUnqualifiedType()->getAsRecordType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000350 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000351 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000352
353 // If this is a typedef for a record type, strip the typedef off without
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000354 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000355 return getDesugaredType()->getAsRecordType();
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000356}
357
Chris Lattnerc8629632007-07-31 19:29:30 +0000358const RecordType *Type::getAsStructureType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000359 // If this is directly a structure type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000360 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000361 if (RT->getDecl()->isStruct())
Chris Lattnerc8629632007-07-31 19:29:30 +0000362 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000363 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000364
365 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000366 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000367 if (!RT->getDecl()->isStruct())
Chris Lattnerdea61462007-10-29 03:41:11 +0000368 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 Spencer5f016e22007-07-11 17:01:13 +0000373 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000374 // Look through type qualifiers
375 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
376 return CanonicalType.getUnqualifiedType()->getAsStructureType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000377 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000378}
379
Chris Lattnerc8629632007-07-31 19:29:30 +0000380const RecordType *Type::getAsUnionType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000381 // If this is directly a union type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000382 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000383 if (RT->getDecl()->isUnion())
Chris Lattnerc8629632007-07-31 19:29:30 +0000384 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000385 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000386
Chris Lattnerdea61462007-10-29 03:41:11 +0000387 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000388 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000389 if (!RT->getDecl()->isUnion())
Chris Lattnerdea61462007-10-29 03:41:11 +0000390 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 Spencer5f016e22007-07-11 17:01:13 +0000395 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000396
397 // Look through type qualifiers
398 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
399 return CanonicalType.getUnqualifiedType()->getAsUnionType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000400 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000401}
402
Eli Friedmanad74a752008-06-28 06:23:08 +0000403const 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 Lattnerc6fb90a2007-08-21 16:54:08 +0000410const 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 Lattnerdea61462007-10-29 03:41:11 +0000415 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000416 if (!isa<ComplexType>(CanonicalType)) {
417 // Look through type qualifiers
418 if (isa<ComplexType>(CanonicalType.getUnqualifiedType()))
419 return CanonicalType.getUnqualifiedType()->getAsComplexType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000420 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000421 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000422
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000423 // If this is a typedef for a complex type, strip the typedef off without
424 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000425 return getDesugaredType()->getAsComplexType();
Chris Lattner7a2e0472007-07-16 00:23:25 +0000426}
427
Chris Lattnerc8629632007-07-31 19:29:30 +0000428const VectorType *Type::getAsVectorType() const {
Chris Lattner7a2e0472007-07-16 00:23:25 +0000429 // Are we directly a vector type?
430 if (const VectorType *VTy = dyn_cast<VectorType>(this))
431 return VTy;
Chris Lattnera2c77672007-07-16 22:05:22 +0000432
Chris Lattnerdea61462007-10-29 03:41:11 +0000433 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000434 if (!isa<VectorType>(CanonicalType)) {
435 // Look through type qualifiers
436 if (isa<VectorType>(CanonicalType.getUnqualifiedType()))
437 return CanonicalType.getUnqualifiedType()->getAsVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000438 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000439 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000440
Chris Lattnera2c77672007-07-16 22:05:22 +0000441 // If this is a typedef for a vector type, strip the typedef off without
442 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000443 return getDesugaredType()->getAsVectorType();
Chris Lattner7a2e0472007-07-16 00:23:25 +0000444}
445
Nate Begeman213541a2008-04-18 23:10:10 +0000446const ExtVectorType *Type::getAsExtVectorType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000447 // Are we directly an OpenCU vector type?
Nate Begeman213541a2008-04-18 23:10:10 +0000448 if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this))
Steve Naroff7064f5c2007-07-26 18:32:01 +0000449 return VTy;
450
Chris Lattnerdea61462007-10-29 03:41:11 +0000451 // If the canonical form of this type isn't the right kind, reject it.
Nate Begeman213541a2008-04-18 23:10:10 +0000452 if (!isa<ExtVectorType>(CanonicalType)) {
Christopher Lambebb97e92008-02-04 02:31:56 +0000453 // Look through type qualifiers
Nate Begeman213541a2008-04-18 23:10:10 +0000454 if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType()))
455 return CanonicalType.getUnqualifiedType()->getAsExtVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000456 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000457 }
Steve Naroff7064f5c2007-07-26 18:32:01 +0000458
Nate Begeman213541a2008-04-18 23:10:10 +0000459 // 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 Naroff7064f5c2007-07-26 18:32:01 +0000462}
463
Chris Lattner368eefa2008-04-07 00:27:04 +0000464const ObjCInterfaceType *Type::getAsObjCInterfaceType() const {
Chris Lattnereca7be62008-04-07 05:30:13 +0000465 // There is no sugar for ObjCInterfaceType's, just return the canonical
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000466 // type pointer if it is the right class. There is no typedef information to
467 // return and these cannot be Address-space qualified.
Chris Lattnereca7be62008-04-07 05:30:13 +0000468 return dyn_cast<ObjCInterfaceType>(CanonicalType);
Chris Lattner368eefa2008-04-07 00:27:04 +0000469}
470
471const ObjCQualifiedInterfaceType *
472Type::getAsObjCQualifiedInterfaceType() const {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000473 // There is no sugar for ObjCQualifiedInterfaceType's, just return the
474 // canonical type pointer if it is the right class.
Chris Lattnereca7be62008-04-07 05:30:13 +0000475 return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType);
476}
477
478const 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 Lattner368eefa2008-04-07 00:27:04 +0000482}
483
Douglas Gregor72c3f312008-12-05 18:15:24 +0000484const 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 Lattner2a18dfe2009-01-12 00:21:19 +0000487 // FIXME: can these be address-space qualified?
Douglas Gregor72c3f312008-12-05 18:15:24 +0000488 return dyn_cast<TemplateTypeParmType>(CanonicalType);
489}
Chris Lattner368eefa2008-04-07 00:27:04 +0000490
Reid Spencer5f016e22007-07-11 17:01:13 +0000491bool 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 Lattner834a72a2008-07-25 23:18:17 +0000496 // Incomplete enum types are not treated as integer types.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000497 // FIXME: In C++, enum types are never integer types.
Chris Lattner834a72a2008-07-25 23:18:17 +0000498 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000499 return true;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000500 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
501 return VT->getElementType()->isIntegerType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000502 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
503 return ASQT->getBaseType()->isIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000504 return false;
505}
506
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000507bool 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 Lattner834a72a2008-07-25 23:18:17 +0000512 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
513 return true; // Complete enum types are integral.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000514 // FIXME: In C++, enum types are never integral.
Christopher Lambebb97e92008-02-04 02:31:56 +0000515 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
516 return ASQT->getBaseType()->isIntegralType();
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000517 return false;
518}
519
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000520bool Type::isEnumeralType() const {
521 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000522 return TT->getDecl()->isEnum();
Christopher Lambebb97e92008-02-04 02:31:56 +0000523 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
524 return ASQT->getBaseType()->isEnumeralType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000525 return false;
526}
527
528bool Type::isBooleanType() const {
529 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
530 return BT->getKind() == BuiltinType::Bool;
Christopher Lambebb97e92008-02-04 02:31:56 +0000531 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
532 return ASQT->getBaseType()->isBooleanType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000533 return false;
534}
535
536bool 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 Carlssonc67ad5f2007-10-29 02:52:18 +0000540 BT->getKind() == BuiltinType::Char_S ||
541 BT->getKind() == BuiltinType::SChar;
Christopher Lambebb97e92008-02-04 02:31:56 +0000542 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
543 return ASQT->getBaseType()->isCharType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000544 return false;
545}
546
Douglas Gregor77a52232008-09-12 00:47:35 +0000547bool 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 Lattnerd5bbce42007-08-29 17:48:46 +0000555/// 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 Spencer5f016e22007-07-11 17:01:13 +0000559bool 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 Lattnerd5bbce42007-08-29 17:48:46 +0000564
Chris Lattner37c1b782008-04-06 22:29:16 +0000565 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
566 return ET->getDecl()->getIntegerType()->isSignedIntegerType();
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000567
Steve Naroffc63b96a2007-07-12 21:46:55 +0000568 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
569 return VT->getElementType()->isSignedIntegerType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000570 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
571 return ASQT->getBaseType()->isSignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000572 return false;
573}
574
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000575/// 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 Spencer5f016e22007-07-11 17:01:13 +0000579bool 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 Lattnerd5bbce42007-08-29 17:48:46 +0000584
Chris Lattner37c1b782008-04-06 22:29:16 +0000585 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
586 return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000587
Steve Naroffc63b96a2007-07-12 21:46:55 +0000588 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
589 return VT->getElementType()->isUnsignedIntegerType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000590 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
591 return ASQT->getBaseType()->isUnsignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000592 return false;
593}
594
595bool 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 Lattner729a2132007-08-30 06:19:11 +0000600 return CT->getElementType()->isFloatingType();
Steve Naroffc63b96a2007-07-12 21:46:55 +0000601 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
602 return VT->getElementType()->isFloatingType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000603 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
604 return ASQT->getBaseType()->isFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000605 return false;
606}
607
608bool Type::isRealFloatingType() const {
609 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
610 return BT->getKind() >= BuiltinType::Float &&
611 BT->getKind() <= BuiltinType::LongDouble;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000612 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
613 return VT->getElementType()->isRealFloatingType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000614 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
615 return ASQT->getBaseType()->isRealFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000616 return false;
617}
618
619bool 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 Lattner834a72a2008-07-25 23:18:17 +0000624 return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition();
Steve Naroffc63b96a2007-07-12 21:46:55 +0000625 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
626 return VT->getElementType()->isRealType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000627 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
628 return ASQT->getBaseType()->isRealType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000629 return false;
630}
631
Reid Spencer5f016e22007-07-11 17:01:13 +0000632bool Type::isArithmeticType() const {
633 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
Douglas Gregora7fbf722008-10-30 13:47:07 +0000634 return BT->getKind() >= BuiltinType::Bool &&
635 BT->getKind() <= BuiltinType::LongDouble;
Chris Lattner37c1b782008-04-06 22:29:16 +0000636 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 Lambebb97e92008-02-04 02:31:56 +0000640 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
641 return ASQT->getBaseType()->isArithmeticType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000642 return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType);
643}
644
645bool 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 Lattner834a72a2008-07-25 23:18:17 +0000649 // 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 Spencer5f016e22007-07-11 17:01:13 +0000652 return true;
653 return false;
654 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000655 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
656 return ASQT->getBaseType()->isScalarType();
Steve Naroff5618bd42008-08-27 16:04:49 +0000657 return isa<PointerType>(CanonicalType) ||
658 isa<BlockPointerType>(CanonicalType) ||
Sebastian Redlf30208a2009-01-24 21:16:55 +0000659 isa<MemberPointerType>(CanonicalType) ||
Steve Naroff5618bd42008-08-27 16:04:49 +0000660 isa<ComplexType>(CanonicalType) ||
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000661 isa<ObjCQualifiedIdType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000662}
663
Douglas Gregord7eb8462009-01-30 17:31:00 +0000664/// \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 Spencer5f016e22007-07-11 17:01:13 +0000673bool Type::isAggregateType() const {
Douglas Gregord7eb8462009-01-30 17:31:00 +0000674 if (const CXXRecordType *CXXClassType = dyn_cast<CXXRecordType>(CanonicalType))
675 return CXXClassType->getDecl()->isAggregate();
676 if (isa<RecordType>(CanonicalType))
677 return true;
Christopher Lambebb97e92008-02-04 02:31:56 +0000678 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
679 return ASQT->getBaseType()->isAggregateType();
Eli Friedmanc5773c42008-02-15 18:16:39 +0000680 return isa<ArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000681}
682
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000683/// 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 Gregor898574e2008-12-05 23:32:09 +0000685/// incomplete types or dependent types.
Eli Friedman3c2b3172008-02-15 12:20:59 +0000686bool Type::isConstantSizeType() const {
Christopher Lambebb97e92008-02-04 02:31:56 +0000687 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
Eli Friedman3c2b3172008-02-15 12:20:59 +0000688 return ASQT->getBaseType()->isConstantSizeType();
Chris Lattnerd52a4572007-12-18 07:03:30 +0000689 assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
Douglas Gregor898574e2008-12-05 23:32:09 +0000690 assert(!isDependentType() && "This doesn't make sense for dependent types");
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000691 // The VAT must have a size, as it is known to be complete.
692 return !isa<VariableArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000693}
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.
698bool Type::isIncompleteType() const {
699 switch (CanonicalType->getTypeClass()) {
700 default: return false;
Christopher Lambebb97e92008-02-04 02:31:56 +0000701 case ASQual:
702 return cast<ASQualType>(CanonicalType)->getBaseType()->isIncompleteType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000703 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 Friedmanc5773c42008-02-15 18:16:39 +0000711 case IncompleteArray:
Reid Spencer5f016e22007-07-11 17:01:13 +0000712 // An array of unknown size is an incomplete type (C99 6.2.5p22).
Eli Friedmanc5773c42008-02-15 18:16:39 +0000713 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000714 }
715}
716
Sebastian Redl64b45f72009-01-05 20:52:13 +0000717/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10)
718bool 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 Redlf30208a2009-01-24 21:16:55 +0000737 case MemberPointer:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000738 case Vector:
739 case ExtVector:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000740 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 Spencer5f016e22007-07-11 17:01:13 +0000753bool Type::isPromotableIntegerType() const {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000754 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 Spencer5f016e22007-07-11 17:01:13 +0000768}
769
770const 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 Kyrtzidis46713ef2008-08-09 17:11:33 +0000790 case WChar: return "wchar_t";
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000791 case Overload: return "<overloaded function type>";
Douglas Gregor898574e2008-12-05 23:32:09 +0000792 case Dependent: return "<dependent type>";
Reid Spencer5f016e22007-07-11 17:01:13 +0000793 }
794}
795
Reid Spencer5f016e22007-07-11 17:01:13 +0000796void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
Chris Lattner942cfd32007-07-20 18:48:28 +0000797 arg_type_iterator ArgTys,
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000798 unsigned NumArgs, bool isVariadic,
799 unsigned TypeQuals) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000800 ID.AddPointer(Result.getAsOpaquePtr());
801 for (unsigned i = 0; i != NumArgs; ++i)
802 ID.AddPointer(ArgTys[i].getAsOpaquePtr());
803 ID.AddInteger(isVariadic);
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000804 ID.AddInteger(TypeQuals);
Reid Spencer5f016e22007-07-11 17:01:13 +0000805}
806
807void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) {
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000808 Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(),
809 getTypeQuals());
Reid Spencer5f016e22007-07-11 17:01:13 +0000810}
811
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000812void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
Chris Lattner1ee07002008-04-07 06:37:47 +0000813 const ObjCInterfaceDecl *Decl,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000814 ObjCProtocolDecl **protocols,
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000815 unsigned NumProtocols) {
Chris Lattner1ee07002008-04-07 06:37:47 +0000816 ID.AddPointer(Decl);
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000817 for (unsigned i = 0; i != NumProtocols; i++)
818 ID.AddPointer(protocols[i]);
819}
820
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000821void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
Chris Lattner1ee07002008-04-07 06:37:47 +0000822 Profile(ID, getDecl(), &Protocols[0], getNumProtocols());
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000823}
824
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000825void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID,
Chris Lattner62f5f7f2008-07-26 00:46:50 +0000826 ObjCProtocolDecl **protocols,
827 unsigned NumProtocols) {
Fariborz Jahanianc5692492007-12-17 21:03:50 +0000828 for (unsigned i = 0; i != NumProtocols; i++)
829 ID.AddPointer(protocols[i]);
830}
831
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000832void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) {
Fariborz Jahanianc5692492007-12-17 21:03:50 +0000833 Profile(ID, &Protocols[0], getNumProtocols());
834}
835
Chris Lattnera2c77672007-07-16 22:05:22 +0000836/// 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///
843QualType 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 Lattnerf46699c2008-02-20 20:55:12 +0000854
855
856 /// FIXME:
857 /// FIXME: This is incorrect for ASQuals!
858 /// FIXME:
859 TypeQuals |= CurType.getCVRQualifiers();
Chris Lattnera2c77672007-07-16 22:05:22 +0000860
861 TDT = dyn_cast<TypedefType>(CurType);
862 if (TDT == 0)
863 return QualType(CurType.getTypePtr(), TypeQuals);
864 }
865}
Reid Spencer5f016e22007-07-11 17:01:13 +0000866
Douglas Gregor898574e2008-12-05 23:32:09 +0000867TypeOfExpr::TypeOfExpr(Expr *E, QualType can)
868 : Type(TypeOfExp, can, E->isTypeDependent()), TOExpr(E) {
869 assert(!isa<TypedefType>(can) && "Invalid canonical type");
870}
871
Chris Lattner2daa5df2008-04-06 22:04:54 +0000872bool RecordType::classof(const TagType *TT) {
873 return isa<RecordDecl>(TT->getDecl());
Reid Spencer5f016e22007-07-11 17:01:13 +0000874}
875
Argyrios Kyrtzidis49aa7ff2008-08-07 20:55:28 +0000876bool CXXRecordType::classof(const TagType *TT) {
877 return isa<CXXRecordDecl>(TT->getDecl());
878}
879
Chris Lattner2daa5df2008-04-06 22:04:54 +0000880bool EnumType::classof(const TagType *TT) {
881 return isa<EnumDecl>(TT->getDecl());
Chris Lattner5edb8bf2008-04-06 21:58:47 +0000882}
883
Anders Carlsson97e01792008-12-21 00:16:32 +0000884
Reid Spencer5f016e22007-07-11 17:01:13 +0000885//===----------------------------------------------------------------------===//
886// Type Printing
887//===----------------------------------------------------------------------===//
888
889void QualType::dump(const char *msg) const {
Chris Lattner39caea92007-12-06 04:20:07 +0000890 std::string R = "identifier";
Reid Spencer5f016e22007-07-11 17:01:13 +0000891 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 Lattnerc36d4052008-07-27 00:48:22 +0000897void QualType::dump() const {
898 dump("");
899}
900
901void Type::dump() const {
902 std::string S = "identifier";
903 getAsStringInternal(S);
904 fprintf(stderr, "%s\n", S.c_str());
905}
906
907
Reid Spencer5f016e22007-07-11 17:01:13 +0000908
909static 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
920void QualType::getAsStringInternal(std::string &S) const {
921 if (isNull()) {
Douglas Gregor61366e92008-12-24 00:01:03 +0000922 S += "NULL TYPE";
Reid Spencer5f016e22007-07-11 17:01:13 +0000923 return;
924 }
925
926 // Print qualifiers as appropriate.
Gabor Greif3513e132008-02-21 17:40:55 +0000927 if (unsigned Tq = getCVRQualifiers()) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000928 std::string TQS;
Gabor Greif3513e132008-02-21 17:40:55 +0000929 AppendTypeQualList(TQS, Tq);
Reid Spencer5f016e22007-07-11 17:01:13 +0000930 if (!S.empty())
931 S = TQS + ' ' + S;
932 else
933 S = TQS;
934 }
935
936 getTypePtr()->getAsStringInternal(S);
937}
938
939void 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
949void ComplexType::getAsStringInternal(std::string &S) const {
950 ElementType->getAsStringInternal(S);
951 S = "_Complex " + S;
952}
953
Christopher Lambebb97e92008-02-04 02:31:56 +0000954void ASQualType::getAsStringInternal(std::string &S) const {
955 S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S;
956 BaseType->getAsStringInternal(S);
957}
958
Reid Spencer5f016e22007-07-11 17:01:13 +0000959void 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 Lattnerbdcd6372008-04-02 17:35:06 +0000964 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +0000965 S = '(' + S + ')';
966
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000967 getPointeeType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000968}
969
Steve Naroff5618bd42008-08-27 16:04:49 +0000970void BlockPointerType::getAsStringInternal(std::string &S) const {
971 S = '^' + S;
972 PointeeType.getAsStringInternal(S);
973}
974
Reid Spencer5f016e22007-07-11 17:01:13 +0000975void 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 Lattnerbdcd6372008-04-02 17:35:06 +0000980 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +0000981 S = '(' + S + ')';
982
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000983 getPointeeType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000984}
985
Sebastian Redlf30208a2009-01-24 21:16:55 +0000986void 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 Narofffb22d962007-08-30 01:06:46 +00001000void ConstantArrayType::getAsStringInternal(std::string &S) const {
1001 S += '[';
Steve Naroff6b91cd92007-08-30 18:45:57 +00001002 S += llvm::utostr(getSize().getZExtValue());
Steve Narofffb22d962007-08-30 01:06:46 +00001003 S += ']';
1004
1005 getElementType().getAsStringInternal(S);
1006}
1007
Eli Friedmanc5773c42008-02-15 18:16:39 +00001008void IncompleteArrayType::getAsStringInternal(std::string &S) const {
1009 S += "[]";
1010
1011 getElementType().getAsStringInternal(S);
1012}
1013
Steve Narofffb22d962007-08-30 01:06:46 +00001014void VariableArrayType::getAsStringInternal(std::string &S) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001015 S += '[';
1016
Steve Naroffc9406122007-08-30 18:10:14 +00001017 if (getIndexTypeQualifier()) {
1018 AppendTypeQualList(S, getIndexTypeQualifier());
Reid Spencer5f016e22007-07-11 17:01:13 +00001019 S += ' ';
1020 }
1021
Steve Naroffc9406122007-08-30 18:10:14 +00001022 if (getSizeModifier() == Static)
Reid Spencer5f016e22007-07-11 17:01:13 +00001023 S += "static";
Steve Naroffc9406122007-08-30 18:10:14 +00001024 else if (getSizeModifier() == Star)
Reid Spencer5f016e22007-07-11 17:01:13 +00001025 S += '*';
1026
Steve Narofffb22d962007-08-30 01:06:46 +00001027 if (getSizeExpr()) {
Ted Kremeneka95d3752008-09-13 05:16:45 +00001028 std::string SStr;
1029 llvm::raw_string_ostream s(SStr);
Steve Narofffb22d962007-08-30 01:06:46 +00001030 getSizeExpr()->printPretty(s);
1031 S += s.str();
1032 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001033 S += ']';
1034
Steve Narofffb22d962007-08-30 01:06:46 +00001035 getElementType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +00001036}
1037
Douglas Gregor898574e2008-12-05 23:32:09 +00001038void 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 Spencer5f016e22007-07-11 17:01:13 +00001062void VectorType::getAsStringInternal(std::string &S) const {
Daniel Dunbar5620b502008-10-05 05:43:11 +00001063 // FIXME: We prefer to print the size directly here, but have no way
1064 // to get the size of the type.
Chris Lattner7ee261c2007-11-27 07:28:18 +00001065 S += " __attribute__((__vector_size__(";
Daniel Dunbar5620b502008-10-05 05:43:11 +00001066 S += llvm::utostr_32(NumElements); // convert back to bytes.
1067 S += " * sizeof(" + ElementType.getAsString() + "))))";
Reid Spencer5f016e22007-07-11 17:01:13 +00001068}
1069
Nate Begeman213541a2008-04-18 23:10:10 +00001070void ExtVectorType::getAsStringInternal(std::string &S) const {
1071 S += " __attribute__((ext_vector_type(";
Steve Naroff31a45842007-07-28 23:10:27 +00001072 S += llvm::utostr_32(NumElements);
1073 S += ")))";
1074 ElementType.getAsStringInternal(S);
1075}
1076
Steve Naroffd1861fd2007-07-31 12:34:36 +00001077void TypeOfExpr::getAsStringInternal(std::string &InnerString) const {
Steve Naroff363bcff2007-08-01 23:45:51 +00001078 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'.
1079 InnerString = ' ' + InnerString;
Ted Kremeneka95d3752008-09-13 05:16:45 +00001080 std::string Str;
1081 llvm::raw_string_ostream s(Str);
Chris Lattner6000dac2007-08-08 22:51:59 +00001082 getUnderlyingExpr()->printPretty(s);
Steve Naroff1bfd5cc2007-08-05 03:24:45 +00001083 InnerString = "typeof(" + s.str() + ")" + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001084}
1085
Steve Naroff363bcff2007-08-01 23:45:51 +00001086void TypeOfType::getAsStringInternal(std::string &InnerString) const {
1087 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'.
1088 InnerString = ' ' + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001089 std::string Tmp;
1090 getUnderlyingType().getAsStringInternal(Tmp);
Steve Naroff363bcff2007-08-01 23:45:51 +00001091 InnerString = "typeof(" + Tmp + ")" + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001092}
1093
Reid Spencer5f016e22007-07-11 17:01:13 +00001094void 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
1103void 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
1131void 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 Gregor72c3f312008-12-05 18:15:24 +00001137void 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 Kremeneka526c5c2008-01-07 19:49:32 +00001143void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const {
Steve Naroff3536b442007-09-06 21:24:23 +00001144 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1145 InnerString = ' ' + InnerString;
1146 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1147}
1148
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001149void ObjCQualifiedInterfaceType::getAsStringInternal(
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001150 std::string &InnerString) const {
Fariborz Jahaniandfbcce22007-10-11 18:08:47 +00001151 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1152 InnerString = ' ' + InnerString;
Chris Lattner39f34e92008-11-24 04:00:27 +00001153 std::string ObjCQIString = getDecl()->getNameAsString();
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001154 ObjCQIString += '<';
Chris Lattnercdce6d12008-07-21 05:19:23 +00001155 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 Kremeneka526c5c2008-01-07 19:49:32 +00001160 ObjCQIString += ',';
Chris Lattner39f34e92008-11-24 04:00:27 +00001161 ObjCQIString += (*I)->getNameAsString();
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001162 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001163 ObjCQIString += '>';
1164 InnerString = ObjCQIString + InnerString;
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001165}
1166
Chris Lattnere8e4f922008-07-25 23:07:18 +00001167void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const {
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001168 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1169 InnerString = ' ' + InnerString;
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001170 std::string ObjCQIString = "id";
1171 ObjCQIString += '<';
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001172 int num = getNumProtocols();
1173 for (int i = 0; i < num; i++) {
Chris Lattner39f34e92008-11-24 04:00:27 +00001174 ObjCQIString += getProtocols(i)->getNameAsString();
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001175 if (i < num-1)
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001176 ObjCQIString += ',';
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001177 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001178 ObjCQIString += '>';
1179 InnerString = ObjCQIString + InnerString;
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001180}
1181
Reid Spencer5f016e22007-07-11 17:01:13 +00001182void 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}