Type.h revision a6fe878ddf8804734de57b1bbd1c8a25ff963024
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;
346a6fe878ddf8804734de57b1bbd1c8a25ff963024Chris Lattner  bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; }
347a6fe878ddf8804734de57b1bbd1c8a25ff963024Chris Lattner  bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; }
3487931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner  bool isPointerType() const;
3497aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  bool isBlockPointerType() const;
350f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner  bool isReferenceType() const;
351ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  bool isLValueReferenceType() const;
352ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  bool isRValueReferenceType() const;
353cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner  bool isFunctionPointerType() const;
3547555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  bool isMemberPointerType() const;
3557555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  bool isMemberFunctionPointerType() const;
356e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isArrayType() const;
357a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  bool isConstantArrayType() const;
358a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  bool isIncompleteArrayType() const;
359a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  bool isVariableArrayType() const;
3601b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  bool isDependentSizedArrayType() const;
361e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isRecordType() const;
3622e78db3510b136b3f961af202e6a1a3df4839172Chris Lattner  bool isClassType() const;
363e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  bool isStructureType() const;
36436e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff  bool isUnionType() const;
365b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
366b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isVectorType() const;                    // GCC vector type.
367af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  bool isExtVectorType() const;                 // Extended vector type.
368b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isObjCInterfaceType() const;             // NSString or NSString<foo>
369b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
370b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
371dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
3721b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
3731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
3741b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// that its definition somehow depends on a template parameter
3751b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// (C++ [temp.dep.type]).
3761b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  bool isDependentType() const { return Dependent; }
37700fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor  bool isOverloadableType() const;
378dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
379fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
380fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
381fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
382fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  /// interface types.
383fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  bool hasPointerRepresentation() const;
384fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar
3857c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
3867c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
3877c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian  bool hasObjCPointerRepresentation() const;
3887c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian
389e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  // Type Checking Functions: Check to see if this type is structurally the
39035fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
39135fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  // the best type we can.
3927555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const BuiltinType *getAsBuiltinType() const;
3937555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const FunctionType *getAsFunctionType() const;
3944fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  const FunctionNoProtoType *getAsFunctionNoProtoType() const;
3954fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  const FunctionProtoType *getAsFunctionProtoType() const;
3967931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner  const PointerType *getAsPointerType() const;
3977aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  const BlockPointerType *getAsBlockPointerType() const;
398f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner  const ReferenceType *getAsReferenceType() const;
399ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  const LValueReferenceType *getAsLValueReferenceType() const;
400ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  const RValueReferenceType *getAsRValueReferenceType() const;
4017555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const MemberPointerType *getAsMemberPointerType() const;
4029c7825b737617339724d43bd04960852271f08e2Douglas Gregor  const TagType *getAsTagType() const;
403e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  const RecordType *getAsRecordType() const;
4045c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek  const RecordType *getAsStructureType() const;
4051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
4065c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek  const TypedefType *getAsTypedefType() const;
407e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  const RecordType *getAsUnionType() const;
4080832dbca0e11ee020bbed181c515b3835158436eEli Friedman  const EnumType *getAsEnumType() const;
409e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner  const VectorType *getAsVectorType() const; // GCC vector type.
4107a85fa1ba94c9f4cf960463dd3eb444ef6f89446Chris Lattner  const ComplexType *getAsComplexType() const;
41136e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
412af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  const ExtVectorType *getAsExtVectorType() const; // Extended vector type.
413b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  const ObjCInterfaceType *getAsObjCInterfaceType() const;
414b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const;
415b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner  const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const;
416dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  const TemplateTypeParmType *getAsTemplateTypeParmType() const;
417dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
4188e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  const ClassTemplateSpecializationType *
4197e50826d3559f284eee6659f0aa159c68f504b34Douglas Gregor    getAsClassTemplateSpecializationType() const;
4208e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
421f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC
422f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  /// interface, return the interface type, otherwise return null.
423f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const;
424f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner
425a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
426a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
427a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
428a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
429a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner
4302afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
4315c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
4322afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
4332afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
4342ea769b494649b5ca4864acf154f2fedc7718029Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
4352afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner  /// concrete.
436a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  QualType getDesugaredType() const;
4372afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner
4384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// More type predicates useful for type checking/promotion
4394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
4404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
4414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// isSignedIntegerType - Return true if this is an integer type that is
442bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
443bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
444bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// integer element type.
4454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isSignedIntegerType() const;
4464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
4474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// isUnsignedIntegerType - Return true if this is an integer type that is
448bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
449bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
450bbe686be29157b575e53fbed328613117b525f26Chris Lattner  /// element type.
4514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isUnsignedIntegerType() const;
452bbe686be29157b575e53fbed328613117b525f26Chris Lattner
4534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// isConstantSizeType - Return true if this is not a variable sized type,
4540448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
4550448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner  /// incomplete types.
45662f67fd7f670f1a8b222c6565b257c05e8e80faeEli Friedman  bool isConstantSizeType() const;
457a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner
4584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getCanonicalTypeInternal() const { return CanonicalType; }
459a55e321bd645398b514e246981c04a4889ee2472Chris Lattner  void dump() const;
4604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const = 0;
4614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *) { return true; }
462034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
463034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected:
464034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  /// Emit - Emit a Type to bitcode.  Used by ASTContext.
465034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  void Emit(llvm::Serializer& S) const;
466034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
467034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  /// Create - Construct a Type from bitcode.  Used by ASTContext.
468034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S);
469034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
470034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  /// EmitImpl - Subclasses must implement this method in order to
471034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  ///  be serialized.
4729c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar  // FIXME: Make this abstract once implemented.
4739c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar  virtual void EmitImpl(llvm::Serializer& S) const {
474126949ecf2a1051fa3271b42936129ea0299be99Gabor Greif    assert(false && "Serialization for type not supported.");
4759c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar  }
4764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
4774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
478b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26
479b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// This supports all kinds of type attributes; including,
480b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// address space qualified types, objective-c's __weak and
481b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// __strong attributes.
4822a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb///
483b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode {
48435fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  /// BaseType - This is the underlying type that this qualifies.  All CVR
48535fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  /// qualifiers are stored on the QualType that references this type, so we
48635fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  /// can't have any here.
48735fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  Type *BaseType;
488dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian
4892a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  /// Address Space ID - The address space ID this type is qualified with.
4902a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  unsigned AddressSpace;
491dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian  /// GC __weak/__strong attributes
492af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  QualType::GCAttrTypes GCAttrType;
493dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian
494dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian  ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace,
495af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian              QualType::GCAttrTypes gcAttr) :
49618b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner      Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base),
49718b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner      AddressSpace(AddrSpace), GCAttrType(gcAttr) {
49818b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner    assert(!isa<ExtQualType>(BaseType) &&
49918b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner           "Cannot have ExtQualType of ExtQualType");
50018b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner  }
5012a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  friend class ASTContext;  // ASTContext creates these.
5022a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambpublic:
50335fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  Type *getBaseType() const { return BaseType; }
504af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; }
5051e124fe3e31ab37c45b6fbe6a8075e987fc04408Fariborz Jahanian  unsigned getAddressSpace() const { return AddressSpace; }
5062a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5072a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  virtual void getAsStringInternal(std::string &InnerString) const;
5082a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5092a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  void Profile(llvm::FoldingSetNodeID &ID) {
5101e124fe3e31ab37c45b6fbe6a8075e987fc04408Fariborz Jahanian    Profile(ID, getBaseType(), AddressSpace, GCAttrType);
5112a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  }
51235fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, Type *Base,
513af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian                      unsigned AddrSpace, QualType::GCAttrTypes gcAttr) {
51435fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner    ID.AddPointer(Base);
5152a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb    ID.AddInteger(AddrSpace);
5161e124fe3e31ab37c45b6fbe6a8075e987fc04408Fariborz Jahanian    ID.AddInteger(gcAttr);
5172a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  }
5182a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
519b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian  static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; }
520b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian  static bool classof(const ExtQualType *) { return true; }
5212a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5222a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambprotected:
5232a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  virtual void EmitImpl(llvm::Serializer& S) const;
5242a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
5252a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  friend class Type;
5262a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb};
5272a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5282a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
5294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
5304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types are always canonical and have a literal name field.
5314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass BuiltinType : public Type {
5324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
5334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  enum Kind {
5344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Void,
5354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Bool,     // This is bool and/or _Bool.
5374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Char_U,   // This is 'char' for targets where char is unsigned.
5384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    UChar,    // This is explicitly qualified unsigned char.
5394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    UShort,
5404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    UInt,
5414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ULong,
5424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ULongLong,
5434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Char_S,   // This is 'char' for targets where char is signed.
5454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    SChar,    // This is explicitly qualified signed char.
54685bd81edce4057156d7f49408147f07daa675096Argiris Kirtzidis    WChar,    // This is 'wchar_t' for C++.
5474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Short,
5484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Int,
5494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Long,
5504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    LongLong,
5514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
552d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor    Float, Double, LongDouble,
553d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor
5541b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Overload,  // This represents the type of an overloaded function declaration.
5551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Dependent  // This represents the type of a type-dependent expression.
5564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  };
5574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate:
5584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  Kind TypeKind;
5594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
5601b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  BuiltinType(Kind K)
5611b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)),
5621b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor      TypeKind(K) {}
5634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  Kind getKind() const { return TypeKind; }
5654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  const char *getName() const;
5664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
5684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
5694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
5704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const BuiltinType *) { return true; }
5714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
5724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
573ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't
574ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman/// want to or can't map to named integer types.  These always have a lower
575ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman/// integer rank than builtin types of the same width.
576ff3fcdf47370a4577d971a2adefd259807152078Eli Friedmanclass FixedWidthIntType : public Type {
577ff3fcdf47370a4577d971a2adefd259807152078Eli Friedmanprivate:
578ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  unsigned Width;
579ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  bool Signed;
580ff3fcdf47370a4577d971a2adefd259807152078Eli Friedmanpublic:
581ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false),
582ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman                                          Width(W), Signed(S) {}
583ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman
584ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  unsigned getWidth() const { return Width; }
585ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  bool isSigned() const { return Signed; }
586ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  const char *getName() const;
587ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman
588ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  virtual void getAsStringInternal(std::string &InnerString) const;
589ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman
590ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; }
591ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman  static bool classof(const FixedWidthIntType *) { return true; }
592ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman};
593ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman
5944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
5954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types (_Complex float etc) as well as the GCC integer complex extensions.
5964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
5974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass ComplexType : public Type, public llvm::FoldingSetNode {
5984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType ElementType;
5994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  ComplexType(QualType Element, QualType CanonicalPtr) :
6001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType()),
6011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    ElementType(Element) {
6024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
6044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
6054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getElementType() const { return ElementType; }
6064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
608034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
6094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
6104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Profile(ID, getElementType());
6114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
6134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(Element.getAsOpaquePtr());
6144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
6174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const ComplexType *) { return true; }
61878f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek
619034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected:
620034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
621034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
622034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  friend class Type;
6234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
6244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
625554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
626cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner///
627554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
628cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner  QualType PointeeType;
6294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  PointerType(QualType Pointee, QualType CanonicalPtr) :
631554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar    Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) {
6324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
6344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
6354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
6374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
638554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
639554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar
6404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
6414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Profile(ID, getPointeeType());
6424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
6444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(Pointee.getAsOpaquePtr());
6454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
6464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
6484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const PointerType *) { return true; }
649034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
650034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected:
651034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
652034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
653034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  friend class Type;
6544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
6554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
6567aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// BlockPointerType - pointer to a block type.
6577aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// This type is to represent types syntactically represented as
6587aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
6597aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff///
6607aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
6617aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
6627aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
6631b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType()),
6641b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    PointeeType(Pointee) {
6657aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  }
6667aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
6677aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffpublic:
6687aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6697aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
6707aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
6717aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6727aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
6737aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6747aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
6757aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff      Profile(ID, getPointeeType());
6767aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  }
6777aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
6787aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
6797aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  }
6807aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6817aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  static bool classof(const Type *T) {
6827aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    return T->getTypeClass() == BlockPointer;
6837aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  }
6847aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
6857aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
6867aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff  protected:
6877aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    virtual void EmitImpl(llvm::Serializer& S) const;
6887aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
6897aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    friend class Type;
6907aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff};
6917aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff
692ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
6934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
694554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
695554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar  QualType PointeeType;
696554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar
697ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected:
698ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) :
699ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    Type(tc, CanonicalRef, Referencee->isDependentType()),
700554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar    PointeeType(Referencee) {
7014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
7024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
703554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
704554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar
7054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
706cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner    Profile(ID, getPointeeType());
7074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
7084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
7094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(Referencee.getAsOpaquePtr());
7104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
7114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
712ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const Type *T) {
713ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    return T->getTypeClass() == LValueReference ||
714ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl           T->getTypeClass() == RValueReference;
715ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
7164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const ReferenceType *) { return true; }
7177555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7187555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlprotected:
7197555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  virtual void EmitImpl(llvm::Serializer& S) const;
720ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl};
721ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
722ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
723ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl///
724ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass LValueReferenceType : public ReferenceType {
725ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  LValueReferenceType(QualType Referencee, QualType CanonicalRef) :
726ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    ReferenceType(LValueReference, Referencee, CanonicalRef) {
727ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
728ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  friend class ASTContext; // ASTContext creates these
729ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic:
730ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  virtual void getAsStringInternal(std::string &InnerString) const;
731ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
732ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const Type *T) {
733ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    return T->getTypeClass() == LValueReference;
734ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
735ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
736ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
737ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected:
738ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
739ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  friend class Type;
740ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl};
741ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
742ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
743ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl///
744ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass RValueReferenceType : public ReferenceType {
745ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
746ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    ReferenceType(RValueReference, Referencee, CanonicalRef) {
747ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
748ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  friend class ASTContext; // ASTContext creates these
749ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic:
750ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  virtual void getAsStringInternal(std::string &InnerString) const;
751ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
752ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const Type *T) {
753ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl    return T->getTypeClass() == RValueReference;
754ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  }
755ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
756ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl
757ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected:
7587555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
7597555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  friend class Type;
7607555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl};
7617555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7627555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
7637555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl///
7647555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
7657555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  QualType PointeeType;
7667555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
7677555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
7687555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const Type *Class;
7697555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7707555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
7717555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    Type(MemberPointer, CanonicalPtr,
7727555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl         Cls->isDependentType() || Pointee->isDependentType()),
7737555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    PointeeType(Pointee), Class(Cls) {
7747555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  }
7757555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  friend class ASTContext; // ASTContext creates these.
7767555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlpublic:
7777555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7787555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  QualType getPointeeType() const { return PointeeType; }
7797555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7807555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  const Type *getClass() const { return Class; }
7817555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7827555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  virtual void getAsStringInternal(std::string &InnerString) const;
7837555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7847555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
7857555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    Profile(ID, getPointeeType(), getClass());
7867555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  }
7877555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
7887555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl                      const Type *Class) {
7897555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
7907555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    ID.AddPointer(Class);
7917555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  }
7927555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7937555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static bool classof(const Type *T) {
7947555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    return T->getTypeClass() == MemberPointer;
7957555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  }
7967555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
7977555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl
7987555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlprotected:
7997555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  virtual void EmitImpl(llvm::Serializer& S) const;
8007555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
8017555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  friend class Type;
8024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
8034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
8044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ArrayType - C99 6.7.5.2 - Array Declarators.
8054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
806c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
8074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
8084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
8091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
8101b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// with a star size (e.g. int X[*]).
8111b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// 'static' is only allowed on function parameters.
8124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  enum ArraySizeModifier {
8134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Normal, Static, Star
8144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  };
8154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate:
81683c13010359c33354c581acee65d0c986a75247eSteve Naroff  /// ElementType - The element type of the array.
81783c13010359c33354c581acee65d0c986a75247eSteve Naroff  QualType ElementType;
81824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff
819dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum
82024c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  /// NOTE: These fields are packed into the bitfields space in the Type class.
821dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek  unsigned SizeModifier : 2;
82224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff
82324c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  /// IndexTypeQuals - Capture qualifiers in declarations like:
82424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  /// 'int X[static restrict 4]'. For function parameters only.
82524c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  unsigned IndexTypeQuals : 3;
82624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff
82783c13010359c33354c581acee65d0c986a75247eSteve Naroffprotected:
8281b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  // C++ [temp.dep.type]p1:
8291b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  //   A type is dependent if it is...
8301b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  //     - an array type constructed from any dependent type or whose
8311b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  //       size is specified by a constant expression that is
8321b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  //       value-dependent,
83324c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
83424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff            ArraySizeModifier sm, unsigned tq)
8351b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray),
8361b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor      ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
8371b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
83883c13010359c33354c581acee65d0c986a75247eSteve Naroff  friend class ASTContext;  // ASTContext creates these.
83983c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic:
84083c13010359c33354c581acee65d0c986a75247eSteve Naroff  QualType getElementType() const { return ElementType; }
841dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek  ArraySizeModifier getSizeModifier() const {
842dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek    return ArraySizeModifier(SizeModifier);
843dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek  }
84424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
84583c13010359c33354c581acee65d0c986a75247eSteve Naroff
84683c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const Type *T) {
84783c13010359c33354c581acee65d0c986a75247eSteve Naroff    return T->getTypeClass() == ConstantArray ||
8488ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman           T->getTypeClass() == VariableArray ||
8491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor           T->getTypeClass() == IncompleteArray ||
8501b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor           T->getTypeClass() == DependentSizedArray;
85183c13010359c33354c581acee65d0c986a75247eSteve Naroff  }
85283c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const ArrayType *) { return true; }
85383c13010359c33354c581acee65d0c986a75247eSteve Naroff};
85483c13010359c33354c581acee65d0c986a75247eSteve Naroff
85556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ConstantArrayType - This class represents C arrays with a specified constant
85656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size.  For example 'int A[100]' has ConstantArrayType where the element type
85756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// is 'int' and the size is 100.
858c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ConstantArrayType : public ArrayType {
85983c13010359c33354c581acee65d0c986a75247eSteve Naroff  llvm::APInt Size; // Allows us to unique the type.
86083c13010359c33354c581acee65d0c986a75247eSteve Naroff
8613f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
86224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff                    ArraySizeModifier sm, unsigned tq)
8633f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {}
86483c13010359c33354c581acee65d0c986a75247eSteve Naroff  friend class ASTContext;  // ASTContext creates these.
86583c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic:
866a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  const llvm::APInt &getSize() const { return Size; }
86783c13010359c33354c581acee65d0c986a75247eSteve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
86883c13010359c33354c581acee65d0c986a75247eSteve Naroff
86983c13010359c33354c581acee65d0c986a75247eSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
8703f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    Profile(ID, getElementType(), getSize(),
8713f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner            getSizeModifier(), getIndexTypeQualifier());
87283c13010359c33354c581acee65d0c986a75247eSteve Naroff  }
87383c13010359c33354c581acee65d0c986a75247eSteve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
8743f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
8753f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner                      unsigned TypeQuals) {
87683c13010359c33354c581acee65d0c986a75247eSteve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
87783c13010359c33354c581acee65d0c986a75247eSteve Naroff    ID.AddInteger(ArraySize.getZExtValue());
8783f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    ID.AddInteger(SizeMod);
8793f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    ID.AddInteger(TypeQuals);
88083c13010359c33354c581acee65d0c986a75247eSteve Naroff  }
88183c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const Type *T) {
88283c13010359c33354c581acee65d0c986a75247eSteve Naroff    return T->getTypeClass() == ConstantArray;
88383c13010359c33354c581acee65d0c986a75247eSteve Naroff  }
88483c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const ConstantArrayType *) { return true; }
8854234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek
8864234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenekprotected:
8874234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
8884234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
8894234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek  friend class Type;
89083c13010359c33354c581acee65d0c986a75247eSteve Naroff};
89183c13010359c33354c581acee65d0c986a75247eSteve Naroff
89256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
89356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
89456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// type is 'int' and the size is unspecified.
8958ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanclass IncompleteArrayType : public ArrayType {
8968ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  IncompleteArrayType(QualType et, QualType can,
8978ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman                    ArraySizeModifier sm, unsigned tq)
8988ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman    : ArrayType(IncompleteArray, et, can, sm, tq) {}
8998ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  friend class ASTContext;  // ASTContext creates these.
9008ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanpublic:
9018ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9028ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  virtual void getAsStringInternal(std::string &InnerString) const;
9038ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9048ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  static bool classof(const Type *T) {
9058ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman    return T->getTypeClass() == IncompleteArray;
9068ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  }
9078ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
9088ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9098ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  friend class StmtIteratorBase;
9108ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9118ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
9123f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier());
9138ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  }
9148ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9153f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
9163f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
9178ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
9183f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    ID.AddInteger(SizeMod);
9193f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner    ID.AddInteger(TypeQuals);
9208ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  }
9218ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
9228ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanprotected:
9238ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  virtual void EmitImpl(llvm::Serializer& S) const;
9248ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
9258ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman  friend class Type;
9268ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman};
9278ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman
92856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
92956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
93056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
93156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///
93256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
93356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// should not be: two lexically equivalent variable array types could mean
93456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// different things, for example, these variables do not have the same type
93556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// dynamically:
93656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///
93756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// void foo(int x) {
93856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///   int Y[x];
93956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///   ++x;
94056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///   int Z[x];
94156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// }
94256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner///
943c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass VariableArrayType : public ArrayType {
94483c13010359c33354c581acee65d0c986a75247eSteve Naroff  /// SizeExpr - An assignment expression. VLA's are only permitted within
94583c13010359c33354c581acee65d0c986a75247eSteve Naroff  /// a function block.
946718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek  Stmt *SizeExpr;
9474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
94824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
94924c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff                    ArraySizeModifier sm, unsigned tq)
950718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek    : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
9514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
952db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek  virtual void Destroy(ASTContext& C);
953db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek
9544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
955a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  Expr *getSizeExpr() const {
956718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek    // We use C-style casts instead of cast<> here because we do not wish
957718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
958718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek    return (Expr*) SizeExpr;
959718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek  }
9604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
9614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
9624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
96383c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const Type *T) {
96483c13010359c33354c581acee65d0c986a75247eSteve Naroff    return T->getTypeClass() == VariableArray;
9654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
96683c13010359c33354c581acee65d0c986a75247eSteve Naroff  static bool classof(const VariableArrayType *) { return true; }
96727a32d6f18844a97446d6e2002bf181da591332aTed Kremenek
968fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek  friend class StmtIteratorBase;
9693793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek
9703793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
9717029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner    assert(0 && "Cannnot unique VariableArrayTypes.");
9723793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek  }
9735cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek
9745cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenekprotected:
9755cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
9765cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
9775cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek  friend class Type;
9784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
9794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
9801b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// DependentSizedArrayType - This type represents an array type in
9811b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// C++ whose size is a value-dependent expression. For example:
9821b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// @code
9831b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// template<typename T, int Size>
9841b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// class array {
9851b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor///   T data[Size];
9861b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// };
9871b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// @endcode
9881b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// For these types, we won't actually know what the array bound is
9891b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// until template instantiation occurs, at which point this will
9901b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
9911b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorclass DependentSizedArrayType : public ArrayType {
9921b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// SizeExpr - An assignment expression that will instantiate to the
9931b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// size of the array.
9941b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  Stmt *SizeExpr;
9951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
9961b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  DependentSizedArrayType(QualType et, QualType can, Expr *e,
9971b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor			  ArraySizeModifier sm, unsigned tq)
9981b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
9991b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  friend class ASTContext;  // ASTContext creates these.
10001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  virtual void Destroy(ASTContext& C);
10011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorpublic:
10031b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  Expr *getSizeExpr() const {
10041b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
10051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
10061b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    return (Expr*) SizeExpr;
10071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  }
10081b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  virtual void getAsStringInternal(std::string &InnerString) const;
10101b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10111b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  static bool classof(const Type *T) {
10121b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    return T->getTypeClass() == DependentSizedArray;
10131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  }
10141b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
10151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10161b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  friend class StmtIteratorBase;
10171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10181b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
10197029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner    assert(0 && "Cannnot unique DependentSizedArrayTypes.");
10201b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  }
10211b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10221b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorprotected:
10231b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
10241b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
10251b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  friend class Type;
10261b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor};
10271b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
10284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// VectorType - GCC generic vector type. This type is created using
10294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// __attribute__((vector_size(n)), where "n" specifies the vector size in
10304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// bytes. Since the constructor takes the number of vector elements, the
10314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// client is responsible for converting the size into the number of elements.
10324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass VectorType : public Type, public llvm::FoldingSetNode {
10334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected:
10344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// ElementType - The element type of the vector.
10354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType ElementType;
10364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// NumElements - The number of elements in the vector.
10384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  unsigned NumElements;
10394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
10411b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Type(Vector, canonType, vecType->isDependentType()),
10421b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    ElementType(vecType), NumElements(nElements) {}
10434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
10441486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman             QualType canonType)
10451b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType),
10461b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor      NumElements(nElements) {}
10474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
10484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
10494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getElementType() const { return ElementType; }
10514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  unsigned getNumElements() const { return NumElements; }
10524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
10544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
10554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
10564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Profile(ID, getElementType(), getNumElements(), getTypeClass());
10574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
10584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
10594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner                      unsigned NumElements, TypeClass TypeClass) {
10604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(ElementType.getAsOpaquePtr());
10614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddInteger(NumElements);
10624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddInteger(TypeClass);
10634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
10644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) {
1065af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
10664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
10674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const VectorType *) { return true; }
10684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
10694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
1070af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// ExtVectorType - Extended vector type. This type is created using
1071af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
1072af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
10736154214e20225a883a8a00226499534e9b514315Steve Naroff/// class enables syntactic extensions, like Vector Components for accessing
10746154214e20225a883a8a00226499534e9b514315Steve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
1075af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemanclass ExtVectorType : public VectorType {
1076af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
1077af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman    VectorType(ExtVector, vecType, nElements, canonType) {}
10784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
10794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
10809096b795541c783297fb19684a58c54d0fe823b8Chris Lattner  static int getPointAccessorIdx(char c) {
10819096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    switch (c) {
10829096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    default: return -1;
10839096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    case 'x': return 0;
10849096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    case 'y': return 1;
10859096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    case 'z': return 2;
10869096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    case 'w': return 3;
10879096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    }
10881b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff  }
10891486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman  static int getNumericAccessorIdx(char c) {
10909096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    switch (c) {
10911486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      default: return -1;
10921486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '0': return 0;
10931486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '1': return 1;
10941486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '2': return 2;
10951486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '3': return 3;
10961486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '4': return 4;
10971486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '5': return 5;
10981486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '6': return 6;
10991486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '7': return 7;
11001486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '8': return 8;
11011486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case '9': return 9;
11021486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'a': return 10;
11031486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'b': return 11;
11041486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'c': return 12;
11051486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'd': return 13;
11061486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'e': return 14;
11071486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman      case 'f': return 15;
11089096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    }
11091b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff  }
111042158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner
111142158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner  static int getAccessorIdx(char c) {
111242158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
11131486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman    return getNumericAccessorIdx(c);
111442158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner  }
111542158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner
11169096b795541c783297fb19684a58c54d0fe823b8Chris Lattner  bool isAccessorWithinNumElements(char c) const {
111742158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner    if (int idx = getAccessorIdx(c)+1)
11189096b795541c783297fb19684a58c54d0fe823b8Chris Lattner      return unsigned(idx-1) < NumElements;
11199096b795541c783297fb19684a58c54d0fe823b8Chris Lattner    return false;
11201b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff  }
1121c11705f9b742b542724dd56796bf90e07191e342Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
1122c11705f9b742b542724dd56796bf90e07191e342Steve Naroff
1123806b319509d01bffe47317f11140c930da800dbbSteve Naroff  static bool classof(const Type *T) {
1124af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman    return T->getTypeClass() == ExtVector;
11254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
1126af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  static bool classof(const ExtVectorType *) { return true; }
11274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
11284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
11304fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
11314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner///
11324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionType : public Type {
11334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// SubClassData - This field is owned by the subclass, put here to pack
11344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// tightly with the ivars in Type.
11354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool SubClassData : 1;
11364b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis
11374fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
11384b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  /// other bitfields.
11394fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  /// The qualifiers are part of FunctionProtoType because...
11404b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  ///
11414b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  /// C++ 8.3.5p4: The return type, the parameter type list and the
11424b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  /// cv-qualifier-seq, [...], are part of the function type.
11434b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  ///
11444b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  unsigned TypeQuals : 3;
11454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  // The type returned by the function.
11474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType ResultType;
11484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected:
11494b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,
11501b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor               unsigned typeQuals, QualType Canonical, bool Dependent)
11511b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(tc, Canonical, Dependent),
11524b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis      SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {}
11534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool getSubClassData() const { return SubClassData; }
11544b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  unsigned getTypeQuals() const { return TypeQuals; }
11554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
11564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getResultType() const { return ResultType; }
11584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) {
11614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return T->getTypeClass() == FunctionNoProto ||
11624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner           T->getTypeClass() == FunctionProto;
11634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
11644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const FunctionType *) { return true; }
11654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
11664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11674fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
11684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// no information available about its arguments.
11694fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
11704fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  FunctionNoProtoType(QualType Result, QualType Canonical)
11711b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
1172f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman                   /*Dependent=*/false) {}
11734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
11744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
11754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  // No additional state past what FunctionType provides.
11764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
11784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID) {
11804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    Profile(ID, getResultType());
11814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
11824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) {
11834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    ID.AddPointer(ResultType.getAsOpaquePtr());
11844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
11854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) {
11874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return T->getTypeClass() == FunctionNoProto;
11884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
11894fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
119087f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek
119187f0429f888ee5d332304641611b88f7b54b5065Ted Kremenekprotected:
119287f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
119387f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
119487f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek  friend class Type;
11954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
11964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
11974fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
11984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
11994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// arguments, not as having a single void argument.
12004fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
12011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// hasAnyDependentType - Determine whether there are any dependent
12021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  /// types within the arguments passed in.
12031b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) {
12041b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
12051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor      if (ArgArray[Idx]->isDependentType())
1206f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman    return true;
12071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
12081b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    return false;
12091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  }
12101b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor
12114fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs,
12124b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis                    bool isVariadic, unsigned typeQuals, QualType Canonical)
12131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical,
1214f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman                   (Result->isDependentType() ||
1215f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman                    hasAnyDependentType(ArgArray, numArgs))),
12164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner      NumArgs(numArgs) {
12174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    // Fill in the trailing argument array.
12184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
12194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    for (unsigned i = 0; i != numArgs; ++i)
12204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner      ArgInfo[i] = ArgArray[i];
12214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// NumArgs - The number of arguments this function has, not counting '...'.
12244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  unsigned NumArgs;
12254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
12274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// holds the argument types.
1228db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek
12294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
1230db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek
12314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
12324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  unsigned getNumArgs() const { return NumArgs; }
12334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType getArgType(unsigned i) const {
12344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    assert(i < NumArgs && "Invalid argument number!");
12354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return arg_type_begin()[i];
12364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  bool isVariadic() const { return getSubClassData(); }
12394b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
12404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  typedef const QualType *arg_type_iterator;
12424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  arg_type_iterator arg_type_begin() const {
12434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
12444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
12464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
12484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const Type *T) {
12504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    return T->getTypeClass() == FunctionProto;
12514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12524fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
12534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  void Profile(llvm::FoldingSetNodeID &ID);
12554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
12564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
12574b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis                      bool isVariadic, unsigned TypeQuals);
1258034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek
1259034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected:
1260034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1261034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
1262034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek  friend class Type;
12634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
12644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TypedefType : public Type {
12674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  TypedefDecl *Decl;
1268e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianprotected:
1269e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  TypedefType(TypeClass tc, TypedefDecl *D, QualType can)
12701b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(tc, can, can->isDependentType()), Decl(D) {
12714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner    assert(!isa<TypedefType>(can) && "Invalid canonical type");
12724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  }
12734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  friend class ASTContext;  // ASTContext creates these.
12744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic:
12754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  TypedefDecl *getDecl() const { return Decl; }
12774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
1279a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  /// potentially looking through *all* consecutive typedefs.  This returns the
12804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// sum of the type qualifiers, so if you have:
12814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  ///   typedef const int A;
12824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  ///   typedef volatile A B;
12834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  /// looking through the typedefs for B will give you "const volatile A".
12844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  QualType LookThroughTypedefs() const;
12854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
12874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12884fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
12894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const TypedefType *) { return true; }
12902f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek
12912f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenekprotected:
12922f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
12932f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
12942f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek  friend class Type;
12954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
12964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
12974fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypeOfExprType (GCC extension).
12984fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass TypeOfExprType : public Type {
12997cbb14653934a298c09002b87704dc6531261771Steve Naroff  Expr *TOExpr;
13004fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  TypeOfExprType(Expr *E, QualType can);
13017cbb14653934a298c09002b87704dc6531261771Steve Naroff  friend class ASTContext;  // ASTContext creates these.
13027cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic:
13037cbb14653934a298c09002b87704dc6531261771Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
13047cbb14653934a298c09002b87704dc6531261771Steve Naroff
13057cbb14653934a298c09002b87704dc6531261771Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
13067cbb14653934a298c09002b87704dc6531261771Steve Naroff
13074fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
13084fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
130971af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu
131071af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xuprotected:
131171af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu  virtual void EmitImpl(llvm::Serializer& S) const;
131271af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
131371af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu  friend class Type;
13147cbb14653934a298c09002b87704dc6531261771Steve Naroff};
13157cbb14653934a298c09002b87704dc6531261771Steve Naroff
13167cbb14653934a298c09002b87704dc6531261771Steve Naroff/// TypeOfType (GCC extension).
13177cbb14653934a298c09002b87704dc6531261771Steve Naroffclass TypeOfType : public Type {
13187cbb14653934a298c09002b87704dc6531261771Steve Naroff  QualType TOType;
13191b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  TypeOfType(QualType T, QualType can)
13204fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : Type(TypeOf, can, T->isDependentType()), TOType(T) {
13217cbb14653934a298c09002b87704dc6531261771Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
13227cbb14653934a298c09002b87704dc6531261771Steve Naroff  }
13237cbb14653934a298c09002b87704dc6531261771Steve Naroff  friend class ASTContext;  // ASTContext creates these.
13247cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic:
13257cbb14653934a298c09002b87704dc6531261771Steve Naroff  QualType getUnderlyingType() const { return TOType; }
13267cbb14653934a298c09002b87704dc6531261771Steve Naroff
13277cbb14653934a298c09002b87704dc6531261771Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
13287cbb14653934a298c09002b87704dc6531261771Steve Naroff
13294fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
13307cbb14653934a298c09002b87704dc6531261771Steve Naroff  static bool classof(const TypeOfType *) { return true; }
13310da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu
13320da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xuprotected:
13330da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu  virtual void EmitImpl(llvm::Serializer& S) const;
13340da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
13350da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu  friend class Type;
13367cbb14653934a298c09002b87704dc6531261771Steve Naroff};
13374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
13384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TagType : public Type {
133998b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// Stores the TagDecl associated with this type. The decl will
134098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// point to the TagDecl that actually defines the entity (or is a
134198b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// definition in progress), if there is such a definition. The
134298b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// single-bit value will be non-zero when this tag is in the
134398b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// process of being defined.
13449c7825b737617339724d43bd04960852271f08e2Douglas Gregor  mutable llvm::PointerIntPair<TagDecl *, 1> decl;
134546a837c7ced306c55d1686cea5f77cb7a2f3b908Ted Kremenek  friend class ASTContext;
134698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  friend class TagDecl;
13471d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor
13481d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorprotected:
13491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  // FIXME: We'll need the user to pass in information about whether
13501b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  // this type is dependent or not, because we don't have enough
13511b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  // information to compute it here.
13524fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  TagType(TypeClass TC, TagDecl *D, QualType can)
13534fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : Type(TC, can, /*Dependent=*/false), decl(D, 0) {}
13541d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor
13551d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorpublic:
135698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  TagDecl *getDecl() const { return decl.getPointer(); }
13574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
135898b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// @brief Determines whether this type is in the process of being
135998b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  /// defined.
136098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  bool isBeingDefined() const { return decl.getInt(); }
136198b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor  void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); }
136298b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor
13634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
1364734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  void getAsStringInternal(std::string &InnerString,
1365734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                           bool SuppressTagKind) const;
1366734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
13674fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const Type *T) {
13684fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
13694fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  }
13704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner  static bool classof(const TagType *) { return true; }
13714fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const RecordType *) { return true; }
13724fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  static bool classof(const EnumType *) { return true; }
13734fa58905062efa6a12137b1983a1367220182a20Douglas Gregor
13748db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenekprotected:
13758db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
137664be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
13778db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenek  friend class Type;
13784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner};
13794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
13801baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
13811baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of structs/unions/classes.
13821baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass RecordType : public TagType {
1383ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidisprotected:
13843cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis  explicit RecordType(RecordDecl *D)
13854fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { }
13864fa58905062efa6a12137b1983a1367220182a20Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
13874fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { }
13881d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor  friend class ASTContext;   // ASTContext creates these.
13891baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic:
13901baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
13911baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  RecordDecl *getDecl() const {
13921baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
13931baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  }
13941baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
13951baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // FIXME: This predicate is a helper to QualType/Type. It needs to
13961baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // recursively check all fields for const-ness. If any field is declared
13971baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // const, it needs to return false.
13981baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  bool hasConstFields() const { return false; }
13991baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
14001baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // FIXME: RecordType needs to check when it is created that all fields are in
14011baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  // the same address space, and return that.
14021baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  unsigned getAddressSpace() const { return 0; }
14031baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
1404eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  static bool classof(const TagType *T);
1405eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  static bool classof(const Type *T) {
1406eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
1407eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  }
14081baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  static bool classof(const RecordType *) { return true; }
14091baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner};
14101baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
14111baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
14121baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of enums.
14131baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass EnumType : public TagType {
14143cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis  explicit EnumType(EnumDecl *D)
14154fa58905062efa6a12137b1983a1367220182a20Douglas Gregor    : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { }
14161d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor  friend class ASTContext;   // ASTContext creates these.
14171baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic:
14181baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
14191baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  EnumDecl *getDecl() const {
14201baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
14211baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  }
14221baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
1423eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  static bool classof(const TagType *T);
1424eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  static bool classof(const Type *T) {
1425eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
1426eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner  }
14271baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner  static bool classof(const EnumType *) { return true; }
14281baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner};
14291baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
1430a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
1431a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  unsigned Depth : 16;
1432a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  unsigned Index : 16;
1433a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  IdentifierInfo *Name;
1434dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1435a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N,
1436a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor                       QualType Canon)
1437a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true),
1438a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor      Depth(D), Index(I), Name(N) { }
1439dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1440a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  TemplateTypeParmType(unsigned D, unsigned I)
1441a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true),
1442a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor      Depth(D), Index(I), Name(0) { }
1443dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1444a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  friend class ASTContext;  // ASTContext creates these
1445dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1446a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorpublic:
1447a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  unsigned getDepth() const { return Depth; }
1448a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  unsigned getIndex() const { return Index; }
1449a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  IdentifierInfo *getName() const { return Name; }
1450a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor
1451dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  virtual void getAsStringInternal(std::string &InnerString) const;
14521baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner
1453a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
1454a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    Profile(ID, Depth, Index, Name);
1455a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  }
1456a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor
1457a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
1458a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor                      unsigned Index, IdentifierInfo *Name) {
1459a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    ID.AddInteger(Depth);
1460a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    ID.AddInteger(Index);
1461a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor    ID.AddPointer(Name);
1462a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor  }
1463a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor
1464dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  static bool classof(const Type *T) {
1465dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor    return T->getTypeClass() == TemplateTypeParm;
1466dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  }
1467dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
1468dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1469dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorprotected:
1470dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
1471dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1472dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  friend class Type;
1473dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor};
1474a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor
14758e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// \brief Represents the type of a class template specialization as
14768e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// written in the source code.
14778e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor///
14788e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// Class template specialization types represent the syntactic form
14798e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// of a template-id that refers to a type, e.g., @c vector<int>. All
14808e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization types are syntactic sugar, whose
14818e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// canonical type will point to some other type node that represents
14828e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// the instantiation or class template specialization. For example, a
14838e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization type of @c vector<int> will refer to
14848e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// a tag type for the instantiation
14858e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// @c std::vector<int, std::allocator<int>>.
14868e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorclass ClassTemplateSpecializationType
14878e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  : public Type, public llvm::FoldingSetNode {
14888e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
14898e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  // FIXME: Do we want templates to have a representation in the type
14908e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  // system? It will probably help with dependent templates and
14918e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  // possibly with template-names preceded by a nested-name-specifier.
14928e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  TemplateDecl *Template;
14938e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
1494f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// \brief - The number of template arguments named in this class
1495f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// template specialization.
14968e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  unsigned NumArgs;
14978e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
1498f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  ClassTemplateSpecializationType(TemplateDecl *T,
1499f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor                                  const TemplateArgument *Args,
1500f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor                                  unsigned NumArgs, QualType Canon);
15018e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15026f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor  virtual void Destroy(ASTContext& C);
15036f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor
15048e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  friend class ASTContext;  // ASTContext creates these
15058e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15068e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorpublic:
1507f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// \brief Determine whether any of the given template arguments are
1508f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// dependent.
1509f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
1510f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor                                            unsigned NumArgs);
1511f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor
151256d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
151356d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor  /// enclosing the template arguments.
151456d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
151556d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor                                               unsigned NumArgs);
151656d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor
1517f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  typedef const TemplateArgument * iterator;
1518f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor
1519f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  iterator begin() const { return getArgs(); }
1520f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  iterator end() const;
1521f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor
15228e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  /// \brief Retrieve the template that we are specializing.
15238e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  TemplateDecl *getTemplate() const { return Template; }
15248e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
1525f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// \brief Retrieve the template arguments.
1526f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  const TemplateArgument *getArgs() const {
1527f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
1528f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  }
1529f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor
1530f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  /// \brief Retrieve the number of template arguments.
15318e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
15328e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15338e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
15348e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  /// \precondition @c isArgType(Arg)
1535f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor  const TemplateArgument &getArg(unsigned Idx) const;
15368e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15378e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  virtual void getAsStringInternal(std::string &InnerString) const;
15388e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15398e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
1540f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor    Profile(ID, Template, getArgs(), NumArgs);
15418e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  }
15428e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15438e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateDecl *T,
1544f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor                      const TemplateArgument *Args, unsigned NumArgs);
15458e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15468e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  static bool classof(const Type *T) {
15478e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor    return T->getTypeClass() == ClassTemplateSpecialization;
15488e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  }
15498e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  static bool classof(const ClassTemplateSpecializationType *T) { return true; }
15508e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
15518e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorprotected:
15528e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
15538e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
15548e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor  friend class Type;
15558e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor};
15568e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor
1557734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// \brief Represents a type that was referred to via a qualified
1558734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// name, e.g., N::M::type.
1559734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor///
1560734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// This type is used to keep track of a type name as written in the
1561734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// source code, including any nested-name-specifiers.
1562734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode {
1563734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief The number of components in the qualified name, not
1564734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// counting the final type.
1565734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  unsigned NumComponents;
1566734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1567734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief The type that this qualified name refers to.
1568734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  QualType NamedType;
1569734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1570734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  QualifiedNameType(const NestedNameSpecifier *Components,
1571734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                    unsigned NumComponents, QualType NamedType,
1572734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                    QualType CanonType);
1573734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1574734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  friend class ASTContext;  // ASTContext creates these
1575734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1576734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorpublic:
1577734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  typedef const NestedNameSpecifier * iterator;
1578734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1579734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  iterator begin() const { return getComponents(); }
1580734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  iterator end() const { return getComponents() + getNumComponents(); }
1581734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1582734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief Retrieve the array of nested-name-specifier components.
1583734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  const NestedNameSpecifier *getComponents() const {
1584734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor    return reinterpret_cast<const NestedNameSpecifier *>(this + 1);
1585734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  }
1586734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1587734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief Retrieve the number of nested-name-specifier components.
1588734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  unsigned getNumComponents() const { return NumComponents; }
1589734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1590734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
1591734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  QualType getNamedType() const { return NamedType; }
1592734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1593734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  virtual void getAsStringInternal(std::string &InnerString) const;
1594734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1595734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
1596734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor    Profile(ID, getComponents(), NumComponents, NamedType);
1597734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  }
1598734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1599734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID,
1600734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                      const NestedNameSpecifier *Components,
1601734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                      unsigned NumComponents,
1602734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor                      QualType NamedType);
1603734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1604734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  static bool classof(const Type *T) {
1605734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor    return T->getTypeClass() == QualifiedName;
1606734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  }
1607734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  static bool classof(const QualifiedNameType *T) { return true; }
1608734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1609734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorprotected:
1610734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
1611734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1612734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor  friend class Type;
1613734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor};
1614734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor
1615f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
1616f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// object oriented design.  They basically correspond to C++ classes.  There
1617f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and
1618f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// qualified interfaces, which are qualified with a protocol list like
1619f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// "NSString<NSCopyable, NSAmazing>".  Qualified interface types are instances
1620f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType.
162142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCInterfaceType : public Type {
162242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCInterfaceDecl *Decl;
16230c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanianprotected:
162442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) :
16251b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    Type(tc, QualType(), /*Dependent=*/false), Decl(D) { }
162681f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff  friend class ASTContext;  // ASTContext creates these.
162781f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroffpublic:
162881f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff
162942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCInterfaceDecl *getDecl() const { return Decl; }
163081f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff
1631f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// qual_iterator and friends: this provides access to the (potentially empty)
1632f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// list of protocols qualifying this interface.  If this is an instance of
1633f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an
1634f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// empty list if there are no qualifying protocols.
1635f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1636f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  inline qual_iterator qual_begin() const;
1637f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  inline qual_iterator qual_end() const;
1638f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; }
1639f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1640f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// getNumProtocols - Return the number of qualifying protocols in this
1641f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  /// interface type, or 0 if there are none.
1642f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  inline unsigned getNumProtocols() const;
1643f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1644d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner  /// getProtocol - Return the specified qualifying protocol.
1645d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner  inline ObjCProtocolDecl *getProtocol(unsigned i) const;
164691193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian
1647f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1648f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  virtual void getAsStringInternal(std::string &InnerString) const;
164981f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff  static bool classof(const Type *T) {
1650b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner    return T->getTypeClass() == ObjCInterface ||
1651b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner           T->getTypeClass() == ObjCQualifiedInterface;
165281f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff  }
165342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
165481f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff};
165581f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff
165642730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types
1657e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>.
1658e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner///
1659c5a342d3b1cc5fa6eef09653a6d8d091928366c0Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in
1660c5a342d3b1cc5fa6eef09653a6d8d091928366c0Fariborz Jahanian/// alphabetical order.
166142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType,
16620c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanian                                   public llvm::FoldingSetNode {
16630c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanian
1664c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian  // List of protocols for this protocol conforming object type
1665c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian  // List is sorted on protocol name. No protocol is enterred more than once.
1666f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols;
1667c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian
166842730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D,
1669b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner                             ObjCProtocolDecl **Protos, unsigned NumP) :
167042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek    ObjCInterfaceType(ObjCQualifiedInterface, D),
1671d855a6ead44e3a875179400c472ac0b37df35f70Chris Lattner    Protocols(Protos, Protos+NumP) { }
167291193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  friend class ASTContext;  // ASTContext creates these.
1673c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanianpublic:
1674c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian
1675d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner  ObjCProtocolDecl *getProtocol(unsigned i) const {
167691193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian    return Protocols[i];
167791193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  }
167891193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  unsigned getNumProtocols() const {
167991193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian    return Protocols.size();
168091193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  }
1681b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner
1682b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  qual_iterator qual_begin() const { return Protocols.begin(); }
1683b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  qual_iterator qual_end() const   { return Protocols.end(); }
1684b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner
168591193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  virtual void getAsStringInternal(std::string &InnerString) const;
168691193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian
168791193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  void Profile(llvm::FoldingSetNodeID &ID);
168891193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian  static void Profile(llvm::FoldingSetNodeID &ID,
1689fd5690fe6b5ea1c553dfe20f99d3fef269a50bd1Chris Lattner                      const ObjCInterfaceDecl *Decl,
169042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
169191193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian
1692c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian  static bool classof(const Type *T) {
169342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek    return T->getTypeClass() == ObjCQualifiedInterface;
1694c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian  }
169542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  static bool classof(const ObjCQualifiedInterfaceType *) { return true; }
1696c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian};
1697f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1698f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const {
1699f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  if (const ObjCQualifiedInterfaceType *QIT =
1700f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner         dyn_cast<ObjCQualifiedInterfaceType>(this))
1701f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner    return QIT->qual_begin();
1702f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  return 0;
1703f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner}
1704f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const {
1705f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  if (const ObjCQualifiedInterfaceType *QIT =
1706f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner         dyn_cast<ObjCQualifiedInterfaceType>(this))
1707f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner    return QIT->qual_end();
1708f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  return 0;
1709f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner}
1710f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1711f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// getNumProtocols - Return the number of qualifying protocols in this
1712f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// interface type, or 0 if there are none.
1713f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline unsigned ObjCInterfaceType::getNumProtocols() const {
1714f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  if (const ObjCQualifiedInterfaceType *QIT =
1715f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner        dyn_cast<ObjCQualifiedInterfaceType>(this))
1716f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner    return QIT->getNumProtocols();
1717f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner  return 0;
1718f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner}
1719f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1720d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner/// getProtocol - Return the specified qualifying protocol.
1721d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattnerinline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const {
1722d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner  return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i);
1723f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner}
1724f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1725f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner
1726e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1727e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// ObjCQualifiedIdType - to represent id<protocol-list>.
1728e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner///
1729e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// Duplicate protocols are removed and protocol list is canonicalized to be in
1730e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// alphabetical order.
173142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCQualifiedIdType : public Type,
1732e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian                            public llvm::FoldingSetNode {
1733e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  // List of protocols for this protocol conforming 'id' type
1734e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  // List is sorted on protocol name. No protocol is enterred more than once.
173542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
1736e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
17374a68fe04deb7ab89ac7566dc55b3b623129c72e5Chris Lattner  ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP)
17381b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor    : Type(ObjCQualifiedId, QualType()/*these are always canonical*/,
1739f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman           /*Dependent=*/false),
1740e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  Protocols(Protos, Protos+NumP) { }
1741e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  friend class ASTContext;  // ASTContext creates these.
1742e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianpublic:
1743e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
174442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCProtocolDecl *getProtocols(unsigned i) const {
1745e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian    return Protocols[i];
1746e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  }
1747e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  unsigned getNumProtocols() const {
1748e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian    return Protocols.size();
1749e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  }
175042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  ObjCProtocolDecl **getReferencedProtocols() {
1751957442db1d23f62ee2d0d71310bee240606b267dFariborz Jahanian    return &Protocols[0];
1752b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  }
1753b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner
1754b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1755b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  qual_iterator qual_begin() const { return Protocols.begin(); }
1756b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner  qual_iterator qual_end() const   { return Protocols.end(); }
1757e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1758e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  virtual void getAsStringInternal(std::string &InnerString) const;
1759e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1760e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  void Profile(llvm::FoldingSetNodeID &ID);
17614a68fe04deb7ab89ac7566dc55b3b623129c72e5Chris Lattner  static void Profile(llvm::FoldingSetNodeID &ID,
176242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1763e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1764e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  static bool classof(const Type *T) {
176542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek    return T->getTypeClass() == ObjCQualifiedId;
1766e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian  }
176742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek  static bool classof(const ObjCQualifiedIdType *) { return true; }
1768e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian
1769e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian};
1770c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian
1771262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// ObjCQualifiedClassType - to represent Class<protocol-list>.
1772262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff///
1773262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in
1774262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// alphabetical order.
1775262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroffclass ObjCQualifiedClassType : public Type,
1776262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff                               public llvm::FoldingSetNode {
1777262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  // List of protocols for this protocol conforming 'id' type
1778262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  // List is sorted on protocol name. No protocol is enterred more than once.
1779262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
1780262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1781262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  ObjCQualifiedClassType(ObjCProtocolDecl **Protos, unsigned NumP)
1782d305a86f087fd359cf0f033eba0c968e55a61ff4Steve Naroff    : Type(ObjCQualifiedClass, QualType()/*these are always canonical*/,
1783262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff           /*Dependent=*/false),
1784262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  Protocols(Protos, Protos+NumP) { }
1785262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  friend class ASTContext;  // ASTContext creates these.
1786262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroffpublic:
1787262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1788262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  ObjCProtocolDecl *getProtocols(unsigned i) const {
1789262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff    return Protocols[i];
1790262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  }
1791262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  unsigned getNumProtocols() const {
1792262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff    return Protocols.size();
1793262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  }
1794262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  ObjCProtocolDecl **getReferencedProtocols() {
1795262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff    return &Protocols[0];
1796262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  }
1797262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1798262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1799262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  qual_iterator qual_begin() const { return Protocols.begin(); }
1800262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  qual_iterator qual_end() const   { return Protocols.end(); }
1801262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1802262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
1803262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1804262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
1805262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  static void Profile(llvm::FoldingSetNodeID &ID,
1806262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1807262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1808262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  static bool classof(const Type *T) {
1809d305a86f087fd359cf0f033eba0c968e55a61ff4Steve Naroff    return T->getTypeClass() == ObjCQualifiedClass;
1810262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  }
1811262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff  static bool classof(const ObjCQualifiedClassType *) { return true; }
1812262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff
1813262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff};
18144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
1815b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner// Inline function definitions.
18164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
18172a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers.
18182a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline QualType QualType::getUnqualifiedType() const {
181935fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  Type *TP = getTypePtr();
1820b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian  if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP))
1821b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian    TP = EXTQT->getBaseType();
182235fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner  return QualType(TP, 0);
18232a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb}
18242a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb
18252a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getAddressSpace - Return the address space of this type.
18262a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline unsigned QualType::getAddressSpace() const {
182701ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner  QualType CT = getTypePtr()->getCanonicalTypeInternal();
182801ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
1829a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner    return AT->getElementType().getAddressSpace();
183001ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(CT))
1831efc11216a5755f69b5540289aa2dd374d4bc82abNate Begeman    return RT->getAddressSpace();
1832b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian  if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT))
1833b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian    return EXTQT->getAddressSpace();
18342a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return 0;
18352a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb}
1836b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner
1837af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
1838af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const {
1839af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  QualType CT = getTypePtr()->getCanonicalTypeInternal();
1840af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
1841af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian      return AT->getElementType().getObjCGCAttr();
1842af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian  if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT))
1843af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian    return EXTQT->getObjCGCAttr();
1844184541a6a7d218583d79d408534f77c27b7b8c6eFariborz Jahanian  if (const PointerType *PT = CT->getAsPointerType())
1845184541a6a7d218583d79d408534f77c27b7b8c6eFariborz Jahanian    return PT->getPointeeType().getObjCGCAttr();
18467029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner  return GCNone;
1847af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian}
1848af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian
18493fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
18503fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
18513fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// is more qualified than "const int", "volatile int", and
18523fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int". However, it is not more qualified than "const volatile
18533fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int".
18543fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const {
18553fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  // FIXME: Handle address spaces
18563fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  unsigned MyQuals = this->getCVRQualifiers();
18573fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  unsigned OtherQuals = Other.getCVRQualifiers();
18584459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor  assert(this->getAddressSpace() == 0 && "Address space not checked");
18594459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor  assert(Other.getAddressSpace() == 0 && "Address space not checked");
18603fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
18613fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor}
18623fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor
18633fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
18643fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// as qualified as the Other type. For example, "const volatile
18653fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
18663fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int", and "const volatile int".
18673fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
18683fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  // FIXME: Handle address spaces
18693fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  unsigned MyQuals = this->getCVRQualifiers();
18703fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  unsigned OtherQuals = Other.getCVRQualifiers();
18714459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor  assert(this->getAddressSpace() == 0 && "Address space not checked");
18724459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor  assert(Other.getAddressSpace() == 0 && "Address space not checked");
18733fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  return (MyQuals | OtherQuals) == MyQuals;
18743fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor}
18753fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor
18763fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
18773fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int&), returns the type that the reference refers to ("const
18783fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
18793fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// throughout Sema to implement C++ 5p6:
18803fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///
18813fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
18823fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
18833fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///   analysis, the expression designates the object or function
18843fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
18853fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline QualType QualType::getNonReferenceType() const {
18863fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  if (const ReferenceType *RefType = (*this)->getAsReferenceType())
18873fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor    return RefType->getPointeeType();
18883fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor  else
18893fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor    return *this;
18903fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor}
18913fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor
18925c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenekinline const TypedefType* Type::getAsTypedefType() const {
18935c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek  return dyn_cast<TypedefType>(this);
18945c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek}
1895f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const {
1896f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  if (const PointerType *PT = getAsPointerType())
1897f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner    return PT->getPointeeType()->getAsObjCInterfaceType();
1898f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner  return 0;
1899f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner}
1900f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner
1901a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address
1902a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner// space qualifiers if present.
1903b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isFunctionType() const {
19042a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<FunctionType>(CanonicalType.getUnqualifiedType());
1905b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
1906b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isPointerType() const {
19072a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<PointerType>(CanonicalType.getUnqualifiedType());
1908b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
19097aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffinline bool Type::isBlockPointerType() const {
19107aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff    return isa<BlockPointerType>(CanonicalType);
19117aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff}
1912cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerinline bool Type::isReferenceType() const {
1913cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner  return isa<ReferenceType>(CanonicalType.getUnqualifiedType());
1914cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner}
1915ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isLValueReferenceType() const {
1916ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType());
1917ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}
1918ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isRValueReferenceType() const {
1919ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl  return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType());
1920ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}
192183b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenekinline bool Type::isFunctionPointerType() const {
192274a340749eb63af1ba7098c67f3ef72bd48f5ae8Ted Kremenek  if (const PointerType* T = getAsPointerType())
192383b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek    return T->getPointeeType()->isFunctionType();
192483b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek  else
192583b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek    return false;
192683b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek}
19277555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberPointerType() const {
19287555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  return isa<MemberPointerType>(CanonicalType.getUnqualifiedType());
19297555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl}
19307555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
19317555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  if (const MemberPointerType* T = getAsMemberPointerType())
19327555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    return T->getPointeeType()->isFunctionType();
19337555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl  else
19347555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl    return false;
19357555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl}
1936b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isArrayType() const {
19372a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<ArrayType>(CanonicalType.getUnqualifiedType());
1938b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
1939a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isConstantArrayType() const {
1940a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType());
1941a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner}
1942a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isIncompleteArrayType() const {
1943a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType());
1944a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner}
1945a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isVariableArrayType() const {
1946a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<VariableArrayType>(CanonicalType.getUnqualifiedType());
1947a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner}
19481b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorinline bool Type::isDependentSizedArrayType() const {
19491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor  return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType());
19501b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor}
1951b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isRecordType() const {
19522a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<RecordType>(CanonicalType.getUnqualifiedType());
1953b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
19543277df47de6b65b55721726dc3f7b294e70ef6feChris Lattnerinline bool Type::isAnyComplexType() const {
1955a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ComplexType>(CanonicalType.getUnqualifiedType());
19563277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner}
1957b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isVectorType() const {
19582a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb  return isa<VectorType>(CanonicalType.getUnqualifiedType());
1959b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
1960af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemaninline bool Type::isExtVectorType() const {
1961af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman  return isa<ExtVectorType>(CanonicalType.getUnqualifiedType());
1962b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner}
196342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCInterfaceType() const {
1964a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType());
1965b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner}
1966b06cf30badcddfea862bc9a538447453bdd94598Chris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const {
1967a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType());
1968550e05034c6c8efcb7ab4c65f58048eee0892237Fariborz Jahanian}
196942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
1970a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner  return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType());
1971dcb2b1e489948a570ee07ca65e12d42edffa20efFariborz Jahanian}
1972dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorinline bool Type::isTemplateTypeParmType() const {
1973dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor  return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType());
1974dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor}
1975dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor
1976c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
197745014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor  if (const BuiltinType *BT = getAsBuiltinType())
1978c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
1979c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar      return true;
1980c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar  return false;
1981c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar}
1982c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar
198300fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// \brief Determines whether this is a type for which one can define
198400fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// an overloaded operator.
198500fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregorinline bool Type::isOverloadableType() const {
198600fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
198745014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor}
198845014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor
1989fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
1990fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
1991fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar          isObjCInterfaceType() || isObjCQualifiedIdType() ||
1992fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar          isObjCQualifiedInterfaceType());
1993fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar}
1994fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar
19957c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
19967c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian  return (isObjCInterfaceType() || isObjCQualifiedIdType() ||
19977c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian          isObjCQualifiedInterfaceType());
19987c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian}
19997c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian
2000da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
2001da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// diagnostic with <<.
2002da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2003da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner                                           QualType T) {
2004da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
2005da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner                  Diagnostic::ak_qualtype);
2006da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner  return DB;
2007da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner}
2008da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner
20094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}  // end namespace clang
20104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner
20114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#endif
2012