blob: 1fb1e999bd543cedff24c666eabf52be75cf8370 [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"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000018#include "clang/AST/DeclTemplate.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000019#include "clang/AST/Expr.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020#include "llvm/ADT/StringExtras.h"
Douglas Gregorbad35182009-03-19 03:51:16 +000021#include "llvm/Support/raw_ostream.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000022using namespace clang;
23
Chris Lattner4bbce992009-01-12 00:10:42 +000024bool QualType::isConstant(ASTContext &Ctx) const {
Nuno Lopesb381aac2008-09-01 11:33:04 +000025 if (isConstQualified())
26 return true;
27
28 if (getTypePtr()->isArrayType())
29 return Ctx.getAsArrayType(*this)->getElementType().isConstant(Ctx);
30
31 return false;
32}
33
Ted Kremenek566c2ba2009-01-19 21:31:22 +000034void Type::Destroy(ASTContext& C) {
35 this->~Type();
Steve Naroff3e970492009-01-27 21:25:57 +000036 C.Deallocate(this);
Ted Kremenek4b05b1d2008-05-21 16:38:54 +000037}
38
39void VariableArrayType::Destroy(ASTContext& C) {
40 SizeExpr->Destroy(C);
Ted Kremenek566c2ba2009-01-19 21:31:22 +000041 this->~VariableArrayType();
Steve Naroff3e970492009-01-27 21:25:57 +000042 C.Deallocate(this);
Ted Kremenek4b05b1d2008-05-21 16:38:54 +000043}
Reid Spencer5f016e22007-07-11 17:01:13 +000044
Douglas Gregor898574e2008-12-05 23:32:09 +000045void DependentSizedArrayType::Destroy(ASTContext& C) {
46 SizeExpr->Destroy(C);
Ted Kremenek566c2ba2009-01-19 21:31:22 +000047 this->~DependentSizedArrayType();
Steve Naroff3e970492009-01-27 21:25:57 +000048 C.Deallocate(this);
Douglas Gregor898574e2008-12-05 23:32:09 +000049}
Chris Lattnerc63a1f22008-08-04 07:31:14 +000050
51/// getArrayElementTypeNoTypeQual - If this is an array type, return the
52/// element type of the array, potentially with type qualifiers missing.
53/// This method should never be used when type qualifiers are meaningful.
54const Type *Type::getArrayElementTypeNoTypeQual() const {
55 // If this is directly an array type, return it.
56 if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
57 return ATy->getElementType().getTypePtr();
58
59 // If the canonical form of this type isn't the right kind, reject it.
60 if (!isa<ArrayType>(CanonicalType)) {
61 // Look through type qualifiers
62 if (ArrayType *AT = dyn_cast<ArrayType>(CanonicalType.getUnqualifiedType()))
63 return AT->getElementType().getTypePtr();
64 return 0;
65 }
66
67 // If this is a typedef for an array type, strip the typedef off without
68 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +000069 return cast<ArrayType>(getDesugaredType())->getElementType().getTypePtr();
70}
71
72/// getDesugaredType - Return the specified type with any "sugar" removed from
73/// the type. This takes off typedefs, typeof's etc. If the outer level of
74/// the type is already concrete, it returns it unmodified. This is similar
75/// to getting the canonical type, but it doesn't remove *all* typedefs. For
76/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
77/// concrete.
78QualType QualType::getDesugaredType() const {
79 return getTypePtr()->getDesugaredType()
80 .getWithAdditionalQualifiers(getCVRQualifiers());
Chris Lattnerc63a1f22008-08-04 07:31:14 +000081}
82
83/// getDesugaredType - Return the specified type with any "sugar" removed from
84/// type type. This takes off typedefs, typeof's etc. If the outer level of
85/// the type is already concrete, it returns it unmodified. This is similar
86/// to getting the canonical type, but it doesn't remove *all* typedefs. For
87/// example, it return "T*" as "T*", (not as "int*"), because the pointer is
88/// concrete.
89QualType Type::getDesugaredType() const {
90 if (const TypedefType *TDT = dyn_cast<TypedefType>(this))
Chris Lattner2fa8c252009-03-17 22:51:02 +000091 return TDT->LookThroughTypedefs().getDesugaredType();
Douglas Gregor72564e72009-02-26 23:50:07 +000092 if (const TypeOfExprType *TOE = dyn_cast<TypeOfExprType>(this))
Chris Lattner2fa8c252009-03-17 22:51:02 +000093 return TOE->getUnderlyingExpr()->getType().getDesugaredType();
Chris Lattnerc63a1f22008-08-04 07:31:14 +000094 if (const TypeOfType *TOT = dyn_cast<TypeOfType>(this))
Chris Lattner2fa8c252009-03-17 22:51:02 +000095 return TOT->getUnderlyingType().getDesugaredType();
Douglas Gregor5cdf8212009-02-12 00:15:05 +000096 if (const ClassTemplateSpecializationType *Spec
97 = dyn_cast<ClassTemplateSpecializationType>(this))
Chris Lattner2fa8c252009-03-17 22:51:02 +000098 return Spec->getCanonicalTypeInternal().getDesugaredType();
Douglas Gregore4e5b052009-03-19 00:18:19 +000099 if (const QualifiedNameType *QualName = dyn_cast<QualifiedNameType>(this))
100 return QualName->getNamedType().getDesugaredType();
Douglas Gregor5cdf8212009-02-12 00:15:05 +0000101
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000102 // FIXME: remove this cast.
103 return QualType(const_cast<Type*>(this), 0);
104}
105
Reid Spencer5f016e22007-07-11 17:01:13 +0000106/// isVoidType - Helper method to determine if this is the 'void' type.
107bool Type::isVoidType() const {
108 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
109 return BT->getKind() == BuiltinType::Void;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000110 if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType))
Chris Lattner4bbce992009-01-12 00:10:42 +0000111 return AS->getBaseType()->isVoidType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000112 return false;
113}
114
115bool Type::isObjectType() const {
Sebastian Redl00e68e22009-02-09 18:24:27 +0000116 if (isa<FunctionType>(CanonicalType) || isa<ReferenceType>(CanonicalType))
Reid Spencer5f016e22007-07-11 17:01:13 +0000117 return false;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000118 if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType))
Chris Lattner4bbce992009-01-12 00:10:42 +0000119 return AS->getBaseType()->isObjectType();
120 return !CanonicalType->isIncompleteType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000121}
122
123bool Type::isDerivedType() const {
124 switch (CanonicalType->getTypeClass()) {
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000125 case ExtQual:
126 return cast<ExtQualType>(CanonicalType)->getBaseType()->isDerivedType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000127 case Pointer:
Steve Narofffb22d962007-08-30 01:06:46 +0000128 case VariableArray:
129 case ConstantArray:
Eli Friedmanc5773c42008-02-15 18:16:39 +0000130 case IncompleteArray:
Reid Spencer5f016e22007-07-11 17:01:13 +0000131 case FunctionProto:
132 case FunctionNoProto:
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000133 case LValueReference:
134 case RValueReference:
Douglas Gregor72564e72009-02-26 23:50:07 +0000135 case Record:
Reid Spencer5f016e22007-07-11 17:01:13 +0000136 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000137 default:
138 return false;
139 }
140}
141
Chris Lattner99dc9142008-04-13 18:59:07 +0000142bool Type::isClassType() const {
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000143 if (const RecordType *RT = getAsRecordType())
144 return RT->getDecl()->isClass();
Chris Lattner99dc9142008-04-13 18:59:07 +0000145 return false;
146}
Chris Lattnerc8629632007-07-31 19:29:30 +0000147bool Type::isStructureType() const {
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000148 if (const RecordType *RT = getAsRecordType())
149 return RT->getDecl()->isStruct();
Chris Lattnerc8629632007-07-31 19:29:30 +0000150 return false;
151}
152bool Type::isUnionType() const {
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000153 if (const RecordType *RT = getAsRecordType())
154 return RT->getDecl()->isUnion();
Chris Lattnerc8629632007-07-31 19:29:30 +0000155 return false;
156}
Chris Lattnerc8629632007-07-31 19:29:30 +0000157
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000158bool Type::isComplexType() const {
Steve Naroff02f62a92008-01-15 19:36:10 +0000159 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
160 return CT->getElementType()->isFloatingType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000161 if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType))
Chris Lattner4bbce992009-01-12 00:10:42 +0000162 return AS->getBaseType()->isComplexType();
Steve Naroff02f62a92008-01-15 19:36:10 +0000163 return false;
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000164}
165
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000166bool Type::isComplexIntegerType() const {
167 // Check for GCC complex integer extension.
168 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
169 return CT->getElementType()->isIntegerType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000170 if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType))
Chris Lattner4bbce992009-01-12 00:10:42 +0000171 return AS->getBaseType()->isComplexIntegerType();
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000172 return false;
173}
174
175const ComplexType *Type::getAsComplexIntegerType() const {
176 // Are we directly a complex type?
177 if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) {
178 if (CTy->getElementType()->isIntegerType())
179 return CTy;
Chris Lattner4bbce992009-01-12 00:10:42 +0000180 return 0;
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000181 }
Chris Lattner4bbce992009-01-12 00:10:42 +0000182
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000183 // If the canonical form of this type isn't what we want, reject it.
184 if (!isa<ComplexType>(CanonicalType)) {
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000185 // Look through type qualifiers (e.g. ExtQualType's).
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000186 if (isa<ComplexType>(CanonicalType.getUnqualifiedType()))
187 return CanonicalType.getUnqualifiedType()->getAsComplexIntegerType();
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000188 return 0;
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000189 }
190
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000191 // If this is a typedef for a complex type, strip the typedef off without
192 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000193 return cast<ComplexType>(getDesugaredType());
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000194}
195
Steve Naroff77878cc2007-08-27 04:08:11 +0000196const BuiltinType *Type::getAsBuiltinType() const {
197 // If this is directly a builtin type, return it.
198 if (const BuiltinType *BTy = dyn_cast<BuiltinType>(this))
199 return BTy;
Chris Lattnerdea61462007-10-29 03:41:11 +0000200
201 // If the canonical form of this type isn't a builtin type, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000202 if (!isa<BuiltinType>(CanonicalType)) {
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000203 // Look through type qualifiers (e.g. ExtQualType's).
Christopher Lambebb97e92008-02-04 02:31:56 +0000204 if (isa<BuiltinType>(CanonicalType.getUnqualifiedType()))
205 return CanonicalType.getUnqualifiedType()->getAsBuiltinType();
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 Naroff77878cc2007-08-27 04:08:11 +0000209 // If this is a typedef for a builtin type, strip the typedef off without
210 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000211 return cast<BuiltinType>(getDesugaredType());
Steve Naroff77878cc2007-08-27 04:08:11 +0000212}
213
Chris Lattnerc8629632007-07-31 19:29:30 +0000214const FunctionType *Type::getAsFunctionType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000215 // If this is directly a function type, return it.
216 if (const FunctionType *FTy = dyn_cast<FunctionType>(this))
217 return FTy;
Christopher Lambebb97e92008-02-04 02:31:56 +0000218
Chris Lattnerdea61462007-10-29 03:41:11 +0000219 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000220 if (!isa<FunctionType>(CanonicalType)) {
221 // Look through type qualifiers
222 if (isa<FunctionType>(CanonicalType.getUnqualifiedType()))
223 return CanonicalType.getUnqualifiedType()->getAsFunctionType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000224 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000225 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000226
Steve Naroff7064f5c2007-07-26 18:32:01 +0000227 // If this is a typedef for a function type, strip the typedef off without
228 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000229 return cast<FunctionType>(getDesugaredType());
Reid Spencer5f016e22007-07-11 17:01:13 +0000230}
231
Douglas Gregor72564e72009-02-26 23:50:07 +0000232const FunctionNoProtoType *Type::getAsFunctionNoProtoType() const {
233 return dyn_cast_or_null<FunctionNoProtoType>(getAsFunctionType());
Daniel Dunbarafa74442009-02-19 07:11:26 +0000234}
235
Douglas Gregor72564e72009-02-26 23:50:07 +0000236const FunctionProtoType *Type::getAsFunctionProtoType() const {
237 return dyn_cast_or_null<FunctionProtoType>(getAsFunctionType());
Chris Lattnerb77792e2008-07-26 22:17:49 +0000238}
239
240
Chris Lattnerbefee482007-07-31 16:53:04 +0000241const PointerType *Type::getAsPointerType() const {
Chris Lattner7a2e0472007-07-16 00:23:25 +0000242 // If this is directly a pointer type, return it.
243 if (const PointerType *PTy = dyn_cast<PointerType>(this))
244 return PTy;
Chris Lattnera2c77672007-07-16 22:05:22 +0000245
Chris Lattnerdea61462007-10-29 03:41:11 +0000246 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000247 if (!isa<PointerType>(CanonicalType)) {
248 // Look through type qualifiers
249 if (isa<PointerType>(CanonicalType.getUnqualifiedType()))
250 return CanonicalType.getUnqualifiedType()->getAsPointerType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000251 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000252 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000253
Chris Lattnera2c77672007-07-16 22:05:22 +0000254 // If this is a typedef for a pointer type, strip the typedef off without
255 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000256 return cast<PointerType>(getDesugaredType());
Reid Spencer5f016e22007-07-11 17:01:13 +0000257}
258
Steve Naroff5618bd42008-08-27 16:04:49 +0000259const BlockPointerType *Type::getAsBlockPointerType() const {
260 // If this is directly a block pointer type, return it.
261 if (const BlockPointerType *PTy = dyn_cast<BlockPointerType>(this))
262 return PTy;
263
264 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000265 if (!isa<BlockPointerType>(CanonicalType)) {
266 // Look through type qualifiers
267 if (isa<BlockPointerType>(CanonicalType.getUnqualifiedType()))
268 return CanonicalType.getUnqualifiedType()->getAsBlockPointerType();
Steve Naroff5618bd42008-08-27 16:04:49 +0000269 return 0;
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000270 }
Steve Naroff5618bd42008-08-27 16:04:49 +0000271
272 // If this is a typedef for a block pointer type, strip the typedef off
273 // without losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000274 return cast<BlockPointerType>(getDesugaredType());
Steve Naroff5618bd42008-08-27 16:04:49 +0000275}
276
Chris Lattnera1d9fde2007-07-31 16:56:34 +0000277const ReferenceType *Type::getAsReferenceType() const {
Bill Wendlingea5e79f2007-07-17 04:16:47 +0000278 // If this is directly a reference type, return it.
279 if (const ReferenceType *RTy = dyn_cast<ReferenceType>(this))
280 return RTy;
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000281
Chris Lattnerdea61462007-10-29 03:41:11 +0000282 // If the canonical form of this type isn't the right kind, reject it.
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000283 if (!isa<ReferenceType>(CanonicalType)) {
Christopher Lambebb97e92008-02-04 02:31:56 +0000284 // Look through type qualifiers
285 if (isa<ReferenceType>(CanonicalType.getUnqualifiedType()))
286 return CanonicalType.getUnqualifiedType()->getAsReferenceType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000287 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000288 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000289
Bill Wendlingea5e79f2007-07-17 04:16:47 +0000290 // If this is a typedef for a reference type, strip the typedef off without
291 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000292 return cast<ReferenceType>(getDesugaredType());
Reid Spencer5f016e22007-07-11 17:01:13 +0000293}
294
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000295const LValueReferenceType *Type::getAsLValueReferenceType() const {
296 // If this is directly an lvalue reference type, return it.
297 if (const LValueReferenceType *RTy = dyn_cast<LValueReferenceType>(this))
298 return RTy;
299
300 // If the canonical form of this type isn't the right kind, reject it.
301 if (!isa<LValueReferenceType>(CanonicalType)) {
302 // Look through type qualifiers
303 if (isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()))
304 return CanonicalType.getUnqualifiedType()->getAsLValueReferenceType();
305 return 0;
306 }
307
308 // If this is a typedef for an lvalue reference type, strip the typedef off
309 // without losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000310 return cast<LValueReferenceType>(getDesugaredType());
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000311}
312
313const RValueReferenceType *Type::getAsRValueReferenceType() const {
314 // If this is directly an rvalue reference type, return it.
315 if (const RValueReferenceType *RTy = dyn_cast<RValueReferenceType>(this))
316 return RTy;
317
318 // If the canonical form of this type isn't the right kind, reject it.
319 if (!isa<RValueReferenceType>(CanonicalType)) {
320 // Look through type qualifiers
321 if (isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()))
322 return CanonicalType.getUnqualifiedType()->getAsRValueReferenceType();
323 return 0;
324 }
325
326 // If this is a typedef for an rvalue reference type, strip the typedef off
327 // without losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000328 return cast<RValueReferenceType>(getDesugaredType());
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000329}
330
Sebastian Redlf30208a2009-01-24 21:16:55 +0000331const MemberPointerType *Type::getAsMemberPointerType() const {
332 // If this is directly a member pointer type, return it.
333 if (const MemberPointerType *MTy = dyn_cast<MemberPointerType>(this))
334 return MTy;
335
336 // If the canonical form of this type isn't the right kind, reject it.
337 if (!isa<MemberPointerType>(CanonicalType)) {
338 // Look through type qualifiers
339 if (isa<MemberPointerType>(CanonicalType.getUnqualifiedType()))
340 return CanonicalType.getUnqualifiedType()->getAsMemberPointerType();
341 return 0;
342 }
343
344 // If this is a typedef for a member pointer type, strip the typedef off
345 // without losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000346 return cast<MemberPointerType>(getDesugaredType());
Sebastian Redlf30208a2009-01-24 21:16:55 +0000347}
348
Eli Friedmand3f2f792008-02-17 00:59:11 +0000349/// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length
350/// array types and types that contain variable array types in their
351/// declarator
Steve Naroffd7444aa2007-08-31 17:20:07 +0000352bool Type::isVariablyModifiedType() const {
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000353 // A VLA is a variably modified type.
354 if (isVariableArrayType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000355 return true;
356
357 // An array can contain a variably modified type
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000358 if (const Type *T = getArrayElementTypeNoTypeQual())
359 return T->isVariablyModifiedType();
Eli Friedmand3f2f792008-02-17 00:59:11 +0000360
Sebastian Redlf30208a2009-01-24 21:16:55 +0000361 // A pointer can point to a variably modified type.
362 // Also, C++ references and member pointers can point to a variably modified
363 // type, where VLAs appear as an extension to C++, and should be treated
364 // correctly.
Daniel Dunbar68694ad2009-02-26 19:54:52 +0000365 if (const PointerType *PT = getAsPointerType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000366 return PT->getPointeeType()->isVariablyModifiedType();
Daniel Dunbar68694ad2009-02-26 19:54:52 +0000367 if (const ReferenceType *RT = getAsReferenceType())
368 return RT->getPointeeType()->isVariablyModifiedType();
Sebastian Redl8edef7c2009-01-24 23:29:36 +0000369 if (const MemberPointerType *PT = getAsMemberPointerType())
370 return PT->getPointeeType()->isVariablyModifiedType();
Eli Friedmand3f2f792008-02-17 00:59:11 +0000371
372 // A function can return a variably modified type
373 // This one isn't completely obvious, but it follows from the
374 // definition in C99 6.7.5p3. Because of this rule, it's
375 // illegal to declare a function returning a variably modified type.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000376 if (const FunctionType *FT = getAsFunctionType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000377 return FT->getResultType()->isVariablyModifiedType();
378
Steve Naroffd7444aa2007-08-31 17:20:07 +0000379 return false;
380}
381
Chris Lattnerc8629632007-07-31 19:29:30 +0000382const RecordType *Type::getAsRecordType() const {
Douglas Gregorfc705b82009-02-26 22:19:44 +0000383 // If this is directly a record type, return it.
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000384 if (const RecordType *RTy = dyn_cast<RecordType>(this))
385 return RTy;
386
Chris Lattnerdea61462007-10-29 03:41:11 +0000387 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000388 if (!isa<RecordType>(CanonicalType)) {
389 // Look through type qualifiers
390 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
391 return CanonicalType.getUnqualifiedType()->getAsRecordType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000392 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000393 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000394
395 // If this is a typedef for a record type, strip the typedef off without
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000396 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000397 return cast<RecordType>(getDesugaredType());
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000398}
399
Douglas Gregorfc705b82009-02-26 22:19:44 +0000400const TagType *Type::getAsTagType() const {
401 // If this is directly a tag type, return it.
402 if (const TagType *TagTy = dyn_cast<TagType>(this))
403 return TagTy;
404
405 // If the canonical form of this type isn't the right kind, reject it.
406 if (!isa<TagType>(CanonicalType)) {
407 // Look through type qualifiers
408 if (isa<TagType>(CanonicalType.getUnqualifiedType()))
409 return CanonicalType.getUnqualifiedType()->getAsTagType();
410 return 0;
411 }
412
413 // If this is a typedef for a tag type, strip the typedef off without
414 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000415 return cast<TagType>(getDesugaredType());
Douglas Gregorfc705b82009-02-26 22:19:44 +0000416}
417
Chris Lattnerc8629632007-07-31 19:29:30 +0000418const RecordType *Type::getAsStructureType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000419 // If this is directly a structure type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000420 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000421 if (RT->getDecl()->isStruct())
Chris Lattnerc8629632007-07-31 19:29:30 +0000422 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000423 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000424
425 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000426 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000427 if (!RT->getDecl()->isStruct())
Chris Lattnerdea61462007-10-29 03:41:11 +0000428 return 0;
429
430 // If this is a typedef for a structure type, strip the typedef off without
431 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000432 return cast<RecordType>(getDesugaredType());
Reid Spencer5f016e22007-07-11 17:01:13 +0000433 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000434 // Look through type qualifiers
435 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
436 return CanonicalType.getUnqualifiedType()->getAsStructureType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000437 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000438}
439
Chris Lattnerc8629632007-07-31 19:29:30 +0000440const RecordType *Type::getAsUnionType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000441 // If this is directly a union type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000442 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000443 if (RT->getDecl()->isUnion())
Chris Lattnerc8629632007-07-31 19:29:30 +0000444 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000445 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000446
Chris Lattnerdea61462007-10-29 03:41:11 +0000447 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000448 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000449 if (!RT->getDecl()->isUnion())
Chris Lattnerdea61462007-10-29 03:41:11 +0000450 return 0;
451
452 // If this is a typedef for a union type, strip the typedef off without
453 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000454 return cast<RecordType>(getDesugaredType());
Reid Spencer5f016e22007-07-11 17:01:13 +0000455 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000456
457 // Look through type qualifiers
458 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
459 return CanonicalType.getUnqualifiedType()->getAsUnionType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000460 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000461}
462
Eli Friedmanad74a752008-06-28 06:23:08 +0000463const EnumType *Type::getAsEnumType() const {
464 // Check the canonicalized unqualified type directly; the more complex
465 // version is unnecessary because there isn't any typedef information
466 // to preserve.
467 return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType());
468}
469
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000470const ComplexType *Type::getAsComplexType() const {
471 // Are we directly a complex type?
472 if (const ComplexType *CTy = dyn_cast<ComplexType>(this))
473 return CTy;
474
Chris Lattnerdea61462007-10-29 03:41:11 +0000475 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000476 if (!isa<ComplexType>(CanonicalType)) {
477 // Look through type qualifiers
478 if (isa<ComplexType>(CanonicalType.getUnqualifiedType()))
479 return CanonicalType.getUnqualifiedType()->getAsComplexType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000480 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000481 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000482
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000483 // If this is a typedef for a complex type, strip the typedef off without
484 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000485 return cast<ComplexType>(getDesugaredType());
Chris Lattner7a2e0472007-07-16 00:23:25 +0000486}
487
Chris Lattnerc8629632007-07-31 19:29:30 +0000488const VectorType *Type::getAsVectorType() const {
Chris Lattner7a2e0472007-07-16 00:23:25 +0000489 // Are we directly a vector type?
490 if (const VectorType *VTy = dyn_cast<VectorType>(this))
491 return VTy;
Chris Lattnera2c77672007-07-16 22:05:22 +0000492
Chris Lattnerdea61462007-10-29 03:41:11 +0000493 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000494 if (!isa<VectorType>(CanonicalType)) {
495 // Look through type qualifiers
496 if (isa<VectorType>(CanonicalType.getUnqualifiedType()))
497 return CanonicalType.getUnqualifiedType()->getAsVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000498 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000499 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000500
Chris Lattnera2c77672007-07-16 22:05:22 +0000501 // If this is a typedef for a vector type, strip the typedef off without
502 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000503 return cast<VectorType>(getDesugaredType());
Chris Lattner7a2e0472007-07-16 00:23:25 +0000504}
505
Nate Begeman213541a2008-04-18 23:10:10 +0000506const ExtVectorType *Type::getAsExtVectorType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000507 // Are we directly an OpenCU vector type?
Nate Begeman213541a2008-04-18 23:10:10 +0000508 if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this))
Steve Naroff7064f5c2007-07-26 18:32:01 +0000509 return VTy;
510
Chris Lattnerdea61462007-10-29 03:41:11 +0000511 // If the canonical form of this type isn't the right kind, reject it.
Nate Begeman213541a2008-04-18 23:10:10 +0000512 if (!isa<ExtVectorType>(CanonicalType)) {
Christopher Lambebb97e92008-02-04 02:31:56 +0000513 // Look through type qualifiers
Nate Begeman213541a2008-04-18 23:10:10 +0000514 if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType()))
515 return CanonicalType.getUnqualifiedType()->getAsExtVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000516 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000517 }
Steve Naroff7064f5c2007-07-26 18:32:01 +0000518
Nate Begeman213541a2008-04-18 23:10:10 +0000519 // If this is a typedef for an extended vector type, strip the typedef off
520 // without losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000521 return cast<ExtVectorType>(getDesugaredType());
Steve Naroff7064f5c2007-07-26 18:32:01 +0000522}
523
Chris Lattner368eefa2008-04-07 00:27:04 +0000524const ObjCInterfaceType *Type::getAsObjCInterfaceType() const {
Chris Lattnereca7be62008-04-07 05:30:13 +0000525 // There is no sugar for ObjCInterfaceType's, just return the canonical
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000526 // type pointer if it is the right class. There is no typedef information to
527 // return and these cannot be Address-space qualified.
Fariborz Jahanianfb41ca82009-02-26 23:05:51 +0000528 return dyn_cast<ObjCInterfaceType>(CanonicalType.getUnqualifiedType());
Chris Lattner368eefa2008-04-07 00:27:04 +0000529}
530
531const ObjCQualifiedInterfaceType *
532Type::getAsObjCQualifiedInterfaceType() const {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000533 // There is no sugar for ObjCQualifiedInterfaceType's, just return the
534 // canonical type pointer if it is the right class.
Fariborz Jahanianfb41ca82009-02-26 23:05:51 +0000535 return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType());
Chris Lattnereca7be62008-04-07 05:30:13 +0000536}
537
538const ObjCQualifiedIdType *Type::getAsObjCQualifiedIdType() const {
539 // There is no sugar for ObjCQualifiedIdType's, just return the canonical
540 // type pointer if it is the right class.
Fariborz Jahanianfb41ca82009-02-26 23:05:51 +0000541 return dyn_cast<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType());
Chris Lattner368eefa2008-04-07 00:27:04 +0000542}
543
Douglas Gregor72c3f312008-12-05 18:15:24 +0000544const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const {
545 // There is no sugar for template type parameters, so just return
546 // the canonical type pointer if it is the right class.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000547 // FIXME: can these be address-space qualified?
Douglas Gregor72c3f312008-12-05 18:15:24 +0000548 return dyn_cast<TemplateTypeParmType>(CanonicalType);
549}
Chris Lattner368eefa2008-04-07 00:27:04 +0000550
Douglas Gregor55f6b142009-02-09 18:46:07 +0000551const ClassTemplateSpecializationType *
Douglas Gregorbad35182009-03-19 03:51:16 +0000552Type::getAsClassTemplateSpecializationType() const {
Douglas Gregor55f6b142009-02-09 18:46:07 +0000553 // There is no sugar for class template specialization types, so
554 // just return the canonical type pointer if it is the right class.
555 return dyn_cast<ClassTemplateSpecializationType>(CanonicalType);
556}
557
Reid Spencer5f016e22007-07-11 17:01:13 +0000558bool Type::isIntegerType() const {
559 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
560 return BT->getKind() >= BuiltinType::Bool &&
561 BT->getKind() <= BuiltinType::LongLong;
562 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000563 // Incomplete enum types are not treated as integer types.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000564 // FIXME: In C++, enum types are never integer types.
Chris Lattner834a72a2008-07-25 23:18:17 +0000565 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000566 return true;
Eli Friedmanf98aba32009-02-13 02:31:07 +0000567 if (isa<FixedWidthIntType>(CanonicalType))
568 return true;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000569 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
570 return VT->getElementType()->isIntegerType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000571 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
572 return EXTQT->getBaseType()->isIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000573 return false;
574}
575
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000576bool Type::isIntegralType() const {
577 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
578 return BT->getKind() >= BuiltinType::Bool &&
579 BT->getKind() <= BuiltinType::LongLong;
580 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000581 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
582 return true; // Complete enum types are integral.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000583 // FIXME: In C++, enum types are never integral.
Eli Friedmanf98aba32009-02-13 02:31:07 +0000584 if (isa<FixedWidthIntType>(CanonicalType))
585 return true;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000586 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
587 return EXTQT->getBaseType()->isIntegralType();
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000588 return false;
589}
590
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000591bool Type::isEnumeralType() const {
592 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000593 return TT->getDecl()->isEnum();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000594 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
595 return EXTQT->getBaseType()->isEnumeralType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000596 return false;
597}
598
599bool Type::isBooleanType() const {
600 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
601 return BT->getKind() == BuiltinType::Bool;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000602 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
603 return EXTQT->getBaseType()->isBooleanType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000604 return false;
605}
606
607bool Type::isCharType() const {
608 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
609 return BT->getKind() == BuiltinType::Char_U ||
610 BT->getKind() == BuiltinType::UChar ||
Anders Carlssonc67ad5f2007-10-29 02:52:18 +0000611 BT->getKind() == BuiltinType::Char_S ||
612 BT->getKind() == BuiltinType::SChar;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000613 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
614 return EXTQT->getBaseType()->isCharType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000615 return false;
616}
617
Douglas Gregor77a52232008-09-12 00:47:35 +0000618bool Type::isWideCharType() const {
619 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
620 return BT->getKind() == BuiltinType::WChar;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000621 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
622 return EXTQT->getBaseType()->isWideCharType();
Douglas Gregor77a52232008-09-12 00:47:35 +0000623 return false;
624}
625
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000626/// isSignedIntegerType - Return true if this is an integer type that is
627/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
628/// an enum decl which has a signed representation, or a vector of signed
629/// integer element type.
Reid Spencer5f016e22007-07-11 17:01:13 +0000630bool Type::isSignedIntegerType() const {
631 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
632 return BT->getKind() >= BuiltinType::Char_S &&
633 BT->getKind() <= BuiltinType::LongLong;
634 }
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000635
Chris Lattner37c1b782008-04-06 22:29:16 +0000636 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
637 return ET->getDecl()->getIntegerType()->isSignedIntegerType();
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000638
Eli Friedmanf98aba32009-02-13 02:31:07 +0000639 if (const FixedWidthIntType *FWIT =
640 dyn_cast<FixedWidthIntType>(CanonicalType))
641 return FWIT->isSigned();
642
Steve Naroffc63b96a2007-07-12 21:46:55 +0000643 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
644 return VT->getElementType()->isSignedIntegerType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000645 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
646 return EXTQT->getBaseType()->isSignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000647 return false;
648}
649
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000650/// isUnsignedIntegerType - Return true if this is an integer type that is
651/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
652/// decl which has an unsigned representation, or a vector of unsigned integer
653/// element type.
Reid Spencer5f016e22007-07-11 17:01:13 +0000654bool Type::isUnsignedIntegerType() const {
655 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
656 return BT->getKind() >= BuiltinType::Bool &&
657 BT->getKind() <= BuiltinType::ULongLong;
658 }
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000659
Chris Lattner37c1b782008-04-06 22:29:16 +0000660 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
661 return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000662
Eli Friedmanf98aba32009-02-13 02:31:07 +0000663 if (const FixedWidthIntType *FWIT =
664 dyn_cast<FixedWidthIntType>(CanonicalType))
665 return !FWIT->isSigned();
666
Steve Naroffc63b96a2007-07-12 21:46:55 +0000667 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
668 return VT->getElementType()->isUnsignedIntegerType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000669 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
670 return EXTQT->getBaseType()->isUnsignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000671 return false;
672}
673
674bool Type::isFloatingType() const {
675 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
676 return BT->getKind() >= BuiltinType::Float &&
677 BT->getKind() <= BuiltinType::LongDouble;
678 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
Chris Lattner729a2132007-08-30 06:19:11 +0000679 return CT->getElementType()->isFloatingType();
Steve Naroffc63b96a2007-07-12 21:46:55 +0000680 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
681 return VT->getElementType()->isFloatingType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000682 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
683 return EXTQT->getBaseType()->isFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000684 return false;
685}
686
687bool Type::isRealFloatingType() const {
688 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
689 return BT->getKind() >= BuiltinType::Float &&
690 BT->getKind() <= BuiltinType::LongDouble;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000691 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
692 return VT->getElementType()->isRealFloatingType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000693 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
694 return EXTQT->getBaseType()->isRealFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000695 return false;
696}
697
698bool Type::isRealType() const {
699 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
700 return BT->getKind() >= BuiltinType::Bool &&
701 BT->getKind() <= BuiltinType::LongDouble;
702 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000703 return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition();
Eli Friedmanf98aba32009-02-13 02:31:07 +0000704 if (isa<FixedWidthIntType>(CanonicalType))
705 return true;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000706 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
707 return VT->getElementType()->isRealType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000708 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
709 return EXTQT->getBaseType()->isRealType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000710 return false;
711}
712
Reid Spencer5f016e22007-07-11 17:01:13 +0000713bool Type::isArithmeticType() const {
714 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
Douglas Gregora7fbf722008-10-30 13:47:07 +0000715 return BT->getKind() >= BuiltinType::Bool &&
716 BT->getKind() <= BuiltinType::LongDouble;
Chris Lattner37c1b782008-04-06 22:29:16 +0000717 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
718 // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
719 // If a body isn't seen by the time we get here, return false.
720 return ET->getDecl()->isDefinition();
Eli Friedmanf98aba32009-02-13 02:31:07 +0000721 if (isa<FixedWidthIntType>(CanonicalType))
722 return true;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000723 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
724 return EXTQT->getBaseType()->isArithmeticType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000725 return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType);
726}
727
728bool Type::isScalarType() const {
729 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
730 return BT->getKind() != BuiltinType::Void;
731 if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
Chris Lattner834a72a2008-07-25 23:18:17 +0000732 // Enums are scalar types, but only if they are defined. Incomplete enums
733 // are not treated as scalar types.
734 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000735 return true;
736 return false;
737 }
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000738 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
739 return EXTQT->getBaseType()->isScalarType();
Eli Friedmanf98aba32009-02-13 02:31:07 +0000740 if (isa<FixedWidthIntType>(CanonicalType))
741 return true;
Steve Naroff5618bd42008-08-27 16:04:49 +0000742 return isa<PointerType>(CanonicalType) ||
743 isa<BlockPointerType>(CanonicalType) ||
Sebastian Redlf30208a2009-01-24 21:16:55 +0000744 isa<MemberPointerType>(CanonicalType) ||
Steve Naroff5618bd42008-08-27 16:04:49 +0000745 isa<ComplexType>(CanonicalType) ||
Steve Narofff7f52e72009-02-21 21:17:01 +0000746 isa<ObjCQualifiedIdType>(CanonicalType) ||
747 isa<ObjCQualifiedClassType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000748}
749
Douglas Gregord7eb8462009-01-30 17:31:00 +0000750/// \brief Determines whether the type is a C++ aggregate type or C
751/// aggregate or union type.
752///
753/// An aggregate type is an array or a class type (struct, union, or
754/// class) that has no user-declared constructors, no private or
755/// protected non-static data members, no base classes, and no virtual
756/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
757/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
758/// includes union types.
Reid Spencer5f016e22007-07-11 17:01:13 +0000759bool Type::isAggregateType() const {
Douglas Gregorc1efaec2009-02-28 01:32:25 +0000760 if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) {
761 if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
762 return ClassDecl->isAggregate();
763
Douglas Gregord7eb8462009-01-30 17:31:00 +0000764 return true;
Douglas Gregorc1efaec2009-02-28 01:32:25 +0000765 }
766
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000767 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
768 return EXTQT->getBaseType()->isAggregateType();
Eli Friedmanc5773c42008-02-15 18:16:39 +0000769 return isa<ArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000770}
771
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000772/// isConstantSizeType - Return true if this is not a variable sized type,
773/// according to the rules of C99 6.7.5p3. It is not legal to call this on
Douglas Gregor898574e2008-12-05 23:32:09 +0000774/// incomplete types or dependent types.
Eli Friedman3c2b3172008-02-15 12:20:59 +0000775bool Type::isConstantSizeType() const {
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000776 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
777 return EXTQT->getBaseType()->isConstantSizeType();
Chris Lattnerd52a4572007-12-18 07:03:30 +0000778 assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
Douglas Gregor898574e2008-12-05 23:32:09 +0000779 assert(!isDependentType() && "This doesn't make sense for dependent types");
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000780 // The VAT must have a size, as it is known to be complete.
781 return !isa<VariableArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000782}
783
784/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
785/// - a type that can describe objects, but which lacks information needed to
786/// determine its size.
787bool Type::isIncompleteType() const {
788 switch (CanonicalType->getTypeClass()) {
789 default: return false;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000790 case ExtQual:
791 return cast<ExtQualType>(CanonicalType)->getBaseType()->isIncompleteType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000792 case Builtin:
793 // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
794 // be completed.
795 return isVoidType();
Douglas Gregor72564e72009-02-26 23:50:07 +0000796 case Record:
Douglas Gregor72564e72009-02-26 23:50:07 +0000797 case Enum:
Reid Spencer5f016e22007-07-11 17:01:13 +0000798 // A tagged type (struct/union/enum/class) is incomplete if the decl is a
799 // forward declaration, but not a full definition (C99 6.2.5p22).
800 return !cast<TagType>(CanonicalType)->getDecl()->isDefinition();
Eli Friedmanc5773c42008-02-15 18:16:39 +0000801 case IncompleteArray:
Reid Spencer5f016e22007-07-11 17:01:13 +0000802 // An array of unknown size is an incomplete type (C99 6.2.5p22).
Eli Friedmanc5773c42008-02-15 18:16:39 +0000803 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000804 }
805}
806
Sebastian Redl64b45f72009-01-05 20:52:13 +0000807/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10)
808bool Type::isPODType() const {
809 // The compiler shouldn't query this for incomplete types, but the user might.
810 // We return false for that case.
811 if (isIncompleteType())
812 return false;
813
814 switch (CanonicalType->getTypeClass()) {
815 // Everything not explicitly mentioned is not POD.
816 default: return false;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000817 case ExtQual:
818 return cast<ExtQualType>(CanonicalType)->getBaseType()->isPODType();
Sebastian Redl64b45f72009-01-05 20:52:13 +0000819 case VariableArray:
820 case ConstantArray:
821 // IncompleteArray is caught by isIncompleteType() above.
822 return cast<ArrayType>(CanonicalType)->getElementType()->isPODType();
823
824 case Builtin:
825 case Complex:
826 case Pointer:
Sebastian Redlf30208a2009-01-24 21:16:55 +0000827 case MemberPointer:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000828 case Vector:
829 case ExtVector:
Anders Carlsson672c91d2009-02-09 21:53:01 +0000830 case ObjCQualifiedId:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000831 return true;
832
Douglas Gregor72564e72009-02-26 23:50:07 +0000833 case Enum:
834 return true;
835
836 case Record:
Douglas Gregorc1efaec2009-02-28 01:32:25 +0000837 if (CXXRecordDecl *ClassDecl
838 = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
839 return ClassDecl->isPOD();
840
Sebastian Redl64b45f72009-01-05 20:52:13 +0000841 // C struct/union is POD.
842 return true;
843 }
844}
845
Reid Spencer5f016e22007-07-11 17:01:13 +0000846bool Type::isPromotableIntegerType() const {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000847 if (const BuiltinType *BT = getAsBuiltinType())
848 switch (BT->getKind()) {
849 case BuiltinType::Bool:
850 case BuiltinType::Char_S:
851 case BuiltinType::Char_U:
852 case BuiltinType::SChar:
853 case BuiltinType::UChar:
854 case BuiltinType::Short:
855 case BuiltinType::UShort:
856 return true;
857 default:
858 return false;
859 }
860 return false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000861}
862
863const char *BuiltinType::getName() const {
864 switch (getKind()) {
865 default: assert(0 && "Unknown builtin type!");
866 case Void: return "void";
867 case Bool: return "_Bool";
868 case Char_S: return "char";
869 case Char_U: return "char";
870 case SChar: return "signed char";
871 case Short: return "short";
872 case Int: return "int";
873 case Long: return "long";
874 case LongLong: return "long long";
875 case UChar: return "unsigned char";
876 case UShort: return "unsigned short";
877 case UInt: return "unsigned int";
878 case ULong: return "unsigned long";
879 case ULongLong: return "unsigned long long";
880 case Float: return "float";
881 case Double: return "double";
882 case LongDouble: return "long double";
Argyrios Kyrtzidis46713ef2008-08-09 17:11:33 +0000883 case WChar: return "wchar_t";
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000884 case Overload: return "<overloaded function type>";
Douglas Gregor898574e2008-12-05 23:32:09 +0000885 case Dependent: return "<dependent type>";
Reid Spencer5f016e22007-07-11 17:01:13 +0000886 }
887}
888
Douglas Gregor72564e72009-02-26 23:50:07 +0000889void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
Chris Lattner942cfd32007-07-20 18:48:28 +0000890 arg_type_iterator ArgTys,
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000891 unsigned NumArgs, bool isVariadic,
892 unsigned TypeQuals) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000893 ID.AddPointer(Result.getAsOpaquePtr());
894 for (unsigned i = 0; i != NumArgs; ++i)
895 ID.AddPointer(ArgTys[i].getAsOpaquePtr());
896 ID.AddInteger(isVariadic);
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000897 ID.AddInteger(TypeQuals);
Reid Spencer5f016e22007-07-11 17:01:13 +0000898}
899
Douglas Gregor72564e72009-02-26 23:50:07 +0000900void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) {
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000901 Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(),
902 getTypeQuals());
Reid Spencer5f016e22007-07-11 17:01:13 +0000903}
904
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000905void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
Chris Lattner1ee07002008-04-07 06:37:47 +0000906 const ObjCInterfaceDecl *Decl,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000907 ObjCProtocolDecl **protocols,
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000908 unsigned NumProtocols) {
Chris Lattner1ee07002008-04-07 06:37:47 +0000909 ID.AddPointer(Decl);
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000910 for (unsigned i = 0; i != NumProtocols; i++)
911 ID.AddPointer(protocols[i]);
912}
913
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000914void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
Chris Lattner1ee07002008-04-07 06:37:47 +0000915 Profile(ID, getDecl(), &Protocols[0], getNumProtocols());
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000916}
917
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000918void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID,
Chris Lattner62f5f7f2008-07-26 00:46:50 +0000919 ObjCProtocolDecl **protocols,
920 unsigned NumProtocols) {
Fariborz Jahanianc5692492007-12-17 21:03:50 +0000921 for (unsigned i = 0; i != NumProtocols; i++)
922 ID.AddPointer(protocols[i]);
923}
924
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000925void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) {
Fariborz Jahanianc5692492007-12-17 21:03:50 +0000926 Profile(ID, &Protocols[0], getNumProtocols());
927}
928
Chris Lattnera2c77672007-07-16 22:05:22 +0000929/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
930/// potentially looking through *all* consequtive typedefs. This returns the
931/// sum of the type qualifiers, so if you have:
932/// typedef const int A;
933/// typedef volatile A B;
934/// looking through the typedefs for B will give you "const volatile A".
935///
936QualType TypedefType::LookThroughTypedefs() const {
937 // Usually, there is only a single level of typedefs, be fast in that case.
938 QualType FirstType = getDecl()->getUnderlyingType();
939 if (!isa<TypedefType>(FirstType))
940 return FirstType;
941
942 // Otherwise, do the fully general loop.
943 unsigned TypeQuals = 0;
944 const TypedefType *TDT = this;
945 while (1) {
946 QualType CurType = TDT->getDecl()->getUnderlyingType();
Chris Lattnerf46699c2008-02-20 20:55:12 +0000947
948
949 /// FIXME:
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000950 /// FIXME: This is incorrect for ExtQuals!
Chris Lattnerf46699c2008-02-20 20:55:12 +0000951 /// FIXME:
952 TypeQuals |= CurType.getCVRQualifiers();
Chris Lattnera2c77672007-07-16 22:05:22 +0000953
954 TDT = dyn_cast<TypedefType>(CurType);
955 if (TDT == 0)
956 return QualType(CurType.getTypePtr(), TypeQuals);
957 }
958}
Reid Spencer5f016e22007-07-11 17:01:13 +0000959
Douglas Gregor72564e72009-02-26 23:50:07 +0000960TypeOfExprType::TypeOfExprType(Expr *E, QualType can)
961 : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) {
Douglas Gregor898574e2008-12-05 23:32:09 +0000962 assert(!isa<TypedefType>(can) && "Invalid canonical type");
963}
964
Chris Lattner2daa5df2008-04-06 22:04:54 +0000965bool RecordType::classof(const TagType *TT) {
966 return isa<RecordDecl>(TT->getDecl());
Reid Spencer5f016e22007-07-11 17:01:13 +0000967}
968
Chris Lattner2daa5df2008-04-06 22:04:54 +0000969bool EnumType::classof(const TagType *TT) {
970 return isa<EnumDecl>(TT->getDecl());
Chris Lattner5edb8bf2008-04-06 21:58:47 +0000971}
972
Douglas Gregor40808ce2009-03-09 23:48:35 +0000973bool
Douglas Gregor55f6b142009-02-09 18:46:07 +0000974ClassTemplateSpecializationType::
Douglas Gregor40808ce2009-03-09 23:48:35 +0000975anyDependentTemplateArguments(const TemplateArgument *Args, unsigned NumArgs) {
976 for (unsigned Idx = 0; Idx < NumArgs; ++Idx) {
977 switch (Args[Idx].getKind()) {
978 case TemplateArgument::Type:
979 if (Args[Idx].getAsType()->isDependentType())
980 return true;
981 break;
982
983 case TemplateArgument::Declaration:
984 case TemplateArgument::Integral:
985 // Never dependent
986 break;
Douglas Gregor55f6b142009-02-09 18:46:07 +0000987
Douglas Gregor40808ce2009-03-09 23:48:35 +0000988 case TemplateArgument::Expression:
989 if (Args[Idx].getAsExpr()->isTypeDependent() ||
990 Args[Idx].getAsExpr()->isValueDependent())
991 return true;
992 break;
Douglas Gregor55f6b142009-02-09 18:46:07 +0000993 }
Douglas Gregor55f6b142009-02-09 18:46:07 +0000994 }
Douglas Gregor40808ce2009-03-09 23:48:35 +0000995
996 return false;
Douglas Gregor55f6b142009-02-09 18:46:07 +0000997}
998
999ClassTemplateSpecializationType::
Douglas Gregor40808ce2009-03-09 23:48:35 +00001000ClassTemplateSpecializationType(TemplateDecl *T, const TemplateArgument *Args,
1001 unsigned NumArgs, QualType Canon)
1002 : Type(ClassTemplateSpecialization,
1003 Canon.isNull()? QualType(this, 0) : Canon,
1004 /*FIXME: Check for dependent template */
1005 anyDependentTemplateArguments(Args, NumArgs)),
1006 Template(T), NumArgs(NumArgs)
Douglas Gregor55f6b142009-02-09 18:46:07 +00001007{
Douglas Gregor40808ce2009-03-09 23:48:35 +00001008 assert((!Canon.isNull() ||
1009 anyDependentTemplateArguments(Args, NumArgs)) &&
1010 "No canonical type for non-dependent class template specialization");
Douglas Gregor55f6b142009-02-09 18:46:07 +00001011
Douglas Gregor40808ce2009-03-09 23:48:35 +00001012 TemplateArgument *TemplateArgs
1013 = reinterpret_cast<TemplateArgument *>(this + 1);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001014 for (unsigned Arg = 0; Arg < NumArgs; ++Arg)
Douglas Gregor40808ce2009-03-09 23:48:35 +00001015 new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001016}
1017
Douglas Gregor5908e9f2009-02-09 19:34:22 +00001018void ClassTemplateSpecializationType::Destroy(ASTContext& C) {
Douglas Gregorba498172009-03-13 21:01:28 +00001019 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1020 // FIXME: Not all expressions get cloned, so we can't yet perform
1021 // this destruction.
1022 // if (Expr *E = getArg(Arg).getAsExpr())
1023 // E->Destroy(C);
1024 }
Douglas Gregor5908e9f2009-02-09 19:34:22 +00001025}
1026
Douglas Gregor40808ce2009-03-09 23:48:35 +00001027ClassTemplateSpecializationType::iterator
1028ClassTemplateSpecializationType::end() const {
1029 return begin() + getNumArgs();
Douglas Gregor55f6b142009-02-09 18:46:07 +00001030}
1031
Douglas Gregor40808ce2009-03-09 23:48:35 +00001032const TemplateArgument &
1033ClassTemplateSpecializationType::getArg(unsigned Idx) const {
1034 assert(Idx < getNumArgs() && "Template argument out of range");
1035 return getArgs()[Idx];
1036}
1037
1038void
1039ClassTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
1040 TemplateDecl *T,
1041 const TemplateArgument *Args,
1042 unsigned NumArgs) {
1043 ID.AddPointer(T);
1044
1045 for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
1046 Args[Idx].Profile(ID);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001047}
Anders Carlsson97e01792008-12-21 00:16:32 +00001048
Douglas Gregore4e5b052009-03-19 00:18:19 +00001049QualifiedNameType::QualifiedNameType(const NestedNameSpecifier *Components,
1050 unsigned NumComponents,
1051 QualType NamedType,
1052 QualType CanonType)
1053 : Type(QualifiedName, CanonType, NamedType->isDependentType()),
1054 NumComponents(NumComponents), NamedType(NamedType) {
1055 NestedNameSpecifier *InitComponents
1056 = reinterpret_cast<NestedNameSpecifier *>(this + 1);
1057 for (unsigned I = 0; I < NumComponents; ++I)
1058 new (InitComponents + I) NestedNameSpecifier(Components[I]);
1059}
1060
1061void QualifiedNameType::Profile(llvm::FoldingSetNodeID &ID,
1062 const NestedNameSpecifier *Components,
1063 unsigned NumComponents,
1064 QualType NamedType) {
1065 ID.AddInteger(NumComponents);
1066 for (unsigned I = 0; I < NumComponents; ++I)
1067 ID.AddPointer(Components[I].getAsOpaquePtr());
1068 NamedType.Profile(ID);
1069}
1070
Reid Spencer5f016e22007-07-11 17:01:13 +00001071//===----------------------------------------------------------------------===//
1072// Type Printing
1073//===----------------------------------------------------------------------===//
1074
1075void QualType::dump(const char *msg) const {
Chris Lattner39caea92007-12-06 04:20:07 +00001076 std::string R = "identifier";
Reid Spencer5f016e22007-07-11 17:01:13 +00001077 getAsStringInternal(R);
1078 if (msg)
1079 fprintf(stderr, "%s: %s\n", msg, R.c_str());
1080 else
1081 fprintf(stderr, "%s\n", R.c_str());
1082}
Chris Lattnerc36d4052008-07-27 00:48:22 +00001083void QualType::dump() const {
1084 dump("");
1085}
1086
1087void Type::dump() const {
1088 std::string S = "identifier";
1089 getAsStringInternal(S);
1090 fprintf(stderr, "%s\n", S.c_str());
1091}
1092
1093
Reid Spencer5f016e22007-07-11 17:01:13 +00001094
1095static void AppendTypeQualList(std::string &S, unsigned TypeQuals) {
1096 // Note: funkiness to ensure we get a space only between quals.
1097 bool NonePrinted = true;
1098 if (TypeQuals & QualType::Const)
1099 S += "const", NonePrinted = false;
1100 if (TypeQuals & QualType::Volatile)
1101 S += (NonePrinted+" volatile"), NonePrinted = false;
1102 if (TypeQuals & QualType::Restrict)
1103 S += (NonePrinted+" restrict"), NonePrinted = false;
1104}
1105
1106void QualType::getAsStringInternal(std::string &S) const {
1107 if (isNull()) {
Douglas Gregor61366e92008-12-24 00:01:03 +00001108 S += "NULL TYPE";
Reid Spencer5f016e22007-07-11 17:01:13 +00001109 return;
1110 }
1111
1112 // Print qualifiers as appropriate.
Gabor Greif3513e132008-02-21 17:40:55 +00001113 if (unsigned Tq = getCVRQualifiers()) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001114 std::string TQS;
Gabor Greif3513e132008-02-21 17:40:55 +00001115 AppendTypeQualList(TQS, Tq);
Reid Spencer5f016e22007-07-11 17:01:13 +00001116 if (!S.empty())
1117 S = TQS + ' ' + S;
1118 else
1119 S = TQS;
1120 }
1121
1122 getTypePtr()->getAsStringInternal(S);
1123}
1124
1125void BuiltinType::getAsStringInternal(std::string &S) const {
1126 if (S.empty()) {
1127 S = getName();
1128 } else {
1129 // Prefix the basic type, e.g. 'int X'.
1130 S = ' ' + S;
1131 S = getName() + S;
1132 }
1133}
1134
Eli Friedmanf98aba32009-02-13 02:31:07 +00001135void FixedWidthIntType::getAsStringInternal(std::string &S) const {
1136 // FIXME: Once we get bitwidth attribute, write as
1137 // "int __attribute__((bitwidth(x)))".
1138 std::string prefix = "__clang_fixedwidth";
1139 prefix += llvm::utostr_32(Width);
1140 prefix += (char)(Signed ? 'S' : 'U');
1141 if (S.empty()) {
1142 S = prefix;
1143 } else {
1144 // Prefix the basic type, e.g. 'int X'.
1145 S = prefix + S;
1146 }
1147}
1148
1149
Reid Spencer5f016e22007-07-11 17:01:13 +00001150void ComplexType::getAsStringInternal(std::string &S) const {
1151 ElementType->getAsStringInternal(S);
1152 S = "_Complex " + S;
1153}
1154
Fariborz Jahanianf11284a2009-02-17 18:27:45 +00001155void ExtQualType::getAsStringInternal(std::string &S) const {
Chris Lattner3b6b83b2009-02-18 22:58:38 +00001156 bool NeedsSpace = false;
Fariborz Jahanian4886a422009-02-17 21:45:36 +00001157 if (AddressSpace) {
Fariborz Jahanian59d16d12009-02-17 20:16:45 +00001158 S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S;
Chris Lattner3b6b83b2009-02-18 22:58:38 +00001159 NeedsSpace = true;
Fariborz Jahanian59d16d12009-02-17 20:16:45 +00001160 }
Fariborz Jahaniand33d9c02009-02-18 05:09:49 +00001161 if (GCAttrType != QualType::GCNone) {
Chris Lattner3b6b83b2009-02-18 22:58:38 +00001162 if (NeedsSpace)
Fariborz Jahanian59d16d12009-02-17 20:16:45 +00001163 S += ' ';
1164 S += "__attribute__((objc_gc(";
Fariborz Jahaniand33d9c02009-02-18 05:09:49 +00001165 if (GCAttrType == QualType::Weak)
Fariborz Jahanian59d16d12009-02-17 20:16:45 +00001166 S += "weak";
1167 else
1168 S += "strong";
1169 S += ")))";
1170 }
Christopher Lambebb97e92008-02-04 02:31:56 +00001171 BaseType->getAsStringInternal(S);
1172}
1173
Reid Spencer5f016e22007-07-11 17:01:13 +00001174void PointerType::getAsStringInternal(std::string &S) const {
1175 S = '*' + S;
1176
1177 // Handle things like 'int (*A)[4];' correctly.
1178 // FIXME: this should include vectors, but vectors use attributes I guess.
Chris Lattnerbdcd6372008-04-02 17:35:06 +00001179 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +00001180 S = '(' + S + ')';
1181
Chris Lattnerbdcd6372008-04-02 17:35:06 +00001182 getPointeeType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +00001183}
1184
Steve Naroff5618bd42008-08-27 16:04:49 +00001185void BlockPointerType::getAsStringInternal(std::string &S) const {
1186 S = '^' + S;
1187 PointeeType.getAsStringInternal(S);
1188}
1189
Sebastian Redl7c80bd62009-03-16 23:22:08 +00001190void LValueReferenceType::getAsStringInternal(std::string &S) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001191 S = '&' + S;
Sebastian Redl7c80bd62009-03-16 23:22:08 +00001192
Reid Spencer5f016e22007-07-11 17:01:13 +00001193 // Handle things like 'int (&A)[4];' correctly.
1194 // FIXME: this should include vectors, but vectors use attributes I guess.
Chris Lattnerbdcd6372008-04-02 17:35:06 +00001195 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +00001196 S = '(' + S + ')';
Sebastian Redl7c80bd62009-03-16 23:22:08 +00001197
1198 getPointeeType().getAsStringInternal(S);
1199}
1200
1201void RValueReferenceType::getAsStringInternal(std::string &S) const {
1202 S = "&&" + S;
1203
1204 // Handle things like 'int (&&A)[4];' correctly.
1205 // FIXME: this should include vectors, but vectors use attributes I guess.
1206 if (isa<ArrayType>(getPointeeType()))
1207 S = '(' + S + ')';
1208
Chris Lattnerbdcd6372008-04-02 17:35:06 +00001209 getPointeeType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +00001210}
1211
Sebastian Redlf30208a2009-01-24 21:16:55 +00001212void MemberPointerType::getAsStringInternal(std::string &S) const {
1213 std::string C;
1214 Class->getAsStringInternal(C);
1215 C += "::*";
1216 S = C + S;
1217
Sebastian Redl7c80bd62009-03-16 23:22:08 +00001218 // Handle things like 'int (Cls::*A)[4];' correctly.
Sebastian Redlf30208a2009-01-24 21:16:55 +00001219 // FIXME: this should include vectors, but vectors use attributes I guess.
1220 if (isa<ArrayType>(getPointeeType()))
1221 S = '(' + S + ')';
1222
1223 getPointeeType().getAsStringInternal(S);
1224}
1225
Steve Narofffb22d962007-08-30 01:06:46 +00001226void ConstantArrayType::getAsStringInternal(std::string &S) const {
1227 S += '[';
Steve Naroff6b91cd92007-08-30 18:45:57 +00001228 S += llvm::utostr(getSize().getZExtValue());
Steve Narofffb22d962007-08-30 01:06:46 +00001229 S += ']';
1230
1231 getElementType().getAsStringInternal(S);
1232}
1233
Eli Friedmanc5773c42008-02-15 18:16:39 +00001234void IncompleteArrayType::getAsStringInternal(std::string &S) const {
1235 S += "[]";
1236
1237 getElementType().getAsStringInternal(S);
1238}
1239
Steve Narofffb22d962007-08-30 01:06:46 +00001240void VariableArrayType::getAsStringInternal(std::string &S) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001241 S += '[';
1242
Steve Naroffc9406122007-08-30 18:10:14 +00001243 if (getIndexTypeQualifier()) {
1244 AppendTypeQualList(S, getIndexTypeQualifier());
Reid Spencer5f016e22007-07-11 17:01:13 +00001245 S += ' ';
1246 }
1247
Steve Naroffc9406122007-08-30 18:10:14 +00001248 if (getSizeModifier() == Static)
Reid Spencer5f016e22007-07-11 17:01:13 +00001249 S += "static";
Steve Naroffc9406122007-08-30 18:10:14 +00001250 else if (getSizeModifier() == Star)
Reid Spencer5f016e22007-07-11 17:01:13 +00001251 S += '*';
1252
Steve Narofffb22d962007-08-30 01:06:46 +00001253 if (getSizeExpr()) {
Ted Kremeneka95d3752008-09-13 05:16:45 +00001254 std::string SStr;
1255 llvm::raw_string_ostream s(SStr);
Steve Narofffb22d962007-08-30 01:06:46 +00001256 getSizeExpr()->printPretty(s);
1257 S += s.str();
1258 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001259 S += ']';
1260
Steve Narofffb22d962007-08-30 01:06:46 +00001261 getElementType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +00001262}
1263
Douglas Gregor898574e2008-12-05 23:32:09 +00001264void DependentSizedArrayType::getAsStringInternal(std::string &S) const {
1265 S += '[';
1266
1267 if (getIndexTypeQualifier()) {
1268 AppendTypeQualList(S, getIndexTypeQualifier());
1269 S += ' ';
1270 }
1271
1272 if (getSizeModifier() == Static)
1273 S += "static";
1274 else if (getSizeModifier() == Star)
1275 S += '*';
1276
1277 if (getSizeExpr()) {
1278 std::string SStr;
1279 llvm::raw_string_ostream s(SStr);
1280 getSizeExpr()->printPretty(s);
1281 S += s.str();
1282 }
1283 S += ']';
1284
1285 getElementType().getAsStringInternal(S);
1286}
1287
Reid Spencer5f016e22007-07-11 17:01:13 +00001288void VectorType::getAsStringInternal(std::string &S) const {
Daniel Dunbar5620b502008-10-05 05:43:11 +00001289 // FIXME: We prefer to print the size directly here, but have no way
1290 // to get the size of the type.
Chris Lattner7ee261c2007-11-27 07:28:18 +00001291 S += " __attribute__((__vector_size__(";
Daniel Dunbar5620b502008-10-05 05:43:11 +00001292 S += llvm::utostr_32(NumElements); // convert back to bytes.
1293 S += " * sizeof(" + ElementType.getAsString() + "))))";
Chris Lattner08eddd92009-02-19 23:42:29 +00001294 ElementType.getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +00001295}
1296
Nate Begeman213541a2008-04-18 23:10:10 +00001297void ExtVectorType::getAsStringInternal(std::string &S) const {
1298 S += " __attribute__((ext_vector_type(";
Steve Naroff31a45842007-07-28 23:10:27 +00001299 S += llvm::utostr_32(NumElements);
1300 S += ")))";
1301 ElementType.getAsStringInternal(S);
1302}
1303
Douglas Gregor72564e72009-02-26 23:50:07 +00001304void TypeOfExprType::getAsStringInternal(std::string &InnerString) const {
Steve Naroff363bcff2007-08-01 23:45:51 +00001305 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'.
1306 InnerString = ' ' + InnerString;
Ted Kremeneka95d3752008-09-13 05:16:45 +00001307 std::string Str;
1308 llvm::raw_string_ostream s(Str);
Chris Lattner6000dac2007-08-08 22:51:59 +00001309 getUnderlyingExpr()->printPretty(s);
Steve Naroff1bfd5cc2007-08-05 03:24:45 +00001310 InnerString = "typeof(" + s.str() + ")" + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001311}
1312
Steve Naroff363bcff2007-08-01 23:45:51 +00001313void TypeOfType::getAsStringInternal(std::string &InnerString) const {
1314 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'.
1315 InnerString = ' ' + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001316 std::string Tmp;
1317 getUnderlyingType().getAsStringInternal(Tmp);
Steve Naroff363bcff2007-08-01 23:45:51 +00001318 InnerString = "typeof(" + Tmp + ")" + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001319}
1320
Douglas Gregor72564e72009-02-26 23:50:07 +00001321void FunctionNoProtoType::getAsStringInternal(std::string &S) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001322 // If needed for precedence reasons, wrap the inner part in grouping parens.
1323 if (!S.empty())
1324 S = "(" + S + ")";
1325
1326 S += "()";
1327 getResultType().getAsStringInternal(S);
1328}
1329
Douglas Gregor72564e72009-02-26 23:50:07 +00001330void FunctionProtoType::getAsStringInternal(std::string &S) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001331 // If needed for precedence reasons, wrap the inner part in grouping parens.
1332 if (!S.empty())
1333 S = "(" + S + ")";
1334
1335 S += "(";
1336 std::string Tmp;
1337 for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
1338 if (i) S += ", ";
1339 getArgType(i).getAsStringInternal(Tmp);
1340 S += Tmp;
1341 Tmp.clear();
1342 }
1343
1344 if (isVariadic()) {
1345 if (getNumArgs())
1346 S += ", ";
1347 S += "...";
1348 } else if (getNumArgs() == 0) {
1349 // Do not emit int() if we have a proto, emit 'int(void)'.
1350 S += "void";
1351 }
1352
1353 S += ")";
1354 getResultType().getAsStringInternal(S);
1355}
1356
1357
1358void TypedefType::getAsStringInternal(std::string &InnerString) const {
1359 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1360 InnerString = ' ' + InnerString;
1361 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1362}
1363
Douglas Gregor72c3f312008-12-05 18:15:24 +00001364void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const {
1365 if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'.
1366 InnerString = ' ' + InnerString;
Douglas Gregorfab9d672009-02-05 23:33:38 +00001367
1368 if (!Name)
1369 InnerString = "type-parameter-" + llvm::utostr_32(Depth) + '-' +
1370 llvm::utostr_32(Index) + InnerString;
1371 else
1372 InnerString = Name->getName() + InnerString;
Douglas Gregor72c3f312008-12-05 18:15:24 +00001373}
1374
Douglas Gregordf667e72009-03-10 20:44:00 +00001375std::string ClassTemplateSpecializationType::PrintTemplateArgumentList(
1376 const TemplateArgument *Args,
1377 unsigned NumArgs) {
Douglas Gregor98137532009-03-10 18:33:27 +00001378 std::string SpecString;
Douglas Gregor55f6b142009-02-09 18:46:07 +00001379 SpecString += '<';
1380 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1381 if (Arg)
1382 SpecString += ", ";
1383
1384 // Print the argument into a string.
1385 std::string ArgString;
Douglas Gregor98137532009-03-10 18:33:27 +00001386 switch (Args[Arg].getKind()) {
Douglas Gregor40808ce2009-03-09 23:48:35 +00001387 case TemplateArgument::Type:
Douglas Gregor98137532009-03-10 18:33:27 +00001388 Args[Arg].getAsType().getAsStringInternal(ArgString);
Douglas Gregor40808ce2009-03-09 23:48:35 +00001389 break;
1390
1391 case TemplateArgument::Declaration:
Douglas Gregor98137532009-03-10 18:33:27 +00001392 ArgString = cast<NamedDecl>(Args[Arg].getAsDecl())->getNameAsString();
Douglas Gregor40808ce2009-03-09 23:48:35 +00001393 break;
1394
1395 case TemplateArgument::Integral:
Douglas Gregor98137532009-03-10 18:33:27 +00001396 ArgString = Args[Arg].getAsIntegral()->toString(10, true);
Douglas Gregor40808ce2009-03-09 23:48:35 +00001397 break;
1398
1399 case TemplateArgument::Expression: {
Douglas Gregor55f6b142009-02-09 18:46:07 +00001400 llvm::raw_string_ostream s(ArgString);
Douglas Gregor98137532009-03-10 18:33:27 +00001401 Args[Arg].getAsExpr()->printPretty(s);
Douglas Gregor40808ce2009-03-09 23:48:35 +00001402 break;
1403 }
Douglas Gregor55f6b142009-02-09 18:46:07 +00001404 }
1405
1406 // If this is the first argument and its string representation
1407 // begins with the global scope specifier ('::foo'), add a space
1408 // to avoid printing the diagraph '<:'.
1409 if (!Arg && !ArgString.empty() && ArgString[0] == ':')
1410 SpecString += ' ';
1411
1412 SpecString += ArgString;
1413 }
1414
1415 // If the last character of our string is '>', add another space to
1416 // keep the two '>''s separate tokens. We don't *have* to do this in
1417 // C++0x, but it's still good hygiene.
1418 if (SpecString[SpecString.size() - 1] == '>')
1419 SpecString += ' ';
1420
1421 SpecString += '>';
1422
Douglas Gregor98137532009-03-10 18:33:27 +00001423 return SpecString;
1424}
1425
1426void
1427ClassTemplateSpecializationType::
1428getAsStringInternal(std::string &InnerString) const {
1429 std::string SpecString = Template->getNameAsString();
Douglas Gregordf667e72009-03-10 20:44:00 +00001430 SpecString += PrintTemplateArgumentList(getArgs(), getNumArgs());
Douglas Gregor55f6b142009-02-09 18:46:07 +00001431 if (InnerString.empty())
1432 InnerString.swap(SpecString);
1433 else
1434 InnerString = SpecString + ' ' + InnerString;
1435}
1436
Douglas Gregore4e5b052009-03-19 00:18:19 +00001437void QualifiedNameType::getAsStringInternal(std::string &InnerString) const {
1438 std::string MyString;
1439
Douglas Gregorbad35182009-03-19 03:51:16 +00001440 {
1441 llvm::raw_string_ostream OS(MyString);
1442 NestedNameSpecifier::Print(OS, begin(), end());
Douglas Gregore4e5b052009-03-19 00:18:19 +00001443 }
1444
1445 std::string TypeStr;
1446 if (const TagType *TagT = dyn_cast<TagType>(NamedType.getTypePtr())) {
1447 // Suppress printing of 'enum', 'struct', 'union', or 'class'.
1448 TagT->getAsStringInternal(TypeStr, true);
1449 } else
1450 NamedType.getAsStringInternal(TypeStr);
1451
1452 MyString += TypeStr;
1453 if (InnerString.empty())
1454 InnerString.swap(MyString);
1455 else
1456 InnerString = MyString + ' ' + InnerString;
1457}
1458
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001459void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const {
Steve Naroff3536b442007-09-06 21:24:23 +00001460 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1461 InnerString = ' ' + InnerString;
1462 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1463}
1464
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001465void ObjCQualifiedInterfaceType::getAsStringInternal(
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001466 std::string &InnerString) const {
Fariborz Jahaniandfbcce22007-10-11 18:08:47 +00001467 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1468 InnerString = ' ' + InnerString;
Chris Lattner39f34e92008-11-24 04:00:27 +00001469 std::string ObjCQIString = getDecl()->getNameAsString();
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001470 ObjCQIString += '<';
Chris Lattnercdce6d12008-07-21 05:19:23 +00001471 bool isFirst = true;
1472 for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) {
1473 if (isFirst)
1474 isFirst = false;
1475 else
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001476 ObjCQIString += ',';
Chris Lattner39f34e92008-11-24 04:00:27 +00001477 ObjCQIString += (*I)->getNameAsString();
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001478 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001479 ObjCQIString += '>';
1480 InnerString = ObjCQIString + InnerString;
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001481}
1482
Chris Lattnere8e4f922008-07-25 23:07:18 +00001483void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const {
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001484 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1485 InnerString = ' ' + InnerString;
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001486 std::string ObjCQIString = "id";
1487 ObjCQIString += '<';
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001488 int num = getNumProtocols();
1489 for (int i = 0; i < num; i++) {
Chris Lattner39f34e92008-11-24 04:00:27 +00001490 ObjCQIString += getProtocols(i)->getNameAsString();
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001491 if (i < num-1)
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001492 ObjCQIString += ',';
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001493 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001494 ObjCQIString += '>';
1495 InnerString = ObjCQIString + InnerString;
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001496}
1497
Reid Spencer5f016e22007-07-11 17:01:13 +00001498void TagType::getAsStringInternal(std::string &InnerString) const {
Douglas Gregore4e5b052009-03-19 00:18:19 +00001499 getAsStringInternal(InnerString, false);
1500}
1501
1502void TagType::getAsStringInternal(std::string &InnerString,
1503 bool SuppressTagKind) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001504 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1505 InnerString = ' ' + InnerString;
1506
Douglas Gregore4e5b052009-03-19 00:18:19 +00001507 const char *Kind = SuppressTagKind? 0 : getDecl()->getKindName();
Reid Spencer5f016e22007-07-11 17:01:13 +00001508 const char *ID;
1509 if (const IdentifierInfo *II = getDecl()->getIdentifier())
1510 ID = II->getName();
Douglas Gregor4e16d042009-03-10 18:11:21 +00001511 else if (TypedefDecl *Typedef = getDecl()->getTypedefForAnonDecl()) {
1512 Kind = 0;
1513 assert(Typedef->getIdentifier() && "Typedef without identifier?");
1514 ID = Typedef->getIdentifier()->getName();
1515 } else
Reid Spencer5f016e22007-07-11 17:01:13 +00001516 ID = "<anonymous>";
1517
Douglas Gregor98137532009-03-10 18:33:27 +00001518 // If this is a class template specialization, print the template
1519 // arguments.
1520 if (ClassTemplateSpecializationDecl *Spec
1521 = dyn_cast<ClassTemplateSpecializationDecl>(getDecl())) {
1522 std::string TemplateArgs
Douglas Gregordf667e72009-03-10 20:44:00 +00001523 = ClassTemplateSpecializationType::PrintTemplateArgumentList(
1524 Spec->getTemplateArgs(),
1525 Spec->getNumTemplateArgs());
Douglas Gregor98137532009-03-10 18:33:27 +00001526 InnerString = TemplateArgs + InnerString;
1527 }
1528
Douglas Gregor4e16d042009-03-10 18:11:21 +00001529 if (Kind)
1530 InnerString = std::string(Kind) + " " + ID + InnerString;
1531 else
1532 InnerString = ID + InnerString;
Reid Spencer5f016e22007-07-11 17:01:13 +00001533}