blob: 65fd3b40408ca81339615004b55aa8fde3738476 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Type.cpp - Type representation and manipulation ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements type-related functionality.
11//
12//===----------------------------------------------------------------------===//
13
Nuno Lopesb381aac2008-09-01 11:33:04 +000014#include "clang/AST/ASTContext.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000015#include "clang/AST/Type.h"
Argyrios Kyrtzidis49aa7ff2008-08-07 20:55:28 +000016#include "clang/AST/DeclCXX.h"
Steve Naroff980e5082007-10-01 19:00:59 +000017#include "clang/AST/DeclObjC.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000018#include "clang/AST/Expr.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000019#include "llvm/ADT/StringExtras.h"
Ted Kremenek7360fda2008-09-18 23:09:54 +000020
Reid Spencer5f016e22007-07-11 17:01:13 +000021using namespace clang;
22
Chris Lattner4bbce992009-01-12 00:10:42 +000023bool QualType::isConstant(ASTContext &Ctx) const {
Nuno Lopesb381aac2008-09-01 11:33:04 +000024 if (isConstQualified())
25 return true;
26
27 if (getTypePtr()->isArrayType())
28 return Ctx.getAsArrayType(*this)->getElementType().isConstant(Ctx);
29
30 return false;
31}
32
Ted Kremenek566c2ba2009-01-19 21:31:22 +000033void Type::Destroy(ASTContext& C) {
34 this->~Type();
Steve Naroff3e970492009-01-27 21:25:57 +000035 C.Deallocate(this);
Ted Kremenek4b05b1d2008-05-21 16:38:54 +000036}
37
38void VariableArrayType::Destroy(ASTContext& C) {
39 SizeExpr->Destroy(C);
Ted Kremenek566c2ba2009-01-19 21:31:22 +000040 this->~VariableArrayType();
Steve Naroff3e970492009-01-27 21:25:57 +000041 C.Deallocate(this);
Ted Kremenek4b05b1d2008-05-21 16:38:54 +000042}
Reid Spencer5f016e22007-07-11 17:01:13 +000043
Douglas Gregor898574e2008-12-05 23:32:09 +000044void DependentSizedArrayType::Destroy(ASTContext& C) {
45 SizeExpr->Destroy(C);
Ted Kremenek566c2ba2009-01-19 21:31:22 +000046 this->~DependentSizedArrayType();
Steve Naroff3e970492009-01-27 21:25:57 +000047 C.Deallocate(this);
Douglas Gregor898574e2008-12-05 23:32:09 +000048}
Chris Lattnerc63a1f22008-08-04 07:31:14 +000049
50/// getArrayElementTypeNoTypeQual - If this is an array type, return the
51/// element type of the array, potentially with type qualifiers missing.
52/// This method should never be used when type qualifiers are meaningful.
53const Type *Type::getArrayElementTypeNoTypeQual() const {
54 // If this is directly an array type, return it.
55 if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
56 return ATy->getElementType().getTypePtr();
57
58 // If the canonical form of this type isn't the right kind, reject it.
59 if (!isa<ArrayType>(CanonicalType)) {
60 // Look through type qualifiers
61 if (ArrayType *AT = dyn_cast<ArrayType>(CanonicalType.getUnqualifiedType()))
62 return AT->getElementType().getTypePtr();
63 return 0;
64 }
65
66 // If this is a typedef for an array type, strip the typedef off without
67 // losing all typedef information.
68 return getDesugaredType()->getArrayElementTypeNoTypeQual();
69}
70
71/// getDesugaredType - Return the specified type with any "sugar" removed from
72/// type type. This takes off typedefs, typeof's etc. If the outer level of
73/// the type is already concrete, it returns it unmodified. This is similar
74/// to getting the canonical type, but it doesn't remove *all* typedefs. For
75/// example, it return "T*" as "T*", (not as "int*"), because the pointer is
76/// concrete.
77QualType Type::getDesugaredType() const {
78 if (const TypedefType *TDT = dyn_cast<TypedefType>(this))
79 return TDT->LookThroughTypedefs();
80 if (const TypeOfExpr *TOE = dyn_cast<TypeOfExpr>(this))
81 return TOE->getUnderlyingExpr()->getType();
82 if (const TypeOfType *TOT = dyn_cast<TypeOfType>(this))
83 return TOT->getUnderlyingType();
84 // FIXME: remove this cast.
85 return QualType(const_cast<Type*>(this), 0);
86}
87
Reid Spencer5f016e22007-07-11 17:01:13 +000088/// isVoidType - Helper method to determine if this is the 'void' type.
89bool Type::isVoidType() const {
90 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
91 return BT->getKind() == BuiltinType::Void;
Chris Lattner4bbce992009-01-12 00:10:42 +000092 if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType))
93 return AS->getBaseType()->isVoidType();
Reid Spencer5f016e22007-07-11 17:01:13 +000094 return false;
95}
96
97bool Type::isObjectType() const {
98 if (isa<FunctionType>(CanonicalType))
99 return false;
Chris Lattner4bbce992009-01-12 00:10:42 +0000100 if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType))
101 return AS->getBaseType()->isObjectType();
102 return !CanonicalType->isIncompleteType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000103}
104
105bool Type::isDerivedType() const {
106 switch (CanonicalType->getTypeClass()) {
Chris Lattner4bbce992009-01-12 00:10:42 +0000107 case ASQual:
108 return cast<ASQualType>(CanonicalType)->getBaseType()->isDerivedType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000109 case Pointer:
Steve Narofffb22d962007-08-30 01:06:46 +0000110 case VariableArray:
111 case ConstantArray:
Eli Friedmanc5773c42008-02-15 18:16:39 +0000112 case IncompleteArray:
Reid Spencer5f016e22007-07-11 17:01:13 +0000113 case FunctionProto:
114 case FunctionNoProto:
115 case Reference:
116 return true;
Chris Lattner4bbce992009-01-12 00:10:42 +0000117 case Tagged:
118 return !cast<TagType>(CanonicalType)->getDecl()->isEnum();
Reid Spencer5f016e22007-07-11 17:01:13 +0000119 default:
120 return false;
121 }
122}
123
Chris Lattner99dc9142008-04-13 18:59:07 +0000124bool Type::isClassType() const {
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000125 if (const RecordType *RT = getAsRecordType())
126 return RT->getDecl()->isClass();
Chris Lattner99dc9142008-04-13 18:59:07 +0000127 return false;
128}
Chris Lattnerc8629632007-07-31 19:29:30 +0000129bool Type::isStructureType() const {
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000130 if (const RecordType *RT = getAsRecordType())
131 return RT->getDecl()->isStruct();
Chris Lattnerc8629632007-07-31 19:29:30 +0000132 return false;
133}
134bool Type::isUnionType() const {
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000135 if (const RecordType *RT = getAsRecordType())
136 return RT->getDecl()->isUnion();
Chris Lattnerc8629632007-07-31 19:29:30 +0000137 return false;
138}
Chris Lattnerc8629632007-07-31 19:29:30 +0000139
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000140bool Type::isComplexType() const {
Steve Naroff02f62a92008-01-15 19:36:10 +0000141 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
142 return CT->getElementType()->isFloatingType();
Chris Lattner4bbce992009-01-12 00:10:42 +0000143 if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType))
144 return AS->getBaseType()->isComplexType();
Steve Naroff02f62a92008-01-15 19:36:10 +0000145 return false;
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000146}
147
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000148bool Type::isComplexIntegerType() const {
149 // Check for GCC complex integer extension.
150 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
151 return CT->getElementType()->isIntegerType();
Chris Lattner4bbce992009-01-12 00:10:42 +0000152 if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType))
153 return AS->getBaseType()->isComplexIntegerType();
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000154 return false;
155}
156
157const ComplexType *Type::getAsComplexIntegerType() const {
158 // Are we directly a complex type?
159 if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) {
160 if (CTy->getElementType()->isIntegerType())
161 return CTy;
Chris Lattner4bbce992009-01-12 00:10:42 +0000162 return 0;
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000163 }
Chris Lattner4bbce992009-01-12 00:10:42 +0000164
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000165 // If the canonical form of this type isn't what we want, reject it.
166 if (!isa<ComplexType>(CanonicalType)) {
167 // Look through type qualifiers (e.g. ASQualType's).
168 if (isa<ComplexType>(CanonicalType.getUnqualifiedType()))
169 return CanonicalType.getUnqualifiedType()->getAsComplexIntegerType();
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000170 return 0;
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000171 }
172
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000173 // If this is a typedef for a complex type, strip the typedef off without
174 // losing all typedef information.
175 return getDesugaredType()->getAsComplexIntegerType();
176}
177
Steve Naroff77878cc2007-08-27 04:08:11 +0000178const BuiltinType *Type::getAsBuiltinType() const {
179 // If this is directly a builtin type, return it.
180 if (const BuiltinType *BTy = dyn_cast<BuiltinType>(this))
181 return BTy;
Chris Lattnerdea61462007-10-29 03:41:11 +0000182
183 // If the canonical form of this type isn't a builtin type, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000184 if (!isa<BuiltinType>(CanonicalType)) {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000185 // Look through type qualifiers (e.g. ASQualType's).
Christopher Lambebb97e92008-02-04 02:31:56 +0000186 if (isa<BuiltinType>(CanonicalType.getUnqualifiedType()))
187 return CanonicalType.getUnqualifiedType()->getAsBuiltinType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000188 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000189 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000190
Steve Naroff77878cc2007-08-27 04:08:11 +0000191 // If this is a typedef for a builtin type, strip the typedef off without
192 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000193 return getDesugaredType()->getAsBuiltinType();
Steve Naroff77878cc2007-08-27 04:08:11 +0000194}
195
Chris Lattnerc8629632007-07-31 19:29:30 +0000196const FunctionType *Type::getAsFunctionType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000197 // If this is directly a function type, return it.
198 if (const FunctionType *FTy = dyn_cast<FunctionType>(this))
199 return FTy;
Christopher Lambebb97e92008-02-04 02:31:56 +0000200
Chris Lattnerdea61462007-10-29 03:41:11 +0000201 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000202 if (!isa<FunctionType>(CanonicalType)) {
203 // Look through type qualifiers
204 if (isa<FunctionType>(CanonicalType.getUnqualifiedType()))
205 return CanonicalType.getUnqualifiedType()->getAsFunctionType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000206 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000207 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000208
Steve Naroff7064f5c2007-07-26 18:32:01 +0000209 // If this is a typedef for a function type, strip the typedef off without
210 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000211 return getDesugaredType()->getAsFunctionType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000212}
213
Chris Lattnerb77792e2008-07-26 22:17:49 +0000214const FunctionTypeProto *Type::getAsFunctionTypeProto() const {
215 return dyn_cast_or_null<FunctionTypeProto>(getAsFunctionType());
216}
217
218
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000219const PointerLikeType *Type::getAsPointerLikeType() const {
220 // If this is directly a pointer-like type, return it.
221 if (const PointerLikeType *PTy = dyn_cast<PointerLikeType>(this))
222 return PTy;
223
224 // If the canonical form of this type isn't the right kind, reject it.
225 if (!isa<PointerLikeType>(CanonicalType)) {
226 // Look through type qualifiers
227 if (isa<PointerLikeType>(CanonicalType.getUnqualifiedType()))
228 return CanonicalType.getUnqualifiedType()->getAsPointerLikeType();
229 return 0;
230 }
231
232 // If this is a typedef for a pointer type, strip the typedef off without
233 // losing all typedef information.
234 return getDesugaredType()->getAsPointerLikeType();
235}
236
Chris Lattnerbefee482007-07-31 16:53:04 +0000237const PointerType *Type::getAsPointerType() const {
Chris Lattner7a2e0472007-07-16 00:23:25 +0000238 // If this is directly a pointer type, return it.
239 if (const PointerType *PTy = dyn_cast<PointerType>(this))
240 return PTy;
Chris Lattnera2c77672007-07-16 22:05:22 +0000241
Chris Lattnerdea61462007-10-29 03:41:11 +0000242 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000243 if (!isa<PointerType>(CanonicalType)) {
244 // Look through type qualifiers
245 if (isa<PointerType>(CanonicalType.getUnqualifiedType()))
246 return CanonicalType.getUnqualifiedType()->getAsPointerType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000247 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000248 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000249
Chris Lattnera2c77672007-07-16 22:05:22 +0000250 // If this is a typedef for a pointer type, strip the typedef off without
251 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000252 return getDesugaredType()->getAsPointerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000253}
254
Steve Naroff5618bd42008-08-27 16:04:49 +0000255const BlockPointerType *Type::getAsBlockPointerType() const {
256 // If this is directly a block pointer type, return it.
257 if (const BlockPointerType *PTy = dyn_cast<BlockPointerType>(this))
258 return PTy;
259
260 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000261 if (!isa<BlockPointerType>(CanonicalType)) {
262 // Look through type qualifiers
263 if (isa<BlockPointerType>(CanonicalType.getUnqualifiedType()))
264 return CanonicalType.getUnqualifiedType()->getAsBlockPointerType();
Steve Naroff5618bd42008-08-27 16:04:49 +0000265 return 0;
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000266 }
Steve Naroff5618bd42008-08-27 16:04:49 +0000267
268 // If this is a typedef for a block pointer type, strip the typedef off
269 // without losing all typedef information.
270 return getDesugaredType()->getAsBlockPointerType();
271}
272
Chris Lattnera1d9fde2007-07-31 16:56:34 +0000273const ReferenceType *Type::getAsReferenceType() const {
Bill Wendlingea5e79f2007-07-17 04:16:47 +0000274 // If this is directly a reference type, return it.
275 if (const ReferenceType *RTy = dyn_cast<ReferenceType>(this))
276 return RTy;
277
Chris Lattnerdea61462007-10-29 03:41:11 +0000278 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000279 if (!isa<ReferenceType>(CanonicalType)) {
280 // Look through type qualifiers
281 if (isa<ReferenceType>(CanonicalType.getUnqualifiedType()))
282 return CanonicalType.getUnqualifiedType()->getAsReferenceType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000283 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000284 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000285
Bill Wendlingea5e79f2007-07-17 04:16:47 +0000286 // If this is a typedef for a reference type, strip the typedef off without
287 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000288 return getDesugaredType()->getAsReferenceType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000289}
290
Sebastian Redlf30208a2009-01-24 21:16:55 +0000291const MemberPointerType *Type::getAsMemberPointerType() const {
292 // If this is directly a member pointer type, return it.
293 if (const MemberPointerType *MTy = dyn_cast<MemberPointerType>(this))
294 return MTy;
295
296 // If the canonical form of this type isn't the right kind, reject it.
297 if (!isa<MemberPointerType>(CanonicalType)) {
298 // Look through type qualifiers
299 if (isa<MemberPointerType>(CanonicalType.getUnqualifiedType()))
300 return CanonicalType.getUnqualifiedType()->getAsMemberPointerType();
301 return 0;
302 }
303
304 // If this is a typedef for a member pointer type, strip the typedef off
305 // without losing all typedef information.
306 return getDesugaredType()->getAsMemberPointerType();
307}
308
Eli Friedmand3f2f792008-02-17 00:59:11 +0000309/// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length
310/// array types and types that contain variable array types in their
311/// declarator
Steve Naroffd7444aa2007-08-31 17:20:07 +0000312bool Type::isVariablyModifiedType() const {
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000313 // A VLA is a variably modified type.
314 if (isVariableArrayType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000315 return true;
316
317 // An array can contain a variably modified type
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000318 if (const Type *T = getArrayElementTypeNoTypeQual())
319 return T->isVariablyModifiedType();
Eli Friedmand3f2f792008-02-17 00:59:11 +0000320
Sebastian Redlf30208a2009-01-24 21:16:55 +0000321 // A pointer can point to a variably modified type.
322 // Also, C++ references and member pointers can point to a variably modified
323 // type, where VLAs appear as an extension to C++, and should be treated
324 // correctly.
325 if (const PointerLikeType *PT = getAsPointerLikeType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000326 return PT->getPointeeType()->isVariablyModifiedType();
Sebastian Redl8edef7c2009-01-24 23:29:36 +0000327 if (const MemberPointerType *PT = getAsMemberPointerType())
328 return PT->getPointeeType()->isVariablyModifiedType();
Eli Friedmand3f2f792008-02-17 00:59:11 +0000329
330 // A function can return a variably modified type
331 // This one isn't completely obvious, but it follows from the
332 // definition in C99 6.7.5p3. Because of this rule, it's
333 // illegal to declare a function returning a variably modified type.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000334 if (const FunctionType *FT = getAsFunctionType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000335 return FT->getResultType()->isVariablyModifiedType();
336
Steve Naroffd7444aa2007-08-31 17:20:07 +0000337 return false;
338}
339
Chris Lattnerc8629632007-07-31 19:29:30 +0000340const RecordType *Type::getAsRecordType() const {
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000341 // If this is directly a reference type, return it.
342 if (const RecordType *RTy = dyn_cast<RecordType>(this))
343 return RTy;
344
Chris Lattnerdea61462007-10-29 03:41:11 +0000345 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000346 if (!isa<RecordType>(CanonicalType)) {
347 // Look through type qualifiers
348 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
349 return CanonicalType.getUnqualifiedType()->getAsRecordType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000350 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000351 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000352
353 // If this is a typedef for a record type, strip the typedef off without
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000354 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000355 return getDesugaredType()->getAsRecordType();
Steve Naroffdfa6aae2007-07-26 03:11:44 +0000356}
357
Chris Lattnerc8629632007-07-31 19:29:30 +0000358const RecordType *Type::getAsStructureType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000359 // If this is directly a structure type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000360 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000361 if (RT->getDecl()->isStruct())
Chris Lattnerc8629632007-07-31 19:29:30 +0000362 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000363 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000364
365 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000366 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000367 if (!RT->getDecl()->isStruct())
Chris Lattnerdea61462007-10-29 03:41:11 +0000368 return 0;
369
370 // If this is a typedef for a structure type, strip the typedef off without
371 // losing all typedef information.
372 return getDesugaredType()->getAsStructureType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000373 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000374 // Look through type qualifiers
375 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
376 return CanonicalType.getUnqualifiedType()->getAsStructureType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000377 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000378}
379
Chris Lattnerc8629632007-07-31 19:29:30 +0000380const RecordType *Type::getAsUnionType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000381 // If this is directly a union type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000382 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000383 if (RT->getDecl()->isUnion())
Chris Lattnerc8629632007-07-31 19:29:30 +0000384 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000385 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000386
Chris Lattnerdea61462007-10-29 03:41:11 +0000387 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000388 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000389 if (!RT->getDecl()->isUnion())
Chris Lattnerdea61462007-10-29 03:41:11 +0000390 return 0;
391
392 // If this is a typedef for a union type, strip the typedef off without
393 // losing all typedef information.
394 return getDesugaredType()->getAsUnionType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000395 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000396
397 // Look through type qualifiers
398 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
399 return CanonicalType.getUnqualifiedType()->getAsUnionType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000400 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000401}
402
Eli Friedmanad74a752008-06-28 06:23:08 +0000403const EnumType *Type::getAsEnumType() const {
404 // Check the canonicalized unqualified type directly; the more complex
405 // version is unnecessary because there isn't any typedef information
406 // to preserve.
407 return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType());
408}
409
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000410const ComplexType *Type::getAsComplexType() const {
411 // Are we directly a complex type?
412 if (const ComplexType *CTy = dyn_cast<ComplexType>(this))
413 return CTy;
414
Chris Lattnerdea61462007-10-29 03:41:11 +0000415 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000416 if (!isa<ComplexType>(CanonicalType)) {
417 // Look through type qualifiers
418 if (isa<ComplexType>(CanonicalType.getUnqualifiedType()))
419 return CanonicalType.getUnqualifiedType()->getAsComplexType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000420 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000421 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000422
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000423 // If this is a typedef for a complex type, strip the typedef off without
424 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000425 return getDesugaredType()->getAsComplexType();
Chris Lattner7a2e0472007-07-16 00:23:25 +0000426}
427
Chris Lattnerc8629632007-07-31 19:29:30 +0000428const VectorType *Type::getAsVectorType() const {
Chris Lattner7a2e0472007-07-16 00:23:25 +0000429 // Are we directly a vector type?
430 if (const VectorType *VTy = dyn_cast<VectorType>(this))
431 return VTy;
Chris Lattnera2c77672007-07-16 22:05:22 +0000432
Chris Lattnerdea61462007-10-29 03:41:11 +0000433 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000434 if (!isa<VectorType>(CanonicalType)) {
435 // Look through type qualifiers
436 if (isa<VectorType>(CanonicalType.getUnqualifiedType()))
437 return CanonicalType.getUnqualifiedType()->getAsVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000438 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000439 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000440
Chris Lattnera2c77672007-07-16 22:05:22 +0000441 // If this is a typedef for a vector type, strip the typedef off without
442 // losing all typedef information.
Chris Lattnerdea61462007-10-29 03:41:11 +0000443 return getDesugaredType()->getAsVectorType();
Chris Lattner7a2e0472007-07-16 00:23:25 +0000444}
445
Nate Begeman213541a2008-04-18 23:10:10 +0000446const ExtVectorType *Type::getAsExtVectorType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000447 // Are we directly an OpenCU vector type?
Nate Begeman213541a2008-04-18 23:10:10 +0000448 if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this))
Steve Naroff7064f5c2007-07-26 18:32:01 +0000449 return VTy;
450
Chris Lattnerdea61462007-10-29 03:41:11 +0000451 // If the canonical form of this type isn't the right kind, reject it.
Nate Begeman213541a2008-04-18 23:10:10 +0000452 if (!isa<ExtVectorType>(CanonicalType)) {
Christopher Lambebb97e92008-02-04 02:31:56 +0000453 // Look through type qualifiers
Nate Begeman213541a2008-04-18 23:10:10 +0000454 if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType()))
455 return CanonicalType.getUnqualifiedType()->getAsExtVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000456 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000457 }
Steve Naroff7064f5c2007-07-26 18:32:01 +0000458
Nate Begeman213541a2008-04-18 23:10:10 +0000459 // If this is a typedef for an extended vector type, strip the typedef off
460 // without losing all typedef information.
461 return getDesugaredType()->getAsExtVectorType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000462}
463
Chris Lattner368eefa2008-04-07 00:27:04 +0000464const ObjCInterfaceType *Type::getAsObjCInterfaceType() const {
Chris Lattnereca7be62008-04-07 05:30:13 +0000465 // There is no sugar for ObjCInterfaceType's, just return the canonical
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000466 // type pointer if it is the right class. There is no typedef information to
467 // return and these cannot be Address-space qualified.
Chris Lattnereca7be62008-04-07 05:30:13 +0000468 return dyn_cast<ObjCInterfaceType>(CanonicalType);
Chris Lattner368eefa2008-04-07 00:27:04 +0000469}
470
471const ObjCQualifiedInterfaceType *
472Type::getAsObjCQualifiedInterfaceType() const {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000473 // There is no sugar for ObjCQualifiedInterfaceType's, just return the
474 // canonical type pointer if it is the right class.
Chris Lattnereca7be62008-04-07 05:30:13 +0000475 return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType);
476}
477
478const ObjCQualifiedIdType *Type::getAsObjCQualifiedIdType() const {
479 // There is no sugar for ObjCQualifiedIdType's, just return the canonical
480 // type pointer if it is the right class.
481 return dyn_cast<ObjCQualifiedIdType>(CanonicalType);
Chris Lattner368eefa2008-04-07 00:27:04 +0000482}
483
Douglas Gregor72c3f312008-12-05 18:15:24 +0000484const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const {
485 // There is no sugar for template type parameters, so just return
486 // the canonical type pointer if it is the right class.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000487 // FIXME: can these be address-space qualified?
Douglas Gregor72c3f312008-12-05 18:15:24 +0000488 return dyn_cast<TemplateTypeParmType>(CanonicalType);
489}
Chris Lattner368eefa2008-04-07 00:27:04 +0000490
Reid Spencer5f016e22007-07-11 17:01:13 +0000491bool Type::isIntegerType() const {
492 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
493 return BT->getKind() >= BuiltinType::Bool &&
494 BT->getKind() <= BuiltinType::LongLong;
495 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000496 // Incomplete enum types are not treated as integer types.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000497 // FIXME: In C++, enum types are never integer types.
Chris Lattner834a72a2008-07-25 23:18:17 +0000498 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000499 return true;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000500 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
501 return VT->getElementType()->isIntegerType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000502 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
503 return ASQT->getBaseType()->isIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000504 return false;
505}
506
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000507bool Type::isIntegralType() const {
508 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
509 return BT->getKind() >= BuiltinType::Bool &&
510 BT->getKind() <= BuiltinType::LongLong;
511 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000512 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
513 return true; // Complete enum types are integral.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000514 // FIXME: In C++, enum types are never integral.
Christopher Lambebb97e92008-02-04 02:31:56 +0000515 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
516 return ASQT->getBaseType()->isIntegralType();
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000517 return false;
518}
519
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000520bool Type::isEnumeralType() const {
521 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000522 return TT->getDecl()->isEnum();
Christopher Lambebb97e92008-02-04 02:31:56 +0000523 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
524 return ASQT->getBaseType()->isEnumeralType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000525 return false;
526}
527
528bool Type::isBooleanType() const {
529 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
530 return BT->getKind() == BuiltinType::Bool;
Christopher Lambebb97e92008-02-04 02:31:56 +0000531 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
532 return ASQT->getBaseType()->isBooleanType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000533 return false;
534}
535
536bool Type::isCharType() const {
537 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
538 return BT->getKind() == BuiltinType::Char_U ||
539 BT->getKind() == BuiltinType::UChar ||
Anders Carlssonc67ad5f2007-10-29 02:52:18 +0000540 BT->getKind() == BuiltinType::Char_S ||
541 BT->getKind() == BuiltinType::SChar;
Christopher Lambebb97e92008-02-04 02:31:56 +0000542 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
543 return ASQT->getBaseType()->isCharType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000544 return false;
545}
546
Douglas Gregor77a52232008-09-12 00:47:35 +0000547bool Type::isWideCharType() const {
548 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
549 return BT->getKind() == BuiltinType::WChar;
550 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
551 return ASQT->getBaseType()->isWideCharType();
552 return false;
553}
554
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000555/// isSignedIntegerType - Return true if this is an integer type that is
556/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
557/// an enum decl which has a signed representation, or a vector of signed
558/// integer element type.
Reid Spencer5f016e22007-07-11 17:01:13 +0000559bool Type::isSignedIntegerType() const {
560 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
561 return BT->getKind() >= BuiltinType::Char_S &&
562 BT->getKind() <= BuiltinType::LongLong;
563 }
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000564
Chris Lattner37c1b782008-04-06 22:29:16 +0000565 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
566 return ET->getDecl()->getIntegerType()->isSignedIntegerType();
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000567
Steve Naroffc63b96a2007-07-12 21:46:55 +0000568 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
569 return VT->getElementType()->isSignedIntegerType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000570 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
571 return ASQT->getBaseType()->isSignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000572 return false;
573}
574
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000575/// isUnsignedIntegerType - Return true if this is an integer type that is
576/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
577/// decl which has an unsigned representation, or a vector of unsigned integer
578/// element type.
Reid Spencer5f016e22007-07-11 17:01:13 +0000579bool Type::isUnsignedIntegerType() const {
580 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
581 return BT->getKind() >= BuiltinType::Bool &&
582 BT->getKind() <= BuiltinType::ULongLong;
583 }
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000584
Chris Lattner37c1b782008-04-06 22:29:16 +0000585 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
586 return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000587
Steve Naroffc63b96a2007-07-12 21:46:55 +0000588 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
589 return VT->getElementType()->isUnsignedIntegerType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000590 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
591 return ASQT->getBaseType()->isUnsignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000592 return false;
593}
594
595bool Type::isFloatingType() const {
596 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
597 return BT->getKind() >= BuiltinType::Float &&
598 BT->getKind() <= BuiltinType::LongDouble;
599 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
Chris Lattner729a2132007-08-30 06:19:11 +0000600 return CT->getElementType()->isFloatingType();
Steve Naroffc63b96a2007-07-12 21:46:55 +0000601 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
602 return VT->getElementType()->isFloatingType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000603 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
604 return ASQT->getBaseType()->isFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000605 return false;
606}
607
608bool Type::isRealFloatingType() const {
609 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
610 return BT->getKind() >= BuiltinType::Float &&
611 BT->getKind() <= BuiltinType::LongDouble;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000612 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
613 return VT->getElementType()->isRealFloatingType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000614 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
615 return ASQT->getBaseType()->isRealFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000616 return false;
617}
618
619bool Type::isRealType() const {
620 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
621 return BT->getKind() >= BuiltinType::Bool &&
622 BT->getKind() <= BuiltinType::LongDouble;
623 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000624 return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition();
Steve Naroffc63b96a2007-07-12 21:46:55 +0000625 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
626 return VT->getElementType()->isRealType();
Christopher Lambebb97e92008-02-04 02:31:56 +0000627 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
628 return ASQT->getBaseType()->isRealType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000629 return false;
630}
631
Reid Spencer5f016e22007-07-11 17:01:13 +0000632bool Type::isArithmeticType() const {
633 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
Douglas Gregora7fbf722008-10-30 13:47:07 +0000634 return BT->getKind() >= BuiltinType::Bool &&
635 BT->getKind() <= BuiltinType::LongDouble;
Chris Lattner37c1b782008-04-06 22:29:16 +0000636 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
637 // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
638 // If a body isn't seen by the time we get here, return false.
639 return ET->getDecl()->isDefinition();
Christopher Lambebb97e92008-02-04 02:31:56 +0000640 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
641 return ASQT->getBaseType()->isArithmeticType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000642 return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType);
643}
644
645bool Type::isScalarType() const {
646 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
647 return BT->getKind() != BuiltinType::Void;
648 if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
Chris Lattner834a72a2008-07-25 23:18:17 +0000649 // Enums are scalar types, but only if they are defined. Incomplete enums
650 // are not treated as scalar types.
651 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000652 return true;
653 return false;
654 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000655 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
656 return ASQT->getBaseType()->isScalarType();
Steve Naroff5618bd42008-08-27 16:04:49 +0000657 return isa<PointerType>(CanonicalType) ||
658 isa<BlockPointerType>(CanonicalType) ||
Sebastian Redlf30208a2009-01-24 21:16:55 +0000659 isa<MemberPointerType>(CanonicalType) ||
Steve Naroff5618bd42008-08-27 16:04:49 +0000660 isa<ComplexType>(CanonicalType) ||
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000661 isa<ObjCQualifiedIdType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000662}
663
664bool Type::isAggregateType() const {
665 if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000666 if (TT->getDecl()->isStruct())
Reid Spencer5f016e22007-07-11 17:01:13 +0000667 return true;
668 return false;
669 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000670 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
671 return ASQT->getBaseType()->isAggregateType();
Eli Friedmanc5773c42008-02-15 18:16:39 +0000672 return isa<ArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000673}
674
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000675/// isConstantSizeType - Return true if this is not a variable sized type,
676/// according to the rules of C99 6.7.5p3. It is not legal to call this on
Douglas Gregor898574e2008-12-05 23:32:09 +0000677/// incomplete types or dependent types.
Eli Friedman3c2b3172008-02-15 12:20:59 +0000678bool Type::isConstantSizeType() const {
Christopher Lambebb97e92008-02-04 02:31:56 +0000679 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
Eli Friedman3c2b3172008-02-15 12:20:59 +0000680 return ASQT->getBaseType()->isConstantSizeType();
Chris Lattnerd52a4572007-12-18 07:03:30 +0000681 assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
Douglas Gregor898574e2008-12-05 23:32:09 +0000682 assert(!isDependentType() && "This doesn't make sense for dependent types");
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000683 // The VAT must have a size, as it is known to be complete.
684 return !isa<VariableArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000685}
686
687/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
688/// - a type that can describe objects, but which lacks information needed to
689/// determine its size.
690bool Type::isIncompleteType() const {
691 switch (CanonicalType->getTypeClass()) {
692 default: return false;
Christopher Lambebb97e92008-02-04 02:31:56 +0000693 case ASQual:
694 return cast<ASQualType>(CanonicalType)->getBaseType()->isIncompleteType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000695 case Builtin:
696 // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
697 // be completed.
698 return isVoidType();
699 case Tagged:
700 // A tagged type (struct/union/enum/class) is incomplete if the decl is a
701 // forward declaration, but not a full definition (C99 6.2.5p22).
702 return !cast<TagType>(CanonicalType)->getDecl()->isDefinition();
Eli Friedmanc5773c42008-02-15 18:16:39 +0000703 case IncompleteArray:
Reid Spencer5f016e22007-07-11 17:01:13 +0000704 // An array of unknown size is an incomplete type (C99 6.2.5p22).
Eli Friedmanc5773c42008-02-15 18:16:39 +0000705 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000706 }
707}
708
Sebastian Redl64b45f72009-01-05 20:52:13 +0000709/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10)
710bool Type::isPODType() const {
711 // The compiler shouldn't query this for incomplete types, but the user might.
712 // We return false for that case.
713 if (isIncompleteType())
714 return false;
715
716 switch (CanonicalType->getTypeClass()) {
717 // Everything not explicitly mentioned is not POD.
718 default: return false;
719 case ASQual:
720 return cast<ASQualType>(CanonicalType)->getBaseType()->isPODType();
721 case VariableArray:
722 case ConstantArray:
723 // IncompleteArray is caught by isIncompleteType() above.
724 return cast<ArrayType>(CanonicalType)->getElementType()->isPODType();
725
726 case Builtin:
727 case Complex:
728 case Pointer:
Sebastian Redlf30208a2009-01-24 21:16:55 +0000729 case MemberPointer:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000730 case Vector:
731 case ExtVector:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000732 return true;
733
734 case Tagged:
735 if (isEnumeralType())
736 return true;
737 if (CXXRecordDecl *RDecl = dyn_cast<CXXRecordDecl>(
738 cast<TagType>(CanonicalType)->getDecl()))
739 return RDecl->isPOD();
740 // C struct/union is POD.
741 return true;
742 }
743}
744
Reid Spencer5f016e22007-07-11 17:01:13 +0000745bool Type::isPromotableIntegerType() const {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000746 if (const BuiltinType *BT = getAsBuiltinType())
747 switch (BT->getKind()) {
748 case BuiltinType::Bool:
749 case BuiltinType::Char_S:
750 case BuiltinType::Char_U:
751 case BuiltinType::SChar:
752 case BuiltinType::UChar:
753 case BuiltinType::Short:
754 case BuiltinType::UShort:
755 return true;
756 default:
757 return false;
758 }
759 return false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000760}
761
762const char *BuiltinType::getName() const {
763 switch (getKind()) {
764 default: assert(0 && "Unknown builtin type!");
765 case Void: return "void";
766 case Bool: return "_Bool";
767 case Char_S: return "char";
768 case Char_U: return "char";
769 case SChar: return "signed char";
770 case Short: return "short";
771 case Int: return "int";
772 case Long: return "long";
773 case LongLong: return "long long";
774 case UChar: return "unsigned char";
775 case UShort: return "unsigned short";
776 case UInt: return "unsigned int";
777 case ULong: return "unsigned long";
778 case ULongLong: return "unsigned long long";
779 case Float: return "float";
780 case Double: return "double";
781 case LongDouble: return "long double";
Argyrios Kyrtzidis46713ef2008-08-09 17:11:33 +0000782 case WChar: return "wchar_t";
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000783 case Overload: return "<overloaded function type>";
Douglas Gregor898574e2008-12-05 23:32:09 +0000784 case Dependent: return "<dependent type>";
Reid Spencer5f016e22007-07-11 17:01:13 +0000785 }
786}
787
Reid Spencer5f016e22007-07-11 17:01:13 +0000788void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
Chris Lattner942cfd32007-07-20 18:48:28 +0000789 arg_type_iterator ArgTys,
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000790 unsigned NumArgs, bool isVariadic,
791 unsigned TypeQuals) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000792 ID.AddPointer(Result.getAsOpaquePtr());
793 for (unsigned i = 0; i != NumArgs; ++i)
794 ID.AddPointer(ArgTys[i].getAsOpaquePtr());
795 ID.AddInteger(isVariadic);
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000796 ID.AddInteger(TypeQuals);
Reid Spencer5f016e22007-07-11 17:01:13 +0000797}
798
799void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) {
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000800 Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(),
801 getTypeQuals());
Reid Spencer5f016e22007-07-11 17:01:13 +0000802}
803
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000804void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
Chris Lattner1ee07002008-04-07 06:37:47 +0000805 const ObjCInterfaceDecl *Decl,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000806 ObjCProtocolDecl **protocols,
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000807 unsigned NumProtocols) {
Chris Lattner1ee07002008-04-07 06:37:47 +0000808 ID.AddPointer(Decl);
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000809 for (unsigned i = 0; i != NumProtocols; i++)
810 ID.AddPointer(protocols[i]);
811}
812
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000813void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
Chris Lattner1ee07002008-04-07 06:37:47 +0000814 Profile(ID, getDecl(), &Protocols[0], getNumProtocols());
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000815}
816
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000817void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID,
Chris Lattner62f5f7f2008-07-26 00:46:50 +0000818 ObjCProtocolDecl **protocols,
819 unsigned NumProtocols) {
Fariborz Jahanianc5692492007-12-17 21:03:50 +0000820 for (unsigned i = 0; i != NumProtocols; i++)
821 ID.AddPointer(protocols[i]);
822}
823
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000824void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) {
Fariborz Jahanianc5692492007-12-17 21:03:50 +0000825 Profile(ID, &Protocols[0], getNumProtocols());
826}
827
Chris Lattnera2c77672007-07-16 22:05:22 +0000828/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
829/// potentially looking through *all* consequtive typedefs. This returns the
830/// sum of the type qualifiers, so if you have:
831/// typedef const int A;
832/// typedef volatile A B;
833/// looking through the typedefs for B will give you "const volatile A".
834///
835QualType TypedefType::LookThroughTypedefs() const {
836 // Usually, there is only a single level of typedefs, be fast in that case.
837 QualType FirstType = getDecl()->getUnderlyingType();
838 if (!isa<TypedefType>(FirstType))
839 return FirstType;
840
841 // Otherwise, do the fully general loop.
842 unsigned TypeQuals = 0;
843 const TypedefType *TDT = this;
844 while (1) {
845 QualType CurType = TDT->getDecl()->getUnderlyingType();
Chris Lattnerf46699c2008-02-20 20:55:12 +0000846
847
848 /// FIXME:
849 /// FIXME: This is incorrect for ASQuals!
850 /// FIXME:
851 TypeQuals |= CurType.getCVRQualifiers();
Chris Lattnera2c77672007-07-16 22:05:22 +0000852
853 TDT = dyn_cast<TypedefType>(CurType);
854 if (TDT == 0)
855 return QualType(CurType.getTypePtr(), TypeQuals);
856 }
857}
Reid Spencer5f016e22007-07-11 17:01:13 +0000858
Douglas Gregor898574e2008-12-05 23:32:09 +0000859TypeOfExpr::TypeOfExpr(Expr *E, QualType can)
860 : Type(TypeOfExp, can, E->isTypeDependent()), TOExpr(E) {
861 assert(!isa<TypedefType>(can) && "Invalid canonical type");
862}
863
Chris Lattner2daa5df2008-04-06 22:04:54 +0000864bool RecordType::classof(const TagType *TT) {
865 return isa<RecordDecl>(TT->getDecl());
Reid Spencer5f016e22007-07-11 17:01:13 +0000866}
867
Argyrios Kyrtzidis49aa7ff2008-08-07 20:55:28 +0000868bool CXXRecordType::classof(const TagType *TT) {
869 return isa<CXXRecordDecl>(TT->getDecl());
870}
871
Chris Lattner2daa5df2008-04-06 22:04:54 +0000872bool EnumType::classof(const TagType *TT) {
873 return isa<EnumDecl>(TT->getDecl());
Chris Lattner5edb8bf2008-04-06 21:58:47 +0000874}
875
Anders Carlsson97e01792008-12-21 00:16:32 +0000876
Reid Spencer5f016e22007-07-11 17:01:13 +0000877//===----------------------------------------------------------------------===//
878// Type Printing
879//===----------------------------------------------------------------------===//
880
881void QualType::dump(const char *msg) const {
Chris Lattner39caea92007-12-06 04:20:07 +0000882 std::string R = "identifier";
Reid Spencer5f016e22007-07-11 17:01:13 +0000883 getAsStringInternal(R);
884 if (msg)
885 fprintf(stderr, "%s: %s\n", msg, R.c_str());
886 else
887 fprintf(stderr, "%s\n", R.c_str());
888}
Chris Lattnerc36d4052008-07-27 00:48:22 +0000889void QualType::dump() const {
890 dump("");
891}
892
893void Type::dump() const {
894 std::string S = "identifier";
895 getAsStringInternal(S);
896 fprintf(stderr, "%s\n", S.c_str());
897}
898
899
Reid Spencer5f016e22007-07-11 17:01:13 +0000900
901static void AppendTypeQualList(std::string &S, unsigned TypeQuals) {
902 // Note: funkiness to ensure we get a space only between quals.
903 bool NonePrinted = true;
904 if (TypeQuals & QualType::Const)
905 S += "const", NonePrinted = false;
906 if (TypeQuals & QualType::Volatile)
907 S += (NonePrinted+" volatile"), NonePrinted = false;
908 if (TypeQuals & QualType::Restrict)
909 S += (NonePrinted+" restrict"), NonePrinted = false;
910}
911
912void QualType::getAsStringInternal(std::string &S) const {
913 if (isNull()) {
Douglas Gregor61366e92008-12-24 00:01:03 +0000914 S += "NULL TYPE";
Reid Spencer5f016e22007-07-11 17:01:13 +0000915 return;
916 }
917
918 // Print qualifiers as appropriate.
Gabor Greif3513e132008-02-21 17:40:55 +0000919 if (unsigned Tq = getCVRQualifiers()) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000920 std::string TQS;
Gabor Greif3513e132008-02-21 17:40:55 +0000921 AppendTypeQualList(TQS, Tq);
Reid Spencer5f016e22007-07-11 17:01:13 +0000922 if (!S.empty())
923 S = TQS + ' ' + S;
924 else
925 S = TQS;
926 }
927
928 getTypePtr()->getAsStringInternal(S);
929}
930
931void BuiltinType::getAsStringInternal(std::string &S) const {
932 if (S.empty()) {
933 S = getName();
934 } else {
935 // Prefix the basic type, e.g. 'int X'.
936 S = ' ' + S;
937 S = getName() + S;
938 }
939}
940
941void ComplexType::getAsStringInternal(std::string &S) const {
942 ElementType->getAsStringInternal(S);
943 S = "_Complex " + S;
944}
945
Christopher Lambebb97e92008-02-04 02:31:56 +0000946void ASQualType::getAsStringInternal(std::string &S) const {
947 S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S;
948 BaseType->getAsStringInternal(S);
949}
950
Reid Spencer5f016e22007-07-11 17:01:13 +0000951void PointerType::getAsStringInternal(std::string &S) const {
952 S = '*' + S;
953
954 // Handle things like 'int (*A)[4];' correctly.
955 // FIXME: this should include vectors, but vectors use attributes I guess.
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000956 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +0000957 S = '(' + S + ')';
958
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000959 getPointeeType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000960}
961
Steve Naroff5618bd42008-08-27 16:04:49 +0000962void BlockPointerType::getAsStringInternal(std::string &S) const {
963 S = '^' + S;
964 PointeeType.getAsStringInternal(S);
965}
966
Reid Spencer5f016e22007-07-11 17:01:13 +0000967void ReferenceType::getAsStringInternal(std::string &S) const {
968 S = '&' + S;
969
970 // Handle things like 'int (&A)[4];' correctly.
971 // FIXME: this should include vectors, but vectors use attributes I guess.
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000972 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +0000973 S = '(' + S + ')';
974
Chris Lattnerbdcd6372008-04-02 17:35:06 +0000975 getPointeeType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000976}
977
Sebastian Redlf30208a2009-01-24 21:16:55 +0000978void MemberPointerType::getAsStringInternal(std::string &S) const {
979 std::string C;
980 Class->getAsStringInternal(C);
981 C += "::*";
982 S = C + S;
983
984 // Handle things like 'int (&A)[4];' correctly.
985 // FIXME: this should include vectors, but vectors use attributes I guess.
986 if (isa<ArrayType>(getPointeeType()))
987 S = '(' + S + ')';
988
989 getPointeeType().getAsStringInternal(S);
990}
991
Steve Narofffb22d962007-08-30 01:06:46 +0000992void ConstantArrayType::getAsStringInternal(std::string &S) const {
993 S += '[';
Steve Naroff6b91cd92007-08-30 18:45:57 +0000994 S += llvm::utostr(getSize().getZExtValue());
Steve Narofffb22d962007-08-30 01:06:46 +0000995 S += ']';
996
997 getElementType().getAsStringInternal(S);
998}
999
Eli Friedmanc5773c42008-02-15 18:16:39 +00001000void IncompleteArrayType::getAsStringInternal(std::string &S) const {
1001 S += "[]";
1002
1003 getElementType().getAsStringInternal(S);
1004}
1005
Steve Narofffb22d962007-08-30 01:06:46 +00001006void VariableArrayType::getAsStringInternal(std::string &S) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001007 S += '[';
1008
Steve Naroffc9406122007-08-30 18:10:14 +00001009 if (getIndexTypeQualifier()) {
1010 AppendTypeQualList(S, getIndexTypeQualifier());
Reid Spencer5f016e22007-07-11 17:01:13 +00001011 S += ' ';
1012 }
1013
Steve Naroffc9406122007-08-30 18:10:14 +00001014 if (getSizeModifier() == Static)
Reid Spencer5f016e22007-07-11 17:01:13 +00001015 S += "static";
Steve Naroffc9406122007-08-30 18:10:14 +00001016 else if (getSizeModifier() == Star)
Reid Spencer5f016e22007-07-11 17:01:13 +00001017 S += '*';
1018
Steve Narofffb22d962007-08-30 01:06:46 +00001019 if (getSizeExpr()) {
Ted Kremeneka95d3752008-09-13 05:16:45 +00001020 std::string SStr;
1021 llvm::raw_string_ostream s(SStr);
Steve Narofffb22d962007-08-30 01:06:46 +00001022 getSizeExpr()->printPretty(s);
1023 S += s.str();
1024 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001025 S += ']';
1026
Steve Narofffb22d962007-08-30 01:06:46 +00001027 getElementType().getAsStringInternal(S);
Reid Spencer5f016e22007-07-11 17:01:13 +00001028}
1029
Douglas Gregor898574e2008-12-05 23:32:09 +00001030void DependentSizedArrayType::getAsStringInternal(std::string &S) const {
1031 S += '[';
1032
1033 if (getIndexTypeQualifier()) {
1034 AppendTypeQualList(S, getIndexTypeQualifier());
1035 S += ' ';
1036 }
1037
1038 if (getSizeModifier() == Static)
1039 S += "static";
1040 else if (getSizeModifier() == Star)
1041 S += '*';
1042
1043 if (getSizeExpr()) {
1044 std::string SStr;
1045 llvm::raw_string_ostream s(SStr);
1046 getSizeExpr()->printPretty(s);
1047 S += s.str();
1048 }
1049 S += ']';
1050
1051 getElementType().getAsStringInternal(S);
1052}
1053
Reid Spencer5f016e22007-07-11 17:01:13 +00001054void VectorType::getAsStringInternal(std::string &S) const {
Daniel Dunbar5620b502008-10-05 05:43:11 +00001055 // FIXME: We prefer to print the size directly here, but have no way
1056 // to get the size of the type.
Chris Lattner7ee261c2007-11-27 07:28:18 +00001057 S += " __attribute__((__vector_size__(";
Daniel Dunbar5620b502008-10-05 05:43:11 +00001058 S += llvm::utostr_32(NumElements); // convert back to bytes.
1059 S += " * sizeof(" + ElementType.getAsString() + "))))";
Reid Spencer5f016e22007-07-11 17:01:13 +00001060}
1061
Nate Begeman213541a2008-04-18 23:10:10 +00001062void ExtVectorType::getAsStringInternal(std::string &S) const {
1063 S += " __attribute__((ext_vector_type(";
Steve Naroff31a45842007-07-28 23:10:27 +00001064 S += llvm::utostr_32(NumElements);
1065 S += ")))";
1066 ElementType.getAsStringInternal(S);
1067}
1068
Steve Naroffd1861fd2007-07-31 12:34:36 +00001069void TypeOfExpr::getAsStringInternal(std::string &InnerString) const {
Steve Naroff363bcff2007-08-01 23:45:51 +00001070 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'.
1071 InnerString = ' ' + InnerString;
Ted Kremeneka95d3752008-09-13 05:16:45 +00001072 std::string Str;
1073 llvm::raw_string_ostream s(Str);
Chris Lattner6000dac2007-08-08 22:51:59 +00001074 getUnderlyingExpr()->printPretty(s);
Steve Naroff1bfd5cc2007-08-05 03:24:45 +00001075 InnerString = "typeof(" + s.str() + ")" + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001076}
1077
Steve Naroff363bcff2007-08-01 23:45:51 +00001078void TypeOfType::getAsStringInternal(std::string &InnerString) const {
1079 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'.
1080 InnerString = ' ' + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001081 std::string Tmp;
1082 getUnderlyingType().getAsStringInternal(Tmp);
Steve Naroff363bcff2007-08-01 23:45:51 +00001083 InnerString = "typeof(" + Tmp + ")" + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001084}
1085
Reid Spencer5f016e22007-07-11 17:01:13 +00001086void FunctionTypeNoProto::getAsStringInternal(std::string &S) const {
1087 // If needed for precedence reasons, wrap the inner part in grouping parens.
1088 if (!S.empty())
1089 S = "(" + S + ")";
1090
1091 S += "()";
1092 getResultType().getAsStringInternal(S);
1093}
1094
1095void FunctionTypeProto::getAsStringInternal(std::string &S) const {
1096 // If needed for precedence reasons, wrap the inner part in grouping parens.
1097 if (!S.empty())
1098 S = "(" + S + ")";
1099
1100 S += "(";
1101 std::string Tmp;
1102 for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
1103 if (i) S += ", ";
1104 getArgType(i).getAsStringInternal(Tmp);
1105 S += Tmp;
1106 Tmp.clear();
1107 }
1108
1109 if (isVariadic()) {
1110 if (getNumArgs())
1111 S += ", ";
1112 S += "...";
1113 } else if (getNumArgs() == 0) {
1114 // Do not emit int() if we have a proto, emit 'int(void)'.
1115 S += "void";
1116 }
1117
1118 S += ")";
1119 getResultType().getAsStringInternal(S);
1120}
1121
1122
1123void TypedefType::getAsStringInternal(std::string &InnerString) const {
1124 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1125 InnerString = ' ' + InnerString;
1126 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1127}
1128
Douglas Gregor72c3f312008-12-05 18:15:24 +00001129void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const {
1130 if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'.
1131 InnerString = ' ' + InnerString;
1132 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1133}
1134
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001135void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const {
Steve Naroff3536b442007-09-06 21:24:23 +00001136 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1137 InnerString = ' ' + InnerString;
1138 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1139}
1140
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001141void ObjCQualifiedInterfaceType::getAsStringInternal(
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001142 std::string &InnerString) const {
Fariborz Jahaniandfbcce22007-10-11 18:08:47 +00001143 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1144 InnerString = ' ' + InnerString;
Chris Lattner39f34e92008-11-24 04:00:27 +00001145 std::string ObjCQIString = getDecl()->getNameAsString();
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001146 ObjCQIString += '<';
Chris Lattnercdce6d12008-07-21 05:19:23 +00001147 bool isFirst = true;
1148 for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) {
1149 if (isFirst)
1150 isFirst = false;
1151 else
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001152 ObjCQIString += ',';
Chris Lattner39f34e92008-11-24 04:00:27 +00001153 ObjCQIString += (*I)->getNameAsString();
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001154 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001155 ObjCQIString += '>';
1156 InnerString = ObjCQIString + InnerString;
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001157}
1158
Chris Lattnere8e4f922008-07-25 23:07:18 +00001159void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const {
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001160 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1161 InnerString = ' ' + InnerString;
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001162 std::string ObjCQIString = "id";
1163 ObjCQIString += '<';
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001164 int num = getNumProtocols();
1165 for (int i = 0; i < num; i++) {
Chris Lattner39f34e92008-11-24 04:00:27 +00001166 ObjCQIString += getProtocols(i)->getNameAsString();
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001167 if (i < num-1)
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001168 ObjCQIString += ',';
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001169 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001170 ObjCQIString += '>';
1171 InnerString = ObjCQIString + InnerString;
Fariborz Jahanianc5692492007-12-17 21:03:50 +00001172}
1173
Reid Spencer5f016e22007-07-11 17:01:13 +00001174void TagType::getAsStringInternal(std::string &InnerString) const {
1175 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1176 InnerString = ' ' + InnerString;
1177
1178 const char *Kind = getDecl()->getKindName();
1179 const char *ID;
1180 if (const IdentifierInfo *II = getDecl()->getIdentifier())
1181 ID = II->getName();
1182 else
1183 ID = "<anonymous>";
1184
1185 InnerString = std::string(Kind) + " " + ID + InnerString;
1186}