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