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