Type.h revision 7e50826d3559f284eee6659f0aa159c68f504b34
14b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
24b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//
34b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//                     The LLVM Compiler Infrastructure
44b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//
5959e5be188a505881058777f35abaaa3fe2de40bChris Lattner// This file is distributed under the University of Illinois Open Source
6959e5be188a505881058777f35abaaa3fe2de40bChris Lattner// License. See LICENSE.TXT for details.
74b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//
84b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//===----------------------------------------------------------------------===//
94b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//
104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//  This file defines the Type interface and subclasses.
114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//
124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//===----------------------------------------------------------------------===//
134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#ifndef LLVM_CLANG_AST_TYPE_H
154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#define LLVM_CLANG_AST_TYPE_H
164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
17da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner#include "clang/Basic/Diagnostic.h"
18734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#include "llvm/Support/Casting.h"
2083c13010359c33354c581acee65d0c986a75247eSteve Naroff#include "llvm/ADT/APSInt.h"
2148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/FoldingSet.h"
2248a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/PointerIntPair.h"
2378f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek#include "llvm/Bitcode/SerializationFwd.h"
244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::isa;
254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast;
264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast_or_null;
274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast;
284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast_or_null;
294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang {
314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  class ASTContext;
324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  class Type;
334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  class TypedefDecl;
348e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  class TemplateDecl;
35dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  class TemplateTypeParmDecl;
36279272e63b321f89c8fa0bb198acd3a834459aebDouglas Gregor  class NonTypeTemplateParmDecl;
37279272e63b321f89c8fa0bb198acd3a834459aebDouglas Gregor  class TemplateTemplateParamDecl;
384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  class TagDecl;
394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  class RecordDecl;
40ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis  class CXXRecordDecl;
414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  class EnumDecl;
4264be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek  class FieldDecl;
4342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  class ObjCInterfaceDecl;
4442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  class ObjCProtocolDecl;
4542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  class ObjCMethodDecl;
464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  class Expr;
47718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek  class Stmt;
484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  class SourceLocation;
49fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek  class StmtIteratorBase;
50f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  class TemplateArgument;
51734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  class QualifiedNameType;
524fa58905062efa6a12137b1983a1367220182a20Douglas Gregor
534fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  // Provide forward declarations for all of the *Type classes
544fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define TYPE(Class, Base) class Class##Type;
554fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def"
567555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// QualType - For efficiency, we don't store CVR-qualified types as nodes on
584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// their own: instead each reference to a type stores the qualifiers.  This
594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// greatly reduces the number of nodes we need to allocate for types (for
604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// example we only need one for 'int', 'const int', 'volatile int',
614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'const volatile int', etc).
624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// As an added efficiency bonus, instead of making this a pair, we just store
644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// the three bits we care about in the low bits of the pointer.  To handle the
654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// packing/unpacking, we make QualType be a simple wrapper class that acts like
664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// a smart pointer.
674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass QualType {
6848a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  llvm::PointerIntPair<Type*, 3> Value;
694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  enum TQ {   // NOTE: These flags must be kept in sync with DeclSpec::TQ.
714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Const    = 0x1,
724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Restrict = 0x2,
734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Volatile = 0x4,
744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    CVRFlags = Const|Restrict|Volatile
754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  };
764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
77af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  enum GCAttrTypes {
78af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian    GCNone = 0,
79af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian    Weak,
80af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian    Strong
81af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  };
82af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian
8348a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  QualType() {}
844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
8548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  QualType(const Type *Ptr, unsigned Quals)
8648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner    : Value(const_cast<Type*>(Ptr), Quals) {}
874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
8848a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  unsigned getCVRQualifiers() const { return Value.getInt(); }
89b9b218e566459808be9f1c52b03afad3e0d39ed3Chris Lattner  void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); }
9048a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  Type *getTypePtr() const { return Value.getPointer(); }
9148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner
9248a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static QualType getFromOpaquePtr(void *Ptr) {
944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    QualType T;
9548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner    T.Value.setFromOpaqueValue(Ptr);
964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return T;
974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  Type &operator*() const {
1004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return *getTypePtr();
1014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
1034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  Type *operator->() const {
1044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return getTypePtr();
1054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
1074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// isNull - Return true if this QualType doesn't point to a type yet.
1084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isNull() const {
10948a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner    return getTypePtr() == 0;
1104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
1124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isConstQualified() const {
11348a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner    return (getCVRQualifiers() & Const) ? true : false;
1144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isVolatileQualified() const {
11648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner    return (getCVRQualifiers() & Volatile) ? true : false;
1174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isRestrictQualified() const {
11948a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner    return (getCVRQualifiers() & Restrict) ? true : false;
1204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
121a7bbf567dac9dfd58f12c9ff14584d64104694f3Nuno Lopes
122a7bbf567dac9dfd58f12c9ff14584d64104694f3Nuno Lopes  bool isConstant(ASTContext& Ctx) const;
1232e3b1d2ed22e5638fa9c55cc1ea5dac4db6aecdcChris Lattner
1242e3b1d2ed22e5638fa9c55cc1ea5dac4db6aecdcChris Lattner  /// addConst/addVolatile/addRestrict - add the specified type qual to this
1252e3b1d2ed22e5638fa9c55cc1ea5dac4db6aecdcChris Lattner  /// QualType.
12648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  void addConst()    { Value.setInt(Value.getInt() | Const); }
12748a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  void addVolatile() { Value.setInt(Value.getInt() | Volatile); }
12848a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  void addRestrict() { Value.setInt(Value.getInt() | Restrict); }
1294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
13048a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  void removeConst()    { Value.setInt(Value.getInt() & ~Const); }
13148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); }
13248a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner  void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); }
13393eb82549eec82d75ce5dd3afbeeaf6fdb0e2a27Sanjiv Gupta
1344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getQualifiedType(unsigned TQs) const {
1354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return QualType(getTypePtr(), TQs);
1364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
137a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  QualType getWithAdditionalQualifiers(unsigned TQs) const {
138a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner    return QualType(getTypePtr(), TQs|getCVRQualifiers());
139a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  }
1404b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis
1414b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  QualType withConst() const { return getWithAdditionalQualifiers(Const); }
1424b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);}
1434b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);}
1444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
1453fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  QualType getUnqualifiedType() const;
1463fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
1473fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
1483fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  QualType getNonReferenceType() const;
1494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
150835327293da59eb16667ae5a2b7158131865a079Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
151835327293da59eb16667ae5a2b7158131865a079Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
152835327293da59eb16667ae5a2b7158131865a079Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
153835327293da59eb16667ae5a2b7158131865a079Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
154835327293da59eb16667ae5a2b7158131865a079Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
155835327293da59eb16667ae5a2b7158131865a079Chris Lattner  /// concrete.
156835327293da59eb16667ae5a2b7158131865a079Chris Lattner  QualType getDesugaredType() const;
1576573cfd6fc32eab0b696cfc318bb21f4e3933f35Douglas Gregor
1584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// operator==/!= - Indicate whether the specified types and qualifiers are
1594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// identical.
1604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool operator==(const QualType &RHS) const {
16148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner    return Value == RHS.Value;
1624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool operator!=(const QualType &RHS) const {
16448a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner    return Value != RHS.Value;
1654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  std::string getAsString() const {
1674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    std::string S;
1684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    getAsStringInternal(S);
1694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return S;
1704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void getAsStringInternal(std::string &Str) const;
1724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
173a55e321bd645398b514e246981c04a4889ee2472Chris Lattner  void dump(const char *s) const;
174a55e321bd645398b514e246981c04a4889ee2472Chris Lattner  void dump() const;
1759d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek
1769d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
1779d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
1789d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek  }
1794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
180b06cf30badcddfea862bc9a538447453bdd94598Chris Lattnerpublic:
1814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
1822a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  /// getAddressSpace - Return the address space of this type.
1832a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  inline unsigned getAddressSpace() const;
1842a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
185af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  /// GCAttrTypesAttr - Returns gc attribute of this type.
186af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  inline QualType::GCAttrTypes getObjCGCAttr() const;
18785534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian
18885534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
18985534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian  bool isObjCGCWeak() const {
19085534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian    return getObjCGCAttr() == Weak;
19185534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian  }
19285534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian
19385534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
19485534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian  bool isObjCGCStrong() const {
19585534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian    return getObjCGCAttr() == Strong;
19685534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian  }
197af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian
198034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  /// Emit - Serialize a QualType to Bitcode.
19978f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek  void Emit(llvm::Serializer& S) const;
20078f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek
201034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  /// Read - Deserialize a QualType from Bitcode.
202034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  static QualType ReadVal(llvm::Deserializer& D);
20364be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek
20464be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek  void ReadBackpatch(llvm::Deserializer& D);
2054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
2064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
2074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end clang.
2084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
2094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace llvm {
2104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
2114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// to a specific Type class.
2124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type<const ::clang::QualType> {
2134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  typedef ::clang::Type* SimpleType;
2144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
2154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return Val.getTypePtr();
2164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
2174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
2184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type< ::clang::QualType>
2194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  : public simplify_type<const ::clang::QualType> {};
22078f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek
22178f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek} // end namespace llvm
2224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
2234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang {
2244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
2254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Type - This is the base class of the type hierarchy.  A central concept
2264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// with types is that each type always has a canonical type.  A canonical type
2274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is the type with any typedef names stripped out of it or the types it
2284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// references.  For example, consider:
2294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
2304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///  typedef int  foo;
2314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///  typedef foo* bar;
2324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///    'int *'    'foo *'    'bar'
2334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
2344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// There will be a Type object created for 'int'.  Since int is canonical, its
2354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
2364fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
2374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// there is a PointerType that represents 'int*', which, like 'int', is
2384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
2394fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
2404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is also 'int*'.
2414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
2424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Non-canonical types are useful for emitting diagnostics, without losing
2434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// information about typedefs being used.  Canonical types are useful for type
2444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// comparisons (they allow by-pointer equality tests) and useful for reasoning
2454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// about whether something has a particular form (e.g. is a function type),
2464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// because they implicitly, recursively, strip all typedefs out of a type.
2474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
2484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Types, once created, are immutable.
2494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
2504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass Type {
2514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
2524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  enum TypeClass {
2534fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define TYPE(Class, Base) Class,
2544fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
2554fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def"
2564fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    TagFirst = Record, TagLast = Enum
2574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  };
258af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian
2594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate:
2604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType CanonicalType;
2614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
2621b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
2631b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  bool Dependent : 1;
2641b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
2654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
2664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// Note that this should stay at the end of the ivars for Type so that
2674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// subclasses can pack their bitfields into the same word.
2682a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  unsigned TC : 5;
2691b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
2704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected:
2717c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
2727c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser  Type *this_() { return this; }
2731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  Type(TypeClass tc, QualType Canonical, bool dependent)
27435fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner    : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical),
2751b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor      Dependent(dependent), TC(tc) {}
2761b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  virtual ~Type() {}
277db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek  virtual void Destroy(ASTContext& C);
2784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;
27978f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek
28078f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek  void EmitTypeInternal(llvm::Serializer& S) const;
28178f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek  void ReadTypeInternal(llvm::Deserializer& D);
28278f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek
2834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
28492803daaa6a40a3899c2e599bddc42732c2ce593Hartmut Kaiser  TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); }
2854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
2864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isCanonical() const { return CanonicalType.getTypePtr() == this; }
2874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
2884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
2894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// object types, function types, and incomplete types.
2904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
2914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// isObjectType - types that fully describe objects. An object is a region
2924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// of memory that can be examined and stored into (H&S).
2934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isObjectType() const;
2944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
2954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// isIncompleteType - Return true if this is an incomplete type.
2964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// A type that can describe objects, but which lacks information needed to
2974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
2984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// routine will need to determine if the size is actually required.
2994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isIncompleteType() const;
3009db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner
3019db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
3029db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner  /// type, in other words, not a function type.
3039db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner  bool isIncompleteOrObjectType() const {
3049db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner    return !isFunctionType();
3059db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner  }
30639c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl
30739c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
30839c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl  bool isPODType() const;
30939c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl
3105eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff  /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
3115eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff  /// types that have a non-constant expression. This does not include "[]".
3125eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff  bool isVariablyModifiedType() const;
3135eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff
3144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// Helper methods to distinguish type categories. All type predicates
3152a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
316c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar
317c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
318c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
3198888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff
3208888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
3218888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
3224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
3238d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff  bool isEnumeralType() const;
3248d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff  bool isBooleanType() const;
3258d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff  bool isCharType() const;
3261815b3bfc1382c88bee771bd158755b2426f0780Douglas Gregor  bool isWideCharType() const;
327c81f316d260b8b8b9da21a0f9a22baa334e063fbFariborz Jahanian  bool isIntegralType() const;
3284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
3294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// Floating point categories.
3304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
3314300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
3324300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
3334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isComplexType() const;      // C99 6.2.5p11 (complex)
3343277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
3354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
3364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
3374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
338e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isVoidType() const;         // C99 6.2.5p19
339e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
340e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
341e7ef500151147ba851db502fc4d36319f863db80Douglas Gregor  bool isAggregateType() const;
3424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
343e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  // Type Predicates: Check to see if this type is structurally the specified
3442a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  // type, ignoring typedefs and qualifiers.
345e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isFunctionType() const;
3467931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner  bool isPointerType() const;
3477aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  bool isBlockPointerType() const;
348f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner  bool isReferenceType() const;
349ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  bool isLValueReferenceType() const;
350ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  bool isRValueReferenceType() const;
351cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner  bool isFunctionPointerType() const;
3527555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  bool isMemberPointerType() const;
3537555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  bool isMemberFunctionPointerType() const;
354e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isArrayType() const;
355a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  bool isConstantArrayType() const;
356a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  bool isIncompleteArrayType() const;
357a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  bool isVariableArrayType() const;
3581b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  bool isDependentSizedArrayType() const;
359e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isRecordType() const;
3602e78db3510b136b3f961af202e6a1a3df4839172Chris Lattner  bool isClassType() const;
361e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isStructureType() const;
36236e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff  bool isUnionType() const;
363b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
364b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isVectorType() const;                    // GCC vector type.
365af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  bool isExtVectorType() const;                 // Extended vector type.
366b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isObjCInterfaceType() const;             // NSString or NSString<foo>
367b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
368b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
369dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
3701b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
3711b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
3721b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// that its definition somehow depends on a template parameter
3731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// (C++ [temp.dep.type]).
3741b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  bool isDependentType() const { return Dependent; }
37500fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor  bool isOverloadableType() const;
376dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
377fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
378fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
379fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
380fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  /// interface types.
381fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  bool hasPointerRepresentation() const;
382fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar
3837c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
3847c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
3857c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian  bool hasObjCPointerRepresentation() const;
3867c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian
387e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  // Type Checking Functions: Check to see if this type is structurally the
38835fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
38935fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  // the best type we can.
3907555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const BuiltinType *getAsBuiltinType() const;
3917555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const FunctionType *getAsFunctionType() const;
3924fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  const FunctionNoProtoType *getAsFunctionNoProtoType() const;
3934fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  const FunctionProtoType *getAsFunctionProtoType() const;
3947931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner  const PointerType *getAsPointerType() const;
3957aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  const BlockPointerType *getAsBlockPointerType() const;
396f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner  const ReferenceType *getAsReferenceType() const;
397ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  const LValueReferenceType *getAsLValueReferenceType() const;
398ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  const RValueReferenceType *getAsRValueReferenceType() const;
3997555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const MemberPointerType *getAsMemberPointerType() const;
4009c7825b737617339724d43bd04960852271f08e2Douglas Gregor  const TagType *getAsTagType() const;
401e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  const RecordType *getAsRecordType() const;
4025c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek  const RecordType *getAsStructureType() const;
4031b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
4045c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek  const TypedefType *getAsTypedefType() const;
405e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  const RecordType *getAsUnionType() const;
4060832dbca0e11ee020bbed181c515b3835158436eEli Friedman  const EnumType *getAsEnumType() const;
407e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  const VectorType *getAsVectorType() const; // GCC vector type.
4087a85fa1ba94c9f4cf960463dd3eb444ef6f89446Chris Lattner  const ComplexType *getAsComplexType() const;
40936e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
410af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  const ExtVectorType *getAsExtVectorType() const; // Extended vector type.
411b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  const ObjCInterfaceType *getAsObjCInterfaceType() const;
412b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const;
413b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const;
414dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  const TemplateTypeParmType *getAsTemplateTypeParmType() const;
415dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
4168e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  const ClassTemplateSpecializationType *
4177e50826d3559f284eee6659f0aa159c68f504b34Douglas Gregor    getAsClassTemplateSpecializationType() const;
4188e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
419f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC
420f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  /// interface, return the interface type, otherwise return null.
421f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const;
422f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner
423a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
424a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
425a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
426a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
427a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner
4282afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
4295c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
4302afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
4312afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
4322ea769b494649b5ca4864acf154f2fedc7718029Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
4332afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner  /// concrete.
434a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  QualType getDesugaredType() const;
4352afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner
4364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// More type predicates useful for type checking/promotion
4374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
4384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
4394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// isSignedIntegerType - Return true if this is an integer type that is
440bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
441bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
442bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// integer element type.
4434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isSignedIntegerType() const;
4444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
4454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// isUnsignedIntegerType - Return true if this is an integer type that is
446bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
447bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
448bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// element type.
4494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isUnsignedIntegerType() const;
450bbe686be29157b575e53fbed328613117b525f26Chris Lattner
4514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// isConstantSizeType - Return true if this is not a variable sized type,
4520448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
4530448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner  /// incomplete types.
45462f67fd7f670f1a8b222c6565b257c05e8e80faeEli Friedman  bool isConstantSizeType() const;
455a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner
4564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getCanonicalTypeInternal() const { return CanonicalType; }
457a55e321bd645398b514e246981c04a4889ee2472Chris Lattner  void dump() const;
4584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const = 0;
4594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *) { return true; }
460034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
461034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected:
462034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  /// Emit - Emit a Type to bitcode.  Used by ASTContext.
463034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  void Emit(llvm::Serializer& S) const;
464034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
465034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  /// Create - Construct a Type from bitcode.  Used by ASTContext.
466034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S);
467034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
468034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  /// EmitImpl - Subclasses must implement this method in order to
469034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  ///  be serialized.
4709c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar  // FIXME: Make this abstract once implemented.
4719c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar  virtual void EmitImpl(llvm::Serializer& S) const {
472126949ecf2a1051fa3271b42936129ea0299be99Gabor Greif    assert(false && "Serialization for type not supported.");
4739c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar  }
4744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
4754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
476b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26
477b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// This supports all kinds of type attributes; including,
478b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// address space qualified types, objective-c's __weak and
479b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// __strong attributes.
4802a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb///
481b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode {
48235fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  /// BaseType - This is the underlying type that this qualifies.  All CVR
48335fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  /// qualifiers are stored on the QualType that references this type, so we
48435fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  /// can't have any here.
48535fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  Type *BaseType;
486dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian
4872a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  /// Address Space ID - The address space ID this type is qualified with.
4882a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  unsigned AddressSpace;
489dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian  /// GC __weak/__strong attributes
490af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  QualType::GCAttrTypes GCAttrType;
491dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian
492dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian  ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace,
493af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian              QualType::GCAttrTypes gcAttr) :
49418b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner      Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base),
49518b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner      AddressSpace(AddrSpace), GCAttrType(gcAttr) {
49618b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner    assert(!isa<ExtQualType>(BaseType) &&
49718b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner           "Cannot have ExtQualType of ExtQualType");
49818b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner  }
4992a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  friend class ASTContext;  // ASTContext creates these.
5002a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambpublic:
50135fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  Type *getBaseType() const { return BaseType; }
502af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; }
5031e124fe3e31ab37c45b6fbe6a8075e987fc04408Fariborz Jahanian  unsigned getAddressSpace() const { return AddressSpace; }
5042a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5052a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  virtual void getAsStringInternal(std::string &InnerString) const;
5062a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5072a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  void Profile(llvm::FoldingSetNodeID &ID) {
5081e124fe3e31ab37c45b6fbe6a8075e987fc04408Fariborz Jahanian    Profile(ID, getBaseType(), AddressSpace, GCAttrType);
5092a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  }
51035fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, Type *Base,
511af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian                      unsigned AddrSpace, QualType::GCAttrTypes gcAttr) {
51235fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner    ID.AddPointer(Base);
5132a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb    ID.AddInteger(AddrSpace);
5141e124fe3e31ab37c45b6fbe6a8075e987fc04408Fariborz Jahanian    ID.AddInteger(gcAttr);
5152a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  }
5162a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
517b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian  static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; }
518b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian  static bool classof(const ExtQualType *) { return true; }
5192a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5202a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambprotected:
5212a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  virtual void EmitImpl(llvm::Serializer& S) const;
5222a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
5232a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  friend class Type;
5242a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb};
5252a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5262a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
5284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types are always canonical and have a literal name field.
5294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass BuiltinType : public Type {
5304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
5314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  enum Kind {
5324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Void,
5334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Bool,     // This is bool and/or _Bool.
5354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Char_U,   // This is 'char' for targets where char is unsigned.
5364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    UChar,    // This is explicitly qualified unsigned char.
5374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    UShort,
5384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    UInt,
5394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ULong,
5404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ULongLong,
5414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Char_S,   // This is 'char' for targets where char is signed.
5434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    SChar,    // This is explicitly qualified signed char.
54485bd81edce4057156d7f49408147f07daa675096Argiris Kirtzidis    WChar,    // This is 'wchar_t' for C++.
5454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Short,
5464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Int,
5474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Long,
5484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    LongLong,
5494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
550d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor    Float, Double, LongDouble,
551d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor
5521b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Overload,  // This represents the type of an overloaded function declaration.
5531b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Dependent  // This represents the type of a type-dependent expression.
5544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  };
5554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate:
5564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  Kind TypeKind;
5574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
5581b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  BuiltinType(Kind K)
5591b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)),
5601b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor      TypeKind(K) {}
5614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  Kind getKind() const { return TypeKind; }
5634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  const char *getName() const;
5644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
5664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
5684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const BuiltinType *) { return true; }
5694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
5704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
571ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't
572ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman/// want to or can't map to named integer types.  These always have a lower
573ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman/// integer rank than builtin types of the same width.
574ff3fcdf47370a4577d971a2adefd259807152078Eli Friedmanclass FixedWidthIntType : public Type {
575ff3fcdf47370a4577d971a2adefd259807152078Eli Friedmanprivate:
576ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  unsigned Width;
577ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  bool Signed;
578ff3fcdf47370a4577d971a2adefd259807152078Eli Friedmanpublic:
579ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false),
580ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman                                          Width(W), Signed(S) {}
581ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman
582ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  unsigned getWidth() const { return Width; }
583ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  bool isSigned() const { return Signed; }
584ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  const char *getName() const;
585ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman
586ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  virtual void getAsStringInternal(std::string &InnerString) const;
587ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman
588ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; }
589ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  static bool classof(const FixedWidthIntType *) { return true; }
590ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman};
591ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman
5924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
5934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types (_Complex float etc) as well as the GCC integer complex extensions.
5944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
5954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass ComplexType : public Type, public llvm::FoldingSetNode {
5964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType ElementType;
5974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  ComplexType(QualType Element, QualType CanonicalPtr) :
5981b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType()),
5991b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    ElementType(Element) {
6004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
6024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
6034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getElementType() const { return ElementType; }
6044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
606034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
6074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
6084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Profile(ID, getElementType());
6094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
6114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(Element.getAsOpaquePtr());
6124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
6154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const ComplexType *) { return true; }
61678f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek
617034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected:
618034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
619034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
620034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  friend class Type;
6214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
6224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
623554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
624cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner///
625554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
626cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner  QualType PointeeType;
6274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  PointerType(QualType Pointee, QualType CanonicalPtr) :
629554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar    Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) {
6304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
6324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
6334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
6354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
636554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
637554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar
6384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
6394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Profile(ID, getPointeeType());
6404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
6424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(Pointee.getAsOpaquePtr());
6434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
6464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const PointerType *) { return true; }
647034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
648034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected:
649034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
650034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
651034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  friend class Type;
6524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
6534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6547aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// BlockPointerType - pointer to a block type.
6557aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// This type is to represent types syntactically represented as
6567aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
6577aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff///
6587aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
6597aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
6607aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
6611b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType()),
6621b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    PointeeType(Pointee) {
6637aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  }
6647aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
6657aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffpublic:
6667aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6677aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
6687aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
6697aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6707aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
6717aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6727aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
6737aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff      Profile(ID, getPointeeType());
6747aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  }
6757aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
6767aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
6777aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  }
6787aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6797aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  static bool classof(const Type *T) {
6807aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    return T->getTypeClass() == BlockPointer;
6817aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  }
6827aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
6837aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6847aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  protected:
6857aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    virtual void EmitImpl(llvm::Serializer& S) const;
6867aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
6877aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    friend class Type;
6887aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff};
6897aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
690ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
6914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
692554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
693554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar  QualType PointeeType;
694554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar
695ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected:
696ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) :
697ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    Type(tc, CanonicalRef, Referencee->isDependentType()),
698554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar    PointeeType(Referencee) {
6994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
7004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
701554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
702554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar
7034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
704cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner    Profile(ID, getPointeeType());
7054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
7064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
7074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(Referencee.getAsOpaquePtr());
7084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
7094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
710ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const Type *T) {
711ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    return T->getTypeClass() == LValueReference ||
712ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl           T->getTypeClass() == RValueReference;
713ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
7144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const ReferenceType *) { return true; }
7157555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7167555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlprotected:
7177555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  virtual void EmitImpl(llvm::Serializer& S) const;
718ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl};
719ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
720ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
721ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl///
722ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass LValueReferenceType : public ReferenceType {
723ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  LValueReferenceType(QualType Referencee, QualType CanonicalRef) :
724ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    ReferenceType(LValueReference, Referencee, CanonicalRef) {
725ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
726ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  friend class ASTContext; // ASTContext creates these
727ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic:
728ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  virtual void getAsStringInternal(std::string &InnerString) const;
729ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
730ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const Type *T) {
731ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    return T->getTypeClass() == LValueReference;
732ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
733ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
734ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
735ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected:
736ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
737ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  friend class Type;
738ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl};
739ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
740ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
741ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl///
742ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass RValueReferenceType : public ReferenceType {
743ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
744ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    ReferenceType(RValueReference, Referencee, CanonicalRef) {
745ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
746ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  friend class ASTContext; // ASTContext creates these
747ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic:
748ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  virtual void getAsStringInternal(std::string &InnerString) const;
749ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
750ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const Type *T) {
751ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    return T->getTypeClass() == RValueReference;
752ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
753ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
754ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
755ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected:
7567555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
7577555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  friend class Type;
7587555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl};
7597555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7607555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
7617555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl///
7627555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
7637555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  QualType PointeeType;
7647555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
7657555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
7667555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const Type *Class;
7677555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7687555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
7697555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    Type(MemberPointer, CanonicalPtr,
7707555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl         Cls->isDependentType() || Pointee->isDependentType()),
7717555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    PointeeType(Pointee), Class(Cls) {
7727555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  }
7737555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  friend class ASTContext; // ASTContext creates these.
7747555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlpublic:
7757555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7767555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  QualType getPointeeType() const { return PointeeType; }
7777555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7787555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const Type *getClass() const { return Class; }
7797555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7807555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  virtual void getAsStringInternal(std::string &InnerString) const;
7817555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7827555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
7837555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    Profile(ID, getPointeeType(), getClass());
7847555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  }
7857555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
7867555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl                      const Type *Class) {
7877555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
7887555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    ID.AddPointer(Class);
7897555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  }
7907555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7917555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static bool classof(const Type *T) {
7927555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    return T->getTypeClass() == MemberPointer;
7937555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  }
7947555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
7957555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7967555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlprotected:
7977555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  virtual void EmitImpl(llvm::Serializer& S) const;
7987555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
7997555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  friend class Type;
8004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
8014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
8024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ArrayType - C99 6.7.5.2 - Array Declarators.
8034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
804c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
8054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
8064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
8071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
8081b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// with a star size (e.g. int X[*]).
8091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// 'static' is only allowed on function parameters.
8104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  enum ArraySizeModifier {
8114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Normal, Static, Star
8124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  };
8134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate:
81483c13010359c33354c581acee65d0c986a75247eSteve Naroff  /// ElementType - The element type of the array.
81583c13010359c33354c581acee65d0c986a75247eSteve Naroff  QualType ElementType;
81624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff
817dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum
81824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  /// NOTE: These fields are packed into the bitfields space in the Type class.
819dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek  unsigned SizeModifier : 2;
82024c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff
82124c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  /// IndexTypeQuals - Capture qualifiers in declarations like:
82224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  /// 'int X[static restrict 4]'. For function parameters only.
82324c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  unsigned IndexTypeQuals : 3;
82424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff
82583c13010359c33354c581acee65d0c986a75247eSteve Naroffprotected:
8261b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  // C++ [temp.dep.type]p1:
8271b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  //   A type is dependent if it is...
8281b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  //     - an array type constructed from any dependent type or whose
8291b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  //       size is specified by a constant expression that is
8301b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  //       value-dependent,
83124c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
83224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff            ArraySizeModifier sm, unsigned tq)
8331b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray),
8341b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor      ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
8351b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
83683c13010359c33354c581acee65d0c986a75247eSteve Naroff  friend class ASTContext;  // ASTContext creates these.
83783c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic:
83883c13010359c33354c581acee65d0c986a75247eSteve Naroff  QualType getElementType() const { return ElementType; }
839dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek  ArraySizeModifier getSizeModifier() const {
840dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek    return ArraySizeModifier(SizeModifier);
841dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek  }
84224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
84383c13010359c33354c581acee65d0c986a75247eSteve Naroff
84483c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const Type *T) {
84583c13010359c33354c581acee65d0c986a75247eSteve Naroff    return T->getTypeClass() == ConstantArray ||
8468ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman           T->getTypeClass() == VariableArray ||
8471b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor           T->getTypeClass() == IncompleteArray ||
8481b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor           T->getTypeClass() == DependentSizedArray;
84983c13010359c33354c581acee65d0c986a75247eSteve Naroff  }
85083c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const ArrayType *) { return true; }
85183c13010359c33354c581acee65d0c986a75247eSteve Naroff};
85283c13010359c33354c581acee65d0c986a75247eSteve Naroff
85356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ConstantArrayType - This class represents C arrays with a specified constant
85456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size.  For example 'int A[100]' has ConstantArrayType where the element type
85556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// is 'int' and the size is 100.
856c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ConstantArrayType : public ArrayType {
85783c13010359c33354c581acee65d0c986a75247eSteve Naroff  llvm::APInt Size; // Allows us to unique the type.
85883c13010359c33354c581acee65d0c986a75247eSteve Naroff
8593f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
86024c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff                    ArraySizeModifier sm, unsigned tq)
8613f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {}
86283c13010359c33354c581acee65d0c986a75247eSteve Naroff  friend class ASTContext;  // ASTContext creates these.
86383c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic:
864a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  const llvm::APInt &getSize() const { return Size; }
86583c13010359c33354c581acee65d0c986a75247eSteve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
86683c13010359c33354c581acee65d0c986a75247eSteve Naroff
86783c13010359c33354c581acee65d0c986a75247eSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
8683f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    Profile(ID, getElementType(), getSize(),
8693f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner            getSizeModifier(), getIndexTypeQualifier());
87083c13010359c33354c581acee65d0c986a75247eSteve Naroff  }
87183c13010359c33354c581acee65d0c986a75247eSteve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
8723f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
8733f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner                      unsigned TypeQuals) {
87483c13010359c33354c581acee65d0c986a75247eSteve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
87583c13010359c33354c581acee65d0c986a75247eSteve Naroff    ID.AddInteger(ArraySize.getZExtValue());
8763f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    ID.AddInteger(SizeMod);
8773f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    ID.AddInteger(TypeQuals);
87883c13010359c33354c581acee65d0c986a75247eSteve Naroff  }
87983c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const Type *T) {
88083c13010359c33354c581acee65d0c986a75247eSteve Naroff    return T->getTypeClass() == ConstantArray;
88183c13010359c33354c581acee65d0c986a75247eSteve Naroff  }
88283c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const ConstantArrayType *) { return true; }
8834234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek
8844234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenekprotected:
8854234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
8864234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
8874234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek  friend class Type;
88883c13010359c33354c581acee65d0c986a75247eSteve Naroff};
88983c13010359c33354c581acee65d0c986a75247eSteve Naroff
89056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
89156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
89256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// type is 'int' and the size is unspecified.
8938ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanclass IncompleteArrayType : public ArrayType {
8948ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  IncompleteArrayType(QualType et, QualType can,
8958ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman                    ArraySizeModifier sm, unsigned tq)
8968ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman    : ArrayType(IncompleteArray, et, can, sm, tq) {}
8978ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  friend class ASTContext;  // ASTContext creates these.
8988ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanpublic:
8998ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9008ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  virtual void getAsStringInternal(std::string &InnerString) const;
9018ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9028ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  static bool classof(const Type *T) {
9038ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman    return T->getTypeClass() == IncompleteArray;
9048ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  }
9058ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
9068ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9078ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  friend class StmtIteratorBase;
9088ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9098ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
9103f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier());
9118ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  }
9128ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9133f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
9143f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
9158ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
9163f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    ID.AddInteger(SizeMod);
9173f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    ID.AddInteger(TypeQuals);
9188ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  }
9198ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9208ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanprotected:
9218ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  virtual void EmitImpl(llvm::Serializer& S) const;
9228ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
9238ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  friend class Type;
9248ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman};
9258ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
92656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
92756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
92856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
92956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///
93056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
93156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// should not be: two lexically equivalent variable array types could mean
93256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// different things, for example, these variables do not have the same type
93356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// dynamically:
93456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///
93556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// void foo(int x) {
93656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///   int Y[x];
93756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///   ++x;
93856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///   int Z[x];
93956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// }
94056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///
941c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass VariableArrayType : public ArrayType {
94283c13010359c33354c581acee65d0c986a75247eSteve Naroff  /// SizeExpr - An assignment expression. VLA's are only permitted within
94383c13010359c33354c581acee65d0c986a75247eSteve Naroff  /// a function block.
944718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek  Stmt *SizeExpr;
9454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
94624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
94724c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff                    ArraySizeModifier sm, unsigned tq)
948718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek    : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
9494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
950db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek  virtual void Destroy(ASTContext& C);
951db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek
9524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
953a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  Expr *getSizeExpr() const {
954718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek    // We use C-style casts instead of cast<> here because we do not wish
955718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
956718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek    return (Expr*) SizeExpr;
957718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek  }
9584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
9594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
9604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
96183c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const Type *T) {
96283c13010359c33354c581acee65d0c986a75247eSteve Naroff    return T->getTypeClass() == VariableArray;
9634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
96483c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const VariableArrayType *) { return true; }
96527a32d6f18844a97446d6e2002bf181da591332aTed Kremenek
966fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek  friend class StmtIteratorBase;
9673793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek
9683793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
9697029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner    assert(0 && "Cannnot unique VariableArrayTypes.");
9703793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek  }
9715cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek
9725cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenekprotected:
9735cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
9745cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
9755cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek  friend class Type;
9764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
9774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
9781b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// DependentSizedArrayType - This type represents an array type in
9791b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// C++ whose size is a value-dependent expression. For example:
9801b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// @code
9811b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// template<typename T, int Size>
9821b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// class array {
9831b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor///   T data[Size];
9841b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// };
9851b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// @endcode
9861b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// For these types, we won't actually know what the array bound is
9871b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// until template instantiation occurs, at which point this will
9881b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
9891b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorclass DependentSizedArrayType : public ArrayType {
9901b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// SizeExpr - An assignment expression that will instantiate to the
9911b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// size of the array.
9921b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  Stmt *SizeExpr;
9931b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
9941b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  DependentSizedArrayType(QualType et, QualType can, Expr *e,
9951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor			  ArraySizeModifier sm, unsigned tq)
9961b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
9971b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  friend class ASTContext;  // ASTContext creates these.
9981b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  virtual void Destroy(ASTContext& C);
9991b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorpublic:
10011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  Expr *getSizeExpr() const {
10021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
10031b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
10041b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    return (Expr*) SizeExpr;
10051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  }
10061b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  virtual void getAsStringInternal(std::string &InnerString) const;
10081b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  static bool classof(const Type *T) {
10101b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    return T->getTypeClass() == DependentSizedArray;
10111b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  }
10121b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
10131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10141b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  friend class StmtIteratorBase;
10151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10161b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
10177029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner    assert(0 && "Cannnot unique DependentSizedArrayTypes.");
10181b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  }
10191b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10201b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorprotected:
10211b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
10221b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
10231b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  friend class Type;
10241b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor};
10251b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// VectorType - GCC generic vector type. This type is created using
10274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// __attribute__((vector_size(n)), where "n" specifies the vector size in
10284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// bytes. Since the constructor takes the number of vector elements, the
10294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// client is responsible for converting the size into the number of elements.
10304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass VectorType : public Type, public llvm::FoldingSetNode {
10314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected:
10324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// ElementType - The element type of the vector.
10334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType ElementType;
10344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// NumElements - The number of elements in the vector.
10364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  unsigned NumElements;
10374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
10391b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Type(Vector, canonType, vecType->isDependentType()),
10401b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    ElementType(vecType), NumElements(nElements) {}
10414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
10421486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman             QualType canonType)
10431b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType),
10441b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor      NumElements(nElements) {}
10454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
10464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
10474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getElementType() const { return ElementType; }
10494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  unsigned getNumElements() const { return NumElements; }
10504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
10524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
10544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Profile(ID, getElementType(), getNumElements(), getTypeClass());
10554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
10564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
10574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner                      unsigned NumElements, TypeClass TypeClass) {
10584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(ElementType.getAsOpaquePtr());
10594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddInteger(NumElements);
10604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddInteger(TypeClass);
10614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
10624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) {
1063af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
10644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
10654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const VectorType *) { return true; }
10664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
10674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
1068af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// ExtVectorType - Extended vector type. This type is created using
1069af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
1070af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
10716154214e20225a883a8a00226499534e9b514315Steve Naroff/// class enables syntactic extensions, like Vector Components for accessing
10726154214e20225a883a8a00226499534e9b514315Steve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
1073af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemanclass ExtVectorType : public VectorType {
1074af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
1075af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman    VectorType(ExtVector, vecType, nElements, canonType) {}
10764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
10774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
10789096b795541c783297fb19684a58c54d0fe823b8Chris Lattner  static int getPointAccessorIdx(char c) {
10799096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    switch (c) {
10809096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    default: return -1;
10819096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    case 'x': return 0;
10829096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    case 'y': return 1;
10839096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    case 'z': return 2;
10849096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    case 'w': return 3;
10859096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    }
10861b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff  }
10871486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman  static int getNumericAccessorIdx(char c) {
10889096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    switch (c) {
10891486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      default: return -1;
10901486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '0': return 0;
10911486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '1': return 1;
10921486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '2': return 2;
10931486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '3': return 3;
10941486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '4': return 4;
10951486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '5': return 5;
10961486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '6': return 6;
10971486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '7': return 7;
10981486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '8': return 8;
10991486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '9': return 9;
11001486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'a': return 10;
11011486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'b': return 11;
11021486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'c': return 12;
11031486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'd': return 13;
11041486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'e': return 14;
11051486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'f': return 15;
11069096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    }
11071b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff  }
110842158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner
110942158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner  static int getAccessorIdx(char c) {
111042158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
11111486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman    return getNumericAccessorIdx(c);
111242158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner  }
111342158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner
11149096b795541c783297fb19684a58c54d0fe823b8Chris Lattner  bool isAccessorWithinNumElements(char c) const {
111542158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner    if (int idx = getAccessorIdx(c)+1)
11169096b795541c783297fb19684a58c54d0fe823b8Chris Lattner      return unsigned(idx-1) < NumElements;
11179096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    return false;
11181b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff  }
1119c11705f9b742b542724dd56796bf90e07191e342Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
1120c11705f9b742b542724dd56796bf90e07191e342Steve Naroff
1121806b319509d01bffe47317f11140c930da800dbbSteve Naroff  static bool classof(const Type *T) {
1122af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman    return T->getTypeClass() == ExtVector;
11234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1124af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  static bool classof(const ExtVectorType *) { return true; }
11254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
11264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
11284fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
11294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
11304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionType : public Type {
11314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// SubClassData - This field is owned by the subclass, put here to pack
11324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// tightly with the ivars in Type.
11334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool SubClassData : 1;
11344b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis
11354fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
11364b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  /// other bitfields.
11374fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  /// The qualifiers are part of FunctionProtoType because...
11384b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  ///
11394b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  /// C++ 8.3.5p4: The return type, the parameter type list and the
11404b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  /// cv-qualifier-seq, [...], are part of the function type.
11414b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  ///
11424b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  unsigned TypeQuals : 3;
11434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  // The type returned by the function.
11454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType ResultType;
11464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected:
11474b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,
11481b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor               unsigned typeQuals, QualType Canonical, bool Dependent)
11491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(tc, Canonical, Dependent),
11504b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis      SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {}
11514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool getSubClassData() const { return SubClassData; }
11524b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  unsigned getTypeQuals() const { return TypeQuals; }
11534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
11544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getResultType() const { return ResultType; }
11564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) {
11594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return T->getTypeClass() == FunctionNoProto ||
11604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner           T->getTypeClass() == FunctionProto;
11614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
11624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const FunctionType *) { return true; }
11634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
11644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11654fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
11664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// no information available about its arguments.
11674fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
11684fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  FunctionNoProtoType(QualType Result, QualType Canonical)
11691b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
1170f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman                   /*Dependent=*/false) {}
11714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
11724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
11734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  // No additional state past what FunctionType provides.
11744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
11764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
11784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Profile(ID, getResultType());
11794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
11804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) {
11814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(ResultType.getAsOpaquePtr());
11824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
11834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) {
11854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return T->getTypeClass() == FunctionNoProto;
11864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
11874fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
118887f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek
118987f0429f888ee5d332304641611b88f7b54b5065Ted Kremenekprotected:
119087f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
119187f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
119287f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek  friend class Type;
11934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
11944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11954fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
11964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
11974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// arguments, not as having a single void argument.
11984fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
11991b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// hasAnyDependentType - Determine whether there are any dependent
12001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// types within the arguments passed in.
12011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) {
12021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
12031b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor      if (ArgArray[Idx]->isDependentType())
1204f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman    return true;
12051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
12061b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    return false;
12071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  }
12081b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
12094fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs,
12104b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis                    bool isVariadic, unsigned typeQuals, QualType Canonical)
12111b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical,
1212f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman                   (Result->isDependentType() ||
1213f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman                    hasAnyDependentType(ArgArray, numArgs))),
12144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner      NumArgs(numArgs) {
12154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    // Fill in the trailing argument array.
12164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
12174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    for (unsigned i = 0; i != numArgs; ++i)
12184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner      ArgInfo[i] = ArgArray[i];
12194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// NumArgs - The number of arguments this function has, not counting '...'.
12224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  unsigned NumArgs;
12234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
12254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// holds the argument types.
1226db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek
12274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
1228db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek
12294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
12304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  unsigned getNumArgs() const { return NumArgs; }
12314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getArgType(unsigned i) const {
12324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    assert(i < NumArgs && "Invalid argument number!");
12334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return arg_type_begin()[i];
12344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isVariadic() const { return getSubClassData(); }
12374b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
12384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  typedef const QualType *arg_type_iterator;
12404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  arg_type_iterator arg_type_begin() const {
12414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
12424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
12444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
12464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) {
12484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return T->getTypeClass() == FunctionProto;
12494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12504fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
12514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID);
12534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
12544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
12554b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis                      bool isVariadic, unsigned TypeQuals);
1256034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
1257034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected:
1258034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1259034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
1260034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  friend class Type;
12614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
12624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TypedefType : public Type {
12654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  TypedefDecl *Decl;
1266e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianprotected:
1267e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  TypedefType(TypeClass tc, TypedefDecl *D, QualType can)
12681b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(tc, can, can->isDependentType()), Decl(D) {
12694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    assert(!isa<TypedefType>(can) && "Invalid canonical type");
12704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
12724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
12734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  TypedefDecl *getDecl() const { return Decl; }
12754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
1277a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  /// potentially looking through *all* consecutive typedefs.  This returns the
12784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// sum of the type qualifiers, so if you have:
12794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  ///   typedef const int A;
12804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  ///   typedef volatile A B;
12814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// looking through the typedefs for B will give you "const volatile A".
12824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType LookThroughTypedefs() const;
12834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
12854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12864fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
12874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const TypedefType *) { return true; }
12882f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek
12892f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenekprotected:
12902f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
12912f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
12922f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek  friend class Type;
12934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
12944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12954fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypeOfExprType (GCC extension).
12964fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass TypeOfExprType : public Type {
12977cbb14653934a298c09002b87704dc6531261771Steve Naroff  Expr *TOExpr;
12984fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  TypeOfExprType(Expr *E, QualType can);
12997cbb14653934a298c09002b87704dc6531261771Steve Naroff  friend class ASTContext;  // ASTContext creates these.
13007cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic:
13017cbb14653934a298c09002b87704dc6531261771Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
13027cbb14653934a298c09002b87704dc6531261771Steve Naroff
13037cbb14653934a298c09002b87704dc6531261771Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
13047cbb14653934a298c09002b87704dc6531261771Steve Naroff
13054fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
13064fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
130771af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu
130871af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xuprotected:
130971af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu  virtual void EmitImpl(llvm::Serializer& S) const;
131071af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
131171af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu  friend class Type;
13127cbb14653934a298c09002b87704dc6531261771Steve Naroff};
13137cbb14653934a298c09002b87704dc6531261771Steve Naroff
13147cbb14653934a298c09002b87704dc6531261771Steve Naroff/// TypeOfType (GCC extension).
13157cbb14653934a298c09002b87704dc6531261771Steve Naroffclass TypeOfType : public Type {
13167cbb14653934a298c09002b87704dc6531261771Steve Naroff  QualType TOType;
13171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  TypeOfType(QualType T, QualType can)
13184fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : Type(TypeOf, can, T->isDependentType()), TOType(T) {
13197cbb14653934a298c09002b87704dc6531261771Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
13207cbb14653934a298c09002b87704dc6531261771Steve Naroff  }
13217cbb14653934a298c09002b87704dc6531261771Steve Naroff  friend class ASTContext;  // ASTContext creates these.
13227cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic:
13237cbb14653934a298c09002b87704dc6531261771Steve Naroff  QualType getUnderlyingType() const { return TOType; }
13247cbb14653934a298c09002b87704dc6531261771Steve Naroff
13257cbb14653934a298c09002b87704dc6531261771Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
13267cbb14653934a298c09002b87704dc6531261771Steve Naroff
13274fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
13287cbb14653934a298c09002b87704dc6531261771Steve Naroff  static bool classof(const TypeOfType *) { return true; }
13290da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu
13300da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xuprotected:
13310da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu  virtual void EmitImpl(llvm::Serializer& S) const;
13320da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
13330da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu  friend class Type;
13347cbb14653934a298c09002b87704dc6531261771Steve Naroff};
13354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
13364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TagType : public Type {
133798b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// Stores the TagDecl associated with this type. The decl will
133898b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// point to the TagDecl that actually defines the entity (or is a
133998b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// definition in progress), if there is such a definition. The
134098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// single-bit value will be non-zero when this tag is in the
134198b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// process of being defined.
13429c7825b737617339724d43bd04960852271f08e2Douglas Gregor  mutable llvm::PointerIntPair<TagDecl *, 1> decl;
134346a837c7ced306c55d1686cea5f77cb7a2f3b908Ted Kremenek  friend class ASTContext;
134498b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  friend class TagDecl;
13451d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor
13461d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorprotected:
13471b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  // FIXME: We'll need the user to pass in information about whether
13481b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  // this type is dependent or not, because we don't have enough
13491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  // information to compute it here.
13504fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  TagType(TypeClass TC, TagDecl *D, QualType can)
13514fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : Type(TC, can, /*Dependent=*/false), decl(D, 0) {}
13521d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor
13531d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorpublic:
135498b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  TagDecl *getDecl() const { return decl.getPointer(); }
13554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
135698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// @brief Determines whether this type is in the process of being
135798b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// defined.
135898b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  bool isBeingDefined() const { return decl.getInt(); }
135998b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); }
136098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor
13614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
1362734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  void getAsStringInternal(std::string &InnerString,
1363734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                           bool SuppressTagKind) const;
1364734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
13654fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const Type *T) {
13664fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
13674fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  }
13684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const TagType *) { return true; }
13694fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const RecordType *) { return true; }
13704fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const EnumType *) { return true; }
13714fa58905062efa6a12137b1983a1367220182a20Douglas Gregor
13728db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenekprotected:
13738db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
137464be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
13758db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenek  friend class Type;
13764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
13774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
13781baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
13791baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of structs/unions/classes.
13801baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass RecordType : public TagType {
1381ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidisprotected:
13823cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis  explicit RecordType(RecordDecl *D)
13834fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { }
13844fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
13854fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { }
13861d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor  friend class ASTContext;   // ASTContext creates these.
13871baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic:
13881baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
13891baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  RecordDecl *getDecl() const {
13901baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
13911baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  }
13921baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
13931baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // FIXME: This predicate is a helper to QualType/Type. It needs to
13941baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // recursively check all fields for const-ness. If any field is declared
13951baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // const, it needs to return false.
13961baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  bool hasConstFields() const { return false; }
13971baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
13981baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // FIXME: RecordType needs to check when it is created that all fields are in
13991baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // the same address space, and return that.
14001baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  unsigned getAddressSpace() const { return 0; }
14011baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
1402eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  static bool classof(const TagType *T);
1403eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  static bool classof(const Type *T) {
1404eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
1405eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  }
14061baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  static bool classof(const RecordType *) { return true; }
14071baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner};
14081baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
14091baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
14101baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of enums.
14111baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass EnumType : public TagType {
14123cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis  explicit EnumType(EnumDecl *D)
14134fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { }
14141d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor  friend class ASTContext;   // ASTContext creates these.
14151baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic:
14161baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
14171baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  EnumDecl *getDecl() const {
14181baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
14191baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  }
14201baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
1421eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  static bool classof(const TagType *T);
1422eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  static bool classof(const Type *T) {
1423eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
1424eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  }
14251baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  static bool classof(const EnumType *) { return true; }
14261baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner};
14271baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
1428a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
1429a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  unsigned Depth : 16;
1430a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  unsigned Index : 16;
1431a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  IdentifierInfo *Name;
1432dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1433a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N,
1434a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor                       QualType Canon)
1435a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true),
1436a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor      Depth(D), Index(I), Name(N) { }
1437dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1438a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  TemplateTypeParmType(unsigned D, unsigned I)
1439a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true),
1440a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor      Depth(D), Index(I), Name(0) { }
1441dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1442a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  friend class ASTContext;  // ASTContext creates these
1443dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1444a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorpublic:
1445a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  unsigned getDepth() const { return Depth; }
1446a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  unsigned getIndex() const { return Index; }
1447a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  IdentifierInfo *getName() const { return Name; }
1448a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor
1449dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  virtual void getAsStringInternal(std::string &InnerString) const;
14501baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
1451a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
1452a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    Profile(ID, Depth, Index, Name);
1453a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  }
1454a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor
1455a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
1456a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor                      unsigned Index, IdentifierInfo *Name) {
1457a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    ID.AddInteger(Depth);
1458a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    ID.AddInteger(Index);
1459a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    ID.AddPointer(Name);
1460a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  }
1461a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor
1462dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  static bool classof(const Type *T) {
1463dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor    return T->getTypeClass() == TemplateTypeParm;
1464dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  }
1465dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
1466dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1467dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorprotected:
1468dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
1469dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1470dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  friend class Type;
1471dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor};
1472a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor
14738e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// \brief Represents the type of a class template specialization as
14748e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// written in the source code.
14758e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor///
14768e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// Class template specialization types represent the syntactic form
14778e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// of a template-id that refers to a type, e.g., @c vector<int>. All
14788e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization types are syntactic sugar, whose
14798e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// canonical type will point to some other type node that represents
14808e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// the instantiation or class template specialization. For example, a
14818e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization type of @c vector<int> will refer to
14828e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// a tag type for the instantiation
14838e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// @c std::vector<int, std::allocator<int>>.
14848e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorclass ClassTemplateSpecializationType
14858e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  : public Type, public llvm::FoldingSetNode {
14868e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
14878e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  // FIXME: Do we want templates to have a representation in the type
14888e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  // system? It will probably help with dependent templates and
14898e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  // possibly with template-names preceded by a nested-name-specifier.
14908e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  TemplateDecl *Template;
14918e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
1492f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// \brief - The number of template arguments named in this class
1493f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// template specialization.
14948e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  unsigned NumArgs;
14958e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
1496f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  ClassTemplateSpecializationType(TemplateDecl *T,
1497f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor                                  const TemplateArgument *Args,
1498f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor                                  unsigned NumArgs, QualType Canon);
14998e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15006f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor  virtual void Destroy(ASTContext& C);
15016f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor
15028e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  friend class ASTContext;  // ASTContext creates these
15038e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15048e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorpublic:
1505f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// \brief Determine whether any of the given template arguments are
1506f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// dependent.
1507f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
1508f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor                                            unsigned NumArgs);
1509f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor
151056d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
151156d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor  /// enclosing the template arguments.
151256d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
151356d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor                                               unsigned NumArgs);
151456d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor
1515f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  typedef const TemplateArgument * iterator;
1516f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor
1517f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  iterator begin() const { return getArgs(); }
1518f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  iterator end() const;
1519f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor
15208e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  /// \brief Retrieve the template that we are specializing.
15218e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  TemplateDecl *getTemplate() const { return Template; }
15228e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
1523f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// \brief Retrieve the template arguments.
1524f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  const TemplateArgument *getArgs() const {
1525f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
1526f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  }
1527f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor
1528f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// \brief Retrieve the number of template arguments.
15298e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
15308e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15318e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
15328e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  /// \precondition @c isArgType(Arg)
1533f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  const TemplateArgument &getArg(unsigned Idx) const;
15348e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15358e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  virtual void getAsStringInternal(std::string &InnerString) const;
15368e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15378e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
1538f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor    Profile(ID, Template, getArgs(), NumArgs);
15398e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  }
15408e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15418e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateDecl *T,
1542f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor                      const TemplateArgument *Args, unsigned NumArgs);
15438e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15448e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  static bool classof(const Type *T) {
15458e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor    return T->getTypeClass() == ClassTemplateSpecialization;
15468e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  }
15478e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  static bool classof(const ClassTemplateSpecializationType *T) { return true; }
15488e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15498e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorprotected:
15508e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
15518e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
15528e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  friend class Type;
15538e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor};
15548e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
1555734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// \brief Represents a type that was referred to via a qualified
1556734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// name, e.g., N::M::type.
1557734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor///
1558734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// This type is used to keep track of a type name as written in the
1559734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// source code, including any nested-name-specifiers.
1560734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode {
1561734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief The number of components in the qualified name, not
1562734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// counting the final type.
1563734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  unsigned NumComponents;
1564734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1565734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief The type that this qualified name refers to.
1566734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  QualType NamedType;
1567734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1568734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  QualifiedNameType(const NestedNameSpecifier *Components,
1569734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                    unsigned NumComponents, QualType NamedType,
1570734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                    QualType CanonType);
1571734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1572734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  friend class ASTContext;  // ASTContext creates these
1573734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1574734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorpublic:
1575734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  typedef const NestedNameSpecifier * iterator;
1576734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1577734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  iterator begin() const { return getComponents(); }
1578734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  iterator end() const { return getComponents() + getNumComponents(); }
1579734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1580734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief Retrieve the array of nested-name-specifier components.
1581734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  const NestedNameSpecifier *getComponents() const {
1582734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor    return reinterpret_cast<const NestedNameSpecifier *>(this + 1);
1583734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  }
1584734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1585734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief Retrieve the number of nested-name-specifier components.
1586734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  unsigned getNumComponents() const { return NumComponents; }
1587734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1588734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
1589734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  QualType getNamedType() const { return NamedType; }
1590734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1591734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  virtual void getAsStringInternal(std::string &InnerString) const;
1592734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1593734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
1594734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor    Profile(ID, getComponents(), NumComponents, NamedType);
1595734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  }
1596734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1597734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID,
1598734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                      const NestedNameSpecifier *Components,
1599734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                      unsigned NumComponents,
1600734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                      QualType NamedType);
1601734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1602734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  static bool classof(const Type *T) {
1603734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor    return T->getTypeClass() == QualifiedName;
1604734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  }
1605734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  static bool classof(const QualifiedNameType *T) { return true; }
1606734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1607734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorprotected:
1608734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
1609734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1610734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  friend class Type;
1611734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor};
1612734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1613f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
1614f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// object oriented design.  They basically correspond to C++ classes.  There
1615f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and
1616f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// qualified interfaces, which are qualified with a protocol list like
1617f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// "NSString<NSCopyable, NSAmazing>".  Qualified interface types are instances
1618f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType.
161942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCInterfaceType : public Type {
162042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCInterfaceDecl *Decl;
16210c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanianprotected:
162242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) :
16231b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Type(tc, QualType(), /*Dependent=*/false), Decl(D) { }
162481f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff  friend class ASTContext;  // ASTContext creates these.
162581f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroffpublic:
162681f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff
162742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCInterfaceDecl *getDecl() const { return Decl; }
162881f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff
1629f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// qual_iterator and friends: this provides access to the (potentially empty)
1630f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// list of protocols qualifying this interface.  If this is an instance of
1631f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an
1632f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// empty list if there are no qualifying protocols.
1633f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1634f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  inline qual_iterator qual_begin() const;
1635f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  inline qual_iterator qual_end() const;
1636f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; }
1637f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1638f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// getNumProtocols - Return the number of qualifying protocols in this
1639f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// interface type, or 0 if there are none.
1640f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  inline unsigned getNumProtocols() const;
1641f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1642d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner  /// getProtocol - Return the specified qualifying protocol.
1643d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner  inline ObjCProtocolDecl *getProtocol(unsigned i) const;
164491193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian
1645f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1646f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
164781f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff  static bool classof(const Type *T) {
1648b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner    return T->getTypeClass() == ObjCInterface ||
1649b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner           T->getTypeClass() == ObjCQualifiedInterface;
165081f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff  }
165142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
165281f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff};
165381f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff
165442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types
1655e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>.
1656e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner///
1657c5a342d3b1cc5fa6eef09653a6d8d091928366c0Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in
1658c5a342d3b1cc5fa6eef09653a6d8d091928366c0Fariborz Jahanian/// alphabetical order.
165942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType,
16600c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanian                                   public llvm::FoldingSetNode {
16610c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanian
1662c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian  // List of protocols for this protocol conforming object type
1663c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian  // List is sorted on protocol name. No protocol is enterred more than once.
1664f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols;
1665c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian
166642730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D,
1667b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner                             ObjCProtocolDecl **Protos, unsigned NumP) :
166842730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek    ObjCInterfaceType(ObjCQualifiedInterface, D),
1669d855a6ead44e3a875179400c472ac0b37df35f70Chris Lattner    Protocols(Protos, Protos+NumP) { }
167091193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  friend class ASTContext;  // ASTContext creates these.
1671c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanianpublic:
1672c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian
1673d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner  ObjCProtocolDecl *getProtocol(unsigned i) const {
167491193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian    return Protocols[i];
167591193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  }
167691193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  unsigned getNumProtocols() const {
167791193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian    return Protocols.size();
167891193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  }
1679b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner
1680b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  qual_iterator qual_begin() const { return Protocols.begin(); }
1681b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  qual_iterator qual_end() const   { return Protocols.end(); }
1682b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner
168391193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  virtual void getAsStringInternal(std::string &InnerString) const;
168491193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian
168591193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  void Profile(llvm::FoldingSetNodeID &ID);
168691193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  static void Profile(llvm::FoldingSetNodeID &ID,
1687fd5690fe6b5ea1c553dfe20f99d3fef269a50bd1Chris Lattner                      const ObjCInterfaceDecl *Decl,
168842730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
168991193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian
1690c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian  static bool classof(const Type *T) {
169142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek    return T->getTypeClass() == ObjCQualifiedInterface;
1692c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian  }
169342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  static bool classof(const ObjCQualifiedInterfaceType *) { return true; }
1694c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian};
1695f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1696f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const {
1697f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  if (const ObjCQualifiedInterfaceType *QIT =
1698f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner         dyn_cast<ObjCQualifiedInterfaceType>(this))
1699f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner    return QIT->qual_begin();
1700f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  return 0;
1701f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner}
1702f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const {
1703f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  if (const ObjCQualifiedInterfaceType *QIT =
1704f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner         dyn_cast<ObjCQualifiedInterfaceType>(this))
1705f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner    return QIT->qual_end();
1706f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  return 0;
1707f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner}
1708f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1709f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// getNumProtocols - Return the number of qualifying protocols in this
1710f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// interface type, or 0 if there are none.
1711f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline unsigned ObjCInterfaceType::getNumProtocols() const {
1712f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  if (const ObjCQualifiedInterfaceType *QIT =
1713f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner        dyn_cast<ObjCQualifiedInterfaceType>(this))
1714f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner    return QIT->getNumProtocols();
1715f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  return 0;
1716f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner}
1717f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1718d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner/// getProtocol - Return the specified qualifying protocol.
1719d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattnerinline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const {
1720d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner  return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i);
1721f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner}
1722f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1723f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1724e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1725e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// ObjCQualifiedIdType - to represent id<protocol-list>.
1726e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner///
1727e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// Duplicate protocols are removed and protocol list is canonicalized to be in
1728e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// alphabetical order.
172942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCQualifiedIdType : public Type,
1730e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian                            public llvm::FoldingSetNode {
1731e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  // List of protocols for this protocol conforming 'id' type
1732e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  // List is sorted on protocol name. No protocol is enterred more than once.
173342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
1734e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
17354a68fe04deb7ab89ac7566dc55b3b623129c72e5Chris Lattner  ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP)
17361b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(ObjCQualifiedId, QualType()/*these are always canonical*/,
1737f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman           /*Dependent=*/false),
1738e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  Protocols(Protos, Protos+NumP) { }
1739e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  friend class ASTContext;  // ASTContext creates these.
1740e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianpublic:
1741e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
174242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCProtocolDecl *getProtocols(unsigned i) const {
1743e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian    return Protocols[i];
1744e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  }
1745e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  unsigned getNumProtocols() const {
1746e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian    return Protocols.size();
1747e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  }
174842730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCProtocolDecl **getReferencedProtocols() {
1749957442db1d23f62ee2d0d71310bee240606b267dFariborz Jahanian    return &Protocols[0];
1750b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  }
1751b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner
1752b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1753b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  qual_iterator qual_begin() const { return Protocols.begin(); }
1754b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  qual_iterator qual_end() const   { return Protocols.end(); }
1755e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1756e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  virtual void getAsStringInternal(std::string &InnerString) const;
1757e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1758e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  void Profile(llvm::FoldingSetNodeID &ID);
17594a68fe04deb7ab89ac7566dc55b3b623129c72e5Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID,
176042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1761e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1762e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  static bool classof(const Type *T) {
176342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek    return T->getTypeClass() == ObjCQualifiedId;
1764e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  }
176542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  static bool classof(const ObjCQualifiedIdType *) { return true; }
1766e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1767e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian};
1768c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian
1769262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// ObjCQualifiedClassType - to represent Class<protocol-list>.
1770262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff///
1771262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in
1772262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// alphabetical order.
1773262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroffclass ObjCQualifiedClassType : public Type,
1774262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff                               public llvm::FoldingSetNode {
1775262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  // List of protocols for this protocol conforming 'id' type
1776262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  // List is sorted on protocol name. No protocol is enterred more than once.
1777262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
1778262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1779262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  ObjCQualifiedClassType(ObjCProtocolDecl **Protos, unsigned NumP)
1780d305a86f087fd359cf0f033eba0c968e55a61ff4Steve Naroff    : Type(ObjCQualifiedClass, QualType()/*these are always canonical*/,
1781262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff           /*Dependent=*/false),
1782262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  Protocols(Protos, Protos+NumP) { }
1783262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  friend class ASTContext;  // ASTContext creates these.
1784262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroffpublic:
1785262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1786262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  ObjCProtocolDecl *getProtocols(unsigned i) const {
1787262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff    return Protocols[i];
1788262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  }
1789262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  unsigned getNumProtocols() const {
1790262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff    return Protocols.size();
1791262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  }
1792262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  ObjCProtocolDecl **getReferencedProtocols() {
1793262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff    return &Protocols[0];
1794262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  }
1795262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1796262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1797262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  qual_iterator qual_begin() const { return Protocols.begin(); }
1798262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  qual_iterator qual_end() const   { return Protocols.end(); }
1799262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1800262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
1801262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1802262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
1803262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  static void Profile(llvm::FoldingSetNodeID &ID,
1804262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1805262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1806262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  static bool classof(const Type *T) {
1807d305a86f087fd359cf0f033eba0c968e55a61ff4Steve Naroff    return T->getTypeClass() == ObjCQualifiedClass;
1808262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  }
1809262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  static bool classof(const ObjCQualifiedClassType *) { return true; }
1810262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1811262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff};
18124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
1813b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner// Inline function definitions.
18144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
18152a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers.
18162a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline QualType QualType::getUnqualifiedType() const {
181735fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  Type *TP = getTypePtr();
1818b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian  if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP))
1819b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian    TP = EXTQT->getBaseType();
182035fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  return QualType(TP, 0);
18212a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb}
18222a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
18232a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getAddressSpace - Return the address space of this type.
18242a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline unsigned QualType::getAddressSpace() const {
182501ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner  QualType CT = getTypePtr()->getCanonicalTypeInternal();
182601ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
1827a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner    return AT->getElementType().getAddressSpace();
182801ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(CT))
1829efc11216a5755f69b5540289aa2dd374d4bc82abNate Begeman    return RT->getAddressSpace();
1830b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian  if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT))
1831b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian    return EXTQT->getAddressSpace();
18322a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return 0;
18332a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb}
1834b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner
1835af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
1836af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const {
1837af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  QualType CT = getTypePtr()->getCanonicalTypeInternal();
1838af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
1839af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian      return AT->getElementType().getObjCGCAttr();
1840af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT))
1841af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian    return EXTQT->getObjCGCAttr();
1842184541a6a7d218583d79d408534f77c27b7b8c6eFariborz Jahanian  if (const PointerType *PT = CT->getAsPointerType())
1843184541a6a7d218583d79d408534f77c27b7b8c6eFariborz Jahanian    return PT->getPointeeType().getObjCGCAttr();
18447029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner  return GCNone;
1845af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian}
1846af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian
18473fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
18483fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
18493fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// is more qualified than "const int", "volatile int", and
18503fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int". However, it is not more qualified than "const volatile
18513fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int".
18523fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const {
18533fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  // FIXME: Handle address spaces
18543fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  unsigned MyQuals = this->getCVRQualifiers();
18553fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  unsigned OtherQuals = Other.getCVRQualifiers();
18564459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor  assert(this->getAddressSpace() == 0 && "Address space not checked");
18574459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor  assert(Other.getAddressSpace() == 0 && "Address space not checked");
18583fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
18593fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor}
18603fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor
18613fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
18623fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// as qualified as the Other type. For example, "const volatile
18633fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
18643fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int", and "const volatile int".
18653fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
18663fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  // FIXME: Handle address spaces
18673fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  unsigned MyQuals = this->getCVRQualifiers();
18683fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  unsigned OtherQuals = Other.getCVRQualifiers();
18694459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor  assert(this->getAddressSpace() == 0 && "Address space not checked");
18704459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor  assert(Other.getAddressSpace() == 0 && "Address space not checked");
18713fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  return (MyQuals | OtherQuals) == MyQuals;
18723fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor}
18733fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor
18743fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
18753fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int&), returns the type that the reference refers to ("const
18763fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
18773fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// throughout Sema to implement C++ 5p6:
18783fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///
18793fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
18803fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
18813fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///   analysis, the expression designates the object or function
18823fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
18833fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline QualType QualType::getNonReferenceType() const {
18843fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  if (const ReferenceType *RefType = (*this)->getAsReferenceType())
18853fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor    return RefType->getPointeeType();
18863fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  else
18873fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor    return *this;
18883fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor}
18893fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor
18905c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenekinline const TypedefType* Type::getAsTypedefType() const {
18915c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek  return dyn_cast<TypedefType>(this);
18925c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek}
1893f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const {
1894f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  if (const PointerType *PT = getAsPointerType())
1895f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner    return PT->getPointeeType()->getAsObjCInterfaceType();
1896f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  return 0;
1897f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner}
1898f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner
1899a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address
1900a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner// space qualifiers if present.
1901b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isFunctionType() const {
19022a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<FunctionType>(CanonicalType.getUnqualifiedType());
1903b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
1904b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isPointerType() const {
19052a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<PointerType>(CanonicalType.getUnqualifiedType());
1906b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
19077aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffinline bool Type::isBlockPointerType() const {
19087aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    return isa<BlockPointerType>(CanonicalType);
19097aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff}
1910cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerinline bool Type::isReferenceType() const {
1911cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner  return isa<ReferenceType>(CanonicalType.getUnqualifiedType());
1912cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner}
1913ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isLValueReferenceType() const {
1914ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType());
1915ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}
1916ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isRValueReferenceType() const {
1917ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType());
1918ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}
191983b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenekinline bool Type::isFunctionPointerType() const {
192074a340749eb63af1ba7098c67f3ef72bd48f5ae8Ted Kremenek  if (const PointerType* T = getAsPointerType())
192183b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek    return T->getPointeeType()->isFunctionType();
192283b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek  else
192383b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek    return false;
192483b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek}
19257555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberPointerType() const {
19267555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  return isa<MemberPointerType>(CanonicalType.getUnqualifiedType());
19277555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl}
19287555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
19297555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  if (const MemberPointerType* T = getAsMemberPointerType())
19307555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    return T->getPointeeType()->isFunctionType();
19317555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  else
19327555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    return false;
19337555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl}
1934b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isArrayType() const {
19352a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<ArrayType>(CanonicalType.getUnqualifiedType());
1936b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
1937a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isConstantArrayType() const {
1938a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType());
1939a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner}
1940a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isIncompleteArrayType() const {
1941a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType());
1942a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner}
1943a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isVariableArrayType() const {
1944a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<VariableArrayType>(CanonicalType.getUnqualifiedType());
1945a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner}
19461b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorinline bool Type::isDependentSizedArrayType() const {
19471b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType());
19481b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor}
1949b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isRecordType() const {
19502a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<RecordType>(CanonicalType.getUnqualifiedType());
1951b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
19523277df47de6b65b55721726dc3f7b294e70ef6feChris Lattnerinline bool Type::isAnyComplexType() const {
1953a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ComplexType>(CanonicalType.getUnqualifiedType());
19543277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner}
1955b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isVectorType() const {
19562a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<VectorType>(CanonicalType.getUnqualifiedType());
1957b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
1958af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemaninline bool Type::isExtVectorType() const {
1959af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  return isa<ExtVectorType>(CanonicalType.getUnqualifiedType());
1960b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
196142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCInterfaceType() const {
1962a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType());
1963b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner}
1964b06cf30badcddfea862bc9a538447453bdd94598Chris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const {
1965a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType());
1966550e05034c6c8efcb7ab4c65f58048eee0892237Fariborz Jahanian}
196742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
1968a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType());
1969dcb2b1e489948a570ee07ca65e12d42edffa20efFariborz Jahanian}
1970dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorinline bool Type::isTemplateTypeParmType() const {
1971dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType());
1972dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor}
1973dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1974c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
197545014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor  if (const BuiltinType *BT = getAsBuiltinType())
1976c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
1977c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar      return true;
1978c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar  return false;
1979c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar}
1980c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar
198100fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// \brief Determines whether this is a type for which one can define
198200fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// an overloaded operator.
198300fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregorinline bool Type::isOverloadableType() const {
198400fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
198545014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor}
198645014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor
1987fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
1988fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
1989fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar          isObjCInterfaceType() || isObjCQualifiedIdType() ||
1990fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar          isObjCQualifiedInterfaceType());
1991fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar}
1992fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar
19937c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
19947c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian  return (isObjCInterfaceType() || isObjCQualifiedIdType() ||
19957c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian          isObjCQualifiedInterfaceType());
19967c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian}
19977c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian
1998da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
1999da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// diagnostic with <<.
2000da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2001da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner                                           QualType T) {
2002da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
2003da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner                  Diagnostic::ak_qualtype);
2004da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner  return DB;
2005da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner}
2006da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner
20074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}  // end namespace clang
20084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
20094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#endif
2010