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/IdentifierTable.h"
00018 #include "clang/Basic/LangOptions.h"
00019 #include "clang/Basic/OperatorKinds.h"
00020 #include "clang/Basic/PartialDiagnostic.h"
00021 #include "clang/AST/Attr.h"
00022 #include "clang/AST/Decl.h"
00023 #include "clang/AST/NestedNameSpecifier.h"
00024 #include "clang/AST/PrettyPrinter.h"
00025 #include "clang/AST/TemplateName.h"
00026 #include "clang/AST/Type.h"
00027 #include "clang/AST/CanonicalType.h"
00028 #include "clang/AST/UsuallyTinyPtrVector.h"
00029 #include "llvm/ADT/DenseMap.h"
00030 #include "llvm/ADT/FoldingSet.h"
00031 #include "llvm/ADT/OwningPtr.h"
00032 #include "llvm/ADT/SmallPtrSet.h"
00033 #include "llvm/Support/Allocator.h"
00034 #include <vector>
00035 
00036 namespace llvm {
00037   struct fltSemantics;
00038   class raw_ostream;
00039 }
00040 
00041 namespace clang {
00042   class FileManager;
00043   class ASTRecordLayout;
00044   class BlockExpr;
00045   class CharUnits;
00046   class Diagnostic;
00047   class Expr;
00048   class ExternalASTSource;
00049   class IdentifierTable;
00050   class SelectorTable;
00051   class SourceManager;
00052   class TargetInfo;
00053   // Decls
00054   class DeclContext;
00055   class CXXMethodDecl;
00056   class CXXRecordDecl;
00057   class Decl;
00058   class FieldDecl;
00059   class ObjCIvarDecl;
00060   class ObjCIvarRefExpr;
00061   class ObjCPropertyDecl;
00062   class RecordDecl;
00063   class StoredDeclsMap;
00064   class TagDecl;
00065   class TemplateTypeParmDecl;
00066   class TranslationUnitDecl;
00067   class TypeDecl;
00068   class TypedefDecl;
00069   class UsingDecl;
00070   class UsingShadowDecl;
00071   class UnresolvedSetIterator;
00072 
00073   namespace Builtin { class Context; }
00074 
00075 /// ASTContext - This class holds long-lived AST nodes (such as types and
00076 /// decls) that can be referred to throughout the semantic analysis of a file.
00077 class ASTContext {
00078   std::vector<Type*> Types;
00079   llvm::FoldingSet<ExtQuals> ExtQualNodes;
00080   llvm::FoldingSet<ComplexType> ComplexTypes;
00081   llvm::FoldingSet<PointerType> PointerTypes;
00082   llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
00083   llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
00084   llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
00085   llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
00086   llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
00087   llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
00088   std::vector<VariableArrayType*> VariableArrayTypes;
00089   llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
00090   llvm::FoldingSet<DependentSizedExtVectorType> DependentSizedExtVectorTypes;
00091   llvm::FoldingSet<VectorType> VectorTypes;
00092   llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
00093   llvm::FoldingSet<FunctionProtoType> FunctionProtoTypes;
00094   llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
00095   llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
00096   llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
00097   llvm::FoldingSet<SubstTemplateTypeParmType> SubstTemplateTypeParmTypes;
00098   llvm::FoldingSet<TemplateSpecializationType> TemplateSpecializationTypes;
00099   llvm::FoldingSet<QualifiedNameType> QualifiedNameTypes;
00100   llvm::FoldingSet<DependentNameType> DependentNameTypes;
00101   llvm::FoldingSet<ObjCInterfaceType> ObjCInterfaceTypes;
00102   llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
00103   llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
00104 
00105   llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
00106   llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
00107 
00108   /// \brief The set of nested name specifiers.
00109   ///
00110   /// This set is managed by the NestedNameSpecifier class.
00111   llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
00112   NestedNameSpecifier *GlobalNestedNameSpecifier;
00113   friend class NestedNameSpecifier;
00114 
00115   /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
00116   ///  This is lazily created.  This is intentionally not serialized.
00117   llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> ASTRecordLayouts;
00118   llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*> ObjCLayouts;
00119 
00120   /// KeyFunctions - A cache mapping from CXXRecordDecls to key functions.
00121   llvm::DenseMap<const CXXRecordDecl*, const CXXMethodDecl*> KeyFunctions;
00122   
00123   /// \brief Mapping from ObjCContainers to their ObjCImplementations.
00124   llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
00125 
00126   /// BuiltinVaListType - built-in va list type.
00127   /// This is initially null and set by Sema::LazilyCreateBuiltin when
00128   /// a builtin that takes a valist is encountered.
00129   QualType BuiltinVaListType;
00130 
00131   /// ObjCIdType - a pseudo built-in typedef type (set by Sema).
00132   QualType ObjCIdTypedefType;
00133 
00134   /// ObjCSelType - another pseudo built-in typedef type (set by Sema).
00135   QualType ObjCSelTypedefType;
00136 
00137   /// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
00138   QualType ObjCProtoType;
00139   const RecordType *ProtoStructType;
00140 
00141   /// ObjCClassType - another pseudo built-in typedef type (set by Sema).
00142   QualType ObjCClassTypedefType;
00143 
00144   QualType ObjCConstantStringType;
00145   RecordDecl *CFConstantStringTypeDecl;
00146 
00147   RecordDecl *NSConstantStringTypeDecl;
00148 
00149   RecordDecl *ObjCFastEnumerationStateTypeDecl;
00150 
00151   /// \brief The type for the C FILE type.
00152   TypeDecl *FILEDecl;
00153 
00154   /// \brief The type for the C jmp_buf type.
00155   TypeDecl *jmp_bufDecl;
00156 
00157   /// \brief The type for the C sigjmp_buf type.
00158   TypeDecl *sigjmp_bufDecl;
00159 
00160   /// \brief Type for the Block descriptor for Blocks CodeGen.
00161   RecordDecl *BlockDescriptorType;
00162 
00163   /// \brief Type for the Block descriptor for Blocks CodeGen.
00164   RecordDecl *BlockDescriptorExtendedType;
00165 
00166   /// \brief Keeps track of all declaration attributes.
00167   ///
00168   /// Since so few decls have attrs, we keep them in a hash map instead of
00169   /// wasting space in the Decl class.
00170   llvm::DenseMap<const Decl*, Attr*> DeclAttrs;
00171 
00172   /// \brief Keeps track of the static data member templates from which
00173   /// static data members of class template specializations were instantiated.
00174   ///
00175   /// This data structure stores the mapping from instantiations of static
00176   /// data members to the static data member representations within the
00177   /// class template from which they were instantiated along with the kind
00178   /// of instantiation or specialization (a TemplateSpecializationKind - 1).
00179   ///
00180   /// Given the following example:
00181   ///
00182   /// \code
00183   /// template<typename T>
00184   /// struct X {
00185   ///   static T value;
00186   /// };
00187   ///
00188   /// template<typename T>
00189   ///   T X<T>::value = T(17);
00190   ///
00191   /// int *x = &X<int>::value;
00192   /// \endcode
00193   ///
00194   /// This mapping will contain an entry that maps from the VarDecl for
00195   /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
00196   /// class template X) and will be marked TSK_ImplicitInstantiation.
00197   llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *> 
00198     InstantiatedFromStaticDataMember;
00199 
00200   /// \brief Keeps track of the declaration from which a UsingDecl was
00201   /// created during instantiation.  The source declaration is always
00202   /// a UsingDecl, an UnresolvedUsingValueDecl, or an
00203   /// UnresolvedUsingTypenameDecl.
00204   ///
00205   /// For example:
00206   /// \code
00207   /// template<typename T>
00208   /// struct A {
00209   ///   void f();
00210   /// };
00211   ///
00212   /// template<typename T>
00213   /// struct B : A<T> {
00214   ///   using A<T>::f;
00215   /// };
00216   ///
00217   /// template struct B<int>;
00218   /// \endcode
00219   ///
00220   /// This mapping will contain an entry that maps from the UsingDecl in
00221   /// B<int> to the UnresolvedUsingDecl in B<T>.
00222   llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl;
00223 
00224   llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
00225     InstantiatedFromUsingShadowDecl;
00226 
00227   llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
00228 
00229   /// \brief Mapping that stores the methods overridden by a given C++
00230   /// member function.
00231   ///
00232   /// Since most C++ member functions aren't virtual and therefore
00233   /// don't override anything, we store the overridden functions in
00234   /// this map on the side rather than within the CXXMethodDecl structure.
00235   typedef UsuallyTinyPtrVector<const CXXMethodDecl> CXXMethodVector;
00236   llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
00237 
00238   TranslationUnitDecl *TUDecl;
00239 
00240   /// SourceMgr - The associated SourceManager object.
00241   SourceManager &SourceMgr;
00242 
00243   /// LangOpts - The language options used to create the AST associated with
00244   ///  this ASTContext object.
00245   LangOptions LangOpts;
00246 
00247   /// MallocAlloc/BumpAlloc - The allocator objects used to create AST objects.
00248   bool FreeMemory;
00249   llvm::MallocAllocator MallocAlloc;
00250   llvm::BumpPtrAllocator BumpAlloc;
00251 
00252   /// \brief Allocator for partial diagnostics.
00253   PartialDiagnostic::StorageAllocator DiagAllocator;
00254   
00255 public:
00256   const TargetInfo &Target;
00257   IdentifierTable &Idents;
00258   SelectorTable &Selectors;
00259   Builtin::Context &BuiltinInfo;
00260   DeclarationNameTable DeclarationNames;
00261   llvm::OwningPtr<ExternalASTSource> ExternalSource;
00262   clang::PrintingPolicy PrintingPolicy;
00263 
00264   // Typedefs which may be provided defining the structure of Objective-C
00265   // pseudo-builtins
00266   QualType ObjCIdRedefinitionType;
00267   QualType ObjCClassRedefinitionType;
00268   QualType ObjCSelRedefinitionType;
00269 
00270   SourceManager& getSourceManager() { return SourceMgr; }
00271   const SourceManager& getSourceManager() const { return SourceMgr; }
00272   void *Allocate(unsigned Size, unsigned Align = 8) {
00273     return FreeMemory ? MallocAlloc.Allocate(Size, Align) :
00274                         BumpAlloc.Allocate(Size, Align);
00275   }
00276   void Deallocate(void *Ptr) {
00277     if (FreeMemory)
00278       MallocAlloc.Deallocate(Ptr);
00279   }
00280   
00281   PartialDiagnostic::StorageAllocator &getDiagAllocator() {
00282     return DiagAllocator;
00283   }
00284 
00285   const LangOptions& getLangOptions() const { return LangOpts; }
00286 
00287   FullSourceLoc getFullLoc(SourceLocation Loc) const {
00288     return FullSourceLoc(Loc,SourceMgr);
00289   }
00290 
00291   /// \brief Retrieve the attributes for the given declaration.
00292   Attr*& getDeclAttrs(const Decl *D) { return DeclAttrs[D]; }
00293 
00294   /// \brief Erase the attributes corresponding to the given declaration.
00295   void eraseDeclAttrs(const Decl *D) { DeclAttrs.erase(D); }
00296 
00297   /// \brief If this variable is an instantiated static data member of a
00298   /// class template specialization, returns the templated static data member
00299   /// from which it was instantiated.
00300   MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
00301                                                            const VarDecl *Var);
00302 
00303   /// \brief Note that the static data member \p Inst is an instantiation of
00304   /// the static data member template \p Tmpl of a class template.
00305   void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
00306                                            TemplateSpecializationKind TSK);
00307 
00308   /// \brief If the given using decl is an instantiation of a
00309   /// (possibly unresolved) using decl from a template instantiation,
00310   /// return it.
00311   NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
00312 
00313   /// \brief Remember that the using decl \p Inst is an instantiation
00314   /// of the using decl \p Pattern of a class template.
00315   void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
00316 
00317   void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
00318                                           UsingShadowDecl *Pattern);
00319   UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
00320 
00321   FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
00322 
00323   void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
00324 
00325   // Access to the set of methods overridden by the given C++ method.
00326   typedef CXXMethodVector::iterator overridden_cxx_method_iterator;
00327   overridden_cxx_method_iterator
00328   overridden_methods_begin(const CXXMethodDecl *Method) const;
00329 
00330   overridden_cxx_method_iterator
00331   overridden_methods_end(const CXXMethodDecl *Method) const;
00332 
00333   /// \brief Note that the given C++ \p Method overrides the given \p
00334   /// Overridden method.
00335   void addOverriddenMethod(const CXXMethodDecl *Method, 
00336                            const CXXMethodDecl *Overridden);
00337   
00338   TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
00339 
00340 
00341   // Builtin Types.
00342   CanQualType VoidTy;
00343   CanQualType BoolTy;
00344   CanQualType CharTy;
00345   CanQualType WCharTy;  // [C++ 3.9.1p5], integer type in C99.
00346   CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
00347   CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
00348   CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
00349   CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
00350   CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
00351   CanQualType FloatTy, DoubleTy, LongDoubleTy;
00352   CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
00353   CanQualType VoidPtrTy, NullPtrTy;
00354   CanQualType OverloadTy;
00355   CanQualType DependentTy;
00356   CanQualType UndeducedAutoTy;
00357   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
00358 
00359   ASTContext(const LangOptions& LOpts, SourceManager &SM, const TargetInfo &t,
00360              IdentifierTable &idents, SelectorTable &sels,
00361              Builtin::Context &builtins,
00362              bool FreeMemory = true, unsigned size_reserve=0);
00363 
00364   ~ASTContext();
00365 
00366   /// \brief Attach an external AST source to the AST context.
00367   ///
00368   /// The external AST source provides the ability to load parts of
00369   /// the abstract syntax tree as needed from some external storage,
00370   /// e.g., a precompiled header.
00371   void setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source);
00372 
00373   /// \brief Retrieve a pointer to the external AST source associated
00374   /// with this AST context, if any.
00375   ExternalASTSource *getExternalSource() const { return ExternalSource.get(); }
00376 
00377   void PrintStats() const;
00378   const std::vector<Type*>& getTypes() const { return Types; }
00379 
00380   //===--------------------------------------------------------------------===//
00381   //                           Type Constructors
00382   //===--------------------------------------------------------------------===//
00383 
00384 private:
00385   /// getExtQualType - Return a type with extended qualifiers.
00386   QualType getExtQualType(const Type *Base, Qualifiers Quals);
00387 
00388   QualType getTypeDeclTypeSlow(const TypeDecl *Decl);
00389 
00390 public:
00391   /// getAddSpaceQualType - Return the uniqued reference to the type for an
00392   /// address space qualified type with the specified type and address space.
00393   /// The resulting type has a union of the qualifiers from T and the address
00394   /// space. If T already has an address space specifier, it is silently
00395   /// replaced.
00396   QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace);
00397 
00398   /// getObjCGCQualType - Returns the uniqued reference to the type for an
00399   /// objc gc qualified type. The retulting type has a union of the qualifiers
00400   /// from T and the gc attribute.
00401   QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr);
00402 
00403   /// getRestrictType - Returns the uniqued reference to the type for a
00404   /// 'restrict' qualified type.  The resulting type has a union of the
00405   /// qualifiers from T and 'restrict'.
00406   QualType getRestrictType(QualType T) {
00407     return T.withFastQualifiers(Qualifiers::Restrict);
00408   }
00409 
00410   /// getVolatileType - Returns the uniqued reference to the type for a
00411   /// 'volatile' qualified type.  The resulting type has a union of the
00412   /// qualifiers from T and 'volatile'.
00413   QualType getVolatileType(QualType T);
00414 
00415   /// getConstType - Returns the uniqued reference to the type for a
00416   /// 'const' qualified type.  The resulting type has a union of the
00417   /// qualifiers from T and 'const'.
00418   ///
00419   /// It can be reasonably expected that this will always be
00420   /// equivalent to calling T.withConst().
00421   QualType getConstType(QualType T) { return T.withConst(); }
00422 
00423   /// getNoReturnType - Add or remove the noreturn attribute to the given type 
00424   /// which must be a FunctionType or a pointer to an allowable type or a 
00425   /// BlockPointer.
00426   QualType getNoReturnType(QualType T, bool AddNoReturn = true);
00427 
00428   /// getCallConvType - Adds the specified calling convention attribute to
00429   /// the given type, which must be a FunctionType or a pointer to an
00430   /// allowable type.
00431   QualType getCallConvType(QualType T, CallingConv CallConv);
00432 
00433   /// getRegParmType - Sets the specified regparm attribute to
00434   /// the given type, which must be a FunctionType or a pointer to an
00435   /// allowable type.
00436   QualType getRegParmType(QualType T, unsigned RegParm);
00437 
00438   /// getComplexType - Return the uniqued reference to the type for a complex
00439   /// number with the specified element type.
00440   QualType getComplexType(QualType T);
00441   CanQualType getComplexType(CanQualType T) {
00442     return CanQualType::CreateUnsafe(getComplexType((QualType) T));
00443   }
00444 
00445   /// getPointerType - Return the uniqued reference to the type for a pointer to
00446   /// the specified type.
00447   QualType getPointerType(QualType T);
00448   CanQualType getPointerType(CanQualType T) {
00449     return CanQualType::CreateUnsafe(getPointerType((QualType) T));
00450   }
00451 
00452   /// getBlockPointerType - Return the uniqued reference to the type for a block
00453   /// of the specified type.
00454   QualType getBlockPointerType(QualType T);
00455 
00456   /// This gets the struct used to keep track of the descriptor for pointer to
00457   /// blocks.
00458   QualType getBlockDescriptorType();
00459 
00460   // Set the type for a Block descriptor type.
00461   void setBlockDescriptorType(QualType T);
00462   /// Get the BlockDescriptorType type, or NULL if it hasn't yet been built.
00463   QualType getRawBlockdescriptorType() {
00464     if (BlockDescriptorType)
00465       return getTagDeclType(BlockDescriptorType);
00466     return QualType();
00467   }
00468 
00469   /// This gets the struct used to keep track of the extended descriptor for
00470   /// pointer to blocks.
00471   QualType getBlockDescriptorExtendedType();
00472 
00473   // Set the type for a Block descriptor extended type.
00474   void setBlockDescriptorExtendedType(QualType T);
00475   /// Get the BlockDescriptorExtendedType type, or NULL if it hasn't yet been
00476   /// built.
00477   QualType getRawBlockdescriptorExtendedType() {
00478     if (BlockDescriptorExtendedType)
00479       return getTagDeclType(BlockDescriptorExtendedType);
00480     return QualType();
00481   }
00482 
00483   /// This gets the struct used to keep track of pointer to blocks, complete
00484   /// with captured variables.
00485   QualType getBlockParmType(bool BlockHasCopyDispose,
00486                             llvm::SmallVector<const Expr *, 8> &BDRDs);
00487 
00488   /// This builds the struct used for __block variables.
00489   QualType BuildByRefType(const char *DeclName, QualType Ty);
00490 
00491   /// Returns true iff we need copy/dispose helpers for the given type.
00492   bool BlockRequiresCopying(QualType Ty);
00493 
00494   /// getLValueReferenceType - Return the uniqued reference to the type for an
00495   /// lvalue reference to the specified type.
00496   QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true);
00497 
00498   /// getRValueReferenceType - Return the uniqued reference to the type for an
00499   /// rvalue reference to the specified type.
00500   QualType getRValueReferenceType(QualType T);
00501 
00502   /// getMemberPointerType - Return the uniqued reference to the type for a
00503   /// member pointer to the specified type in the specified class. The class
00504   /// is a Type because it could be a dependent name.
00505   QualType getMemberPointerType(QualType T, const Type *Cls);
00506 
00507   /// getVariableArrayType - Returns a non-unique reference to the type for a
00508   /// variable array of the specified element type.
00509   QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
00510                                 ArrayType::ArraySizeModifier ASM,
00511                                 unsigned EltTypeQuals,
00512                                 SourceRange Brackets);
00513 
00514   /// getDependentSizedArrayType - Returns a non-unique reference to
00515   /// the type for a dependently-sized array of the specified element
00516   /// type. FIXME: We will need these to be uniqued, or at least
00517   /// comparable, at some point.
00518   QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
00519                                       ArrayType::ArraySizeModifier ASM,
00520                                       unsigned EltTypeQuals,
00521                                       SourceRange Brackets);
00522 
00523   /// getIncompleteArrayType - Returns a unique reference to the type for a
00524   /// incomplete array of the specified element type.
00525   QualType getIncompleteArrayType(QualType EltTy,
00526                                   ArrayType::ArraySizeModifier ASM,
00527                                   unsigned EltTypeQuals);
00528 
00529   /// getConstantArrayType - Return the unique reference to the type for a
00530   /// constant array of the specified element type.
00531   QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
00532                                 ArrayType::ArraySizeModifier ASM,
00533                                 unsigned EltTypeQuals);
00534 
00535   /// getVectorType - Return the unique reference to a vector type of
00536   /// the specified element type and size. VectorType must be a built-in type.
00537   QualType getVectorType(QualType VectorType, unsigned NumElts,
00538                          bool AltiVec, bool IsPixel);
00539 
00540   /// getExtVectorType - Return the unique reference to an extended vector type
00541   /// of the specified element type and size.  VectorType must be a built-in
00542   /// type.
00543   QualType getExtVectorType(QualType VectorType, unsigned NumElts);
00544 
00545   /// getDependentSizedExtVectorType - Returns a non-unique reference to
00546   /// the type for a dependently-sized vector of the specified element
00547   /// type. FIXME: We will need these to be uniqued, or at least
00548   /// comparable, at some point.
00549   QualType getDependentSizedExtVectorType(QualType VectorType,
00550                                           Expr *SizeExpr,
00551                                           SourceLocation AttrLoc);
00552 
00553   /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'.
00554   ///
00555   QualType getFunctionNoProtoType(QualType ResultTy,
00556                                   const FunctionType::ExtInfo &Info);
00557 
00558   QualType getFunctionNoProtoType(QualType ResultTy) {
00559     return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo());
00560   }
00561 
00562   /// getFunctionType - Return a normal function type with a typed argument
00563   /// list.  isVariadic indicates whether the argument list includes '...'.
00564   QualType getFunctionType(QualType ResultTy, const QualType *ArgArray,
00565                            unsigned NumArgs, bool isVariadic,
00566                            unsigned TypeQuals, bool hasExceptionSpec,
00567                            bool hasAnyExceptionSpec,
00568                            unsigned NumExs, const QualType *ExArray,
00569                            const FunctionType::ExtInfo &Info);
00570 
00571   /// getTypeDeclType - Return the unique reference to the type for
00572   /// the specified type declaration.
00573   QualType getTypeDeclType(const TypeDecl *Decl,
00574                            const TypeDecl *PrevDecl = 0) {
00575     assert(Decl && "Passed null for Decl param");
00576     if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
00577 
00578     if (PrevDecl) {
00579       assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
00580       Decl->TypeForDecl = PrevDecl->TypeForDecl;
00581       return QualType(PrevDecl->TypeForDecl, 0);
00582     }
00583 
00584     return getTypeDeclTypeSlow(Decl);
00585   }
00586 
00587   /// getTypedefType - Return the unique reference to the type for the
00588   /// specified typename decl.
00589   QualType getTypedefType(const TypedefDecl *Decl);
00590 
00591   QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST);
00592 
00593   QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
00594                                         QualType Replacement);
00595 
00596   QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
00597                                    bool ParameterPack,
00598                                    IdentifierInfo *Name = 0);
00599 
00600   QualType getTemplateSpecializationType(TemplateName T,
00601                                          const TemplateArgument *Args,
00602                                          unsigned NumArgs,
00603                                          QualType Canon = QualType(),
00604                                          bool IsCurrentInstantiation = false);
00605 
00606   QualType getTemplateSpecializationType(TemplateName T,
00607                                          const TemplateArgumentListInfo &Args,
00608                                          QualType Canon = QualType(),
00609                                          bool IsCurrentInstantiation = false);
00610 
00611   TypeSourceInfo *
00612   getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc,
00613                                     const TemplateArgumentListInfo &Args,
00614                                     QualType Canon = QualType());
00615 
00616   QualType getQualifiedNameType(NestedNameSpecifier *NNS,
00617                                 QualType NamedType);
00618   QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
00619                                 NestedNameSpecifier *NNS,
00620                                 const IdentifierInfo *Name,
00621                                 QualType Canon = QualType());
00622   QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
00623                                 NestedNameSpecifier *NNS,
00624                                 const TemplateSpecializationType *TemplateId,
00625                                 QualType Canon = QualType());
00626   QualType getElaboratedType(QualType UnderlyingType,
00627                              ElaboratedType::TagKind Tag);
00628 
00629   QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
00630                                 ObjCProtocolDecl **Protocols = 0,
00631                                 unsigned NumProtocols = 0);
00632 
00633   /// getObjCObjectPointerType - Return a ObjCObjectPointerType type for the
00634   /// given interface decl and the conforming protocol list.
00635   QualType getObjCObjectPointerType(QualType OIT,
00636                                     ObjCProtocolDecl **ProtocolList = 0,
00637                                     unsigned NumProtocols = 0,
00638                                     unsigned Quals = 0);
00639 
00640   /// getTypeOfType - GCC extension.
00641   QualType getTypeOfExprType(Expr *e);
00642   QualType getTypeOfType(QualType t);
00643 
00644   /// getDecltypeType - C++0x decltype.
00645   QualType getDecltypeType(Expr *e);
00646 
00647   /// getTagDeclType - Return the unique reference to the type for the
00648   /// specified TagDecl (struct/union/class/enum) decl.
00649   QualType getTagDeclType(const TagDecl *Decl);
00650 
00651   /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
00652   /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
00653   CanQualType getSizeType() const;
00654 
00655   /// getWCharType - In C++, this returns the unique wchar_t type.  In C99, this
00656   /// returns a type compatible with the type defined in <stddef.h> as defined
00657   /// by the target.
00658   QualType getWCharType() const { return WCharTy; }
00659 
00660   /// getSignedWCharType - Return the type of "signed wchar_t".
00661   /// Used when in C++, as a GCC extension.
00662   QualType getSignedWCharType() const;
00663 
00664   /// getUnsignedWCharType - Return the type of "unsigned wchar_t".
00665   /// Used when in C++, as a GCC extension.
00666   QualType getUnsignedWCharType() const;
00667 
00668   /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
00669   /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
00670   QualType getPointerDiffType() const;
00671 
00672   // getCFConstantStringType - Return the C structure type used to represent
00673   // constant CFStrings.
00674   QualType getCFConstantStringType();
00675 
00676   // getNSConstantStringType - Return the C structure type used to represent
00677   // constant NSStrings.
00678   QualType getNSConstantStringType();
00679   /// Get the structure type used to representation NSStrings, or NULL
00680   /// if it hasn't yet been built.
00681   QualType getRawNSConstantStringType() {
00682     if (NSConstantStringTypeDecl)
00683       return getTagDeclType(NSConstantStringTypeDecl);
00684     return QualType();
00685   }
00686   void setNSConstantStringType(QualType T);
00687 
00688 
00689   /// Get the structure type used to representation CFStrings, or NULL
00690   /// if it hasn't yet been built.
00691   QualType getRawCFConstantStringType() {
00692     if (CFConstantStringTypeDecl)
00693       return getTagDeclType(CFConstantStringTypeDecl);
00694     return QualType();
00695   }
00696   void setCFConstantStringType(QualType T);
00697 
00698   // This setter/getter represents the ObjC type for an NSConstantString.
00699   void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
00700   QualType getObjCConstantStringInterface() const {
00701     return ObjCConstantStringType;
00702   }
00703 
00704   //// This gets the struct used to keep track of fast enumerations.
00705   QualType getObjCFastEnumerationStateType();
00706 
00707   /// Get the ObjCFastEnumerationState type, or NULL if it hasn't yet
00708   /// been built.
00709   QualType getRawObjCFastEnumerationStateType() {
00710     if (ObjCFastEnumerationStateTypeDecl)
00711       return getTagDeclType(ObjCFastEnumerationStateTypeDecl);
00712     return QualType();
00713   }
00714 
00715   void setObjCFastEnumerationStateType(QualType T);
00716 
00717   /// \brief Set the type for the C FILE type.
00718   void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
00719 
00720   /// \brief Retrieve the C FILE type.
00721   QualType getFILEType() {
00722     if (FILEDecl)
00723       return getTypeDeclType(FILEDecl);
00724     return QualType();
00725   }
00726 
00727   /// \brief Set the type for the C jmp_buf type.
00728   void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
00729     this->jmp_bufDecl = jmp_bufDecl;
00730   }
00731 
00732   /// \brief Retrieve the C jmp_buf type.
00733   QualType getjmp_bufType() {
00734     if (jmp_bufDecl)
00735       return getTypeDeclType(jmp_bufDecl);
00736     return QualType();
00737   }
00738 
00739   /// \brief Set the type for the C sigjmp_buf type.
00740   void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
00741     this->sigjmp_bufDecl = sigjmp_bufDecl;
00742   }
00743 
00744   /// \brief Retrieve the C sigjmp_buf type.
00745   QualType getsigjmp_bufType() {
00746     if (sigjmp_bufDecl)
00747       return getTypeDeclType(sigjmp_bufDecl);
00748     return QualType();
00749   }
00750 
00751   /// getObjCEncodingForType - Emit the ObjC type encoding for the
00752   /// given type into \arg S. If \arg NameFields is specified then
00753   /// record field names are also encoded.
00754   void getObjCEncodingForType(QualType t, std::string &S,
00755                               const FieldDecl *Field=0);
00756 
00757   void getLegacyIntegralTypeEncoding(QualType &t) const;
00758 
00759   // Put the string version of type qualifiers into S.
00760   void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
00761                                        std::string &S) const;
00762 
00763   /// getObjCEncodingForMethodDecl - Return the encoded type for this method
00764   /// declaration.
00765   void getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S);
00766 
00767   /// getObjCEncodingForBlockDecl - Return the encoded type for this block
00768   /// declaration.
00769   void getObjCEncodingForBlock(const BlockExpr *Expr, std::string& S);
00770   
00771   /// getObjCEncodingForPropertyDecl - Return the encoded type for
00772   /// this method declaration. If non-NULL, Container must be either
00773   /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
00774   /// only be NULL when getting encodings for protocol properties.
00775   void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
00776                                       const Decl *Container,
00777                                       std::string &S);
00778 
00779   bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
00780                                       ObjCProtocolDecl *rProto);
00781 
00782   /// getObjCEncodingTypeSize returns size of type for objective-c encoding
00783   /// purpose in characters.
00784   CharUnits getObjCEncodingTypeSize(QualType t);
00785 
00786   /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by
00787   /// Sema.  id is always a (typedef for a) pointer type, a pointer to a struct.
00788   QualType getObjCIdType() const { return ObjCIdTypedefType; }
00789   void setObjCIdType(QualType T);
00790 
00791   void setObjCSelType(QualType T);
00792   QualType getObjCSelType() const { return ObjCSelTypedefType; }
00793 
00794   void setObjCProtoType(QualType QT);
00795   QualType getObjCProtoType() const { return ObjCProtoType; }
00796 
00797   /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
00798   /// Sema.  'Class' is always a (typedef for a) pointer type, a pointer to a
00799   /// struct.
00800   QualType getObjCClassType() const { return ObjCClassTypedefType; }
00801   void setObjCClassType(QualType T);
00802 
00803   void setBuiltinVaListType(QualType T);
00804   QualType getBuiltinVaListType() const { return BuiltinVaListType; }
00805 
00806   /// getCVRQualifiedType - Returns a type with additional const,
00807   /// volatile, or restrict qualifiers.
00808   QualType getCVRQualifiedType(QualType T, unsigned CVR) {
00809     return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
00810   }
00811 
00812   /// getQualifiedType - Returns a type with additional qualifiers.
00813   QualType getQualifiedType(QualType T, Qualifiers Qs) {
00814     if (!Qs.hasNonFastQualifiers())
00815       return T.withFastQualifiers(Qs.getFastQualifiers());
00816     QualifierCollector Qc(Qs);
00817     const Type *Ptr = Qc.strip(T);
00818     return getExtQualType(Ptr, Qc);
00819   }
00820 
00821   /// getQualifiedType - Returns a type with additional qualifiers.
00822   QualType getQualifiedType(const Type *T, Qualifiers Qs) {
00823     if (!Qs.hasNonFastQualifiers())
00824       return QualType(T, Qs.getFastQualifiers());
00825     return getExtQualType(T, Qs);
00826   }
00827 
00828   DeclarationName getNameForTemplate(TemplateName Name);
00829 
00830   TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
00831                                          UnresolvedSetIterator End);
00832 
00833   TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
00834                                         bool TemplateKeyword,
00835                                         TemplateDecl *Template);
00836 
00837   TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
00838                                         const IdentifierInfo *Name);
00839   TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
00840                                         OverloadedOperatorKind Operator);
00841 
00842   enum GetBuiltinTypeError {
00843     GE_None,              //< No error
00844     GE_Missing_stdio,     //< Missing a type from <stdio.h>
00845     GE_Missing_setjmp     //< Missing a type from <setjmp.h>
00846   };
00847 
00848   /// GetBuiltinType - Return the type for the specified builtin.
00849   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error);
00850 
00851 private:
00852   CanQualType getFromTargetType(unsigned Type) const;
00853 
00854   //===--------------------------------------------------------------------===//
00855   //                         Type Predicates.
00856   //===--------------------------------------------------------------------===//
00857 
00858 public:
00859   /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
00860   /// garbage collection attribute.
00861   ///
00862   Qualifiers::GC getObjCGCAttrKind(const QualType &Ty) const;
00863 
00864   /// isObjCNSObjectType - Return true if this is an NSObject object with
00865   /// its NSObject attribute set.
00866   bool isObjCNSObjectType(QualType Ty) const;
00867 
00868   //===--------------------------------------------------------------------===//
00869   //                         Type Sizing and Analysis
00870   //===--------------------------------------------------------------------===//
00871 
00872   /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified
00873   /// scalar floating point type.
00874   const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
00875 
00876   /// getTypeInfo - Get the size and alignment of the specified complete type in
00877   /// bits.
00878   std::pair<uint64_t, unsigned> getTypeInfo(const Type *T);
00879   std::pair<uint64_t, unsigned> getTypeInfo(QualType T) {
00880     return getTypeInfo(T.getTypePtr());
00881   }
00882 
00883   /// getTypeSize - Return the size of the specified type, in bits.  This method
00884   /// does not work on incomplete types.
00885   uint64_t getTypeSize(QualType T) {
00886     return getTypeInfo(T).first;
00887   }
00888   uint64_t getTypeSize(const Type *T) {
00889     return getTypeInfo(T).first;
00890   }
00891 
00892   /// getCharWidth - Return the size of the character type, in bits
00893   uint64_t getCharWidth() {
00894     return getTypeSize(CharTy);
00895   }
00896   
00897   /// getTypeSizeInChars - Return the size of the specified type, in characters.
00898   /// This method does not work on incomplete types.
00899   CharUnits getTypeSizeInChars(QualType T);
00900   CharUnits getTypeSizeInChars(const Type *T);
00901 
00902   /// getTypeAlign - Return the ABI-specified alignment of a type, in bits.
00903   /// This method does not work on incomplete types.
00904   unsigned getTypeAlign(QualType T) {
00905     return getTypeInfo(T).second;
00906   }
00907   unsigned getTypeAlign(const Type *T) {
00908     return getTypeInfo(T).second;
00909   }
00910 
00911   /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in 
00912   /// characters. This method does not work on incomplete types.
00913   CharUnits getTypeAlignInChars(QualType T);
00914   CharUnits getTypeAlignInChars(const Type *T);
00915 
00916   /// getPreferredTypeAlign - Return the "preferred" alignment of the specified
00917   /// type for the current target in bits.  This can be different than the ABI
00918   /// alignment in cases where it is beneficial for performance to overalign
00919   /// a data type.
00920   unsigned getPreferredTypeAlign(const Type *T);
00921 
00922   /// getDeclAlign - Return a conservative estimate of the alignment of
00923   /// the specified decl.  Note that bitfields do not have a valid alignment, so
00924   /// this method will assert on them.
00925   /// If @p RefAsPointee, references are treated like their underlying type
00926   /// (for alignof), else they're treated like pointers (for CodeGen).
00927   CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false);
00928 
00929   /// getASTRecordLayout - Get or compute information about the layout of the
00930   /// specified record (struct/union/class), which indicates its size and field
00931   /// position information.
00932   const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D);
00933 
00934   /// getASTObjCInterfaceLayout - Get or compute information about the
00935   /// layout of the specified Objective-C interface.
00936   const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D);
00937 
00938   void DumpRecordLayout(const RecordDecl *RD, llvm::raw_ostream &OS);
00939 
00940   /// getASTObjCImplementationLayout - Get or compute information about
00941   /// the layout of the specified Objective-C implementation. This may
00942   /// differ from the interface if synthesized ivars are present.
00943   const ASTRecordLayout &
00944   getASTObjCImplementationLayout(const ObjCImplementationDecl *D);
00945 
00946   /// getKeyFunction - Get the key function for the given record decl. 
00947   /// The key function is, according to the Itanium C++ ABI section 5.2.3:
00948   ///
00949   /// ...the first non-pure virtual function that is not inline at the point
00950   /// of class definition.
00951   const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD);
00952 
00953   void CollectObjCIvars(const ObjCInterfaceDecl *OI,
00954                         llvm::SmallVectorImpl<FieldDecl*> &Fields);
00955 
00956   void ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
00957                                llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
00958   void CollectNonClassIvars(const ObjCInterfaceDecl *OI,
00959                                llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
00960   unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI);
00961   void CollectInheritedProtocols(const Decl *CDecl,
00962                           llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
00963 
00964   //===--------------------------------------------------------------------===//
00965   //                            Type Operators
00966   //===--------------------------------------------------------------------===//
00967 
00968   /// getCanonicalType - Return the canonical (structural) type corresponding to
00969   /// the specified potentially non-canonical type.  The non-canonical version
00970   /// of a type may have many "decorated" versions of types.  Decorators can
00971   /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
00972   /// to be free of any of these, allowing two canonical types to be compared
00973   /// for exact equality with a simple pointer comparison.
00974   CanQualType getCanonicalType(QualType T);
00975   const Type *getCanonicalType(const Type *T) {
00976     return T->getCanonicalTypeInternal().getTypePtr();
00977   }
00978 
00979   /// getCanonicalParamType - Return the canonical parameter type
00980   /// corresponding to the specific potentially non-canonical one.
00981   /// Qualifiers are stripped off, functions are turned into function
00982   /// pointers, and arrays decay one level into pointers.
00983   CanQualType getCanonicalParamType(QualType T);
00984 
00985   /// \brief Determine whether the given types are equivalent.
00986   bool hasSameType(QualType T1, QualType T2) {
00987     return getCanonicalType(T1) == getCanonicalType(T2);
00988   }
00989 
00990   /// \brief Returns this type as a completely-unqualified array type,
00991   /// capturing the qualifiers in Quals. This will remove the minimal amount of
00992   /// sugaring from the types, similar to the behavior of
00993   /// QualType::getUnqualifiedType().
00994   ///
00995   /// \param T is the qualified type, which may be an ArrayType
00996   ///
00997   /// \param Quals will receive the full set of qualifiers that were
00998   /// applied to the array.
00999   ///
01000   /// \returns if this is an array type, the completely unqualified array type
01001   /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
01002   QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
01003 
01004   /// \brief Determine whether the given types are equivalent after
01005   /// cvr-qualifiers have been removed.
01006   bool hasSameUnqualifiedType(QualType T1, QualType T2) {
01007     CanQualType CT1 = getCanonicalType(T1);
01008     CanQualType CT2 = getCanonicalType(T2);
01009 
01010     Qualifiers Quals;
01011     QualType UnqualT1 = getUnqualifiedArrayType(CT1, Quals);
01012     QualType UnqualT2 = getUnqualifiedArrayType(CT2, Quals);
01013     return UnqualT1 == UnqualT2;
01014   }
01015 
01016   /// \brief Retrieves the "canonical" declaration of
01017 
01018   /// \brief Retrieves the "canonical" nested name specifier for a
01019   /// given nested name specifier.
01020   ///
01021   /// The canonical nested name specifier is a nested name specifier
01022   /// that uniquely identifies a type or namespace within the type
01023   /// system. For example, given:
01024   ///
01025   /// \code
01026   /// namespace N {
01027   ///   struct S {
01028   ///     template<typename T> struct X { typename T* type; };
01029   ///   };
01030   /// }
01031   ///
01032   /// template<typename T> struct Y {
01033   ///   typename N::S::X<T>::type member;
01034   /// };
01035   /// \endcode
01036   ///
01037   /// Here, the nested-name-specifier for N::S::X<T>:: will be
01038   /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined
01039   /// by declarations in the type system and the canonical type for
01040   /// the template type parameter 'T' is template-param-0-0.
01041   NestedNameSpecifier *
01042   getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS);
01043 
01044   /// \brief Retrieves the canonical representation of the given
01045   /// calling convention.
01046   CallingConv getCanonicalCallConv(CallingConv CC) {
01047     if (CC == CC_C)
01048       return CC_Default;
01049     return CC;
01050   }
01051 
01052   /// \brief Determines whether two calling conventions name the same
01053   /// calling convention.
01054   bool isSameCallConv(CallingConv lcc, CallingConv rcc) {
01055     return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc));
01056   }
01057 
01058   /// \brief Retrieves the "canonical" template name that refers to a
01059   /// given template.
01060   ///
01061   /// The canonical template name is the simplest expression that can
01062   /// be used to refer to a given template. For most templates, this
01063   /// expression is just the template declaration itself. For example,
01064   /// the template std::vector can be referred to via a variety of
01065   /// names---std::vector, ::std::vector, vector (if vector is in
01066   /// scope), etc.---but all of these names map down to the same
01067   /// TemplateDecl, which is used to form the canonical template name.
01068   ///
01069   /// Dependent template names are more interesting. Here, the
01070   /// template name could be something like T::template apply or
01071   /// std::allocator<T>::template rebind, where the nested name
01072   /// specifier itself is dependent. In this case, the canonical
01073   /// template name uses the shortest form of the dependent
01074   /// nested-name-specifier, which itself contains all canonical
01075   /// types, values, and templates.
01076   TemplateName getCanonicalTemplateName(TemplateName Name);
01077 
01078   /// \brief Determine whether the given template names refer to the same
01079   /// template.
01080   bool hasSameTemplateName(TemplateName X, TemplateName Y);
01081   
01082   /// \brief Retrieve the "canonical" template argument.
01083   ///
01084   /// The canonical template argument is the simplest template argument
01085   /// (which may be a type, value, expression, or declaration) that
01086   /// expresses the value of the argument.
01087   TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg);
01088 
01089   /// Type Query functions.  If the type is an instance of the specified class,
01090   /// return the Type pointer for the underlying maximally pretty type.  This
01091   /// is a member of ASTContext because this may need to do some amount of
01092   /// canonicalization, e.g. to move type qualifiers into the element type.
01093   const ArrayType *getAsArrayType(QualType T);
01094   const ConstantArrayType *getAsConstantArrayType(QualType T) {
01095     return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
01096   }
01097   const VariableArrayType *getAsVariableArrayType(QualType T) {
01098     return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
01099   }
01100   const IncompleteArrayType *getAsIncompleteArrayType(QualType T) {
01101     return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
01102   }
01103   const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T) {
01104     return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
01105   }
01106   
01107   /// getBaseElementType - Returns the innermost element type of an array type.
01108   /// For example, will return "int" for int[m][n]
01109   QualType getBaseElementType(const ArrayType *VAT);
01110 
01111   /// getBaseElementType - Returns the innermost element type of a type
01112   /// (which needn't actually be an array type).
01113   QualType getBaseElementType(QualType QT);
01114 
01115   /// getConstantArrayElementCount - Returns number of constant array elements.
01116   uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
01117 
01118   /// getArrayDecayedType - Return the properly qualified result of decaying the
01119   /// specified array type to a pointer.  This operation is non-trivial when
01120   /// handling typedefs etc.  The canonical type of "T" must be an array type,
01121   /// this returns a pointer to a properly qualified element of the array.
01122   ///
01123   /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
01124   QualType getArrayDecayedType(QualType T);
01125 
01126   /// getPromotedIntegerType - Returns the type that Promotable will
01127   /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable
01128   /// integer type.
01129   QualType getPromotedIntegerType(QualType PromotableType);
01130 
01131   /// \brief Whether this is a promotable bitfield reference according
01132   /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
01133   ///
01134   /// \returns the type this bit-field will promote to, or NULL if no
01135   /// promotion occurs.
01136   QualType isPromotableBitField(Expr *E);
01137 
01138   /// getIntegerTypeOrder - Returns the highest ranked integer type:
01139   /// C99 6.3.1.8p1.  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
01140   /// LHS < RHS, return -1.
01141   int getIntegerTypeOrder(QualType LHS, QualType RHS);
01142 
01143   /// getFloatingTypeOrder - Compare the rank of the two specified floating
01144   /// point types, ignoring the domain of the type (i.e. 'double' ==
01145   /// '_Complex double').  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
01146   /// LHS < RHS, return -1.
01147   int getFloatingTypeOrder(QualType LHS, QualType RHS);
01148 
01149   /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
01150   /// point or a complex type (based on typeDomain/typeSize).
01151   /// 'typeDomain' is a real floating point or complex type.
01152   /// 'typeSize' is a real floating point or complex type.
01153   QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
01154                                              QualType typeDomain) const;
01155 
01156 private:
01157   // Helper for integer ordering
01158   unsigned getIntegerRank(Type* T);
01159 
01160 public:
01161 
01162   //===--------------------------------------------------------------------===//
01163   //                    Type Compatibility Predicates
01164   //===--------------------------------------------------------------------===//
01165 
01166   /// Compatibility predicates used to check assignment expressions.
01167   bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
01168 
01169   bool typesAreBlockPointerCompatible(QualType, QualType); 
01170 
01171   bool isObjCIdType(QualType T) const {
01172     return T == ObjCIdTypedefType;
01173   }
01174   bool isObjCClassType(QualType T) const {
01175     return T == ObjCClassTypedefType;
01176   }
01177   bool isObjCSelType(QualType T) const {
01178     return T == ObjCSelTypedefType;
01179   }
01180   bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
01181   bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
01182                                          bool ForCompare);
01183 
01184   // Check the safety of assignment from LHS to RHS
01185   bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
01186                                const ObjCObjectPointerType *RHSOPT);
01187   bool canAssignObjCInterfaces(const ObjCInterfaceType *LHS,
01188                                const ObjCInterfaceType *RHS);
01189   bool canAssignObjCInterfacesInBlockPointer(
01190                                           const ObjCObjectPointerType *LHSOPT,
01191                                           const ObjCObjectPointerType *RHSOPT);
01192   bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
01193   QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
01194                                    const ObjCObjectPointerType *RHSOPT);
01195   
01196   // Functions for calculating composite types
01197   QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false);
01198   QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false);
01199 
01200   /// UsualArithmeticConversionsType - handles the various conversions
01201   /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
01202   /// and returns the result type of that conversion.
01203   QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
01204 
01205   //===--------------------------------------------------------------------===//
01206   //                    Integer Predicates
01207   //===--------------------------------------------------------------------===//
01208 
01209   // The width of an integer, as defined in C99 6.2.6.2. This is the number
01210   // of bits in an integer type excluding any padding bits.
01211   unsigned getIntWidth(QualType T);
01212 
01213   // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
01214   // unsigned integer type.  This method takes a signed type, and returns the
01215   // corresponding unsigned integer type.
01216   QualType getCorrespondingUnsignedType(QualType T);
01217 
01218   //===--------------------------------------------------------------------===//
01219   //                    Type Iterators.
01220   //===--------------------------------------------------------------------===//
01221 
01222   typedef std::vector<Type*>::iterator       type_iterator;
01223   typedef std::vector<Type*>::const_iterator const_type_iterator;
01224 
01225   type_iterator types_begin() { return Types.begin(); }
01226   type_iterator types_end() { return Types.end(); }
01227   const_type_iterator types_begin() const { return Types.begin(); }
01228   const_type_iterator types_end() const { return Types.end(); }
01229 
01230   //===--------------------------------------------------------------------===//
01231   //                    Integer Values
01232   //===--------------------------------------------------------------------===//
01233 
01234   /// MakeIntValue - Make an APSInt of the appropriate width and
01235   /// signedness for the given \arg Value and integer \arg Type.
01236   llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) {
01237     llvm::APSInt Res(getIntWidth(Type), !Type->isSignedIntegerType());
01238     Res = Value;
01239     return Res;
01240   }
01241 
01242   /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists.
01243   ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
01244   /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists.
01245   ObjCCategoryImplDecl   *getObjCImplementation(ObjCCategoryDecl *D);
01246 
01247   /// \brief Set the implementation of ObjCInterfaceDecl.
01248   void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
01249                              ObjCImplementationDecl *ImplD);
01250   /// \brief Set the implementation of ObjCCategoryDecl.
01251   void setObjCImplementation(ObjCCategoryDecl *CatD,
01252                              ObjCCategoryImplDecl *ImplD);
01253 
01254   /// \brief Allocate an uninitialized TypeSourceInfo.
01255   ///
01256   /// The caller should initialize the memory held by TypeSourceInfo using
01257   /// the TypeLoc wrappers.
01258   ///
01259   /// \param T the type that will be the basis for type source info. This type
01260   /// should refer to how the declarator was written in source code, not to
01261   /// what type semantic analysis resolved the declarator to.
01262   ///
01263   /// \param Size the size of the type info to create, or 0 if the size
01264   /// should be calculated based on the type.
01265   TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0);
01266 
01267   /// \brief Allocate a TypeSourceInfo where all locations have been
01268   /// initialized to a given location, which defaults to the empty
01269   /// location.
01270   TypeSourceInfo *
01271   getTrivialTypeSourceInfo(QualType T, SourceLocation Loc = SourceLocation());
01272 
01273 private:
01274   ASTContext(const ASTContext&); // DO NOT IMPLEMENT
01275   void operator=(const ASTContext&); // DO NOT IMPLEMENT
01276 
01277   void InitBuiltinTypes();
01278   void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
01279 
01280   // Return the ObjC type encoding for a given type.
01281   void getObjCEncodingForTypeImpl(QualType t, std::string &S,
01282                                   bool ExpandPointedToStructures,
01283                                   bool ExpandStructures,
01284                                   const FieldDecl *Field,
01285                                   bool OutermostType = false,
01286                                   bool EncodingProperty = false);
01287 
01288   const ASTRecordLayout &getObjCLayout(const ObjCInterfaceDecl *D,
01289                                        const ObjCImplementationDecl *Impl);
01290   
01291 private:
01292   // FIXME: This currently contains the set of StoredDeclMaps used
01293   // by DeclContext objects.  This probably should not be in ASTContext,
01294   // but we include it here so that ASTContext can quickly deallocate them.
01295   llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM;
01296   friend class DeclContext;
01297   void ReleaseDeclContextMaps();
01298 };
01299   
01300 /// @brief Utility function for constructing a nullary selector.
01301 static inline Selector GetNullarySelector(const char* name, ASTContext& Ctx) {
01302   IdentifierInfo* II = &Ctx.Idents.get(name);
01303   return Ctx.Selectors.getSelector(0, &II);
01304 }
01305 
01306 /// @brief Utility function for constructing an unary selector.
01307 static inline Selector GetUnarySelector(const char* name, ASTContext& Ctx) {
01308   IdentifierInfo* II = &Ctx.Idents.get(name);
01309   return Ctx.Selectors.getSelector(1, &II);
01310 }
01311 
01312 }  // end namespace clang
01313 
01314 // operator new and delete aren't allowed inside namespaces.
01315 // The throw specifications are mandated by the standard.
01316 /// @brief Placement new for using the ASTContext's allocator.
01317 ///
01318 /// This placement form of operator new uses the ASTContext's allocator for
01319 /// obtaining memory. It is a non-throwing new, which means that it returns
01320 /// null on error. (If that is what the allocator does. The current does, so if
01321 /// this ever changes, this operator will have to be changed, too.)
01322 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
01323 /// @code
01324 /// // Default alignment (8)
01325 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
01326 /// // Specific alignment
01327 /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
01328 /// @endcode
01329 /// Please note that you cannot use delete on the pointer; it must be
01330 /// deallocated using an explicit destructor call followed by
01331 /// @c Context.Deallocate(Ptr).
01332 ///
01333 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
01334 /// @param C The ASTContext that provides the allocator.
01335 /// @param Alignment The alignment of the allocated memory (if the underlying
01336 ///                  allocator supports it).
01337 /// @return The allocated memory. Could be NULL.
01338 inline void *operator new(size_t Bytes, clang::ASTContext &C,
01339                           size_t Alignment) throw () {
01340   return C.Allocate(Bytes, Alignment);
01341 }
01342 /// @brief Placement delete companion to the new above.
01343 ///
01344 /// This operator is just a companion to the new above. There is no way of
01345 /// invoking it directly; see the new operator for more details. This operator
01346 /// is called implicitly by the compiler if a placement new expression using
01347 /// the ASTContext throws in the object constructor.
01348 inline void operator delete(void *Ptr, clang::ASTContext &C, size_t)
01349               throw () {
01350   C.Deallocate(Ptr);
01351 }
01352 
01353 /// This placement form of operator new[] uses the ASTContext's allocator for
01354 /// obtaining memory. It is a non-throwing new[], which means that it returns
01355 /// null on error.
01356 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
01357 /// @code
01358 /// // Default alignment (8)
01359 /// char *data = new (Context) char[10];
01360 /// // Specific alignment
01361 /// char *data = new (Context, 4) char[10];
01362 /// @endcode
01363 /// Please note that you cannot use delete on the pointer; it must be
01364 /// deallocated using an explicit destructor call followed by
01365 /// @c Context.Deallocate(Ptr).
01366 ///
01367 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
01368 /// @param C The ASTContext that provides the allocator.
01369 /// @param Alignment The alignment of the allocated memory (if the underlying
01370 ///                  allocator supports it).
01371 /// @return The allocated memory. Could be NULL.
01372 inline void *operator new[](size_t Bytes, clang::ASTContext& C,
01373                             size_t Alignment = 8) throw () {
01374   return C.Allocate(Bytes, Alignment);
01375 }
01376 
01377 /// @brief Placement delete[] companion to the new[] above.
01378 ///
01379 /// This operator is just a companion to the new[] above. There is no way of
01380 /// invoking it directly; see the new[] operator for more details. This operator
01381 /// is called implicitly by the compiler if a placement new[] expression using
01382 /// the ASTContext throws in the object constructor.
01383 inline void operator delete[](void *Ptr, clang::ASTContext &C, size_t)
01384               throw () {
01385   C.Deallocate(Ptr);
01386 }
01387 
01388 #endif