 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
61.5% |
315 / 512 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
79.9% |
409 / 512 |
| |
|
Line Coverage: |
94.5% |
919 / 972 |
| |
 |
|
 |
 |
|
 |
|
| Programs: |
187 |
|
Runs |
386283 |
| |
 |
|
 |
1 : //===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
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 defines the Type interface and subclasses.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #ifndef LLVM_CLANG_AST_TYPE_H
15 : #define LLVM_CLANG_AST_TYPE_H
16 :
17 : #include "clang/Basic/Diagnostic.h"
18 : #include "clang/Basic/IdentifierTable.h"
19 : #include "clang/Basic/Linkage.h"
20 : #include "clang/AST/NestedNameSpecifier.h"
21 : #include "clang/AST/TemplateName.h"
22 : #include "llvm/Support/Casting.h"
23 : #include "llvm/Support/type_traits.h"
24 : #include "llvm/ADT/APSInt.h"
25 : #include "llvm/ADT/FoldingSet.h"
26 : #include "llvm/ADT/PointerIntPair.h"
27 : #include "llvm/ADT/PointerUnion.h"
28 :
29 : using llvm::isa;
30 : using llvm::cast;
31 : using llvm::cast_or_null;
32 : using llvm::dyn_cast;
33 : using llvm::dyn_cast_or_null;
34 : namespace clang {
35 : enum {
36 : TypeAlignmentInBits = 3,
37 : TypeAlignment = 1 << TypeAlignmentInBits
38 : };
39 : class Type;
40 : class ExtQuals;
41 : class QualType;
42 : }
43 :
44 : namespace llvm {
45 : template <typename T>
46 : class PointerLikeTypeTraits;
47 : template<>
48 : class PointerLikeTypeTraits< ::clang::Type*> {
49 : public:
50 1023402: static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
51 17814380: static inline ::clang::Type *getFromVoidPointer(void *P) {
52 17814380: return static_cast< ::clang::Type*>(P);
53 : }
54 : enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
55 : };
56 : template<>
57 : class PointerLikeTypeTraits< ::clang::ExtQuals*> {
58 : public:
59 14120: static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
60 96383: static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
61 96383: return static_cast< ::clang::ExtQuals*>(P);
62 : }
63 : enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
64 : };
65 :
66 : template <>
67 : struct isPodLike<clang::QualType> { static const bool value = true; };
68 : }
69 :
70 : namespace clang {
71 : class ASTContext;
72 : class TypedefDecl;
73 : class TemplateDecl;
74 : class TemplateTypeParmDecl;
75 : class NonTypeTemplateParmDecl;
76 : class TemplateTemplateParmDecl;
77 : class TagDecl;
78 : class RecordDecl;
79 : class CXXRecordDecl;
80 : class EnumDecl;
81 : class FieldDecl;
82 : class ObjCInterfaceDecl;
83 : class ObjCProtocolDecl;
84 : class ObjCMethodDecl;
85 : class UnresolvedUsingTypenameDecl;
86 : class Expr;
87 : class Stmt;
88 : class SourceLocation;
89 : class StmtIteratorBase;
90 : class TemplateArgument;
91 : class TemplateArgumentLoc;
92 : class TemplateArgumentListInfo;
93 : class QualifiedNameType;
94 : struct PrintingPolicy;
95 :
96 : // Provide forward declarations for all of the *Type classes
97 : #define TYPE(Class, Base) class Class##Type;
98 : #include "clang/AST/TypeNodes.def"
99 :
100 : /// Qualifiers - The collection of all-type qualifiers we support.
101 : /// Clang supports five independent qualifiers:
102 : /// * C99: const, volatile, and restrict
103 : /// * Embedded C (TR18037): address spaces
104 : /// * Objective C: the GC attributes (none, weak, or strong)
105 66: class Qualifiers {
106 : public:
107 : enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
108 : Const = 0x1,
109 : Restrict = 0x2,
110 : Volatile = 0x4,
111 : CVRMask = Const | Volatile | Restrict
112 : };
113 :
114 : enum GC {
115 : GCNone = 0,
116 : Weak,
117 : Strong
118 : };
119 :
120 : enum {
121 : /// The maximum supported address space number.
122 : /// 24 bits should be enough for anyone.
123 : MaxAddressSpace = 0xffffffu,
124 :
125 : /// The width of the "fast" qualifier mask.
126 : FastWidth = 2,
127 :
128 : /// The fast qualifier mask.
129 : FastMask = (1 << FastWidth) - 1
130 : };
131 :
132 1527264: Qualifiers() : Mask(0) {}
133 :
134 : static Qualifiers fromFastMask(unsigned Mask) {
135 : Qualifiers Qs;
136 : Qs.addFastQualifiers(Mask);
137 : return Qs;
138 : }
139 :
140 50279: static Qualifiers fromCVRMask(unsigned CVR) {
141 50279: Qualifiers Qs;
142 50279: Qs.addCVRQualifiers(CVR);
143 : return Qs;
144 : }
145 :
146 : // Deserialize qualifiers from an opaque representation.
147 1: static Qualifiers fromOpaqueValue(unsigned opaque) {
148 1: Qualifiers Qs;
149 1: Qs.Mask = opaque;
150 : return Qs;
151 : }
152 :
153 : // Serialize these qualifiers into an opaque representation.
154 1: unsigned getAsOpaqueValue() const {
155 1: return Mask;
156 : }
157 :
158 6896: bool hasConst() const { return Mask & Const; }
159 : void setConst(bool flag) {
160 : Mask = (Mask & ~Const) | (flag ? Const : 0);
161 : }
162 1914: void removeConst() { Mask &= ~Const; }
163 433: void addConst() { Mask |= Const; }
164 :
165 30998: bool hasVolatile() const { return Mask & Volatile; }
166 : void setVolatile(bool flag) {
167 : Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
168 : }
169 1883: void removeVolatile() { Mask &= ~Volatile; }
170 4551: void addVolatile() { Mask |= Volatile; }
171 :
172 20801: bool hasRestrict() const { return Mask & Restrict; }
173 : void setRestrict(bool flag) {
174 : Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
175 : }
176 1: void removeRestrict() { Mask &= ~Restrict; }
177 261: void addRestrict() { Mask |= Restrict; }
178 :
179 : bool hasCVRQualifiers() const { return getCVRQualifiers(); }
180 7546: unsigned getCVRQualifiers() const { return Mask & CVRMask; }
181 129: void setCVRQualifiers(unsigned mask) {
0: branch 0 not taken
129: branch 1 taken
182 129: assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
183 129: Mask = (Mask & ~CVRMask) | mask;
184 129: }
185 3: void removeCVRQualifiers(unsigned mask) {
0: branch 0 not taken
3: branch 1 taken
186 3: assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
187 3: Mask &= ~mask;
188 3: }
189 : void removeCVRQualifiers() {
190 : removeCVRQualifiers(CVRMask);
191 : }
192 51693: void addCVRQualifiers(unsigned mask) {
0: branch 0 not taken
51693: branch 1 taken
193 51693: assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
194 51693: Mask |= mask;
195 51693: }
196 :
197 1272: bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
198 8979: GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
199 13141: void setObjCGCAttr(GC type) {
200 13141: Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
201 13141: }
202 5123: void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
203 642: void addObjCGCAttr(GC type) {
0: branch 0 not taken
642: branch 1 taken
204 642: assert(type);
205 642: setObjCGCAttr(type);
206 642: }
207 :
208 2351: bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
209 1200: unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
210 815: void setAddressSpace(unsigned space) {
0: branch 0 not taken
815: branch 1 taken
211 815: assert(space <= MaxAddressSpace);
212 : Mask = (Mask & ~AddressSpaceMask)
213 815: | (((uint32_t) space) << AddressSpaceShift);
214 815: }
215 7: void removeAddressSpace() { setAddressSpace(0); }
216 450: void addAddressSpace(unsigned space) {
0: branch 0 not taken
450: branch 1 taken
217 450: assert(space);
218 450: setAddressSpace(space);
219 450: }
220 :
221 : // Fast qualifiers are those that can be allocated directly
222 : // on a QualType object.
223 30583: bool hasFastQualifiers() const { return getFastQualifiers(); }
224 124860: unsigned getFastQualifiers() const { return Mask & FastMask; }
225 : void setFastQualifiers(unsigned mask) {
226 : assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
227 : Mask = (Mask & ~FastMask) | mask;
228 : }
229 14120: void removeFastQualifiers(unsigned mask) {
0: branch 0 not taken
14120: branch 1 taken
230 14120: assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
231 14120: Mask &= ~mask;
232 14120: }
233 14120: void removeFastQualifiers() {
234 14120: removeFastQualifiers(FastMask);
235 14120: }
236 1359205: void addFastQualifiers(unsigned mask) {
0: branch 0 not taken
1359205: branch 1 taken
237 1359205: assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
238 1359205: Mask |= mask;
239 1359205: }
240 :
241 : /// hasNonFastQualifiers - Return true if the set contains any
242 : /// qualifiers which require an ExtQuals node to be allocated.
243 90479: bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
244 : Qualifiers getNonFastQualifiers() const {
245 : Qualifiers Quals = *this;
246 : Quals.setFastQualifiers(0);
247 : return Quals;
248 : }
249 :
250 : /// hasQualifiers - Return true if the set contains any qualifiers.
251 938978: bool hasQualifiers() const { return Mask; }
252 8908: bool empty() const { return !Mask; }
253 :
254 : /// \brief Add the qualifiers from the given set to this set.
255 198797: void addQualifiers(Qualifiers Q) {
256 : // If the other set doesn't have any non-boolean qualifiers, just
257 : // bit-or it in.
197845: branch 0 taken
952: branch 1 taken
258 198797: if (!(Q.Mask & ~CVRMask))
259 197845: Mask |= Q.Mask;
260 : else {
261 952: Mask |= (Q.Mask & CVRMask);
400: branch 1 taken
552: branch 2 taken
262 952: if (Q.hasAddressSpace())
263 400: addAddressSpace(Q.getAddressSpace());
552: branch 1 taken
400: branch 2 taken
264 952: if (Q.hasObjCGCAttr())
265 552: addObjCGCAttr(Q.getObjCGCAttr());
266 : }
267 198797: }
268 :
269 13812: bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
270 3358: bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
271 :
272 9694: operator bool() const { return hasQualifiers(); }
273 :
274 2308: Qualifiers &operator+=(Qualifiers R) {
275 2308: addQualifiers(R);
276 2308: return *this;
277 : }
278 :
279 : // Union two qualifier sets. If an enumerated qualifier appears
280 : // in both sets, use the one from the right.
281 1539: friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
282 1539: L += R;
283 1539: return L;
284 : }
285 :
286 : std::string getAsString() const;
287 0: std::string getAsString(const PrintingPolicy &Policy) const {
288 0: std::string Buffer;
289 0: getAsStringInternal(Buffer, Policy);
290 : return Buffer;
291 : }
292 : void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
293 :
294 30039: void Profile(llvm::FoldingSetNodeID &ID) const {
295 30039: ID.AddInteger(Mask);
296 30039: }
297 :
298 : private:
299 :
300 : // bits: |0 1 2|3 .. 4|5 .. 31|
301 : // |C R V|GCAttr|AddrSpace|
302 : uint32_t Mask;
303 :
304 : static const uint32_t GCAttrMask = 0x18;
305 : static const uint32_t GCAttrShift = 3;
306 : static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask);
307 : static const uint32_t AddressSpaceShift = 5;
308 : };
309 :
310 :
311 : /// ExtQuals - We can encode up to three bits in the low bits of a
312 : /// type pointer, but there are many more type qualifiers that we want
313 : /// to be able to apply to an arbitrary type. Therefore we have this
314 : /// struct, intended to be heap-allocated and used by QualType to
315 : /// store qualifiers.
316 : ///
317 : /// The current design tags the 'const' and 'restrict' qualifiers in
318 : /// two low bits on the QualType pointer; a third bit records whether
319 : /// the pointer is an ExtQuals node. 'const' was chosen because it is
320 : /// orders of magnitude more common than the other two qualifiers, in
321 : /// both library and user code. It's relatively rare to see
322 : /// 'restrict' in user code, but many standard C headers are saturated
323 : /// with 'restrict' declarations, so that representing them efficiently
324 : /// is a critical goal of this representation.
325 : class ExtQuals : public llvm::FoldingSetNode {
326 : // NOTE: changing the fast qualifiers should be straightforward as
327 : // long as you don't make 'const' non-fast.
328 : // 1. Qualifiers:
329 : // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
330 : // Fast qualifiers must occupy the low-order bits.
331 : // b) Update Qualifiers::FastWidth and FastMask.
332 : // 2. QualType:
333 : // a) Update is{Volatile,Restrict}Qualified(), defined inline.
334 : // b) Update remove{Volatile,Restrict}, defined near the end of
335 : // this header.
336 : // 3. ASTContext:
337 : // a) Update get{Volatile,Restrict}Type.
338 :
339 : /// Context - the context to which this set belongs. We save this
340 : /// here so that QualifierCollector can use it to reapply extended
341 : /// qualifiers to an arbitrary type without requiring a context to
342 : /// be pushed through every single API dealing with qualifiers.
343 : ASTContext& Context;
344 :
345 : /// BaseType - the underlying type that this qualifies
346 : const Type *BaseType;
347 :
348 : /// Quals - the immutable set of qualifiers applied by this
349 : /// node; always contains extended qualifiers.
350 : Qualifiers Quals;
351 :
352 : public:
353 544: ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals)
354 544: : Context(Context), BaseType(Base), Quals(Quals)
355 : {
356 : assert(Quals.hasNonFastQualifiers()
544: branch 1 taken
0: branch 2 not taken
357 544: && "ExtQuals created with no fast qualifiers");
358 : assert(!Quals.hasFastQualifiers()
544: branch 1 taken
0: branch 2 not taken
359 544: && "ExtQuals created with fast qualifiers");
360 544: }
361 :
362 29315: Qualifiers getQualifiers() const { return Quals; }
363 :
364 5974: bool hasVolatile() const { return Quals.hasVolatile(); }
365 :
366 230: bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
367 209: Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
368 :
369 1211: bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
370 165: unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
371 :
372 98645: const Type *getBaseType() const { return BaseType; }
373 :
374 9497: ASTContext &getContext() const { return Context; }
375 :
376 : public:
377 15919: void Profile(llvm::FoldingSetNodeID &ID) const {
378 15919: Profile(ID, getBaseType(), Quals);
379 15919: }
380 : static void Profile(llvm::FoldingSetNodeID &ID,
381 : const Type *BaseType,
382 30039: Qualifiers Quals) {
30039: branch 1 taken
0: branch 2 not taken
383 30039: assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
384 30039: ID.AddPointer(BaseType);
385 30039: Quals.Profile(ID);
386 30039: }
387 : };
388 :
389 : /// CallingConv - Specifies the calling convention that a function uses.
390 : enum CallingConv {
391 : CC_Default,
392 : CC_C, // __attribute__((cdecl))
393 : CC_X86StdCall, // __attribute__((stdcall))
394 : CC_X86FastCall // __attribute__((fastcall))
395 : };
396 :
397 :
398 : /// QualType - For efficiency, we don't store CV-qualified types as nodes on
399 : /// their own: instead each reference to a type stores the qualifiers. This
400 : /// greatly reduces the number of nodes we need to allocate for types (for
401 : /// example we only need one for 'int', 'const int', 'volatile int',
402 : /// 'const volatile int', etc).
403 : ///
404 : /// As an added efficiency bonus, instead of making this a pair, we
405 : /// just store the two bits we care about in the low bits of the
406 : /// pointer. To handle the packing/unpacking, we make QualType be a
407 : /// simple wrapper class that acts like a smart pointer. A third bit
408 : /// indicates whether there are extended qualifiers present, in which
409 : /// case the pointer points to a special structure.
410 2816: class QualType {
411 : // Thankfully, these are efficiently composable.
412 : llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
413 : Qualifiers::FastWidth> Value;
414 :
415 96383: const ExtQuals *getExtQualsUnsafe() const {
416 96383: return Value.getPointer().get<const ExtQuals*>();
417 : }
418 :
419 17814377: const Type *getTypePtrUnsafe() const {
420 17814377: return Value.getPointer().get<const Type*>();
421 : }
422 :
423 : QualType getUnqualifiedTypeSlow() const;
424 :
425 : friend class QualifierCollector;
426 : public:
427 3395298: QualType() {}
428 :
429 1023365: QualType(const Type *Ptr, unsigned Quals)
430 1023365: : Value(Ptr, Quals) {}
431 14120: QualType(const ExtQuals *Ptr, unsigned Quals)
432 14120: : Value(Ptr, Quals) {}
433 :
434 4310552: unsigned getLocalFastQualifiers() const { return Value.getInt(); }
435 : void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
436 :
437 : /// Retrieves a pointer to the underlying (unqualified) type.
438 : /// This should really return a const Type, but it's not worth
439 : /// changing all the users right now.
440 16936757: Type *getTypePtr() const {
73229: branch 1 taken
16863528: branch 2 taken
441 16936757: if (hasLocalNonFastQualifiers())
442 73229: return const_cast<Type*>(getExtQualsUnsafe()->getBaseType());
443 16863528: return const_cast<Type*>(getTypePtrUnsafe());
444 : }
445 :
446 1383711: void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
447 1171409: static QualType getFromOpaquePtr(void *Ptr) {
448 1171409: QualType T;
449 1171409: T.Value.setFromOpaqueValue(Ptr);
450 : return T;
451 : }
452 :
453 : Type &operator*() const {
454 : return *getTypePtr();
455 : }
456 :
457 4950666: Type *operator->() const {
458 4950666: return getTypePtr();
459 : }
460 :
461 : bool isCanonical() const;
462 : bool isCanonicalAsParam() const;
463 :
464 : /// isNull - Return true if this QualType doesn't point to a type yet.
465 3193959: bool isNull() const {
466 3193959: return Value.getPointer().isNull();
467 : }
468 :
469 : /// \brief Determine whether this particular QualType instance has the
470 : /// "const" qualifier set, without looking through typedefs that may have
471 : /// added "const" at a different level.
472 40535: bool isLocalConstQualified() const {
473 40535: return (getLocalFastQualifiers() & Qualifiers::Const);
474 : }
475 :
476 : /// \brief Determine whether this type is const-qualified.
477 : bool isConstQualified() const;
478 :
479 : /// \brief Determine whether this particular QualType instance has the
480 : /// "restrict" qualifier set, without looking through typedefs that may have
481 : /// added "restrict" at a different level.
482 15973: bool isLocalRestrictQualified() const {
483 15973: return (getLocalFastQualifiers() & Qualifiers::Restrict);
484 : }
485 :
486 : /// \brief Determine whether this type is restrict-qualified.
487 : bool isRestrictQualified() const;
488 :
489 : /// \brief Determine whether this particular QualType instance has the
490 : /// "volatile" qualifier set, without looking through typedefs that may have
491 : /// added "volatile" at a different level.
492 227901: bool isLocalVolatileQualified() const {
5937: branch 5 taken
37: branch 6 taken
493 227901: return (hasLocalNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile());
494 : }
495 :
496 : /// \brief Determine whether this type is volatile-qualified.
497 : bool isVolatileQualified() const;
498 :
499 : /// \brief Determine whether this particular QualType instance has any
500 : /// qualifiers, without looking through any typedefs that might add
501 : /// qualifiers at a different level.
502 2677206: bool hasLocalQualifiers() const {
54388: branch 2 taken
11106: branch 4 taken
2611712: branch 5 taken
0: branch 5 not taken
503 2677206: return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
504 : }
505 :
506 : /// \brief Determine whether this type has any qualifiers.
507 : bool hasQualifiers() const;
508 :
509 : /// \brief Determine whether this particular QualType instance has any
510 : /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
511 : /// instance.
512 21309157: bool hasLocalNonFastQualifiers() const {
513 21309157: return Value.getPointer().is<const ExtQuals*>();
514 : }
515 :
516 : /// \brief Retrieve the set of qualifiers local to this particular QualType
517 : /// instance, not including any qualifiers acquired through typedefs or
518 : /// other sugar.
519 398859: Qualifiers getLocalQualifiers() const {
520 398859: Qualifiers Quals;
6242: branch 1 taken
392617: branch 2 taken
521 398859: if (hasLocalNonFastQualifiers())
522 6242: Quals = getExtQualsUnsafe()->getQualifiers();
523 398859: Quals.addFastQualifiers(getLocalFastQualifiers());
524 : return Quals;
525 : }
526 :
527 : /// \brief Retrieve the set of qualifiers applied to this type.
528 : Qualifiers getQualifiers() const;
529 :
530 : /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
531 : /// local to this particular QualType instance, not including any qualifiers
532 : /// acquired through typedefs or other sugar.
533 214708: unsigned getLocalCVRQualifiers() const {
534 214708: unsigned CVR = getLocalFastQualifiers();
5844: branch 1 taken
208864: branch 2 taken
535 214708: if (isLocalVolatileQualified())
536 5844: CVR |= Qualifiers::Volatile;
537 214708: return CVR;
538 : }
539 :
540 : /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
541 : /// applied to this type.
542 : unsigned getCVRQualifiers() const;
543 :
544 : /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
545 : /// applied to this type, looking through any number of unqualified array
546 : /// types to their element types' qualifiers.
547 : unsigned getCVRQualifiersThroughArrayTypes() const;
548 :
549 10626: bool isConstant(ASTContext& Ctx) const {
550 10626: return QualType::isConstant(*this, Ctx);
551 : }
552 :
553 : // Don't promise in the API that anything besides 'const' can be
554 : // easily added.
555 :
556 : /// addConst - add the specified type qualifier to this QualType.
557 519: void addConst() {
558 519: addFastQualifiers(Qualifiers::Const);
559 519: }
560 8313: QualType withConst() const {
561 8313: return withFastQualifiers(Qualifiers::Const);
562 : }
563 :
564 90465: void addFastQualifiers(unsigned TQs) {
565 : assert(!(TQs & ~Qualifiers::FastMask)
0: branch 0 not taken
90465: branch 1 taken
566 90465: && "non-fast qualifier bits set in mask!");
567 90465: Value.setInt(Value.getInt() | TQs);
568 90465: }
569 :
570 : // FIXME: The remove* functions are semantically broken, because they might
571 : // not remove a qualifier stored on a typedef. Most of the with* functions
572 : // have the same problem.
573 : void removeConst();
574 : void removeVolatile();
575 : void removeRestrict();
576 : void removeCVRQualifiers(unsigned Mask);
577 :
578 1689: void removeFastQualifiers() { Value.setInt(0); }
579 1473: void removeFastQualifiers(unsigned Mask) {
0: branch 0 not taken
1473: branch 1 taken
580 1473: assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
581 1473: Value.setInt(Value.getInt() & ~Mask);
582 1473: }
583 :
584 : // Creates a type with the given qualifiers in addition to any
585 : // qualifiers already on this type.
586 89946: QualType withFastQualifiers(unsigned TQs) const {
587 89946: QualType T = *this;
588 89946: T.addFastQualifiers(TQs);
589 : return T;
590 : }
591 :
592 : // Creates a type with exactly the given fast qualifiers, removing
593 : // any existing fast qualifiers.
594 : QualType withExactFastQualifiers(unsigned TQs) const {
595 : return withoutFastQualifiers().withFastQualifiers(TQs);
596 : }
597 :
598 : // Removes fast qualifiers, but leaves any extended qualifiers in place.
599 : QualType withoutFastQualifiers() const {
600 : QualType T = *this;
601 : T.removeFastQualifiers();
602 : return T;
603 : }
604 :
605 : /// \brief Return this type with all of the instance-specific qualifiers
606 : /// removed, but without removing any qualifiers that may have been applied
607 : /// through typedefs.
608 512798: QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
609 :
610 : /// \brief Return the unqualified form of the given type, which might be
611 : /// desugared to eliminate qualifiers introduced via typedefs.
612 322474: QualType getUnqualifiedType() const {
613 322474: QualType T = getLocalUnqualifiedType();
322459: branch 1 taken
15: branch 2 taken
614 322474: if (!T.hasQualifiers())
615 322459: return T;
616 :
617 15: return getUnqualifiedTypeSlow();
618 : }
619 :
620 : bool isMoreQualifiedThan(QualType Other) const;
621 : bool isAtLeastAsQualifiedAs(QualType Other) const;
622 : QualType getNonReferenceType() const;
623 :
624 : /// getDesugaredType - Return the specified type with any "sugar" removed from
625 : /// the type. This takes off typedefs, typeof's etc. If the outer level of
626 : /// the type is already concrete, it returns it unmodified. This is similar
627 : /// to getting the canonical type, but it doesn't remove *all* typedefs. For
628 : /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
629 : /// concrete.
630 : ///
631 : /// Qualifiers are left in place.
632 1033: QualType getDesugaredType() const {
633 1033: return QualType::getDesugaredType(*this);
634 : }
635 :
636 : /// operator==/!= - Indicate whether the specified types and qualifiers are
637 : /// identical.
638 388544: friend bool operator==(const QualType &LHS, const QualType &RHS) {
639 388544: return LHS.Value == RHS.Value;
640 : }
641 70447: friend bool operator!=(const QualType &LHS, const QualType &RHS) {
642 70447: return LHS.Value != RHS.Value;
643 : }
644 : std::string getAsString() const;
645 :
646 3171: std::string getAsString(const PrintingPolicy &Policy) const {
647 3171: std::string S;
648 3171: getAsStringInternal(S, Policy);
649 : return S;
650 : }
651 : void getAsStringInternal(std::string &Str,
652 : const PrintingPolicy &Policy) const;
653 :
654 : void dump(const char *s) const;
655 : void dump() const;
656 :
657 85135: void Profile(llvm::FoldingSetNodeID &ID) const {
658 85135: ID.AddPointer(getAsOpaquePtr());
659 85135: }
660 :
661 : /// getAddressSpace - Return the address space of this type.
662 : inline unsigned getAddressSpace() const;
663 :
664 : /// GCAttrTypesAttr - Returns gc attribute of this type.
665 : inline Qualifiers::GC getObjCGCAttr() const;
666 :
667 : /// isObjCGCWeak true when Type is objc's weak.
668 11313: bool isObjCGCWeak() const {
669 11313: return getObjCGCAttr() == Qualifiers::Weak;
670 : }
671 :
672 : /// isObjCGCStrong true when Type is objc's strong.
673 334: bool isObjCGCStrong() const {
674 334: return getObjCGCAttr() == Qualifiers::Strong;
675 : }
676 :
677 : /// getNoReturnAttr - Returns true if the type has the noreturn attribute,
678 : /// false otherwise.
679 : bool getNoReturnAttr() const;
680 :
681 : /// getCallConv - Returns the calling convention of the type if the type
682 : /// is a function type, CC_Default otherwise.
683 : CallingConv getCallConv() const;
684 :
685 : private:
686 : // These methods are implemented in a separate translation unit;
687 : // "static"-ize them to avoid creating temporary QualTypes in the
688 : // caller.
689 : static bool isConstant(QualType T, ASTContext& Ctx);
690 : static QualType getDesugaredType(QualType T);
691 : };
692 :
693 : } // end clang.
694 :
695 : namespace llvm {
696 : /// Implement simplify_type for QualType, so that we can dyn_cast from QualType
697 : /// to a specific Type class.
698 : template<> struct simplify_type<const ::clang::QualType> {
699 : typedef ::clang::Type* SimpleType;
700 6689736: static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
701 6689736: return Val.getTypePtr();
702 : }
703 : };
704 : template<> struct simplify_type< ::clang::QualType>
705 : : public simplify_type<const ::clang::QualType> {};
706 :
707 : // Teach SmallPtrSet that QualType is "basically a pointer".
708 : template<>
709 : class PointerLikeTypeTraits<clang::QualType> {
710 : public:
711 370: static inline void *getAsVoidPointer(clang::QualType P) {
712 370: return P.getAsOpaquePtr();
713 : }
714 937: static inline clang::QualType getFromVoidPointer(void *P) {
715 937: return clang::QualType::getFromOpaquePtr(P);
716 : }
717 : // Various qualifiers go in low bits.
718 : enum { NumLowBitsAvailable = 0 };
719 : };
720 :
721 : } // end namespace llvm
722 :
723 : namespace clang {
724 :
725 : /// Type - This is the base class of the type hierarchy. A central concept
726 : /// with types is that each type always has a canonical type. A canonical type
727 : /// is the type with any typedef names stripped out of it or the types it
728 : /// references. For example, consider:
729 : ///
730 : /// typedef int foo;
731 : /// typedef foo* bar;
732 : /// 'int *' 'foo *' 'bar'
733 : ///
734 : /// There will be a Type object created for 'int'. Since int is canonical, its
735 : /// canonicaltype pointer points to itself. There is also a Type for 'foo' (a
736 : /// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next
737 : /// there is a PointerType that represents 'int*', which, like 'int', is
738 : /// canonical. Finally, there is a PointerType type for 'foo*' whose canonical
739 : /// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
740 : /// is also 'int*'.
741 : ///
742 : /// Non-canonical types are useful for emitting diagnostics, without losing
743 : /// information about typedefs being used. Canonical types are useful for type
744 : /// comparisons (they allow by-pointer equality tests) and useful for reasoning
745 : /// about whether something has a particular form (e.g. is a function type),
746 : /// because they implicitly, recursively, strip all typedefs out of a type.
747 : ///
748 : /// Types, once created, are immutable.
749 : ///
750 : class Type {
751 : public:
752 : enum TypeClass {
753 : #define TYPE(Class, Base) Class,
754 : #define ABSTRACT_TYPE(Class, Base)
755 : #include "clang/AST/TypeNodes.def"
756 : TagFirst = Record, TagLast = Enum
757 : };
758 :
759 : protected:
760 : enum { TypeClassBitSize = 6 };
761 :
762 : private:
763 : QualType CanonicalType;
764 :
765 : /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
766 : bool Dependent : 1;
767 :
768 : /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
769 : /// Note that this should stay at the end of the ivars for Type so that
770 : /// subclasses can pack their bitfields into the same word.
771 : unsigned TC : TypeClassBitSize;
772 :
773 : Type(const Type&); // DO NOT IMPLEMENT.
774 : void operator=(const Type&); // DO NOT IMPLEMENT.
775 : protected:
776 : // silence VC++ warning C4355: 'this' : used in base member initializer list
777 121877: Type *this_() { return this; }
778 158611: Type(TypeClass tc, QualType Canonical, bool dependent)
779 : : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical),
121877: branch 1 taken
36734: branch 2 taken
780 158611: Dependent(dependent), TC(tc) {}
0: branch 0 not taken
129266: branch 1 taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 6 not taken
0: branch 7 not taken
781 129266: virtual ~Type() {}
782 : virtual void Destroy(ASTContext& C);
783 : friend class ASTContext;
784 :
785 : public:
786 16882613: TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); }
787 :
788 1215997: bool isCanonicalUnqualified() const {
789 1215997: return CanonicalType.getTypePtr() == this;
790 : }
791 :
792 : /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
793 : /// object types, function types, and incomplete types.
794 :
795 : /// \brief Determines whether the type describes an object in memory.
796 : ///
797 : /// Note that this definition of object type corresponds to the C++
798 : /// definition of object type, which includes incomplete types, as
799 : /// opposed to the C definition (which does not include incomplete
800 : /// types).
801 : bool isObjectType() const;
802 :
803 : /// isIncompleteType - Return true if this is an incomplete type.
804 : /// A type that can describe objects, but which lacks information needed to
805 : /// determine its size (e.g. void, or a fwd declared struct). Clients of this
806 : /// routine will need to determine if the size is actually required.
807 : bool isIncompleteType() const;
808 :
809 : /// isIncompleteOrObjectType - Return true if this is an incomplete or object
810 : /// type, in other words, not a function type.
811 1129: bool isIncompleteOrObjectType() const {
812 1129: return !isFunctionType();
813 : }
814 :
815 : /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
816 : bool isPODType() const;
817 :
818 : /// isLiteralType - Return true if this is a literal type
819 : /// (C++0x [basic.types]p10)
820 : bool isLiteralType() const;
821 :
822 : /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
823 : /// types that have a non-constant expression. This does not include "[]".
824 : bool isVariablyModifiedType() const;
825 :
826 : /// Helper methods to distinguish type categories. All type predicates
827 : /// operate on the canonical type, ignoring typedefs and qualifiers.
828 :
829 : /// isSpecificBuiltinType - Test for a particular builtin type.
830 : bool isSpecificBuiltinType(unsigned K) const;
831 :
832 : /// isIntegerType() does *not* include complex integers (a GCC extension).
833 : /// isComplexIntegerType() can be used to test for complex integers.
834 : bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum)
835 : bool isEnumeralType() const;
836 : bool isBooleanType() const;
837 : bool isCharType() const;
838 : bool isWideCharType() const;
839 : bool isAnyCharacterType() const;
840 : bool isIntegralType() const;
841 :
842 : /// Floating point categories.
843 : bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
844 : /// isComplexType() does *not* include complex integers (a GCC extension).
845 : /// isComplexIntegerType() can be used to test for complex integers.
846 : bool isComplexType() const; // C99 6.2.5p11 (complex)
847 : bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int.
848 : bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
849 : bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
850 : bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
851 : bool isVoidType() const; // C99 6.2.5p19
852 : bool isDerivedType() const; // C99 6.2.5p20
853 : bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
854 : bool isAggregateType() const;
855 :
856 : // Type Predicates: Check to see if this type is structurally the specified
857 : // type, ignoring typedefs and qualifiers.
858 : bool isFunctionType() const;
859 1496: bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
860 146: bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
861 : bool isPointerType() const;
862 : bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
863 : bool isBlockPointerType() const;
864 : bool isVoidPointerType() const;
865 : bool isReferenceType() const;
866 : bool isLValueReferenceType() const;
867 : bool isRValueReferenceType() const;
868 : bool isFunctionPointerType() const;
869 : bool isMemberPointerType() const;
870 : bool isMemberFunctionPointerType() const;
871 : bool isArrayType() const;
872 : bool isConstantArrayType() const;
873 : bool isIncompleteArrayType() const;
874 : bool isVariableArrayType() const;
875 : bool isDependentSizedArrayType() const;
876 : bool isRecordType() const;
877 : bool isClassType() const;
878 : bool isStructureType() const;
879 : bool isUnionType() const;
880 : bool isComplexIntegerType() const; // GCC _Complex integer type.
881 : bool isVectorType() const; // GCC vector type.
882 : bool isExtVectorType() const; // Extended vector type.
883 : bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object.
884 : // FIXME: change this to 'raw' interface type, so we can used 'interface' type
885 : // for the common case.
886 : bool isObjCInterfaceType() const; // NSString or NSString<foo>
887 : bool isObjCQualifiedInterfaceType() const; // NSString<foo>
888 : bool isObjCQualifiedIdType() const; // id<foo>
889 : bool isObjCQualifiedClassType() const; // Class<foo>
890 : bool isObjCIdType() const; // id
891 : bool isObjCClassType() const; // Class
892 : bool isObjCSelType() const; // Class
893 : bool isObjCBuiltinType() const; // 'id' or 'Class'
894 : bool isTemplateTypeParmType() const; // C++ template type parameter
895 : bool isNullPtrType() const; // C++0x nullptr_t
896 :
897 : /// isDependentType - Whether this type is a dependent type, meaning
898 : /// that its definition somehow depends on a template parameter
899 : /// (C++ [temp.dep.type]).
900 453653: bool isDependentType() const { return Dependent; }
901 : bool isOverloadableType() const;
902 :
903 : /// hasPointerRepresentation - Whether this type is represented
904 : /// natively as a pointer; this includes pointers, references, block
905 : /// pointers, and Objective-C interface, qualified id, and qualified
906 : /// interface types, as well as nullptr_t.
907 : bool hasPointerRepresentation() const;
908 :
909 : /// hasObjCPointerRepresentation - Whether this type can represent
910 : /// an objective pointer type for the purpose of GC'ability
911 : bool hasObjCPointerRepresentation() const;
912 :
913 : // Type Checking Functions: Check to see if this type is structurally the
914 : // specified type, ignoring typedefs and qualifiers, and return a pointer to
915 : // the best type we can.
916 : const RecordType *getAsStructureType() const;
917 : /// NOTE: getAs*ArrayType are methods on ASTContext.
918 : const RecordType *getAsUnionType() const;
919 : const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
920 : // The following is a convenience method that returns an ObjCObjectPointerType
921 : // for object declared using an interface.
922 : const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
923 : const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
924 : const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const;
925 : const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
926 :
927 : // Member-template getAs<specific type>'. This scheme will eventually
928 : // replace the specific getAsXXXX methods above.
929 : //
930 : // There are some specializations of this member template listed
931 : // immediately following this class.
932 1129936: template <typename T> const T *getAs() const;
933 :
934 : /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC
935 : /// interface, return the interface type, otherwise return null.
936 : const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const;
937 :
938 : /// getArrayElementTypeNoTypeQual - If this is an array type, return the
939 : /// element type of the array, potentially with type qualifiers missing.
940 : /// This method should never be used when type qualifiers are meaningful.
941 : const Type *getArrayElementTypeNoTypeQual() const;
942 :
943 : /// getPointeeType - If this is a pointer, ObjC object pointer, or block
944 : /// pointer, this returns the respective pointee.
945 : QualType getPointeeType() const;
946 :
947 : /// getUnqualifiedDesugaredType() - Return the specified type with
948 : /// any "sugar" removed from the type, removing any typedefs,
949 : /// typeofs, etc., as well as any qualifiers.
950 : const Type *getUnqualifiedDesugaredType() const;
951 :
952 : /// More type predicates useful for type checking/promotion
953 : bool isPromotableIntegerType() const; // C99 6.3.1.1p2
954 :
955 : /// isSignedIntegerType - Return true if this is an integer type that is
956 : /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
957 : /// an enum decl which has a signed representation, or a vector of signed
958 : /// integer element type.
959 : bool isSignedIntegerType() const;
960 :
961 : /// isUnsignedIntegerType - Return true if this is an integer type that is
962 : /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
963 : /// decl which has an unsigned representation, or a vector of unsigned integer
964 : /// element type.
965 : bool isUnsignedIntegerType() const;
966 :
967 : /// isConstantSizeType - Return true if this is not a variable sized type,
968 : /// according to the rules of C99 6.7.5p3. It is not legal to call this on
969 : /// incomplete types.
970 : bool isConstantSizeType() const;
971 :
972 : /// isSpecifierType - Returns true if this type can be represented by some
973 : /// set of type specifiers.
974 : bool isSpecifierType() const;
975 :
976 : const char *getTypeClassName() const;
977 :
978 : /// \brief Determine the linkage of this type.
979 : virtual Linkage getLinkage() const;
980 :
981 1851451: QualType getCanonicalTypeInternal() const { return CanonicalType; }
982 : void dump() const;
983 1351875: static bool classof(const Type *) { return true; }
984 : };
985 :
986 622: template <> inline const TypedefType *Type::getAs() const {
987 622: return dyn_cast<TypedefType>(this);
988 : }
989 :
990 : // We can do canonical leaf types faster, because we don't have to
991 : // worry about preserving child type decoration.
992 : #define TYPE(Class, Base)
993 : #define LEAF_TYPE(Class) \
994 : template <> inline const Class##Type *Type::getAs() const { \
995 : return dyn_cast<Class##Type>(CanonicalType); \
996 : }
997 : #include "clang/AST/TypeNodes.def"
998 :
999 :
1000 : /// BuiltinType - This class is used for builtin types like 'int'. Builtin
1001 : /// types are always canonical and have a literal name field.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
55739: branch 6 taken
1002 55739: class BuiltinType : public Type {
1003 : public:
1004 : enum Kind {
1005 : Void,
1006 :
1007 : Bool, // This is bool and/or _Bool.
1008 : Char_U, // This is 'char' for targets where char is unsigned.
1009 : UChar, // This is explicitly qualified unsigned char.
1010 : Char16, // This is 'char16_t' for C++.
1011 : Char32, // This is 'char32_t' for C++.
1012 : UShort,
1013 : UInt,
1014 : ULong,
1015 : ULongLong,
1016 : UInt128, // __uint128_t
1017 :
1018 : Char_S, // This is 'char' for targets where char is signed.
1019 : SChar, // This is explicitly qualified signed char.
1020 : WChar, // This is 'wchar_t' for C++.
1021 : Short,
1022 : Int,
1023 : Long,
1024 : LongLong,
1025 : Int128, // __int128_t
1026 :
1027 : Float, Double, LongDouble,
1028 :
1029 : NullPtr, // This is the type of C++0x 'nullptr'.
1030 :
1031 : Overload, // This represents the type of an overloaded function declaration.
1032 : Dependent, // This represents the type of a type-dependent expression.
1033 :
1034 : UndeducedAuto, // In C++0x, this represents the type of an auto variable
1035 : // that has not been deduced yet.
1036 : ObjCId, // This represents the ObjC 'id' type.
1037 : ObjCClass, // This represents the ObjC 'Class' type.
1038 : ObjCSel // This represents the ObjC 'SEL' type.
1039 : };
1040 : private:
1041 : Kind TypeKind;
1042 : public:
1043 58794: BuiltinType(Kind K)
1044 : : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)),
1045 58794: TypeKind(K) {}
1046 :
1047 1257309: Kind getKind() const { return TypeKind; }
1048 : const char *getName(const LangOptions &LO) const;
1049 :
1050 952: bool isSugared() const { return false; }
1051 0: QualType desugar() const { return QualType(this, 0); }
1052 :
1053 6208: bool isInteger() const {
6208: branch 0 taken
0: branch 1 not taken
6208: branch 2 taken
0: branch 3 not taken
1054 6208: return TypeKind >= Bool && TypeKind <= Int128;
1055 : }
1056 :
1057 : bool isSignedInteger() const {
1058 : return TypeKind >= Char_S && TypeKind <= Int128;
1059 : }
1060 :
1061 6106: bool isUnsignedInteger() const {
6106: branch 0 taken
0: branch 1 not taken
2491: branch 2 taken
3615: branch 3 taken
1062 6106: return TypeKind >= Bool && TypeKind <= UInt128;
1063 : }
1064 :
1065 26959: bool isFloatingPoint() const {
6235: branch 0 taken
20724: branch 1 taken
6211: branch 2 taken
24: branch 3 taken
1066 26959: return TypeKind >= Float && TypeKind <= LongDouble;
1067 : }
1068 :
1069 : virtual Linkage getLinkage() const;
1070 :
1071 2099790: static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
1072 : static bool classof(const BuiltinType *) { return true; }
1073 : };
1074 :
1075 : /// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex
1076 : /// types (_Complex float etc) as well as the GCC integer complex extensions.
1077 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
6422: branch 6 taken
1078 6422: class ComplexType : public Type, public llvm::FoldingSetNode {
1079 : QualType ElementType;
1080 6785: ComplexType(QualType Element, QualType CanonicalPtr) :
1081 : Type(Complex, CanonicalPtr, Element->isDependentType()),
1082 6785: ElementType(Element) {
1083 6785: }
1084 : friend class ASTContext; // ASTContext creates these.
1085 : public:
1086 1887: QualType getElementType() const { return ElementType; }
1087 :
1088 19: bool isSugared() const { return false; }
1089 0: QualType desugar() const { return QualType(this, 0); }
1090 :
1091 387: void Profile(llvm::FoldingSetNodeID &ID) {
1092 387: Profile(ID, getElementType());
1093 387: }
1094 7418: static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
1095 7418: ID.AddPointer(Element.getAsOpaquePtr());
1096 7418: }
1097 :
1098 : virtual Linkage getLinkage() const;
1099 :
1100 212577: static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
1101 : static bool classof(const ComplexType *) { return true; }
1102 : };
1103 :
1104 : /// PointerType - C99 6.7.5.1 - Pointer Declarators.
1105 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
14551: branch 6 taken
1106 14551: class PointerType : public Type, public llvm::FoldingSetNode {
1107 : QualType PointeeType;
1108 :
1109 15592: PointerType(QualType Pointee, QualType CanonicalPtr) :
1110 15592: Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) {
1111 15592: }
1112 : friend class ASTContext; // ASTContext creates these.
1113 : public:
1114 :
1115 206075: QualType getPointeeType() const { return PointeeType; }
1116 :
1117 8289: bool isSugared() const { return false; }
1118 0: QualType desugar() const { return QualType(this, 0); }
1119 :
1120 46967: void Profile(llvm::FoldingSetNodeID &ID) {
1121 46967: Profile(ID, getPointeeType());
1122 46967: }
1123 99611: static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
1124 99611: ID.AddPointer(Pointee.getAsOpaquePtr());
1125 99611: }
1126 :
1127 : virtual Linkage getLinkage() const;
1128 :
1129 757865: static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
1130 : static bool classof(const PointerType *) { return true; }
1131 : };
1132 :
1133 : /// BlockPointerType - pointer to a block type.
1134 : /// This type is to represent types syntactically represented as
1135 : /// "void (^)(int)", etc. Pointee is required to always be a function type.
1136 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
220: branch 6 taken
1137 220: class BlockPointerType : public Type, public llvm::FoldingSetNode {
1138 : QualType PointeeType; // Block is some kind of pointer type
1139 223: BlockPointerType(QualType Pointee, QualType CanonicalCls) :
1140 : Type(BlockPointer, CanonicalCls, Pointee->isDependentType()),
1141 223: PointeeType(Pointee) {
1142 223: }
1143 : friend class ASTContext; // ASTContext creates these.
1144 : public:
1145 :
1146 : // Get the pointee type. Pointee is required to always be a function type.
1147 2020: QualType getPointeeType() const { return PointeeType; }
1148 :
1149 77: bool isSugared() const { return false; }
1150 0: QualType desugar() const { return QualType(this, 0); }
1151 :
1152 305: void Profile(llvm::FoldingSetNodeID &ID) {
1153 305: Profile(ID, getPointeeType());
1154 305: }
1155 827: static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
1156 827: ID.AddPointer(Pointee.getAsOpaquePtr());
1157 827: }
1158 :
1159 : virtual Linkage getLinkage() const;
1160 :
1161 102810: static bool classof(const Type *T) {
1162 102810: return T->getTypeClass() == BlockPointer;
1163 : }
1164 : static bool classof(const BlockPointerType *) { return true; }
1165 : };
1166 :
1167 : /// ReferenceType - Base for LValueReferenceType and RValueReferenceType
1168 : ///
0: branch 1 not taken
9384: branch 2 taken
0: branch 5 not taken
0: branch 6 not taken
1169 9384: class ReferenceType : public Type, public llvm::FoldingSetNode {
1170 : QualType PointeeType;
1171 :
1172 : /// True if the type was originally spelled with an lvalue sigil.
1173 : /// This is never true of rvalue references but can also be false
1174 : /// on lvalue references because of C++0x [dcl.typedef]p9,
1175 : /// as follows:
1176 : ///
1177 : /// typedef int &ref; // lvalue, spelled lvalue
1178 : /// typedef int &&rvref; // rvalue
1179 : /// ref &a; // lvalue, inner ref, spelled lvalue
1180 : /// ref &&a; // lvalue, inner ref
1181 : /// rvref &a; // lvalue, inner ref, spelled lvalue
1182 : /// rvref &&a; // rvalue, inner ref
1183 : bool SpelledAsLValue;
1184 :
1185 : /// True if the inner type is a reference type. This only happens
1186 : /// in non-canonical forms.
1187 : bool InnerRef;
1188 :
1189 : protected:
1190 : ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
1191 9581: bool SpelledAsLValue) :
1192 : Type(tc, CanonicalRef, Referencee->isDependentType()),
1193 : PointeeType(Referencee), SpelledAsLValue(SpelledAsLValue),
1194 9581: InnerRef(Referencee->isReferenceType()) {
1195 9581: }
1196 : public:
1197 283: bool isSpelledAsLValue() const { return SpelledAsLValue; }
1198 :
1199 8181: QualType getPointeeTypeAsWritten() const { return PointeeType; }
1200 33025: QualType getPointeeType() const {
1201 : // FIXME: this might strip inner qualifiers; okay?
1202 33025: const ReferenceType *T = this;
44: branch 0 taken
33025: branch 1 taken
1203 66094: while (T->InnerRef)
1204 44: T = T->PointeeType->getAs<ReferenceType>();
1205 33025: return T->PointeeType;
1206 : }
1207 :
1208 30303: void Profile(llvm::FoldingSetNodeID &ID) {
1209 30303: Profile(ID, PointeeType, SpelledAsLValue);
1210 30303: }
1211 : static void Profile(llvm::FoldingSetNodeID &ID,
1212 : QualType Referencee,
1213 61464: bool SpelledAsLValue) {
1214 61464: ID.AddPointer(Referencee.getAsOpaquePtr());
1215 61464: ID.AddBoolean(SpelledAsLValue);
1216 61464: }
1217 :
1218 : virtual Linkage getLinkage() const;
1219 :
1220 976553: static bool classof(const Type *T) {
1221 : return T->getTypeClass() == LValueReference ||
860354: branch 1 taken
116199: branch 2 taken
575: branch 4 taken
859779: branch 5 taken
1222 976553: T->getTypeClass() == RValueReference;
1223 : }
1224 : static bool classof(const ReferenceType *) { return true; }
1225 : };
1226 :
1227 : /// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
1228 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
9367: branch 6 taken
1229 9367: class LValueReferenceType : public ReferenceType {
1230 : LValueReferenceType(QualType Referencee, QualType CanonicalRef,
1231 9564: bool SpelledAsLValue) :
1232 9564: ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
1233 9564: {}
1234 : friend class ASTContext; // ASTContext creates these
1235 : public:
1236 338: bool isSugared() const { return false; }
1237 0: QualType desugar() const { return QualType(this, 0); }
1238 :
1239 32109: static bool classof(const Type *T) {
1240 32109: return T->getTypeClass() == LValueReference;
1241 : }
1242 : static bool classof(const LValueReferenceType *) { return true; }
1243 : };
1244 :
1245 : /// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
1246 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
17: branch 6 taken
1247 17: class RValueReferenceType : public ReferenceType {
1248 17: RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
1249 17: ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
1250 17: }
1251 : friend class ASTContext; // ASTContext creates these
1252 : public:
1253 19: bool isSugared() const { return false; }
1254 0: QualType desugar() const { return QualType(this, 0); }
1255 :
1256 23853: static bool classof(const Type *T) {
1257 23853: return T->getTypeClass() == RValueReference;
1258 : }
1259 : static bool classof(const RValueReferenceType *) { return true; }
1260 : };
1261 :
1262 : /// MemberPointerType - C++ 8.3.3 - Pointers to members
1263 : ///
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
324: branch 6 taken
1264 324: class MemberPointerType : public Type, public llvm::FoldingSetNode {
1265 : QualType PointeeType;
1266 : /// The class of which the pointee is a member. Must ultimately be a
1267 : /// RecordType, but could be a typedef or a template parameter too.
1268 : const Type *Class;
1269 :
1270 324: MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
1271 : Type(MemberPointer, CanonicalPtr,
1272 : Cls->isDependentType() || Pointee->isDependentType()),
289: branch 1 taken
35: branch 2 taken
0: branch 5 not taken
289: branch 6 taken
1273 324: PointeeType(Pointee), Class(Cls) {
1274 324: }
1275 : friend class ASTContext; // ASTContext creates these.
1276 : public:
1277 :
1278 4322: QualType getPointeeType() const { return PointeeType; }
1279 :
1280 1712: const Type *getClass() const { return Class; }
1281 :
1282 416: bool isSugared() const { return false; }
1283 0: QualType desugar() const { return QualType(this, 0); }
1284 :
1285 395: void Profile(llvm::FoldingSetNodeID &ID) {
1286 395: Profile(ID, getPointeeType(), getClass());
1287 395: }
1288 : static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
1289 1074: const Type *Class) {
1290 1074: ID.AddPointer(Pointee.getAsOpaquePtr());
1291 1074: ID.AddPointer(Class);
1292 1074: }
1293 :
1294 : virtual Linkage getLinkage() const;
1295 :
1296 286815: static bool classof(const Type *T) {
1297 286815: return T->getTypeClass() == MemberPointer;
1298 : }
1299 : static bool classof(const MemberPointerType *) { return true; }
1300 : };
1301 :
1302 : /// ArrayType - C99 6.7.5.2 - Array Declarators.
1303 : ///
0: branch 1 not taken
2738: branch 2 taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 9 not taken
0: branch 10 not taken
1304 2738: class ArrayType : public Type, public llvm::FoldingSetNode {
1305 : public:
1306 : /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
1307 : /// an array with a static size (e.g. int X[static 4]), or an array
1308 : /// with a star size (e.g. int X[*]).
1309 : /// 'static' is only allowed on function parameters.
1310 : enum ArraySizeModifier {
1311 : Normal, Static, Star
1312 : };
1313 : private:
1314 : /// ElementType - The element type of the array.
1315 : QualType ElementType;
1316 :
1317 : // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum
1318 : /// NOTE: These fields are packed into the bitfields space in the Type class.
1319 : unsigned SizeModifier : 2;
1320 :
1321 : /// IndexTypeQuals - Capture qualifiers in declarations like:
1322 : /// 'int X[static restrict 4]'. For function parameters only.
1323 : unsigned IndexTypeQuals : 3;
1324 :
1325 : protected:
1326 : // C++ [temp.dep.type]p1:
1327 : // A type is dependent if it is...
1328 : // - an array type constructed from any dependent type or whose
1329 : // size is specified by a constant expression that is
1330 : // value-dependent,
1331 : ArrayType(TypeClass tc, QualType et, QualType can,
1332 2923: ArraySizeModifier sm, unsigned tq)
1333 : : Type(tc, can, et->isDependentType() || tc == DependentSizedArray),
2868: branch 2 taken
55: branch 3 taken
30: branch 4 taken
2838: branch 5 taken
1334 2923: ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
1335 :
1336 : friend class ASTContext; // ASTContext creates these.
1337 : public:
1338 31044: QualType getElementType() const { return ElementType; }
1339 3278: ArraySizeModifier getSizeModifier() const {
1340 3278: return ArraySizeModifier(SizeModifier);
1341 : }
1342 2974: Qualifiers getIndexTypeQualifiers() const {
1343 2974: return Qualifiers::fromCVRMask(IndexTypeQuals);
1344 : }
1345 3096: unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; }
1346 :
1347 : virtual Linkage getLinkage() const;
1348 :
1349 1015591: static bool classof(const Type *T) {
1350 : return T->getTypeClass() == ConstantArray ||
1351 : T->getTypeClass() == VariableArray ||
1352 : T->getTypeClass() == IncompleteArray ||
961695: branch 4 taken
53896: branch 5 taken
958884: branch 7 taken
2811: branch 8 taken
950322: branch 10 taken
8562: branch 11 taken
1002: branch 11 taken
949320: branch 11 taken
1353 1015591: T->getTypeClass() == DependentSizedArray;
1354 : }
1355 : static bool classof(const ArrayType *) { return true; }
1356 : };
1357 :
1358 : /// ConstantArrayType - This class represents the canonical version of
1359 : /// C arrays with a specified constant size. For example, the canonical
1360 : /// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
1361 : /// type is 'int' and the size is 404.
0: branch 2 not taken
0: branch 3 not taken
0: branch 7 not taken
2213: branch 8 taken
1362 2213: class ConstantArrayType : public ArrayType {
1363 : llvm::APInt Size; // Allows us to unique the type.
1364 :
1365 : ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
1366 2377: ArraySizeModifier sm, unsigned tq)
1367 : : ArrayType(ConstantArray, et, can, sm, tq),
1368 2377: Size(size) {}
1369 : protected:
1370 : ConstantArrayType(TypeClass tc, QualType et, QualType can,
1371 : const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
1372 : : ArrayType(tc, et, can, sm, tq), Size(size) {}
1373 : friend class ASTContext; // ASTContext creates these.
1374 : public:
1375 5963: const llvm::APInt &getSize() const { return Size; }
1376 764: bool isSugared() const { return false; }
1377 0: QualType desugar() const { return QualType(this, 0); }
1378 :
1379 2549: void Profile(llvm::FoldingSetNodeID &ID) {
1380 : Profile(ID, getElementType(), getSize(),
1381 2549: getSizeModifier(), getIndexTypeCVRQualifiers());
1382 2549: }
1383 : static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
1384 : const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
1385 7229: unsigned TypeQuals) {
1386 7229: ID.AddPointer(ET.getAsOpaquePtr());
1387 7229: ID.AddInteger(ArraySize.getZExtValue());
1388 7229: ID.AddInteger(SizeMod);
1389 7229: ID.AddInteger(TypeQuals);
1390 7229: }
1391 8192: static bool classof(const Type *T) {
1392 8192: return T->getTypeClass() == ConstantArray;
1393 : }
1394 : static bool classof(const ConstantArrayType *) { return true; }
1395 : };
1396 :
1397 : /// IncompleteArrayType - This class represents C arrays with an unspecified
1398 : /// size. For example 'int A[]' has an IncompleteArrayType where the element
1399 : /// type is 'int' and the size is unspecified.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
258: branch 6 taken
1400 258: class IncompleteArrayType : public ArrayType {
1401 :
1402 : IncompleteArrayType(QualType et, QualType can,
1403 275: ArraySizeModifier sm, unsigned tq)
1404 275: : ArrayType(IncompleteArray, et, can, sm, tq) {}
1405 : friend class ASTContext; // ASTContext creates these.
1406 : public:
1407 105: bool isSugared() const { return false; }
1408 0: QualType desugar() const { return QualType(this, 0); }
1409 :
1410 15585: static bool classof(const Type *T) {
1411 15585: return T->getTypeClass() == IncompleteArray;
1412 : }
1413 : static bool classof(const IncompleteArrayType *) { return true; }
1414 :
1415 : friend class StmtIteratorBase;
1416 :
1417 131: void Profile(llvm::FoldingSetNodeID &ID) {
1418 : Profile(ID, getElementType(), getSizeModifier(),
1419 131: getIndexTypeCVRQualifiers());
1420 131: }
1421 :
1422 : static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
1423 526: ArraySizeModifier SizeMod, unsigned TypeQuals) {
1424 526: ID.AddPointer(ET.getAsOpaquePtr());
1425 526: ID.AddInteger(SizeMod);
1426 526: ID.AddInteger(TypeQuals);
1427 526: }
1428 : };
1429 :
1430 : /// VariableArrayType - This class represents C arrays with a specified size
1431 : /// which is not an integer-constant-expression. For example, 'int s[x+foo()]'.
1432 : /// Since the size expression is an arbitrary expression, we store it as such.
1433 : ///
1434 : /// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
1435 : /// should not be: two lexically equivalent variable array types could mean
1436 : /// different things, for example, these variables do not have the same type
1437 : /// dynamically:
1438 : ///
1439 : /// void foo(int x) {
1440 : /// int Y[x];
1441 : /// ++x;
1442 : /// int Z[x];
1443 : /// }
1444 : ///
0: branch 2 not taken
0: branch 5 not taken
203: branch 6 taken
1445 203: class VariableArrayType : public ArrayType {
1446 : /// SizeExpr - An assignment expression. VLA's are only permitted within
1447 : /// a function block.
1448 : Stmt *SizeExpr;
1449 : /// Brackets - The left and right array brackets.
1450 : SourceRange Brackets;
1451 :
1452 : VariableArrayType(QualType et, QualType can, Expr *e,
1453 : ArraySizeModifier sm, unsigned tq,
1454 207: SourceRange brackets)
1455 : : ArrayType(VariableArray, et, can, sm, tq),
1456 207: SizeExpr((Stmt*) e), Brackets(brackets) {}
1457 : friend class ASTContext; // ASTContext creates these.
1458 : virtual void Destroy(ASTContext& C);
1459 :
1460 : public:
1461 436: Expr *getSizeExpr() const {
1462 : // We use C-style casts instead of cast<> here because we do not wish
1463 : // to have a dependency of Type.h on Stmt.h/Expr.h.
1464 436: return (Expr*) SizeExpr;
1465 : }
1466 15: SourceRange getBracketsRange() const { return Brackets; }
1467 1: SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
1468 1: SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
1469 :
1470 19: bool isSugared() const { return false; }
1471 0: QualType desugar() const { return QualType(this, 0); }
1472 :
1473 99549: static bool classof(const Type *T) {
1474 99549: return T->getTypeClass() == VariableArray;
1475 : }
1476 : static bool classof(const VariableArrayType *) { return true; }
1477 :
1478 : friend class StmtIteratorBase;
1479 :
1480 : void Profile(llvm::FoldingSetNodeID &ID) {
1481 : assert(0 && "Cannnot unique VariableArrayTypes.");
1482 : }
1483 : };
1484 :
1485 : /// DependentSizedArrayType - This type represents an array type in
1486 : /// C++ whose size is a value-dependent expression. For example:
1487 : ///
1488 : /// \code
1489 : /// template<typename T, int Size>
1490 : /// class array {
1491 : /// T data[Size];
1492 : /// };
1493 : /// \endcode
1494 : ///
1495 : /// For these types, we won't actually know what the array bound is
1496 : /// until template instantiation occurs, at which point this will
1497 : /// become either a ConstantArrayType or a VariableArrayType.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
64: branch 6 taken
1498 64: class DependentSizedArrayType : public ArrayType {
1499 : ASTContext &Context;
1500 :
1501 : /// \brief An assignment expression that will instantiate to the
1502 : /// size of the array.
1503 : ///
1504 : /// The expression itself might be NULL, in which case the array
1505 : /// type will have its size deduced from an initializer.
1506 : Stmt *SizeExpr;
1507 :
1508 : /// Brackets - The left and right array brackets.
1509 : SourceRange Brackets;
1510 :
1511 : DependentSizedArrayType(ASTContext &Context, QualType et, QualType can,
1512 : Expr *e, ArraySizeModifier sm, unsigned tq,
1513 64: SourceRange brackets)
1514 : : ArrayType(DependentSizedArray, et, can, sm, tq),
1515 64: Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {}
1516 : friend class ASTContext; // ASTContext creates these.
1517 : virtual void Destroy(ASTContext& C);
1518 :
1519 : public:
1520 167: Expr *getSizeExpr() const {
1521 : // We use C-style casts instead of cast<> here because we do not wish
1522 : // to have a dependency of Type.h on Stmt.h/Expr.h.
1523 167: return (Expr*) SizeExpr;
1524 : }
1525 2: SourceRange getBracketsRange() const { return Brackets; }
1526 : SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
1527 : SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
1528 :
1529 2: bool isSugared() const { return false; }
1530 0: QualType desugar() const { return QualType(this, 0); }
1531 :
1532 142: static bool classof(const Type *T) {
1533 142: return T->getTypeClass() == DependentSizedArray;
1534 : }
1535 : static bool classof(const DependentSizedArrayType *) { return true; }
1536 :
1537 : friend class StmtIteratorBase;
1538 :
1539 :
1540 7: void Profile(llvm::FoldingSetNodeID &ID) {
1541 : Profile(ID, Context, getElementType(),
1542 7: getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
1543 7: }
1544 :
1545 : static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
1546 : QualType ET, ArraySizeModifier SizeMod,
1547 : unsigned TypeQuals, Expr *E);
1548 : };
1549 :
1550 : /// DependentSizedExtVectorType - This type represent an extended vector type
1551 : /// where either the type or size is dependent. For example:
1552 : /// @code
1553 : /// template<typename T, int Size>
1554 : /// class vector {
1555 : /// typedef T __attribute__((ext_vector_type(Size))) type;
1556 : /// }
1557 : /// @endcode
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
12: branch 6 taken
1558 12: class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
1559 : ASTContext &Context;
1560 : Expr *SizeExpr;
1561 : /// ElementType - The element type of the array.
1562 : QualType ElementType;
1563 : SourceLocation loc;
1564 :
1565 : DependentSizedExtVectorType(ASTContext &Context, QualType ElementType,
1566 12: QualType can, Expr *SizeExpr, SourceLocation loc)
1567 : : Type (DependentSizedExtVector, can, true),
1568 : Context(Context), SizeExpr(SizeExpr), ElementType(ElementType),
1569 12: loc(loc) {}
1570 : friend class ASTContext;
1571 : virtual void Destroy(ASTContext& C);
1572 :
1573 : public:
1574 11: Expr *getSizeExpr() const { return SizeExpr; }
1575 15: QualType getElementType() const { return ElementType; }
1576 6: SourceLocation getAttributeLoc() const { return loc; }
1577 :
1578 0: bool isSugared() const { return false; }
1579 0: QualType desugar() const { return QualType(this, 0); }
1580 :
1581 10: static bool classof(const Type *T) {
1582 10: return T->getTypeClass() == DependentSizedExtVector;
1583 : }
1584 : static bool classof(const DependentSizedExtVectorType *) { return true; }
1585 :
1586 3: void Profile(llvm::FoldingSetNodeID &ID) {
1587 3: Profile(ID, Context, getElementType(), getSizeExpr());
1588 3: }
1589 :
1590 : static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
1591 : QualType ElementType, Expr *SizeExpr);
1592 : };
1593 :
1594 :
1595 : /// VectorType - GCC generic vector type. This type is created using
1596 : /// __attribute__((vector_size(n)), where "n" specifies the vector size in
1597 : /// bytes; or from an Altivec __vector or vector declaration.
1598 : /// Since the constructor takes the number of vector elements, the
1599 : /// client is responsible for converting the size into the number of elements.
0: branch 1 not taken
67: branch 2 taken
0: branch 5 not taken
156: branch 6 taken
1600 223: class VectorType : public Type, public llvm::FoldingSetNode {
1601 : protected:
1602 : /// ElementType - The element type of the vector.
1603 : QualType ElementType;
1604 :
1605 : /// NumElements - The number of elements in the vector.
1606 : unsigned NumElements;
1607 :
1608 : /// AltiVec - True if this is for an Altivec vector.
1609 : bool AltiVec;
1610 :
1611 : /// Pixel - True if this is for an Altivec vector pixel.
1612 : bool Pixel;
1613 :
1614 : VectorType(QualType vecType, unsigned nElements, QualType canonType,
1615 186: bool isAltiVec, bool isPixel) :
1616 : Type(Vector, canonType, vecType->isDependentType()),
1617 : ElementType(vecType), NumElements(nElements),
1618 186: AltiVec(isAltiVec), Pixel(isPixel) {}
1619 : VectorType(TypeClass tc, QualType vecType, unsigned nElements,
1620 67: QualType canonType, bool isAltiVec, bool isPixel)
1621 : : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType),
1622 67: NumElements(nElements), AltiVec(isAltiVec), Pixel(isPixel) {}
1623 : friend class ASTContext; // ASTContext creates these.
1624 : public:
1625 :
1626 8483: QualType getElementType() const { return ElementType; }
1627 13139: unsigned getNumElements() const { return NumElements; }
1628 :
1629 1430: bool isSugared() const { return false; }
1630 0: QualType desugar() const { return QualType(this, 0); }
1631 :
1632 15: bool isAltiVec() const { return AltiVec; }
1633 :
1634 8: bool isPixel() const { return Pixel; }
1635 :
1636 2849: void Profile(llvm::FoldingSetNodeID &ID) {
1637 : Profile(ID, getElementType(), getNumElements(), getTypeClass(),
1638 2849: AltiVec, Pixel);
1639 2849: }
1640 : static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
1641 : unsigned NumElements, TypeClass TypeClass,
1642 5674: bool isAltiVec, bool isPixel) {
1643 5674: ID.AddPointer(ElementType.getAsOpaquePtr());
1644 5674: ID.AddInteger(NumElements);
1645 5674: ID.AddInteger(TypeClass);
1646 5674: ID.AddBoolean(isAltiVec);
1647 5674: ID.AddBoolean(isPixel);
1648 5674: }
1649 :
1650 : virtual Linkage getLinkage() const;
1651 :
1652 177466: static bool classof(const Type *T) {
159250: branch 2 taken
18147: branch 4 taken
1264: branch 5 taken
158055: branch 5 taken
1653 177466: return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
1654 : }
1655 : static bool classof(const VectorType *) { return true; }
1656 : };
1657 :
1658 : /// ExtVectorType - Extended vector type. This type is created using
1659 : /// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
1660 : /// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
1661 : /// class enables syntactic extensions, like Vector Components for accessing
1662 : /// points, colors, and textures (modeled after OpenGL Shading Language).
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
67: branch 6 taken
1663 67: class ExtVectorType : public VectorType {
1664 67: ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
1665 67: VectorType(ExtVector, vecType, nElements, canonType, false, false) {}
1666 : friend class ASTContext; // ASTContext creates these.
1667 : public:
1668 469: static int getPointAccessorIdx(char c) {
15: branch 0 taken
193: branch 1 taken
142: branch 2 taken
56: branch 3 taken
63: branch 4 taken
1669 469: switch (c) {
1670 15: default: return -1;
1671 193: case 'x': return 0;
1672 142: case 'y': return 1;
1673 56: case 'z': return 2;
1674 63: case 'w': return 3;
1675 : }
1676 : }
1677 19: static int getNumericAccessorIdx(char c) {
1: branch 0 taken
7: branch 1 taken
5: branch 2 taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 6 not taken
2: branch 7 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
4: branch 16 taken
1678 19: switch (c) {
1679 1: default: return -1;
1680 7: case '0': return 0;
1681 5: case '1': return 1;
1682 0: case '2': return 2;
1683 0: case '3': return 3;
1684 0: case '4': return 4;
1685 0: case '5': return 5;
1686 2: case '6': return 6;
1687 0: case '7': return 7;
1688 0: case '8': return 8;
1689 0: case '9': return 9;
1690 : case 'A':
1691 0: case 'a': return 10;
1692 : case 'B':
1693 0: case 'b': return 11;
1694 : case 'C':
1695 0: case 'c': return 12;
1696 : case 'D':
1697 0: case 'd': return 13;
1698 : case 'E':
1699 0: case 'e': return 14;
1700 : case 'F':
1701 4: case 'f': return 15;
1702 : }
1703 : }
1704 :
1705 279: static int getAccessorIdx(char c) {
271: branch 1 taken
8: branch 2 taken
1706 279: if (int idx = getPointAccessorIdx(c)+1) return idx-1;
1707 8: return getNumericAccessorIdx(c);
1708 : }
1709 :
1710 187: bool isAccessorWithinNumElements(char c) const {
187: branch 1 taken
0: branch 2 not taken
1711 187: if (int idx = getAccessorIdx(c)+1)
1712 187: return unsigned(idx-1) < NumElements;
1713 0: return false;
1714 : }
1715 351: bool isSugared() const { return false; }
1716 0: QualType desugar() const { return QualType(this, 0); }
1717 :
1718 8652: static bool classof(const Type *T) {
1719 8652: return T->getTypeClass() == ExtVector;
1720 : }
1721 : static bool classof(const ExtVectorType *) { return true; }
1722 : };
1723 :
1724 : /// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base
1725 : /// class of FunctionNoProtoType and FunctionProtoType.
1726 : ///
0: branch 1 not taken
19590: branch 2 taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 9 not taken
0: branch 10 not taken
1727 19590: class FunctionType : public Type {
1728 : /// SubClassData - This field is owned by the subclass, put here to pack
1729 : /// tightly with the ivars in Type.
1730 : bool SubClassData : 1;
1731 :
1732 : /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
1733 : /// other bitfields.
1734 : /// The qualifiers are part of FunctionProtoType because...
1735 : ///
1736 : /// C++ 8.3.5p4: The return type, the parameter type list and the
1737 : /// cv-qualifier-seq, [...], are part of the function type.
1738 : ///
1739 : unsigned TypeQuals : 3;
1740 :
1741 : /// NoReturn - Indicates if the function type is attribute noreturn.
1742 : unsigned NoReturn : 1;
1743 :
1744 : /// CallConv - The calling convention used by the function.
1745 : unsigned CallConv : 2;
1746 :
1747 : // The type returned by the function.
1748 : QualType ResultType;
1749 : protected:
1750 : FunctionType(TypeClass tc, QualType res, bool SubclassInfo,
1751 : unsigned typeQuals, QualType Canonical, bool Dependent,
1752 21580: bool noReturn = false, CallingConv callConv = CC_Default)
1753 : : Type(tc, Canonical, Dependent),
1754 : SubClassData(SubclassInfo), TypeQuals(typeQuals), NoReturn(noReturn),
1755 21580: CallConv(callConv), ResultType(res) {}
1756 60093: bool getSubClassData() const { return SubClassData; }
1757 74045: unsigned getTypeQuals() const { return TypeQuals; }
1758 : public:
1759 :
1760 230628: QualType getResultType() const { return ResultType; }
1761 68627: bool getNoReturnAttr() const { return NoReturn; }
1762 58818: CallingConv getCallConv() const { return (CallingConv)CallConv; }
1763 :
1764 : static llvm::StringRef getNameForCallConv(CallingConv CC);
1765 :
1766 1240197: static bool classof(const Type *T) {
1767 : return T->getTypeClass() == FunctionNoProto ||
1156333: branch 1 taken
83864: branch 2 taken
806877: branch 4 taken
349456: branch 5 taken
1768 1240197: T->getTypeClass() == FunctionProto;
1769 : }
1770 : static bool classof(const FunctionType *) { return true; }
1771 : };
1772 :
1773 : /// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
1774 : /// no information available about its arguments.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
1027: branch 6 taken
1775 1027: class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
1776 : FunctionNoProtoType(QualType Result, QualType Canonical,
1777 1084: bool NoReturn = false, CallingConv CallConv = CC_Default)
1778 : : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
1779 1084: /*Dependent=*/false, NoReturn, CallConv) {}
1780 : friend class ASTContext; // ASTContext creates these.
1781 : public:
1782 : // No additional state past what FunctionType provides.
1783 :
1784 77: bool isSugared() const { return false; }
1785 0: QualType desugar() const { return QualType(this, 0); }
1786 :
1787 1570: void Profile(llvm::FoldingSetNodeID &ID) {
1788 1570: Profile(ID, getResultType(), getNoReturnAttr(), getCallConv());
1789 1570: }
1790 : static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
1791 4096: bool NoReturn, CallingConv CallConv) {
1792 4096: ID.AddInteger(CallConv);
1793 4096: ID.AddInteger(NoReturn);
1794 4096: ID.AddPointer(ResultType.getAsOpaquePtr());
1795 4096: }
1796 :
1797 : virtual Linkage getLinkage() const;
1798 :
1799 220958: static bool classof(const Type *T) {
1800 220958: return T->getTypeClass() == FunctionNoProto;
1801 : }
1802 : static bool classof(const FunctionNoProtoType *) { return true; }
1803 : };
1804 :
1805 : /// FunctionProtoType - Represents a prototype with argument type info, e.g.
1806 : /// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
1807 : /// arguments, not as having a single void argument. Such a type can have an
1808 : /// exception specification, but this specification is not part of the canonical
1809 : /// type.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
18563: branch 6 taken
1810 18563: class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
1811 : /// hasAnyDependentType - Determine whether there are any dependent
1812 : /// types within the arguments passed in.
1813 20060: static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) {
23248: branch 0 taken
19246: branch 1 taken
1814 42494: for (unsigned Idx = 0; Idx < numArgs; ++Idx)
814: branch 2 taken
22434: branch 3 taken
1815 23248: if (ArgArray[Idx]->isDependentType())
1816 814: return true;
1817 :
1818 19246: return false;
1819 : }
1820 :
1821 : FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs,
1822 : bool isVariadic, unsigned typeQuals, bool hasExs,
1823 : bool hasAnyExs, const QualType *ExArray,
1824 : unsigned numExs, QualType Canonical, bool NoReturn,
1825 20496: CallingConv CallConv)
1826 : : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical,
1827 : (Result->isDependentType() ||
1828 : hasAnyDependentType(ArgArray, numArgs)), NoReturn,
1829 : CallConv),
1830 : NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs),
20060: branch 2 taken
436: branch 3 taken
814: branch 5 taken
19246: branch 6 taken
1831 20496: AnyExceptionSpec(hasAnyExs) {
1832 : // Fill in the trailing argument array.
1833 20496: QualType *ArgInfo = reinterpret_cast<QualType*>(this+1);
23830: branch 0 taken
20496: branch 1 taken
1834 44326: for (unsigned i = 0; i != numArgs; ++i)
1835 23830: ArgInfo[i] = ArgArray[i];
1836 : // Fill in the exception array.
1837 20496: QualType *Ex = ArgInfo + numArgs;
103: branch 0 taken
20496: branch 1 taken
1838 20599: for (unsigned i = 0; i != numExs; ++i)
1839 103: Ex[i] = ExArray[i];
1840 20496: }
1841 :
1842 : /// NumArgs - The number of arguments this function has, not counting '...'.
1843 : unsigned NumArgs : 20;
1844 :
1845 : /// NumExceptions - The number of types in the exception spec, if any.
1846 : unsigned NumExceptions : 10;
1847 :
1848 : /// HasExceptionSpec - Whether this function has an exception spec at all.
1849 : bool HasExceptionSpec : 1;
1850 :
1851 : /// AnyExceptionSpec - Whether this function has a throw(...) spec.
1852 : bool AnyExceptionSpec : 1;
1853 :
1854 : /// ArgInfo - There is an variable size array after the class in memory that
1855 : /// holds the argument types.
1856 :
1857 : /// Exceptions - There is another variable size array after ArgInfo that
1858 : /// holds the exception types.
1859 :
1860 : friend class ASTContext; // ASTContext creates these.
1861 :
1862 : public:
1863 245832: unsigned getNumArgs() const { return NumArgs; }
1864 25836: QualType getArgType(unsigned i) const {
0: branch 0 not taken
25836: branch 1 taken
1865 25836: assert(i < NumArgs && "Invalid argument number!");
1866 25836: return arg_type_begin()[i];
1867 : }
1868 :
1869 42794: bool hasExceptionSpec() const { return HasExceptionSpec; }
1870 38294: bool hasAnyExceptionSpec() const { return AnyExceptionSpec; }
1871 37142: unsigned getNumExceptions() const { return NumExceptions; }
1872 9: QualType getExceptionType(unsigned i) const {
0: branch 0 not taken
9: branch 1 taken
1873 9: assert(i < NumExceptions && "Invalid exception number!");
1874 9: return exception_begin()[i];
1875 : }
1876 2637: bool hasEmptyExceptionSpec() const {
1877 : return hasExceptionSpec() && !hasAnyExceptionSpec() &&
58: branch 1 taken
2579: branch 2 taken
58: branch 4 taken
0: branch 5 not taken
14: branch 7 taken
44: branch 8 taken
1878 2637: getNumExceptions() == 0;
1879 : }
1880 :
1881 60093: bool isVariadic() const { return getSubClassData(); }
1882 74045: unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
1883 :
1884 : typedef const QualType *arg_type_iterator;
1885 116677: arg_type_iterator arg_type_begin() const {
1886 116677: return reinterpret_cast<const QualType *>(this+1);
1887 : }
1888 44788: arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
1889 :
1890 : typedef const QualType *exception_iterator;
1891 37134: exception_iterator exception_begin() const {
1892 : // exceptions begin where arguments end
1893 37134: return arg_type_end();
1894 : }
1895 79: exception_iterator exception_end() const {
1896 79: return exception_begin() + NumExceptions;
1897 : }
1898 :
1899 317: bool isSugared() const { return false; }
1900 0: QualType desugar() const { return QualType(this, 0); }
1901 :
1902 : virtual Linkage getLinkage() const;
1903 :
1904 386082: static bool classof(const Type *T) {
1905 386082: return T->getTypeClass() == FunctionProto;
1906 : }
1907 : static bool classof(const FunctionProtoType *) { return true; }
1908 :
1909 : void Profile(llvm::FoldingSetNodeID &ID);
1910 : static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
1911 : arg_type_iterator ArgTys, unsigned NumArgs,
1912 : bool isVariadic, unsigned TypeQuals,
1913 : bool hasExceptionSpec, bool anyExceptionSpec,
1914 : unsigned NumExceptions, exception_iterator Exs,
1915 : bool NoReturn, CallingConv CallConv);
1916 : };
1917 :
1918 :
1919 : /// \brief Represents the dependent type named by a dependently-scoped
1920 : /// typename using declaration, e.g.
1921 : /// using typename Base<T>::foo;
1922 : /// Template instantiation turns these into the underlying type.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
1: branch 6 taken
1923 1: class UnresolvedUsingType : public Type {
1924 : UnresolvedUsingTypenameDecl *Decl;
1925 :
1926 1: UnresolvedUsingType(UnresolvedUsingTypenameDecl *D)
1927 1: : Type(UnresolvedUsing, QualType(), true), Decl(D) {}
1928 : friend class ASTContext; // ASTContext creates these.
1929 : public:
1930 :
1931 2: UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
1932 :
1933 0: bool isSugared() const { return false; }
1934 0: QualType desugar() const { return QualType(this, 0); }
1935 :
1936 1: static bool classof(const Type *T) {
1937 1: return T->getTypeClass() == UnresolvedUsing;
1938 : }
1939 : static bool classof(const UnresolvedUsingType *) { return true; }
1940 :
1941 : void Profile(llvm::FoldingSetNodeID &ID) {
1942 : return Profile(ID, Decl);
1943 : }
1944 : static void Profile(llvm::FoldingSetNodeID &ID,
1945 : UnresolvedUsingTypenameDecl *D) {
1946 : ID.AddPointer(D);
1947 : }
1948 : };
1949 :
1950 :
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
4298: branch 6 taken
1951 4298: class TypedefType : public Type {
1952 : TypedefDecl *Decl;
1953 : protected:
1954 4839: TypedefType(TypeClass tc, TypedefDecl *D, QualType can)
1955 4839: : Type(tc, can, can->isDependentType()), Decl(D) {
4839: branch 1 taken
0: branch 2 not taken
1956 4839: assert(!isa<TypedefType>(can) && "Invalid canonical type");
1957 4839: }
1958 : friend class ASTContext; // ASTContext creates these.
1959 : public:
1960 :
1961 24970: TypedefDecl *getDecl() const { return Decl; }
1962 :
1963 : /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
1964 : /// potentially looking through *all* consecutive typedefs. This returns the
1965 : /// sum of the type qualifiers, so if you have:
1966 : /// typedef const int A;
1967 : /// typedef volatile A B;
1968 : /// looking through the typedefs for B will give you "const volatile A".
1969 : QualType LookThroughTypedefs() const;
1970 :
1971 15552: bool isSugared() const { return true; }
1972 : QualType desugar() const;
1973 :
1974 33835: static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
1975 : static bool classof(const TypedefType *) { return true; }
1976 : };
1977 :
1978 : /// TypeOfExprType (GCC extension).
0: branch 1 not taken
4: branch 2 taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 9 not taken
256: branch 10 taken
1979 260: class TypeOfExprType : public Type {
1980 : Expr *TOExpr;
1981 :
1982 : protected:
1983 : TypeOfExprType(Expr *E, QualType can = QualType());
1984 : friend class ASTContext; // ASTContext creates these.
1985 : public:
1986 250: Expr *getUnderlyingExpr() const { return TOExpr; }
1987 :
1988 : /// \brief Remove a single level of sugar.
1989 : QualType desugar() const;
1990 :
1991 : /// \brief Returns whether this type directly provides sugar.
1992 157: bool isSugared() const { return true; }
1993 :
1994 263: static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
1995 : static bool classof(const TypeOfExprType *) { return true; }
1996 : };
1997 :
1998 : /// Subclass of TypeOfExprType that is used for canonical, dependent
1999 : /// typeof(expr) types.
2000 : class DependentTypeOfExprType
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
4: branch 6 taken
2001 4: : public TypeOfExprType, public llvm::FoldingSetNode {
2002 : ASTContext &Context;
2003 :
2004 : public:
2005 4: DependentTypeOfExprType(ASTContext &Context, Expr *E)
2006 4: : TypeOfExprType(E), Context(Context) { }
2007 :
2008 : bool isSugared() const { return false; }
2009 : QualType desugar() const { return QualType(this, 0); }
2010 :
2011 3: void Profile(llvm::FoldingSetNodeID &ID) {
2012 3: Profile(ID, Context, getUnderlyingExpr());
2013 3: }
2014 :
2015 : static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
2016 : Expr *E);
2017 : };
2018 :
2019 : /// TypeOfType (GCC extension).
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
23: branch 6 taken
2020 23: class TypeOfType : public Type {
2021 : QualType TOType;
2022 23: TypeOfType(QualType T, QualType can)
2023 23: : Type(TypeOf, can, T->isDependentType()), TOType(T) {
23: branch 1 taken
0: branch 2 not taken
2024 23: assert(!isa<TypedefType>(can) && "Invalid canonical type");
2025 23: }
2026 : friend class ASTContext; // ASTContext creates these.
2027 : public:
2028 39: QualType getUnderlyingType() const { return TOType; }
2029 :
2030 : /// \brief Remove a single level of sugar.
2031 28: QualType desugar() const { return getUnderlyingType(); }
2032 :
2033 : /// \brief Returns whether this type directly provides sugar.
2034 28: bool isSugared() const { return true; }
2035 :
2036 39: static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
2037 : static bool classof(const TypeOfType *) { return true; }
2038 : };
2039 :
2040 : /// DecltypeType (C++0x)
0: branch 1 not taken
5: branch 2 taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 9 not taken
11: branch 10 taken
2041 16: class DecltypeType : public Type {
2042 : Expr *E;
2043 :
2044 : // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
2045 : // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
2046 : // from it.
2047 : QualType UnderlyingType;
2048 :
2049 : protected:
2050 : DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
2051 : friend class ASTContext; // ASTContext creates these.
2052 : public:
2053 5: Expr *getUnderlyingExpr() const { return E; }
2054 3: QualType getUnderlyingType() const { return UnderlyingType; }
2055 :
2056 : /// \brief Remove a single level of sugar.
2057 3: QualType desugar() const { return getUnderlyingType(); }
2058 :
2059 : /// \brief Returns whether this type directly provides sugar.
2060 3: bool isSugared() const { return !isDependentType(); }
2061 :
2062 5: static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
2063 : static bool classof(const DecltypeType *) { return true; }
2064 : };
2065 :
2066 : /// Subclass of DecltypeType that is used for canonical, dependent
2067 : /// C++0x decltype types.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
5: branch 6 taken
2068 5: class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
2069 : ASTContext &Context;
2070 :
2071 : public:
2072 : DependentDecltypeType(ASTContext &Context, Expr *E);
2073 :
2074 : bool isSugared() const { return false; }
2075 : QualType desugar() const { return QualType(this, 0); }
2076 :
2077 1: void Profile(llvm::FoldingSetNodeID &ID) {
2078 1: Profile(ID, Context, getUnderlyingExpr());
2079 1: }
2080 :
2081 : static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
2082 : Expr *E);
2083 : };
2084 :
0: branch 1 not taken
8017: branch 2 taken
0: branch 5 not taken
0: branch 6 not taken
2085 8017: class TagType : public Type {
2086 : /// Stores the TagDecl associated with this type. The decl will
2087 : /// point to the TagDecl that actually defines the entity (or is a
2088 : /// definition in progress), if there is such a definition. The
2089 : /// single-bit value will be non-zero when this tag is in the
2090 : /// process of being defined.
2091 : mutable llvm::PointerIntPair<TagDecl *, 1> decl;
2092 : friend class ASTContext;
2093 : friend class TagDecl;
2094 :
2095 : protected:
2096 : TagType(TypeClass TC, TagDecl *D, QualType can);
2097 :
2098 : public:
2099 797093: TagDecl *getDecl() const { return decl.getPointer(); }
2100 :
2101 : /// @brief Determines whether this type is in the process of being
2102 : /// defined.
2103 98526: bool isBeingDefined() const { return decl.getInt(); }
2104 : void setBeingDefined(bool Def) const { decl.setInt(Def? 1 : 0); }
2105 :
2106 : virtual Linkage getLinkage() const;
2107 :
2108 1786954: static bool classof(const Type *T) {
1179434: branch 2 taken
607520: branch 4 taken
1112039: branch 5 taken
67395: branch 5 taken
2109 1786954: return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
2110 : }
2111 : static bool classof(const TagType *) { return true; }
2112 : static bool classof(const RecordType *) { return true; }
2113 : static bool classof(const EnumType *) { return true; }
2114 : };
2115 :
2116 : /// RecordType - This is a helper class that allows the use of isa/cast/dyncast
2117 : /// to detect TagType objects of structs/unions/classes.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
7340: branch 6 taken
2118 7340: class RecordType : public TagType {
2119 : protected:
2120 7574: explicit RecordType(RecordDecl *D)
2121 7574: : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { }
2122 : explicit RecordType(TypeClass TC, RecordDecl *D)
2123 : : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { }
2124 : friend class ASTContext; // ASTContext creates these.
2125 : public:
2126 :
2127 97063: RecordDecl *getDecl() const {
2128 97063: return reinterpret_cast<RecordDecl*>(TagType::getDecl());
2129 : }
2130 :
2131 : // FIXME: This predicate is a helper to QualType/Type. It needs to
2132 : // recursively check all fields for const-ness. If any field is declared
2133 : // const, it needs to return false.
2134 54: bool hasConstFields() const { return false; }
2135 :
2136 : // FIXME: RecordType needs to check when it is created that all fields are in
2137 : // the same address space, and return that.
2138 15709: unsigned getAddressSpace() const { return 0; }
2139 :
2140 22102: bool isSugared() const { return false; }
2141 0: QualType desugar() const { return QualType(this, 0); }
2142 :
2143 : static bool classof(const TagType *T);
2144 776711: static bool classof(const Type *T) {
429841: branch 2 taken
333496: branch 5 taken
13374: branch 6 taken
0: branch 6 not taken
2145 776711: return isa<TagType>(T) && classof(cast<TagType>(T));
2146 : }
2147 : static bool classof(const RecordType *) { return true; }
2148 : };
2149 :
2150 : /// EnumType - This is a helper class that allows the use of isa/cast/dyncast
2151 : /// to detect TagType objects of enums.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
677: branch 6 taken
2152 677: class EnumType : public TagType {
2153 685: explicit EnumType(EnumDecl *D)
2154 685: : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { }
2155 : friend class ASTContext; // ASTContext creates these.
2156 : public:
2157 :
2158 23041: EnumDecl *getDecl() const {
2159 23041: return reinterpret_cast<EnumDecl*>(TagType::getDecl());
2160 : }
2161 :
2162 22: bool isSugared() const { return false; }
2163 0: QualType desugar() const { return QualType(this, 0); }
2164 :
2165 : static bool classof(const TagType *T);
2166 151701: static bool classof(const Type *T) {
115711: branch 2 taken
34995: branch 5 taken
995: branch 6 taken
0: branch 6 not taken
2167 151701: return isa<TagType>(T) && classof(cast<TagType>(T));
2168 : }
2169 : static bool classof(const EnumType *) { return true; }
2170 : };
2171 :
2172 : /// ElaboratedType - A non-canonical type used to represents uses of
2173 : /// elaborated type specifiers in C++. For example:
2174 : ///
2175 : /// void foo(union MyUnion);
2176 : /// ^^^^^^^^^^^^^
2177 : ///
2178 : /// At the moment, for efficiency we do not create elaborated types in
2179 : /// C, since outside of typedefs all references to structs would
2180 : /// necessarily be elaborated.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
381: branch 6 taken
2181 381: class ElaboratedType : public Type, public llvm::FoldingSetNode {
2182 : public:
2183 : enum TagKind {
2184 : TK_struct,
2185 : TK_union,
2186 : TK_class,
2187 : TK_enum
2188 : };
2189 :
2190 : private:
2191 : /// The tag that was used in this elaborated type specifier.
2192 : TagKind Tag;
2193 :
2194 : /// The underlying type.
2195 : QualType UnderlyingType;
2196 :
2197 441: explicit ElaboratedType(QualType Ty, TagKind Tag, QualType Canon)
2198 : : Type(Elaborated, Canon, Canon->isDependentType()),
2199 441: Tag(Tag), UnderlyingType(Ty) { }
2200 : friend class ASTContext; // ASTContext creates these.
2201 :
2202 : public:
2203 125: TagKind getTagKind() const { return Tag; }
2204 1415: QualType getUnderlyingType() const { return UnderlyingType; }
2205 :
2206 : /// \brief Remove a single level of sugar.
2207 1193: QualType desugar() const { return getUnderlyingType(); }
2208 :
2209 : /// \brief Returns whether this type directly provides sugar.
2210 1178: bool isSugared() const { return true; }
2211 :
2212 3137: static const char *getNameForTagKind(TagKind Kind) {
0: branch 0 not taken
2627: branch 1 taken
57: branch 2 taken
390: branch 3 taken
63: branch 4 taken
2213 3137: switch (Kind) {
2214 0: default: assert(0 && "Unknown TagKind!");
2215 2627: case TK_struct: return "struct";
2216 57: case TK_union: return "union";
2217 390: case TK_class: return "class";
2218 63: case TK_enum: return "enum";
2219 : }
2220 : }
2221 :
2222 73: void Profile(llvm::FoldingSetNodeID &ID) {
2223 73: Profile(ID, getUnderlyingType(), getTagKind());
2224 73: }
2225 565: static void Profile(llvm::FoldingSetNodeID &ID, QualType T, TagKind Tag) {
2226 565: ID.AddPointer(T.getAsOpaquePtr());
2227 565: ID.AddInteger(Tag);
2228 565: }
2229 :
2230 : static bool classof(const ElaboratedType*) { return true; }
2231 4615: static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; }
2232 : };
2233 :
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
1188: branch 6 taken
2234 1188: class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
2235 : unsigned Depth : 15;
2236 : unsigned Index : 16;
2237 : unsigned ParameterPack : 1;
2238 : IdentifierInfo *Name;
2239 :
2240 : TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N,
2241 658: QualType Canon)
2242 : : Type(TemplateTypeParm, Canon, /*Dependent=*/true),
2243 658: Depth(D), Index(I), ParameterPack(PP), Name(N) { }
2244 :
2245 535: TemplateTypeParmType(unsigned D, unsigned I, bool PP)
2246 : : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true),
2247 535: Depth(D), Index(I), ParameterPack(PP), Name(0) { }
2248 :
2249 : friend class ASTContext; // ASTContext creates these
2250 :
2251 : public:
2252 12879: unsigned getDepth() const { return Depth; }
2253 10189: unsigned getIndex() const { return Index; }
2254 68: bool isParameterPack() const { return ParameterPack; }
2255 270: IdentifierInfo *getName() const { return Name; }
2256 :
2257 1: bool isSugared() const { return false; }
2258 0: QualType desugar() const { return QualType(this, 0); }
2259 :
2260 1543: void Profile(llvm::FoldingSetNodeID &ID) {
2261 1543: Profile(ID, Depth, Index, ParameterPack, Name);
2262 1543: }
2263 :
2264 : static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
2265 : unsigned Index, bool ParameterPack,
2266 4137: IdentifierInfo *Name) {
2267 4137: ID.AddInteger(Depth);
2268 4137: ID.AddInteger(Index);
2269 4137: ID.AddBoolean(ParameterPack);
2270 4137: ID.AddPointer(Name);
2271 4137: }
2272 :
2273 7754: static bool classof(const Type *T) {
2274 7754: return T->getTypeClass() == TemplateTypeParm;
2275 : }
2276 : static bool classof(const TemplateTypeParmType *T) { return true; }
2277 : };
2278 :
2279 : /// \brief Represents the result of substituting a type for a template
2280 : /// type parameter.
2281 : ///
2282 : /// Within an instantiated template, all template type parameters have
2283 : /// been replaced with these. They are used solely to record that a
2284 : /// type was originally written as a template type parameter;
2285 : /// therefore they are never canonical.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
907: branch 6 taken
2286 907: class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
2287 : // The original type parameter.
2288 : const TemplateTypeParmType *Replaced;
2289 :
2290 911: SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
2291 : : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType()),
2292 911: Replaced(Param) { }
2293 :
2294 : friend class ASTContext;
2295 :
2296 : public:
2297 : IdentifierInfo *getName() const { return Replaced->getName(); }
2298 :
2299 : /// Gets the template parameter that was substituted for.
2300 1884: const TemplateTypeParmType *getReplacedParameter() const {
2301 1884: return Replaced;
2302 : }
2303 :
2304 : /// Gets the type that was substituted for the template
2305 : /// parameter.
2306 6639: QualType getReplacementType() const {
2307 6639: return getCanonicalTypeInternal();
2308 : }
2309 :
2310 4281: bool isSugared() const { return true; }
2311 4436: QualType desugar() const { return getReplacementType(); }
2312 :
2313 1884: void Profile(llvm::FoldingSetNodeID &ID) {
2314 1884: Profile(ID, getReplacedParameter(), getReplacementType());
2315 1884: }
2316 : static void Profile(llvm::FoldingSetNodeID &ID,
2317 : const TemplateTypeParmType *Replaced,
2318 4581: QualType Replacement) {
2319 4581: ID.AddPointer(Replaced);
2320 4581: ID.AddPointer(Replacement.getAsOpaquePtr());
2321 4581: }
2322 :
2323 7972: static bool classof(const Type *T) {
2324 7972: return T->getTypeClass() == SubstTemplateTypeParm;
2325 : }
2326 : static bool classof(const SubstTemplateTypeParmType *T) { return true; }
2327 : };
2328 :
2329 : /// \brief Represents the type of a template specialization as written
2330 : /// in the source code.
2331 : ///
2332 : /// Template specialization types represent the syntactic form of a
2333 : /// template-id that refers to a type, e.g., @c vector<int>. Some
2334 : /// template specialization types are syntactic sugar, whose canonical
2335 : /// type will point to some other type node that represents the
2336 : /// instantiation or class template specialization. For example, a
2337 : /// class template specialization type of @c vector<int> will refer to
2338 : /// a tag type for the instantiation
2339 : /// @c std::vector<int, std::allocator<int>>.
2340 : ///
2341 : /// Other template specialization types, for which the template name
2342 : /// is dependent, may be canonical types. These types are always
2343 : /// dependent.
2344 : class TemplateSpecializationType
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
2345 0: : public Type, public llvm::FoldingSetNode {
2346 :
2347 : // FIXME: Currently needed for profiling expressions; can we avoid this?
2348 : ASTContext &Context;
2349 :
2350 : /// \brief The name of the template being specialized.
2351 : TemplateName Template;
2352 :
2353 : /// \brief - The number of template arguments named in this class
2354 : /// template specialization.
2355 : unsigned NumArgs;
2356 :
2357 : TemplateSpecializationType(ASTContext &Context,
2358 : TemplateName T,
2359 : const TemplateArgument *Args,
2360 : unsigned NumArgs, QualType Canon);
2361 :
2362 : virtual void Destroy(ASTContext& C);
2363 :
2364 : friend class ASTContext; // ASTContext creates these
2365 :
2366 : public:
2367 : /// \brief Determine whether any of the given template arguments are
2368 : /// dependent.
2369 : static bool anyDependentTemplateArguments(const TemplateArgument *Args,
2370 : unsigned NumArgs);
2371 :
2372 : static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
2373 : unsigned NumArgs);
2374 :
2375 : static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
2376 :
2377 : /// \brief Print a template argument list, including the '<' and '>'
2378 : /// enclosing the template arguments.
2379 : static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
2380 : unsigned NumArgs,
2381 : const PrintingPolicy &Policy);
2382 :
2383 : static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
2384 : unsigned NumArgs,
2385 : const PrintingPolicy &Policy);
2386 :
2387 : static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
2388 : const PrintingPolicy &Policy);
2389 :
2390 : typedef const TemplateArgument * iterator;
2391 :
2392 0: iterator begin() const { return getArgs(); }
2393 : iterator end() const;
2394 :
2395 : /// \brief Retrieve the name of the template that we are specializing.
2396 2451: TemplateName getTemplateName() const { return Template; }
2397 :
2398 : /// \brief Retrieve the template arguments.
2399 8484: const TemplateArgument *getArgs() const {
2400 8484: return reinterpret_cast<const TemplateArgument *>(this + 1);
2401 : }
2402 :
2403 : /// \brief Retrieve the number of template arguments.
2404 22282: unsigned getNumArgs() const { return NumArgs; }
2405 :
2406 : /// \brief Retrieve a specific template argument as a type.
2407 : /// \precondition @c isArgType(Arg)
2408 : const TemplateArgument &getArg(unsigned Idx) const;
2409 :
2410 13003: bool isSugared() const { return !isDependentType(); }
2411 13006: QualType desugar() const { return getCanonicalTypeInternal(); }
2412 :
2413 427: void Profile(llvm::FoldingSetNodeID &ID) {
2414 427: Profile(ID, Template, getArgs(), NumArgs, Context);
2415 427: }
2416 :
2417 : static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
2418 : const TemplateArgument *Args, unsigned NumArgs,
2419 : ASTContext &Context);
2420 :
2421 40895: static bool classof(const Type *T) {
2422 40895: return T->getTypeClass() == TemplateSpecialization;
2423 : }
2424 : static bool classof(const TemplateSpecializationType *T) { return true; }
2425 : };
2426 :
2427 : /// \brief Represents a type that was referred to via a qualified
2428 : /// name, e.g., N::M::type.
2429 : ///
2430 : /// This type is used to keep track of a type name as written in the
2431 : /// source code, including any nested-name-specifiers. The type itself
2432 : /// is always "sugar", used to express what was written in the source
2433 : /// code but containing no additional semantic information.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
431: branch 6 taken
2434 431: class QualifiedNameType : public Type, public llvm::FoldingSetNode {
2435 : /// \brief The nested name specifier containing the qualifier.
2436 : NestedNameSpecifier *NNS;
2437 :
2438 : /// \brief The type that this qualified name refers to.
2439 : QualType NamedType;
2440 :
2441 : QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType,
2442 435: QualType CanonType)
2443 : : Type(QualifiedName, CanonType, NamedType->isDependentType()),
2444 435: NNS(NNS), NamedType(NamedType) { }
2445 :
2446 : friend class ASTContext; // ASTContext creates these
2447 :
2448 : public:
2449 : /// \brief Retrieve the qualification on this type.
2450 33: NestedNameSpecifier *getQualifier() const { return NNS; }
2451 :
2452 : /// \brief Retrieve the type named by the qualified-id.
2453 2221: QualType getNamedType() const { return NamedType; }
2454 :
2455 : /// \brief Remove a single level of sugar.
2456 2151: QualType desugar() const { return getNamedType(); }
2457 :
2458 : /// \brief Returns whether this type directly provides sugar.
2459 2124: bool isSugared() const { return true; }
2460 :
2461 209: void Profile(llvm::FoldingSetNodeID &ID) {
2462 209: Profile(ID, NNS, NamedType);
2463 209: }
2464 :
2465 : static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
2466 761: QualType NamedType) {
2467 761: ID.AddPointer(NNS);
2468 761: NamedType.Profile(ID);
2469 761: }
2470 :
2471 5530: static bool classof(const Type *T) {
2472 5530: return T->getTypeClass() == QualifiedName;
2473 : }
2474 : static bool classof(const QualifiedNameType *T) { return true; }
2475 : };
2476 :
2477 : /// \brief Represents a 'typename' specifier that names a type within
2478 : /// a dependent type, e.g., "typename T::type".
2479 : ///
2480 : /// TypenameType has a very similar structure to QualifiedNameType,
2481 : /// which also involves a nested-name-specifier following by a type,
2482 : /// and (FIXME!) both can even be prefixed by the 'typename'
2483 : /// keyword. However, the two types serve very different roles:
2484 : /// QualifiedNameType is a non-semantic type that serves only as sugar
2485 : /// to show how a particular type was written in the source
2486 : /// code. TypenameType, on the other hand, only occurs when the
2487 : /// nested-name-specifier is dependent, such that we cannot resolve
2488 : /// the actual type until after instantiation.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
175: branch 6 taken
2489 175: class TypenameType : public Type, public llvm::FoldingSetNode {
2490 : /// \brief The nested name specifier containing the qualifier.
2491 : NestedNameSpecifier *NNS;
2492 :
2493 : typedef llvm::PointerUnion<const IdentifierInfo *,
2494 : const TemplateSpecializationType *> NameType;
2495 :
2496 : /// \brief The type that this typename specifier refers to.
2497 : NameType Name;
2498 :
2499 : TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name,
2500 147: QualType CanonType)
2501 147: : Type(Typename, CanonType, true), NNS(NNS), Name(Name) {
2502 : assert(NNS->isDependent() &&
147: branch 1 taken
0: branch 2 not taken
2503 147: "TypenameType requires a dependent nested-name-specifier");
2504 147: }
2505 :
2506 : TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty,
2507 28: QualType CanonType)
2508 28: : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) {
2509 : assert(NNS->isDependent() &&
28: branch 1 taken
0: branch 2 not taken
2510 28: "TypenameType requires a dependent nested-name-specifier");
2511 28: }
2512 :
2513 : friend class ASTContext; // ASTContext creates these
2514 :
2515 : public:
2516 : /// \brief Retrieve the qualification on this type.
2517 170: NestedNameSpecifier *getQualifier() const { return NNS; }
2518 :
2519 : /// \brief Retrieve the type named by the typename specifier as an
2520 : /// identifier.
2521 : ///
2522 : /// This routine will return a non-NULL identifier pointer when the
2523 : /// form of the original typename was terminated by an identifier,
2524 : /// e.g., "typename T::type".
2525 149: const IdentifierInfo *getIdentifier() const {
2526 149: return Name.dyn_cast<const IdentifierInfo *>();
2527 : }
2528 :
2529 : /// \brief Retrieve the type named by the typename specifier as a
2530 : /// type specialization.
2531 138: const TemplateSpecializationType *getTemplateId() const {
2532 138: return Name.dyn_cast<const TemplateSpecializationType *>();
2533 : }
2534 :
2535 0: bool isSugared() const { return false; }
2536 0: QualType desugar() const { return QualType(this, 0); }
2537 :
2538 38: void Profile(llvm::FoldingSetNodeID &ID) {
2539 38: Profile(ID, NNS, Name);
2540 38: }
2541 :
2542 : static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
2543 239: NameType Name) {
2544 239: ID.AddPointer(NNS);
2545 239: ID.AddPointer(Name.getOpaqueValue());
2546 239: }
2547 :
2548 145: static bool classof(const Type *T) {
2549 145: return T->getTypeClass() == Typename;
2550 : }
2551 : static bool classof(const TypenameType *T) { return true; }
2552 : };
2553 :
2554 : /// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
2555 : /// object oriented design. They basically correspond to C++ classes. There
2556 : /// are two kinds of interface types, normal interfaces like "NSString" and
2557 : /// qualified interfaces, which are qualified with a protocol list like
2558 : /// "NSString<NSCopyable, NSAmazing>".
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
1856: branch 6 taken
2559 1856: class ObjCInterfaceType : public Type, public llvm::FoldingSetNode {
2560 : ObjCInterfaceDecl *Decl;
2561 :
2562 : /// \brief The number of protocols stored after the ObjCInterfaceType node.
2563 : /// The list of protocols is sorted on protocol name. No protocol is enterred
2564 : /// more than once.
2565 : unsigned NumProtocols;
2566 :
2567 : ObjCInterfaceType(QualType Canonical, ObjCInterfaceDecl *D,
2568 : ObjCProtocolDecl **Protos, unsigned NumP);
2569 : friend class ASTContext; // ASTContext creates these.
2570 : public:
2571 : void Destroy(ASTContext& C);
2572 :
2573 6419: ObjCInterfaceDecl *getDecl() const { return Decl; }
2574 :
2575 : /// getNumProtocols - Return the number of qualifying protocols in this
2576 : /// interface type, or 0 if there are none.
2577 9544: unsigned getNumProtocols() const { return NumProtocols; }
2578 :
2579 : /// qual_iterator and friends: this provides access to the (potentially empty)
2580 : /// list of protocols qualifying this interface.
2581 : typedef ObjCProtocolDecl* const * qual_iterator;
2582 4839: qual_iterator qual_begin() const {
2583 4839: return reinterpret_cast<qual_iterator>(this + 1);
2584 : }
2585 65: qual_iterator qual_end() const {
2586 65: return qual_begin() + NumProtocols;
2587 : }
2588 : bool qual_empty() const { return NumProtocols == 0; }
2589 :
2590 28: bool isSugared() const { return false; }
2591 0: QualType desugar() const { return QualType(this, 0); }
2592 :
2593 : void Profile(llvm::FoldingSetNodeID &ID);
2594 : static void Profile(llvm::FoldingSetNodeID &ID,
2595 : const ObjCInterfaceDecl *Decl,
2596 : ObjCProtocolDecl * const *protocols,
2597 : unsigned NumProtocols);
2598 :
2599 : virtual Linkage getLinkage() const;
2600 :
2601 97376: static bool classof(const Type *T) {
2602 97376: return T->getTypeClass() == ObjCInterface;
2603 : }
2604 : static bool classof(const ObjCInterfaceType *) { return true; }
2605 : };
2606 :
2607 : /// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>',
2608 : /// and 'Interface <p> *'.
2609 : ///
2610 : /// Duplicate protocols are removed and protocol list is canonicalized to be in
2611 : /// alphabetical order.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
2510: branch 6 taken
2612 2510: class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
2613 : QualType PointeeType; // A builtin or interface type.
2614 :
2615 : /// \brief The number of protocols stored after the ObjCObjectPointerType
2616 : /// node.
2617 : ///
2618 : /// The list of protocols is sorted on protocol name. No protocol is enterred
2619 : /// more than once.
2620 : unsigned NumProtocols;
2621 :
2622 : ObjCObjectPointerType(QualType Canonical, QualType T,
2623 : ObjCProtocolDecl **Protos, unsigned NumP);
2624 : friend class ASTContext; // ASTContext creates these.
2625 :
2626 : public:
2627 : void Destroy(ASTContext& C);
2628 :
2629 : // Get the pointee type. Pointee will either be:
2630 : // - a built-in type (for 'id' and 'Class').
2631 : // - an interface type (for user-defined types).
2632 : // - a TypedefType whose canonical type is an interface (as in 'T' below).
2633 : // For example: typedef NSObject T; T *var;
2634 32082: QualType getPointeeType() const { return PointeeType; }
2635 :
2636 6984: const ObjCInterfaceType *getInterfaceType() const {
2637 6984: return PointeeType->getAs<ObjCInterfaceType>();
2638 : }
2639 : /// getInterfaceDecl - returns an interface decl for user-defined types.
2640 2580: ObjCInterfaceDecl *getInterfaceDecl() const {
1772: branch 1 taken
808: branch 2 taken
2641 2580: return getInterfaceType() ? getInterfaceType()->getDecl() : 0;
2642 : }
2643 : /// isObjCIdType - true for "id".
2644 6645: bool isObjCIdType() const {
2645 : return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) &&
3424: branch 3 taken
3221: branch 4 taken
2537: branch 5 taken
887: branch 6 taken
2646 6645: !NumProtocols;
2647 : }
2648 : /// isObjCClassType - true for "Class".
2649 5171: bool isObjCClassType() const {
2650 : return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) &&
128: branch 3 taken
5043: branch 4 taken
119: branch 5 taken
9: branch 6 taken
2651 5171: !NumProtocols;
2652 : }
2653 :
2654 : /// isObjCQualifiedIdType - true for "id <p>".
2655 3421: bool isObjCQualifiedIdType() const {
2656 : return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) &&
1272: branch 3 taken
2149: branch 4 taken
622: branch 5 taken
650: branch 6 taken
2657 3421: NumProtocols;
2658 : }
2659 : /// isObjCQualifiedClassType - true for "Class <p>".
2660 933: bool isObjCQualifiedClassType() const {
2661 : return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) &&
5: branch 3 taken
928: branch 4 taken
5: branch 5 taken
0: branch 6 not taken
2662 933: NumProtocols;
2663 : }
2664 : /// qual_iterator and friends: this provides access to the (potentially empty)
2665 : /// list of protocols qualifying this interface.
2666 : typedef ObjCProtocolDecl* const * qual_iterator;
2667 :
2668 3555: qual_iterator qual_begin() const {
2669 3555: return reinterpret_cast<qual_iterator> (this + 1);
2670 : }
2671 700: qual_iterator qual_end() const {
2672 700: return qual_begin() + NumProtocols;
2673 : }
2674 498: bool qual_empty() const { return NumProtocols == 0; }
2675 :
2676 : /// getNumProtocols - Return the number of qualifying protocols in this
2677 : /// interface type, or 0 if there are none.
2678 15375: unsigned getNumProtocols() const { return NumProtocols; }
2679 :
2680 3106: bool isSugared() const { return false; }
2681 0: QualType desugar() const { return QualType(this, 0); }
2682 :
2683 : virtual Linkage getLinkage() const;
2684 :
2685 : void Profile(llvm::FoldingSetNodeID &ID);
2686 : static void Profile(llvm::FoldingSetNodeID &ID, QualType T,
2687 : ObjCProtocolDecl *const *protocols,
2688 : unsigned NumProtocols);
2689 204693: static bool classof(const Type *T) {
2690 204693: return T->getTypeClass() == ObjCObjectPointer;
2691 : }
2692 : static bool classof(const ObjCObjectPointerType *) { return true; }
2693 : };
2694 :
2695 : /// A qualifier set is used to build a set of qualifiers.
2696 : class QualifierCollector : public Qualifiers {
2697 : ASTContext *Context;
2698 :
2699 : public:
2700 957994: QualifierCollector(Qualifiers Qs = Qualifiers())
2701 957994: : Qualifiers(Qs), Context(0) {}
2702 : QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers())
2703 : : Qualifiers(Qs), Context(&Context) {}
2704 :
2705 : void setContext(ASTContext &C) { Context = &C; }
2706 :
2707 : /// Collect any qualifiers on the given type and return an
2708 : /// unqualified type.
2709 960346: const Type *strip(QualType QT) {
2710 960346: addFastQualifiers(QT.getLocalFastQualifiers());
9497: branch 1 taken
950849: branch 2 taken
2711 960346: if (QT.hasLocalNonFastQualifiers()) {
2712 9497: const ExtQuals *EQ = QT.getExtQualsUnsafe();
2713 9497: Context = &EQ->getContext();
2714 9497: addQualifiers(EQ->getQualifiers());
2715 9497: return EQ->getBaseType();
2716 : }
2717 950849: return QT.getTypePtrUnsafe();
2718 : }
2719 :
2720 : /// Apply the collected qualifiers to the given type.
2721 : QualType apply(QualType QT) const;
2722 :
2723 : /// Apply the collected qualifiers to the given type.
2724 : QualType apply(const Type* T) const;
2725 :
2726 : };
2727 :
2728 :
2729 : // Inline function definitions.
2730 :
2731 1180316: inline bool QualType::isCanonical() const {
2732 1180316: const Type *T = getTypePtr();
1138197: branch 2 taken
0: branch 2 not taken
2733 1180316: if (hasLocalQualifiers())
40741: branch 1 taken
383: branch 2 taken
40733: branch 4 taken
8: branch 5 taken
2734 41124: return T->isCanonicalUnqualified() && !isa<ArrayType>(T);
2735 1139192: return T->isCanonicalUnqualified();
2736 : }
2737 :
2738 20194: inline bool QualType::isCanonicalAsParam() const {
193: branch 1 taken
20001: branch 2 taken
2739 20194: if (hasLocalQualifiers()) return false;
2740 20001: const Type *T = getTypePtr();
2741 : return T->isCanonicalUnqualified() &&
18276: branch 1 taken
1725: branch 2 taken
18276: branch 4 taken
0: branch 5 not taken
18276: branch 7 taken
0: branch 8 not taken
2742 20001: !isa<FunctionType>(T) && !isa<ArrayType>(T);
2743 : }
2744 :
2745 20955: inline bool QualType::isConstQualified() const {
2746 : return isLocalConstQualified() ||
19285: branch 1 taken
1670: branch 2 taken
7: branch 6 taken
19278: branch 7 taken
2747 20955: getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified();
2748 : }
2749 :
2750 8004: inline bool QualType::isRestrictQualified() const {
2751 : return isLocalRestrictQualified() ||
7967: branch 1 taken
37: branch 2 taken
0: branch 6 not taken
7967: branch 7 taken
2752 8004: getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified();
2753 : }
2754 :
2755 :
2756 4720: inline bool QualType::isVolatileQualified() const {
2757 : return isLocalVolatileQualified() ||
4632: branch 1 taken
88: branch 2 taken
0: branch 6 not taken
4632: branch 7 taken
2758 4720: getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified();
2759 : }
2760 :
2761 375777: inline bool QualType::hasQualifiers() const {
2762 : return hasLocalQualifiers() ||
374615: branch 1 taken
1162: branch 2 taken
31: branch 6 taken
374584: branch 7 taken
2763 375777: getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers();
2764 : }
2765 :
2766 186992: inline Qualifiers QualType::getQualifiers() const {
2767 186992: Qualifiers Quals = getLocalQualifiers();
2768 : Quals.addQualifiers(
2769 186992: getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers());
2770 : return Quals;
2771 : }
2772 :
2773 65650: inline unsigned QualType::getCVRQualifiers() const {
2774 : return getLocalCVRQualifiers() |
2775 65650: getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers();
2776 : }
2777 :
2778 : /// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this
2779 : /// type, returns them. Otherwise, if this is an array type, recurses
2780 : /// on the element type until some qualifiers have been found or a non-array
2781 : /// type reached.
2782 15531: inline unsigned QualType::getCVRQualifiersThroughArrayTypes() const {
9840: branch 2 taken
2783 15531: if (unsigned Quals = getCVRQualifiers())
2784 5691: return Quals;
2785 9840: QualType CT = getTypePtr()->getCanonicalTypeInternal();
80: branch 1 taken
9760: branch 2 taken
2786 9840: if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
2787 80: return AT->getElementType().getCVRQualifiersThroughArrayTypes();
2788 9760: return 0;
2789 : }
2790 :
2791 0: inline void QualType::removeConst() {
2792 0: removeFastQualifiers(Qualifiers::Const);
2793 0: }
2794 :
2795 : inline void QualType::removeRestrict() {
2796 : removeFastQualifiers(Qualifiers::Restrict);
2797 : }
2798 :
2799 : inline void QualType::removeVolatile() {
2800 : QualifierCollector Qc;
2801 : const Type *Ty = Qc.strip(*this);
2802 : if (Qc.hasVolatile()) {
2803 : Qc.removeVolatile();
2804 : *this = Qc.apply(Ty);
2805 : }
2806 : }
2807 :
2808 1476: inline void QualType::removeCVRQualifiers(unsigned Mask) {
0: branch 0 not taken
1476: branch 1 taken
2809 1476: assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
2810 :
2811 : // Fast path: we don't need to touch the slow qualifiers.
1473: branch 0 taken
3: branch 1 taken
2812 1476: if (!(Mask & ~Qualifiers::FastMask)) {
2813 1473: removeFastQualifiers(Mask);
2814 1473: return;
2815 : }
2816 :
2817 3: QualifierCollector Qc;
2818 3: const Type *Ty = Qc.strip(*this);
2819 3: Qc.removeCVRQualifiers(Mask);
2820 3: *this = Qc.apply(Ty);
2821 : }
2822 :
2823 : /// getAddressSpace - Return the address space of this type.
2824 62640: inline unsigned QualType::getAddressSpace() const {
1204: branch 1 taken
61436: branch 2 taken
2825 62640: if (hasLocalNonFastQualifiers()) {
2826 1204: const ExtQuals *EQ = getExtQualsUnsafe();
163: branch 1 taken
1041: branch 2 taken
2827 1204: if (EQ->hasAddressSpace())
2828 163: return EQ->getAddressSpace();
2829 : }
2830 :
2831 62477: QualType CT = getTypePtr()->getCanonicalTypeInternal();
7: branch 1 taken
62470: branch 2 taken
2832 62477: if (CT.hasLocalNonFastQualifiers()) {
2833 7: const ExtQuals *EQ = CT.getExtQualsUnsafe();
2: branch 1 taken
5: branch 2 taken
2834 7: if (EQ->hasAddressSpace())
2835 2: return EQ->getAddressSpace();
2836 : }
2837 :
1191: branch 1 taken
61284: branch 2 taken
2838 62475: if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
2839 1191: return AT->getElementType().getAddressSpace();
15709: branch 1 taken
45575: branch 2 taken
2840 61284: if (const RecordType *RT = dyn_cast<RecordType>(CT))
2841 15709: return RT->getAddressSpace();
2842 45575: return 0;
2843 : }
2844 :
2845 : /// getObjCGCAttr - Return the gc attribute of this type.
2846 17753: inline Qualifiers::GC QualType::getObjCGCAttr() const {
230: branch 2 taken
17523: branch 2 taken
2847 17753: if (hasLocalNonFastQualifiers()) {
2848 230: const ExtQuals *EQ = getExtQualsUnsafe();
209: branch 1 taken
21: branch 2 taken
2849 230: if (EQ->hasObjCGCAttr())
2850 209: return EQ->getObjCGCAttr();
2851 : }
2852 :
2853 17544: QualType CT = getTypePtr()->getCanonicalTypeInternal();
0: branch 1 not taken
17544: branch 2 taken
2854 17544: if (CT.hasLocalNonFastQualifiers()) {
2855 0: const ExtQuals *EQ = CT.getExtQualsUnsafe();
0: branch 1 not taken
0: branch 2 not taken
2856 0: if (EQ->hasObjCGCAttr())
2857 0: return EQ->getObjCGCAttr();
2858 : }
2859 :
1102: branch 1 taken
16442: branch 2 taken
2860 17544: if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
2861 1102: return AT->getElementType().getObjCGCAttr();
1353: branch 2 taken
15089: branch 3 taken
2862 16442: if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>())
2863 1353: return PT->getPointeeType().getObjCGCAttr();
2864 : // We most look at all pointer types, not just pointer to interface types.
2799: branch 2 taken
12290: branch 3 taken
2865 15089: if (const PointerType *PT = CT->getAs<PointerType>())
2866 2799: return PT->getPointeeType().getObjCGCAttr();
2867 12290: return Qualifiers::GCNone;
2868 : }
2869 :
2870 : /// getNoReturnAttr - Returns true if the type has the noreturn attribute,
2871 : /// false otherwise.
2872 3198: inline bool QualType::getNoReturnAttr() const {
2873 3198: QualType CT = getTypePtr()->getCanonicalTypeInternal();
3039: branch 2 taken
159: branch 3 taken
2874 3198: if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) {
3039: branch 3 taken
0: branch 4 not taken
2875 3039: if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
2876 3039: return FT->getNoReturnAttr();
60: branch 2 taken
99: branch 3 taken
2877 159: } else if (const FunctionType *FT = getTypePtr()->getAs<FunctionType>())
2878 60: return FT->getNoReturnAttr();
2879 :
2880 99: return false;
2881 : }
2882 :
2883 : /// getCallConv - Returns the calling convention of the type if the type
2884 : /// is a function type, CC_Default otherwise.
2885 8512: inline CallingConv QualType::getCallConv() const {
2919: branch 2 taken
5593: branch 3 taken
2886 8512: if (const PointerType *PT = getTypePtr()->getAs<PointerType>())
2887 2919: return PT->getPointeeType().getCallConv();
0: branch 2 not taken
5593: branch 3 taken
2888 5593: else if (const ReferenceType *RT = getTypePtr()->getAs<ReferenceType>())
2889 0: return RT->getPointeeType().getCallConv();
405: branch 0 taken
5188: branch 1 taken
2890 5593: else if (const MemberPointerType *MPT =
2891 5593: getTypePtr()->getAs<MemberPointerType>())
2892 405: return MPT->getPointeeType().getCallConv();
4: branch 0 taken
5184: branch 1 taken
2893 5188: else if (const BlockPointerType *BPT =
2894 5188: getTypePtr()->getAs<BlockPointerType>()) {
4: branch 3 taken
0: branch 4 not taken
2895 4: if (const FunctionType *FT = BPT->getPointeeType()->getAs<FunctionType>())
2896 4: return FT->getCallConv();
3625: branch 2 taken
1559: branch 3 taken
2897 5184: } else if (const FunctionType *FT = getTypePtr()->getAs<FunctionType>())
2898 3625: return FT->getCallConv();
2899 :
2900 1559: return CC_Default;
2901 : }
2902 :
2903 : /// isMoreQualifiedThan - Determine whether this type is more
2904 : /// qualified than the Other type. For example, "const volatile int"
2905 : /// is more qualified than "const int", "volatile int", and
2906 : /// "int". However, it is not more qualified than "const volatile
2907 : /// int".
2908 4161: inline bool QualType::isMoreQualifiedThan(QualType Other) const {
2909 : // FIXME: work on arbitrary qualifiers
2910 4161: unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
2911 4161: unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
0: branch 2 not taken
4161: branch 3 taken
2912 4161: if (getAddressSpace() != Other.getAddressSpace())
2913 0: return false;
2128: branch 0 taken
2033: branch 1 taken
1888: branch 2 taken
240: branch 3 taken
2914 4161: return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
2915 : }
2916 :
2917 : /// isAtLeastAsQualifiedAs - Determine whether this type is at last
2918 : /// as qualified as the Other type. For example, "const volatile
2919 : /// int" is at least as qualified as "const int", "volatile int",
2920 : /// "int", and "const volatile int".
2921 3500: inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
2922 : // FIXME: work on arbitrary qualifiers
2923 3500: unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
2924 3500: unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
3: branch 2 taken
3497: branch 3 taken
2925 3500: if (getAddressSpace() != Other.getAddressSpace())
2926 3: return false;
2927 3497: return (MyQuals | OtherQuals) == MyQuals;
2928 : }
2929 :
2930 : /// getNonReferenceType - If Type is a reference type (e.g., const
2931 : /// int&), returns the type that the reference refers to ("const
2932 : /// int"). Otherwise, returns the type itself. This routine is used
2933 : /// throughout Sema to implement C++ 5p6:
2934 : ///
2935 : /// If an expression initially has the type "reference to T" (8.3.2,
2936 : /// 8.5.3), the type is adjusted to "T" prior to any further
2937 : /// analysis, the expression designates the object or function
2938 : /// denoted by the reference, and the expression is an lvalue.
2939 85026: inline QualType QualType::getNonReferenceType() const {
4059: branch 2 taken
80967: branch 3 taken
2940 85026: if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
2941 4059: return RefType->getPointeeType();
2942 : else
2943 80967: return *this;
2944 : }
2945 :
2946 : inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const {
2947 : if (const PointerType *PT = getAs<PointerType>())
2948 : return PT->getPointeeType()->getAs<ObjCInterfaceType>();
2949 : return 0;
2950 : }
2951 :
2952 287440: inline bool Type::isFunctionType() const {
2953 287440: return isa<FunctionType>(CanonicalType);
2954 : }
2955 125123: inline bool Type::isPointerType() const {
2956 125123: return isa<PointerType>(CanonicalType);
2957 : }
2958 56322: inline bool Type::isAnyPointerType() const {
35050: branch 1 taken
21272: branch 2 taken
13595: branch 4 taken
21455: branch 5 taken
2959 56322: return isPointerType() || isObjCObjectPointerType();
2960 : }
2961 72160: inline bool Type::isBlockPointerType() const {
2962 72160: return isa<BlockPointerType>(CanonicalType);
2963 : }
2964 477570: inline bool Type::isReferenceType() const {
2965 477570: return isa<ReferenceType>(CanonicalType);
2966 : }
2967 19295: inline bool Type::isLValueReferenceType() const {
2968 19295: return isa<LValueReferenceType>(CanonicalType);
2969 : }
2970 20997: inline bool Type::isRValueReferenceType() const {
2971 20997: return isa<RValueReferenceType>(CanonicalType);
2972 : }
2973 11019: inline bool Type::isFunctionPointerType() const {
2974 11019: if (const PointerType* T = getAs<PointerType>())
2975 6131: return T->getPointeeType()->isFunctionType();
2976 : else
2977 4888: return false;
2978 : }
2979 3037: inline bool Type::isMemberPointerType() const {
2980 3037: return isa<MemberPointerType>(CanonicalType);
2981 : }
2982 30923: inline bool Type::isMemberFunctionPointerType() const {
2983 30923: if (const MemberPointerType* T = getAs<MemberPointerType>())
2984 316: return T->getPointeeType()->isFunctionType();
2985 : else
2986 30607: return false;
2987 : }
2988 195152: inline bool Type::isArrayType() const {
2989 195152: return isa<ArrayType>(CanonicalType);
2990 : }
2991 : inline bool Type::isConstantArrayType() const {
2992 : return isa<ConstantArrayType>(CanonicalType);
2993 : }
2994 11572: inline bool Type::isIncompleteArrayType() const {
2995 11572: return isa<IncompleteArrayType>(CanonicalType);
2996 : }
2997 83870: inline bool Type::isVariableArrayType() const {
2998 83870: return isa<VariableArrayType>(CanonicalType);
2999 : }
3000 : inline bool Type::isDependentSizedArrayType() const {
3001 : return isa<DependentSizedArrayType>(CanonicalType);
3002 : }
3003 169582: inline bool Type::isRecordType() const {
3004 169582: return isa<RecordType>(CanonicalType);
3005 : }
3006 42655: inline bool Type::isAnyComplexType() const {
3007 42655: return isa<ComplexType>(CanonicalType);
3008 : }
3009 66722: inline bool Type::isVectorType() const {
3010 66722: return isa<VectorType>(CanonicalType);
3011 : }
3012 7775: inline bool Type::isExtVectorType() const {
3013 7775: return isa<ExtVectorType>(CanonicalType);
3014 : }
3015 65780: inline bool Type::isObjCObjectPointerType() const {
3016 65780: return isa<ObjCObjectPointerType>(CanonicalType);
3017 : }
3018 71087: inline bool Type::isObjCInterfaceType() const {
3019 71087: return isa<ObjCInterfaceType>(CanonicalType);
3020 : }
3021 1116: inline bool Type::isObjCQualifiedIdType() const {
575: branch 2 taken
3022 1116: if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3023 541: return OPT->isObjCQualifiedIdType();
3024 575: return false;
3025 : }
3026 662: inline bool Type::isObjCQualifiedClassType() const {
654: branch 1 taken
8: branch 2 taken
3027 662: if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3028 654: return OPT->isObjCQualifiedClassType();
3029 8: return false;
3030 : }
3031 6619: inline bool Type::isObjCIdType() const {
4605: branch 1 taken
2014: branch 2 taken
3032 6619: if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3033 4605: return OPT->isObjCIdType();
3034 2014: return false;
3035 : }
3036 16832: inline bool Type::isObjCClassType() const {
4639: branch 1 taken
12193: branch 2 taken
3037 16832: if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3038 4639: return OPT->isObjCClassType();
3039 12193: return false;
3040 : }
3041 1576: inline bool Type::isObjCSelType() const {
91: branch 1 taken
1485: branch 2 taken
3042 1576: if (const PointerType *OPT = getAs<PointerType>())
3043 91: return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
3044 1485: return false;
3045 : }
3046 2035: inline bool Type::isObjCBuiltinType() const {
1332: branch 1 taken
703: branch 2 taken
1302: branch 4 taken
30: branch 5 taken
0: branch 7 not taken
1302: branch 8 taken
3047 2035: return isObjCIdType() || isObjCClassType() || isObjCSelType();
3048 : }
3049 155: inline bool Type::isTemplateTypeParmType() const {
3050 155: return isa<TemplateTypeParmType>(CanonicalType);
3051 : }
3052 :
3053 69162: inline bool Type::isSpecificBuiltinType(unsigned K) const {
43532: branch 1 taken
25630: branch 2 taken
3054 69162: if (const BuiltinType *BT = getAs<BuiltinType>())
5677: branch 1 taken
37855: branch 2 taken
3055 43532: if (BT->getKind() == (BuiltinType::Kind) K)
3056 5677: return true;
3057 63485: return false;
3058 : }
3059 :
3060 : /// \brief Determines whether this is a type for which one can define
3061 : /// an overloaded operator.
3062 6438: inline bool Type::isOverloadableType() const {
6263: branch 1 taken
175: branch 2 taken
5852: branch 4 taken
411: branch 5 taken
100: branch 7 taken
5752: branch 8 taken
3063 6438: return isDependentType() || isRecordType() || isEnumeralType();
3064 : }
3065 :
3066 11163: inline bool Type::hasPointerRepresentation() const {
3067 : return (isPointerType() || isReferenceType() || isBlockPointerType() ||
3068 : isObjCInterfaceType() || isObjCObjectPointerType() ||
4437: branch 1 taken
6726: branch 2 taken
4239: branch 4 taken
198: branch 5 taken
4179: branch 7 taken
60: branch 8 taken
4179: branch 10 taken
0: branch 11 not taken
2444: branch 13 taken
1735: branch 14 taken
2444: branch 16 taken
0: branch 17 not taken
0: branch 19 not taken
2444: branch 20 taken
3069 11163: isObjCQualifiedInterfaceType() || isNullPtrType());
3070 : }
3071 :
3072 : inline bool Type::hasObjCPointerRepresentation() const {
3073 : return (isObjCInterfaceType() || isObjCObjectPointerType() ||
3074 : isObjCQualifiedInterfaceType());
3075 : }
3076 :
3077 : /// Insertion operator for diagnostics. This allows sending QualType's into a
3078 : /// diagnostic with <<.
3079 : inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3080 3906: QualType T) {
3081 : DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
3082 3906: Diagnostic::ak_qualtype);
3083 3906: return DB;
3084 : }
3085 :
3086 : // Helper class template that is used by Type::getAs to ensure that one does
3087 : // not try to look through a qualified type to get to an array type.
3088 : template<typename T,
3089 : bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
3090 : llvm::is_base_of<ArrayType, T>::value)>
3091 : struct ArrayType_cannot_be_used_with_getAs { };
3092 :
3093 : template<typename T>
3094 : struct ArrayType_cannot_be_used_with_getAs<T, true>;
3095 :
3096 : /// Member-template getAs<specific type>'.
3097 423376: template <typename T> const T *Type::getAs() const {
3098 : ArrayType_cannot_be_used_with_getAs<T> at;
3099 : (void)at;
3100 :
3101 : // If this is directly a T type, return it.
226106: branch 1 taken
583476: branch 2 taken
16551: branch 4 taken
40464: branch 5 taken
807: branch 7 taken
11411: branch 8 taken
60298: branch 10 taken
11911: branch 11 taken
73: branch 13 taken
1488: branch 14 taken
309588: branch 16 taken
49231: branch 17 taken
100742: branch 19 taken
141160: branch 20 taken
0: branch 22 not taken
0: branch 23 not taken
0: branch 25 not taken
6: branch 26 taken
0: branch 28 not taken
0: branch 29 not taken
0: branch 31 not taken
0: branch 32 not taken
3102 1553312: if (const T *Ty = dyn_cast<T>(this))
3103 714165: return Ty;
3104 :
3105 : // If the canonical form of this type isn't the right kind, reject it.
567955: branch 1 taken
15521: branch 2 taken
0: branch 29 not taken
0: branch 32 not taken
0: branch 17 not taken
0: branch 19 not taken
0: branch 19 not taken
0: branch 20 not taken
0: branch 23 not taken
0: branch 25 not taken
0: branch 26 not taken
0: branch 28 not taken
0: branch 29 not taken
3106 839147: if (!isa<T>(CanonicalType))
3107 804666: return 0;
3108 :
3109 : // If this is a typedef for the type, strip the typedef off without
3110 : // losing all typedef information.
3111 34481: return cast<T>(getUnqualifiedDesugaredType());
3112 : }
3113 :
3114 : } // end namespace clang
3115 :
3116 : #endif
Generated: 2010-02-10 01:31 by zcov