ASTContext.h revision 400f5125e2432d648f2c8a31b36a7f318a880c47
1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===//
2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//
3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//                     The LLVM Compiler Infrastructure
4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//
5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source
6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// License. See LICENSE.TXT for details.
7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//
87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch//===----------------------------------------------------------------------===//
9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//  This file defines the ASTContext interface.
110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch//
127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch//===----------------------------------------------------------------------===//
137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#ifndef LLVM_CLANG_AST_ASTCONTEXT_H
15effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#define LLVM_CLANG_AST_ASTCONTEXT_H
167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/Basic/IdentifierTable.h"
18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/Basic/LangOptions.h"
19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/Basic/OperatorKinds.h"
20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/Basic/PartialDiagnostic.h"
21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/AST/Attr.h"
22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/AST/Decl.h"
23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/AST/NestedNameSpecifier.h"
24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/AST/PrettyPrinter.h"
2546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "clang/AST/TemplateName.h"
26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/AST/Type.h"
27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "clang/AST/CanonicalType.h"
287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "clang/AST/UsuallyTinyPtrVector.h"
297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "llvm/ADT/DenseMap.h"
307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "llvm/ADT/FoldingSet.h"
317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "llvm/ADT/OwningPtr.h"
324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "llvm/ADT/SmallPtrSet.h"
334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "llvm/Support/Allocator.h"
344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <vector>
354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace llvm {
374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  struct fltSemantics;
384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  class raw_ostream;
39f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
41f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)namespace clang {
42f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class FileManager;
43f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class ASTRecordLayout;
44f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class BlockExpr;
45f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class CharUnits;
46f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class Diagnostic;
47f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class Expr;
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  class ExternalASTSource;
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  class IdentifierTable;
501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  class SelectorTable;
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  class SourceManager;
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  class TargetInfo;
5368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Decls
5468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  class DeclContext;
555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  class CXXMethodDecl;
565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  class CXXRecordDecl;
575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  class Decl;
584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  class FieldDecl;
594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  class ObjCIvarDecl;
60f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class ObjCIvarRefExpr;
61f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class ObjCPropertyDecl;
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  class RecordDecl;
63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  class StoredDeclsMap;
64f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class TagDecl;
65f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class TemplateTemplateParmDecl;
66f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class TemplateTypeParmDecl;
67f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class TranslationUnitDecl;
68f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  class TypeDecl;
695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  class TypedefDecl;
704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  class UsingDecl;
714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  class UsingShadowDecl;
724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  class UnresolvedSetIterator;
734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  namespace Builtin { class Context; }
754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/// ASTContext - This class holds long-lived AST nodes (such as types and
774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/// decls) that can be referred to throughout the semantic analysis of a file.
784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class ASTContext {
794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ASTContext &this_() { return *this; }
804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  std::vector<Type*> Types;
824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  llvm::FoldingSet<ExtQuals> ExtQualNodes;
834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  llvm::FoldingSet<ComplexType> ComplexTypes;
844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  llvm::FoldingSet<PointerType> PointerTypes;
855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
90effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
91ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  std::vector<VariableArrayType*> VariableArrayTypes;
92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  llvm::FoldingSet<DependentSizedExtVectorType> DependentSizedExtVectorTypes;
94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  llvm::FoldingSet<VectorType> VectorTypes;
95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  llvm::FoldingSet<FunctionProtoType> FunctionProtoTypes;
97a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
9968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
10068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  llvm::FoldingSet<SubstTemplateTypeParmType> SubstTemplateTypeParmTypes;
10168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
10268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    TemplateSpecializationTypes;
10368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
10468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  llvm::FoldingSet<DependentNameType> DependentNameTypes;
105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  llvm::ContextualFoldingSet<DependentTemplateSpecializationType, ASTContext&>
1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    DependentTemplateSpecializationTypes;
1074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
1114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// \brief The set of nested name specifiers.
114cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ///
115f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  /// This set is managed by the NestedNameSpecifier class.
116f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  NestedNameSpecifier *GlobalNestedNameSpecifier;
118cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class NestedNameSpecifier;
119cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
120cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
121cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ///  This is lazily created.  This is intentionally not serialized.
122f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> ASTRecordLayouts;
123f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*> ObjCLayouts;
124cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// KeyFunctions - A cache mapping from CXXRecordDecls to key functions.
1264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  llvm::DenseMap<const CXXRecordDecl*, const CXXMethodDecl*> KeyFunctions;
1274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  /// \brief Mapping from ObjCContainers to their ObjCImplementations.
129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// \brief Representation of a "canonical" template template parameter that
132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// is used in canonical template names.
133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
134    TemplateTemplateParmDecl *Parm;
135
136  public:
137    CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm)
138      : Parm(Parm) { }
139
140    TemplateTemplateParmDecl *getParam() const { return Parm; }
141
142    void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); }
143
144    static void Profile(llvm::FoldingSetNodeID &ID,
145                        TemplateTemplateParmDecl *Parm);
146  };
147  llvm::FoldingSet<CanonicalTemplateTemplateParm> CanonTemplateTemplateParms;
148
149  TemplateTemplateParmDecl *getCanonicalTemplateTemplateParmDecl(
150                                               TemplateTemplateParmDecl *TTP);
151
152  /// \brief Whether __[u]int128_t identifier is installed.
153  bool IsInt128Installed;
154
155  /// BuiltinVaListType - built-in va list type.
156  /// This is initially null and set by Sema::LazilyCreateBuiltin when
157  /// a builtin that takes a valist is encountered.
158  QualType BuiltinVaListType;
159
160  /// ObjCIdType - a pseudo built-in typedef type (set by Sema).
161  QualType ObjCIdTypedefType;
162
163  /// ObjCSelType - another pseudo built-in typedef type (set by Sema).
164  QualType ObjCSelTypedefType;
165
166  /// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
167  QualType ObjCProtoType;
168  const RecordType *ProtoStructType;
169
170  /// ObjCClassType - another pseudo built-in typedef type (set by Sema).
171  QualType ObjCClassTypedefType;
172
173  QualType ObjCConstantStringType;
174  RecordDecl *CFConstantStringTypeDecl;
175
176  RecordDecl *NSConstantStringTypeDecl;
177
178  RecordDecl *ObjCFastEnumerationStateTypeDecl;
179
180  /// \brief The type for the C FILE type.
181  TypeDecl *FILEDecl;
182
183  /// \brief The type for the C jmp_buf type.
184  TypeDecl *jmp_bufDecl;
185
186  /// \brief The type for the C sigjmp_buf type.
187  TypeDecl *sigjmp_bufDecl;
188
189  /// \brief Type for the Block descriptor for Blocks CodeGen.
190  RecordDecl *BlockDescriptorType;
191
192  /// \brief Type for the Block descriptor for Blocks CodeGen.
193  RecordDecl *BlockDescriptorExtendedType;
194
195  TypeSourceInfo NullTypeSourceInfo;
196
197  /// \brief Keeps track of all declaration attributes.
198  ///
199  /// Since so few decls have attrs, we keep them in a hash map instead of
200  /// wasting space in the Decl class.
201  llvm::DenseMap<const Decl*, Attr*> DeclAttrs;
202
203  /// \brief Keeps track of the static data member templates from which
204  /// static data members of class template specializations were instantiated.
205  ///
206  /// This data structure stores the mapping from instantiations of static
207  /// data members to the static data member representations within the
208  /// class template from which they were instantiated along with the kind
209  /// of instantiation or specialization (a TemplateSpecializationKind - 1).
210  ///
211  /// Given the following example:
212  ///
213  /// \code
214  /// template<typename T>
215  /// struct X {
216  ///   static T value;
217  /// };
218  ///
219  /// template<typename T>
220  ///   T X<T>::value = T(17);
221  ///
222  /// int *x = &X<int>::value;
223  /// \endcode
224  ///
225  /// This mapping will contain an entry that maps from the VarDecl for
226  /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
227  /// class template X) and will be marked TSK_ImplicitInstantiation.
228  llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *>
229    InstantiatedFromStaticDataMember;
230
231  /// \brief Keeps track of the declaration from which a UsingDecl was
232  /// created during instantiation.  The source declaration is always
233  /// a UsingDecl, an UnresolvedUsingValueDecl, or an
234  /// UnresolvedUsingTypenameDecl.
235  ///
236  /// For example:
237  /// \code
238  /// template<typename T>
239  /// struct A {
240  ///   void f();
241  /// };
242  ///
243  /// template<typename T>
244  /// struct B : A<T> {
245  ///   using A<T>::f;
246  /// };
247  ///
248  /// template struct B<int>;
249  /// \endcode
250  ///
251  /// This mapping will contain an entry that maps from the UsingDecl in
252  /// B<int> to the UnresolvedUsingDecl in B<T>.
253  llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl;
254
255  llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
256    InstantiatedFromUsingShadowDecl;
257
258  llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
259
260  /// \brief Mapping that stores the methods overridden by a given C++
261  /// member function.
262  ///
263  /// Since most C++ member functions aren't virtual and therefore
264  /// don't override anything, we store the overridden functions in
265  /// this map on the side rather than within the CXXMethodDecl structure.
266  typedef UsuallyTinyPtrVector<const CXXMethodDecl> CXXMethodVector;
267  llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
268
269  TranslationUnitDecl *TUDecl;
270
271  /// SourceMgr - The associated SourceManager object.
272  SourceManager &SourceMgr;
273
274  /// LangOpts - The language options used to create the AST associated with
275  ///  this ASTContext object.
276  LangOptions LangOpts;
277
278  /// MallocAlloc/BumpAlloc - The allocator objects used to create AST objects.
279  bool FreeMemory;
280  llvm::MallocAllocator MallocAlloc;
281  llvm::BumpPtrAllocator BumpAlloc;
282
283  /// \brief Allocator for partial diagnostics.
284  PartialDiagnostic::StorageAllocator DiagAllocator;
285
286public:
287  const TargetInfo &Target;
288  IdentifierTable &Idents;
289  SelectorTable &Selectors;
290  Builtin::Context &BuiltinInfo;
291  DeclarationNameTable DeclarationNames;
292  llvm::OwningPtr<ExternalASTSource> ExternalSource;
293  clang::PrintingPolicy PrintingPolicy;
294
295  // Typedefs which may be provided defining the structure of Objective-C
296  // pseudo-builtins
297  QualType ObjCIdRedefinitionType;
298  QualType ObjCClassRedefinitionType;
299  QualType ObjCSelRedefinitionType;
300
301  SourceManager& getSourceManager() { return SourceMgr; }
302  const SourceManager& getSourceManager() const { return SourceMgr; }
303  void *Allocate(unsigned Size, unsigned Align = 8) {
304    return FreeMemory ? MallocAlloc.Allocate(Size, Align) :
305                        BumpAlloc.Allocate(Size, Align);
306  }
307  void Deallocate(void *Ptr) {
308    if (FreeMemory)
309      MallocAlloc.Deallocate(Ptr);
310  }
311
312  PartialDiagnostic::StorageAllocator &getDiagAllocator() {
313    return DiagAllocator;
314  }
315
316  const LangOptions& getLangOptions() const { return LangOpts; }
317
318  FullSourceLoc getFullLoc(SourceLocation Loc) const {
319    return FullSourceLoc(Loc,SourceMgr);
320  }
321
322  /// \brief Retrieve the attributes for the given declaration.
323  Attr*& getDeclAttrs(const Decl *D) { return DeclAttrs[D]; }
324
325  /// \brief Erase the attributes corresponding to the given declaration.
326  void eraseDeclAttrs(const Decl *D) { DeclAttrs.erase(D); }
327
328  /// \brief If this variable is an instantiated static data member of a
329  /// class template specialization, returns the templated static data member
330  /// from which it was instantiated.
331  MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
332                                                           const VarDecl *Var);
333
334  /// \brief Note that the static data member \p Inst is an instantiation of
335  /// the static data member template \p Tmpl of a class template.
336  void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
337                                           TemplateSpecializationKind TSK,
338                        SourceLocation PointOfInstantiation = SourceLocation());
339
340  /// \brief If the given using decl is an instantiation of a
341  /// (possibly unresolved) using decl from a template instantiation,
342  /// return it.
343  NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
344
345  /// \brief Remember that the using decl \p Inst is an instantiation
346  /// of the using decl \p Pattern of a class template.
347  void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
348
349  void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
350                                          UsingShadowDecl *Pattern);
351  UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
352
353  FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
354
355  void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
356
357  // Access to the set of methods overridden by the given C++ method.
358  typedef CXXMethodVector::iterator overridden_cxx_method_iterator;
359  overridden_cxx_method_iterator
360  overridden_methods_begin(const CXXMethodDecl *Method) const;
361
362  overridden_cxx_method_iterator
363  overridden_methods_end(const CXXMethodDecl *Method) const;
364
365  unsigned overridden_methods_size(const CXXMethodDecl *Method) const;
366
367  /// \brief Note that the given C++ \p Method overrides the given \p
368  /// Overridden method.
369  void addOverriddenMethod(const CXXMethodDecl *Method,
370                           const CXXMethodDecl *Overridden);
371
372  TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
373
374
375  // Builtin Types.
376  CanQualType VoidTy;
377  CanQualType BoolTy;
378  CanQualType CharTy;
379  CanQualType WCharTy;  // [C++ 3.9.1p5], integer type in C99.
380  CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
381  CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
382  CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
383  CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
384  CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
385  CanQualType FloatTy, DoubleTy, LongDoubleTy;
386  CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
387  CanQualType VoidPtrTy, NullPtrTy;
388  CanQualType OverloadTy;
389  CanQualType DependentTy;
390  CanQualType UndeducedAutoTy;
391  CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
392
393  ASTContext(const LangOptions& LOpts, SourceManager &SM, const TargetInfo &t,
394             IdentifierTable &idents, SelectorTable &sels,
395             Builtin::Context &builtins,
396             bool FreeMemory = true, unsigned size_reserve=0);
397
398  ~ASTContext();
399
400  /// \brief Attach an external AST source to the AST context.
401  ///
402  /// The external AST source provides the ability to load parts of
403  /// the abstract syntax tree as needed from some external storage,
404  /// e.g., a precompiled header.
405  void setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source);
406
407  /// \brief Retrieve a pointer to the external AST source associated
408  /// with this AST context, if any.
409  ExternalASTSource *getExternalSource() const { return ExternalSource.get(); }
410
411  void PrintStats() const;
412  const std::vector<Type*>& getTypes() const { return Types; }
413
414  //===--------------------------------------------------------------------===//
415  //                           Type Constructors
416  //===--------------------------------------------------------------------===//
417
418private:
419  /// getExtQualType - Return a type with extended qualifiers.
420  QualType getExtQualType(const Type *Base, Qualifiers Quals);
421
422  QualType getTypeDeclTypeSlow(const TypeDecl *Decl);
423
424public:
425  /// getAddSpaceQualType - Return the uniqued reference to the type for an
426  /// address space qualified type with the specified type and address space.
427  /// The resulting type has a union of the qualifiers from T and the address
428  /// space. If T already has an address space specifier, it is silently
429  /// replaced.
430  QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace);
431
432  /// getObjCGCQualType - Returns the uniqued reference to the type for an
433  /// objc gc qualified type. The retulting type has a union of the qualifiers
434  /// from T and the gc attribute.
435  QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr);
436
437  /// getRestrictType - Returns the uniqued reference to the type for a
438  /// 'restrict' qualified type.  The resulting type has a union of the
439  /// qualifiers from T and 'restrict'.
440  QualType getRestrictType(QualType T) {
441    return T.withFastQualifiers(Qualifiers::Restrict);
442  }
443
444  /// getVolatileType - Returns the uniqued reference to the type for a
445  /// 'volatile' qualified type.  The resulting type has a union of the
446  /// qualifiers from T and 'volatile'.
447  QualType getVolatileType(QualType T);
448
449  /// getConstType - Returns the uniqued reference to the type for a
450  /// 'const' qualified type.  The resulting type has a union of the
451  /// qualifiers from T and 'const'.
452  ///
453  /// It can be reasonably expected that this will always be
454  /// equivalent to calling T.withConst().
455  QualType getConstType(QualType T) { return T.withConst(); }
456
457  /// getNoReturnType - Add or remove the noreturn attribute to the given type
458  /// which must be a FunctionType or a pointer to an allowable type or a
459  /// BlockPointer.
460  QualType getNoReturnType(QualType T, bool AddNoReturn = true);
461
462  /// getCallConvType - Adds the specified calling convention attribute to
463  /// the given type, which must be a FunctionType or a pointer to an
464  /// allowable type.
465  QualType getCallConvType(QualType T, CallingConv CallConv);
466
467  /// getRegParmType - Sets the specified regparm attribute to
468  /// the given type, which must be a FunctionType or a pointer to an
469  /// allowable type.
470  QualType getRegParmType(QualType T, unsigned RegParm);
471
472  /// getComplexType - Return the uniqued reference to the type for a complex
473  /// number with the specified element type.
474  QualType getComplexType(QualType T);
475  CanQualType getComplexType(CanQualType T) {
476    return CanQualType::CreateUnsafe(getComplexType((QualType) T));
477  }
478
479  /// getPointerType - Return the uniqued reference to the type for a pointer to
480  /// the specified type.
481  QualType getPointerType(QualType T);
482  CanQualType getPointerType(CanQualType T) {
483    return CanQualType::CreateUnsafe(getPointerType((QualType) T));
484  }
485
486  /// getBlockPointerType - Return the uniqued reference to the type for a block
487  /// of the specified type.
488  QualType getBlockPointerType(QualType T);
489
490  /// This gets the struct used to keep track of the descriptor for pointer to
491  /// blocks.
492  QualType getBlockDescriptorType();
493
494  // Set the type for a Block descriptor type.
495  void setBlockDescriptorType(QualType T);
496  /// Get the BlockDescriptorType type, or NULL if it hasn't yet been built.
497  QualType getRawBlockdescriptorType() {
498    if (BlockDescriptorType)
499      return getTagDeclType(BlockDescriptorType);
500    return QualType();
501  }
502
503  /// This gets the struct used to keep track of the extended descriptor for
504  /// pointer to blocks.
505  QualType getBlockDescriptorExtendedType();
506
507  // Set the type for a Block descriptor extended type.
508  void setBlockDescriptorExtendedType(QualType T);
509  /// Get the BlockDescriptorExtendedType type, or NULL if it hasn't yet been
510  /// built.
511  QualType getRawBlockdescriptorExtendedType() {
512    if (BlockDescriptorExtendedType)
513      return getTagDeclType(BlockDescriptorExtendedType);
514    return QualType();
515  }
516
517  /// This gets the struct used to keep track of pointer to blocks, complete
518  /// with captured variables.
519  QualType getBlockParmType(bool BlockHasCopyDispose,
520                            llvm::SmallVectorImpl<const Expr *> &Layout);
521
522  /// This builds the struct used for __block variables.
523  QualType BuildByRefType(const char *DeclName, QualType Ty);
524
525  /// Returns true iff we need copy/dispose helpers for the given type.
526  bool BlockRequiresCopying(QualType Ty);
527
528  /// getLValueReferenceType - Return the uniqued reference to the type for an
529  /// lvalue reference to the specified type.
530  QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true);
531
532  /// getRValueReferenceType - Return the uniqued reference to the type for an
533  /// rvalue reference to the specified type.
534  QualType getRValueReferenceType(QualType T);
535
536  /// getMemberPointerType - Return the uniqued reference to the type for a
537  /// member pointer to the specified type in the specified class. The class
538  /// is a Type because it could be a dependent name.
539  QualType getMemberPointerType(QualType T, const Type *Cls);
540
541  /// getVariableArrayType - Returns a non-unique reference to the type for a
542  /// variable array of the specified element type.
543  QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
544                                ArrayType::ArraySizeModifier ASM,
545                                unsigned EltTypeQuals,
546                                SourceRange Brackets);
547
548  /// getDependentSizedArrayType - Returns a non-unique reference to
549  /// the type for a dependently-sized array of the specified element
550  /// type. FIXME: We will need these to be uniqued, or at least
551  /// comparable, at some point.
552  QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
553                                      ArrayType::ArraySizeModifier ASM,
554                                      unsigned EltTypeQuals,
555                                      SourceRange Brackets);
556
557  /// getIncompleteArrayType - Returns a unique reference to the type for a
558  /// incomplete array of the specified element type.
559  QualType getIncompleteArrayType(QualType EltTy,
560                                  ArrayType::ArraySizeModifier ASM,
561                                  unsigned EltTypeQuals);
562
563  /// getConstantArrayType - Return the unique reference to the type for a
564  /// constant array of the specified element type.
565  QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
566                                ArrayType::ArraySizeModifier ASM,
567                                unsigned EltTypeQuals);
568
569  /// getVectorType - Return the unique reference to a vector type of
570  /// the specified element type and size. VectorType must be a built-in type.
571  QualType getVectorType(QualType VectorType, unsigned NumElts,
572                         VectorType::AltiVecSpecific AltiVecSpec);
573
574  /// getExtVectorType - Return the unique reference to an extended vector type
575  /// of the specified element type and size.  VectorType must be a built-in
576  /// type.
577  QualType getExtVectorType(QualType VectorType, unsigned NumElts);
578
579  /// getDependentSizedExtVectorType - Returns a non-unique reference to
580  /// the type for a dependently-sized vector of the specified element
581  /// type. FIXME: We will need these to be uniqued, or at least
582  /// comparable, at some point.
583  QualType getDependentSizedExtVectorType(QualType VectorType,
584                                          Expr *SizeExpr,
585                                          SourceLocation AttrLoc);
586
587  /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'.
588  ///
589  QualType getFunctionNoProtoType(QualType ResultTy,
590                                  const FunctionType::ExtInfo &Info);
591
592  QualType getFunctionNoProtoType(QualType ResultTy) {
593    return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo());
594  }
595
596  /// getFunctionType - Return a normal function type with a typed argument
597  /// list.  isVariadic indicates whether the argument list includes '...'.
598  QualType getFunctionType(QualType ResultTy, const QualType *ArgArray,
599                           unsigned NumArgs, bool isVariadic,
600                           unsigned TypeQuals, bool hasExceptionSpec,
601                           bool hasAnyExceptionSpec,
602                           unsigned NumExs, const QualType *ExArray,
603                           const FunctionType::ExtInfo &Info);
604
605  /// getTypeDeclType - Return the unique reference to the type for
606  /// the specified type declaration.
607  QualType getTypeDeclType(const TypeDecl *Decl,
608                           const TypeDecl *PrevDecl = 0) {
609    assert(Decl && "Passed null for Decl param");
610    if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
611
612    if (PrevDecl) {
613      assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
614      Decl->TypeForDecl = PrevDecl->TypeForDecl;
615      return QualType(PrevDecl->TypeForDecl, 0);
616    }
617
618    return getTypeDeclTypeSlow(Decl);
619  }
620
621  /// getTypedefType - Return the unique reference to the type for the
622  /// specified typename decl.
623  QualType getTypedefType(const TypedefDecl *Decl, QualType Canon = QualType());
624
625  QualType getRecordType(const RecordDecl *Decl);
626
627  QualType getEnumType(const EnumDecl *Decl);
628
629  QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST);
630
631  QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
632                                        QualType Replacement);
633
634  QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
635                                   bool ParameterPack,
636                                   IdentifierInfo *Name = 0);
637
638  QualType getTemplateSpecializationType(TemplateName T,
639                                         const TemplateArgument *Args,
640                                         unsigned NumArgs,
641                                         QualType Canon = QualType());
642
643  QualType getCanonicalTemplateSpecializationType(TemplateName T,
644                                                  const TemplateArgument *Args,
645                                                  unsigned NumArgs);
646
647  QualType getTemplateSpecializationType(TemplateName T,
648                                         const TemplateArgumentListInfo &Args,
649                                         QualType Canon = QualType());
650
651  TypeSourceInfo *
652  getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc,
653                                    const TemplateArgumentListInfo &Args,
654                                    QualType Canon = QualType());
655
656  QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
657                             NestedNameSpecifier *NNS,
658                             QualType NamedType);
659  QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
660                                NestedNameSpecifier *NNS,
661                                const IdentifierInfo *Name,
662                                QualType Canon = QualType());
663
664  QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
665                                                  NestedNameSpecifier *NNS,
666                                                  const IdentifierInfo *Name,
667                                          const TemplateArgumentListInfo &Args);
668  QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
669                                                  NestedNameSpecifier *NNS,
670                                                  const IdentifierInfo *Name,
671                                                  unsigned NumArgs,
672                                                  const TemplateArgument *Args);
673
674  QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl);
675
676  QualType getObjCObjectType(QualType Base,
677                             ObjCProtocolDecl * const *Protocols,
678                             unsigned NumProtocols);
679
680  /// getObjCObjectPointerType - Return a ObjCObjectPointerType type
681  /// for the given ObjCObjectType.
682  QualType getObjCObjectPointerType(QualType OIT);
683
684  /// getTypeOfType - GCC extension.
685  QualType getTypeOfExprType(Expr *e);
686  QualType getTypeOfType(QualType t);
687
688  /// getDecltypeType - C++0x decltype.
689  QualType getDecltypeType(Expr *e);
690
691  /// getTagDeclType - Return the unique reference to the type for the
692  /// specified TagDecl (struct/union/class/enum) decl.
693  QualType getTagDeclType(const TagDecl *Decl);
694
695  /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
696  /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
697  CanQualType getSizeType() const;
698
699  /// getWCharType - In C++, this returns the unique wchar_t type.  In C99, this
700  /// returns a type compatible with the type defined in <stddef.h> as defined
701  /// by the target.
702  QualType getWCharType() const { return WCharTy; }
703
704  /// getSignedWCharType - Return the type of "signed wchar_t".
705  /// Used when in C++, as a GCC extension.
706  QualType getSignedWCharType() const;
707
708  /// getUnsignedWCharType - Return the type of "unsigned wchar_t".
709  /// Used when in C++, as a GCC extension.
710  QualType getUnsignedWCharType() const;
711
712  /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
713  /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
714  QualType getPointerDiffType() const;
715
716  // getCFConstantStringType - Return the C structure type used to represent
717  // constant CFStrings.
718  QualType getCFConstantStringType();
719
720  // getNSConstantStringType - Return the C structure type used to represent
721  // constant NSStrings.
722  QualType getNSConstantStringType();
723  /// Get the structure type used to representation NSStrings, or NULL
724  /// if it hasn't yet been built.
725  QualType getRawNSConstantStringType() {
726    if (NSConstantStringTypeDecl)
727      return getTagDeclType(NSConstantStringTypeDecl);
728    return QualType();
729  }
730  void setNSConstantStringType(QualType T);
731
732
733  /// Get the structure type used to representation CFStrings, or NULL
734  /// if it hasn't yet been built.
735  QualType getRawCFConstantStringType() {
736    if (CFConstantStringTypeDecl)
737      return getTagDeclType(CFConstantStringTypeDecl);
738    return QualType();
739  }
740  void setCFConstantStringType(QualType T);
741
742  // This setter/getter represents the ObjC type for an NSConstantString.
743  void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
744  QualType getObjCConstantStringInterface() const {
745    return ObjCConstantStringType;
746  }
747
748  //// This gets the struct used to keep track of fast enumerations.
749  QualType getObjCFastEnumerationStateType();
750
751  /// Get the ObjCFastEnumerationState type, or NULL if it hasn't yet
752  /// been built.
753  QualType getRawObjCFastEnumerationStateType() {
754    if (ObjCFastEnumerationStateTypeDecl)
755      return getTagDeclType(ObjCFastEnumerationStateTypeDecl);
756    return QualType();
757  }
758
759  void setObjCFastEnumerationStateType(QualType T);
760
761  /// \brief Set the type for the C FILE type.
762  void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
763
764  /// \brief Retrieve the C FILE type.
765  QualType getFILEType() {
766    if (FILEDecl)
767      return getTypeDeclType(FILEDecl);
768    return QualType();
769  }
770
771  /// \brief Set the type for the C jmp_buf type.
772  void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
773    this->jmp_bufDecl = jmp_bufDecl;
774  }
775
776  /// \brief Retrieve the C jmp_buf type.
777  QualType getjmp_bufType() {
778    if (jmp_bufDecl)
779      return getTypeDeclType(jmp_bufDecl);
780    return QualType();
781  }
782
783  /// \brief Set the type for the C sigjmp_buf type.
784  void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
785    this->sigjmp_bufDecl = sigjmp_bufDecl;
786  }
787
788  /// \brief Retrieve the C sigjmp_buf type.
789  QualType getsigjmp_bufType() {
790    if (sigjmp_bufDecl)
791      return getTypeDeclType(sigjmp_bufDecl);
792    return QualType();
793  }
794
795  /// getObjCEncodingForType - Emit the ObjC type encoding for the
796  /// given type into \arg S. If \arg NameFields is specified then
797  /// record field names are also encoded.
798  void getObjCEncodingForType(QualType t, std::string &S,
799                              const FieldDecl *Field=0);
800
801  void getLegacyIntegralTypeEncoding(QualType &t) const;
802
803  // Put the string version of type qualifiers into S.
804  void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
805                                       std::string &S) const;
806
807  /// getObjCEncodingForMethodDecl - Return the encoded type for this method
808  /// declaration.
809  void getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S);
810
811  /// getObjCEncodingForBlockDecl - Return the encoded type for this block
812  /// declaration.
813  void getObjCEncodingForBlock(const BlockExpr *Expr, std::string& S);
814
815  /// getObjCEncodingForPropertyDecl - Return the encoded type for
816  /// this method declaration. If non-NULL, Container must be either
817  /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
818  /// only be NULL when getting encodings for protocol properties.
819  void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
820                                      const Decl *Container,
821                                      std::string &S);
822
823  bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
824                                      ObjCProtocolDecl *rProto);
825
826  /// getObjCEncodingTypeSize returns size of type for objective-c encoding
827  /// purpose in characters.
828  CharUnits getObjCEncodingTypeSize(QualType t);
829
830  /// \brief Whether __[u]int128_t identifier is installed.
831  bool isInt128Installed() const { return IsInt128Installed; }
832  void setInt128Installed() { IsInt128Installed = true; }
833
834  /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by
835  /// Sema.  id is always a (typedef for a) pointer type, a pointer to a struct.
836  QualType getObjCIdType() const { return ObjCIdTypedefType; }
837  void setObjCIdType(QualType T);
838
839  void setObjCSelType(QualType T);
840  QualType getObjCSelType() const { return ObjCSelTypedefType; }
841
842  void setObjCProtoType(QualType QT);
843  QualType getObjCProtoType() const { return ObjCProtoType; }
844
845  /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
846  /// Sema.  'Class' is always a (typedef for a) pointer type, a pointer to a
847  /// struct.
848  QualType getObjCClassType() const { return ObjCClassTypedefType; }
849  void setObjCClassType(QualType T);
850
851  void setBuiltinVaListType(QualType T);
852  QualType getBuiltinVaListType() const { return BuiltinVaListType; }
853
854  /// getCVRQualifiedType - Returns a type with additional const,
855  /// volatile, or restrict qualifiers.
856  QualType getCVRQualifiedType(QualType T, unsigned CVR) {
857    return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
858  }
859
860  /// getQualifiedType - Returns a type with additional qualifiers.
861  QualType getQualifiedType(QualType T, Qualifiers Qs) {
862    if (!Qs.hasNonFastQualifiers())
863      return T.withFastQualifiers(Qs.getFastQualifiers());
864    QualifierCollector Qc(Qs);
865    const Type *Ptr = Qc.strip(T);
866    return getExtQualType(Ptr, Qc);
867  }
868
869  /// getQualifiedType - Returns a type with additional qualifiers.
870  QualType getQualifiedType(const Type *T, Qualifiers Qs) {
871    if (!Qs.hasNonFastQualifiers())
872      return QualType(T, Qs.getFastQualifiers());
873    return getExtQualType(T, Qs);
874  }
875
876  DeclarationName getNameForTemplate(TemplateName Name);
877
878  TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
879                                         UnresolvedSetIterator End);
880
881  TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
882                                        bool TemplateKeyword,
883                                        TemplateDecl *Template);
884
885  TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
886                                        const IdentifierInfo *Name);
887  TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
888                                        OverloadedOperatorKind Operator);
889
890  enum GetBuiltinTypeError {
891    GE_None,              //< No error
892    GE_Missing_stdio,     //< Missing a type from <stdio.h>
893    GE_Missing_setjmp     //< Missing a type from <setjmp.h>
894  };
895
896  /// GetBuiltinType - Return the type for the specified builtin.
897  QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error);
898
899private:
900  CanQualType getFromTargetType(unsigned Type) const;
901
902  //===--------------------------------------------------------------------===//
903  //                         Type Predicates.
904  //===--------------------------------------------------------------------===//
905
906public:
907  /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
908  /// garbage collection attribute.
909  ///
910  Qualifiers::GC getObjCGCAttrKind(const QualType &Ty) const;
911
912  /// isObjCNSObjectType - Return true if this is an NSObject object with
913  /// its NSObject attribute set.
914  bool isObjCNSObjectType(QualType Ty) const;
915
916  //===--------------------------------------------------------------------===//
917  //                         Type Sizing and Analysis
918  //===--------------------------------------------------------------------===//
919
920  /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified
921  /// scalar floating point type.
922  const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
923
924  /// getTypeInfo - Get the size and alignment of the specified complete type in
925  /// bits.
926  std::pair<uint64_t, unsigned> getTypeInfo(const Type *T);
927  std::pair<uint64_t, unsigned> getTypeInfo(QualType T) {
928    return getTypeInfo(T.getTypePtr());
929  }
930
931  /// getTypeSize - Return the size of the specified type, in bits.  This method
932  /// does not work on incomplete types.
933  uint64_t getTypeSize(QualType T) {
934    return getTypeInfo(T).first;
935  }
936  uint64_t getTypeSize(const Type *T) {
937    return getTypeInfo(T).first;
938  }
939
940  /// getCharWidth - Return the size of the character type, in bits
941  uint64_t getCharWidth() {
942    return getTypeSize(CharTy);
943  }
944
945  /// getTypeSizeInChars - Return the size of the specified type, in characters.
946  /// This method does not work on incomplete types.
947  CharUnits getTypeSizeInChars(QualType T);
948  CharUnits getTypeSizeInChars(const Type *T);
949
950  /// getTypeAlign - Return the ABI-specified alignment of a type, in bits.
951  /// This method does not work on incomplete types.
952  unsigned getTypeAlign(QualType T) {
953    return getTypeInfo(T).second;
954  }
955  unsigned getTypeAlign(const Type *T) {
956    return getTypeInfo(T).second;
957  }
958
959  /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in
960  /// characters. This method does not work on incomplete types.
961  CharUnits getTypeAlignInChars(QualType T);
962  CharUnits getTypeAlignInChars(const Type *T);
963
964  std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T);
965  std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T);
966
967  /// getPreferredTypeAlign - Return the "preferred" alignment of the specified
968  /// type for the current target in bits.  This can be different than the ABI
969  /// alignment in cases where it is beneficial for performance to overalign
970  /// a data type.
971  unsigned getPreferredTypeAlign(const Type *T);
972
973  /// getDeclAlign - Return a conservative estimate of the alignment of
974  /// the specified decl.  Note that bitfields do not have a valid alignment, so
975  /// this method will assert on them.
976  /// If @p RefAsPointee, references are treated like their underlying type
977  /// (for alignof), else they're treated like pointers (for CodeGen).
978  CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false);
979
980  /// getASTRecordLayout - Get or compute information about the layout of the
981  /// specified record (struct/union/class), which indicates its size and field
982  /// position information.
983  const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D);
984
985  /// getASTObjCInterfaceLayout - Get or compute information about the
986  /// layout of the specified Objective-C interface.
987  const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D);
988
989  void DumpRecordLayout(const RecordDecl *RD, llvm::raw_ostream &OS);
990
991  /// getASTObjCImplementationLayout - Get or compute information about
992  /// the layout of the specified Objective-C implementation. This may
993  /// differ from the interface if synthesized ivars are present.
994  const ASTRecordLayout &
995  getASTObjCImplementationLayout(const ObjCImplementationDecl *D);
996
997  /// getKeyFunction - Get the key function for the given record decl, or NULL
998  /// if there isn't one.  The key function is, according to the Itanium C++ ABI
999  /// section 5.2.3:
1000  ///
1001  /// ...the first non-pure virtual function that is not inline at the point
1002  /// of class definition.
1003  const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD);
1004
1005  void CollectObjCIvars(const ObjCInterfaceDecl *OI,
1006                        llvm::SmallVectorImpl<FieldDecl*> &Fields);
1007
1008  void ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
1009                               llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
1010  void CollectNonClassIvars(const ObjCInterfaceDecl *OI,
1011                               llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
1012  unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI);
1013  void CollectInheritedProtocols(const Decl *CDecl,
1014                          llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
1015
1016  //===--------------------------------------------------------------------===//
1017  //                            Type Operators
1018  //===--------------------------------------------------------------------===//
1019
1020  /// getCanonicalType - Return the canonical (structural) type corresponding to
1021  /// the specified potentially non-canonical type.  The non-canonical version
1022  /// of a type may have many "decorated" versions of types.  Decorators can
1023  /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
1024  /// to be free of any of these, allowing two canonical types to be compared
1025  /// for exact equality with a simple pointer comparison.
1026  CanQualType getCanonicalType(QualType T);
1027  const Type *getCanonicalType(const Type *T) {
1028    return T->getCanonicalTypeInternal().getTypePtr();
1029  }
1030
1031  /// getCanonicalParamType - Return the canonical parameter type
1032  /// corresponding to the specific potentially non-canonical one.
1033  /// Qualifiers are stripped off, functions are turned into function
1034  /// pointers, and arrays decay one level into pointers.
1035  CanQualType getCanonicalParamType(QualType T);
1036
1037  /// \brief Determine whether the given types are equivalent.
1038  bool hasSameType(QualType T1, QualType T2) {
1039    return getCanonicalType(T1) == getCanonicalType(T2);
1040  }
1041
1042  /// \brief Returns this type as a completely-unqualified array type,
1043  /// capturing the qualifiers in Quals. This will remove the minimal amount of
1044  /// sugaring from the types, similar to the behavior of
1045  /// QualType::getUnqualifiedType().
1046  ///
1047  /// \param T is the qualified type, which may be an ArrayType
1048  ///
1049  /// \param Quals will receive the full set of qualifiers that were
1050  /// applied to the array.
1051  ///
1052  /// \returns if this is an array type, the completely unqualified array type
1053  /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
1054  QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
1055
1056  /// \brief Determine whether the given types are equivalent after
1057  /// cvr-qualifiers have been removed.
1058  bool hasSameUnqualifiedType(QualType T1, QualType T2) {
1059    CanQualType CT1 = getCanonicalType(T1);
1060    CanQualType CT2 = getCanonicalType(T2);
1061
1062    Qualifiers Quals;
1063    QualType UnqualT1 = getUnqualifiedArrayType(CT1, Quals);
1064    QualType UnqualT2 = getUnqualifiedArrayType(CT2, Quals);
1065    return UnqualT1 == UnqualT2;
1066  }
1067
1068  bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2);
1069
1070  /// \brief Retrieves the "canonical" declaration of
1071
1072  /// \brief Retrieves the "canonical" nested name specifier for a
1073  /// given nested name specifier.
1074  ///
1075  /// The canonical nested name specifier is a nested name specifier
1076  /// that uniquely identifies a type or namespace within the type
1077  /// system. For example, given:
1078  ///
1079  /// \code
1080  /// namespace N {
1081  ///   struct S {
1082  ///     template<typename T> struct X { typename T* type; };
1083  ///   };
1084  /// }
1085  ///
1086  /// template<typename T> struct Y {
1087  ///   typename N::S::X<T>::type member;
1088  /// };
1089  /// \endcode
1090  ///
1091  /// Here, the nested-name-specifier for N::S::X<T>:: will be
1092  /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined
1093  /// by declarations in the type system and the canonical type for
1094  /// the template type parameter 'T' is template-param-0-0.
1095  NestedNameSpecifier *
1096  getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS);
1097
1098  /// \brief Retrieves the canonical representation of the given
1099  /// calling convention.
1100  CallingConv getCanonicalCallConv(CallingConv CC) {
1101    if (CC == CC_C)
1102      return CC_Default;
1103    return CC;
1104  }
1105
1106  /// \brief Determines whether two calling conventions name the same
1107  /// calling convention.
1108  bool isSameCallConv(CallingConv lcc, CallingConv rcc) {
1109    return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc));
1110  }
1111
1112  /// \brief Retrieves the "canonical" template name that refers to a
1113  /// given template.
1114  ///
1115  /// The canonical template name is the simplest expression that can
1116  /// be used to refer to a given template. For most templates, this
1117  /// expression is just the template declaration itself. For example,
1118  /// the template std::vector can be referred to via a variety of
1119  /// names---std::vector, ::std::vector, vector (if vector is in
1120  /// scope), etc.---but all of these names map down to the same
1121  /// TemplateDecl, which is used to form the canonical template name.
1122  ///
1123  /// Dependent template names are more interesting. Here, the
1124  /// template name could be something like T::template apply or
1125  /// std::allocator<T>::template rebind, where the nested name
1126  /// specifier itself is dependent. In this case, the canonical
1127  /// template name uses the shortest form of the dependent
1128  /// nested-name-specifier, which itself contains all canonical
1129  /// types, values, and templates.
1130  TemplateName getCanonicalTemplateName(TemplateName Name);
1131
1132  /// \brief Determine whether the given template names refer to the same
1133  /// template.
1134  bool hasSameTemplateName(TemplateName X, TemplateName Y);
1135
1136  /// \brief Retrieve the "canonical" template argument.
1137  ///
1138  /// The canonical template argument is the simplest template argument
1139  /// (which may be a type, value, expression, or declaration) that
1140  /// expresses the value of the argument.
1141  TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg);
1142
1143  /// Type Query functions.  If the type is an instance of the specified class,
1144  /// return the Type pointer for the underlying maximally pretty type.  This
1145  /// is a member of ASTContext because this may need to do some amount of
1146  /// canonicalization, e.g. to move type qualifiers into the element type.
1147  const ArrayType *getAsArrayType(QualType T);
1148  const ConstantArrayType *getAsConstantArrayType(QualType T) {
1149    return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
1150  }
1151  const VariableArrayType *getAsVariableArrayType(QualType T) {
1152    return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
1153  }
1154  const IncompleteArrayType *getAsIncompleteArrayType(QualType T) {
1155    return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
1156  }
1157  const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T) {
1158    return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
1159  }
1160
1161  /// getBaseElementType - Returns the innermost element type of an array type.
1162  /// For example, will return "int" for int[m][n]
1163  QualType getBaseElementType(const ArrayType *VAT);
1164
1165  /// getBaseElementType - Returns the innermost element type of a type
1166  /// (which needn't actually be an array type).
1167  QualType getBaseElementType(QualType QT);
1168
1169  /// getConstantArrayElementCount - Returns number of constant array elements.
1170  uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
1171
1172  /// getArrayDecayedType - Return the properly qualified result of decaying the
1173  /// specified array type to a pointer.  This operation is non-trivial when
1174  /// handling typedefs etc.  The canonical type of "T" must be an array type,
1175  /// this returns a pointer to a properly qualified element of the array.
1176  ///
1177  /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
1178  QualType getArrayDecayedType(QualType T);
1179
1180  /// getPromotedIntegerType - Returns the type that Promotable will
1181  /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable
1182  /// integer type.
1183  QualType getPromotedIntegerType(QualType PromotableType);
1184
1185  /// \brief Whether this is a promotable bitfield reference according
1186  /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
1187  ///
1188  /// \returns the type this bit-field will promote to, or NULL if no
1189  /// promotion occurs.
1190  QualType isPromotableBitField(Expr *E);
1191
1192  /// getIntegerTypeOrder - Returns the highest ranked integer type:
1193  /// C99 6.3.1.8p1.  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
1194  /// LHS < RHS, return -1.
1195  int getIntegerTypeOrder(QualType LHS, QualType RHS);
1196
1197  /// getFloatingTypeOrder - Compare the rank of the two specified floating
1198  /// point types, ignoring the domain of the type (i.e. 'double' ==
1199  /// '_Complex double').  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
1200  /// LHS < RHS, return -1.
1201  int getFloatingTypeOrder(QualType LHS, QualType RHS);
1202
1203  /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
1204  /// point or a complex type (based on typeDomain/typeSize).
1205  /// 'typeDomain' is a real floating point or complex type.
1206  /// 'typeSize' is a real floating point or complex type.
1207  QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
1208                                             QualType typeDomain) const;
1209
1210private:
1211  // Helper for integer ordering
1212  unsigned getIntegerRank(Type* T);
1213
1214public:
1215
1216  //===--------------------------------------------------------------------===//
1217  //                    Type Compatibility Predicates
1218  //===--------------------------------------------------------------------===//
1219
1220  /// Compatibility predicates used to check assignment expressions.
1221  bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
1222
1223  bool typesAreBlockPointerCompatible(QualType, QualType);
1224
1225  bool isObjCIdType(QualType T) const {
1226    return T == ObjCIdTypedefType;
1227  }
1228  bool isObjCClassType(QualType T) const {
1229    return T == ObjCClassTypedefType;
1230  }
1231  bool isObjCSelType(QualType T) const {
1232    return T == ObjCSelTypedefType;
1233  }
1234  bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
1235  bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
1236                                         bool ForCompare);
1237
1238  // Check the safety of assignment from LHS to RHS
1239  bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
1240                               const ObjCObjectPointerType *RHSOPT);
1241  bool canAssignObjCInterfaces(const ObjCObjectType *LHS,
1242                               const ObjCObjectType *RHS);
1243  bool canAssignObjCInterfacesInBlockPointer(
1244                                          const ObjCObjectPointerType *LHSOPT,
1245                                          const ObjCObjectPointerType *RHSOPT);
1246  bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
1247  QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
1248                                   const ObjCObjectPointerType *RHSOPT);
1249
1250  // Functions for calculating composite types
1251  QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false);
1252  QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false);
1253
1254  QualType mergeObjCGCQualifiers(QualType, QualType);
1255
1256  /// UsualArithmeticConversionsType - handles the various conversions
1257  /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
1258  /// and returns the result type of that conversion.
1259  QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
1260
1261  //===--------------------------------------------------------------------===//
1262  //                    Integer Predicates
1263  //===--------------------------------------------------------------------===//
1264
1265  // The width of an integer, as defined in C99 6.2.6.2. This is the number
1266  // of bits in an integer type excluding any padding bits.
1267  unsigned getIntWidth(QualType T);
1268
1269  // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
1270  // unsigned integer type.  This method takes a signed type, and returns the
1271  // corresponding unsigned integer type.
1272  QualType getCorrespondingUnsignedType(QualType T);
1273
1274  //===--------------------------------------------------------------------===//
1275  //                    Type Iterators.
1276  //===--------------------------------------------------------------------===//
1277
1278  typedef std::vector<Type*>::iterator       type_iterator;
1279  typedef std::vector<Type*>::const_iterator const_type_iterator;
1280
1281  type_iterator types_begin() { return Types.begin(); }
1282  type_iterator types_end() { return Types.end(); }
1283  const_type_iterator types_begin() const { return Types.begin(); }
1284  const_type_iterator types_end() const { return Types.end(); }
1285
1286  //===--------------------------------------------------------------------===//
1287  //                    Integer Values
1288  //===--------------------------------------------------------------------===//
1289
1290  /// MakeIntValue - Make an APSInt of the appropriate width and
1291  /// signedness for the given \arg Value and integer \arg Type.
1292  llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) {
1293    llvm::APSInt Res(getIntWidth(Type), !Type->isSignedIntegerType());
1294    Res = Value;
1295    return Res;
1296  }
1297
1298  /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists.
1299  ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
1300  /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists.
1301  ObjCCategoryImplDecl   *getObjCImplementation(ObjCCategoryDecl *D);
1302
1303  /// \brief Set the implementation of ObjCInterfaceDecl.
1304  void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
1305                             ObjCImplementationDecl *ImplD);
1306  /// \brief Set the implementation of ObjCCategoryDecl.
1307  void setObjCImplementation(ObjCCategoryDecl *CatD,
1308                             ObjCCategoryImplDecl *ImplD);
1309
1310  /// \brief Allocate an uninitialized TypeSourceInfo.
1311  ///
1312  /// The caller should initialize the memory held by TypeSourceInfo using
1313  /// the TypeLoc wrappers.
1314  ///
1315  /// \param T the type that will be the basis for type source info. This type
1316  /// should refer to how the declarator was written in source code, not to
1317  /// what type semantic analysis resolved the declarator to.
1318  ///
1319  /// \param Size the size of the type info to create, or 0 if the size
1320  /// should be calculated based on the type.
1321  TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0);
1322
1323  /// \brief Allocate a TypeSourceInfo where all locations have been
1324  /// initialized to a given location, which defaults to the empty
1325  /// location.
1326  TypeSourceInfo *
1327  getTrivialTypeSourceInfo(QualType T, SourceLocation Loc = SourceLocation());
1328
1329  TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; }
1330
1331  /// \brief Add a deallocation callback that will be invoked when the
1332  /// ASTContext is destroyed.
1333  ///
1334  /// \brief Callback A callback function that will be invoked on destruction.
1335  ///
1336  /// \brief Data Pointer data that will be provided to the callback function
1337  /// when it is called.
1338  void AddDeallocation(void (*Callback)(void*), void *Data);
1339
1340  //===--------------------------------------------------------------------===//
1341  //                    Statistics
1342  //===--------------------------------------------------------------------===//
1343
1344  /// \brief The number of implicitly-declared default constructors.
1345  static unsigned NumImplicitDefaultConstructors;
1346
1347  /// \brief The number of implicitly-declared default constructors for
1348  /// which declarations were built.
1349  static unsigned NumImplicitDefaultConstructorsDeclared;
1350
1351  /// \brief The number of implicitly-declared copy constructors.
1352  static unsigned NumImplicitCopyConstructors;
1353
1354  /// \brief The number of implicitly-declared copy constructors for
1355  /// which declarations were built.
1356  static unsigned NumImplicitCopyConstructorsDeclared;
1357
1358  /// \brief The number of implicitly-declared copy assignment operators.
1359  static unsigned NumImplicitCopyAssignmentOperators;
1360
1361  /// \brief The number of implicitly-declared copy assignment operators for
1362  /// which declarations were built.
1363  static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
1364
1365  /// \brief The number of implicitly-declared destructors.
1366  static unsigned NumImplicitDestructors;
1367
1368  /// \brief The number of implicitly-declared destructors for which
1369  /// declarations were built.
1370  static unsigned NumImplicitDestructorsDeclared;
1371
1372private:
1373  ASTContext(const ASTContext&); // DO NOT IMPLEMENT
1374  void operator=(const ASTContext&); // DO NOT IMPLEMENT
1375
1376  void InitBuiltinTypes();
1377  void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
1378
1379  // Return the ObjC type encoding for a given type.
1380  void getObjCEncodingForTypeImpl(QualType t, std::string &S,
1381                                  bool ExpandPointedToStructures,
1382                                  bool ExpandStructures,
1383                                  const FieldDecl *Field,
1384                                  bool OutermostType = false,
1385                                  bool EncodingProperty = false);
1386
1387  const ASTRecordLayout &getObjCLayout(const ObjCInterfaceDecl *D,
1388                                       const ObjCImplementationDecl *Impl);
1389
1390private:
1391  /// \brief A set of deallocations that should be performed when the
1392  /// ASTContext is destroyed.
1393  llvm::SmallVector<std::pair<void (*)(void*), void *>, 16> Deallocations;
1394
1395  // FIXME: This currently contains the set of StoredDeclMaps used
1396  // by DeclContext objects.  This probably should not be in ASTContext,
1397  // but we include it here so that ASTContext can quickly deallocate them.
1398  llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM;
1399
1400  /// \brief A counter used to uniquely identify "blocks".
1401  unsigned int UniqueBlockByRefTypeID;
1402  unsigned int UniqueBlockParmTypeID;
1403
1404  friend class DeclContext;
1405  friend class DeclarationNameTable;
1406  void ReleaseDeclContextMaps();
1407};
1408
1409/// @brief Utility function for constructing a nullary selector.
1410static inline Selector GetNullarySelector(const char* name, ASTContext& Ctx) {
1411  IdentifierInfo* II = &Ctx.Idents.get(name);
1412  return Ctx.Selectors.getSelector(0, &II);
1413}
1414
1415/// @brief Utility function for constructing an unary selector.
1416static inline Selector GetUnarySelector(const char* name, ASTContext& Ctx) {
1417  IdentifierInfo* II = &Ctx.Idents.get(name);
1418  return Ctx.Selectors.getSelector(1, &II);
1419}
1420
1421}  // end namespace clang
1422
1423// operator new and delete aren't allowed inside namespaces.
1424// The throw specifications are mandated by the standard.
1425/// @brief Placement new for using the ASTContext's allocator.
1426///
1427/// This placement form of operator new uses the ASTContext's allocator for
1428/// obtaining memory. It is a non-throwing new, which means that it returns
1429/// null on error. (If that is what the allocator does. The current does, so if
1430/// this ever changes, this operator will have to be changed, too.)
1431/// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
1432/// @code
1433/// // Default alignment (8)
1434/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
1435/// // Specific alignment
1436/// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
1437/// @endcode
1438/// Please note that you cannot use delete on the pointer; it must be
1439/// deallocated using an explicit destructor call followed by
1440/// @c Context.Deallocate(Ptr).
1441///
1442/// @param Bytes The number of bytes to allocate. Calculated by the compiler.
1443/// @param C The ASTContext that provides the allocator.
1444/// @param Alignment The alignment of the allocated memory (if the underlying
1445///                  allocator supports it).
1446/// @return The allocated memory. Could be NULL.
1447inline void *operator new(size_t Bytes, clang::ASTContext &C,
1448                          size_t Alignment) throw () {
1449  return C.Allocate(Bytes, Alignment);
1450}
1451/// @brief Placement delete companion to the new above.
1452///
1453/// This operator is just a companion to the new above. There is no way of
1454/// invoking it directly; see the new operator for more details. This operator
1455/// is called implicitly by the compiler if a placement new expression using
1456/// the ASTContext throws in the object constructor.
1457inline void operator delete(void *Ptr, clang::ASTContext &C, size_t)
1458              throw () {
1459  C.Deallocate(Ptr);
1460}
1461
1462/// This placement form of operator new[] uses the ASTContext's allocator for
1463/// obtaining memory. It is a non-throwing new[], which means that it returns
1464/// null on error.
1465/// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
1466/// @code
1467/// // Default alignment (8)
1468/// char *data = new (Context) char[10];
1469/// // Specific alignment
1470/// char *data = new (Context, 4) char[10];
1471/// @endcode
1472/// Please note that you cannot use delete on the pointer; it must be
1473/// deallocated using an explicit destructor call followed by
1474/// @c Context.Deallocate(Ptr).
1475///
1476/// @param Bytes The number of bytes to allocate. Calculated by the compiler.
1477/// @param C The ASTContext that provides the allocator.
1478/// @param Alignment The alignment of the allocated memory (if the underlying
1479///                  allocator supports it).
1480/// @return The allocated memory. Could be NULL.
1481inline void *operator new[](size_t Bytes, clang::ASTContext& C,
1482                            size_t Alignment = 8) throw () {
1483  return C.Allocate(Bytes, Alignment);
1484}
1485
1486/// @brief Placement delete[] companion to the new[] above.
1487///
1488/// This operator is just a companion to the new[] above. There is no way of
1489/// invoking it directly; see the new[] operator for more details. This operator
1490/// is called implicitly by the compiler if a placement new[] expression using
1491/// the ASTContext throws in the object constructor.
1492inline void operator delete[](void *Ptr, clang::ASTContext &C, size_t)
1493              throw () {
1494  C.Deallocate(Ptr);
1495}
1496
1497#endif
1498