clang API Documentation

ASTContext.h
Go to the documentation of this file.
00001 //===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the ASTContext interface.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_ASTCONTEXT_H
00015 #define LLVM_CLANG_AST_ASTCONTEXT_H
00016 
00017 #include "clang/Basic/AddressSpaces.h"
00018 #include "clang/Basic/IdentifierTable.h"
00019 #include "clang/Basic/LangOptions.h"
00020 #include "clang/Basic/OperatorKinds.h"
00021 #include "clang/Basic/PartialDiagnostic.h"
00022 #include "clang/Basic/VersionTuple.h"
00023 #include "clang/AST/Decl.h"
00024 #include "clang/AST/LambdaMangleContext.h"
00025 #include "clang/AST/NestedNameSpecifier.h"
00026 #include "clang/AST/PrettyPrinter.h"
00027 #include "clang/AST/TemplateName.h"
00028 #include "clang/AST/Type.h"
00029 #include "clang/AST/CanonicalType.h"
00030 #include "llvm/ADT/DenseMap.h"
00031 #include "llvm/ADT/FoldingSet.h"
00032 #include "llvm/ADT/IntrusiveRefCntPtr.h"
00033 #include "llvm/ADT/OwningPtr.h"
00034 #include "llvm/ADT/SmallPtrSet.h"
00035 #include "llvm/ADT/TinyPtrVector.h"
00036 #include "llvm/Support/Allocator.h"
00037 #include <vector>
00038 
00039 namespace llvm {
00040   struct fltSemantics;
00041 }
00042 
00043 namespace clang {
00044   class FileManager;
00045   class ASTRecordLayout;
00046   class BlockExpr;
00047   class CharUnits;
00048   class DiagnosticsEngine;
00049   class Expr;
00050   class ExternalASTSource;
00051   class ASTMutationListener;
00052   class IdentifierTable;
00053   class SelectorTable;
00054   class SourceManager;
00055   class TargetInfo;
00056   class CXXABI;
00057   // Decls
00058   class DeclContext;
00059   class CXXConversionDecl;
00060   class CXXMethodDecl;
00061   class CXXRecordDecl;
00062   class Decl;
00063   class FieldDecl;
00064   class MangleContext;
00065   class ObjCIvarDecl;
00066   class ObjCIvarRefExpr;
00067   class ObjCPropertyDecl;
00068   class ParmVarDecl;
00069   class RecordDecl;
00070   class StoredDeclsMap;
00071   class TagDecl;
00072   class TemplateTemplateParmDecl;
00073   class TemplateTypeParmDecl;
00074   class TranslationUnitDecl;
00075   class TypeDecl;
00076   class TypedefNameDecl;
00077   class UsingDecl;
00078   class UsingShadowDecl;
00079   class UnresolvedSetIterator;
00080 
00081   namespace Builtin { class Context; }
00082 
00083 /// ASTContext - This class holds long-lived AST nodes (such as types and
00084 /// decls) that can be referred to throughout the semantic analysis of a file.
00085 class ASTContext : public RefCountedBase<ASTContext> {
00086   ASTContext &this_() { return *this; }
00087 
00088   mutable std::vector<Type*> Types;
00089   mutable llvm::FoldingSet<ExtQuals> ExtQualNodes;
00090   mutable llvm::FoldingSet<ComplexType> ComplexTypes;
00091   mutable llvm::FoldingSet<PointerType> PointerTypes;
00092   mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
00093   mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
00094   mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
00095   mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
00096   mutable llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
00097   mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
00098   mutable std::vector<VariableArrayType*> VariableArrayTypes;
00099   mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
00100   mutable llvm::FoldingSet<DependentSizedExtVectorType>
00101     DependentSizedExtVectorTypes;
00102   mutable llvm::FoldingSet<VectorType> VectorTypes;
00103   mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
00104   mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&>
00105     FunctionProtoTypes;
00106   mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
00107   mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
00108   mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
00109   mutable llvm::FoldingSet<SubstTemplateTypeParmType>
00110     SubstTemplateTypeParmTypes;
00111   mutable llvm::FoldingSet<SubstTemplateTypeParmPackType>
00112     SubstTemplateTypeParmPackTypes;
00113   mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
00114     TemplateSpecializationTypes;
00115   mutable llvm::FoldingSet<ParenType> ParenTypes;
00116   mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
00117   mutable llvm::FoldingSet<DependentNameType> DependentNameTypes;
00118   mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType,
00119                                      ASTContext&>
00120     DependentTemplateSpecializationTypes;
00121   llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
00122   mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
00123   mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
00124   mutable llvm::FoldingSet<AutoType> AutoTypes;
00125   mutable llvm::FoldingSet<AtomicType> AtomicTypes;
00126   llvm::FoldingSet<AttributedType> AttributedTypes;
00127 
00128   mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
00129   mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
00130   mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage> 
00131     SubstTemplateTemplateParms;
00132   mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage,
00133                                      ASTContext&> 
00134     SubstTemplateTemplateParmPacks;
00135   
00136   /// \brief The set of nested name specifiers.
00137   ///
00138   /// This set is managed by the NestedNameSpecifier class.
00139   mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
00140   mutable NestedNameSpecifier *GlobalNestedNameSpecifier;
00141   friend class NestedNameSpecifier;
00142 
00143   /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
00144   ///  This is lazily created.  This is intentionally not serialized.
00145   mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>
00146     ASTRecordLayouts;
00147   mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>
00148     ObjCLayouts;
00149 
00150   /// TypeInfoMap - A cache from types to size and alignment information.
00151   typedef llvm::DenseMap<const Type*,
00152                          std::pair<uint64_t, unsigned> > TypeInfoMap;
00153   mutable TypeInfoMap MemoizedTypeInfo;
00154 
00155   /// KeyFunctions - A cache mapping from CXXRecordDecls to key functions.
00156   llvm::DenseMap<const CXXRecordDecl*, const CXXMethodDecl*> KeyFunctions;
00157   
00158   /// \brief Mapping from ObjCContainers to their ObjCImplementations.
00159   llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
00160   
00161   /// \brief Mapping from ObjCMethod to its duplicate declaration in the same
00162   /// interface.
00163   llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls;
00164 
00165   /// \brief Mapping from __block VarDecls to their copy initialization expr.
00166   llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits;
00167     
00168   /// \brief Mapping from class scope functions specialization to their
00169   ///  template patterns.
00170   llvm::DenseMap<const FunctionDecl*, FunctionDecl*>
00171     ClassScopeSpecializationPattern;
00172 
00173   /// \brief Representation of a "canonical" template template parameter that
00174   /// is used in canonical template names.
00175   class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
00176     TemplateTemplateParmDecl *Parm;
00177     
00178   public:
00179     CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm) 
00180       : Parm(Parm) { }
00181     
00182     TemplateTemplateParmDecl *getParam() const { return Parm; }
00183     
00184     void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); }
00185     
00186     static void Profile(llvm::FoldingSetNodeID &ID, 
00187                         TemplateTemplateParmDecl *Parm);
00188   };
00189   mutable llvm::FoldingSet<CanonicalTemplateTemplateParm>
00190     CanonTemplateTemplateParms;
00191   
00192   TemplateTemplateParmDecl *
00193     getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const;
00194 
00195   /// \brief The typedef for the __int128_t type.
00196   mutable TypedefDecl *Int128Decl;
00197 
00198   /// \brief The typedef for the __uint128_t type.
00199   mutable TypedefDecl *UInt128Decl;
00200   
00201   /// BuiltinVaListType - built-in va list type.
00202   /// This is initially null and set by Sema::LazilyCreateBuiltin when
00203   /// a builtin that takes a valist is encountered.
00204   QualType BuiltinVaListType;
00205 
00206   /// \brief The typedef for the predefined 'id' type.
00207   mutable TypedefDecl *ObjCIdDecl;
00208   
00209   /// \brief The typedef for the predefined 'SEL' type.
00210   mutable TypedefDecl *ObjCSelDecl;
00211 
00212   /// \brief The typedef for the predefined 'Class' type.
00213   mutable TypedefDecl *ObjCClassDecl;
00214 
00215   /// \brief The typedef for the predefined 'Protocol' class in Objective-C.
00216   mutable ObjCInterfaceDecl *ObjCProtocolClassDecl;
00217 
00218   // Typedefs which may be provided defining the structure of Objective-C
00219   // pseudo-builtins
00220   QualType ObjCIdRedefinitionType;
00221   QualType ObjCClassRedefinitionType;
00222   QualType ObjCSelRedefinitionType;
00223 
00224   QualType ObjCConstantStringType;
00225   mutable RecordDecl *CFConstantStringTypeDecl;
00226   
00227   QualType ObjCNSStringType;
00228 
00229   /// \brief The typedef declaration for the Objective-C "instancetype" type.
00230   TypedefDecl *ObjCInstanceTypeDecl;
00231   
00232   /// \brief The type for the C FILE type.
00233   TypeDecl *FILEDecl;
00234 
00235   /// \brief The type for the C jmp_buf type.
00236   TypeDecl *jmp_bufDecl;
00237 
00238   /// \brief The type for the C sigjmp_buf type.
00239   TypeDecl *sigjmp_bufDecl;
00240 
00241   /// \brief The type for the C ucontext_t type.
00242   TypeDecl *ucontext_tDecl;
00243 
00244   /// \brief Type for the Block descriptor for Blocks CodeGen.
00245   ///
00246   /// Since this is only used for generation of debug info, it is not
00247   /// serialized.
00248   mutable RecordDecl *BlockDescriptorType;
00249 
00250   /// \brief Type for the Block descriptor for Blocks CodeGen.
00251   ///
00252   /// Since this is only used for generation of debug info, it is not
00253   /// serialized.
00254   mutable RecordDecl *BlockDescriptorExtendedType;
00255 
00256   /// \brief Declaration for the CUDA cudaConfigureCall function.
00257   FunctionDecl *cudaConfigureCallDecl;
00258 
00259   TypeSourceInfo NullTypeSourceInfo;
00260 
00261   /// \brief Keeps track of all declaration attributes.
00262   ///
00263   /// Since so few decls have attrs, we keep them in a hash map instead of
00264   /// wasting space in the Decl class.
00265   llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs;
00266 
00267   /// \brief Keeps track of the static data member templates from which
00268   /// static data members of class template specializations were instantiated.
00269   ///
00270   /// This data structure stores the mapping from instantiations of static
00271   /// data members to the static data member representations within the
00272   /// class template from which they were instantiated along with the kind
00273   /// of instantiation or specialization (a TemplateSpecializationKind - 1).
00274   ///
00275   /// Given the following example:
00276   ///
00277   /// \code
00278   /// template<typename T>
00279   /// struct X {
00280   ///   static T value;
00281   /// };
00282   ///
00283   /// template<typename T>
00284   ///   T X<T>::value = T(17);
00285   ///
00286   /// int *x = &X<int>::value;
00287   /// \endcode
00288   ///
00289   /// This mapping will contain an entry that maps from the VarDecl for
00290   /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
00291   /// class template X) and will be marked TSK_ImplicitInstantiation.
00292   llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *> 
00293     InstantiatedFromStaticDataMember;
00294 
00295   /// \brief Keeps track of the declaration from which a UsingDecl was
00296   /// created during instantiation.  The source declaration is always
00297   /// a UsingDecl, an UnresolvedUsingValueDecl, or an
00298   /// UnresolvedUsingTypenameDecl.
00299   ///
00300   /// For example:
00301   /// \code
00302   /// template<typename T>
00303   /// struct A {
00304   ///   void f();
00305   /// };
00306   ///
00307   /// template<typename T>
00308   /// struct B : A<T> {
00309   ///   using A<T>::f;
00310   /// };
00311   ///
00312   /// template struct B<int>;
00313   /// \endcode
00314   ///
00315   /// This mapping will contain an entry that maps from the UsingDecl in
00316   /// B<int> to the UnresolvedUsingDecl in B<T>.
00317   llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl;
00318 
00319   llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
00320     InstantiatedFromUsingShadowDecl;
00321 
00322   llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
00323 
00324   /// \brief Mapping that stores the methods overridden by a given C++
00325   /// member function.
00326   ///
00327   /// Since most C++ member functions aren't virtual and therefore
00328   /// don't override anything, we store the overridden functions in
00329   /// this map on the side rather than within the CXXMethodDecl structure.
00330   typedef llvm::TinyPtrVector<const CXXMethodDecl*> CXXMethodVector;
00331   llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
00332 
00333   /// \brief Mapping from each declaration context to its corresponding lambda 
00334   /// mangling context.
00335   llvm::DenseMap<const DeclContext *, LambdaMangleContext> LambdaMangleContexts;
00336   
00337   /// \brief Mapping that stores parameterIndex values for ParmVarDecls
00338   /// when that value exceeds the bitfield size of
00339   /// ParmVarDeclBits.ParameterIndex.
00340   typedef llvm::DenseMap<const VarDecl *, unsigned> ParameterIndexTable;
00341   ParameterIndexTable ParamIndices;  
00342   
00343   ImportDecl *FirstLocalImport;
00344   ImportDecl *LastLocalImport;
00345   
00346   TranslationUnitDecl *TUDecl;
00347 
00348   /// SourceMgr - The associated SourceManager object.
00349   SourceManager &SourceMgr;
00350 
00351   /// LangOpts - The language options used to create the AST associated with
00352   ///  this ASTContext object.
00353   LangOptions &LangOpts;
00354 
00355   /// \brief The allocator used to create AST objects.
00356   ///
00357   /// AST objects are never destructed; rather, all memory associated with the
00358   /// AST objects will be released when the ASTContext itself is destroyed.
00359   mutable llvm::BumpPtrAllocator BumpAlloc;
00360 
00361   /// \brief Allocator for partial diagnostics.
00362   PartialDiagnostic::StorageAllocator DiagAllocator;
00363 
00364   /// \brief The current C++ ABI.
00365   OwningPtr<CXXABI> ABI;
00366   CXXABI *createCXXABI(const TargetInfo &T);
00367 
00368   /// \brief The logical -> physical address space map.
00369   const LangAS::Map *AddrSpaceMap;
00370 
00371   friend class ASTDeclReader;
00372   friend class ASTReader;
00373   friend class ASTWriter;
00374   friend class CXXRecordDecl;
00375 
00376   const TargetInfo *Target;
00377   clang::PrintingPolicy PrintingPolicy;
00378   
00379 public:
00380   IdentifierTable &Idents;
00381   SelectorTable &Selectors;
00382   Builtin::Context &BuiltinInfo;
00383   mutable DeclarationNameTable DeclarationNames;
00384   OwningPtr<ExternalASTSource> ExternalSource;
00385   ASTMutationListener *Listener;
00386 
00387   clang::PrintingPolicy getPrintingPolicy() const { return PrintingPolicy; }
00388 
00389   void setPrintingPolicy(clang::PrintingPolicy Policy) {
00390     PrintingPolicy = Policy;
00391   }
00392   
00393   SourceManager& getSourceManager() { return SourceMgr; }
00394   const SourceManager& getSourceManager() const { return SourceMgr; }
00395   void *Allocate(unsigned Size, unsigned Align = 8) const {
00396     return BumpAlloc.Allocate(Size, Align);
00397   }
00398   void Deallocate(void *Ptr) const { }
00399   
00400   /// Return the total amount of physical memory allocated for representing
00401   /// AST nodes and type information.
00402   size_t getASTAllocatedMemory() const {
00403     return BumpAlloc.getTotalMemory();
00404   }
00405   /// Return the total memory used for various side tables.
00406   size_t getSideTableAllocatedMemory() const;
00407   
00408   PartialDiagnostic::StorageAllocator &getDiagAllocator() {
00409     return DiagAllocator;
00410   }
00411 
00412   const TargetInfo &getTargetInfo() const { return *Target; }
00413   
00414   const LangOptions& getLangOpts() const { return LangOpts; }
00415 
00416   DiagnosticsEngine &getDiagnostics() const;
00417 
00418   FullSourceLoc getFullLoc(SourceLocation Loc) const {
00419     return FullSourceLoc(Loc,SourceMgr);
00420   }
00421 
00422   /// \brief Retrieve the attributes for the given declaration.
00423   AttrVec& getDeclAttrs(const Decl *D);
00424 
00425   /// \brief Erase the attributes corresponding to the given declaration.
00426   void eraseDeclAttrs(const Decl *D);
00427 
00428   /// \brief If this variable is an instantiated static data member of a
00429   /// class template specialization, returns the templated static data member
00430   /// from which it was instantiated.
00431   MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
00432                                                            const VarDecl *Var);
00433 
00434   FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD);
00435 
00436   void setClassScopeSpecializationPattern(FunctionDecl *FD,
00437                                           FunctionDecl *Pattern);
00438 
00439   /// \brief Note that the static data member \p Inst is an instantiation of
00440   /// the static data member template \p Tmpl of a class template.
00441   void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
00442                                            TemplateSpecializationKind TSK,
00443                         SourceLocation PointOfInstantiation = SourceLocation());
00444 
00445   /// \brief If the given using decl is an instantiation of a
00446   /// (possibly unresolved) using decl from a template instantiation,
00447   /// return it.
00448   NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
00449 
00450   /// \brief Remember that the using decl \p Inst is an instantiation
00451   /// of the using decl \p Pattern of a class template.
00452   void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
00453 
00454   void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
00455                                           UsingShadowDecl *Pattern);
00456   UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
00457 
00458   FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
00459 
00460   void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
00461   
00462   /// ZeroBitfieldFollowsNonBitfield - return 'true" if 'FD' is a zero-length
00463   /// bitfield which follows the non-bitfield 'LastFD'.
00464   bool ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD, 
00465                                       const FieldDecl *LastFD) const;
00466 
00467   /// ZeroBitfieldFollowsBitfield - return 'true" if 'FD' is a zero-length
00468   /// bitfield which follows the bitfield 'LastFD'.
00469   bool ZeroBitfieldFollowsBitfield(const FieldDecl *FD,
00470                                    const FieldDecl *LastFD) const;
00471   
00472   /// BitfieldFollowsBitfield - return 'true" if 'FD' is a
00473   /// bitfield which follows the bitfield 'LastFD'.
00474   bool BitfieldFollowsBitfield(const FieldDecl *FD,
00475                                const FieldDecl *LastFD) const;
00476   
00477   /// NonBitfieldFollowsBitfield - return 'true" if 'FD' is not a
00478   /// bitfield which follows the bitfield 'LastFD'.
00479   bool NonBitfieldFollowsBitfield(const FieldDecl *FD,
00480                                   const FieldDecl *LastFD) const;
00481   
00482   /// BitfieldFollowsNonBitfield - return 'true" if 'FD' is a
00483   /// bitfield which follows the none bitfield 'LastFD'.
00484   bool BitfieldFollowsNonBitfield(const FieldDecl *FD,
00485                                   const FieldDecl *LastFD) const;
00486 
00487   // Access to the set of methods overridden by the given C++ method.
00488   typedef CXXMethodVector::const_iterator overridden_cxx_method_iterator;
00489   overridden_cxx_method_iterator
00490   overridden_methods_begin(const CXXMethodDecl *Method) const;
00491 
00492   overridden_cxx_method_iterator
00493   overridden_methods_end(const CXXMethodDecl *Method) const;
00494 
00495   unsigned overridden_methods_size(const CXXMethodDecl *Method) const;
00496 
00497   /// \brief Note that the given C++ \p Method overrides the given \p
00498   /// Overridden method.
00499   void addOverriddenMethod(const CXXMethodDecl *Method, 
00500                            const CXXMethodDecl *Overridden);
00501   
00502   /// \brief Notify the AST context that a new import declaration has been
00503   /// parsed or implicitly created within this translation unit.
00504   void addedLocalImportDecl(ImportDecl *Import);
00505 
00506   static ImportDecl *getNextLocalImport(ImportDecl *Import) {
00507     return Import->NextLocalImport;
00508   }
00509   
00510   /// \brief Iterator that visits import declarations.
00511   class import_iterator {
00512     ImportDecl *Import;
00513     
00514   public:
00515     typedef ImportDecl               *value_type;
00516     typedef ImportDecl               *reference;
00517     typedef ImportDecl               *pointer;
00518     typedef int                       difference_type;
00519     typedef std::forward_iterator_tag iterator_category;
00520     
00521     import_iterator() : Import() { }
00522     explicit import_iterator(ImportDecl *Import) : Import(Import) { }
00523     
00524     reference operator*() const { return Import; }
00525     pointer operator->() const { return Import; }
00526     
00527     import_iterator &operator++() {
00528       Import = ASTContext::getNextLocalImport(Import);
00529       return *this;
00530     }
00531 
00532     import_iterator operator++(int) {
00533       import_iterator Other(*this);
00534       ++(*this);
00535       return Other;
00536     }
00537     
00538     friend bool operator==(import_iterator X, import_iterator Y) {
00539       return X.Import == Y.Import;
00540     }
00541 
00542     friend bool operator!=(import_iterator X, import_iterator Y) {
00543       return X.Import != Y.Import;
00544     }
00545   };
00546   
00547   import_iterator local_import_begin() const { 
00548     return import_iterator(FirstLocalImport); 
00549   }
00550   import_iterator local_import_end() const { return import_iterator(); }
00551   
00552   TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
00553 
00554 
00555   // Builtin Types.
00556   CanQualType VoidTy;
00557   CanQualType BoolTy;
00558   CanQualType CharTy;
00559   CanQualType WCharTy;  // [C++ 3.9.1p5], integer type in C99.
00560   CanQualType WIntTy;   // [C99 7.24.1], integer type unchanged by default promotions.
00561   CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
00562   CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
00563   CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
00564   CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
00565   CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
00566   CanQualType FloatTy, DoubleTy, LongDoubleTy;
00567   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
00568   CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
00569   CanQualType VoidPtrTy, NullPtrTy;
00570   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
00571   CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
00572   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
00573   CanQualType ObjCBuiltinBoolTy;
00574 
00575   // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
00576   mutable QualType AutoDeductTy;     // Deduction against 'auto'.
00577   mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'.
00578 
00579   ASTContext(LangOptions& LOpts, SourceManager &SM, const TargetInfo *t,
00580              IdentifierTable &idents, SelectorTable &sels,
00581              Builtin::Context &builtins,
00582              unsigned size_reserve,
00583              bool DelayInitialization = false);
00584 
00585   ~ASTContext();
00586 
00587   /// \brief Attach an external AST source to the AST context.
00588   ///
00589   /// The external AST source provides the ability to load parts of
00590   /// the abstract syntax tree as needed from some external storage,
00591   /// e.g., a precompiled header.
00592   void setExternalSource(OwningPtr<ExternalASTSource> &Source);
00593 
00594   /// \brief Retrieve a pointer to the external AST source associated
00595   /// with this AST context, if any.
00596   ExternalASTSource *getExternalSource() const { return ExternalSource.get(); }
00597 
00598   /// \brief Attach an AST mutation listener to the AST context.
00599   ///
00600   /// The AST mutation listener provides the ability to track modifications to
00601   /// the abstract syntax tree entities committed after they were initially
00602   /// created.
00603   void setASTMutationListener(ASTMutationListener *Listener) {
00604     this->Listener = Listener;
00605   }
00606 
00607   /// \brief Retrieve a pointer to the AST mutation listener associated
00608   /// with this AST context, if any.
00609   ASTMutationListener *getASTMutationListener() const { return Listener; }
00610 
00611   void PrintStats() const;
00612   const std::vector<Type*>& getTypes() const { return Types; }
00613 
00614   /// \brief Retrieve the declaration for the 128-bit signed integer type.
00615   TypedefDecl *getInt128Decl() const;
00616 
00617   /// \brief Retrieve the declaration for the 128-bit unsigned integer type.
00618   TypedefDecl *getUInt128Decl() const;
00619   
00620   //===--------------------------------------------------------------------===//
00621   //                           Type Constructors
00622   //===--------------------------------------------------------------------===//
00623 
00624 private:
00625   /// getExtQualType - Return a type with extended qualifiers.
00626   QualType getExtQualType(const Type *Base, Qualifiers Quals) const;
00627 
00628   QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;
00629 
00630 public:
00631   /// getAddSpaceQualType - Return the uniqued reference to the type for an
00632   /// address space qualified type with the specified type and address space.
00633   /// The resulting type has a union of the qualifiers from T and the address
00634   /// space. If T already has an address space specifier, it is silently
00635   /// replaced.
00636   QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const;
00637 
00638   /// getObjCGCQualType - Returns the uniqued reference to the type for an
00639   /// objc gc qualified type. The retulting type has a union of the qualifiers
00640   /// from T and the gc attribute.
00641   QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
00642 
00643   /// getRestrictType - Returns the uniqued reference to the type for a
00644   /// 'restrict' qualified type.  The resulting type has a union of the
00645   /// qualifiers from T and 'restrict'.
00646   QualType getRestrictType(QualType T) const {
00647     return T.withFastQualifiers(Qualifiers::Restrict);
00648   }
00649 
00650   /// getVolatileType - Returns the uniqued reference to the type for a
00651   /// 'volatile' qualified type.  The resulting type has a union of the
00652   /// qualifiers from T and 'volatile'.
00653   QualType getVolatileType(QualType T) const {
00654     return T.withFastQualifiers(Qualifiers::Volatile);
00655   }
00656 
00657   /// getConstType - Returns the uniqued reference to the type for a
00658   /// 'const' qualified type.  The resulting type has a union of the
00659   /// qualifiers from T and 'const'.
00660   ///
00661   /// It can be reasonably expected that this will always be
00662   /// equivalent to calling T.withConst().
00663   QualType getConstType(QualType T) const { return T.withConst(); }
00664 
00665   /// adjustFunctionType - Change the ExtInfo on a function type.
00666   const FunctionType *adjustFunctionType(const FunctionType *Fn,
00667                                          FunctionType::ExtInfo EInfo);
00668 
00669   /// getComplexType - Return the uniqued reference to the type for a complex
00670   /// number with the specified element type.
00671   QualType getComplexType(QualType T) const;
00672   CanQualType getComplexType(CanQualType T) const {
00673     return CanQualType::CreateUnsafe(getComplexType((QualType) T));
00674   }
00675 
00676   /// getPointerType - Return the uniqued reference to the type for a pointer to
00677   /// the specified type.
00678   QualType getPointerType(QualType T) const;
00679   CanQualType getPointerType(CanQualType T) const {
00680     return CanQualType::CreateUnsafe(getPointerType((QualType) T));
00681   }
00682 
00683   /// getAtomicType - Return the uniqued reference to the atomic type for
00684   /// the specified type.
00685   QualType getAtomicType(QualType T) const;
00686 
00687   /// getBlockPointerType - Return the uniqued reference to the type for a block
00688   /// of the specified type.
00689   QualType getBlockPointerType(QualType T) const;
00690 
00691   /// This gets the struct used to keep track of the descriptor for pointer to
00692   /// blocks.
00693   QualType getBlockDescriptorType() const;
00694 
00695   /// This gets the struct used to keep track of the extended descriptor for
00696   /// pointer to blocks.
00697   QualType getBlockDescriptorExtendedType() const;
00698 
00699   void setcudaConfigureCallDecl(FunctionDecl *FD) {
00700     cudaConfigureCallDecl = FD;
00701   }
00702   FunctionDecl *getcudaConfigureCallDecl() {
00703     return cudaConfigureCallDecl;
00704   }
00705 
00706   /// This builds the struct used for __block variables.
00707   QualType BuildByRefType(StringRef DeclName, QualType Ty) const;
00708 
00709   /// Returns true iff we need copy/dispose helpers for the given type.
00710   bool BlockRequiresCopying(QualType Ty) const;
00711 
00712   /// getLValueReferenceType - Return the uniqued reference to the type for an
00713   /// lvalue reference to the specified type.
00714   QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true)
00715     const;
00716 
00717   /// getRValueReferenceType - Return the uniqued reference to the type for an
00718   /// rvalue reference to the specified type.
00719   QualType getRValueReferenceType(QualType T) const;
00720 
00721   /// getMemberPointerType - Return the uniqued reference to the type for a
00722   /// member pointer to the specified type in the specified class. The class
00723   /// is a Type because it could be a dependent name.
00724   QualType getMemberPointerType(QualType T, const Type *Cls) const;
00725 
00726   /// getVariableArrayType - Returns a non-unique reference to the type for a
00727   /// variable array of the specified element type.
00728   QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
00729                                 ArrayType::ArraySizeModifier ASM,
00730                                 unsigned IndexTypeQuals,
00731                                 SourceRange Brackets) const;
00732 
00733   /// getDependentSizedArrayType - Returns a non-unique reference to
00734   /// the type for a dependently-sized array of the specified element
00735   /// type. FIXME: We will need these to be uniqued, or at least
00736   /// comparable, at some point.
00737   QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
00738                                       ArrayType::ArraySizeModifier ASM,
00739                                       unsigned IndexTypeQuals,
00740                                       SourceRange Brackets) const;
00741 
00742   /// getIncompleteArrayType - Returns a unique reference to the type for a
00743   /// incomplete array of the specified element type.
00744   QualType getIncompleteArrayType(QualType EltTy,
00745                                   ArrayType::ArraySizeModifier ASM,
00746                                   unsigned IndexTypeQuals) const;
00747 
00748   /// getConstantArrayType - Return the unique reference to the type for a
00749   /// constant array of the specified element type.
00750   QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
00751                                 ArrayType::ArraySizeModifier ASM,
00752                                 unsigned IndexTypeQuals) const;
00753   
00754   /// getVariableArrayDecayedType - Returns a vla type where known sizes
00755   /// are replaced with [*].
00756   QualType getVariableArrayDecayedType(QualType Ty) const;
00757 
00758   /// getVectorType - Return the unique reference to a vector type of
00759   /// the specified element type and size. VectorType must be a built-in type.
00760   QualType getVectorType(QualType VectorType, unsigned NumElts,
00761                          VectorType::VectorKind VecKind) const;
00762 
00763   /// getExtVectorType - Return the unique reference to an extended vector type
00764   /// of the specified element type and size.  VectorType must be a built-in
00765   /// type.
00766   QualType getExtVectorType(QualType VectorType, unsigned NumElts) const;
00767 
00768   /// getDependentSizedExtVectorType - Returns a non-unique reference to
00769   /// the type for a dependently-sized vector of the specified element
00770   /// type. FIXME: We will need these to be uniqued, or at least
00771   /// comparable, at some point.
00772   QualType getDependentSizedExtVectorType(QualType VectorType,
00773                                           Expr *SizeExpr,
00774                                           SourceLocation AttrLoc) const;
00775 
00776   /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'.
00777   ///
00778   QualType getFunctionNoProtoType(QualType ResultTy,
00779                                   const FunctionType::ExtInfo &Info) const;
00780 
00781   QualType getFunctionNoProtoType(QualType ResultTy) const {
00782     return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo());
00783   }
00784 
00785   /// getFunctionType - Return a normal function type with a typed
00786   /// argument list.
00787   QualType getFunctionType(QualType ResultTy,
00788                            const QualType *Args, unsigned NumArgs,
00789                            const FunctionProtoType::ExtProtoInfo &EPI) const;
00790 
00791   /// getTypeDeclType - Return the unique reference to the type for
00792   /// the specified type declaration.
00793   QualType getTypeDeclType(const TypeDecl *Decl,
00794                            const TypeDecl *PrevDecl = 0) const {
00795     assert(Decl && "Passed null for Decl param");
00796     if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
00797 
00798     if (PrevDecl) {
00799       assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
00800       Decl->TypeForDecl = PrevDecl->TypeForDecl;
00801       return QualType(PrevDecl->TypeForDecl, 0);
00802     }
00803 
00804     return getTypeDeclTypeSlow(Decl);
00805   }
00806 
00807   /// getTypedefType - Return the unique reference to the type for the
00808   /// specified typedef-name decl.
00809   QualType getTypedefType(const TypedefNameDecl *Decl,
00810                           QualType Canon = QualType()) const;
00811 
00812   QualType getRecordType(const RecordDecl *Decl) const;
00813 
00814   QualType getEnumType(const EnumDecl *Decl) const;
00815 
00816   QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
00817 
00818   QualType getAttributedType(AttributedType::Kind attrKind,
00819                              QualType modifiedType,
00820                              QualType equivalentType);
00821 
00822   QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
00823                                         QualType Replacement) const;
00824   QualType getSubstTemplateTypeParmPackType(
00825                                           const TemplateTypeParmType *Replaced,
00826                                             const TemplateArgument &ArgPack);
00827 
00828   QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
00829                                    bool ParameterPack,
00830                                    TemplateTypeParmDecl *ParmDecl = 0) const;
00831 
00832   QualType getTemplateSpecializationType(TemplateName T,
00833                                          const TemplateArgument *Args,
00834                                          unsigned NumArgs,
00835                                          QualType Canon = QualType()) const;
00836 
00837   QualType getCanonicalTemplateSpecializationType(TemplateName T,
00838                                                   const TemplateArgument *Args,
00839                                                   unsigned NumArgs) const;
00840 
00841   QualType getTemplateSpecializationType(TemplateName T,
00842                                          const TemplateArgumentListInfo &Args,
00843                                          QualType Canon = QualType()) const;
00844 
00845   TypeSourceInfo *
00846   getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc,
00847                                     const TemplateArgumentListInfo &Args,
00848                                     QualType Canon = QualType()) const;
00849 
00850   QualType getParenType(QualType NamedType) const;
00851 
00852   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
00853                              NestedNameSpecifier *NNS,
00854                              QualType NamedType) const;
00855   QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
00856                                 NestedNameSpecifier *NNS,
00857                                 const IdentifierInfo *Name,
00858                                 QualType Canon = QualType()) const;
00859 
00860   QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
00861                                                   NestedNameSpecifier *NNS,
00862                                                   const IdentifierInfo *Name,
00863                                     const TemplateArgumentListInfo &Args) const;
00864   QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
00865                                                   NestedNameSpecifier *NNS,
00866                                                   const IdentifierInfo *Name,
00867                                                   unsigned NumArgs,
00868                                             const TemplateArgument *Args) const;
00869 
00870   QualType getPackExpansionType(QualType Pattern,
00871                                 llvm::Optional<unsigned> NumExpansions);
00872 
00873   QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
00874                                 ObjCInterfaceDecl *PrevDecl = 0) const;
00875 
00876   QualType getObjCObjectType(QualType Base,
00877                              ObjCProtocolDecl * const *Protocols,
00878                              unsigned NumProtocols) const;
00879 
00880   /// getObjCObjectPointerType - Return a ObjCObjectPointerType type
00881   /// for the given ObjCObjectType.
00882   QualType getObjCObjectPointerType(QualType OIT) const;
00883 
00884   /// getTypeOfType - GCC extension.
00885   QualType getTypeOfExprType(Expr *e) const;
00886   QualType getTypeOfType(QualType t) const;
00887 
00888   /// getDecltypeType - C++0x decltype.
00889   QualType getDecltypeType(Expr *e, QualType UnderlyingType) const;
00890 
00891   /// getUnaryTransformType - unary type transforms
00892   QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType,
00893                                  UnaryTransformType::UTTKind UKind) const;
00894 
00895   /// getAutoType - C++0x deduced auto type.
00896   QualType getAutoType(QualType DeducedType) const;
00897 
00898   /// getAutoDeductType - C++0x deduction pattern for 'auto' type.
00899   QualType getAutoDeductType() const;
00900 
00901   /// getAutoRRefDeductType - C++0x deduction pattern for 'auto &&' type.
00902   QualType getAutoRRefDeductType() const;
00903 
00904   /// getTagDeclType - Return the unique reference to the type for the
00905   /// specified TagDecl (struct/union/class/enum) decl.
00906   QualType getTagDeclType(const TagDecl *Decl) const;
00907 
00908   /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
00909   /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
00910   CanQualType getSizeType() const;
00911 
00912   /// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5),
00913   /// defined in <stdint.h>.
00914   CanQualType getIntMaxType() const;
00915 
00916   /// getUIntMaxType - Return the unique type for "uintmax_t" (C99 7.18.1.5),
00917   /// defined in <stdint.h>.
00918   CanQualType getUIntMaxType() const;
00919 
00920   /// getWCharType - In C++, this returns the unique wchar_t type.  In C99, this
00921   /// returns a type compatible with the type defined in <stddef.h> as defined
00922   /// by the target.
00923   QualType getWCharType() const { return WCharTy; }
00924 
00925   /// getSignedWCharType - Return the type of "signed wchar_t".
00926   /// Used when in C++, as a GCC extension.
00927   QualType getSignedWCharType() const;
00928 
00929   /// getUnsignedWCharType - Return the type of "unsigned wchar_t".
00930   /// Used when in C++, as a GCC extension.
00931   QualType getUnsignedWCharType() const;
00932 
00933   /// getWIntType - In C99, this returns a type compatible with the type
00934   /// defined in <stddef.h> as defined by the target.
00935   QualType getWIntType() const { return WIntTy; }
00936 
00937   /// getPointerDiffType - Return the unique type for "ptrdiff_t" (C99 7.17)
00938   /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
00939   QualType getPointerDiffType() const;
00940 
00941   // getCFConstantStringType - Return the C structure type used to represent
00942   // constant CFStrings.
00943   QualType getCFConstantStringType() const;
00944 
00945   /// Get the structure type used to representation CFStrings, or NULL
00946   /// if it hasn't yet been built.
00947   QualType getRawCFConstantStringType() const {
00948     if (CFConstantStringTypeDecl)
00949       return getTagDeclType(CFConstantStringTypeDecl);
00950     return QualType();
00951   }
00952   void setCFConstantStringType(QualType T);
00953 
00954   // This setter/getter represents the ObjC type for an NSConstantString.
00955   void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
00956   QualType getObjCConstantStringInterface() const {
00957     return ObjCConstantStringType;
00958   }
00959 
00960   QualType getObjCNSStringType() const {
00961     return ObjCNSStringType;
00962   }
00963   
00964   void setObjCNSStringType(QualType T) {
00965     ObjCNSStringType = T;
00966   }
00967   
00968   /// \brief Retrieve the type that 'id' has been defined to, which may be
00969   /// different from the built-in 'id' if 'id' has been typedef'd.
00970   QualType getObjCIdRedefinitionType() const {
00971     if (ObjCIdRedefinitionType.isNull())
00972       return getObjCIdType();
00973     return ObjCIdRedefinitionType;
00974   }
00975   
00976   /// \brief Set the user-written type that redefines 'id'.
00977   void setObjCIdRedefinitionType(QualType RedefType) {
00978     ObjCIdRedefinitionType = RedefType;
00979   }
00980 
00981   /// \brief Retrieve the type that 'Class' has been defined to, which may be
00982   /// different from the built-in 'Class' if 'Class' has been typedef'd.
00983   QualType getObjCClassRedefinitionType() const {
00984     if (ObjCClassRedefinitionType.isNull())
00985       return getObjCClassType();
00986     return ObjCClassRedefinitionType;
00987   }
00988   
00989   /// \brief Set the user-written type that redefines 'SEL'.
00990   void setObjCClassRedefinitionType(QualType RedefType) {
00991     ObjCClassRedefinitionType = RedefType;
00992   }
00993 
00994   /// \brief Retrieve the type that 'SEL' has been defined to, which may be
00995   /// different from the built-in 'SEL' if 'SEL' has been typedef'd.
00996   QualType getObjCSelRedefinitionType() const {
00997     if (ObjCSelRedefinitionType.isNull())
00998       return getObjCSelType();
00999     return ObjCSelRedefinitionType;
01000   }
01001 
01002   
01003   /// \brief Set the user-written type that redefines 'SEL'.
01004   void setObjCSelRedefinitionType(QualType RedefType) {
01005     ObjCSelRedefinitionType = RedefType;
01006   }
01007 
01008   /// \brief Retrieve the Objective-C "instancetype" type, if already known;
01009   /// otherwise, returns a NULL type;
01010   QualType getObjCInstanceType() {
01011     return getTypeDeclType(getObjCInstanceTypeDecl());
01012   }
01013 
01014   /// \brief Retrieve the typedef declaration corresponding to the Objective-C
01015   /// "instancetype" type.
01016   TypedefDecl *getObjCInstanceTypeDecl();
01017   
01018   /// \brief Set the type for the C FILE type.
01019   void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
01020 
01021   /// \brief Retrieve the C FILE type.
01022   QualType getFILEType() const {
01023     if (FILEDecl)
01024       return getTypeDeclType(FILEDecl);
01025     return QualType();
01026   }
01027 
01028   /// \brief Set the type for the C jmp_buf type.
01029   void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
01030     this->jmp_bufDecl = jmp_bufDecl;
01031   }
01032 
01033   /// \brief Retrieve the C jmp_buf type.
01034   QualType getjmp_bufType() const {
01035     if (jmp_bufDecl)
01036       return getTypeDeclType(jmp_bufDecl);
01037     return QualType();
01038   }
01039 
01040   /// \brief Set the type for the C sigjmp_buf type.
01041   void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
01042     this->sigjmp_bufDecl = sigjmp_bufDecl;
01043   }
01044 
01045   /// \brief Retrieve the C sigjmp_buf type.
01046   QualType getsigjmp_bufType() const {
01047     if (sigjmp_bufDecl)
01048       return getTypeDeclType(sigjmp_bufDecl);
01049     return QualType();
01050   }
01051 
01052   /// \brief Set the type for the C ucontext_t type.
01053   void setucontext_tDecl(TypeDecl *ucontext_tDecl) {
01054     this->ucontext_tDecl = ucontext_tDecl;
01055   }
01056 
01057   /// \brief Retrieve the C ucontext_t type.
01058   QualType getucontext_tType() const {
01059     if (ucontext_tDecl)
01060       return getTypeDeclType(ucontext_tDecl);
01061     return QualType();
01062   }
01063 
01064   /// \brief The result type of logical operations, '<', '>', '!=', etc.
01065   QualType getLogicalOperationType() const {
01066     return getLangOpts().CPlusPlus ? BoolTy : IntTy;
01067   }
01068 
01069   /// getObjCEncodingForType - Emit the ObjC type encoding for the
01070   /// given type into \arg S. If \arg NameFields is specified then
01071   /// record field names are also encoded.
01072   void getObjCEncodingForType(QualType t, std::string &S,
01073                               const FieldDecl *Field=0) const;
01074 
01075   void getLegacyIntegralTypeEncoding(QualType &t) const;
01076 
01077   // Put the string version of type qualifiers into S.
01078   void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
01079                                        std::string &S) const;
01080 
01081   /// getObjCEncodingForFunctionDecl - Returns the encoded type for this
01082   /// function.  This is in the same format as Objective-C method encodings.  
01083   ///
01084   /// \returns true if an error occurred (e.g., because one of the parameter
01085   /// types is incomplete), false otherwise.
01086   bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S);
01087 
01088   /// getObjCEncodingForMethodDecl - Return the encoded type for this method
01089   /// declaration.
01090   ///
01091   /// \returns true if an error occurred (e.g., because one of the parameter
01092   /// types is incomplete), false otherwise.
01093   bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S,
01094                                     bool Extended = false)
01095     const;
01096 
01097   /// getObjCEncodingForBlock - Return the encoded type for this block
01098   /// declaration.
01099   std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
01100   
01101   /// getObjCEncodingForPropertyDecl - Return the encoded type for
01102   /// this method declaration. If non-NULL, Container must be either
01103   /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
01104   /// only be NULL when getting encodings for protocol properties.
01105   void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
01106                                       const Decl *Container,
01107                                       std::string &S) const;
01108 
01109   bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
01110                                       ObjCProtocolDecl *rProto) const;
01111 
01112   /// getObjCEncodingTypeSize returns size of type for objective-c encoding
01113   /// purpose in characters.
01114   CharUnits getObjCEncodingTypeSize(QualType t) const;
01115 
01116   /// \brief Retrieve the typedef corresponding to the predefined 'id' type
01117   /// in Objective-C.
01118   TypedefDecl *getObjCIdDecl() const;
01119   
01120   /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by
01121   /// Sema.  id is always a (typedef for a) pointer type, a pointer to a struct.
01122   QualType getObjCIdType() const {
01123     return getTypeDeclType(getObjCIdDecl());
01124   }
01125 
01126   /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type
01127   /// in Objective-C.
01128   TypedefDecl *getObjCSelDecl() const;
01129   
01130   /// \brief Retrieve the type that corresponds to the predefined Objective-C
01131   /// 'SEL' type.
01132   QualType getObjCSelType() const { 
01133     return getTypeDeclType(getObjCSelDecl());
01134   }
01135 
01136   /// \brief Retrieve the typedef declaration corresponding to the predefined
01137   /// Objective-C 'Class' type.
01138   TypedefDecl *getObjCClassDecl() const;
01139   
01140   /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
01141   /// Sema.  'Class' is always a (typedef for a) pointer type, a pointer to a
01142   /// struct.
01143   QualType getObjCClassType() const { 
01144     return getTypeDeclType(getObjCClassDecl());
01145   }
01146 
01147   /// \brief Retrieve the Objective-C class declaration corresponding to 
01148   /// the predefined 'Protocol' class.
01149   ObjCInterfaceDecl *getObjCProtocolDecl() const;
01150   
01151   /// \brief Retrieve the type of the Objective-C "Protocol" class.
01152   QualType getObjCProtoType() const {
01153     return getObjCInterfaceType(getObjCProtocolDecl());
01154   }
01155   
01156   void setBuiltinVaListType(QualType T);
01157   QualType getBuiltinVaListType() const { return BuiltinVaListType; }
01158 
01159   /// getCVRQualifiedType - Returns a type with additional const,
01160   /// volatile, or restrict qualifiers.
01161   QualType getCVRQualifiedType(QualType T, unsigned CVR) const {
01162     return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
01163   }
01164 
01165   /// getQualifiedType - Un-split a SplitQualType.
01166   QualType getQualifiedType(SplitQualType split) const {
01167     return getQualifiedType(split.Ty, split.Quals);
01168   }
01169 
01170   /// getQualifiedType - Returns a type with additional qualifiers.
01171   QualType getQualifiedType(QualType T, Qualifiers Qs) const {
01172     if (!Qs.hasNonFastQualifiers())
01173       return T.withFastQualifiers(Qs.getFastQualifiers());
01174     QualifierCollector Qc(Qs);
01175     const Type *Ptr = Qc.strip(T);
01176     return getExtQualType(Ptr, Qc);
01177   }
01178 
01179   /// getQualifiedType - Returns a type with additional qualifiers.
01180   QualType getQualifiedType(const Type *T, Qualifiers Qs) const {
01181     if (!Qs.hasNonFastQualifiers())
01182       return QualType(T, Qs.getFastQualifiers());
01183     return getExtQualType(T, Qs);
01184   }
01185 
01186   /// getLifetimeQualifiedType - Returns a type with the given
01187   /// lifetime qualifier.
01188   QualType getLifetimeQualifiedType(QualType type,
01189                                     Qualifiers::ObjCLifetime lifetime) {
01190     assert(type.getObjCLifetime() == Qualifiers::OCL_None);
01191     assert(lifetime != Qualifiers::OCL_None);
01192 
01193     Qualifiers qs;
01194     qs.addObjCLifetime(lifetime);
01195     return getQualifiedType(type, qs);
01196   }
01197 
01198   DeclarationNameInfo getNameForTemplate(TemplateName Name,
01199                                          SourceLocation NameLoc) const;
01200 
01201   TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
01202                                          UnresolvedSetIterator End) const;
01203 
01204   TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
01205                                         bool TemplateKeyword,
01206                                         TemplateDecl *Template) const;
01207 
01208   TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
01209                                         const IdentifierInfo *Name) const;
01210   TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
01211                                         OverloadedOperatorKind Operator) const;
01212   TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param,
01213                                             TemplateName replacement) const;
01214   TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param,
01215                                         const TemplateArgument &ArgPack) const;
01216   
01217   enum GetBuiltinTypeError {
01218     GE_None,              //< No error
01219     GE_Missing_stdio,     //< Missing a type from <stdio.h>
01220     GE_Missing_setjmp,    //< Missing a type from <setjmp.h>
01221     GE_Missing_ucontext   //< Missing a type from <ucontext.h>
01222   };
01223 
01224   /// GetBuiltinType - Return the type for the specified builtin.  If 
01225   /// IntegerConstantArgs is non-null, it is filled in with a bitmask of
01226   /// arguments to the builtin that are required to be integer constant
01227   /// expressions.
01228   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
01229                           unsigned *IntegerConstantArgs = 0) const;
01230 
01231 private:
01232   CanQualType getFromTargetType(unsigned Type) const;
01233   std::pair<uint64_t, unsigned> getTypeInfoImpl(const Type *T) const;
01234 
01235   //===--------------------------------------------------------------------===//
01236   //                         Type Predicates.
01237   //===--------------------------------------------------------------------===//
01238 
01239 public:
01240   /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
01241   /// garbage collection attribute.
01242   ///
01243   Qualifiers::GC getObjCGCAttrKind(QualType Ty) const;
01244 
01245   /// areCompatibleVectorTypes - Return true if the given vector types
01246   /// are of the same unqualified type or if they are equivalent to the same
01247   /// GCC vector type, ignoring whether they are target-specific (AltiVec or
01248   /// Neon) types.
01249   bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
01250 
01251   /// isObjCNSObjectType - Return true if this is an NSObject object with
01252   /// its NSObject attribute set.
01253   static bool isObjCNSObjectType(QualType Ty) {
01254     return Ty->isObjCNSObjectType();
01255   }
01256 
01257   //===--------------------------------------------------------------------===//
01258   //                         Type Sizing and Analysis
01259   //===--------------------------------------------------------------------===//
01260 
01261   /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified
01262   /// scalar floating point type.
01263   const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
01264 
01265   /// getTypeInfo - Get the size and alignment of the specified complete type in
01266   /// bits.
01267   std::pair<uint64_t, unsigned> getTypeInfo(const Type *T) const;
01268   std::pair<uint64_t, unsigned> getTypeInfo(QualType T) const {
01269     return getTypeInfo(T.getTypePtr());
01270   }
01271 
01272   /// getTypeSize - Return the size of the specified type, in bits.  This method
01273   /// does not work on incomplete types.
01274   uint64_t getTypeSize(QualType T) const {
01275     return getTypeInfo(T).first;
01276   }
01277   uint64_t getTypeSize(const Type *T) const {
01278     return getTypeInfo(T).first;
01279   }
01280 
01281   /// getCharWidth - Return the size of the character type, in bits
01282   uint64_t getCharWidth() const {
01283     return getTypeSize(CharTy);
01284   }
01285   
01286   /// toCharUnitsFromBits - Convert a size in bits to a size in characters.
01287   CharUnits toCharUnitsFromBits(int64_t BitSize) const;
01288 
01289   /// toBits - Convert a size in characters to a size in bits.
01290   int64_t toBits(CharUnits CharSize) const;
01291 
01292   /// getTypeSizeInChars - Return the size of the specified type, in characters.
01293   /// This method does not work on incomplete types.
01294   CharUnits getTypeSizeInChars(QualType T) const;
01295   CharUnits getTypeSizeInChars(const Type *T) const;
01296 
01297   /// getTypeAlign - Return the ABI-specified alignment of a type, in bits.
01298   /// This method does not work on incomplete types.
01299   unsigned getTypeAlign(QualType T) const {
01300     return getTypeInfo(T).second;
01301   }
01302   unsigned getTypeAlign(const Type *T) const {
01303     return getTypeInfo(T).second;
01304   }
01305 
01306   /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in 
01307   /// characters. This method does not work on incomplete types.
01308   CharUnits getTypeAlignInChars(QualType T) const;
01309   CharUnits getTypeAlignInChars(const Type *T) const;
01310 
01311   std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const;
01312   std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const;
01313 
01314   /// getPreferredTypeAlign - Return the "preferred" alignment of the specified
01315   /// type for the current target in bits.  This can be different than the ABI
01316   /// alignment in cases where it is beneficial for performance to overalign
01317   /// a data type.
01318   unsigned getPreferredTypeAlign(const Type *T) const;
01319 
01320   /// getDeclAlign - Return a conservative estimate of the alignment of
01321   /// the specified decl.  Note that bitfields do not have a valid alignment, so
01322   /// this method will assert on them.
01323   /// If @p RefAsPointee, references are treated like their underlying type
01324   /// (for alignof), else they're treated like pointers (for CodeGen).
01325   CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false) const;
01326 
01327   /// getASTRecordLayout - Get or compute information about the layout of the
01328   /// specified record (struct/union/class), which indicates its size and field
01329   /// position information.
01330   const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const;
01331 
01332   /// getASTObjCInterfaceLayout - Get or compute information about the
01333   /// layout of the specified Objective-C interface.
01334   const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D)
01335     const;
01336 
01337   void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS,
01338                         bool Simple = false) const;
01339 
01340   /// getASTObjCImplementationLayout - Get or compute information about
01341   /// the layout of the specified Objective-C implementation. This may
01342   /// differ from the interface if synthesized ivars are present.
01343   const ASTRecordLayout &
01344   getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const;
01345 
01346   /// getKeyFunction - Get the key function for the given record decl, or NULL
01347   /// if there isn't one.  The key function is, according to the Itanium C++ ABI
01348   /// section 5.2.3:
01349   ///
01350   /// ...the first non-pure virtual function that is not inline at the point
01351   /// of class definition.
01352   const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD);
01353 
01354   /// Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
01355   uint64_t getFieldOffset(const ValueDecl *FD) const;
01356 
01357   bool isNearlyEmpty(const CXXRecordDecl *RD) const;
01358 
01359   MangleContext *createMangleContext();
01360   
01361   void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
01362                             SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const;
01363   
01364   unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const;
01365   void CollectInheritedProtocols(const Decl *CDecl,
01366                           llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
01367 
01368   //===--------------------------------------------------------------------===//
01369   //                            Type Operators
01370   //===--------------------------------------------------------------------===//
01371 
01372   /// getCanonicalType - Return the canonical (structural) type corresponding to
01373   /// the specified potentially non-canonical type.  The non-canonical version
01374   /// of a type may have many "decorated" versions of types.  Decorators can
01375   /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
01376   /// to be free of any of these, allowing two canonical types to be compared
01377   /// for exact equality with a simple pointer comparison.
01378   CanQualType getCanonicalType(QualType T) const {
01379     return CanQualType::CreateUnsafe(T.getCanonicalType());
01380   }
01381 
01382   const Type *getCanonicalType(const Type *T) const {
01383     return T->getCanonicalTypeInternal().getTypePtr();
01384   }
01385 
01386   /// getCanonicalParamType - Return the canonical parameter type
01387   /// corresponding to the specific potentially non-canonical one.
01388   /// Qualifiers are stripped off, functions are turned into function
01389   /// pointers, and arrays decay one level into pointers.
01390   CanQualType getCanonicalParamType(QualType T) const;
01391 
01392   /// \brief Determine whether the given types are equivalent.
01393   bool hasSameType(QualType T1, QualType T2) const {
01394     return getCanonicalType(T1) == getCanonicalType(T2);
01395   }
01396 
01397   /// \brief Returns this type as a completely-unqualified array type,
01398   /// capturing the qualifiers in Quals. This will remove the minimal amount of
01399   /// sugaring from the types, similar to the behavior of
01400   /// QualType::getUnqualifiedType().
01401   ///
01402   /// \param T is the qualified type, which may be an ArrayType
01403   ///
01404   /// \param Quals will receive the full set of qualifiers that were
01405   /// applied to the array.
01406   ///
01407   /// \returns if this is an array type, the completely unqualified array type
01408   /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
01409   QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
01410 
01411   /// \brief Determine whether the given types are equivalent after
01412   /// cvr-qualifiers have been removed.
01413   bool hasSameUnqualifiedType(QualType T1, QualType T2) const {
01414     return getCanonicalType(T1).getTypePtr() ==
01415            getCanonicalType(T2).getTypePtr();
01416   }
01417 
01418   bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2);
01419   
01420   /// \brief Retrieves the "canonical" nested name specifier for a
01421   /// given nested name specifier.
01422   ///
01423   /// The canonical nested name specifier is a nested name specifier
01424   /// that uniquely identifies a type or namespace within the type
01425   /// system. For example, given:
01426   ///
01427   /// \code
01428   /// namespace N {
01429   ///   struct S {
01430   ///     template<typename T> struct X { typename T* type; };
01431   ///   };
01432   /// }
01433   ///
01434   /// template<typename T> struct Y {
01435   ///   typename N::S::X<T>::type member;
01436   /// };
01437   /// \endcode
01438   ///
01439   /// Here, the nested-name-specifier for N::S::X<T>:: will be
01440   /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined
01441   /// by declarations in the type system and the canonical type for
01442   /// the template type parameter 'T' is template-param-0-0.
01443   NestedNameSpecifier *
01444   getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const;
01445 
01446   /// \brief Retrieves the default calling convention to use for
01447   /// C++ instance methods.
01448   CallingConv getDefaultMethodCallConv();
01449 
01450   /// \brief Retrieves the canonical representation of the given
01451   /// calling convention.
01452   CallingConv getCanonicalCallConv(CallingConv CC) const {
01453     if (!LangOpts.MRTD && CC == CC_C)
01454       return CC_Default;
01455     return CC;
01456   }
01457 
01458   /// \brief Determines whether two calling conventions name the same
01459   /// calling convention.
01460   bool isSameCallConv(CallingConv lcc, CallingConv rcc) {
01461     return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc));
01462   }
01463 
01464   /// \brief Retrieves the "canonical" template name that refers to a
01465   /// given template.
01466   ///
01467   /// The canonical template name is the simplest expression that can
01468   /// be used to refer to a given template. For most templates, this
01469   /// expression is just the template declaration itself. For example,
01470   /// the template std::vector can be referred to via a variety of
01471   /// names---std::vector, ::std::vector, vector (if vector is in
01472   /// scope), etc.---but all of these names map down to the same
01473   /// TemplateDecl, which is used to form the canonical template name.
01474   ///
01475   /// Dependent template names are more interesting. Here, the
01476   /// template name could be something like T::template apply or
01477   /// std::allocator<T>::template rebind, where the nested name
01478   /// specifier itself is dependent. In this case, the canonical
01479   /// template name uses the shortest form of the dependent
01480   /// nested-name-specifier, which itself contains all canonical
01481   /// types, values, and templates.
01482   TemplateName getCanonicalTemplateName(TemplateName Name) const;
01483 
01484   /// \brief Determine whether the given template names refer to the same
01485   /// template.
01486   bool hasSameTemplateName(TemplateName X, TemplateName Y);
01487   
01488   /// \brief Retrieve the "canonical" template argument.
01489   ///
01490   /// The canonical template argument is the simplest template argument
01491   /// (which may be a type, value, expression, or declaration) that
01492   /// expresses the value of the argument.
01493   TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg)
01494     const;
01495 
01496   /// Type Query functions.  If the type is an instance of the specified class,
01497   /// return the Type pointer for the underlying maximally pretty type.  This
01498   /// is a member of ASTContext because this may need to do some amount of
01499   /// canonicalization, e.g. to move type qualifiers into the element type.
01500   const ArrayType *getAsArrayType(QualType T) const;
01501   const ConstantArrayType *getAsConstantArrayType(QualType T) const {
01502     return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
01503   }
01504   const VariableArrayType *getAsVariableArrayType(QualType T) const {
01505     return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
01506   }
01507   const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const {
01508     return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
01509   }
01510   const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T)
01511     const {
01512     return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
01513   }
01514   
01515   /// getBaseElementType - Returns the innermost element type of an array type.
01516   /// For example, will return "int" for int[m][n]
01517   QualType getBaseElementType(const ArrayType *VAT) const;
01518 
01519   /// getBaseElementType - Returns the innermost element type of a type
01520   /// (which needn't actually be an array type).
01521   QualType getBaseElementType(QualType QT) const;
01522 
01523   /// getConstantArrayElementCount - Returns number of constant array elements.
01524   uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
01525 
01526   /// \brief Perform adjustment on the parameter type of a function.
01527   ///
01528   /// This routine adjusts the given parameter type @p T to the actual
01529   /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8],
01530   /// C++ [dcl.fct]p3). The adjusted parameter type is returned.
01531   QualType getAdjustedParameterType(QualType T);
01532   
01533   /// \brief Retrieve the parameter type as adjusted for use in the signature
01534   /// of a function, decaying array and function types and removing top-level
01535   /// cv-qualifiers.
01536   QualType getSignatureParameterType(QualType T);
01537   
01538   /// getArrayDecayedType - Return the properly qualified result of decaying the
01539   /// specified array type to a pointer.  This operation is non-trivial when
01540   /// handling typedefs etc.  The canonical type of "T" must be an array type,
01541   /// this returns a pointer to a properly qualified element of the array.
01542   ///
01543   /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
01544   QualType getArrayDecayedType(QualType T) const;
01545 
01546   /// getPromotedIntegerType - Returns the type that Promotable will
01547   /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable
01548   /// integer type.
01549   QualType getPromotedIntegerType(QualType PromotableType) const;
01550 
01551   /// \brief Recurses in pointer/array types until it finds an objc retainable
01552   /// type and returns its ownership.
01553   Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const;
01554 
01555   /// \brief Whether this is a promotable bitfield reference according
01556   /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
01557   ///
01558   /// \returns the type this bit-field will promote to, or NULL if no
01559   /// promotion occurs.
01560   QualType isPromotableBitField(Expr *E) const;
01561 
01562   /// getIntegerTypeOrder - Returns the highest ranked integer type:
01563   /// C99 6.3.1.8p1.  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
01564   /// LHS < RHS, return -1.
01565   int getIntegerTypeOrder(QualType LHS, QualType RHS) const;
01566 
01567   /// getFloatingTypeOrder - Compare the rank of the two specified floating
01568   /// point types, ignoring the domain of the type (i.e. 'double' ==
01569   /// '_Complex double').  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
01570   /// LHS < RHS, return -1.
01571   int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
01572 
01573   /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
01574   /// point or a complex type (based on typeDomain/typeSize).
01575   /// 'typeDomain' is a real floating point or complex type.
01576   /// 'typeSize' is a real floating point or complex type.
01577   QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
01578                                              QualType typeDomain) const;
01579 
01580   unsigned getTargetAddressSpace(QualType T) const {
01581     return getTargetAddressSpace(T.getQualifiers());
01582   }
01583 
01584   unsigned getTargetAddressSpace(Qualifiers Q) const {
01585     return getTargetAddressSpace(Q.getAddressSpace());
01586   }
01587 
01588   unsigned getTargetAddressSpace(unsigned AS) const {
01589     if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count)
01590       return AS;
01591     else
01592       return (*AddrSpaceMap)[AS - LangAS::Offset];
01593   }
01594 
01595 private:
01596   // Helper for integer ordering
01597   unsigned getIntegerRank(const Type *T) const;
01598 
01599 public:
01600 
01601   //===--------------------------------------------------------------------===//
01602   //                    Type Compatibility Predicates
01603   //===--------------------------------------------------------------------===//
01604 
01605   /// Compatibility predicates used to check assignment expressions.
01606   bool typesAreCompatible(QualType T1, QualType T2, 
01607                           bool CompareUnqualified = false); // C99 6.2.7p1
01608 
01609   bool propertyTypesAreCompatible(QualType, QualType); 
01610   bool typesAreBlockPointerCompatible(QualType, QualType); 
01611 
01612   bool isObjCIdType(QualType T) const {
01613     return T == getObjCIdType();
01614   }
01615   bool isObjCClassType(QualType T) const {
01616     return T == getObjCClassType();
01617   }
01618   bool isObjCSelType(QualType T) const {
01619     return T == getObjCSelType();
01620   }
01621   bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
01622   bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
01623                                          bool ForCompare);
01624 
01625   bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS);
01626   
01627   // Check the safety of assignment from LHS to RHS
01628   bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
01629                                const ObjCObjectPointerType *RHSOPT);
01630   bool canAssignObjCInterfaces(const ObjCObjectType *LHS,
01631                                const ObjCObjectType *RHS);
01632   bool canAssignObjCInterfacesInBlockPointer(
01633                                           const ObjCObjectPointerType *LHSOPT,
01634                                           const ObjCObjectPointerType *RHSOPT,
01635                                           bool BlockReturnType);
01636   bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
01637   QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
01638                                    const ObjCObjectPointerType *RHSOPT);
01639   bool canBindObjCObjectType(QualType To, QualType From);
01640 
01641   // Functions for calculating composite types
01642   QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false,
01643                       bool Unqualified = false, bool BlockReturnType = false);
01644   QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false,
01645                               bool Unqualified = false);
01646   QualType mergeFunctionArgumentTypes(QualType, QualType,
01647                                       bool OfBlockPointer=false,
01648                                       bool Unqualified = false);
01649   QualType mergeTransparentUnionType(QualType, QualType,
01650                                      bool OfBlockPointer=false,
01651                                      bool Unqualified = false);
01652   
01653   QualType mergeObjCGCQualifiers(QualType, QualType);
01654     
01655   bool FunctionTypesMatchOnNSConsumedAttrs(
01656          const FunctionProtoType *FromFunctionType,
01657          const FunctionProtoType *ToFunctionType);
01658 
01659   void ResetObjCLayout(const ObjCContainerDecl *CD) {
01660     ObjCLayouts[CD] = 0;
01661   }
01662 
01663   //===--------------------------------------------------------------------===//
01664   //                    Integer Predicates
01665   //===--------------------------------------------------------------------===//
01666 
01667   // The width of an integer, as defined in C99 6.2.6.2. This is the number
01668   // of bits in an integer type excluding any padding bits.
01669   unsigned getIntWidth(QualType T) const;
01670 
01671   // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
01672   // unsigned integer type.  This method takes a signed type, and returns the
01673   // corresponding unsigned integer type.
01674   QualType getCorrespondingUnsignedType(QualType T);
01675 
01676   //===--------------------------------------------------------------------===//
01677   //                    Type Iterators.
01678   //===--------------------------------------------------------------------===//
01679 
01680   typedef std::vector<Type*>::iterator       type_iterator;
01681   typedef std::vector<Type*>::const_iterator const_type_iterator;
01682 
01683   type_iterator types_begin() { return Types.begin(); }
01684   type_iterator types_end() { return Types.end(); }
01685   const_type_iterator types_begin() const { return Types.begin(); }
01686   const_type_iterator types_end() const { return Types.end(); }
01687 
01688   //===--------------------------------------------------------------------===//
01689   //                    Integer Values
01690   //===--------------------------------------------------------------------===//
01691 
01692   /// MakeIntValue - Make an APSInt of the appropriate width and
01693   /// signedness for the given \arg Value and integer \arg Type.
01694   llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const {
01695     llvm::APSInt Res(getIntWidth(Type), 
01696                      !Type->isSignedIntegerOrEnumerationType());
01697     Res = Value;
01698     return Res;
01699   }
01700 
01701   bool isSentinelNullExpr(const Expr *E);
01702 
01703   /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists.
01704   ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
01705   /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists.
01706   ObjCCategoryImplDecl   *getObjCImplementation(ObjCCategoryDecl *D);
01707 
01708   /// \brief returns true if there is at lease one @implementation in TU.
01709   bool AnyObjCImplementation() {
01710     return !ObjCImpls.empty();
01711   }
01712 
01713   /// \brief Set the implementation of ObjCInterfaceDecl.
01714   void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
01715                              ObjCImplementationDecl *ImplD);
01716   /// \brief Set the implementation of ObjCCategoryDecl.
01717   void setObjCImplementation(ObjCCategoryDecl *CatD,
01718                              ObjCCategoryImplDecl *ImplD);
01719 
01720   /// \brief Get the duplicate declaration of a ObjCMethod in the same
01721   /// interface, or null if non exists.
01722   const ObjCMethodDecl *getObjCMethodRedeclaration(
01723                                                const ObjCMethodDecl *MD) const {
01724     llvm::DenseMap<const ObjCMethodDecl*, const ObjCMethodDecl*>::const_iterator
01725       I = ObjCMethodRedecls.find(MD);
01726     if (I == ObjCMethodRedecls.end())
01727       return 0;
01728     return I->second;
01729   }
01730 
01731   void setObjCMethodRedeclaration(const ObjCMethodDecl *MD,
01732                                   const ObjCMethodDecl *Redecl) {
01733     ObjCMethodRedecls[MD] = Redecl;
01734   }
01735 
01736   /// \brief Returns the objc interface that \arg ND belongs to if it is a
01737   /// objc method/property/ivar etc. that is part of an interface,
01738   /// otherwise returns null.
01739   ObjCInterfaceDecl *getObjContainingInterface(NamedDecl *ND) const;
01740   
01741   /// \brief Set the copy inialization expression of a block var decl.
01742   void setBlockVarCopyInits(VarDecl*VD, Expr* Init);
01743   /// \brief Get the copy initialization expression of VarDecl,or NULL if 
01744   /// none exists.
01745   Expr *getBlockVarCopyInits(const VarDecl*VD);
01746 
01747   /// \brief Allocate an uninitialized TypeSourceInfo.
01748   ///
01749   /// The caller should initialize the memory held by TypeSourceInfo using
01750   /// the TypeLoc wrappers.
01751   ///
01752   /// \param T the type that will be the basis for type source info. This type
01753   /// should refer to how the declarator was written in source code, not to
01754   /// what type semantic analysis resolved the declarator to.
01755   ///
01756   /// \param Size the size of the type info to create, or 0 if the size
01757   /// should be calculated based on the type.
01758   TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const;
01759 
01760   /// \brief Allocate a TypeSourceInfo where all locations have been
01761   /// initialized to a given location, which defaults to the empty
01762   /// location.
01763   TypeSourceInfo *
01764   getTrivialTypeSourceInfo(QualType T, 
01765                            SourceLocation Loc = SourceLocation()) const;
01766 
01767   TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; }
01768 
01769   /// \brief Add a deallocation callback that will be invoked when the 
01770   /// ASTContext is destroyed.
01771   ///
01772   /// \brief Callback A callback function that will be invoked on destruction.
01773   ///
01774   /// \brief Data Pointer data that will be provided to the callback function
01775   /// when it is called.
01776   void AddDeallocation(void (*Callback)(void*), void *Data);
01777 
01778   GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD);
01779   GVALinkage GetGVALinkageForVariable(const VarDecl *VD);
01780 
01781   /// \brief Determines if the decl can be CodeGen'ed or deserialized from PCH
01782   /// lazily, only when used; this is only relevant for function or file scoped
01783   /// var definitions.
01784   ///
01785   /// \returns true if the function/var must be CodeGen'ed/deserialized even if
01786   /// it is not used.
01787   bool DeclMustBeEmitted(const Decl *D);
01788 
01789   /// \brief Retrieve the lambda mangling number for a lambda expression.
01790   unsigned getLambdaManglingNumber(CXXMethodDecl *CallOperator);
01791   
01792   /// \brief Used by ParmVarDecl to store on the side the
01793   /// index of the parameter when it exceeds the size of the normal bitfield.
01794   void setParameterIndex(const ParmVarDecl *D, unsigned index);
01795 
01796   /// \brief Used by ParmVarDecl to retrieve on the side the
01797   /// index of the parameter when it exceeds the size of the normal bitfield.
01798   unsigned getParameterIndex(const ParmVarDecl *D) const;
01799   
01800   //===--------------------------------------------------------------------===//
01801   //                    Statistics
01802   //===--------------------------------------------------------------------===//
01803 
01804   /// \brief The number of implicitly-declared default constructors.
01805   static unsigned NumImplicitDefaultConstructors;
01806   
01807   /// \brief The number of implicitly-declared default constructors for 
01808   /// which declarations were built.
01809   static unsigned NumImplicitDefaultConstructorsDeclared;
01810 
01811   /// \brief The number of implicitly-declared copy constructors.
01812   static unsigned NumImplicitCopyConstructors;
01813   
01814   /// \brief The number of implicitly-declared copy constructors for 
01815   /// which declarations were built.
01816   static unsigned NumImplicitCopyConstructorsDeclared;
01817 
01818   /// \brief The number of implicitly-declared move constructors.
01819   static unsigned NumImplicitMoveConstructors;
01820 
01821   /// \brief The number of implicitly-declared move constructors for
01822   /// which declarations were built.
01823   static unsigned NumImplicitMoveConstructorsDeclared;
01824 
01825   /// \brief The number of implicitly-declared copy assignment operators.
01826   static unsigned NumImplicitCopyAssignmentOperators;
01827   
01828   /// \brief The number of implicitly-declared copy assignment operators for 
01829   /// which declarations were built.
01830   static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
01831 
01832   /// \brief The number of implicitly-declared move assignment operators.
01833   static unsigned NumImplicitMoveAssignmentOperators;
01834   
01835   /// \brief The number of implicitly-declared move assignment operators for 
01836   /// which declarations were built.
01837   static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
01838 
01839   /// \brief The number of implicitly-declared destructors.
01840   static unsigned NumImplicitDestructors;
01841   
01842   /// \brief The number of implicitly-declared destructors for which 
01843   /// declarations were built.
01844   static unsigned NumImplicitDestructorsDeclared;
01845   
01846 private:
01847   ASTContext(const ASTContext&); // DO NOT IMPLEMENT
01848   void operator=(const ASTContext&); // DO NOT IMPLEMENT
01849 
01850 public:
01851   /// \brief Initialize built-in types.
01852   ///
01853   /// This routine may only be invoked once for a given ASTContext object.
01854   /// It is normally invoked by the ASTContext constructor. However, the
01855   /// constructor can be asked to delay initialization, which places the burden
01856   /// of calling this function on the user of that object.
01857   ///
01858   /// \param Target The target 
01859   void InitBuiltinTypes(const TargetInfo &Target);
01860   
01861 private:
01862   void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
01863 
01864   // Return the ObjC type encoding for a given type.
01865   void getObjCEncodingForTypeImpl(QualType t, std::string &S,
01866                                   bool ExpandPointedToStructures,
01867                                   bool ExpandStructures,
01868                                   const FieldDecl *Field,
01869                                   bool OutermostType = false,
01870                                   bool EncodingProperty = false,
01871                                   bool StructField = false,
01872                                   bool EncodeBlockParameters = false,
01873                                   bool EncodeClassNames = false) const;
01874 
01875   // Adds the encoding of the structure's members.
01876   void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S,
01877                                        const FieldDecl *Field,
01878                                        bool includeVBases = true) const;
01879 
01880   // Adds the encoding of a method parameter or return type.
01881   void getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT,
01882                                          QualType T, std::string& S,
01883                                          bool Extended) const;
01884 
01885   const ASTRecordLayout &
01886   getObjCLayout(const ObjCInterfaceDecl *D,
01887                 const ObjCImplementationDecl *Impl) const;
01888 
01889 private:
01890   /// \brief A set of deallocations that should be performed when the 
01891   /// ASTContext is destroyed.
01892   SmallVector<std::pair<void (*)(void*), void *>, 16> Deallocations;
01893                                        
01894   // FIXME: This currently contains the set of StoredDeclMaps used
01895   // by DeclContext objects.  This probably should not be in ASTContext,
01896   // but we include it here so that ASTContext can quickly deallocate them.
01897   llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM;
01898 
01899   /// \brief A counter used to uniquely identify "blocks".
01900   mutable unsigned int UniqueBlockByRefTypeID;
01901   
01902   friend class DeclContext;
01903   friend class DeclarationNameTable;
01904   void ReleaseDeclContextMaps();
01905 };
01906   
01907 /// @brief Utility function for constructing a nullary selector.
01908 static inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) {
01909   IdentifierInfo* II = &Ctx.Idents.get(name);
01910   return Ctx.Selectors.getSelector(0, &II);
01911 }
01912 
01913 /// @brief Utility function for constructing an unary selector.
01914 static inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) {
01915   IdentifierInfo* II = &Ctx.Idents.get(name);
01916   return Ctx.Selectors.getSelector(1, &II);
01917 }
01918 
01919 }  // end namespace clang
01920 
01921 // operator new and delete aren't allowed inside namespaces.
01922 
01923 /// @brief Placement new for using the ASTContext's allocator.
01924 ///
01925 /// This placement form of operator new uses the ASTContext's allocator for
01926 /// obtaining memory.
01927 ///
01928 /// IMPORTANT: These are also declared in clang/AST/Attr.h! Any changes here
01929 /// need to also be made there.
01930 ///
01931 /// We intentionally avoid using a nothrow specification here so that the calls
01932 /// to this operator will not perform a null check on the result -- the
01933 /// underlying allocator never returns null pointers.
01934 ///
01935 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
01936 /// @code
01937 /// // Default alignment (8)
01938 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
01939 /// // Specific alignment
01940 /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
01941 /// @endcode
01942 /// Please note that you cannot use delete on the pointer; it must be
01943 /// deallocated using an explicit destructor call followed by
01944 /// @c Context.Deallocate(Ptr).
01945 ///
01946 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
01947 /// @param C The ASTContext that provides the allocator.
01948 /// @param Alignment The alignment of the allocated memory (if the underlying
01949 ///                  allocator supports it).
01950 /// @return The allocated memory. Could be NULL.
01951 inline void *operator new(size_t Bytes, const clang::ASTContext &C,
01952                           size_t Alignment) {
01953   return C.Allocate(Bytes, Alignment);
01954 }
01955 /// @brief Placement delete companion to the new above.
01956 ///
01957 /// This operator is just a companion to the new above. There is no way of
01958 /// invoking it directly; see the new operator for more details. This operator
01959 /// is called implicitly by the compiler if a placement new expression using
01960 /// the ASTContext throws in the object constructor.
01961 inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) {
01962   C.Deallocate(Ptr);
01963 }
01964 
01965 /// This placement form of operator new[] uses the ASTContext's allocator for
01966 /// obtaining memory.
01967 ///
01968 /// We intentionally avoid using a nothrow specification here so that the calls
01969 /// to this operator will not perform a null check on the result -- the
01970 /// underlying allocator never returns null pointers.
01971 ///
01972 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
01973 /// @code
01974 /// // Default alignment (8)
01975 /// char *data = new (Context) char[10];
01976 /// // Specific alignment
01977 /// char *data = new (Context, 4) char[10];
01978 /// @endcode
01979 /// Please note that you cannot use delete on the pointer; it must be
01980 /// deallocated using an explicit destructor call followed by
01981 /// @c Context.Deallocate(Ptr).
01982 ///
01983 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
01984 /// @param C The ASTContext that provides the allocator.
01985 /// @param Alignment The alignment of the allocated memory (if the underlying
01986 ///                  allocator supports it).
01987 /// @return The allocated memory. Could be NULL.
01988 inline void *operator new[](size_t Bytes, const clang::ASTContext& C,
01989                             size_t Alignment = 8) {
01990   return C.Allocate(Bytes, Alignment);
01991 }
01992 
01993 /// @brief Placement delete[] companion to the new[] above.
01994 ///
01995 /// This operator is just a companion to the new[] above. There is no way of
01996 /// invoking it directly; see the new[] operator for more details. This operator
01997 /// is called implicitly by the compiler if a placement new[] expression using
01998 /// the ASTContext throws in the object constructor.
01999 inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) {
02000   C.Deallocate(Ptr);
02001 }
02002 
02003 #endif