 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
70.9% |
378 / 533 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
88.4% |
471 / 533 |
| |
|
Line Coverage: |
89.4% |
462 / 517 |
| |
 |
|
 |
1 : //===--- Type.cpp - Type representation and manipulation ------------------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file implements type-related functionality.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #include "clang/AST/ASTContext.h"
15 : #include "clang/AST/Type.h"
16 : #include "clang/AST/DeclCXX.h"
17 : #include "clang/AST/DeclObjC.h"
18 : #include "clang/AST/DeclTemplate.h"
19 : #include "clang/AST/Expr.h"
20 : #include "clang/AST/PrettyPrinter.h"
21 : #include "llvm/ADT/StringExtras.h"
22 : #include "llvm/Support/raw_ostream.h"
23 : using namespace clang;
24 :
25 10626: bool QualType::isConstant(QualType T, ASTContext &Ctx) {
226: branch 1 taken
10400: branch 2 taken
26 10626: if (T.isConstQualified())
27 226: return true;
28 :
727: branch 1 taken
9673: branch 2 taken
29 10400: if (const ArrayType *AT = Ctx.getAsArrayType(T))
30 727: return AT->getElementType().isConstant(Ctx);
31 :
32 9673: return false;
33 : }
34 :
35 124621: void Type::Destroy(ASTContext& C) {
36 124621: this->~Type();
37 124621: C.Deallocate(this);
38 124621: }
39 :
40 203: void VariableArrayType::Destroy(ASTContext& C) {
195: branch 0 taken
8: branch 1 taken
41 203: if (SizeExpr)
42 195: SizeExpr->Destroy(C);
43 203: this->~VariableArrayType();
44 203: C.Deallocate(this);
45 203: }
46 :
47 64: void DependentSizedArrayType::Destroy(ASTContext& C) {
48 : // FIXME: Resource contention like in ConstantArrayWithExprType ?
49 : // May crash, depending on platform or a particular build.
50 : // SizeExpr->Destroy(C);
51 64: this->~DependentSizedArrayType();
52 64: C.Deallocate(this);
53 64: }
54 :
55 : void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
56 : ASTContext &Context,
57 : QualType ET,
58 : ArraySizeModifier SizeMod,
59 : unsigned TypeQuals,
60 70: Expr *E) {
61 70: ID.AddPointer(ET.getAsOpaquePtr());
62 70: ID.AddInteger(SizeMod);
63 70: ID.AddInteger(TypeQuals);
64 70: E->Profile(ID, Context, true);
65 70: }
66 :
67 : void
68 : DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID,
69 : ASTContext &Context,
70 15: QualType ElementType, Expr *SizeExpr) {
71 15: ID.AddPointer(ElementType.getAsOpaquePtr());
72 15: SizeExpr->Profile(ID, Context, true);
73 15: }
74 :
75 12: void DependentSizedExtVectorType::Destroy(ASTContext& C) {
76 : // FIXME: Deallocate size expression, once we're cloning properly.
77 : // if (SizeExpr)
78 : // SizeExpr->Destroy(C);
79 12: this->~DependentSizedExtVectorType();
80 12: C.Deallocate(this);
81 12: }
82 :
83 : /// getArrayElementTypeNoTypeQual - If this is an array type, return the
84 : /// element type of the array, potentially with type qualifiers missing.
85 : /// This method should never be used when type qualifiers are meaningful.
86 61855: const Type *Type::getArrayElementTypeNoTypeQual() const {
87 : // If this is directly an array type, return it.
1983: branch 1 taken
59872: branch 2 taken
88 61855: if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
89 1983: return ATy->getElementType().getTypePtr();
90 :
91 : // If the canonical form of this type isn't the right kind, reject it.
59809: branch 1 taken
63: branch 2 taken
92 59872: if (!isa<ArrayType>(CanonicalType))
93 59809: return 0;
94 :
95 : // If this is a typedef for an array type, strip the typedef off without
96 : // losing all typedef information.
97 : return cast<ArrayType>(getUnqualifiedDesugaredType())
98 63: ->getElementType().getTypePtr();
99 : }
100 :
101 : /// \brief Retrieve the unqualified variant of the given type, removing as
102 : /// little sugar as possible.
103 : ///
104 : /// This routine looks through various kinds of sugar to find the
105 : /// least-desuraged type that is unqualified. For example, given:
106 : ///
107 : /// \code
108 : /// typedef int Integer;
109 : /// typedef const Integer CInteger;
110 : /// typedef CInteger DifferenceType;
111 : /// \endcode
112 : ///
113 : /// Executing \c getUnqualifiedTypeSlow() on the type \c DifferenceType will
114 : /// desugar until we hit the type \c Integer, which has no qualifiers on it.
115 15: QualType QualType::getUnqualifiedTypeSlow() const {
116 15: QualType Cur = *this;
117 15: while (true) {
0: branch 1 not taken
30: branch 2 taken
118 30: if (!Cur.hasQualifiers())
119 0: return Cur;
120 :
121 30: const Type *CurTy = Cur.getTypePtr();
11: branch 1 taken
0: branch 2 not taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 7 not taken
0: branch 8 not taken
0: branch 9 not taken
0: branch 10 not taken
0: branch 11 not taken
0: branch 12 not taken
0: branch 13 not taken
0: branch 14 not taken
0: branch 15 not taken
0: branch 16 not taken
0: branch 17 not taken
4: branch 18 taken
0: branch 19 not taken
0: branch 20 not taken
0: branch 21 not taken
4: branch 22 taken
0: branch 23 not taken
0: branch 24 not taken
0: branch 25 not taken
11: branch 26 taken
0: branch 27 not taken
0: branch 28 not taken
0: branch 29 not taken
0: branch 30 not taken
0: branch 31 not taken
0: branch 32 not taken
122 30: switch (CurTy->getTypeClass()) {
123 : #define ABSTRACT_TYPE(Class, Parent)
124 : #define TYPE(Class, Parent) \
125 : case Type::Class: { \
126 : const Class##Type *Ty = cast<Class##Type>(CurTy); \
127 : if (!Ty->isSugared()) \
128 : return Cur.getLocalUnqualifiedType(); \
129 : Cur = Ty->desugar(); \
130 : break; \
131 : }
132 : #include "clang/AST/TypeNodes.def"
133 : }
134 : }
135 :
136 : return Cur.getUnqualifiedType();
137 : }
138 :
139 : /// getDesugaredType - Return the specified type with any "sugar" removed from
140 : /// the type. This takes off typedefs, typeof's etc. If the outer level of
141 : /// the type is already concrete, it returns it unmodified. This is similar
142 : /// to getting the canonical type, but it doesn't remove *all* typedefs. For
143 : /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
144 : /// concrete.
145 1033: QualType QualType::getDesugaredType(QualType T) {
146 1033: QualifierCollector Qs;
147 :
148 1033: QualType Cur = T;
149 465: while (true) {
150 1498: const Type *CurTy = Qs.strip(Cur);
122: branch 1 taken
4: branch 2 taken
43: branch 3 taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 7 not taken
667: branch 8 taken
92: branch 9 taken
19: branch 10 taken
2: branch 11 taken
0: branch 12 not taken
0: branch 13 not taken
7: branch 14 taken
6: branch 15 taken
4: branch 16 taken
0: branch 17 not taken
379: branch 18 taken
14: branch 19 taken
10: branch 20 taken
0: branch 21 not taken
36: branch 22 taken
0: branch 23 not taken
5: branch 24 taken
0: branch 25 not taken
57: branch 26 taken
0: branch 27 not taken
0: branch 28 not taken
0: branch 29 not taken
0: branch 30 not taken
31: branch 31 taken
0: branch 32 not taken
151 1498: switch (CurTy->getTypeClass()) {
152 : #define ABSTRACT_TYPE(Class, Parent)
153 : #define TYPE(Class, Parent) \
154 : case Type::Class: { \
155 : const Class##Type *Ty = cast<Class##Type>(CurTy); \
156 : if (!Ty->isSugared()) \
157 : return Qs.apply(Cur); \
158 : Cur = Ty->desugar(); \
159 : break; \
160 : }
161 : #include "clang/AST/TypeNodes.def"
162 : }
163 : }
164 : }
165 :
166 : /// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic
167 : /// sugar off the given type. This should produce an object of the
168 : /// same dynamic type as the canonical type.
169 34580: const Type *Type::getUnqualifiedDesugaredType() const {
170 34580: const Type *Cur = this;
171 :
172 35662: while (true) {
0: branch 1 not taken
12: branch 2 taken
7758: branch 3 taken
36: branch 4 taken
267: branch 5 taken
14: branch 6 taken
374: branch 7 taken
55: branch 8 taken
8: branch 9 taken
0: branch 10 not taken
0: branch 11 not taken
0: branch 12 not taken
1421: branch 13 taken
344: branch 14 taken
221: branch 15 taken
66: branch 16 taken
0: branch 17 not taken
15002: branch 18 taken
133: branch 19 taken
11: branch 20 taken
3: branch 21 taken
21129: branch 22 taken
3: branch 23 taken
1173: branch 24 taken
0: branch 25 not taken
4213: branch 26 taken
13003: branch 27 taken
2124: branch 28 taken
0: branch 29 not taken
0: branch 30 not taken
2872: branch 31 taken
0: branch 32 not taken
173 70242: switch (Cur->getTypeClass()) {
174 : #define ABSTRACT_TYPE(Class, Parent)
175 : #define TYPE(Class, Parent) \
176 : case Class: { \
177 : const Class##Type *Ty = cast<Class##Type>(Cur); \
178 : if (!Ty->isSugared()) return Cur; \
179 : Cur = Ty->desugar().getTypePtr(); \
180 : break; \
181 : }
182 : #include "clang/AST/TypeNodes.def"
183 : }
184 : }
185 : }
186 :
187 : /// isVoidType - Helper method to determine if this is the 'void' type.
188 183435: bool Type::isVoidType() const {
119269: branch 1 taken
64166: branch 2 taken
189 183435: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
190 119269: return BT->getKind() == BuiltinType::Void;
191 64166: return false;
192 : }
193 :
194 894: bool Type::isObjectType() const {
721: branch 1 taken
173: branch 2 taken
721: branch 4 taken
0: branch 5 not taken
721: branch 7 taken
0: branch 8 not taken
43: branch 10 taken
678: branch 11 taken
216: branch 12 taken
678: branch 13 taken
195 894: if (isa<FunctionType>(CanonicalType) || isa<ReferenceType>(CanonicalType) ||
196 : isa<IncompleteArrayType>(CanonicalType) || isVoidType())
197 216: return false;
198 678: return true;
199 : }
200 :
201 0: bool Type::isDerivedType() const {
0: branch 2 not taken
0: branch 3 not taken
202 0: switch (CanonicalType->getTypeClass()) {
203 : case Pointer:
204 : case VariableArray:
205 : case ConstantArray:
206 : case IncompleteArray:
207 : case FunctionProto:
208 : case FunctionNoProto:
209 : case LValueReference:
210 : case RValueReference:
211 : case Record:
212 0: return true;
213 : default:
214 0: return false;
215 : }
216 : }
217 :
218 0: bool Type::isClassType() const {
0: branch 1 not taken
0: branch 2 not taken
219 0: if (const RecordType *RT = getAs<RecordType>())
220 0: return RT->getDecl()->isClass();
221 0: return false;
222 : }
223 12942: bool Type::isStructureType() const {
715: branch 1 taken
12227: branch 2 taken
224 12942: if (const RecordType *RT = getAs<RecordType>())
225 715: return RT->getDecl()->isStruct();
226 12227: return false;
227 : }
228 567: bool Type::isVoidPointerType() const {
194: branch 1 taken
373: branch 2 taken
229 567: if (const PointerType *PT = getAs<PointerType>())
230 194: return PT->getPointeeType()->isVoidType();
231 373: return false;
232 : }
233 :
234 9249: bool Type::isUnionType() const {
2390: branch 1 taken
6859: branch 2 taken
235 9249: if (const RecordType *RT = getAs<RecordType>())
236 2390: return RT->getDecl()->isUnion();
237 6859: return false;
238 : }
239 :
240 38263: bool Type::isComplexType() const {
186: branch 1 taken
38077: branch 2 taken
241 38263: if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
242 186: return CT->getElementType()->isFloatingType();
243 38077: return false;
244 : }
245 :
246 12440: bool Type::isComplexIntegerType() const {
247 : // Check for GCC complex integer extension.
248 12440: return getAsComplexIntegerType();
249 : }
250 :
251 12506: const ComplexType *Type::getAsComplexIntegerType() const {
162: branch 1 taken
12344: branch 2 taken
252 12506: if (const ComplexType *Complex = getAs<ComplexType>())
93: branch 3 taken
69: branch 4 taken
253 162: if (Complex->getElementType()->isIntegerType())
254 93: return Complex;
255 12413: return 0;
256 : }
257 :
258 3874: QualType Type::getPointeeType() const {
3123: branch 1 taken
751: branch 2 taken
259 3874: if (const PointerType *PT = getAs<PointerType>())
260 3123: return PT->getPointeeType();
365: branch 1 taken
386: branch 2 taken
261 751: if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
262 365: return OPT->getPointeeType();
184: branch 1 taken
202: branch 2 taken
263 386: if (const BlockPointerType *BPT = getAs<BlockPointerType>())
264 184: return BPT->getPointeeType();
202: branch 1 taken
0: branch 2 not taken
265 202: if (const ReferenceType *RT = getAs<ReferenceType>())
266 202: return RT->getPointeeType();
267 0: return QualType();
268 : }
269 :
270 : /// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length
271 : /// array types and types that contain variable array types in their
272 : /// declarator
273 62164: bool Type::isVariablyModifiedType() const {
274 : // A VLA is a variably modified type.
312: branch 1 taken
61852: branch 2 taken
275 62164: if (isVariableArrayType())
276 312: return true;
277 :
278 : // An array can contain a variably modified type
2043: branch 1 taken
59809: branch 2 taken
279 61852: if (const Type *T = getArrayElementTypeNoTypeQual())
280 2043: return T->isVariablyModifiedType();
281 :
282 : // A pointer can point to a variably modified type.
283 : // Also, C++ references and member pointers can point to a variably modified
284 : // type, where VLAs appear as an extension to C++, and should be treated
285 : // correctly.
12589: branch 1 taken
47220: branch 2 taken
286 59809: if (const PointerType *PT = getAs<PointerType>())
287 12589: return PT->getPointeeType()->isVariablyModifiedType();
1130: branch 1 taken
46090: branch 2 taken
288 47220: if (const ReferenceType *RT = getAs<ReferenceType>())
289 1130: return RT->getPointeeType()->isVariablyModifiedType();
211: branch 1 taken
45879: branch 2 taken
290 46090: if (const MemberPointerType *PT = getAs<MemberPointerType>())
291 211: return PT->getPointeeType()->isVariablyModifiedType();
292 :
293 : // A function can return a variably modified type
294 : // This one isn't completely obvious, but it follows from the
295 : // definition in C99 6.7.5p3. Because of this rule, it's
296 : // illegal to declare a function returning a variably modified type.
1340: branch 1 taken
44539: branch 2 taken
297 45879: if (const FunctionType *FT = getAs<FunctionType>())
298 1340: return FT->getResultType()->isVariablyModifiedType();
299 :
300 44539: return false;
301 : }
302 :
303 343: const RecordType *Type::getAsStructureType() const {
304 : // If this is directly a structure type, return it.
179: branch 1 taken
164: branch 2 taken
305 343: if (const RecordType *RT = dyn_cast<RecordType>(this)) {
178: branch 2 taken
1: branch 3 taken
306 179: if (RT->getDecl()->isStruct())
307 178: return RT;
308 : }
309 :
310 : // If the canonical form of this type isn't the right kind, reject it.
32: branch 1 taken
133: branch 2 taken
311 165: if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
1: branch 2 taken
31: branch 3 taken
312 32: if (!RT->getDecl()->isStruct())
313 1: return 0;
314 :
315 : // If this is a typedef for a structure type, strip the typedef off without
316 : // losing all typedef information.
317 31: return cast<RecordType>(getUnqualifiedDesugaredType());
318 : }
319 133: return 0;
320 : }
321 :
322 52: const RecordType *Type::getAsUnionType() const {
323 : // If this is directly a union type, return it.
6: branch 1 taken
46: branch 2 taken
324 52: if (const RecordType *RT = dyn_cast<RecordType>(this)) {
6: branch 2 taken
0: branch 3 not taken
325 6: if (RT->getDecl()->isUnion())
326 6: return RT;
327 : }
328 :
329 : // If the canonical form of this type isn't the right kind, reject it.
5: branch 1 taken
41: branch 2 taken
330 46: if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
0: branch 2 not taken
5: branch 3 taken
331 5: if (!RT->getDecl()->isUnion())
332 0: return 0;
333 :
334 : // If this is a typedef for a union type, strip the typedef off without
335 : // losing all typedef information.
336 5: return cast<RecordType>(getUnqualifiedDesugaredType());
337 : }
338 :
339 41: return 0;
340 : }
341 :
342 : ObjCInterfaceType::ObjCInterfaceType(QualType Canonical,
343 : ObjCInterfaceDecl *D,
344 1964: ObjCProtocolDecl **Protos, unsigned NumP) :
345 : Type(ObjCInterface, Canonical, /*Dependent=*/false),
346 1964: Decl(D), NumProtocols(NumP)
347 : {
75: branch 0 taken
1889: branch 1 taken
1889: branch 2 taken
1889: branch 3 taken
348 1964: if (NumProtocols)
349 : memcpy(reinterpret_cast<ObjCProtocolDecl**>(this + 1), Protos,
350 75: NumProtocols * sizeof(*Protos));
351 1964: }
352 :
353 1856: void ObjCInterfaceType::Destroy(ASTContext& C) {
354 1856: this->~ObjCInterfaceType();
355 1856: C.Deallocate(this);
356 1856: }
357 :
358 2549: const ObjCInterfaceType *Type::getAsObjCQualifiedInterfaceType() const {
359 : // There is no sugar for ObjCInterfaceType's, just return the canonical
360 : // type pointer if it is the right class. There is no typedef information to
361 : // return and these cannot be Address-space qualified.
34: branch 1 taken
2515: branch 2 taken
362 2549: if (const ObjCInterfaceType *OIT = getAs<ObjCInterfaceType>())
14: branch 1 taken
20: branch 2 taken
363 34: if (OIT->getNumProtocols())
364 14: return OIT;
365 2535: return 0;
366 : }
367 :
368 2549: bool Type::isObjCQualifiedInterfaceType() const {
369 2549: return getAsObjCQualifiedInterfaceType() != 0;
370 : }
371 :
372 : ObjCObjectPointerType::ObjCObjectPointerType(QualType Canonical, QualType T,
373 : ObjCProtocolDecl **Protos,
374 2686: unsigned NumP) :
375 : Type(ObjCObjectPointer, Canonical, /*Dependent=*/false),
376 2686: PointeeType(T), NumProtocols(NumP)
377 : {
201: branch 0 taken
2485: branch 1 taken
2485: branch 2 taken
2485: branch 3 taken
378 2686: if (NumProtocols)
379 : memcpy(reinterpret_cast<ObjCProtocolDecl **>(this + 1), Protos,
380 201: NumProtocols * sizeof(*Protos));
381 2686: }
382 :
383 2510: void ObjCObjectPointerType::Destroy(ASTContext& C) {
384 2510: this->~ObjCObjectPointerType();
385 2510: C.Deallocate(this);
386 2510: }
387 :
388 852: const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const {
389 : // There is no sugar for ObjCQualifiedIdType's, just return the canonical
390 : // type pointer if it is the right class.
844: branch 1 taken
8: branch 2 taken
391 852: if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
185: branch 1 taken
659: branch 2 taken
392 844: if (OPT->isObjCQualifiedIdType())
393 185: return OPT;
394 : }
395 667: return 0;
396 : }
397 :
398 1116: const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const {
972: branch 1 taken
144: branch 2 taken
399 1116: if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
967: branch 1 taken
5: branch 2 taken
400 972: if (OPT->getInterfaceType())
401 967: return OPT;
402 : }
403 149: return 0;
404 : }
405 :
406 2: const CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const {
2: branch 1 taken
0: branch 2 not taken
407 2: if (const PointerType *PT = getAs<PointerType>())
2: branch 3 taken
0: branch 4 not taken
408 2: if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>())
409 2: return dyn_cast<CXXRecordDecl>(RT->getDecl());
410 0: return 0;
411 : }
412 :
413 140902: bool Type::isIntegerType() const {
99925: branch 1 taken
40977: branch 2 taken
414 140902: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
415 : return BT->getKind() >= BuiltinType::Bool &&
99234: branch 1 taken
691: branch 2 taken
91698: branch 4 taken
7536: branch 5 taken
416 99925: BT->getKind() <= BuiltinType::Int128;
2360: branch 1 taken
38617: branch 2 taken
417 40977: if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
418 : // Incomplete enum types are not treated as integer types.
419 : // FIXME: In C++, enum types are never integer types.
894: branch 2 taken
1466: branch 3 taken
894: branch 6 taken
0: branch 7 not taken
894: branch 8 taken
1466: branch 9 taken
420 2360: if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
421 894: return true;
138: branch 1 taken
39945: branch 2 taken
422 40083: if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
423 138: return VT->getElementType()->isIntegerType();
424 39945: return false;
425 : }
426 :
427 147619: bool Type::isIntegralType() const {
109822: branch 1 taken
37797: branch 2 taken
428 147619: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
429 : return BT->getKind() >= BuiltinType::Bool &&
109814: branch 1 taken
8: branch 2 taken
102623: branch 4 taken
7191: branch 5 taken
430 109822: BT->getKind() <= BuiltinType::Int128;
12836: branch 1 taken
24961: branch 2 taken
431 37797: if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
10669: branch 2 taken
2167: branch 3 taken
10663: branch 6 taken
6: branch 7 taken
10663: branch 8 taken
2173: branch 9 taken
432 12836: if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
433 10663: return true; // Complete enum types are integral.
434 : // FIXME: In C++, enum types are never integral.
435 27134: return false;
436 : }
437 :
438 40764: bool Type::isEnumeralType() const {
8198: branch 1 taken
32566: branch 2 taken
439 40764: if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
440 8198: return TT->getDecl()->isEnum();
441 32566: return false;
442 : }
443 :
444 114366: bool Type::isBooleanType() const {
92798: branch 1 taken
21568: branch 2 taken
445 114366: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
446 92798: return BT->getKind() == BuiltinType::Bool;
447 21568: return false;
448 : }
449 :
450 1405: bool Type::isCharType() const {
1290: branch 1 taken
115: branch 2 taken
451 1405: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
452 : return BT->getKind() == BuiltinType::Char_U ||
453 : BT->getKind() == BuiltinType::UChar ||
454 : BT->getKind() == BuiltinType::Char_S ||
1290: branch 1 taken
0: branch 2 not taken
1288: branch 4 taken
2: branch 5 taken
1153: branch 7 taken
135: branch 8 taken
0: branch 10 not taken
1153: branch 11 taken
455 1290: BT->getKind() == BuiltinType::SChar;
456 115: return false;
457 : }
458 :
459 15632: bool Type::isWideCharType() const {
10673: branch 1 taken
4959: branch 2 taken
460 15632: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
461 10673: return BT->getKind() == BuiltinType::WChar;
462 4959: return false;
463 : }
464 :
465 : /// \brief Determine whether this type is any of the built-in character
466 : /// types.
467 15: bool Type::isAnyCharacterType() const {
15: branch 1 taken
0: branch 2 not taken
468 15: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
469 : return (BT->getKind() >= BuiltinType::Char_U &&
470 : BT->getKind() <= BuiltinType::Char32) ||
471 : (BT->getKind() >= BuiltinType::Char_S &&
15: branch 1 taken
0: branch 2 not taken
15: branch 4 taken
0: branch 5 not taken
14: branch 7 taken
1: branch 8 taken
3: branch 10 taken
11: branch 11 taken
472 15: BT->getKind() <= BuiltinType::WChar);
473 :
474 0: return false;
475 : }
476 :
477 : /// isSignedIntegerType - Return true if this is an integer type that is
478 : /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
479 : /// an enum decl which has a signed representation, or a vector of signed
480 : /// integer element type.
481 32336: bool Type::isSignedIntegerType() const {
31071: branch 1 taken
1265: branch 2 taken
482 32336: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
483 : return BT->getKind() >= BuiltinType::Char_S &&
15149: branch 1 taken
15922: branch 2 taken
15134: branch 4 taken
15: branch 5 taken
484 31071: BT->getKind() <= BuiltinType::Int128;
485 : }
486 :
1113: branch 1 taken
152: branch 2 taken
487 1265: if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
488 1113: return ET->getDecl()->getIntegerType()->isSignedIntegerType();
489 :
16: branch 1 taken
136: branch 2 taken
490 152: if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
491 16: return VT->getElementType()->isSignedIntegerType();
492 136: return false;
493 : }
494 :
495 : /// isUnsignedIntegerType - Return true if this is an integer type that is
496 : /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
497 : /// decl which has an unsigned representation, or a vector of unsigned integer
498 : /// element type.
499 50679: bool Type::isUnsignedIntegerType() const {
44760: branch 1 taken
5919: branch 2 taken
500 50679: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
501 : return BT->getKind() >= BuiltinType::Bool &&
44760: branch 1 taken
0: branch 2 not taken
13058: branch 4 taken
31702: branch 5 taken
502 44760: BT->getKind() <= BuiltinType::UInt128;
503 : }
504 :
15: branch 1 taken
5904: branch 2 taken
505 5919: if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
506 15: return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
507 :
8: branch 1 taken
5896: branch 2 taken
508 5904: if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
509 8: return VT->getElementType()->isUnsignedIntegerType();
510 5896: return false;
511 : }
512 :
513 38229: bool Type::isFloatingType() const {
20457: branch 1 taken
17772: branch 2 taken
514 38229: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
515 : return BT->getKind() >= BuiltinType::Float &&
7005: branch 1 taken
13452: branch 2 taken
6912: branch 4 taken
93: branch 5 taken
516 20457: BT->getKind() <= BuiltinType::LongDouble;
101: branch 1 taken
17671: branch 2 taken
517 17772: if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
518 101: return CT->getElementType()->isFloatingType();
913: branch 1 taken
16758: branch 2 taken
519 17671: if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
520 913: return VT->getElementType()->isFloatingType();
521 16758: return false;
522 : }
523 :
524 21232: bool Type::isRealFloatingType() const {
20031: branch 1 taken
1201: branch 2 taken
525 21232: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
526 20031: return BT->isFloatingPoint();
0: branch 1 not taken
1201: branch 2 taken
527 1201: if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
528 0: return VT->getElementType()->isRealFloatingType();
529 1201: return false;
530 : }
531 :
532 1922: bool Type::isRealType() const {
1702: branch 1 taken
220: branch 2 taken
533 1922: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
534 : return BT->getKind() >= BuiltinType::Bool &&
1702: branch 1 taken
0: branch 2 not taken
1699: branch 4 taken
3: branch 5 taken
535 1702: BT->getKind() <= BuiltinType::LongDouble;
6: branch 1 taken
214: branch 2 taken
536 220: if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
0: branch 2 not taken
6: branch 3 taken
0: branch 6 not taken
0: branch 7 not taken
537 6: return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition();
0: branch 1 not taken
214: branch 2 taken
538 214: if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
539 0: return VT->getElementType()->isRealType();
540 214: return false;
541 : }
542 :
543 43461: bool Type::isArithmeticType() const {
37447: branch 1 taken
6014: branch 2 taken
544 43461: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
545 : return BT->getKind() >= BuiltinType::Bool &&
37401: branch 1 taken
46: branch 2 taken
37386: branch 4 taken
15: branch 5 taken
546 37447: BT->getKind() <= BuiltinType::LongDouble;
30: branch 1 taken
5984: branch 2 taken
547 6014: if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
548 : // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
549 : // If a body isn't seen by the time we get here, return false.
550 30: return ET->getDecl()->isDefinition();
5282: branch 1 taken
702: branch 2 taken
4: branch 4 taken
5278: branch 5 taken
551 5984: return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType);
552 : }
553 :
554 17561: bool Type::isScalarType() const {
10572: branch 1 taken
6989: branch 2 taken
555 17561: if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
556 10572: return BT->getKind() != BuiltinType::Void;
1061: branch 1 taken
5928: branch 2 taken
557 6989: if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
558 : // Enums are scalar types, but only if they are defined. Incomplete enums
559 : // are not treated as scalar types.
11: branch 2 taken
1050: branch 3 taken
9: branch 6 taken
2: branch 7 taken
9: branch 8 taken
1052: branch 9 taken
560 1061: if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
561 9: return true;
562 1052: return false;
563 : }
564 : return isa<PointerType>(CanonicalType) ||
565 : isa<BlockPointerType>(CanonicalType) ||
566 : isa<MemberPointerType>(CanonicalType) ||
567 : isa<ComplexType>(CanonicalType) ||
4223: branch 1 taken
1705: branch 2 taken
4201: branch 4 taken
22: branch 5 taken
4199: branch 7 taken
2: branch 8 taken
4179: branch 10 taken
20: branch 11 taken
401: branch 13 taken
3778: branch 14 taken
568 5928: isa<ObjCObjectPointerType>(CanonicalType);
569 : }
570 :
571 : /// \brief Determines whether the type is a C++ aggregate type or C
572 : /// aggregate or union type.
573 : ///
574 : /// An aggregate type is an array or a class type (struct, union, or
575 : /// class) that has no user-declared constructors, no private or
576 : /// protected non-static data members, no base classes, and no virtual
577 : /// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
578 : /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
579 : /// includes union types.
580 1549: bool Type::isAggregateType() const {
636: branch 1 taken
913: branch 2 taken
581 1549: if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) {
111: branch 2 taken
525: branch 3 taken
582 636: if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
583 111: return ClassDecl->isAggregate();
584 :
585 525: return true;
586 : }
587 :
588 913: return isa<ArrayType>(CanonicalType);
589 : }
590 :
591 : /// isConstantSizeType - Return true if this is not a variable sized type,
592 : /// according to the rules of C99 6.7.5p3. It is not legal to call this on
593 : /// incomplete types or dependent types.
594 11414: bool Type::isConstantSizeType() const {
11414: branch 1 taken
0: branch 2 not taken
595 11414: assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
11414: branch 1 taken
0: branch 2 not taken
596 11414: assert(!isDependentType() && "This doesn't make sense for dependent types");
597 : // The VAT must have a size, as it is known to be complete.
598 11414: return !isa<VariableArrayType>(CanonicalType);
599 : }
600 :
601 : /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
602 : /// - a type that can describe objects, but which lacks information needed to
603 : /// determine its size.
604 143808: bool Type::isIncompleteType() const {
29112: branch 2 taken
59576: branch 3 taken
52979: branch 4 taken
2014: branch 5 taken
91: branch 6 taken
36: branch 7 taken
605 143808: switch (CanonicalType->getTypeClass()) {
606 29112: default: return false;
607 : case Builtin:
608 : // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
609 : // be completed.
610 59576: return isVoidType();
611 : case Record:
612 : case Enum:
613 : // A tagged type (struct/union/enum/class) is incomplete if the decl is a
614 : // forward declaration, but not a full definition (C99 6.2.5p22).
615 52979: return !cast<TagType>(CanonicalType)->getDecl()->isDefinition();
616 : case ConstantArray:
617 : // An array is incomplete if its element type is incomplete
618 : // (C++ [dcl.array]p1).
619 : // We don't handle variable arrays (they're not allowed in C++) or
620 : // dependent-sized arrays (dependent types are never treated as incomplete).
621 2014: return cast<ArrayType>(CanonicalType)->getElementType()->isIncompleteType();
622 : case IncompleteArray:
623 : // An array of unknown size is an incomplete type (C99 6.2.5p22).
624 91: return true;
625 : case ObjCInterface:
626 : // ObjC interfaces are incomplete if they are @class, not @interface.
627 36: return cast<ObjCInterfaceType>(this)->getDecl()->isForwardDecl();
628 : }
629 : }
630 :
631 : /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10)
632 3541: bool Type::isPODType() const {
633 : // The compiler shouldn't query this for incomplete types, but the user might.
634 : // We return false for that case.
0: branch 1 not taken
3541: branch 2 taken
635 3541: if (isIncompleteType())
636 0: return false;
637 :
120: branch 2 taken
187: branch 3 taken
2636: branch 4 taken
6: branch 5 taken
592: branch 6 taken
638 3541: switch (CanonicalType->getTypeClass()) {
639 : // Everything not explicitly mentioned is not POD.
640 120: default: return false;
641 : case VariableArray:
642 : case ConstantArray:
643 : // IncompleteArray is caught by isIncompleteType() above.
644 187: return cast<ArrayType>(CanonicalType)->getElementType()->isPODType();
645 :
646 : case Builtin:
647 : case Complex:
648 : case Pointer:
649 : case MemberPointer:
650 : case Vector:
651 : case ExtVector:
652 : case ObjCObjectPointer:
653 2636: return true;
654 :
655 : case Enum:
656 6: return true;
657 :
658 : case Record:
544: branch 0 taken
48: branch 1 taken
659 592: if (CXXRecordDecl *ClassDecl
660 592: = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
661 544: return ClassDecl->isPOD();
662 :
663 : // C struct/union is POD.
664 48: return true;
665 : }
666 : }
667 :
668 6: bool Type::isLiteralType() const {
0: branch 1 not taken
6: branch 2 taken
669 6: if (isIncompleteType())
670 0: return false;
671 :
672 : // C++0x [basic.types]p10:
673 : // A type is a literal type if it is:
0: branch 2 not taken
5: branch 3 taken
0: branch 4 not taken
1: branch 5 taken
674 6: switch (CanonicalType->getTypeClass()) {
675 : // We're whitelisting
676 0: default: return false;
677 :
678 : // -- a scalar type
679 : case Builtin:
680 : case Complex:
681 : case Pointer:
682 : case MemberPointer:
683 : case Vector:
684 : case ExtVector:
685 : case ObjCObjectPointer:
686 : case Enum:
687 5: return true;
688 :
689 : // -- a class type with ...
690 : case Record:
691 : // FIXME: Do the tests
692 0: return false;
693 :
694 : // -- an array of literal type
695 : // Extension: variable arrays cannot be literal types, since they're
696 : // runtime-sized.
697 : case ConstantArray:
698 1: return cast<ArrayType>(CanonicalType)->getElementType()->isLiteralType();
699 : }
700 : }
701 :
702 69770: bool Type::isPromotableIntegerType() const {
46775: branch 1 taken
22995: branch 2 taken
703 69770: if (const BuiltinType *BT = getAs<BuiltinType>())
6110: branch 1 taken
40665: branch 2 taken
704 46775: switch (BT->getKind()) {
705 : case BuiltinType::Bool:
706 : case BuiltinType::Char_S:
707 : case BuiltinType::Char_U:
708 : case BuiltinType::SChar:
709 : case BuiltinType::UChar:
710 : case BuiltinType::Short:
711 : case BuiltinType::UShort:
712 6110: return true;
713 : default:
714 40665: return false;
715 : }
716 :
717 : // Enumerated types are promotable to their compatible integer types
718 : // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2).
7522: branch 1 taken
15473: branch 2 taken
719 22995: if (const EnumType *ET = getAs<EnumType>()){
7522: branch 1 taken
0: branch 2 not taken
1: branch 6 taken
7521: branch 7 taken
1: branch 8 taken
7521: branch 9 taken
720 7522: if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull())
721 1: return false;
722 :
723 : const BuiltinType *BT
724 7521: = ET->getDecl()->getPromotionType()->getAs<BuiltinType>();
725 : return BT->getKind() == BuiltinType::Int
75: branch 1 taken
7446: branch 2 taken
56: branch 4 taken
19: branch 5 taken
726 7521: || BT->getKind() == BuiltinType::UInt;
727 : }
728 :
729 15473: return false;
730 : }
731 :
732 16858: bool Type::isNullPtrType() const {
6797: branch 1 taken
10061: branch 2 taken
733 16858: if (const BuiltinType *BT = getAs<BuiltinType>())
734 6797: return BT->getKind() == BuiltinType::NullPtr;
735 10061: return false;
736 : }
737 :
738 12: bool Type::isSpecifierType() const {
739 : // Note that this intentionally does not use the canonical type.
8: branch 1 taken
4: branch 2 taken
740 12: switch (getTypeClass()) {
741 : case Builtin:
742 : case Record:
743 : case Enum:
744 : case Typedef:
745 : case Complex:
746 : case TypeOfExpr:
747 : case TypeOf:
748 : case TemplateTypeParm:
749 : case SubstTemplateTypeParm:
750 : case TemplateSpecialization:
751 : case QualifiedName:
752 : case Typename:
753 : case ObjCInterface:
754 : case ObjCObjectPointer:
755 : case Elaborated:
756 8: return true;
757 : default:
758 4: return false;
759 : }
760 : }
761 :
762 0: const char *Type::getTypeClassName() const {
0: branch 0 not taken
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 7 not taken
0: branch 8 not taken
0: branch 9 not taken
0: branch 10 not taken
0: branch 11 not taken
0: branch 12 not taken
0: branch 13 not taken
0: branch 14 not taken
0: branch 15 not taken
0: branch 16 not taken
0: branch 17 not taken
0: branch 18 not taken
0: branch 19 not taken
0: branch 20 not taken
0: branch 21 not taken
0: branch 22 not taken
0: branch 23 not taken
0: branch 24 not taken
0: branch 25 not taken
0: branch 26 not taken
0: branch 27 not taken
0: branch 28 not taken
0: branch 29 not taken
0: branch 30 not taken
0: branch 31 not taken
763 0: switch (TC) {
764 0: default: assert(0 && "Type class not in TypeNodes.def!");
765 : #define ABSTRACT_TYPE(Derived, Base)
766 : #define TYPE(Derived, Base) case Derived: return #Derived;
767 : #include "clang/AST/TypeNodes.def"
768 : }
769 : }
770 :
771 3428: const char *BuiltinType::getName(const LangOptions &LO) const {
0: branch 1 not taken
609: branch 2 taken
9: branch 3 taken
274: branch 4 taken
0: branch 5 not taken
19: branch 6 taken
79: branch 7 taken
1543: branch 8 taken
105: branch 9 taken
40: branch 10 taken
1: branch 11 taken
19: branch 12 taken
10: branch 13 taken
110: branch 14 taken
73: branch 15 taken
21: branch 16 taken
1: branch 17 taken
289: branch 18 taken
156: branch 19 taken
50: branch 20 taken
0: branch 21 not taken
0: branch 22 not taken
0: branch 23 not taken
5: branch 24 taken
5: branch 25 taken
0: branch 26 not taken
3: branch 27 taken
0: branch 28 not taken
0: branch 29 not taken
7: branch 30 taken
772 3428: switch (getKind()) {
773 0: default: assert(0 && "Unknown builtin type!");
774 609: case Void: return "void";
9: branch 0 taken
0: branch 1 not taken
775 9: case Bool: return LO.Bool ? "bool" : "_Bool";
776 274: case Char_S: return "char";
777 0: case Char_U: return "char";
778 19: case SChar: return "signed char";
779 79: case Short: return "short";
780 1543: case Int: return "int";
781 105: case Long: return "long";
782 40: case LongLong: return "long long";
783 1: case Int128: return "__int128_t";
784 19: case UChar: return "unsigned char";
785 10: case UShort: return "unsigned short";
786 110: case UInt: return "unsigned int";
787 73: case ULong: return "unsigned long";
788 21: case ULongLong: return "unsigned long long";
789 1: case UInt128: return "__uint128_t";
790 289: case Float: return "float";
791 156: case Double: return "double";
792 50: case LongDouble: return "long double";
793 0: case WChar: return "wchar_t";
794 0: case Char16: return "char16_t";
795 0: case Char32: return "char32_t";
796 5: case NullPtr: return "nullptr_t";
797 5: case Overload: return "<overloaded function type>";
798 0: case Dependent: return "<dependent type>";
799 3: case UndeducedAuto: return "auto";
800 0: case ObjCId: return "id";
801 0: case ObjCClass: return "Class";
802 7: case ObjCSel: return "SEL";
803 : }
804 : }
805 :
806 6: llvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) {
0: branch 0 not taken
0: branch 1 not taken
0: branch 2 not taken
2: branch 3 taken
4: branch 4 taken
807 6: switch (CC) {
808 0: case CC_Default: llvm_unreachable("no name for default cc");
809 0: default: return "";
810 :
811 0: case CC_C: return "cdecl";
812 2: case CC_X86StdCall: return "stdcall";
813 4: case CC_X86FastCall: return "fastcall";
814 : }
815 : }
816 :
817 : void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
818 : arg_type_iterator ArgTys,
819 : unsigned NumArgs, bool isVariadic,
820 : unsigned TypeQuals, bool hasExceptionSpec,
821 : bool anyExceptionSpec, unsigned NumExceptions,
822 : exception_iterator Exs, bool NoReturn,
823 75555: CallingConv CallConv) {
824 75555: ID.AddPointer(Result.getAsOpaquePtr());
63633: branch 0 taken
75555: branch 1 taken
825 139188: for (unsigned i = 0; i != NumArgs; ++i)
826 63633: ID.AddPointer(ArgTys[i].getAsOpaquePtr());
827 75555: ID.AddInteger(isVariadic);
828 75555: ID.AddInteger(TypeQuals);
829 75555: ID.AddInteger(hasExceptionSpec);
1484: branch 0 taken
74071: branch 1 taken
830 75555: if (hasExceptionSpec) {
831 1484: ID.AddInteger(anyExceptionSpec);
350: branch 0 taken
1484: branch 1 taken
832 1834: for (unsigned i = 0; i != NumExceptions; ++i)
833 350: ID.AddPointer(Exs[i].getAsOpaquePtr());
834 : }
835 75555: ID.AddInteger(NoReturn);
836 75555: ID.AddInteger(CallConv);
837 75555: }
838 :
839 36808: void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) {
840 : Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(),
841 : getTypeQuals(), hasExceptionSpec(), hasAnyExceptionSpec(),
842 : getNumExceptions(), exception_begin(), getNoReturnAttr(),
843 36808: getCallConv());
844 36808: }
845 :
846 : void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID,
847 : QualType OIT,
848 : ObjCProtocolDecl * const *protocols,
849 6782: unsigned NumProtocols) {
850 6782: ID.AddPointer(OIT.getAsOpaquePtr());
681: branch 0 taken
6782: branch 1 taken
851 7463: for (unsigned i = 0; i != NumProtocols; i++)
852 681: ID.AddPointer(protocols[i]);
853 6782: }
854 :
855 2117: void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID) {
856 2117: Profile(ID, getPointeeType(), qual_begin(), getNumProtocols());
857 2117: }
858 :
859 : /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
860 : /// potentially looking through *all* consequtive typedefs. This returns the
861 : /// sum of the type qualifiers, so if you have:
862 : /// typedef const int A;
863 : /// typedef volatile A B;
864 : /// looking through the typedefs for B will give you "const volatile A".
865 : ///
866 2: QualType TypedefType::LookThroughTypedefs() const {
867 : // Usually, there is only a single level of typedefs, be fast in that case.
868 2: QualType FirstType = getDecl()->getUnderlyingType();
2: branch 1 taken
0: branch 2 not taken
869 2: if (!isa<TypedefType>(FirstType))
870 2: return FirstType;
871 :
872 : // Otherwise, do the fully general loop.
873 0: QualifierCollector Qs;
874 :
875 0: QualType CurType;
876 0: const TypedefType *TDT = this;
0: branch 0 not taken
0: branch 1 not taken
877 0: do {
878 0: CurType = TDT->getDecl()->getUnderlyingType();
879 0: TDT = dyn_cast<TypedefType>(Qs.strip(CurType));
880 : } while (TDT);
881 :
882 0: return Qs.apply(CurType);
883 : }
884 :
885 15552: QualType TypedefType::desugar() const {
886 15552: return getDecl()->getUnderlyingType();
887 : }
888 :
889 282: TypeOfExprType::TypeOfExprType(Expr *E, QualType can)
890 282: : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) {
891 282: }
892 :
893 157: QualType TypeOfExprType::desugar() const {
894 157: return getUnderlyingExpr()->getType();
895 : }
896 :
897 : void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
898 10: ASTContext &Context, Expr *E) {
899 10: E->Profile(ID, Context, true);
900 10: }
901 :
902 16: DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can)
903 : : Type(Decltype, can, E->isTypeDependent()), E(E),
904 16: UnderlyingType(underlyingType) {
905 16: }
906 :
907 5: DependentDecltypeType::DependentDecltypeType(ASTContext &Context, Expr *E)
908 5: : DecltypeType(E, Context.DependentTy), Context(Context) { }
909 :
910 : void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
911 7: ASTContext &Context, Expr *E) {
912 7: E->Profile(ID, Context, true);
913 7: }
914 :
915 8259: TagType::TagType(TypeClass TC, TagDecl *D, QualType can)
916 8259: : Type(TC, can, D->isDependentType()), decl(D, 0) {}
917 :
918 349195: bool RecordType::classof(const TagType *TT) {
919 349195: return isa<RecordDecl>(TT->getDecl());
920 : }
921 :
922 38783: bool EnumType::classof(const TagType *TT) {
923 38783: return isa<EnumDecl>(TT->getDecl());
924 : }
925 :
926 10519: static bool isDependent(const TemplateArgument &Arg) {
0: branch 1 not taken
7631: branch 2 taken
63: branch 3 taken
19: branch 4 taken
2806: branch 5 taken
0: branch 6 not taken
0: branch 7 not taken
927 10519: switch (Arg.getKind()) {
928 : case TemplateArgument::Null:
929 0: assert(false && "Should not have a NULL template argument");
930 : return false;
931 :
932 : case TemplateArgument::Type:
933 7631: return Arg.getAsType()->isDependentType();
934 :
935 : case TemplateArgument::Template:
936 63: return Arg.getAsTemplate().isDependent();
937 :
938 : case TemplateArgument::Declaration:
939 : case TemplateArgument::Integral:
940 : // Never dependent
941 19: return false;
942 :
943 : case TemplateArgument::Expression:
944 : return (Arg.getAsExpr()->isTypeDependent() ||
2786: branch 2 taken
20: branch 3 taken
301: branch 6 taken
2485: branch 7 taken
945 2806: Arg.getAsExpr()->isValueDependent());
946 :
947 : case TemplateArgument::Pack:
948 0: assert(0 && "FIXME: Implement!");
949 : return false;
950 : }
951 :
952 0: return false;
953 : }
954 :
955 : bool TemplateSpecializationType::
956 3222: anyDependentTemplateArguments(const TemplateArgumentListInfo &Args) {
957 3222: return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size());
958 : }
959 :
960 : bool TemplateSpecializationType::
961 3425: anyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) {
4210: branch 0 taken
2819: branch 1 taken
962 7029: for (unsigned i = 0; i != N; ++i)
606: branch 2 taken
3604: branch 3 taken
963 4210: if (isDependent(Args[i].getArgument()))
964 606: return true;
965 2819: return false;
966 : }
967 :
968 : bool TemplateSpecializationType::
969 5337: anyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) {
6309: branch 0 taken
2867: branch 1 taken
970 9176: for (unsigned i = 0; i != N; ++i)
2470: branch 1 taken
3839: branch 2 taken
971 6309: if (isDependent(Args[i]))
972 2470: return true;
973 2867: return false;
974 : }
975 :
976 : TemplateSpecializationType::
977 : TemplateSpecializationType(ASTContext &Context, TemplateName T,
978 : const TemplateArgument *Args,
979 5017: unsigned NumArgs, QualType Canon)
980 : : Type(TemplateSpecialization,
981 : Canon.isNull()? QualType(this, 0) : Canon,
982 : T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)),
983 : Context(Context),
4837: branch 1 taken
180: branch 2 taken
1970: branch 4 taken
2867: branch 5 taken
552: branch 7 taken
4465: branch 8 taken
0: branch 13 not taken
0: branch 14 not taken
0: branch 16 not taken
0: branch 17 not taken
0: branch 19 not taken
0: branch 20 not taken
984 5017: Template(T), NumArgs(NumArgs) {
985 : assert((!Canon.isNull() ||
986 : T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) &&
552: branch 1 taken
4465: branch 2 taken
500: branch 4 taken
52: branch 5 taken
500: branch 7 taken
0: branch 8 not taken
0: branch 11 not taken
0: branch 12 not taken
0: branch 14 not taken
0: branch 15 not taken
0: branch 17 not taken
0: branch 18 not taken
987 5017: "No canonical type for non-dependent class template specialization");
988 :
989 : TemplateArgument *TemplateArgs
990 5017: = reinterpret_cast<TemplateArgument *>(this + 1);
6556: branch 0 taken
5017: branch 1 taken
5017: branch 2 taken
5017: branch 3 taken
991 11573: for (unsigned Arg = 0; Arg < NumArgs; ++Arg)
6556: branch 1 taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
992 6556: new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]);
993 5017: }
994 :
995 4844: void TemplateSpecializationType::Destroy(ASTContext& C) {
6383: branch 0 taken
4844: branch 1 taken
996 4844: for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
997 : // FIXME: Not all expressions get cloned, so we can't yet perform
998 : // this destruction.
999 : // if (Expr *E = getArg(Arg).getAsExpr())
1000 : // E->Destroy(C);
1001 : }
1002 4844: }
1003 :
1004 : TemplateSpecializationType::iterator
1005 0: TemplateSpecializationType::end() const {
1006 0: return begin() + getNumArgs();
1007 : }
1008 :
1009 : const TemplateArgument &
1010 7935: TemplateSpecializationType::getArg(unsigned Idx) const {
7935: branch 1 taken
0: branch 2 not taken
1011 7935: assert(Idx < getNumArgs() && "Template argument out of range");
1012 7935: return getArgs()[Idx];
1013 : }
1014 :
1015 : void
1016 : TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
1017 : TemplateName T,
1018 : const TemplateArgument *Args,
1019 : unsigned NumArgs,
1020 1374: ASTContext &Context) {
1021 1374: T.Profile(ID);
1748: branch 0 taken
1374: branch 1 taken
1022 3122: for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
1023 1748: Args[Idx].Profile(ID, Context);
1024 1374: }
1025 :
1026 11174: QualType QualifierCollector::apply(QualType QT) const {
11115: branch 1 taken
59: branch 2 taken
1027 11174: if (!hasNonFastQualifiers())
1028 11115: return QT.withFastQualifiers(getFastQualifiers());
1029 :
0: branch 0 not taken
59: branch 1 taken
1030 59: assert(Context && "extended qualifiers but no context!");
1031 59: return Context->getQualifiedType(QT, *this);
1032 : }
1033 :
1034 8: QualType QualifierCollector::apply(const Type *T) const {
8: branch 1 taken
0: branch 2 not taken
1035 8: if (!hasNonFastQualifiers())
1036 8: return QualType(T, getFastQualifiers());
1037 :
0: branch 0 not taken
0: branch 1 not taken
1038 0: assert(Context && "extended qualifiers but no context!");
1039 0: return Context->getQualifiedType(T, *this);
1040 : }
1041 :
1042 : void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
1043 : const ObjCInterfaceDecl *Decl,
1044 : ObjCProtocolDecl * const *protocols,
1045 7285: unsigned NumProtocols) {
1046 7285: ID.AddPointer(Decl);
253: branch 0 taken
7285: branch 1 taken
1047 7538: for (unsigned i = 0; i != NumProtocols; i++)
1048 253: ID.AddPointer(protocols[i]);
1049 7285: }
1050 :
1051 2734: void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
1052 2734: Profile(ID, getDecl(), qual_begin(), getNumProtocols());
1053 2734: }
1054 :
1055 844: Linkage Type::getLinkage() const {
1056 : // C++ [basic.link]p8:
1057 : // Names not covered by these rules have no linkage.
490: branch 1 taken
354: branch 2 taken
1058 844: if (this != CanonicalType.getTypePtr())
1059 490: return CanonicalType->getLinkage();
1060 :
1061 354: return NoLinkage;
1062 : }
1063 :
1064 4508: Linkage BuiltinType::getLinkage() const {
1065 : // C++ [basic.link]p8:
1066 : // A type is said to have linkage if and only if:
1067 : // - it is a fundamental type (3.9.1); or
1068 4508: return ExternalLinkage;
1069 : }
1070 :
1071 1205: Linkage TagType::getLinkage() const {
1072 : // C++ [basic.link]p8:
1073 : // - it is a class or enumeration type that is named (or has a name for
1074 : // linkage purposes (7.1.3)) and the name has linkage; or
1075 : // - it is a specialization of a class template (14); or
1076 1205: return getDecl()->getLinkage();
1077 : }
1078 :
1079 : // C++ [basic.link]p8:
1080 : // - it is a compound type (3.9.2) other than a class or enumeration,
1081 : // compounded exclusively from types that have linkage; or
1082 2: Linkage ComplexType::getLinkage() const {
1083 2: return ElementType->getLinkage();
1084 : }
1085 :
1086 3346: Linkage PointerType::getLinkage() const {
1087 3346: return PointeeType->getLinkage();
1088 : }
1089 :
1090 7: Linkage BlockPointerType::getLinkage() const {
1091 7: return PointeeType->getLinkage();
1092 : }
1093 :
1094 378: Linkage ReferenceType::getLinkage() const {
1095 378: return PointeeType->getLinkage();
1096 : }
1097 :
1098 105: Linkage MemberPointerType::getLinkage() const {
1099 105: return minLinkage(Class->getLinkage(), PointeeType->getLinkage());
1100 : }
1101 :
1102 64: Linkage ArrayType::getLinkage() const {
1103 64: return ElementType->getLinkage();
1104 : }
1105 :
1106 0: Linkage VectorType::getLinkage() const {
1107 0: return ElementType->getLinkage();
1108 : }
1109 :
1110 0: Linkage FunctionNoProtoType::getLinkage() const {
1111 0: return getResultType()->getLinkage();
1112 : }
1113 :
1114 3193: Linkage FunctionProtoType::getLinkage() const {
1115 3193: Linkage L = getResultType()->getLinkage();
1272: branch 2 taken
3193: branch 3 taken
1116 4465: for (arg_type_iterator A = arg_type_begin(), AEnd = arg_type_end();
1117 : A != AEnd; ++A)
1118 1272: L = minLinkage(L, (*A)->getLinkage());
1119 :
1120 3193: return L;
1121 : }
1122 :
1123 0: Linkage ObjCInterfaceType::getLinkage() const {
1124 0: return ExternalLinkage;
1125 : }
1126 :
1127 0: Linkage ObjCObjectPointerType::getLinkage() const {
1128 0: return ExternalLinkage;
1129 : }
Generated: 2010-02-10 01:31 by zcov