ASTContext.h revision 7a9d49fd2bfac00e905b361ba76d26ab5b6c3b09
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
55f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file was developed by Chris Lattner and is distributed under
65f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// the University of Illinois Open Source License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the ASTContext interface.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_ASTCONTEXT_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_ASTCONTEXT_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Builtins.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h"
19464175bba1318bef7905122e9fda20cff926df78Chris Lattner#include "clang/AST/RecordLayout.h"
20464175bba1318bef7905122e9fda20cff926df78Chris Lattner#include "clang/AST/Type.h"
21464175bba1318bef7905122e9fda20cff926df78Chris Lattner#include "llvm/ADT/DenseMap.h"
22a9aa5e69d8253e196be90c070738ab5bd9813730Steve Naroff#include "llvm/ADT/StringMap.h"
2368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff#include "llvm/ADT/FoldingSet.h"
247192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek#include "llvm/Bitcode/SerializationFwd.h"
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <vector>
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
29c7229c338c21ef26b01ef3ecf9eec4fd373fa9ecChris Lattner  class IdentifierTable;
30980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ASTContext - This class holds long-lived AST nodes (such as types and
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// decls) that can be referred to throughout the semantic analysis of a file.
332bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenekclass ASTContext {
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  std::vector<Type*> Types;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<ComplexType> ComplexTypes;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<PointerType> PointerTypes;
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<ReferenceType> ReferenceTypes;
387192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
392bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  llvm::FoldingSet<VariableArrayType> IncompleteVariableArrayTypes;
40347b9f33b3216459bcf60cdd52c739fa3028321eTed Kremenek  std::vector<VariableArrayType*> CompleteVariableArrayTypes;
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<VectorType> VectorTypes;
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos;
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
444b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  llvm::FoldingSet<ObjcQualifiedInterfaceType> ObjcQualifiedInterfaceTypes;
4588a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
46a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek  ///  This is lazily created.  This is intentionally not serialized.
4788a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> ASTRecordLayouts;
48b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson
49b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  /// BuiltinVaListType - built-in va list type.
50b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  /// This is initially null and set by Sema::LazilyCreateBuiltin when
51b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  /// a builtin that takes a valist is encountered.
52b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  QualType BuiltinVaListType;
537e219e47de26346885d667131977bd9ca2d7662aSteve Naroff
547e219e47de26346885d667131977bd9ca2d7662aSteve Naroff  /// ObjcIdType - a psuedo built-in typedef type (set by Sema).
557e219e47de26346885d667131977bd9ca2d7662aSteve Naroff  QualType ObjcIdType;
567e219e47de26346885d667131977bd9ca2d7662aSteve Naroff  const RecordType *IdStructType;
572198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff
58b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  /// ObjcSelType - another psuedo built-in typedef type (set by Sema).
59b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  QualType ObjcSelType;
60b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  const RecordType *SelStructType;
61b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
62390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  /// ObjcProtoType - another psuedo built-in typedef type (set by Sema).
63390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  QualType ObjcProtoType;
64390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  const RecordType *ProtoStructType;
658baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson
668baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  /// ObjcClassType - another psuedo built-in typedef type (set by Sema).
678baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  QualType ObjcClassType;
688baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  const RecordType *ClassStructType;
69390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian
702198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff  QualType ObjcConstantStringType;
712198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff  RecordDecl *CFConstantStringTypeDecl;
727a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek
73b800dc2d5e27ec60f567567b623cdc61152b8fb8Chris Lattner  SourceManager &SourceMgr;
747a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenekpublic:
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TargetInfo &Target;
7671993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson  IdentifierTable &Idents;
7729238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff  SelectorTable &Selectors;
78a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek
797a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek  SourceManager& getSourceManager() { return SourceMgr; }
807a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek
81a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek  /// This is intentionally not serialized.  It is populated by the
82a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek  /// ASTContext ctor, and there are no external pointers/references to
83a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek  /// internal variables of BuiltinInfo.
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Builtin::Context BuiltinInfo;
855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Builtin Types.
875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType VoidTy;
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType BoolTy;
895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CharTy;
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy;
915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType UnsignedLongLongTy;
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType FloatTy, DoubleTy, LongDoubleTy;
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
9533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  QualType VoidPtrTy;
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  ASTContext(SourceManager &SM, TargetInfo &t, IdentifierTable &idents,
98fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek             SelectorTable &sels, unsigned size_reserve=0 ) :
9968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff    CFConstantStringTypeDecl(0), SourceMgr(SM), Target(t),
10068d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff    Idents(idents), Selectors(sels) {
101fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek
102fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek    if (size_reserve > 0) Types.reserve(size_reserve);
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    InitBuiltinTypes();
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    BuiltinInfo.InitializeBuiltins(idents, Target);
105fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek  }
106fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ~ASTContext();
1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void PrintStats() const;
11003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  const std::vector<Type*>& getTypes() const { return Types; }
11103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek
112464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
113464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //                           Type Constructors
114464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
115d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner
1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getComplexType - Return the uniqued reference to the type for a complex
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// number with the specified element type.
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getComplexType(QualType T);
1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getPointerType - Return the uniqued reference to the type for a pointer to
1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the specified type.
1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getPointerType(QualType T);
1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getReferenceType - Return the uniqued reference to the type for a
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference to the specified type.
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getReferenceType(QualType T);
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
128bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff  /// getVariableArrayType - Returns a non-unique reference to the type for a
129bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff  /// variable array of the specified element type.
130c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
131c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                                ArrayType::ArraySizeModifier ASM,
132c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                                unsigned EltTypeQuals);
133fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
134bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff  /// getConstantArrayType - Return the unique reference to the type for a
135bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff  /// constant array of the specified element type.
136c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
137c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                                ArrayType::ArraySizeModifier ASM,
138c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                                unsigned EltTypeQuals);
1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  /// getVectorType - Return the unique reference to a vector type of
14173322924127c873c13101b705dd823f5539ffa5fSteve Naroff  /// the specified element type and size. VectorType must be a built-in type.
14273322924127c873c13101b705dd823f5539ffa5fSteve Naroff  QualType getVectorType(QualType VectorType, unsigned NumElts);
14373322924127c873c13101b705dd823f5539ffa5fSteve Naroff
14473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  /// getOCUVectorType - Return the unique reference to an OCU vector type of
14573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  /// the specified element type and size. VectorType must be a built-in type.
14673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  QualType getOCUVectorType(QualType VectorType, unsigned NumElts);
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'.
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getFunctionTypeNoProto(QualType ResultTy);
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getFunctionType - Return a normal function type with a typed argument
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// list.  isVariadic indicates whether the argument list includes '...'.
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getFunctionType(QualType ResultTy, QualType *ArgArray,
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                           unsigned NumArgs, bool isVariadic);
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getTypedefType - Return the unique reference to the type for the
1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// specified typename decl.
1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getTypedefType(TypedefDecl *Decl);
1603536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  QualType getObjcInterfaceType(ObjcInterfaceDecl *Decl);
1614b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian
1624b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  /// getObjcQualifiedInterfaceType - Return a
1634b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  /// ObjcQualifiedInterfaceType type for the given interface decl and
1644b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  /// the conforming protocol list.
1654b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  QualType getObjcQualifiedInterfaceType(ObjcInterfaceDecl *Decl,
1664b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian             ObjcProtocolDecl **ProtocolList, unsigned NumProtocols);
1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
168d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  /// getTypeOfType - GCC extension.
1698d1a3b8ca1e5fcc4567b5a6f51d82be2e460de1cSteve Naroff  QualType getTypeOfExpr(Expr *e);
170d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getTypeOfType(QualType t);
171d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getTagDeclType - Return the unique reference to the type for the
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// specified TagDecl (struct/union/class/enum) decl.
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getTagDeclType(TagDecl *Decl);
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getSizeType() const;
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1808b9023ba35a86838789e2c9034a6128728c547aaChris Lattner  /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
1818b9023ba35a86838789e2c9034a6128728c547aaChris Lattner  /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
1828b9023ba35a86838789e2c9034a6128728c547aaChris Lattner  QualType getPointerDiffType() const;
1838b9023ba35a86838789e2c9034a6128728c547aaChris Lattner
184beaf299a2701c5559a4e5d76b0c40f805afb8e6aSteve Naroff  // getCFConstantStringType - Return the C structure type used to represent
185beaf299a2701c5559a4e5d76b0c40f805afb8e6aSteve Naroff  // constant CFStrings.
18671993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson  QualType getCFConstantStringType();
18771993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson
188983df5b2280980e59b0b062bcc2882230465a61eSteve Naroff  // This setter/getter represents the ObjC type for an NSConstantString.
1892198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff  void setObjcConstantStringInterface(ObjcInterfaceDecl *Decl);
1902198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff  QualType getObjcConstantStringInterface() const {
1912198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff    return ObjcConstantStringType;
1922198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff  }
193b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
19485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson  // Return the ObjC type encoding for a given type.
19585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson  void getObjcEncodingForType(QualType t, std::string &S) const;
19633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian
197ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian  // Put the string version of type qualifiers into S.
198ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian  void getObjcEncodingForTypeQualifier(Decl::ObjcDeclQualifier QT,
199ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian                                       std::string &S) const;
200ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian
20133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  /// getObjcEncodingForMethodDecl - Return the encoded type for this method
20233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  /// declaration.
20333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  void getObjcEncodingForMethodDecl(ObjcMethodDecl *Decl, std::string &S);
20433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian
20533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  /// getObjcEncodingTypeSize returns size of type for objective-c encoding
20633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  /// purpose.
20733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  int getObjcEncodingTypeSize(QualType t);
20885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson
209983df5b2280980e59b0b062bcc2882230465a61eSteve Naroff  // This setter/getter repreents the ObjC 'id' type. It is setup lazily, by
210983df5b2280980e59b0b062bcc2882230465a61eSteve Naroff  // Sema.
2117e219e47de26346885d667131977bd9ca2d7662aSteve Naroff  void setObjcIdType(TypedefDecl *Decl);
2127e219e47de26346885d667131977bd9ca2d7662aSteve Naroff  QualType getObjcIdType() const { return ObjcIdType; }
213b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
214b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  void setObjcSelType(TypedefDecl *Decl);
215b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  QualType getObjcSelType() const { return ObjcSelType; }
216b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
21766c5dfc193c4090b67c5effb0e80e287b94de17eFariborz Jahanian  void setObjcProtoType(QualType QT);
218390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  QualType getObjcProtoType() const { return ObjcProtoType; }
219390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian
2208baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  void setObjcClassType(TypedefDecl *Decl);
2218baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  QualType getObjcClassType() const { return ObjcClassType; }
2228baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson
223b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  void setBuiltinVaListType(QualType T);
224b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  QualType getBuiltinVaListType() const { return BuiltinVaListType; }
225b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson
226464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
227464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //                         Type Sizing and Analysis
228464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
229464175bba1318bef7905122e9fda20cff926df78Chris Lattner
230464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// getTypeInfo - Get the size and alignment of the specified complete type in
231464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// bits.
232464175bba1318bef7905122e9fda20cff926df78Chris Lattner  std::pair<uint64_t, unsigned> getTypeInfo(QualType T, SourceLocation L);
233464175bba1318bef7905122e9fda20cff926df78Chris Lattner
234464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// getTypeSize - Return the size of the specified type, in bits.  This method
235464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// does not work on incomplete types.
236464175bba1318bef7905122e9fda20cff926df78Chris Lattner  uint64_t getTypeSize(QualType T, SourceLocation L) {
237464175bba1318bef7905122e9fda20cff926df78Chris Lattner    return getTypeInfo(T, L).first;
238464175bba1318bef7905122e9fda20cff926df78Chris Lattner  }
239464175bba1318bef7905122e9fda20cff926df78Chris Lattner
240464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// getTypeAlign - Return the alignment of the specified type, in bits.  This
241464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// method does not work on incomplete types.
242464175bba1318bef7905122e9fda20cff926df78Chris Lattner  unsigned getTypeAlign(QualType T, SourceLocation L) {
243464175bba1318bef7905122e9fda20cff926df78Chris Lattner    return getTypeInfo(T, L).second;
244464175bba1318bef7905122e9fda20cff926df78Chris Lattner  }
245464175bba1318bef7905122e9fda20cff926df78Chris Lattner
24688a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  /// getASTRecordLayout - Get or compute information about the layout of the
247464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// specified record (struct/union/class), which indicates its size and field
248464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// position information.
24988a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D, SourceLocation L);
250464175bba1318bef7905122e9fda20cff926df78Chris Lattner
251464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
252464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //                            Type Operators
253464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
254464175bba1318bef7905122e9fda20cff926df78Chris Lattner
255464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// maxIntegerType - Returns the highest ranked integer type. Handles 3
256464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// different type combos: unsigned/unsigned, signed/signed, signed/unsigned.
2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType maxIntegerType(QualType lhs, QualType rhs);
2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
259fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff  /// compareFloatingType - Handles 3 different combos:
260fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff  /// float/float, float/complex, complex/complex.
261fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff  /// If lt > rt, return 1. If lt == rt, return 0. If lt < rt, return -1.
262fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff  static int compareFloatingType(QualType lt, QualType rt);
2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
264716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff  /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
265716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff  /// point or a complex type (based on typeDomain/typeSize).
266716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff  /// 'typeDomain' is a real floating point or complex type.
267716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff  /// 'typeSize' is a real floating point or complex type.
268f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff  QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
269f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff                                             QualType typeDomain) const;
270ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff
271ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  //===--------------------------------------------------------------------===//
272ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  //                    Type Compatibility Predicates
273ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  //===--------------------------------------------------------------------===//
274ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff
275ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  /// Compatibility predicates used to check assignment expressions.
276ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
277ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool tagTypesAreCompatible(QualType, QualType); // C99 6.2.7p1
278ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool pointerTypesAreCompatible(QualType, QualType);  // C99 6.7.5.1p2
279ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool referenceTypesAreCompatible(QualType, QualType); // C++ 5.17p6
280ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool functionTypesAreCompatible(QualType, QualType); // C99 6.7.5.3p15
281ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
282ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool builtinTypesAreCompatible(QualType, QualType);
283770951b5bb6028a8d326ddb4a13cef7d4a128162Chris Lattner  bool vectorTypesAreCompatible(QualType, QualType);
284ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff
285ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  /// Objective-C specific type checking.
286ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool interfaceTypesAreCompatible(QualType, QualType);
287ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool objcTypesAreCompatible(QualType, QualType);
288ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool isObjcIdType(QualType T) const {
28945ecd5daa36385b7e0b2f657357805e01f5d8cbfSteve Naroff    if (!IdStructType) // ObjC isn't enabled
29045ecd5daa36385b7e0b2f657357805e01f5d8cbfSteve Naroff      return false;
291ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff    return T->getAsStructureType() == IdStructType;
292ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  }
2938baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  bool isObjcClassType(QualType T) const {
29445ecd5daa36385b7e0b2f657357805e01f5d8cbfSteve Naroff    if (!ClassStructType) // ObjC isn't enabled
29545ecd5daa36385b7e0b2f657357805e01f5d8cbfSteve Naroff      return false;
2968baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson    return T->getAsStructureType() == ClassStructType;
2978baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  }
2988baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  bool isObjcSelType(QualType T) const {
2998baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson    assert(SelStructType && "isObjcSelType used before 'SEL' type is built");
3008baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson    return T->getAsStructureType() == SelStructType;
3018baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  }
3028baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext(const ASTContext&); // DO NOT IMPLEMENT
3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void operator=(const ASTContext&); // DO NOT IMPLEMENT
3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void InitBuiltinTypes();
3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void InitBuiltinType(QualType &R, BuiltinType::Kind K);
3097192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek
3107192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  //===--------------------------------------------------------------------===//
3117192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  //                    Serialization
3127192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  //===--------------------------------------------------------------------===//
313aa499b6ab30975d0cea225f71b33e7ee60b88a1fTed Kremenek
314aa499b6ab30975d0cea225f71b33e7ee60b88a1fTed Kremenekpublic:
3157192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  void Emit(llvm::Serializer& S) const;
3160f84c0059cec39fd1c73ac05bc2864dca664e7f4Ted Kremenek  static ASTContext* Create(llvm::Deserializer& D);
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
322