blob: 1a6ea0a136676744228e7cf831132409ffe74045 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Type.cpp - Type representation and manipulation ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements type-related functionality.
11//
12//===----------------------------------------------------------------------===//
13
Nuno Lopesb381aac2008-09-01 11:33:04 +000014#include "clang/AST/ASTContext.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000015#include "clang/AST/Type.h"
Argyrios Kyrtzidis49aa7ff2008-08-07 20:55:28 +000016#include "clang/AST/DeclCXX.h"
Steve Naroff980e5082007-10-01 19:00:59 +000017#include "clang/AST/DeclObjC.h"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000018#include "clang/AST/DeclTemplate.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000019#include "clang/AST/Expr.h"
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000020#include "clang/AST/PrettyPrinter.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000021#include "llvm/ADT/StringExtras.h"
Douglas Gregorbad35182009-03-19 03:51:16 +000022#include "llvm/Support/raw_ostream.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000023using namespace clang;
24
Chris Lattner4bbce992009-01-12 00:10:42 +000025bool QualType::isConstant(ASTContext &Ctx) const {
Nuno Lopesb381aac2008-09-01 11:33:04 +000026 if (isConstQualified())
27 return true;
28
29 if (getTypePtr()->isArrayType())
30 return Ctx.getAsArrayType(*this)->getElementType().isConstant(Ctx);
31
32 return false;
33}
34
Ted Kremenek566c2ba2009-01-19 21:31:22 +000035void Type::Destroy(ASTContext& C) {
36 this->~Type();
Steve Naroff3e970492009-01-27 21:25:57 +000037 C.Deallocate(this);
Ted Kremenek4b05b1d2008-05-21 16:38:54 +000038}
39
Douglas Gregor7e7eb3d2009-07-06 15:59:29 +000040void ConstantArrayWithExprType::Destroy(ASTContext& C) {
41 // FIXME: destruction of SizeExpr commented out due to resource contention.
42 // SizeExpr->Destroy(C);
43 // See FIXME in SemaDecl.cpp:1536: if we were able to either steal
44 // or clone the SizeExpr there, then here we could freely delete it.
45 // Since we do not know how to steal or clone, we keep a pointer to
46 // a shared resource, but we cannot free it.
47 // (There probably is a trivial solution ... for people knowing clang!).
48 this->~ConstantArrayWithExprType();
49 C.Deallocate(this);
50}
51
Ted Kremenek4b05b1d2008-05-21 16:38:54 +000052void VariableArrayType::Destroy(ASTContext& C) {
Eli Friedmanf91f5c82009-04-26 21:57:51 +000053 if (SizeExpr)
54 SizeExpr->Destroy(C);
Ted Kremenek566c2ba2009-01-19 21:31:22 +000055 this->~VariableArrayType();
Steve Naroff3e970492009-01-27 21:25:57 +000056 C.Deallocate(this);
Ted Kremenek4b05b1d2008-05-21 16:38:54 +000057}
Reid Spencer5f016e22007-07-11 17:01:13 +000058
Douglas Gregor898574e2008-12-05 23:32:09 +000059void DependentSizedArrayType::Destroy(ASTContext& C) {
Argyrios Kyrtzidise7f38402009-07-18 21:18:10 +000060 // FIXME: Resource contention like in ConstantArrayWithExprType ?
61 // May crash, depending on platform or a particular build.
62 // SizeExpr->Destroy(C);
Ted Kremenek566c2ba2009-01-19 21:31:22 +000063 this->~DependentSizedArrayType();
Steve Naroff3e970492009-01-27 21:25:57 +000064 C.Deallocate(this);
Douglas Gregor898574e2008-12-05 23:32:09 +000065}
Chris Lattnerc63a1f22008-08-04 07:31:14 +000066
Mike Stump1eb44332009-09-09 15:08:12 +000067void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
Douglas Gregor04d4bee2009-07-31 00:23:35 +000068 ASTContext &Context,
69 QualType ET,
70 ArraySizeModifier SizeMod,
71 unsigned TypeQuals,
72 Expr *E) {
73 ID.AddPointer(ET.getAsOpaquePtr());
74 ID.AddInteger(SizeMod);
75 ID.AddInteger(TypeQuals);
76 E->Profile(ID, Context, true);
77}
78
Mike Stump1eb44332009-09-09 15:08:12 +000079void
80DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID,
Douglas Gregor2ec09f12009-07-31 03:54:25 +000081 ASTContext &Context,
82 QualType ElementType, Expr *SizeExpr) {
83 ID.AddPointer(ElementType.getAsOpaquePtr());
84 SizeExpr->Profile(ID, Context, true);
85}
86
Douglas Gregor9cdda0c2009-06-17 21:51:59 +000087void DependentSizedExtVectorType::Destroy(ASTContext& C) {
Douglas Gregorbd1099e2009-07-23 16:36:45 +000088 // FIXME: Deallocate size expression, once we're cloning properly.
89// if (SizeExpr)
90// SizeExpr->Destroy(C);
Douglas Gregor9cdda0c2009-06-17 21:51:59 +000091 this->~DependentSizedExtVectorType();
92 C.Deallocate(this);
93}
94
Chris Lattnerc63a1f22008-08-04 07:31:14 +000095/// getArrayElementTypeNoTypeQual - If this is an array type, return the
96/// element type of the array, potentially with type qualifiers missing.
97/// This method should never be used when type qualifiers are meaningful.
98const Type *Type::getArrayElementTypeNoTypeQual() const {
99 // If this is directly an array type, return it.
100 if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
101 return ATy->getElementType().getTypePtr();
Mike Stump1eb44332009-09-09 15:08:12 +0000102
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000103 // If the canonical form of this type isn't the right kind, reject it.
104 if (!isa<ArrayType>(CanonicalType)) {
105 // Look through type qualifiers
106 if (ArrayType *AT = dyn_cast<ArrayType>(CanonicalType.getUnqualifiedType()))
107 return AT->getElementType().getTypePtr();
108 return 0;
109 }
Mike Stump1eb44332009-09-09 15:08:12 +0000110
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000111 // If this is a typedef for an array type, strip the typedef off without
112 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000113 return cast<ArrayType>(getDesugaredType())->getElementType().getTypePtr();
114}
115
116/// getDesugaredType - Return the specified type with any "sugar" removed from
117/// the type. This takes off typedefs, typeof's etc. If the outer level of
118/// the type is already concrete, it returns it unmodified. This is similar
119/// to getting the canonical type, but it doesn't remove *all* typedefs. For
120/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
121/// concrete.
Douglas Gregor969c6892009-04-01 15:47:24 +0000122///
123/// \param ForDisplay When true, the desugaring is provided for
124/// display purposes only. In this case, we apply more heuristics to
125/// decide whether it is worth providing a desugared form of the type
126/// or not.
127QualType QualType::getDesugaredType(bool ForDisplay) const {
128 return getTypePtr()->getDesugaredType(ForDisplay)
Chris Lattner2fa8c252009-03-17 22:51:02 +0000129 .getWithAdditionalQualifiers(getCVRQualifiers());
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000130}
131
132/// getDesugaredType - Return the specified type with any "sugar" removed from
133/// type type. This takes off typedefs, typeof's etc. If the outer level of
134/// the type is already concrete, it returns it unmodified. This is similar
135/// to getting the canonical type, but it doesn't remove *all* typedefs. For
136/// example, it return "T*" as "T*", (not as "int*"), because the pointer is
137/// concrete.
Douglas Gregor969c6892009-04-01 15:47:24 +0000138///
139/// \param ForDisplay When true, the desugaring is provided for
140/// display purposes only. In this case, we apply more heuristics to
141/// decide whether it is worth providing a desugared form of the type
142/// or not.
143QualType Type::getDesugaredType(bool ForDisplay) const {
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000144 if (const TypedefType *TDT = dyn_cast<TypedefType>(this))
Chris Lattner2fa8c252009-03-17 22:51:02 +0000145 return TDT->LookThroughTypedefs().getDesugaredType();
John McCall2191b202009-09-05 06:31:47 +0000146 if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(this))
147 return ET->getUnderlyingType().getDesugaredType();
Douglas Gregor72564e72009-02-26 23:50:07 +0000148 if (const TypeOfExprType *TOE = dyn_cast<TypeOfExprType>(this))
Chris Lattner2fa8c252009-03-17 22:51:02 +0000149 return TOE->getUnderlyingExpr()->getType().getDesugaredType();
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000150 if (const TypeOfType *TOT = dyn_cast<TypeOfType>(this))
Chris Lattner2fa8c252009-03-17 22:51:02 +0000151 return TOT->getUnderlyingType().getDesugaredType();
Anders Carlsson563a03b2009-07-10 19:20:26 +0000152 if (const DecltypeType *DTT = dyn_cast<DecltypeType>(this)) {
153 if (!DTT->getUnderlyingType()->isDependentType())
154 return DTT->getUnderlyingType().getDesugaredType();
155 }
Mike Stump1eb44332009-09-09 15:08:12 +0000156 if (const TemplateSpecializationType *Spec
Douglas Gregorc45c2322009-03-31 00:43:58 +0000157 = dyn_cast<TemplateSpecializationType>(this)) {
Douglas Gregor969c6892009-04-01 15:47:24 +0000158 if (ForDisplay)
159 return QualType(this, 0);
160
Douglas Gregorc45c2322009-03-31 00:43:58 +0000161 QualType Canon = Spec->getCanonicalTypeInternal();
162 if (Canon->getAsTemplateSpecializationType())
163 return QualType(this, 0);
164 return Canon->getDesugaredType();
165 }
Douglas Gregor969c6892009-04-01 15:47:24 +0000166 if (const QualifiedNameType *QualName = dyn_cast<QualifiedNameType>(this)) {
167 if (ForDisplay) {
168 // If desugaring the type that the qualified name is referring to
169 // produces something interesting, that's our desugared type.
170 QualType NamedType = QualName->getNamedType().getDesugaredType();
171 if (NamedType != QualName->getNamedType())
172 return NamedType;
173 } else
174 return QualName->getNamedType().getDesugaredType();
175 }
Douglas Gregor5cdf8212009-02-12 00:15:05 +0000176
Douglas Gregor969c6892009-04-01 15:47:24 +0000177 return QualType(this, 0);
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000178}
179
Reid Spencer5f016e22007-07-11 17:01:13 +0000180/// isVoidType - Helper method to determine if this is the 'void' type.
181bool Type::isVoidType() const {
182 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
183 return BT->getKind() == BuiltinType::Void;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000184 if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType))
Chris Lattner4bbce992009-01-12 00:10:42 +0000185 return AS->getBaseType()->isVoidType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000186 return false;
187}
188
189bool Type::isObjectType() const {
Douglas Gregorbad0e652009-03-24 20:32:41 +0000190 if (isa<FunctionType>(CanonicalType) || isa<ReferenceType>(CanonicalType) ||
191 isa<IncompleteArrayType>(CanonicalType) || isVoidType())
Reid Spencer5f016e22007-07-11 17:01:13 +0000192 return false;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000193 if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType))
Chris Lattner4bbce992009-01-12 00:10:42 +0000194 return AS->getBaseType()->isObjectType();
Douglas Gregorbad0e652009-03-24 20:32:41 +0000195 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000196}
197
198bool Type::isDerivedType() const {
199 switch (CanonicalType->getTypeClass()) {
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000200 case ExtQual:
201 return cast<ExtQualType>(CanonicalType)->getBaseType()->isDerivedType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000202 case Pointer:
Steve Narofffb22d962007-08-30 01:06:46 +0000203 case VariableArray:
204 case ConstantArray:
Douglas Gregor7e7eb3d2009-07-06 15:59:29 +0000205 case ConstantArrayWithExpr:
206 case ConstantArrayWithoutExpr:
Eli Friedmanc5773c42008-02-15 18:16:39 +0000207 case IncompleteArray:
Reid Spencer5f016e22007-07-11 17:01:13 +0000208 case FunctionProto:
209 case FunctionNoProto:
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000210 case LValueReference:
211 case RValueReference:
Douglas Gregor72564e72009-02-26 23:50:07 +0000212 case Record:
Reid Spencer5f016e22007-07-11 17:01:13 +0000213 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000214 default:
215 return false;
216 }
217}
218
Chris Lattner99dc9142008-04-13 18:59:07 +0000219bool Type::isClassType() const {
Ted Kremenek6217b802009-07-29 21:53:49 +0000220 if (const RecordType *RT = getAs<RecordType>())
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000221 return RT->getDecl()->isClass();
Chris Lattner99dc9142008-04-13 18:59:07 +0000222 return false;
223}
Chris Lattnerc8629632007-07-31 19:29:30 +0000224bool Type::isStructureType() const {
Ted Kremenek6217b802009-07-29 21:53:49 +0000225 if (const RecordType *RT = getAs<RecordType>())
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000226 return RT->getDecl()->isStruct();
Chris Lattnerc8629632007-07-31 19:29:30 +0000227 return false;
228}
Steve Naroff7154a772009-07-01 14:36:47 +0000229bool Type::isVoidPointerType() const {
Ted Kremenek6217b802009-07-29 21:53:49 +0000230 if (const PointerType *PT = getAs<PointerType>())
Steve Naroff7154a772009-07-01 14:36:47 +0000231 return PT->getPointeeType()->isVoidType();
232 return false;
233}
234
Chris Lattnerc8629632007-07-31 19:29:30 +0000235bool Type::isUnionType() const {
Ted Kremenek6217b802009-07-29 21:53:49 +0000236 if (const RecordType *RT = getAs<RecordType>())
Chris Lattnerf728a4a2009-01-11 23:59:49 +0000237 return RT->getDecl()->isUnion();
Chris Lattnerc8629632007-07-31 19:29:30 +0000238 return false;
239}
Chris Lattnerc8629632007-07-31 19:29:30 +0000240
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000241bool Type::isComplexType() const {
Steve Naroff02f62a92008-01-15 19:36:10 +0000242 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
243 return CT->getElementType()->isFloatingType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000244 if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType))
Chris Lattner4bbce992009-01-12 00:10:42 +0000245 return AS->getBaseType()->isComplexType();
Steve Naroff02f62a92008-01-15 19:36:10 +0000246 return false;
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000247}
248
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000249bool Type::isComplexIntegerType() const {
250 // Check for GCC complex integer extension.
251 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
252 return CT->getElementType()->isIntegerType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000253 if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType))
Chris Lattner4bbce992009-01-12 00:10:42 +0000254 return AS->getBaseType()->isComplexIntegerType();
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000255 return false;
256}
257
258const ComplexType *Type::getAsComplexIntegerType() const {
259 // Are we directly a complex type?
260 if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) {
261 if (CTy->getElementType()->isIntegerType())
262 return CTy;
Chris Lattner4bbce992009-01-12 00:10:42 +0000263 return 0;
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000264 }
Mike Stump1eb44332009-09-09 15:08:12 +0000265
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000266 // If the canonical form of this type isn't what we want, reject it.
267 if (!isa<ComplexType>(CanonicalType)) {
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000268 // Look through type qualifiers (e.g. ExtQualType's).
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000269 if (isa<ComplexType>(CanonicalType.getUnqualifiedType()))
270 return CanonicalType.getUnqualifiedType()->getAsComplexIntegerType();
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000271 return 0;
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000272 }
Mike Stump1eb44332009-09-09 15:08:12 +0000273
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000274 // If this is a typedef for a complex type, strip the typedef off without
275 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000276 return cast<ComplexType>(getDesugaredType());
Steve Naroff4cdec1c2008-01-15 01:41:59 +0000277}
278
Steve Naroff77878cc2007-08-27 04:08:11 +0000279const BuiltinType *Type::getAsBuiltinType() const {
280 // If this is directly a builtin type, return it.
281 if (const BuiltinType *BTy = dyn_cast<BuiltinType>(this))
282 return BTy;
Chris Lattnerdea61462007-10-29 03:41:11 +0000283
284 // If the canonical form of this type isn't a builtin type, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000285 if (!isa<BuiltinType>(CanonicalType)) {
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000286 // Look through type qualifiers (e.g. ExtQualType's).
Christopher Lambebb97e92008-02-04 02:31:56 +0000287 if (isa<BuiltinType>(CanonicalType.getUnqualifiedType()))
288 return CanonicalType.getUnqualifiedType()->getAsBuiltinType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000289 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000290 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000291
Steve Naroff77878cc2007-08-27 04:08:11 +0000292 // If this is a typedef for a builtin type, strip the typedef off without
293 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000294 return cast<BuiltinType>(getDesugaredType());
Steve Naroff77878cc2007-08-27 04:08:11 +0000295}
296
Chris Lattnerc8629632007-07-31 19:29:30 +0000297const FunctionType *Type::getAsFunctionType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000298 // If this is directly a function type, return it.
299 if (const FunctionType *FTy = dyn_cast<FunctionType>(this))
300 return FTy;
Christopher Lambebb97e92008-02-04 02:31:56 +0000301
Chris Lattnerdea61462007-10-29 03:41:11 +0000302 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000303 if (!isa<FunctionType>(CanonicalType)) {
304 // Look through type qualifiers
305 if (isa<FunctionType>(CanonicalType.getUnqualifiedType()))
306 return CanonicalType.getUnqualifiedType()->getAsFunctionType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000307 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000308 }
Mike Stump1eb44332009-09-09 15:08:12 +0000309
Steve Naroff7064f5c2007-07-26 18:32:01 +0000310 // If this is a typedef for a function type, strip the typedef off without
311 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000312 return cast<FunctionType>(getDesugaredType());
Reid Spencer5f016e22007-07-11 17:01:13 +0000313}
314
Douglas Gregor72564e72009-02-26 23:50:07 +0000315const FunctionNoProtoType *Type::getAsFunctionNoProtoType() const {
316 return dyn_cast_or_null<FunctionNoProtoType>(getAsFunctionType());
Daniel Dunbarafa74442009-02-19 07:11:26 +0000317}
318
Douglas Gregor72564e72009-02-26 23:50:07 +0000319const FunctionProtoType *Type::getAsFunctionProtoType() const {
320 return dyn_cast_or_null<FunctionProtoType>(getAsFunctionType());
Chris Lattnerb77792e2008-07-26 22:17:49 +0000321}
322
Steve Naroff14108da2009-07-10 23:34:53 +0000323QualType Type::getPointeeType() const {
Ted Kremenek6217b802009-07-29 21:53:49 +0000324 if (const PointerType *PT = getAs<PointerType>())
Steve Naroff14108da2009-07-10 23:34:53 +0000325 return PT->getPointeeType();
326 if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType())
327 return OPT->getPointeeType();
Ted Kremenek6217b802009-07-29 21:53:49 +0000328 if (const BlockPointerType *BPT = getAs<BlockPointerType>())
Steve Naroff14108da2009-07-10 23:34:53 +0000329 return BPT->getPointeeType();
330 return QualType();
331}
Chris Lattnerb77792e2008-07-26 22:17:49 +0000332
Eli Friedmand3f2f792008-02-17 00:59:11 +0000333/// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length
334/// array types and types that contain variable array types in their
335/// declarator
Steve Naroffd7444aa2007-08-31 17:20:07 +0000336bool Type::isVariablyModifiedType() const {
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000337 // A VLA is a variably modified type.
338 if (isVariableArrayType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000339 return true;
340
341 // An array can contain a variably modified type
Chris Lattnerc63a1f22008-08-04 07:31:14 +0000342 if (const Type *T = getArrayElementTypeNoTypeQual())
343 return T->isVariablyModifiedType();
Eli Friedmand3f2f792008-02-17 00:59:11 +0000344
Sebastian Redlf30208a2009-01-24 21:16:55 +0000345 // A pointer can point to a variably modified type.
346 // Also, C++ references and member pointers can point to a variably modified
347 // type, where VLAs appear as an extension to C++, and should be treated
348 // correctly.
Ted Kremenek6217b802009-07-29 21:53:49 +0000349 if (const PointerType *PT = getAs<PointerType>())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000350 return PT->getPointeeType()->isVariablyModifiedType();
Ted Kremenek6217b802009-07-29 21:53:49 +0000351 if (const ReferenceType *RT = getAs<ReferenceType>())
Daniel Dunbar68694ad2009-02-26 19:54:52 +0000352 return RT->getPointeeType()->isVariablyModifiedType();
Ted Kremenek6217b802009-07-29 21:53:49 +0000353 if (const MemberPointerType *PT = getAs<MemberPointerType>())
Sebastian Redl8edef7c2009-01-24 23:29:36 +0000354 return PT->getPointeeType()->isVariablyModifiedType();
Eli Friedmand3f2f792008-02-17 00:59:11 +0000355
356 // A function can return a variably modified type
357 // This one isn't completely obvious, but it follows from the
358 // definition in C99 6.7.5p3. Because of this rule, it's
359 // illegal to declare a function returning a variably modified type.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000360 if (const FunctionType *FT = getAsFunctionType())
Eli Friedmand3f2f792008-02-17 00:59:11 +0000361 return FT->getResultType()->isVariablyModifiedType();
362
Steve Naroffd7444aa2007-08-31 17:20:07 +0000363 return false;
364}
365
Chris Lattnerc8629632007-07-31 19:29:30 +0000366const RecordType *Type::getAsStructureType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000367 // If this is directly a structure type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000368 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000369 if (RT->getDecl()->isStruct())
Chris Lattnerc8629632007-07-31 19:29:30 +0000370 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000371 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000372
373 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000374 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000375 if (!RT->getDecl()->isStruct())
Chris Lattnerdea61462007-10-29 03:41:11 +0000376 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000377
Chris Lattnerdea61462007-10-29 03:41:11 +0000378 // If this is a typedef for a structure type, strip the typedef off without
379 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000380 return cast<RecordType>(getDesugaredType());
Reid Spencer5f016e22007-07-11 17:01:13 +0000381 }
Christopher Lambebb97e92008-02-04 02:31:56 +0000382 // Look through type qualifiers
383 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
384 return CanonicalType.getUnqualifiedType()->getAsStructureType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000385 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000386}
387
Mike Stump1eb44332009-09-09 15:08:12 +0000388const RecordType *Type::getAsUnionType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000389 // If this is directly a union type, return it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000390 if (const RecordType *RT = dyn_cast<RecordType>(this)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000391 if (RT->getDecl()->isUnion())
Chris Lattnerc8629632007-07-31 19:29:30 +0000392 return RT;
Steve Naroff7064f5c2007-07-26 18:32:01 +0000393 }
Mike Stump1eb44332009-09-09 15:08:12 +0000394
Chris Lattnerdea61462007-10-29 03:41:11 +0000395 // If the canonical form of this type isn't the right kind, reject it.
Chris Lattnerc8629632007-07-31 19:29:30 +0000396 if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000397 if (!RT->getDecl()->isUnion())
Chris Lattnerdea61462007-10-29 03:41:11 +0000398 return 0;
399
400 // If this is a typedef for a union type, strip the typedef off without
401 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000402 return cast<RecordType>(getDesugaredType());
Reid Spencer5f016e22007-07-11 17:01:13 +0000403 }
Mike Stump1eb44332009-09-09 15:08:12 +0000404
Christopher Lambebb97e92008-02-04 02:31:56 +0000405 // Look through type qualifiers
406 if (isa<RecordType>(CanonicalType.getUnqualifiedType()))
407 return CanonicalType.getUnqualifiedType()->getAsUnionType();
Steve Naroff7064f5c2007-07-26 18:32:01 +0000408 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000409}
410
Eli Friedmanad74a752008-06-28 06:23:08 +0000411const EnumType *Type::getAsEnumType() const {
412 // Check the canonicalized unqualified type directly; the more complex
413 // version is unnecessary because there isn't any typedef information
414 // to preserve.
415 return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType());
416}
417
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000418const ComplexType *Type::getAsComplexType() const {
419 // Are we directly a complex type?
420 if (const ComplexType *CTy = dyn_cast<ComplexType>(this))
421 return CTy;
Mike Stump1eb44332009-09-09 15:08:12 +0000422
Chris Lattnerdea61462007-10-29 03:41:11 +0000423 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000424 if (!isa<ComplexType>(CanonicalType)) {
425 // Look through type qualifiers
426 if (isa<ComplexType>(CanonicalType.getUnqualifiedType()))
427 return CanonicalType.getUnqualifiedType()->getAsComplexType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000428 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000429 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000430
Chris Lattnerc6fb90a2007-08-21 16:54:08 +0000431 // If this is a typedef for a complex type, strip the typedef off without
432 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000433 return cast<ComplexType>(getDesugaredType());
Chris Lattner7a2e0472007-07-16 00:23:25 +0000434}
435
Chris Lattnerc8629632007-07-31 19:29:30 +0000436const VectorType *Type::getAsVectorType() const {
Chris Lattner7a2e0472007-07-16 00:23:25 +0000437 // Are we directly a vector type?
438 if (const VectorType *VTy = dyn_cast<VectorType>(this))
439 return VTy;
Mike Stump1eb44332009-09-09 15:08:12 +0000440
Chris Lattnerdea61462007-10-29 03:41:11 +0000441 // If the canonical form of this type isn't the right kind, reject it.
Christopher Lambebb97e92008-02-04 02:31:56 +0000442 if (!isa<VectorType>(CanonicalType)) {
443 // Look through type qualifiers
444 if (isa<VectorType>(CanonicalType.getUnqualifiedType()))
445 return CanonicalType.getUnqualifiedType()->getAsVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000446 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000447 }
Chris Lattnerdea61462007-10-29 03:41:11 +0000448
Chris Lattnera2c77672007-07-16 22:05:22 +0000449 // If this is a typedef for a vector type, strip the typedef off without
450 // losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000451 return cast<VectorType>(getDesugaredType());
Chris Lattner7a2e0472007-07-16 00:23:25 +0000452}
453
Nate Begeman213541a2008-04-18 23:10:10 +0000454const ExtVectorType *Type::getAsExtVectorType() const {
Steve Naroff7064f5c2007-07-26 18:32:01 +0000455 // Are we directly an OpenCU vector type?
Nate Begeman213541a2008-04-18 23:10:10 +0000456 if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this))
Steve Naroff7064f5c2007-07-26 18:32:01 +0000457 return VTy;
Mike Stump1eb44332009-09-09 15:08:12 +0000458
Chris Lattnerdea61462007-10-29 03:41:11 +0000459 // If the canonical form of this type isn't the right kind, reject it.
Mike Stump1eb44332009-09-09 15:08:12 +0000460 if (!isa<ExtVectorType>(CanonicalType)) {
Christopher Lambebb97e92008-02-04 02:31:56 +0000461 // Look through type qualifiers
Nate Begeman213541a2008-04-18 23:10:10 +0000462 if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType()))
463 return CanonicalType.getUnqualifiedType()->getAsExtVectorType();
Chris Lattnerdea61462007-10-29 03:41:11 +0000464 return 0;
Christopher Lambebb97e92008-02-04 02:31:56 +0000465 }
Steve Naroff7064f5c2007-07-26 18:32:01 +0000466
Nate Begeman213541a2008-04-18 23:10:10 +0000467 // If this is a typedef for an extended vector type, strip the typedef off
468 // without losing all typedef information.
Chris Lattner2fa8c252009-03-17 22:51:02 +0000469 return cast<ExtVectorType>(getDesugaredType());
Steve Naroff7064f5c2007-07-26 18:32:01 +0000470}
471
Chris Lattner368eefa2008-04-07 00:27:04 +0000472const ObjCInterfaceType *Type::getAsObjCInterfaceType() const {
Chris Lattnereca7be62008-04-07 05:30:13 +0000473 // There is no sugar for ObjCInterfaceType's, just return the canonical
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000474 // type pointer if it is the right class. There is no typedef information to
475 // return and these cannot be Address-space qualified.
Fariborz Jahanianfb41ca82009-02-26 23:05:51 +0000476 return dyn_cast<ObjCInterfaceType>(CanonicalType.getUnqualifiedType());
Chris Lattner368eefa2008-04-07 00:27:04 +0000477}
478
Steve Naroffc15cb2a2009-07-18 15:33:26 +0000479const ObjCInterfaceType *Type::getAsObjCQualifiedInterfaceType() const {
480 // There is no sugar for ObjCInterfaceType's, just return the canonical
481 // type pointer if it is the right class. There is no typedef information to
482 // return and these cannot be Address-space qualified.
483 if (const ObjCInterfaceType *OIT = getAsObjCInterfaceType())
484 if (OIT->getNumProtocols())
485 return OIT;
486 return 0;
487}
488
489bool Type::isObjCQualifiedInterfaceType() const {
Steve Naroffe61ad0b2009-07-18 15:38:31 +0000490 return getAsObjCQualifiedInterfaceType() != 0;
Steve Naroffc15cb2a2009-07-18 15:33:26 +0000491}
492
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000493const ObjCObjectPointerType *Type::getAsObjCObjectPointerType() const {
494 // There is no sugar for ObjCObjectPointerType's, just return the
495 // canonical type pointer if it is the right class.
496 return dyn_cast<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType());
497}
498
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000499const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const {
Chris Lattnereca7be62008-04-07 05:30:13 +0000500 // There is no sugar for ObjCQualifiedIdType's, just return the canonical
501 // type pointer if it is the right class.
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000502 if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) {
503 if (OPT->isObjCQualifiedIdType())
504 return OPT;
505 }
506 return 0;
Chris Lattner368eefa2008-04-07 00:27:04 +0000507}
508
Steve Naroff14108da2009-07-10 23:34:53 +0000509const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const {
510 if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) {
511 if (OPT->getInterfaceType())
512 return OPT;
513 }
514 return 0;
515}
516
Douglas Gregor72c3f312008-12-05 18:15:24 +0000517const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const {
518 // There is no sugar for template type parameters, so just return
519 // the canonical type pointer if it is the right class.
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000520 // FIXME: can these be address-space qualified?
Douglas Gregor72c3f312008-12-05 18:15:24 +0000521 return dyn_cast<TemplateTypeParmType>(CanonicalType);
522}
Chris Lattner368eefa2008-04-07 00:27:04 +0000523
Fariborz Jahaniana91d6a62009-07-29 00:44:13 +0000524const CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const {
Ted Kremenek6217b802009-07-29 21:53:49 +0000525 if (const PointerType *PT = getAs<PointerType>())
526 if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>())
Fariborz Jahaniana91d6a62009-07-29 00:44:13 +0000527 return dyn_cast<CXXRecordDecl>(RT->getDecl());
528 return 0;
529}
530
Douglas Gregor7532dc62009-03-30 22:58:21 +0000531const TemplateSpecializationType *
532Type::getAsTemplateSpecializationType() const {
Douglas Gregor55f6b142009-02-09 18:46:07 +0000533 // There is no sugar for class template specialization types, so
534 // just return the canonical type pointer if it is the right class.
Douglas Gregor6946baf2009-09-02 13:05:45 +0000535 return this->getAs<TemplateSpecializationType>();
Douglas Gregor55f6b142009-02-09 18:46:07 +0000536}
537
Reid Spencer5f016e22007-07-11 17:01:13 +0000538bool Type::isIntegerType() const {
539 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
540 return BT->getKind() >= BuiltinType::Bool &&
Chris Lattner2df9ced2009-04-30 02:43:43 +0000541 BT->getKind() <= BuiltinType::Int128;
Reid Spencer5f016e22007-07-11 17:01:13 +0000542 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000543 // Incomplete enum types are not treated as integer types.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000544 // FIXME: In C++, enum types are never integer types.
Chris Lattner834a72a2008-07-25 23:18:17 +0000545 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000546 return true;
Eli Friedmanf98aba32009-02-13 02:31:07 +0000547 if (isa<FixedWidthIntType>(CanonicalType))
548 return true;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000549 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
550 return VT->getElementType()->isIntegerType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000551 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
552 return EXTQT->getBaseType()->isIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000553 return false;
554}
555
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000556bool Type::isIntegralType() const {
557 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
558 return BT->getKind() >= BuiltinType::Bool &&
559 BT->getKind() <= BuiltinType::LongLong;
560 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000561 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
562 return true; // Complete enum types are integral.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000563 // FIXME: In C++, enum types are never integral.
Eli Friedmanf98aba32009-02-13 02:31:07 +0000564 if (isa<FixedWidthIntType>(CanonicalType))
565 return true;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000566 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
567 return EXTQT->getBaseType()->isIntegralType();
Fariborz Jahanian33e1d642007-10-29 22:57:28 +0000568 return false;
569}
570
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000571bool Type::isEnumeralType() const {
572 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Argyrios Kyrtzidis39ba4ae2008-06-09 23:19:58 +0000573 return TT->getDecl()->isEnum();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000574 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
575 return EXTQT->getBaseType()->isEnumeralType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000576 return false;
577}
578
579bool Type::isBooleanType() const {
580 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
581 return BT->getKind() == BuiltinType::Bool;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000582 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
583 return EXTQT->getBaseType()->isBooleanType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000584 return false;
585}
586
587bool Type::isCharType() const {
588 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
589 return BT->getKind() == BuiltinType::Char_U ||
590 BT->getKind() == BuiltinType::UChar ||
Anders Carlssonc67ad5f2007-10-29 02:52:18 +0000591 BT->getKind() == BuiltinType::Char_S ||
592 BT->getKind() == BuiltinType::SChar;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000593 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
594 return EXTQT->getBaseType()->isCharType();
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000595 return false;
596}
597
Douglas Gregor77a52232008-09-12 00:47:35 +0000598bool Type::isWideCharType() const {
599 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
600 return BT->getKind() == BuiltinType::WChar;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000601 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
602 return EXTQT->getBaseType()->isWideCharType();
Douglas Gregor77a52232008-09-12 00:47:35 +0000603 return false;
604}
605
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000606/// isSignedIntegerType - Return true if this is an integer type that is
607/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
608/// an enum decl which has a signed representation, or a vector of signed
609/// integer element type.
Reid Spencer5f016e22007-07-11 17:01:13 +0000610bool Type::isSignedIntegerType() const {
611 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
612 return BT->getKind() >= BuiltinType::Char_S &&
613 BT->getKind() <= BuiltinType::LongLong;
614 }
Mike Stump1eb44332009-09-09 15:08:12 +0000615
Chris Lattner37c1b782008-04-06 22:29:16 +0000616 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
617 return ET->getDecl()->getIntegerType()->isSignedIntegerType();
Mike Stump1eb44332009-09-09 15:08:12 +0000618
Eli Friedmanf98aba32009-02-13 02:31:07 +0000619 if (const FixedWidthIntType *FWIT =
620 dyn_cast<FixedWidthIntType>(CanonicalType))
621 return FWIT->isSigned();
Mike Stump1eb44332009-09-09 15:08:12 +0000622
Steve Naroffc63b96a2007-07-12 21:46:55 +0000623 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
624 return VT->getElementType()->isSignedIntegerType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000625 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
626 return EXTQT->getBaseType()->isSignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000627 return false;
628}
629
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000630/// isUnsignedIntegerType - Return true if this is an integer type that is
631/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
632/// decl which has an unsigned representation, or a vector of unsigned integer
633/// element type.
Reid Spencer5f016e22007-07-11 17:01:13 +0000634bool Type::isUnsignedIntegerType() const {
635 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
636 return BT->getKind() >= BuiltinType::Bool &&
637 BT->getKind() <= BuiltinType::ULongLong;
638 }
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000639
Chris Lattner37c1b782008-04-06 22:29:16 +0000640 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
641 return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
Chris Lattnerd5bbce42007-08-29 17:48:46 +0000642
Eli Friedmanf98aba32009-02-13 02:31:07 +0000643 if (const FixedWidthIntType *FWIT =
644 dyn_cast<FixedWidthIntType>(CanonicalType))
645 return !FWIT->isSigned();
646
Steve Naroffc63b96a2007-07-12 21:46:55 +0000647 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
648 return VT->getElementType()->isUnsignedIntegerType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000649 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
650 return EXTQT->getBaseType()->isUnsignedIntegerType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000651 return false;
652}
653
654bool Type::isFloatingType() const {
655 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
656 return BT->getKind() >= BuiltinType::Float &&
657 BT->getKind() <= BuiltinType::LongDouble;
658 if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
Chris Lattner729a2132007-08-30 06:19:11 +0000659 return CT->getElementType()->isFloatingType();
Steve Naroffc63b96a2007-07-12 21:46:55 +0000660 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
661 return VT->getElementType()->isFloatingType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000662 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
663 return EXTQT->getBaseType()->isFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000664 return false;
665}
666
667bool Type::isRealFloatingType() const {
668 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
669 return BT->getKind() >= BuiltinType::Float &&
670 BT->getKind() <= BuiltinType::LongDouble;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000671 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
672 return VT->getElementType()->isRealFloatingType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000673 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
674 return EXTQT->getBaseType()->isRealFloatingType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000675 return false;
676}
677
678bool Type::isRealType() const {
679 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
680 return BT->getKind() >= BuiltinType::Bool &&
681 BT->getKind() <= BuiltinType::LongDouble;
682 if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
Chris Lattner834a72a2008-07-25 23:18:17 +0000683 return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition();
Eli Friedmanf98aba32009-02-13 02:31:07 +0000684 if (isa<FixedWidthIntType>(CanonicalType))
685 return true;
Steve Naroffc63b96a2007-07-12 21:46:55 +0000686 if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
687 return VT->getElementType()->isRealType();
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000688 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
689 return EXTQT->getBaseType()->isRealType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000690 return false;
691}
692
Reid Spencer5f016e22007-07-11 17:01:13 +0000693bool Type::isArithmeticType() const {
694 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
Douglas Gregora7fbf722008-10-30 13:47:07 +0000695 return BT->getKind() >= BuiltinType::Bool &&
696 BT->getKind() <= BuiltinType::LongDouble;
Chris Lattner37c1b782008-04-06 22:29:16 +0000697 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
698 // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
699 // If a body isn't seen by the time we get here, return false.
700 return ET->getDecl()->isDefinition();
Eli Friedmanf98aba32009-02-13 02:31:07 +0000701 if (isa<FixedWidthIntType>(CanonicalType))
702 return true;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000703 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
704 return EXTQT->getBaseType()->isArithmeticType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000705 return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType);
706}
707
708bool Type::isScalarType() const {
709 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
710 return BT->getKind() != BuiltinType::Void;
711 if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
Chris Lattner834a72a2008-07-25 23:18:17 +0000712 // Enums are scalar types, but only if they are defined. Incomplete enums
713 // are not treated as scalar types.
714 if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000715 return true;
716 return false;
717 }
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000718 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
719 return EXTQT->getBaseType()->isScalarType();
Eli Friedmanf98aba32009-02-13 02:31:07 +0000720 if (isa<FixedWidthIntType>(CanonicalType))
721 return true;
Steve Naroff5618bd42008-08-27 16:04:49 +0000722 return isa<PointerType>(CanonicalType) ||
723 isa<BlockPointerType>(CanonicalType) ||
Sebastian Redlf30208a2009-01-24 21:16:55 +0000724 isa<MemberPointerType>(CanonicalType) ||
Steve Naroff5618bd42008-08-27 16:04:49 +0000725 isa<ComplexType>(CanonicalType) ||
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000726 isa<ObjCObjectPointerType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000727}
728
Douglas Gregord7eb8462009-01-30 17:31:00 +0000729/// \brief Determines whether the type is a C++ aggregate type or C
730/// aggregate or union type.
731///
732/// An aggregate type is an array or a class type (struct, union, or
733/// class) that has no user-declared constructors, no private or
734/// protected non-static data members, no base classes, and no virtual
735/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
736/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
737/// includes union types.
Reid Spencer5f016e22007-07-11 17:01:13 +0000738bool Type::isAggregateType() const {
Douglas Gregorc1efaec2009-02-28 01:32:25 +0000739 if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) {
740 if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
741 return ClassDecl->isAggregate();
742
Douglas Gregord7eb8462009-01-30 17:31:00 +0000743 return true;
Douglas Gregorc1efaec2009-02-28 01:32:25 +0000744 }
745
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000746 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
747 return EXTQT->getBaseType()->isAggregateType();
Eli Friedmanc5773c42008-02-15 18:16:39 +0000748 return isa<ArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000749}
750
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000751/// isConstantSizeType - Return true if this is not a variable sized type,
752/// according to the rules of C99 6.7.5p3. It is not legal to call this on
Douglas Gregor898574e2008-12-05 23:32:09 +0000753/// incomplete types or dependent types.
Eli Friedman3c2b3172008-02-15 12:20:59 +0000754bool Type::isConstantSizeType() const {
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000755 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType))
756 return EXTQT->getBaseType()->isConstantSizeType();
Chris Lattnerd52a4572007-12-18 07:03:30 +0000757 assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
Douglas Gregor898574e2008-12-05 23:32:09 +0000758 assert(!isDependentType() && "This doesn't make sense for dependent types");
Chris Lattner9bfa73c2007-12-18 07:18:16 +0000759 // The VAT must have a size, as it is known to be complete.
760 return !isa<VariableArrayType>(CanonicalType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000761}
762
763/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
764/// - a type that can describe objects, but which lacks information needed to
765/// determine its size.
Mike Stump1eb44332009-09-09 15:08:12 +0000766bool Type::isIncompleteType() const {
767 switch (CanonicalType->getTypeClass()) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000768 default: return false;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000769 case ExtQual:
770 return cast<ExtQualType>(CanonicalType)->getBaseType()->isIncompleteType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000771 case Builtin:
772 // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
773 // be completed.
774 return isVoidType();
Douglas Gregor72564e72009-02-26 23:50:07 +0000775 case Record:
Douglas Gregor72564e72009-02-26 23:50:07 +0000776 case Enum:
Reid Spencer5f016e22007-07-11 17:01:13 +0000777 // A tagged type (struct/union/enum/class) is incomplete if the decl is a
778 // forward declaration, but not a full definition (C99 6.2.5p22).
779 return !cast<TagType>(CanonicalType)->getDecl()->isDefinition();
Eli Friedmanc5773c42008-02-15 18:16:39 +0000780 case IncompleteArray:
Reid Spencer5f016e22007-07-11 17:01:13 +0000781 // An array of unknown size is an incomplete type (C99 6.2.5p22).
Eli Friedmanc5773c42008-02-15 18:16:39 +0000782 return true;
Chris Lattner1efaa952009-04-24 00:30:45 +0000783 case ObjCInterface:
Chris Lattner1efaa952009-04-24 00:30:45 +0000784 // ObjC interfaces are incomplete if they are @class, not @interface.
785 return cast<ObjCInterfaceType>(this)->getDecl()->isForwardDecl();
Reid Spencer5f016e22007-07-11 17:01:13 +0000786 }
787}
788
Sebastian Redl64b45f72009-01-05 20:52:13 +0000789/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10)
790bool Type::isPODType() const {
791 // The compiler shouldn't query this for incomplete types, but the user might.
792 // We return false for that case.
793 if (isIncompleteType())
794 return false;
795
796 switch (CanonicalType->getTypeClass()) {
797 // Everything not explicitly mentioned is not POD.
798 default: return false;
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000799 case ExtQual:
800 return cast<ExtQualType>(CanonicalType)->getBaseType()->isPODType();
Sebastian Redl64b45f72009-01-05 20:52:13 +0000801 case VariableArray:
802 case ConstantArray:
803 // IncompleteArray is caught by isIncompleteType() above.
804 return cast<ArrayType>(CanonicalType)->getElementType()->isPODType();
805
806 case Builtin:
807 case Complex:
808 case Pointer:
Sebastian Redlf30208a2009-01-24 21:16:55 +0000809 case MemberPointer:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000810 case Vector:
811 case ExtVector:
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000812 case ObjCObjectPointer:
Sebastian Redl64b45f72009-01-05 20:52:13 +0000813 return true;
814
Douglas Gregor72564e72009-02-26 23:50:07 +0000815 case Enum:
816 return true;
817
818 case Record:
Mike Stump1eb44332009-09-09 15:08:12 +0000819 if (CXXRecordDecl *ClassDecl
Douglas Gregorc1efaec2009-02-28 01:32:25 +0000820 = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
821 return ClassDecl->isPOD();
822
Sebastian Redl64b45f72009-01-05 20:52:13 +0000823 // C struct/union is POD.
824 return true;
825 }
826}
827
Reid Spencer5f016e22007-07-11 17:01:13 +0000828bool Type::isPromotableIntegerType() const {
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000829 if (const BuiltinType *BT = getAsBuiltinType())
830 switch (BT->getKind()) {
831 case BuiltinType::Bool:
832 case BuiltinType::Char_S:
833 case BuiltinType::Char_U:
834 case BuiltinType::SChar:
835 case BuiltinType::UChar:
836 case BuiltinType::Short:
837 case BuiltinType::UShort:
838 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000839 default:
Chris Lattner2a18dfe2009-01-12 00:21:19 +0000840 return false;
841 }
842 return false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000843}
844
Sebastian Redl6e8ed162009-05-10 18:38:11 +0000845bool Type::isNullPtrType() const {
846 if (const BuiltinType *BT = getAsBuiltinType())
847 return BT->getKind() == BuiltinType::NullPtr;
848 return false;
849}
850
Eli Friedman22b61e92009-05-30 00:10:16 +0000851bool Type::isSpecifierType() const {
852 // Note that this intentionally does not use the canonical type.
853 switch (getTypeClass()) {
854 case Builtin:
855 case Record:
856 case Enum:
857 case Typedef:
Eli Friedmanc8f2c612009-05-30 01:45:29 +0000858 case Complex:
859 case TypeOfExpr:
860 case TypeOf:
861 case TemplateTypeParm:
862 case TemplateSpecialization:
863 case QualifiedName:
864 case Typename:
865 case ObjCInterface:
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000866 case ObjCObjectPointer:
Eli Friedman22b61e92009-05-30 00:10:16 +0000867 return true;
868 default:
869 return false;
870 }
871}
872
Chris Lattnere4f21422009-06-30 01:26:17 +0000873const char *BuiltinType::getName(const LangOptions &LO) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000874 switch (getKind()) {
875 default: assert(0 && "Unknown builtin type!");
876 case Void: return "void";
Chris Lattnere4f21422009-06-30 01:26:17 +0000877 case Bool: return LO.Bool ? "bool" : "_Bool";
Reid Spencer5f016e22007-07-11 17:01:13 +0000878 case Char_S: return "char";
879 case Char_U: return "char";
880 case SChar: return "signed char";
881 case Short: return "short";
882 case Int: return "int";
883 case Long: return "long";
884 case LongLong: return "long long";
Chris Lattner2df9ced2009-04-30 02:43:43 +0000885 case Int128: return "__int128_t";
Reid Spencer5f016e22007-07-11 17:01:13 +0000886 case UChar: return "unsigned char";
887 case UShort: return "unsigned short";
888 case UInt: return "unsigned int";
889 case ULong: return "unsigned long";
890 case ULongLong: return "unsigned long long";
Chris Lattner2df9ced2009-04-30 02:43:43 +0000891 case UInt128: return "__uint128_t";
Reid Spencer5f016e22007-07-11 17:01:13 +0000892 case Float: return "float";
893 case Double: return "double";
894 case LongDouble: return "long double";
Argyrios Kyrtzidis46713ef2008-08-09 17:11:33 +0000895 case WChar: return "wchar_t";
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000896 case Char16: return "char16_t";
897 case Char32: return "char32_t";
Sebastian Redl6e8ed162009-05-10 18:38:11 +0000898 case NullPtr: return "nullptr_t";
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000899 case Overload: return "<overloaded function type>";
Douglas Gregor898574e2008-12-05 23:32:09 +0000900 case Dependent: return "<dependent type>";
Anders Carlsson6a75cd92009-07-11 00:34:39 +0000901 case UndeducedAuto: return "auto";
Steve Naroffde2e22d2009-07-15 18:40:39 +0000902 case ObjCId: return "id";
903 case ObjCClass: return "Class";
Reid Spencer5f016e22007-07-11 17:01:13 +0000904 }
905}
906
Douglas Gregor72564e72009-02-26 23:50:07 +0000907void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
Chris Lattner942cfd32007-07-20 18:48:28 +0000908 arg_type_iterator ArgTys,
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000909 unsigned NumArgs, bool isVariadic,
Sebastian Redl465226e2009-05-27 22:11:52 +0000910 unsigned TypeQuals, bool hasExceptionSpec,
911 bool anyExceptionSpec, unsigned NumExceptions,
Mike Stump24556362009-07-25 21:26:53 +0000912 exception_iterator Exs, bool NoReturn) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000913 ID.AddPointer(Result.getAsOpaquePtr());
914 for (unsigned i = 0; i != NumArgs; ++i)
915 ID.AddPointer(ArgTys[i].getAsOpaquePtr());
916 ID.AddInteger(isVariadic);
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000917 ID.AddInteger(TypeQuals);
Sebastian Redl465226e2009-05-27 22:11:52 +0000918 ID.AddInteger(hasExceptionSpec);
919 if (hasExceptionSpec) {
920 ID.AddInteger(anyExceptionSpec);
Mike Stump1eb44332009-09-09 15:08:12 +0000921 for (unsigned i = 0; i != NumExceptions; ++i)
Sebastian Redl465226e2009-05-27 22:11:52 +0000922 ID.AddPointer(Exs[i].getAsOpaquePtr());
923 }
Mike Stump24556362009-07-25 21:26:53 +0000924 ID.AddInteger(NoReturn);
Reid Spencer5f016e22007-07-11 17:01:13 +0000925}
926
Douglas Gregor72564e72009-02-26 23:50:07 +0000927void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) {
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000928 Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(),
Sebastian Redl465226e2009-05-27 22:11:52 +0000929 getTypeQuals(), hasExceptionSpec(), hasAnyExceptionSpec(),
Mike Stump24556362009-07-25 21:26:53 +0000930 getNumExceptions(), exception_begin(), getNoReturnAttr());
Reid Spencer5f016e22007-07-11 17:01:13 +0000931}
932
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000933void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID,
Steve Naroff14108da2009-07-10 23:34:53 +0000934 QualType OIT, ObjCProtocolDecl **protocols,
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000935 unsigned NumProtocols) {
Steve Naroff14108da2009-07-10 23:34:53 +0000936 ID.AddPointer(OIT.getAsOpaquePtr());
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000937 for (unsigned i = 0; i != NumProtocols; i++)
938 ID.AddPointer(protocols[i]);
939}
940
941void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID) {
Steve Naroff14108da2009-07-10 23:34:53 +0000942 if (getNumProtocols())
943 Profile(ID, getPointeeType(), &Protocols[0], getNumProtocols());
944 else
945 Profile(ID, getPointeeType(), 0, 0);
Steve Naroffd1b3c2d2009-06-17 22:40:22 +0000946}
947
Chris Lattnera2c77672007-07-16 22:05:22 +0000948/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
949/// potentially looking through *all* consequtive typedefs. This returns the
950/// sum of the type qualifiers, so if you have:
951/// typedef const int A;
952/// typedef volatile A B;
953/// looking through the typedefs for B will give you "const volatile A".
954///
955QualType TypedefType::LookThroughTypedefs() const {
956 // Usually, there is only a single level of typedefs, be fast in that case.
957 QualType FirstType = getDecl()->getUnderlyingType();
958 if (!isa<TypedefType>(FirstType))
959 return FirstType;
Mike Stump1eb44332009-09-09 15:08:12 +0000960
Chris Lattnera2c77672007-07-16 22:05:22 +0000961 // Otherwise, do the fully general loop.
962 unsigned TypeQuals = 0;
963 const TypedefType *TDT = this;
964 while (1) {
965 QualType CurType = TDT->getDecl()->getUnderlyingType();
Mike Stump1eb44332009-09-09 15:08:12 +0000966
967
Chris Lattnerf46699c2008-02-20 20:55:12 +0000968 /// FIXME:
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000969 /// FIXME: This is incorrect for ExtQuals!
Chris Lattnerf46699c2008-02-20 20:55:12 +0000970 /// FIXME:
971 TypeQuals |= CurType.getCVRQualifiers();
Chris Lattnera2c77672007-07-16 22:05:22 +0000972
973 TDT = dyn_cast<TypedefType>(CurType);
974 if (TDT == 0)
975 return QualType(CurType.getTypePtr(), TypeQuals);
976 }
977}
Reid Spencer5f016e22007-07-11 17:01:13 +0000978
Douglas Gregor72564e72009-02-26 23:50:07 +0000979TypeOfExprType::TypeOfExprType(Expr *E, QualType can)
980 : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) {
Douglas Gregor898574e2008-12-05 23:32:09 +0000981}
982
Mike Stump1eb44332009-09-09 15:08:12 +0000983void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
Douglas Gregorb1975722009-07-30 23:18:24 +0000984 ASTContext &Context, Expr *E) {
985 E->Profile(ID, Context, true);
986}
987
Anders Carlsson563a03b2009-07-10 19:20:26 +0000988DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can)
Mike Stump1eb44332009-09-09 15:08:12 +0000989 : Type(Decltype, can, E->isTypeDependent()), E(E),
Anders Carlsson563a03b2009-07-10 19:20:26 +0000990 UnderlyingType(underlyingType) {
Anders Carlsson395b4752009-06-24 19:06:50 +0000991}
992
Douglas Gregor9d702ae2009-07-30 23:36:40 +0000993DependentDecltypeType::DependentDecltypeType(ASTContext &Context, Expr *E)
994 : DecltypeType(E, Context.DependentTy), Context(Context) { }
995
Mike Stump1eb44332009-09-09 15:08:12 +0000996void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
Douglas Gregor9d702ae2009-07-30 23:36:40 +0000997 ASTContext &Context, Expr *E) {
998 E->Profile(ID, Context, true);
999}
1000
Mike Stump1eb44332009-09-09 15:08:12 +00001001TagType::TagType(TypeClass TC, TagDecl *D, QualType can)
Douglas Gregor7da97d02009-05-10 22:57:19 +00001002 : Type(TC, can, D->isDependentType()), decl(D, 0) {}
1003
Chris Lattner2daa5df2008-04-06 22:04:54 +00001004bool RecordType::classof(const TagType *TT) {
1005 return isa<RecordDecl>(TT->getDecl());
Reid Spencer5f016e22007-07-11 17:01:13 +00001006}
1007
Chris Lattner2daa5df2008-04-06 22:04:54 +00001008bool EnumType::classof(const TagType *TT) {
1009 return isa<EnumDecl>(TT->getDecl());
Chris Lattner5edb8bf2008-04-06 21:58:47 +00001010}
1011
Mike Stump1eb44332009-09-09 15:08:12 +00001012bool
Douglas Gregor7532dc62009-03-30 22:58:21 +00001013TemplateSpecializationType::
Douglas Gregor40808ce2009-03-09 23:48:35 +00001014anyDependentTemplateArguments(const TemplateArgument *Args, unsigned NumArgs) {
1015 for (unsigned Idx = 0; Idx < NumArgs; ++Idx) {
1016 switch (Args[Idx].getKind()) {
Douglas Gregord560d502009-06-04 00:21:18 +00001017 case TemplateArgument::Null:
1018 assert(false && "Should not have a NULL template argument");
1019 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001020
Douglas Gregor40808ce2009-03-09 23:48:35 +00001021 case TemplateArgument::Type:
1022 if (Args[Idx].getAsType()->isDependentType())
1023 return true;
1024 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001025
Douglas Gregor40808ce2009-03-09 23:48:35 +00001026 case TemplateArgument::Declaration:
1027 case TemplateArgument::Integral:
1028 // Never dependent
1029 break;
Douglas Gregor55f6b142009-02-09 18:46:07 +00001030
Douglas Gregor40808ce2009-03-09 23:48:35 +00001031 case TemplateArgument::Expression:
1032 if (Args[Idx].getAsExpr()->isTypeDependent() ||
1033 Args[Idx].getAsExpr()->isValueDependent())
1034 return true;
1035 break;
Mike Stump1eb44332009-09-09 15:08:12 +00001036
Anders Carlssond01b1da2009-06-15 17:04:53 +00001037 case TemplateArgument::Pack:
1038 assert(0 && "FIXME: Implement!");
1039 break;
Douglas Gregor55f6b142009-02-09 18:46:07 +00001040 }
Douglas Gregor55f6b142009-02-09 18:46:07 +00001041 }
Douglas Gregor40808ce2009-03-09 23:48:35 +00001042
1043 return false;
Douglas Gregor55f6b142009-02-09 18:46:07 +00001044}
1045
Douglas Gregor7532dc62009-03-30 22:58:21 +00001046TemplateSpecializationType::
Mike Stump1eb44332009-09-09 15:08:12 +00001047TemplateSpecializationType(ASTContext &Context, TemplateName T,
Douglas Gregor828e2262009-07-29 16:09:57 +00001048 const TemplateArgument *Args,
Douglas Gregor7532dc62009-03-30 22:58:21 +00001049 unsigned NumArgs, QualType Canon)
Mike Stump1eb44332009-09-09 15:08:12 +00001050 : Type(TemplateSpecialization,
Douglas Gregor40808ce2009-03-09 23:48:35 +00001051 Canon.isNull()? QualType(this, 0) : Canon,
Douglas Gregor7532dc62009-03-30 22:58:21 +00001052 T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)),
Douglas Gregor828e2262009-07-29 16:09:57 +00001053 Context(Context),
Mike Stump1eb44332009-09-09 15:08:12 +00001054 Template(T), NumArgs(NumArgs) {
1055 assert((!Canon.isNull() ||
Douglas Gregor7532dc62009-03-30 22:58:21 +00001056 T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) &&
Douglas Gregor40808ce2009-03-09 23:48:35 +00001057 "No canonical type for non-dependent class template specialization");
Douglas Gregor55f6b142009-02-09 18:46:07 +00001058
Mike Stump1eb44332009-09-09 15:08:12 +00001059 TemplateArgument *TemplateArgs
Douglas Gregor40808ce2009-03-09 23:48:35 +00001060 = reinterpret_cast<TemplateArgument *>(this + 1);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001061 for (unsigned Arg = 0; Arg < NumArgs; ++Arg)
Douglas Gregor40808ce2009-03-09 23:48:35 +00001062 new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001063}
1064
Douglas Gregor7532dc62009-03-30 22:58:21 +00001065void TemplateSpecializationType::Destroy(ASTContext& C) {
Douglas Gregorba498172009-03-13 21:01:28 +00001066 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1067 // FIXME: Not all expressions get cloned, so we can't yet perform
1068 // this destruction.
1069 // if (Expr *E = getArg(Arg).getAsExpr())
1070 // E->Destroy(C);
1071 }
Douglas Gregor5908e9f2009-02-09 19:34:22 +00001072}
1073
Douglas Gregor7532dc62009-03-30 22:58:21 +00001074TemplateSpecializationType::iterator
1075TemplateSpecializationType::end() const {
Douglas Gregor40808ce2009-03-09 23:48:35 +00001076 return begin() + getNumArgs();
Douglas Gregor55f6b142009-02-09 18:46:07 +00001077}
1078
Douglas Gregor40808ce2009-03-09 23:48:35 +00001079const TemplateArgument &
Douglas Gregor7532dc62009-03-30 22:58:21 +00001080TemplateSpecializationType::getArg(unsigned Idx) const {
Douglas Gregor40808ce2009-03-09 23:48:35 +00001081 assert(Idx < getNumArgs() && "Template argument out of range");
1082 return getArgs()[Idx];
1083}
1084
Mike Stump1eb44332009-09-09 15:08:12 +00001085void
1086TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
1087 TemplateName T,
1088 const TemplateArgument *Args,
Douglas Gregor828e2262009-07-29 16:09:57 +00001089 unsigned NumArgs,
1090 ASTContext &Context) {
Douglas Gregor7532dc62009-03-30 22:58:21 +00001091 T.Profile(ID);
Douglas Gregor40808ce2009-03-09 23:48:35 +00001092 for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
Douglas Gregor828e2262009-07-29 16:09:57 +00001093 Args[Idx].Profile(ID, Context);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001094}
Anders Carlsson97e01792008-12-21 00:16:32 +00001095
Douglas Gregor5e03f9e2009-07-23 23:49:00 +00001096const Type *QualifierSet::strip(const Type* T) {
1097 QualType DT = T->getDesugaredType();
John McCall7a1bcdf2009-07-28 05:41:20 +00001098 addCVR(DT.getCVRQualifiers());
Mike Stump1eb44332009-09-09 15:08:12 +00001099
Douglas Gregor5e03f9e2009-07-23 23:49:00 +00001100 if (const ExtQualType* EQT = dyn_cast<ExtQualType>(DT)) {
1101 if (EQT->getAddressSpace())
John McCall7a1bcdf2009-07-28 05:41:20 +00001102 addAddressSpace(EQT->getAddressSpace());
Douglas Gregor5e03f9e2009-07-23 23:49:00 +00001103 if (EQT->getObjCGCAttr())
John McCall7a1bcdf2009-07-28 05:41:20 +00001104 addObjCGCAttrType(EQT->getObjCGCAttr());
Douglas Gregor5e03f9e2009-07-23 23:49:00 +00001105 return EQT->getBaseType();
Mike Stump24556362009-07-25 21:26:53 +00001106 } else {
Douglas Gregor5e03f9e2009-07-23 23:49:00 +00001107 // Use the sugared type unless desugaring found extra qualifiers.
1108 return (DT.getCVRQualifiers() ? DT.getTypePtr() : T);
1109 }
1110}
1111
1112QualType QualifierSet::apply(QualType QT, ASTContext& C) {
John McCall7a1bcdf2009-07-28 05:41:20 +00001113 QT = QT.getWithAdditionalQualifiers(getCVRMask());
1114 if (hasObjCGCAttrType()) QT = C.getObjCGCQualType(QT, getObjCGCAttrType());
1115 if (hasAddressSpace()) QT = C.getAddrSpaceQualType(QT, getAddressSpace());
Douglas Gregor5e03f9e2009-07-23 23:49:00 +00001116 return QT;
1117}
1118
1119
Reid Spencer5f016e22007-07-11 17:01:13 +00001120//===----------------------------------------------------------------------===//
1121// Type Printing
1122//===----------------------------------------------------------------------===//
1123
1124void QualType::dump(const char *msg) const {
Chris Lattner39caea92007-12-06 04:20:07 +00001125 std::string R = "identifier";
Chris Lattnere4f21422009-06-30 01:26:17 +00001126 LangOptions LO;
1127 getAsStringInternal(R, PrintingPolicy(LO));
Reid Spencer5f016e22007-07-11 17:01:13 +00001128 if (msg)
1129 fprintf(stderr, "%s: %s\n", msg, R.c_str());
1130 else
1131 fprintf(stderr, "%s\n", R.c_str());
1132}
Chris Lattnerc36d4052008-07-27 00:48:22 +00001133void QualType::dump() const {
1134 dump("");
1135}
1136
1137void Type::dump() const {
1138 std::string S = "identifier";
Chris Lattnere4f21422009-06-30 01:26:17 +00001139 LangOptions LO;
1140 getAsStringInternal(S, PrintingPolicy(LO));
Chris Lattnerc36d4052008-07-27 00:48:22 +00001141 fprintf(stderr, "%s\n", S.c_str());
1142}
1143
1144
Reid Spencer5f016e22007-07-11 17:01:13 +00001145
1146static void AppendTypeQualList(std::string &S, unsigned TypeQuals) {
1147 // Note: funkiness to ensure we get a space only between quals.
1148 bool NonePrinted = true;
1149 if (TypeQuals & QualType::Const)
1150 S += "const", NonePrinted = false;
1151 if (TypeQuals & QualType::Volatile)
1152 S += (NonePrinted+" volatile"), NonePrinted = false;
1153 if (TypeQuals & QualType::Restrict)
1154 S += (NonePrinted+" restrict"), NonePrinted = false;
1155}
1156
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001157std::string QualType::getAsString() const {
1158 std::string S;
Chris Lattnere4f21422009-06-30 01:26:17 +00001159 LangOptions LO;
1160 getAsStringInternal(S, PrintingPolicy(LO));
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001161 return S;
1162}
1163
Mike Stump1eb44332009-09-09 15:08:12 +00001164void
1165QualType::getAsStringInternal(std::string &S,
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001166 const PrintingPolicy &Policy) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001167 if (isNull()) {
Douglas Gregor61366e92008-12-24 00:01:03 +00001168 S += "NULL TYPE";
Reid Spencer5f016e22007-07-11 17:01:13 +00001169 return;
1170 }
Eli Friedman22b61e92009-05-30 00:10:16 +00001171
Eli Friedman42f42c02009-05-30 04:20:30 +00001172 if (Policy.SuppressSpecifiers && getTypePtr()->isSpecifierType())
Eli Friedman22b61e92009-05-30 00:10:16 +00001173 return;
1174
Reid Spencer5f016e22007-07-11 17:01:13 +00001175 // Print qualifiers as appropriate.
Gabor Greif3513e132008-02-21 17:40:55 +00001176 if (unsigned Tq = getCVRQualifiers()) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001177 std::string TQS;
Gabor Greif3513e132008-02-21 17:40:55 +00001178 AppendTypeQualList(TQS, Tq);
Reid Spencer5f016e22007-07-11 17:01:13 +00001179 if (!S.empty())
1180 S = TQS + ' ' + S;
1181 else
1182 S = TQS;
1183 }
1184
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001185 getTypePtr()->getAsStringInternal(S, Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001186}
1187
Mike Stump1eb44332009-09-09 15:08:12 +00001188void BuiltinType::getAsStringInternal(std::string &S,
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001189 const PrintingPolicy &Policy) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001190 if (S.empty()) {
Chris Lattnere4f21422009-06-30 01:26:17 +00001191 S = getName(Policy.LangOpts);
Reid Spencer5f016e22007-07-11 17:01:13 +00001192 } else {
1193 // Prefix the basic type, e.g. 'int X'.
1194 S = ' ' + S;
Chris Lattnere4f21422009-06-30 01:26:17 +00001195 S = getName(Policy.LangOpts) + S;
Reid Spencer5f016e22007-07-11 17:01:13 +00001196 }
1197}
1198
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001199void FixedWidthIntType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Eli Friedmanf98aba32009-02-13 02:31:07 +00001200 // FIXME: Once we get bitwidth attribute, write as
1201 // "int __attribute__((bitwidth(x)))".
1202 std::string prefix = "__clang_fixedwidth";
1203 prefix += llvm::utostr_32(Width);
1204 prefix += (char)(Signed ? 'S' : 'U');
1205 if (S.empty()) {
1206 S = prefix;
1207 } else {
1208 // Prefix the basic type, e.g. 'int X'.
1209 S = prefix + S;
1210 }
1211}
1212
1213
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001214void ComplexType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
1215 ElementType->getAsStringInternal(S, Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001216 S = "_Complex " + S;
1217}
1218
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001219void ExtQualType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Chris Lattner3b6b83b2009-02-18 22:58:38 +00001220 bool NeedsSpace = false;
Fariborz Jahanian4886a422009-02-17 21:45:36 +00001221 if (AddressSpace) {
Fariborz Jahanian59d16d12009-02-17 20:16:45 +00001222 S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S;
Chris Lattner3b6b83b2009-02-18 22:58:38 +00001223 NeedsSpace = true;
Fariborz Jahanian59d16d12009-02-17 20:16:45 +00001224 }
Fariborz Jahaniand33d9c02009-02-18 05:09:49 +00001225 if (GCAttrType != QualType::GCNone) {
Chris Lattner3b6b83b2009-02-18 22:58:38 +00001226 if (NeedsSpace)
Fariborz Jahanian59d16d12009-02-17 20:16:45 +00001227 S += ' ';
1228 S += "__attribute__((objc_gc(";
Fariborz Jahaniand33d9c02009-02-18 05:09:49 +00001229 if (GCAttrType == QualType::Weak)
Fariborz Jahanian59d16d12009-02-17 20:16:45 +00001230 S += "weak";
1231 else
1232 S += "strong";
1233 S += ")))";
1234 }
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001235 BaseType->getAsStringInternal(S, Policy);
Christopher Lambebb97e92008-02-04 02:31:56 +00001236}
1237
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001238void PointerType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001239 S = '*' + S;
Mike Stump1eb44332009-09-09 15:08:12 +00001240
Reid Spencer5f016e22007-07-11 17:01:13 +00001241 // Handle things like 'int (*A)[4];' correctly.
1242 // FIXME: this should include vectors, but vectors use attributes I guess.
Chris Lattnerbdcd6372008-04-02 17:35:06 +00001243 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +00001244 S = '(' + S + ')';
Mike Stump1eb44332009-09-09 15:08:12 +00001245
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001246 getPointeeType().getAsStringInternal(S, Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001247}
1248
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001249void BlockPointerType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Steve Naroff5618bd42008-08-27 16:04:49 +00001250 S = '^' + S;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001251 PointeeType.getAsStringInternal(S, Policy);
Steve Naroff5618bd42008-08-27 16:04:49 +00001252}
1253
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001254void LValueReferenceType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001255 S = '&' + S;
Sebastian Redl7c80bd62009-03-16 23:22:08 +00001256
Reid Spencer5f016e22007-07-11 17:01:13 +00001257 // Handle things like 'int (&A)[4];' correctly.
1258 // FIXME: this should include vectors, but vectors use attributes I guess.
Chris Lattnerbdcd6372008-04-02 17:35:06 +00001259 if (isa<ArrayType>(getPointeeType()))
Reid Spencer5f016e22007-07-11 17:01:13 +00001260 S = '(' + S + ')';
Sebastian Redl7c80bd62009-03-16 23:22:08 +00001261
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001262 getPointeeType().getAsStringInternal(S, Policy);
Sebastian Redl7c80bd62009-03-16 23:22:08 +00001263}
1264
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001265void RValueReferenceType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Sebastian Redl7c80bd62009-03-16 23:22:08 +00001266 S = "&&" + S;
1267
1268 // Handle things like 'int (&&A)[4];' correctly.
1269 // FIXME: this should include vectors, but vectors use attributes I guess.
1270 if (isa<ArrayType>(getPointeeType()))
1271 S = '(' + S + ')';
1272
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001273 getPointeeType().getAsStringInternal(S, Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001274}
1275
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001276void MemberPointerType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Sebastian Redlf30208a2009-01-24 21:16:55 +00001277 std::string C;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001278 Class->getAsStringInternal(C, Policy);
Sebastian Redlf30208a2009-01-24 21:16:55 +00001279 C += "::*";
1280 S = C + S;
1281
Sebastian Redl7c80bd62009-03-16 23:22:08 +00001282 // Handle things like 'int (Cls::*A)[4];' correctly.
Sebastian Redlf30208a2009-01-24 21:16:55 +00001283 // FIXME: this should include vectors, but vectors use attributes I guess.
1284 if (isa<ArrayType>(getPointeeType()))
1285 S = '(' + S + ')';
1286
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001287 getPointeeType().getAsStringInternal(S, Policy);
Sebastian Redlf30208a2009-01-24 21:16:55 +00001288}
1289
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001290void ConstantArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Steve Narofffb22d962007-08-30 01:06:46 +00001291 S += '[';
Steve Naroff6b91cd92007-08-30 18:45:57 +00001292 S += llvm::utostr(getSize().getZExtValue());
Steve Narofffb22d962007-08-30 01:06:46 +00001293 S += ']';
Mike Stump1eb44332009-09-09 15:08:12 +00001294
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001295 getElementType().getAsStringInternal(S, Policy);
Steve Narofffb22d962007-08-30 01:06:46 +00001296}
1297
Douglas Gregor7e7eb3d2009-07-06 15:59:29 +00001298void ConstantArrayWithExprType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
1299 if (Policy.ConstantArraySizeAsWritten) {
1300 std::string SStr;
1301 llvm::raw_string_ostream s(SStr);
1302 getSizeExpr()->printPretty(s, 0, Policy);
1303 S += '[';
1304 S += s.str();
1305 S += ']';
1306 getElementType().getAsStringInternal(S, Policy);
1307 }
1308 else
1309 ConstantArrayType::getAsStringInternal(S, Policy);
1310}
1311
1312void ConstantArrayWithoutExprType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
1313 if (Policy.ConstantArraySizeAsWritten) {
1314 S += "[]";
1315 getElementType().getAsStringInternal(S, Policy);
1316 }
1317 else
1318 ConstantArrayType::getAsStringInternal(S, Policy);
1319}
1320
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001321void IncompleteArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Eli Friedmanc5773c42008-02-15 18:16:39 +00001322 S += "[]";
1323
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001324 getElementType().getAsStringInternal(S, Policy);
Eli Friedmanc5773c42008-02-15 18:16:39 +00001325}
1326
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001327void VariableArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001328 S += '[';
Mike Stump1eb44332009-09-09 15:08:12 +00001329
Steve Naroffc9406122007-08-30 18:10:14 +00001330 if (getIndexTypeQualifier()) {
1331 AppendTypeQualList(S, getIndexTypeQualifier());
Reid Spencer5f016e22007-07-11 17:01:13 +00001332 S += ' ';
1333 }
Mike Stump1eb44332009-09-09 15:08:12 +00001334
Steve Naroffc9406122007-08-30 18:10:14 +00001335 if (getSizeModifier() == Static)
Reid Spencer5f016e22007-07-11 17:01:13 +00001336 S += "static";
Steve Naroffc9406122007-08-30 18:10:14 +00001337 else if (getSizeModifier() == Star)
Reid Spencer5f016e22007-07-11 17:01:13 +00001338 S += '*';
Mike Stump1eb44332009-09-09 15:08:12 +00001339
Steve Narofffb22d962007-08-30 01:06:46 +00001340 if (getSizeExpr()) {
Ted Kremeneka95d3752008-09-13 05:16:45 +00001341 std::string SStr;
1342 llvm::raw_string_ostream s(SStr);
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001343 getSizeExpr()->printPretty(s, 0, Policy);
Steve Narofffb22d962007-08-30 01:06:46 +00001344 S += s.str();
1345 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001346 S += ']';
Mike Stump1eb44332009-09-09 15:08:12 +00001347
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001348 getElementType().getAsStringInternal(S, Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001349}
1350
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001351void DependentSizedArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Douglas Gregor898574e2008-12-05 23:32:09 +00001352 S += '[';
Mike Stump1eb44332009-09-09 15:08:12 +00001353
Douglas Gregor898574e2008-12-05 23:32:09 +00001354 if (getIndexTypeQualifier()) {
1355 AppendTypeQualList(S, getIndexTypeQualifier());
1356 S += ' ';
1357 }
Mike Stump1eb44332009-09-09 15:08:12 +00001358
Douglas Gregor898574e2008-12-05 23:32:09 +00001359 if (getSizeModifier() == Static)
1360 S += "static";
1361 else if (getSizeModifier() == Star)
1362 S += '*';
Mike Stump1eb44332009-09-09 15:08:12 +00001363
Douglas Gregor898574e2008-12-05 23:32:09 +00001364 if (getSizeExpr()) {
1365 std::string SStr;
1366 llvm::raw_string_ostream s(SStr);
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001367 getSizeExpr()->printPretty(s, 0, Policy);
Douglas Gregor898574e2008-12-05 23:32:09 +00001368 S += s.str();
1369 }
1370 S += ']';
Mike Stump1eb44332009-09-09 15:08:12 +00001371
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001372 getElementType().getAsStringInternal(S, Policy);
Douglas Gregor898574e2008-12-05 23:32:09 +00001373}
1374
Douglas Gregor9cdda0c2009-06-17 21:51:59 +00001375void DependentSizedExtVectorType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
1376 getElementType().getAsStringInternal(S, Policy);
1377
Douglas Gregorf6ddb732009-06-18 18:45:36 +00001378 S += " __attribute__((ext_vector_type(";
Douglas Gregor9cdda0c2009-06-17 21:51:59 +00001379 if (getSizeExpr()) {
1380 std::string SStr;
1381 llvm::raw_string_ostream s(SStr);
1382 getSizeExpr()->printPretty(s, 0, Policy);
1383 S += s.str();
1384 }
1385 S += ")))";
1386}
1387
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001388void VectorType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Daniel Dunbar5620b502008-10-05 05:43:11 +00001389 // FIXME: We prefer to print the size directly here, but have no way
1390 // to get the size of the type.
Chris Lattner7ee261c2007-11-27 07:28:18 +00001391 S += " __attribute__((__vector_size__(";
Daniel Dunbar5620b502008-10-05 05:43:11 +00001392 S += llvm::utostr_32(NumElements); // convert back to bytes.
1393 S += " * sizeof(" + ElementType.getAsString() + "))))";
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001394 ElementType.getAsStringInternal(S, Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001395}
1396
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001397void ExtVectorType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Nate Begeman213541a2008-04-18 23:10:10 +00001398 S += " __attribute__((ext_vector_type(";
Steve Naroff31a45842007-07-28 23:10:27 +00001399 S += llvm::utostr_32(NumElements);
1400 S += ")))";
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001401 ElementType.getAsStringInternal(S, Policy);
Steve Naroff31a45842007-07-28 23:10:27 +00001402}
1403
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001404void TypeOfExprType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
Steve Naroff363bcff2007-08-01 23:45:51 +00001405 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'.
1406 InnerString = ' ' + InnerString;
Ted Kremeneka95d3752008-09-13 05:16:45 +00001407 std::string Str;
1408 llvm::raw_string_ostream s(Str);
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001409 getUnderlyingExpr()->printPretty(s, 0, Policy);
Argyrios Kyrtzidis64096252009-05-22 10:22:18 +00001410 InnerString = "typeof " + s.str() + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001411}
1412
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001413void TypeOfType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
Steve Naroff363bcff2007-08-01 23:45:51 +00001414 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'.
1415 InnerString = ' ' + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001416 std::string Tmp;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001417 getUnderlyingType().getAsStringInternal(Tmp, Policy);
Steve Naroff363bcff2007-08-01 23:45:51 +00001418 InnerString = "typeof(" + Tmp + ")" + InnerString;
Steve Naroffd1861fd2007-07-31 12:34:36 +00001419}
1420
Mike Stump1eb44332009-09-09 15:08:12 +00001421void DecltypeType::getAsStringInternal(std::string &InnerString,
Anders Carlsson395b4752009-06-24 19:06:50 +00001422 const PrintingPolicy &Policy) const {
1423 if (!InnerString.empty()) // Prefix the basic type, e.g. 'decltype(t) X'.
1424 InnerString = ' ' + InnerString;
1425 std::string Str;
1426 llvm::raw_string_ostream s(Str);
1427 getUnderlyingExpr()->printPretty(s, 0, Policy);
1428 InnerString = "decltype(" + s.str() + ")" + InnerString;
1429}
1430
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001431void FunctionNoProtoType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001432 // If needed for precedence reasons, wrap the inner part in grouping parens.
1433 if (!S.empty())
1434 S = "(" + S + ")";
Mike Stump1eb44332009-09-09 15:08:12 +00001435
Reid Spencer5f016e22007-07-11 17:01:13 +00001436 S += "()";
Mike Stump24556362009-07-25 21:26:53 +00001437 if (getNoReturnAttr())
1438 S += " __attribute__((noreturn))";
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001439 getResultType().getAsStringInternal(S, Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001440}
1441
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001442void FunctionProtoType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001443 // If needed for precedence reasons, wrap the inner part in grouping parens.
1444 if (!S.empty())
1445 S = "(" + S + ")";
Mike Stump1eb44332009-09-09 15:08:12 +00001446
Reid Spencer5f016e22007-07-11 17:01:13 +00001447 S += "(";
1448 std::string Tmp;
Eli Friedman22b61e92009-05-30 00:10:16 +00001449 PrintingPolicy ParamPolicy(Policy);
Eli Friedman42f42c02009-05-30 04:20:30 +00001450 ParamPolicy.SuppressSpecifiers = false;
Reid Spencer5f016e22007-07-11 17:01:13 +00001451 for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
1452 if (i) S += ", ";
Eli Friedman22b61e92009-05-30 00:10:16 +00001453 getArgType(i).getAsStringInternal(Tmp, ParamPolicy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001454 S += Tmp;
1455 Tmp.clear();
1456 }
Mike Stump1eb44332009-09-09 15:08:12 +00001457
Reid Spencer5f016e22007-07-11 17:01:13 +00001458 if (isVariadic()) {
1459 if (getNumArgs())
1460 S += ", ";
1461 S += "...";
Chris Lattnere4f21422009-06-30 01:26:17 +00001462 } else if (getNumArgs() == 0 && !Policy.LangOpts.CPlusPlus) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001463 // Do not emit int() if we have a proto, emit 'int(void)'.
1464 S += "void";
1465 }
Mike Stump1eb44332009-09-09 15:08:12 +00001466
Reid Spencer5f016e22007-07-11 17:01:13 +00001467 S += ")";
Mike Stump24556362009-07-25 21:26:53 +00001468 if (getNoReturnAttr())
1469 S += " __attribute__((noreturn))";
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001470 getResultType().getAsStringInternal(S, Policy);
Reid Spencer5f016e22007-07-11 17:01:13 +00001471}
1472
1473
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001474void TypedefType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
Reid Spencer5f016e22007-07-11 17:01:13 +00001475 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1476 InnerString = ' ' + InnerString;
1477 InnerString = getDecl()->getIdentifier()->getName() + InnerString;
1478}
1479
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001480void TemplateTypeParmType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
Douglas Gregor72c3f312008-12-05 18:15:24 +00001481 if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'.
1482 InnerString = ' ' + InnerString;
Douglas Gregorfab9d672009-02-05 23:33:38 +00001483
1484 if (!Name)
Mike Stump1eb44332009-09-09 15:08:12 +00001485 InnerString = "type-parameter-" + llvm::utostr_32(Depth) + '-' +
Douglas Gregorfab9d672009-02-05 23:33:38 +00001486 llvm::utostr_32(Index) + InnerString;
1487 else
1488 InnerString = Name->getName() + InnerString;
Douglas Gregor72c3f312008-12-05 18:15:24 +00001489}
1490
Mike Stump1eb44332009-09-09 15:08:12 +00001491std::string
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001492TemplateSpecializationType::PrintTemplateArgumentList(
1493 const TemplateArgument *Args,
1494 unsigned NumArgs,
1495 const PrintingPolicy &Policy) {
Douglas Gregor98137532009-03-10 18:33:27 +00001496 std::string SpecString;
Douglas Gregor55f6b142009-02-09 18:46:07 +00001497 SpecString += '<';
1498 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1499 if (Arg)
1500 SpecString += ", ";
Mike Stump1eb44332009-09-09 15:08:12 +00001501
Douglas Gregor55f6b142009-02-09 18:46:07 +00001502 // Print the argument into a string.
1503 std::string ArgString;
Douglas Gregor98137532009-03-10 18:33:27 +00001504 switch (Args[Arg].getKind()) {
Douglas Gregor38999462009-06-04 05:28:55 +00001505 case TemplateArgument::Null:
1506 assert(false && "Null template argument");
1507 break;
1508
Douglas Gregor40808ce2009-03-09 23:48:35 +00001509 case TemplateArgument::Type:
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001510 Args[Arg].getAsType().getAsStringInternal(ArgString, Policy);
Douglas Gregor40808ce2009-03-09 23:48:35 +00001511 break;
1512
1513 case TemplateArgument::Declaration:
Douglas Gregor98137532009-03-10 18:33:27 +00001514 ArgString = cast<NamedDecl>(Args[Arg].getAsDecl())->getNameAsString();
Douglas Gregor40808ce2009-03-09 23:48:35 +00001515 break;
1516
1517 case TemplateArgument::Integral:
Douglas Gregor98137532009-03-10 18:33:27 +00001518 ArgString = Args[Arg].getAsIntegral()->toString(10, true);
Douglas Gregor40808ce2009-03-09 23:48:35 +00001519 break;
1520
1521 case TemplateArgument::Expression: {
Douglas Gregor55f6b142009-02-09 18:46:07 +00001522 llvm::raw_string_ostream s(ArgString);
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001523 Args[Arg].getAsExpr()->printPretty(s, 0, Policy);
Douglas Gregor40808ce2009-03-09 23:48:35 +00001524 break;
1525 }
Anders Carlssond01b1da2009-06-15 17:04:53 +00001526 case TemplateArgument::Pack:
1527 assert(0 && "FIXME: Implement!");
1528 break;
Douglas Gregor55f6b142009-02-09 18:46:07 +00001529 }
1530
1531 // If this is the first argument and its string representation
1532 // begins with the global scope specifier ('::foo'), add a space
1533 // to avoid printing the diagraph '<:'.
1534 if (!Arg && !ArgString.empty() && ArgString[0] == ':')
1535 SpecString += ' ';
1536
1537 SpecString += ArgString;
1538 }
1539
1540 // If the last character of our string is '>', add another space to
1541 // keep the two '>''s separate tokens. We don't *have* to do this in
1542 // C++0x, but it's still good hygiene.
1543 if (SpecString[SpecString.size() - 1] == '>')
1544 SpecString += ' ';
1545
1546 SpecString += '>';
1547
Douglas Gregor98137532009-03-10 18:33:27 +00001548 return SpecString;
1549}
1550
Mike Stump1eb44332009-09-09 15:08:12 +00001551void
Douglas Gregor7532dc62009-03-30 22:58:21 +00001552TemplateSpecializationType::
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001553getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
Douglas Gregor7532dc62009-03-30 22:58:21 +00001554 std::string SpecString;
1555
1556 {
1557 llvm::raw_string_ostream OS(SpecString);
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001558 Template.print(OS, Policy);
Douglas Gregor7532dc62009-03-30 22:58:21 +00001559 }
1560
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001561 SpecString += PrintTemplateArgumentList(getArgs(), getNumArgs(), Policy);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001562 if (InnerString.empty())
1563 InnerString.swap(SpecString);
1564 else
1565 InnerString = SpecString + ' ' + InnerString;
1566}
1567
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001568void QualifiedNameType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
Douglas Gregore4e5b052009-03-19 00:18:19 +00001569 std::string MyString;
1570
Douglas Gregorbad35182009-03-19 03:51:16 +00001571 {
1572 llvm::raw_string_ostream OS(MyString);
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001573 NNS->print(OS, Policy);
Douglas Gregore4e5b052009-03-19 00:18:19 +00001574 }
Mike Stump1eb44332009-09-09 15:08:12 +00001575
Douglas Gregore4e5b052009-03-19 00:18:19 +00001576 std::string TypeStr;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001577 PrintingPolicy InnerPolicy(Policy);
1578 InnerPolicy.SuppressTagKind = true;
John McCall2191b202009-09-05 06:31:47 +00001579 InnerPolicy.SuppressScope = true;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001580 NamedType.getAsStringInternal(TypeStr, InnerPolicy);
Douglas Gregore4e5b052009-03-19 00:18:19 +00001581
1582 MyString += TypeStr;
1583 if (InnerString.empty())
1584 InnerString.swap(MyString);
1585 else
1586 InnerString = MyString + ' ' + InnerString;
1587}
1588
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001589void TypenameType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
Douglas Gregord57959a2009-03-27 23:10:48 +00001590 std::string MyString;
1591
1592 {
1593 llvm::raw_string_ostream OS(MyString);
1594 OS << "typename ";
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001595 NNS->print(OS, Policy);
Douglas Gregor17343172009-04-01 00:28:59 +00001596
1597 if (const IdentifierInfo *Ident = getIdentifier())
1598 OS << Ident->getName();
1599 else if (const TemplateSpecializationType *Spec = getTemplateId()) {
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001600 Spec->getTemplateName().print(OS, Policy, true);
Douglas Gregor17343172009-04-01 00:28:59 +00001601 OS << TemplateSpecializationType::PrintTemplateArgumentList(
Mike Stump1eb44332009-09-09 15:08:12 +00001602 Spec->getArgs(),
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001603 Spec->getNumArgs(),
1604 Policy);
Douglas Gregor17343172009-04-01 00:28:59 +00001605 }
Douglas Gregord57959a2009-03-27 23:10:48 +00001606 }
Mike Stump1eb44332009-09-09 15:08:12 +00001607
Douglas Gregord57959a2009-03-27 23:10:48 +00001608 if (InnerString.empty())
1609 InnerString.swap(MyString);
1610 else
1611 InnerString = MyString + ' ' + InnerString;
1612}
1613
Steve Naroffc15cb2a2009-07-18 15:33:26 +00001614void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
1615 const ObjCInterfaceDecl *Decl,
Mike Stump1eb44332009-09-09 15:08:12 +00001616 ObjCProtocolDecl **protocols,
Steve Naroffc15cb2a2009-07-18 15:33:26 +00001617 unsigned NumProtocols) {
1618 ID.AddPointer(Decl);
1619 for (unsigned i = 0; i != NumProtocols; i++)
1620 ID.AddPointer(protocols[i]);
1621}
1622
1623void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
1624 if (getNumProtocols())
1625 Profile(ID, getDecl(), &Protocols[0], getNumProtocols());
1626 else
1627 Profile(ID, getDecl(), 0, 0);
1628}
1629
1630void ObjCInterfaceType::getAsStringInternal(std::string &InnerString,
1631 const PrintingPolicy &Policy) const {
Steve Naroff3536b442007-09-06 21:24:23 +00001632 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1633 InnerString = ' ' + InnerString;
Mike Stump1eb44332009-09-09 15:08:12 +00001634
Steve Naroffc15cb2a2009-07-18 15:33:26 +00001635 std::string ObjCQIString = getDecl()->getNameAsString();
1636 if (getNumProtocols()) {
1637 ObjCQIString += '<';
1638 bool isFirst = true;
1639 for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) {
1640 if (isFirst)
1641 isFirst = false;
1642 else
1643 ObjCQIString += ',';
1644 ObjCQIString += (*I)->getNameAsString();
1645 }
1646 ObjCQIString += '>';
1647 }
1648 InnerString = ObjCQIString + InnerString;
Steve Naroff3536b442007-09-06 21:24:23 +00001649}
1650
Mike Stump1eb44332009-09-09 15:08:12 +00001651void ObjCObjectPointerType::getAsStringInternal(std::string &InnerString,
Steve Naroffd1b3c2d2009-06-17 22:40:22 +00001652 const PrintingPolicy &Policy) const {
Steve Naroffde2e22d2009-07-15 18:40:39 +00001653 std::string ObjCQIString;
Mike Stump1eb44332009-09-09 15:08:12 +00001654
Steve Naroffde2e22d2009-07-15 18:40:39 +00001655 if (isObjCIdType() || isObjCQualifiedIdType())
1656 ObjCQIString = "id";
Steve Naroff470301b2009-07-22 16:07:01 +00001657 else if (isObjCClassType() || isObjCQualifiedClassType())
Steve Naroffde2e22d2009-07-15 18:40:39 +00001658 ObjCQIString = "Class";
1659 else
1660 ObjCQIString = getInterfaceDecl()->getNameAsString();
Steve Naroffd1b3c2d2009-06-17 22:40:22 +00001661
1662 if (!qual_empty()) {
1663 ObjCQIString += '<';
1664 for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) {
1665 ObjCQIString += (*I)->getNameAsString();
1666 if (I+1 != E)
1667 ObjCQIString += ',';
1668 }
1669 ObjCQIString += '>';
1670 }
Steve Naroff14108da2009-07-10 23:34:53 +00001671 if (!isObjCIdType() && !isObjCQualifiedIdType())
1672 ObjCQIString += " *"; // Don't forget the implicit pointer.
1673 else if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1674 InnerString = ' ' + InnerString;
1675
Steve Naroffd1b3c2d2009-06-17 22:40:22 +00001676 InnerString = ObjCQIString + InnerString;
1677}
1678
Mike Stump1eb44332009-09-09 15:08:12 +00001679void ElaboratedType::getAsStringInternal(std::string &InnerString,
John McCall7da24312009-09-05 00:15:47 +00001680 const PrintingPolicy &Policy) const {
1681 std::string TypeStr;
1682 PrintingPolicy InnerPolicy(Policy);
1683 InnerPolicy.SuppressTagKind = true;
1684 UnderlyingType.getAsStringInternal(InnerString, InnerPolicy);
1685
1686 InnerString = std::string(getNameForTagKind(getTagKind())) + ' ' + InnerString;
1687}
1688
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001689void TagType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
Eli Friedman42f42c02009-05-30 04:20:30 +00001690 if (Policy.SuppressTag)
1691 return;
1692
Reid Spencer5f016e22007-07-11 17:01:13 +00001693 if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
1694 InnerString = ' ' + InnerString;
Mike Stump1eb44332009-09-09 15:08:12 +00001695
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001696 const char *Kind = Policy.SuppressTagKind? 0 : getDecl()->getKindName();
Reid Spencer5f016e22007-07-11 17:01:13 +00001697 const char *ID;
1698 if (const IdentifierInfo *II = getDecl()->getIdentifier())
1699 ID = II->getName();
Douglas Gregor4e16d042009-03-10 18:11:21 +00001700 else if (TypedefDecl *Typedef = getDecl()->getTypedefForAnonDecl()) {
1701 Kind = 0;
1702 assert(Typedef->getIdentifier() && "Typedef without identifier?");
1703 ID = Typedef->getIdentifier()->getName();
1704 } else
Reid Spencer5f016e22007-07-11 17:01:13 +00001705 ID = "<anonymous>";
1706
Douglas Gregor98137532009-03-10 18:33:27 +00001707 // If this is a class template specialization, print the template
1708 // arguments.
Mike Stump1eb44332009-09-09 15:08:12 +00001709 if (ClassTemplateSpecializationDecl *Spec
Douglas Gregor98137532009-03-10 18:33:27 +00001710 = dyn_cast<ClassTemplateSpecializationDecl>(getDecl())) {
Douglas Gregor7e063902009-05-11 23:53:27 +00001711 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
Mike Stump1eb44332009-09-09 15:08:12 +00001712 std::string TemplateArgsStr
Douglas Gregor7532dc62009-03-30 22:58:21 +00001713 = TemplateSpecializationType::PrintTemplateArgumentList(
Douglas Gregor7e063902009-05-11 23:53:27 +00001714 TemplateArgs.getFlatArgumentList(),
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001715 TemplateArgs.flat_size(),
1716 Policy);
Douglas Gregor7e063902009-05-11 23:53:27 +00001717 InnerString = TemplateArgsStr + InnerString;
Douglas Gregor98137532009-03-10 18:33:27 +00001718 }
1719
John McCall2191b202009-09-05 06:31:47 +00001720 if (!Policy.SuppressScope) {
Douglas Gregor24c46b32009-03-19 04:25:59 +00001721 // Compute the full nested-name-specifier for this type. In C,
1722 // this will always be empty.
1723 std::string ContextStr;
Mike Stump1eb44332009-09-09 15:08:12 +00001724 for (DeclContext *DC = getDecl()->getDeclContext();
Douglas Gregor24c46b32009-03-19 04:25:59 +00001725 !DC->isTranslationUnit(); DC = DC->getParent()) {
1726 std::string MyPart;
1727 if (NamespaceDecl *NS = dyn_cast<NamespaceDecl>(DC)) {
1728 if (NS->getIdentifier())
1729 MyPart = NS->getNameAsString();
Mike Stump1eb44332009-09-09 15:08:12 +00001730 } else if (ClassTemplateSpecializationDecl *Spec
Douglas Gregor24c46b32009-03-19 04:25:59 +00001731 = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
Douglas Gregor7e063902009-05-11 23:53:27 +00001732 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1733 std::string TemplateArgsStr
Douglas Gregor7532dc62009-03-30 22:58:21 +00001734 = TemplateSpecializationType::PrintTemplateArgumentList(
Douglas Gregor7e063902009-05-11 23:53:27 +00001735 TemplateArgs.getFlatArgumentList(),
Douglas Gregord249e1d1f2009-05-29 20:38:28 +00001736 TemplateArgs.flat_size(),
1737 Policy);
Douglas Gregor7e063902009-05-11 23:53:27 +00001738 MyPart = Spec->getIdentifier()->getName() + TemplateArgsStr;
Douglas Gregor24c46b32009-03-19 04:25:59 +00001739 } else if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
1740 if (TypedefDecl *Typedef = Tag->getTypedefForAnonDecl())
1741 MyPart = Typedef->getIdentifier()->getName();
1742 else if (Tag->getIdentifier())
1743 MyPart = Tag->getIdentifier()->getName();
1744 }
1745
1746 if (!MyPart.empty())
1747 ContextStr = MyPart + "::" + ContextStr;
1748 }
1749
John McCall2191b202009-09-05 06:31:47 +00001750 if (Kind)
1751 InnerString = std::string(Kind) + ' ' + ContextStr + ID + InnerString;
1752 else
1753 InnerString = ContextStr + ID + InnerString;
Douglas Gregor24c46b32009-03-19 04:25:59 +00001754 } else
Douglas Gregor4e16d042009-03-10 18:11:21 +00001755 InnerString = ID + InnerString;
Reid Spencer5f016e22007-07-11 17:01:13 +00001756}