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