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