ASTContext.h revision 6c2b6eb8d836da19007f7540709e16d5e39a1cba
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// 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"
256c2b6eb8d836da19007f7540709e16d5e39a1cbaChris Lattner#include "llvm/Support/Allocator.h"
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <vector>
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
30c7229c338c21ef26b01ef3ecf9eec4fd373fa9ecChris Lattner  class IdentifierTable;
31980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ASTContext - This class holds long-lived AST nodes (such as types and
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// decls) that can be referred to throughout the semantic analysis of a file.
342bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenekclass ASTContext {
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  std::vector<Type*> Types;
36ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  llvm::FoldingSet<ASQualType> ASQualTypes;
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<ComplexType> ComplexTypes;
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<PointerType> PointerTypes;
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<ReferenceType> ReferenceTypes;
407192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
41c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
42c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  std::vector<VariableArrayType*> VariableArrayTypes;
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<VectorType> VectorTypes;
445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos;
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
46a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::FoldingSet<ObjCQualifiedInterfaceType> ObjCQualifiedInterfaceTypes;
47a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::FoldingSet<ObjCQualifiedIdType> ObjCQualifiedIdTypes;
4888a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
49a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek  ///  This is lazily created.  This is intentionally not serialized.
5088a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> ASTRecordLayouts;
517d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian
527d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian  llvm::SmallVector<const RecordType *, 8> EncodingRecordTypes;
53b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson
54b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  /// BuiltinVaListType - built-in va list type.
55b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  /// This is initially null and set by Sema::LazilyCreateBuiltin when
56b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  /// a builtin that takes a valist is encountered.
57b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  QualType BuiltinVaListType;
587e219e47de26346885d667131977bd9ca2d7662aSteve Naroff
596083ea3723ec3996ae3bdf8d1b352b0c3b3922c8Ted Kremenek  /// ObjCIdType - a pseudo built-in typedef type (set by Sema).
60a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType ObjCIdType;
617e219e47de26346885d667131977bd9ca2d7662aSteve Naroff  const RecordType *IdStructType;
622198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff
636083ea3723ec3996ae3bdf8d1b352b0c3b3922c8Ted Kremenek  /// ObjCSelType - another pseudo built-in typedef type (set by Sema).
64a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType ObjCSelType;
65b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian  const RecordType *SelStructType;
66b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
676083ea3723ec3996ae3bdf8d1b352b0c3b3922c8Ted Kremenek  /// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
68a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType ObjCProtoType;
69390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian  const RecordType *ProtoStructType;
708baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson
716083ea3723ec3996ae3bdf8d1b352b0c3b3922c8Ted Kremenek  /// ObjCClassType - another pseudo built-in typedef type (set by Sema).
72a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType ObjCClassType;
738baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  const RecordType *ClassStructType;
74390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian
75a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType ObjCConstantStringType;
762198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff  RecordDecl *CFConstantStringTypeDecl;
777a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek
78b800dc2d5e27ec60f567567b623cdc61152b8fb8Chris Lattner  SourceManager &SourceMgr;
796c2b6eb8d836da19007f7540709e16d5e39a1cbaChris Lattner  llvm::MallocAllocator Allocator;
807a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenekpublic:
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TargetInfo &Target;
8271993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson  IdentifierTable &Idents;
8329238a0bf7cbf5b396efb451a0adb5fe4aa037caSteve Naroff  SelectorTable &Selectors;
84a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek
857a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek  SourceManager& getSourceManager() { return SourceMgr; }
866c2b6eb8d836da19007f7540709e16d5e39a1cbaChris Lattner  llvm::MallocAllocator &getAllocator() { return Allocator; }
876c2b6eb8d836da19007f7540709e16d5e39a1cbaChris Lattner
889c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek  FullSourceLoc getFullLoc(SourceLocation Loc) const {
899c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek    return FullSourceLoc(Loc,SourceMgr);
909c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek  }
917a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek
92a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek  /// This is intentionally not serialized.  It is populated by the
93a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek  /// ASTContext ctor, and there are no external pointers/references to
94a9a4a24592a2164114a8a36717650e6341eb67a4Ted Kremenek  /// internal variables of BuiltinInfo.
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Builtin::Context BuiltinInfo;
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Builtin Types.
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType VoidTy;
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType BoolTy;
1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CharTy;
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy;
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType UnsignedLongLongTy;
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType FloatTy, DoubleTy, LongDoubleTy;
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
10633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  QualType VoidPtrTy;
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  ASTContext(SourceManager &SM, TargetInfo &t, IdentifierTable &idents,
109fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek             SelectorTable &sels, unsigned size_reserve=0 ) :
11068d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff    CFConstantStringTypeDecl(0), SourceMgr(SM), Target(t),
11168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff    Idents(idents), Selectors(sels) {
112fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek
113fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek    if (size_reserve > 0) Types.reserve(size_reserve);
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    InitBuiltinTypes();
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    BuiltinInfo.InitializeBuiltins(idents, Target);
116fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek  }
117fee0452973f28691a61aab0fb074468ce3e34b9bTed Kremenek
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ~ASTContext();
1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void PrintStats() const;
12103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  const std::vector<Type*>& getTypes() const { return Types; }
12203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek
123464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
124464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //                           Type Constructors
125464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
126d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner
127f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  /// getASQualType - Return the uniqued reference to the type for an address
128f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  /// space qualified type with the specified type and address space.  The
129f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  /// resulting type has a union of the qualifiers from T and the address space.
130f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // If T already has an address space specifier, it is silently replaced.
131ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  QualType getASQualType(QualType T, unsigned AddressSpace);
132ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getComplexType - Return the uniqued reference to the type for a complex
1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// number with the specified element type.
1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getComplexType(QualType T);
1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getPointerType - Return the uniqued reference to the type for a pointer to
1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the specified type.
1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getPointerType(QualType T);
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getReferenceType - Return the uniqued reference to the type for a
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference to the specified type.
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getReferenceType(QualType T);
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff  /// getVariableArrayType - Returns a non-unique reference to the type for a
146bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff  /// variable array of the specified element type.
147c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
148c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                                ArrayType::ArraySizeModifier ASM,
149c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                                unsigned EltTypeQuals);
150fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
151c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  /// getIncompleteArrayType - Returns a unique reference to the type for a
152c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  /// incomplete array of the specified element type.
153c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  QualType getIncompleteArrayType(QualType EltTy,
154c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman                                  ArrayType::ArraySizeModifier ASM,
155c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman                                  unsigned EltTypeQuals);
156c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
157bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff  /// getConstantArrayType - Return the unique reference to the type for a
158bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff  /// constant array of the specified element type.
159c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
160c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                                ArrayType::ArraySizeModifier ASM,
161c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                                unsigned EltTypeQuals);
1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16373322924127c873c13101b705dd823f5539ffa5fSteve Naroff  /// getVectorType - Return the unique reference to a vector type of
16473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  /// the specified element type and size. VectorType must be a built-in type.
16573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  QualType getVectorType(QualType VectorType, unsigned NumElts);
16673322924127c873c13101b705dd823f5539ffa5fSteve Naroff
16773322924127c873c13101b705dd823f5539ffa5fSteve Naroff  /// getOCUVectorType - Return the unique reference to an OCU vector type of
16873322924127c873c13101b705dd823f5539ffa5fSteve Naroff  /// the specified element type and size. VectorType must be a built-in type.
16973322924127c873c13101b705dd823f5539ffa5fSteve Naroff  QualType getOCUVectorType(QualType VectorType, unsigned NumElts);
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'.
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getFunctionTypeNoProto(QualType ResultTy);
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getFunctionType - Return a normal function type with a typed argument
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// list.  isVariadic indicates whether the argument list includes '...'.
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getFunctionType(QualType ResultTy, QualType *ArgArray,
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                           unsigned NumArgs, bool isVariadic);
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getTypedefType - Return the unique reference to the type for the
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// specified typename decl.
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getTypedefType(TypedefDecl *Decl);
183a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType getObjCInterfaceType(ObjCInterfaceDecl *Decl);
1844b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian
185a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// getObjCQualifiedInterfaceType - Return a
186a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// ObjCQualifiedInterfaceType type for the given interface decl and
1874b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  /// the conforming protocol list.
188a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl,
189a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek             ObjCProtocolDecl **ProtocolList, unsigned NumProtocols);
190c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian
191a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// getObjCQualifiedIdType - Return an ObjCQualifiedIdType for a
192c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  /// given 'id' and conforming protocol list.
193a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType getObjCQualifiedIdType(QualType idType,
194a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                                  ObjCProtocolDecl **ProtocolList,
195c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian                                  unsigned NumProtocols);
196c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
198d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  /// getTypeOfType - GCC extension.
1998d1a3b8ca1e5fcc4567b5a6f51d82be2e460de1cSteve Naroff  QualType getTypeOfExpr(Expr *e);
200d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getTypeOfType(QualType t);
201d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getTagDeclType - Return the unique reference to the type for the
2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// specified TagDecl (struct/union/class/enum) decl.
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getTagDeclType(TagDecl *Decl);
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getSizeType() const;
209fd888a581d6d329f5b447c8ff4d37cf396315993Eli Friedman
210fd888a581d6d329f5b447c8ff4d37cf396315993Eli Friedman  /// getWcharType - Return the unique type for "wchar_t" (C99 7.17), defined
211fd888a581d6d329f5b447c8ff4d37cf396315993Eli Friedman  /// in <stddef.h>. Wide strings require this (C99 6.4.5p5).
212fd888a581d6d329f5b447c8ff4d37cf396315993Eli Friedman  QualType getWcharType() const;
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2148b9023ba35a86838789e2c9034a6128728c547aaChris Lattner  /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
2158b9023ba35a86838789e2c9034a6128728c547aaChris Lattner  /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
2168b9023ba35a86838789e2c9034a6128728c547aaChris Lattner  QualType getPointerDiffType() const;
2178b9023ba35a86838789e2c9034a6128728c547aaChris Lattner
218beaf299a2701c5559a4e5d76b0c40f805afb8e6aSteve Naroff  // getCFConstantStringType - Return the C structure type used to represent
219beaf299a2701c5559a4e5d76b0c40f805afb8e6aSteve Naroff  // constant CFStrings.
22071993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson  QualType getCFConstantStringType();
22171993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson
222983df5b2280980e59b0b062bcc2882230465a61eSteve Naroff  // This setter/getter represents the ObjC type for an NSConstantString.
223a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
224a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType getObjCConstantStringInterface() const {
225a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    return ObjCConstantStringType;
2262198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff  }
227b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
22885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson  // Return the ObjC type encoding for a given type.
2297d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian  void getObjCEncodingForType(QualType t, std::string &S,
230c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner                              llvm::SmallVector<const RecordType *, 8> &RT) const;
23133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian
232ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian  // Put the string version of type qualifiers into S.
233a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
234ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian                                       std::string &S) const;
235ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian
236a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// getObjCEncodingForMethodDecl - Return the encoded type for this method
23733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  /// declaration.
238a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void getObjCEncodingForMethodDecl(ObjCMethodDecl *Decl, std::string &S);
23933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian
240a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// getObjCEncodingTypeSize returns size of type for objective-c encoding
24133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  /// purpose.
242a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  int getObjCEncodingTypeSize(QualType t);
24385f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson
244983df5b2280980e59b0b062bcc2882230465a61eSteve Naroff  // This setter/getter repreents the ObjC 'id' type. It is setup lazily, by
245983df5b2280980e59b0b062bcc2882230465a61eSteve Naroff  // Sema.
246a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCIdType(TypedefDecl *Decl);
247a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType getObjCIdType() const { return ObjCIdType; }
248b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
249a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCSelType(TypedefDecl *Decl);
250a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType getObjCSelType() const { return ObjCSelType; }
251b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
252a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCProtoType(QualType QT);
253a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType getObjCProtoType() const { return ObjCProtoType; }
254390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian
255a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCClassType(TypedefDecl *Decl);
256a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  QualType getObjCClassType() const { return ObjCClassType; }
2578baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson
258b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  void setBuiltinVaListType(QualType T);
259b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson  QualType getBuiltinVaListType() const { return BuiltinVaListType; }
260b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson
261464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
262464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //                         Type Sizing and Analysis
263464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
264464175bba1318bef7905122e9fda20cff926df78Chris Lattner
265464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// getTypeInfo - Get the size and alignment of the specified complete type in
266464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// bits.
26798be4943e8dc4f3905629a7102668960873cf863Chris Lattner  std::pair<uint64_t, unsigned> getTypeInfo(QualType T);
268464175bba1318bef7905122e9fda20cff926df78Chris Lattner
269464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// getTypeSize - Return the size of the specified type, in bits.  This method
270464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// does not work on incomplete types.
27198be4943e8dc4f3905629a7102668960873cf863Chris Lattner  uint64_t getTypeSize(QualType T) {
27298be4943e8dc4f3905629a7102668960873cf863Chris Lattner    return getTypeInfo(T).first;
273464175bba1318bef7905122e9fda20cff926df78Chris Lattner  }
274464175bba1318bef7905122e9fda20cff926df78Chris Lattner
275464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// getTypeAlign - Return the alignment of the specified type, in bits.  This
276464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// method does not work on incomplete types.
27798be4943e8dc4f3905629a7102668960873cf863Chris Lattner  unsigned getTypeAlign(QualType T) {
27898be4943e8dc4f3905629a7102668960873cf863Chris Lattner    return getTypeInfo(T).second;
279464175bba1318bef7905122e9fda20cff926df78Chris Lattner  }
280464175bba1318bef7905122e9fda20cff926df78Chris Lattner
28188a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  /// getASTRecordLayout - Get or compute information about the layout of the
282464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// specified record (struct/union/class), which indicates its size and field
283464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// position information.
28498be4943e8dc4f3905629a7102668960873cf863Chris Lattner  const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D);
285464175bba1318bef7905122e9fda20cff926df78Chris Lattner
286464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
287464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //                            Type Operators
288464175bba1318bef7905122e9fda20cff926df78Chris Lattner  //===--------------------------------------------------------------------===//
289464175bba1318bef7905122e9fda20cff926df78Chris Lattner
290464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// maxIntegerType - Returns the highest ranked integer type. Handles 3
291464175bba1318bef7905122e9fda20cff926df78Chris Lattner  /// different type combos: unsigned/unsigned, signed/signed, signed/unsigned.
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType maxIntegerType(QualType lhs, QualType rhs);
2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
294fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff  /// compareFloatingType - Handles 3 different combos:
295fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff  /// float/float, float/complex, complex/complex.
296fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff  /// If lt > rt, return 1. If lt == rt, return 0. If lt < rt, return -1.
297fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff  static int compareFloatingType(QualType lt, QualType rt);
2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
299716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff  /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
300716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff  /// point or a complex type (based on typeDomain/typeSize).
301716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff  /// 'typeDomain' is a real floating point or complex type.
302716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff  /// 'typeSize' is a real floating point or complex type.
303f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff  QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
304f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff                                             QualType typeDomain) const;
305ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff
306ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  //===--------------------------------------------------------------------===//
307ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  //                    Type Compatibility Predicates
308ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  //===--------------------------------------------------------------------===//
309ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff
310ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  /// Compatibility predicates used to check assignment expressions.
311ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
312ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool tagTypesAreCompatible(QualType, QualType); // C99 6.2.7p1
313ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool pointerTypesAreCompatible(QualType, QualType);  // C99 6.7.5.1p2
314ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool referenceTypesAreCompatible(QualType, QualType); // C++ 5.17p6
315ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool functionTypesAreCompatible(QualType, QualType); // C99 6.7.5.3p15
316ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
317ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool builtinTypesAreCompatible(QualType, QualType);
318770951b5bb6028a8d326ddb4a13cef7d4a128162Chris Lattner  bool vectorTypesAreCompatible(QualType, QualType);
319ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff
3204ffc54111fdc0baa45bb287f59774e06dea8caa4Fariborz Jahanian  bool QualifiedInterfaceTypesAreCompatible(QualType, QualType);
321a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  bool ObjCQualifiedIdTypesAreCompatible(QualType, QualType, bool = false);
322ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  bool objcTypesAreCompatible(QualType, QualType);
323a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  bool isObjCIdType(QualType T) const {
32445ecd5daa36385b7e0b2f657357805e01f5d8cbfSteve Naroff    if (!IdStructType) // ObjC isn't enabled
32545ecd5daa36385b7e0b2f657357805e01f5d8cbfSteve Naroff      return false;
326ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff    return T->getAsStructureType() == IdStructType;
327ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff  }
328a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  bool isObjCClassType(QualType T) const {
32945ecd5daa36385b7e0b2f657357805e01f5d8cbfSteve Naroff    if (!ClassStructType) // ObjC isn't enabled
33045ecd5daa36385b7e0b2f657357805e01f5d8cbfSteve Naroff      return false;
3318baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson    return T->getAsStructureType() == ClassStructType;
3328baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  }
333a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  bool isObjCSelType(QualType T) const {
334a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    assert(SelStructType && "isObjCSelType used before 'SEL' type is built");
3358baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson    return T->getAsStructureType() == SelStructType;
3368baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson  }
3378baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext(const ASTContext&); // DO NOT IMPLEMENT
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void operator=(const ASTContext&); // DO NOT IMPLEMENT
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void InitBuiltinTypes();
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void InitBuiltinType(QualType &R, BuiltinType::Kind K);
3448cc71e8d00896e758cf56ea86cfc1f62ade16478Fariborz Jahanian
3458cc71e8d00896e758cf56ea86cfc1f62ade16478Fariborz Jahanian  /// helper function for Objective-C specific type checking.
3468cc71e8d00896e758cf56ea86cfc1f62ade16478Fariborz Jahanian  bool interfaceTypesAreCompatible(QualType, QualType);
3477192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek
3487192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  //===--------------------------------------------------------------------===//
3497192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  //                    Serialization
3507192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  //===--------------------------------------------------------------------===//
351aa499b6ab30975d0cea225f71b33e7ee60b88a1fTed Kremenek
352aa499b6ab30975d0cea225f71b33e7ee60b88a1fTed Kremenekpublic:
3537192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek  void Emit(llvm::Serializer& S) const;
3540f84c0059cec39fd1c73ac05bc2864dca664e7f4Ted Kremenek  static ASTContext* Create(llvm::Deserializer& D);
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
360