blob: ebaa01135555d203e115610a42c13b8f78eacbe1 [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();
35 C.getAllocator().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();
41 C.getAllocator().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();
47 C.getAllocator().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();
327
328 // A function can return a variably modified type
329 // This one isn't completely obvious, but it follows from the
330 // definition in C99 6.7.5p3. Because of this rule, it's
331 // illegal to declare a function returning a variably modified type.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000332 if (const FunctionType *FT = getAsFunctionType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000333 return FT->getResultType()->isVariablyModifiedType();
334
Steve Naroffd7444aa2007-08-31 17:20:07 +0000335 return false;
336}
337
Chris Lattnerc8629632007-07-31 19:29:30 +0000338const RecordType *Type::getAsRecordType() const {
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000339 // If this is directly a reference type, return it.
340 if (const RecordType *RTy = dyn_cast<RecordType>(this))
341 return RTy;
342
Chris Lattnerdea61462007-10-29 03:41:11 +0000343 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000344 if (!isa<RecordType>(CanonicalType)) {
345 // Look through type qualifiers
346 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
347 return CanonicalType.getUnqualifiedType()->getAsRecordType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000348 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000349 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000350
351 // If this is a typedef for a record type, strip the typedef off without
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000352 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000353 return getDesugaredType()->getAsRecordType();
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000354}
355
Chris Lattnerc8629632007-07-31 19:29:30 +0000356const RecordType *Type::getAsStructureType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000357 // If this is directly a structure type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000358 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000359 if (RT->getDecl()->isStruct())
Chris Lattnerc8629632007-07-31 19:29:30 +0000360 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000361 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000362
363 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000364 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000365 if (!RT->getDecl()->isStruct())
Chris Lattnerdea61462007-10-29 03:41:11 +0000366 return 0;
367
368 // If this is a typedef for a structure type, strip the typedef off without
369 // losing all typedef information.
370 return getDesugaredType()->getAsStructureType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000371 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000372 // Look through type qualifiers
373 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
374 return CanonicalType.getUnqualifiedType()->getAsStructureType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000375 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000376}
377
Chris Lattnerc8629632007-07-31 19:29:30 +0000378const RecordType *Type::getAsUnionType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000379 // If this is directly a union type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000380 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000381 if (RT->getDecl()->isUnion())
Chris Lattnerc8629632007-07-31 19:29:30 +0000382 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000383 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000384
Chris Lattnerdea61462007-10-29 03:41:11 +0000385 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000386 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000387 if (!RT->getDecl()->isUnion())
Chris Lattnerdea61462007-10-29 03:41:11 +0000388 return 0;
389
390 // If this is a typedef for a union type, strip the typedef off without
391 // losing all typedef information.
392 return getDesugaredType()->getAsUnionType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000393 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000394
395 // Look through type qualifiers
396 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
397 return CanonicalType.getUnqualifiedType()->getAsUnionType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000398 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000399}
400
Eli Friedmanad74a752008-06-28 06:23:08 +0000401const EnumType *Type::getAsEnumType() const {
402 // Check the canonicalized unqualified type directly; the more complex
403 // version is unnecessary because there isn't any typedef information
404 // to preserve.
405 return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType());
406}
407
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000408const ComplexType *Type::getAsComplexType() const {
409 // Are we directly a complex type?
410 if (const ComplexType *CTy = dyn_cast<ComplexType>(this))
411 return CTy;
412
Chris Lattnerdea61462007-10-29 03:41:11 +0000413 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000414 if (!isa<ComplexType>(CanonicalType)) {
415 // Look through type qualifiers
416 if (isa<ComplexType>(CanonicalType.getUnqualifiedType()))
417 return CanonicalType.getUnqualifiedType()->getAsComplexType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000418 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000419 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000420
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000421 // If this is a typedef for a complex type, strip the typedef off without
422 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000423 return getDesugaredType()->getAsComplexType();
Chris Lattner7a2e0472007-07-16 00:23:25 +0000424}
425
Chris Lattnerc8629632007-07-31 19:29:30 +0000426const VectorType *Type::getAsVectorType() const {
Chris Lattner7a2e0472007-07-16 00:23:25 +0000427 // Are we directly a vector type?
428 if (const VectorType *VTy = dyn_cast<VectorType>(this))
429 return VTy;
Chris Lattnera2c77672007-07-16 22:05:22 +0000430
Chris Lattnerdea61462007-10-29 03:41:11 +0000431 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000432 if (!isa<VectorType>(CanonicalType)) {
433 // Look through type qualifiers
434 if (isa<VectorType>(CanonicalType.getUnqualifiedType()))
435 return CanonicalType.getUnqualifiedType()->getAsVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000436 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000437 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000438
Chris Lattnera2c77672007-07-16 22:05:22 +0000439 // If this is a typedef for a vector type, strip the typedef off without
440 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000441 return getDesugaredType()->getAsVectorType();
Chris Lattner7a2e0472007-07-16 00:23:25 +0000442}
443
Nate Begeman213541a2008-04-18 23:10:10 +0000444const ExtVectorType *Type::getAsExtVectorType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000445 // Are we directly an OpenCU vector type?
Nate Begeman213541a2008-04-18 23:10:10 +0000446 if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this))
Steve Naroff7064f5c2007-07-26 18:32:01 +0000447 return VTy;
448
Chris Lattnerdea61462007-10-29 03:41:11 +0000449 // If the canonical form of this type isn't the right kind, reject it.
Nate Begeman213541a2008-04-18 23:10:10 +0000450 if (!isa<ExtVectorType>(CanonicalType)) {
Christopher Lambebb97e92008-02-04 02:31:56 +0000451 // Look through type qualifiers
Nate Begeman213541a2008-04-18 23:10:10 +0000452 if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType()))
453 return CanonicalType.getUnqualifiedType()->getAsExtVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000454 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000455 }
Steve Naroff7064f5c2007-07-26 18:32:01 +0000456
Nate Begeman213541a2008-04-18 23:10:10 +0000457 // If this is a typedef for an extended vector type, strip the typedef off
458 // without losing all typedef information.
459 return getDesugaredType()->getAsExtVectorType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000460}
461
Chris Lattner368eefa2008-04-07 00:27:04 +0000462const ObjCInterfaceType *Type::getAsObjCInterfaceType() const {
Chris Lattnereca7be62008-04-07 05:30:13 +0000463 // There is no sugar for ObjCInterfaceType's, just return the canonical
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000464 // type pointer if it is the right class. There is no typedef information to
465 // return and these cannot be Address-space qualified.
Chris Lattnereca7be62008-04-07 05:30:13 +0000466 return dyn_cast<ObjCInterfaceType>(CanonicalType);
Chris Lattner368eefa2008-04-07 00:27:04 +0000467}
468
469const ObjCQualifiedInterfaceType *
470Type::getAsObjCQualifiedInterfaceType() const {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000471 // There is no sugar for ObjCQualifiedInterfaceType's, just return the
472 // canonical type pointer if it is the right class.
Chris Lattnereca7be62008-04-07 05:30:13 +0000473 return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType);
474}
475
476const ObjCQualifiedIdType *Type::getAsObjCQualifiedIdType() const {
477 // There is no sugar for ObjCQualifiedIdType's, just return the canonical
478 // type pointer if it is the right class.
479 return dyn_cast<ObjCQualifiedIdType>(CanonicalType);
Chris Lattner368eefa2008-04-07 00:27:04 +0000480}
481
Douglas Gregor72c3f312008-12-05 18:15:24 +0000482const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const {
483 // There is no sugar for template type parameters, so just return
484 // the canonical type pointer if it is the right class.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000485 // FIXME: can these be address-space qualified?
Douglas Gregor72c3f312008-12-05 18:15:24 +0000486 return dyn_cast<TemplateTypeParmType>(CanonicalType);
487}
Chris Lattner368eefa2008-04-07 00:27:04 +0000488
Reid Spencer5f016e22007-07-11 17:01:13 +0000489bool Type::isIntegerType() const {
490 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
491 return BT->getKind() >= BuiltinType::Bool &&
492 BT->getKind() <= BuiltinType::LongLong;
493 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000494 // Incomplete enum types are not treated as integer types.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000495 // FIXME: In C++, enum types are never integer types.
Chris Lattner834a72a2008-07-25 23:18:17 +0000496 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000497 return true;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000498 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
499 return VT->getElementType()->isIntegerType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000500 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
501 return ASQT->getBaseType()->isIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000502 return false;
503}
504
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000505bool Type::isIntegralType() const {
506 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
507 return BT->getKind() >= BuiltinType::Bool &&
508 BT->getKind() <= BuiltinType::LongLong;
509 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000510 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
511 return true; // Complete enum types are integral.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000512 // FIXME: In C++, enum types are never integral.
Christopher Lambebb97e92008-02-04 02:31:56 +0000513 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
514 return ASQT->getBaseType()->isIntegralType();
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000515 return false;
516}
517
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000518bool Type::isEnumeralType() const {
519 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000520 return TT->getDecl()->isEnum();
Christopher Lambebb97e92008-02-04 02:31:56 +0000521 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
522 return ASQT->getBaseType()->isEnumeralType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000523 return false;
524}
525
526bool Type::isBooleanType() const {
527 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
528 return BT->getKind() == BuiltinType::Bool;
Christopher Lambebb97e92008-02-04 02:31:56 +0000529 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
530 return ASQT->getBaseType()->isBooleanType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000531 return false;
532}
533
534bool Type::isCharType() const {
535 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
536 return BT->getKind() == BuiltinType::Char_U ||
537 BT->getKind() == BuiltinType::UChar ||
Anders Carlssonc67ad5f2007-10-29 02:52:18 +0000538 BT->getKind() == BuiltinType::Char_S ||
539 BT->getKind() == BuiltinType::SChar;
Christopher Lambebb97e92008-02-04 02:31:56 +0000540 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
541 return ASQT->getBaseType()->isCharType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000542 return false;
543}
544
Douglas Gregor77a52232008-09-12 00:47:35 +0000545bool Type::isWideCharType() const {
546 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
547 return BT->getKind() == BuiltinType::WChar;
548 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
549 return ASQT->getBaseType()->isWideCharType();
550 return false;
551}
552
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000553/// isSignedIntegerType - Return true if this is an integer type that is
554/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
555/// an enum decl which has a signed representation, or a vector of signed
556/// integer element type.
Reid Spencer5f016e22007-07-11 17:01:13 +0000557bool Type::isSignedIntegerType() const {
558 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
559 return BT->getKind() >= BuiltinType::Char_S &&
560 BT->getKind() <= BuiltinType::LongLong;
561 }
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000562
Chris Lattner37c1b782008-04-06 22:29:16 +0000563 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
564 return ET->getDecl()->getIntegerType()->isSignedIntegerType();
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000565
Steve Naroffc63b96a2007-07-12 21:46:55 +0000566 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
567 return VT->getElementType()->isSignedIntegerType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000568 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
569 return ASQT->getBaseType()->isSignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000570 return false;
571}
572
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000573/// isUnsignedIntegerType - Return true if this is an integer type that is
574/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
575/// decl which has an unsigned representation, or a vector of unsigned integer
576/// element type.
Reid Spencer5f016e22007-07-11 17:01:13 +0000577bool Type::isUnsignedIntegerType() const {
578 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
579 return BT->getKind() >= BuiltinType::Bool &&
580 BT->getKind() <= BuiltinType::ULongLong;
581 }
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000582
Chris Lattner37c1b782008-04-06 22:29:16 +0000583 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
584 return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000585
Steve Naroffc63b96a2007-07-12 21:46:55 +0000586 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
587 return VT->getElementType()->isUnsignedIntegerType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000588 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
589 return ASQT->getBaseType()->isUnsignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000590 return false;
591}
592
593bool Type::isFloatingType() const {
594 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
595 return BT->getKind() >= BuiltinType::Float &&
596 BT->getKind() <= BuiltinType::LongDouble;
597 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
Chris Lattner729a2132007-08-30 06:19:11 +0000598 return CT->getElementType()->isFloatingType();
Steve Naroffc63b96a2007-07-12 21:46:55 +0000599 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
600 return VT->getElementType()->isFloatingType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000601 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
602 return ASQT->getBaseType()->isFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000603 return false;
604}
605
606bool Type::isRealFloatingType() const {
607 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
608 return BT->getKind() >= BuiltinType::Float &&
609 BT->getKind() <= BuiltinType::LongDouble;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000610 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
611 return VT->getElementType()->isRealFloatingType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000612 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
613 return ASQT->getBaseType()->isRealFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000614 return false;
615}
616
617bool Type::isRealType() const {
618 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
619 return BT->getKind() >= BuiltinType::Bool &&
620 BT->getKind() <= BuiltinType::LongDouble;
621 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000622 return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition();
Steve Naroffc63b96a2007-07-12 21:46:55 +0000623 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
624 return VT->getElementType()->isRealType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000625 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
626 return ASQT->getBaseType()->isRealType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000627 return false;
628}
629
Reid Spencer5f016e22007-07-11 17:01:13 +0000630bool Type::isArithmeticType() const {
631 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
Douglas Gregora7fbf722008-10-30 13:47:07 +0000632 return BT->getKind() >= BuiltinType::Bool &&
633 BT->getKind() <= BuiltinType::LongDouble;
Chris Lattner37c1b782008-04-06 22:29:16 +0000634 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
635 // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
636 // If a body isn't seen by the time we get here, return false.
637 return ET->getDecl()->isDefinition();
Christopher Lambebb97e92008-02-04 02:31:56 +0000638 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
639 return ASQT->getBaseType()->isArithmeticType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000640 return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType);
641}
642
643bool Type::isScalarType() const {
644 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
645 return BT->getKind() != BuiltinType::Void;
646 if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
Chris Lattner834a72a2008-07-25 23:18:17 +0000647 // Enums are scalar types, but only if they are defined. Incomplete enums
648 // are not treated as scalar types.
649 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000650 return true;
651 return false;
652 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000653 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
654 return ASQT->getBaseType()->isScalarType();
Steve Naroff5618bd42008-08-27 16:04:49 +0000655 return isa<PointerType>(CanonicalType) ||
656 isa<BlockPointerType>(CanonicalType) ||
Sebastian Redlf30208a2009-01-24 21:16:55 +0000657 isa<MemberPointerType>(CanonicalType) ||
Steve Naroff5618bd42008-08-27 16:04:49 +0000658 isa<ComplexType>(CanonicalType) ||
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000659 isa<ObjCQualifiedIdType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000660}
661
662bool Type::isAggregateType() const {
663 if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000664 if (TT->getDecl()->isStruct())
Reid Spencer5f016e22007-07-11 17:01:13 +0000665 return true;
666 return false;
667 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000668 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
669 return ASQT->getBaseType()->isAggregateType();
Eli Friedmanc5773c42008-02-15 18:16:39 +0000670 return isa<ArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000671}
672
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000673/// isConstantSizeType - Return true if this is not a variable sized type,
674/// according to the rules of C99 6.7.5p3. It is not legal to call this on
Douglas Gregor898574e2008-12-05 23:32:09 +0000675/// incomplete types or dependent types.
Eli Friedman3c2b3172008-02-15 12:20:59 +0000676bool Type::isConstantSizeType() const {
Christopher Lambebb97e92008-02-04 02:31:56 +0000677 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
Eli Friedman3c2b3172008-02-15 12:20:59 +0000678 return ASQT->getBaseType()->isConstantSizeType();
Chris Lattnerd52a4572007-12-18 07:03:30 +0000679 assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
Douglas Gregor898574e2008-12-05 23:32:09 +0000680 assert(!isDependentType() && "This doesn't make sense for dependent types");
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000681 // The VAT must have a size, as it is known to be complete.
682 return !isa<VariableArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000683}
684
685/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
686/// - a type that can describe objects, but which lacks information needed to
687/// determine its size.
688bool Type::isIncompleteType() const {
689 switch (CanonicalType->getTypeClass()) {
690 default: return false;
Christopher Lambebb97e92008-02-04 02:31:56 +0000691 case ASQual:
692 return cast<ASQualType>(CanonicalType)->getBaseType()->isIncompleteType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000693 case Builtin:
694 // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
695 // be completed.
696 return isVoidType();
697 case Tagged:
698 // A tagged type (struct/union/enum/class) is incomplete if the decl is a
699 // forward declaration, but not a full definition (C99 6.2.5p22).
700 return !cast<TagType>(CanonicalType)->getDecl()->isDefinition();
Eli Friedmanc5773c42008-02-15 18:16:39 +0000701 case IncompleteArray:
Reid Spencer5f016e22007-07-11 17:01:13 +0000702 // An array of unknown size is an incomplete type (C99 6.2.5p22).
Eli Friedmanc5773c42008-02-15 18:16:39 +0000703 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000704 }
705}
706
Sebastian Redl64b45f72009-01-05 20:52:13 +0000707/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10)
708bool Type::isPODType() const {
709 // The compiler shouldn't query this for incomplete types, but the user might.
710 // We return false for that case.
711 if (isIncompleteType())
712 return false;
713
714 switch (CanonicalType->getTypeClass()) {
715 // Everything not explicitly mentioned is not POD.
716 default: return false;
717 case ASQual:
718 return cast<ASQualType>(CanonicalType)->getBaseType()->isPODType();
719 case VariableArray:
720 case ConstantArray:
721 // IncompleteArray is caught by isIncompleteType() above.
722 return cast<ArrayType>(CanonicalType)->getElementType()->isPODType();
723
724 case Builtin:
725 case Complex:
726 case Pointer:
Sebastian Redlf30208a2009-01-24 21:16:55 +0000727 case MemberPointer:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000728 case Vector:
729 case ExtVector:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000730 return true;
731
732 case Tagged:
733 if (isEnumeralType())
734 return true;
735 if (CXXRecordDecl *RDecl = dyn_cast<CXXRecordDecl>(
736 cast<TagType>(CanonicalType)->getDecl()))
737 return RDecl->isPOD();
738 // C struct/union is POD.
739 return true;
740 }
741}
742
Reid Spencer5f016e22007-07-11 17:01:13 +0000743bool Type::isPromotableIntegerType() const {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000744 if (const BuiltinType *BT = getAsBuiltinType())
745 switch (BT->getKind()) {
746 case BuiltinType::Bool:
747 case BuiltinType::Char_S:
748 case BuiltinType::Char_U:
749 case BuiltinType::SChar:
750 case BuiltinType::UChar:
751 case BuiltinType::Short:
752 case BuiltinType::UShort:
753 return true;
754 default:
755 return false;
756 }
757 return false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000758}
759
760const char *BuiltinType::getName() const {
761 switch (getKind()) {
762 default: assert(0 && "Unknown builtin type!");
763 case Void: return "void";
764 case Bool: return "_Bool";
765 case Char_S: return "char";
766 case Char_U: return "char";
767 case SChar: return "signed char";
768 case Short: return "short";
769 case Int: return "int";
770 case Long: return "long";
771 case LongLong: return "long long";
772 case UChar: return "unsigned char";
773 case UShort: return "unsigned short";
774 case UInt: return "unsigned int";
775 case ULong: return "unsigned long";
776 case ULongLong: return "unsigned long long";
777 case Float: return "float";
778 case Double: return "double";
779 case LongDouble: return "long double";
Argyrios Kyrtzidis46713ef2008-08-09 17:11:33 +0000780 case WChar: return "wchar_t";
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000781 case Overload: return "<overloaded function type>";
Douglas Gregor898574e2008-12-05 23:32:09 +0000782 case Dependent: return "<dependent type>";
Reid Spencer5f016e22007-07-11 17:01:13 +0000783 }
784}
785
Reid Spencer5f016e22007-07-11 17:01:13 +0000786void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
Chris Lattner942cfd32007-07-20 18:48:28 +0000787 arg_type_iterator ArgTys,
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000788 unsigned NumArgs, bool isVariadic,
789 unsigned TypeQuals) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000790 ID.AddPointer(Result.getAsOpaquePtr());
791 for (unsigned i = 0; i != NumArgs; ++i)
792 ID.AddPointer(ArgTys[i].getAsOpaquePtr());
793 ID.AddInteger(isVariadic);
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000794 ID.AddInteger(TypeQuals);
Reid Spencer5f016e22007-07-11 17:01:13 +0000795}
796
797void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) {
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000798 Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(),
799 getTypeQuals());
Reid Spencer5f016e22007-07-11 17:01:13 +0000800}
801
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000802void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
Chris Lattner1ee07002008-04-07 06:37:47 +0000803 const ObjCInterfaceDecl *Decl,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000804 ObjCProtocolDecl **protocols,
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000805 unsigned NumProtocols) {
Chris Lattner1ee07002008-04-07 06:37:47 +0000806 ID.AddPointer(Decl);
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000807 for (unsigned i = 0; i != NumProtocols; i++)
808 ID.AddPointer(protocols[i]);
809}
810
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000811void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
Chris Lattner1ee07002008-04-07 06:37:47 +0000812 Profile(ID, getDecl(), &Protocols[0], getNumProtocols());
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000813}
814
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000815void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID,
Chris Lattner62f5f7f2008-07-26 00:46:50 +0000816 ObjCProtocolDecl **protocols,
817 unsigned NumProtocols) {
Fariborz Jahanianc5692492007-12-17 21:03:50 +0000818 for (unsigned i = 0; i != NumProtocols; i++)
819 ID.AddPointer(protocols[i]);
820}
821
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000822void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) {
Fariborz Jahanianc5692492007-12-17 21:03:50 +0000823 Profile(ID, &Protocols[0], getNumProtocols());
824}
825
Chris Lattnera2c77672007-07-16 22:05:22 +0000826/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
827/// potentially looking through *all* consequtive typedefs. This returns the
828/// sum of the type qualifiers, so if you have:
829/// typedef const int A;
830/// typedef volatile A B;
831/// looking through the typedefs for B will give you "const volatile A".
832///
833QualType TypedefType::LookThroughTypedefs() const {
834 // Usually, there is only a single level of typedefs, be fast in that case.
835 QualType FirstType = getDecl()->getUnderlyingType();
836 if (!isa<TypedefType>(FirstType))
837 return FirstType;
838
839 // Otherwise, do the fully general loop.
840 unsigned TypeQuals = 0;
841 const TypedefType *TDT = this;
842 while (1) {
843 QualType CurType = TDT->getDecl()->getUnderlyingType();
Chris Lattnerf46699c2008-02-20 20:55:12 +0000844
845
846 /// FIXME:
847 /// FIXME: This is incorrect for ASQuals!
848 /// FIXME:
849 TypeQuals |= CurType.getCVRQualifiers();
Chris Lattnera2c77672007-07-16 22:05:22 +0000850
851 TDT = dyn_cast<TypedefType>(CurType);
852 if (TDT == 0)
853 return QualType(CurType.getTypePtr(), TypeQuals);
854 }
855}
Reid Spencer5f016e22007-07-11 17:01:13 +0000856
Douglas Gregor898574e2008-12-05 23:32:09 +0000857TypeOfExpr::TypeOfExpr(Expr *E, QualType can)
858 : Type(TypeOfExp, can, E->isTypeDependent()), TOExpr(E) {
859 assert(!isa<TypedefType>(can) && "Invalid canonical type");
860}
861
Chris Lattner2daa5df2008-04-06 22:04:54 +0000862bool RecordType::classof(const TagType *TT) {
863 return isa<RecordDecl>(TT->getDecl());
Reid Spencer5f016e22007-07-11 17:01:13 +0000864}
865
Argyrios Kyrtzidis49aa7ff2008-08-07 20:55:28 +0000866bool CXXRecordType::classof(const TagType *TT) {
867 return isa<CXXRecordDecl>(TT->getDecl());
868}
869
Chris Lattner2daa5df2008-04-06 22:04:54 +0000870bool EnumType::classof(const TagType *TT) {
871 return isa<EnumDecl>(TT->getDecl());
Chris Lattner5edb8bf2008-04-06 21:58:47 +0000872}
873
Anders Carlsson97e01792008-12-21 00:16:32 +0000874
Reid Spencer5f016e22007-07-11 17:01:13 +0000875//===----------------------------------------------------------------------===//
876// Type Printing
877//===----------------------------------------------------------------------===//
878
879void QualType::dump(const char *msg) const {
Chris Lattner39caea92007-12-06 04:20:07 +0000880 std::string R = "identifier";
Reid Spencer5f016e22007-07-11 17:01:13 +0000881 getAsStringInternal(R);
882 if (msg)
883 fprintf(stderr, "%s: %s\n", msg, R.c_str());
884 else
885 fprintf(stderr, "%s\n", R.c_str());
886}
Chris Lattnerc36d4052008-07-27 00:48:22 +0000887void QualType::dump() const {
888 dump("");
889}
890
891void Type::dump() const {
892 std::string S = "identifier";
893 getAsStringInternal(S);
894 fprintf(stderr, "%s\n", S.c_str());
895}
896
897
Reid Spencer5f016e22007-07-11 17:01:13 +0000898
899static void AppendTypeQualList(std::string &S, unsigned TypeQuals) {
900 // Note: funkiness to ensure we get a space only between quals.
901 bool NonePrinted = true;
902 if (TypeQuals & QualType::Const)
903 S += "const", NonePrinted = false;
904 if (TypeQuals & QualType::Volatile)
905 S += (NonePrinted+" volatile"), NonePrinted = false;
906 if (TypeQuals & QualType::Restrict)
907 S += (NonePrinted+" restrict"), NonePrinted = false;
908}
909
910void QualType::getAsStringInternal(std::string &S) const {
911 if (isNull()) {
Douglas Gregor61366e92008-12-24 00:01:03 +0000912 S += "NULL TYPE";
Reid Spencer5f016e22007-07-11 17:01:13 +0000913 return;
914 }
915
916 // Print qualifiers as appropriate.
Gabor Greif3513e132008-02-21 17:40:55 +0000917 if (unsigned Tq = getCVRQualifiers()) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000918 std::string TQS;
Gabor Greif3513e132008-02-21 17:40:55 +0000919 AppendTypeQualList(TQS, Tq);
Reid Spencer5f016e22007-07-11 17:01:13 +0000920 if (!S.empty())
921 S = TQS + ' ' + S;
922 else
923 S = TQS;
924 }
925
926 getTypePtr()->getAsStringInternal(S);
927}
928
929void BuiltinType::getAsStringInternal(std::string &S) const {
930 if (S.empty()) {
931 S = getName();
932 } else {
933 // Prefix the basic type, e.g. 'int X'.
934 S = ' ' + S;
935 S = getName() + S;
936 }
937}
938
939void ComplexType::getAsStringInternal(std::string &S) const {
940 ElementType->getAsStringInternal(S);
941 S = "_Complex " + S;
942}
943
Christopher Lambebb97e92008-02-04 02:31:56 +0000944void ASQualType::getAsStringInternal(std::string &S) const {
945 S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S;
946 BaseType->getAsStringInternal(S);
947}
948
Reid Spencer5f016e22007-07-11 17:01:13 +0000949void PointerType::getAsStringInternal(std::string &S) const {
950 S = '*' + S;
951
952 // Handle things like 'int (*A)[4];' correctly.
953 // FIXME: this should include vectors, but vectors use attributes I guess.
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000954 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +0000955 S = '(' + S + ')';
956
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000957 getPointeeType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000958}
959
Steve Naroff5618bd42008-08-27 16:04:49 +0000960void BlockPointerType::getAsStringInternal(std::string &S) const {
961 S = '^' + S;
962 PointeeType.getAsStringInternal(S);
963}
964
Reid Spencer5f016e22007-07-11 17:01:13 +0000965void ReferenceType::getAsStringInternal(std::string &S) const {
966 S = '&' + S;
967
968 // Handle things like 'int (&A)[4];' correctly.
969 // FIXME: this should include vectors, but vectors use attributes I guess.
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000970 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +0000971 S = '(' + S + ')';
972
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000973 getPointeeType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000974}
975
Sebastian Redlf30208a2009-01-24 21:16:55 +0000976void MemberPointerType::getAsStringInternal(std::string &S) const {
977 std::string C;
978 Class->getAsStringInternal(C);
979 C += "::*";
980 S = C + S;
981
982 // Handle things like 'int (&A)[4];' correctly.
983 // FIXME: this should include vectors, but vectors use attributes I guess.
984 if (isa<ArrayType>(getPointeeType()))
985 S = '(' + S + ')';
986
987 getPointeeType().getAsStringInternal(S);
988}
989
Steve Narofffb22d962007-08-30 01:06:46 +0000990void ConstantArrayType::getAsStringInternal(std::string &S) const {
991 S += '[';
Steve Naroff6b91cd92007-08-30 18:45:57 +0000992 S += llvm::utostr(getSize().getZExtValue());
Steve Narofffb22d962007-08-30 01:06:46 +0000993 S += ']';
994
995 getElementType().getAsStringInternal(S);
996}
997
Eli Friedmanc5773c42008-02-15 18:16:39 +0000998void IncompleteArrayType::getAsStringInternal(std::string &S) const {
999 S += "[]";
1000
1001 getElementType().getAsStringInternal(S);
1002}
1003
Steve Narofffb22d962007-08-30 01:06:46 +00001004void VariableArrayType::getAsStringInternal(std::string &S) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001005 S += '[';
1006
Steve Naroffc9406122007-08-30 18:10:14 +00001007 if (getIndexTypeQualifier()) {
1008 AppendTypeQualList(S, getIndexTypeQualifier());
Reid Spencer5f016e22007-07-11 17:01:13 +00001009 S += ' ';
1010 }
1011
Steve Naroffc9406122007-08-30 18:10:14 +00001012 if (getSizeModifier() == Static)
Reid Spencer5f016e22007-07-11 17:01:13 +00001013 S += "static";
Steve Naroffc9406122007-08-30 18:10:14 +00001014 else if (getSizeModifier() == Star)
Reid Spencer5f016e22007-07-11 17:01:13 +00001015 S += '*';
1016
Steve Narofffb22d962007-08-30 01:06:46 +00001017 if (getSizeExpr()) {
Ted Kremeneka95d3752008-09-13 05:16:45 +00001018 std::string SStr;
1019 llvm::raw_string_ostream s(SStr);
Steve Narofffb22d962007-08-30 01:06:46 +00001020 getSizeExpr()->printPretty(s);
1021 S += s.str();
1022 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001023 S += ']';
1024
Steve Narofffb22d962007-08-30 01:06:46 +00001025 getElementType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +00001026}
1027
Douglas Gregor898574e2008-12-05 23:32:09 +00001028void DependentSizedArrayType::getAsStringInternal(std::string &S) const {
1029 S += '[';
1030
1031 if (getIndexTypeQualifier()) {
1032 AppendTypeQualList(S, getIndexTypeQualifier());
1033 S += ' ';
1034 }
1035
1036 if (getSizeModifier() == Static)
1037 S += "static";
1038 else if (getSizeModifier() == Star)
1039 S += '*';
1040
1041 if (getSizeExpr()) {
1042 std::string SStr;
1043 llvm::raw_string_ostream s(SStr);
1044 getSizeExpr()->printPretty(s);
1045 S += s.str();
1046 }
1047 S += ']';
1048
1049 getElementType().getAsStringInternal(S);
1050}
1051
Reid Spencer5f016e22007-07-11 17:01:13 +00001052void VectorType::getAsStringInternal(std::string &S) const {
Daniel Dunbar5620b502008-10-05 05:43:11 +00001053 // FIXME: We prefer to print the size directly here, but have no way
1054 // to get the size of the type.
Chris Lattner7ee261c2007-11-27 07:28:18 +00001055 S += " __attribute__((__vector_size__(";
Daniel Dunbar5620b502008-10-05 05:43:11 +00001056 S += llvm::utostr_32(NumElements); // convert back to bytes.
1057 S += " * sizeof(" + ElementType.getAsString() + "))))";
Reid Spencer5f016e22007-07-11 17:01:13 +00001058}
1059
Nate Begeman213541a2008-04-18 23:10:10 +00001060void ExtVectorType::getAsStringInternal(std::string &S) const {
1061 S += " __attribute__((ext_vector_type(";
Steve Naroff31a45842007-07-28 23:10:27 +00001062 S += llvm::utostr_32(NumElements);
1063 S += ")))";
1064 ElementType.getAsStringInternal(S);
1065}
1066
Steve Naroffd1861fd2007-07-31 12:34:36 +00001067void TypeOfExpr::getAsStringInternal(std::string &InnerString) const {
Steve Naroff363bcff2007-08-01 23:45:51 +00001068 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'.
1069 InnerString = ' ' + InnerString;
Ted Kremeneka95d3752008-09-13 05:16:45 +00001070 std::string Str;
1071 llvm::raw_string_ostream s(Str);
Chris Lattner6000dac2007-08-08 22:51:59 +00001072 getUnderlyingExpr()->printPretty(s);
Steve Naroff1bfd5cc2007-08-05 03:24:45 +00001073 InnerString = "typeof(" + s.str() + ")" + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001074}
1075
Steve Naroff363bcff2007-08-01 23:45:51 +00001076void TypeOfType::getAsStringInternal(std::string &InnerString) const {
1077 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'.
1078 InnerString = ' ' + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001079 std::string Tmp;
1080 getUnderlyingType().getAsStringInternal(Tmp);
Steve Naroff363bcff2007-08-01 23:45:51 +00001081 InnerString = "typeof(" + Tmp + ")" + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001082}
1083
Reid Spencer5f016e22007-07-11 17:01:13 +00001084void FunctionTypeNoProto::getAsStringInternal(std::string &S) const {
1085 // If needed for precedence reasons, wrap the inner part in grouping parens.
1086 if (!S.empty())
1087 S = "(" + S + ")";
1088
1089 S += "()";
1090 getResultType().getAsStringInternal(S);
1091}
1092
1093void FunctionTypeProto::getAsStringInternal(std::string &S) const {
1094 // If needed for precedence reasons, wrap the inner part in grouping parens.
1095 if (!S.empty())
1096 S = "(" + S + ")";
1097
1098 S += "(";
1099 std::string Tmp;
1100 for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
1101 if (i) S += ", ";
1102 getArgType(i).getAsStringInternal(Tmp);
1103 S += Tmp;
1104 Tmp.clear();
1105 }
1106
1107 if (isVariadic()) {
1108 if (getNumArgs())
1109 S += ", ";
1110 S += "...";
1111 } else if (getNumArgs() == 0) {
1112 // Do not emit int() if we have a proto, emit 'int(void)'.
1113 S += "void";
1114 }
1115
1116 S += ")";
1117 getResultType().getAsStringInternal(S);
1118}
1119
1120
1121void TypedefType::getAsStringInternal(std::string &InnerString) const {
1122 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1123 InnerString = ' ' + InnerString;
1124 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1125}
1126
Douglas Gregor72c3f312008-12-05 18:15:24 +00001127void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const {
1128 if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'.
1129 InnerString = ' ' + InnerString;
1130 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1131}
1132
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001133void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const {
Steve Naroff3536b442007-09-06 21:24:23 +00001134 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1135 InnerString = ' ' + InnerString;
1136 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1137}
1138
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001139void ObjCQualifiedInterfaceType::getAsStringInternal(
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001140 std::string &InnerString) const {
Fariborz Jahaniandfbcce22007-10-11 18:08:47 +00001141 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1142 InnerString = ' ' + InnerString;
Chris Lattner39f34e92008-11-24 04:00:27 +00001143 std::string ObjCQIString = getDecl()->getNameAsString();
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001144 ObjCQIString += '<';
Chris Lattnercdce6d12008-07-21 05:19:23 +00001145 bool isFirst = true;
1146 for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) {
1147 if (isFirst)
1148 isFirst = false;
1149 else
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001150 ObjCQIString += ',';
Chris Lattner39f34e92008-11-24 04:00:27 +00001151 ObjCQIString += (*I)->getNameAsString();
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001152 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001153 ObjCQIString += '>';
1154 InnerString = ObjCQIString + InnerString;
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001155}
1156
Chris Lattnere8e4f922008-07-25 23:07:18 +00001157void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const {
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001158 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1159 InnerString = ' ' + InnerString;
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001160 std::string ObjCQIString = "id";
1161 ObjCQIString += '<';
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001162 int num = getNumProtocols();
1163 for (int i = 0; i < num; i++) {
Chris Lattner39f34e92008-11-24 04:00:27 +00001164 ObjCQIString += getProtocols(i)->getNameAsString();
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001165 if (i < num-1)
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001166 ObjCQIString += ',';
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001167 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001168 ObjCQIString += '>';
1169 InnerString = ObjCQIString + InnerString;
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001170}
1171
Reid Spencer5f016e22007-07-11 17:01:13 +00001172void TagType::getAsStringInternal(std::string &InnerString) const {
1173 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1174 InnerString = ' ' + InnerString;
1175
1176 const char *Kind = getDecl()->getKindName();
1177 const char *ID;
1178 if (const IdentifierInfo *II = getDecl()->getIdentifier())
1179 ID = II->getName();
1180 else
1181 ID = "<anonymous>";
1182
1183 InnerString = std::string(Kind) + " " + ID + InnerString;
1184}