zcov: / include/clang/AST/ASTContext.h


Files: 1 Branches Taken: 40.0% 2 / 5
Generated: 2010-02-10 01:31 Branches Executed: 40.0% 2 / 5
Line Coverage: 95.3% 121 / 127


Programs: 158 Runs 313374


       1                 : //===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : //  This file defines the ASTContext interface.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #ifndef LLVM_CLANG_AST_ASTCONTEXT_H
      15                 : #define LLVM_CLANG_AST_ASTCONTEXT_H
      16                 : 
      17                 : #include "clang/Basic/IdentifierTable.h"
      18                 : #include "clang/Basic/LangOptions.h"
      19                 : #include "clang/Basic/OperatorKinds.h"
      20                 : #include "clang/AST/Attr.h"
      21                 : #include "clang/AST/Decl.h"
      22                 : #include "clang/AST/NestedNameSpecifier.h"
      23                 : #include "clang/AST/PrettyPrinter.h"
      24                 : #include "clang/AST/TemplateName.h"
      25                 : #include "clang/AST/Type.h"
      26                 : #include "clang/AST/CanonicalType.h"
      27                 : #include "llvm/ADT/DenseMap.h"
      28                 : #include "llvm/ADT/FoldingSet.h"
      29                 : #include "llvm/ADT/OwningPtr.h"
      30                 : #include "llvm/Support/Allocator.h"
      31                 : #include <vector>
      32                 : 
      33                 : namespace llvm {
      34                 :   struct fltSemantics;
      35                 : }
      36                 : 
      37                 : namespace clang {
      38                 :   class FileManager;
      39                 :   class ASTRecordLayout;
      40                 :   class BlockExpr;
      41                 :   class CharUnits;
      42                 :   class Expr;
      43                 :   class ExternalASTSource;
      44                 :   class IdentifierTable;
      45                 :   class SelectorTable;
      46                 :   class SourceManager;
      47                 :   class TargetInfo;
      48                 :   // Decls
      49                 :   class CXXMethodDecl;
      50                 :   class CXXRecordDecl;
      51                 :   class Decl;
      52                 :   class FieldDecl;
      53                 :   class ObjCIvarDecl;
      54                 :   class ObjCIvarRefExpr;
      55                 :   class ObjCPropertyDecl;
      56                 :   class RecordDecl;
      57                 :   class TagDecl;
      58                 :   class TemplateTypeParmDecl;
      59                 :   class TranslationUnitDecl;
      60                 :   class TypeDecl;
      61                 :   class TypedefDecl;
      62                 :   class UsingDecl;
      63                 :   class UsingShadowDecl;
      64                 :   class UnresolvedSetIterator;
      65                 : 
      66                 :   namespace Builtin { class Context; }
      67                 : 
      68                 : /// ASTContext - This class holds long-lived AST nodes (such as types and
      69                 : /// decls) that can be referred to throughout the semantic analysis of a file.
      70                 : class ASTContext {
      71                 :   std::vector<Type*> Types;
      72                 :   llvm::FoldingSet<ExtQuals> ExtQualNodes;
      73                 :   llvm::FoldingSet<ComplexType> ComplexTypes;
      74                 :   llvm::FoldingSet<PointerType> PointerTypes;
      75                 :   llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
      76                 :   llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
      77                 :   llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
      78                 :   llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
      79                 :   llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
      80                 :   llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
      81                 :   std::vector<VariableArrayType*> VariableArrayTypes;
      82                 :   llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
      83                 :   llvm::FoldingSet<DependentSizedExtVectorType> DependentSizedExtVectorTypes;
      84                 :   llvm::FoldingSet<VectorType> VectorTypes;
      85                 :   llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
      86                 :   llvm::FoldingSet<FunctionProtoType> FunctionProtoTypes;
      87                 :   llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
      88                 :   llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
      89                 :   llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
      90                 :   llvm::FoldingSet<SubstTemplateTypeParmType> SubstTemplateTypeParmTypes;
      91                 :   llvm::FoldingSet<TemplateSpecializationType> TemplateSpecializationTypes;
      92                 :   llvm::FoldingSet<QualifiedNameType> QualifiedNameTypes;
      93                 :   llvm::FoldingSet<TypenameType> TypenameTypes;
      94                 :   llvm::FoldingSet<ObjCInterfaceType> ObjCInterfaceTypes;
      95                 :   llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
      96                 :   llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
      97                 : 
      98                 :   llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
      99                 :   llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
     100                 : 
     101                 :   /// \brief The set of nested name specifiers.
     102                 :   ///
     103                 :   /// This set is managed by the NestedNameSpecifier class.
     104                 :   llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
     105                 :   NestedNameSpecifier *GlobalNestedNameSpecifier;
     106                 :   friend class NestedNameSpecifier;
     107                 : 
     108                 :   /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
     109                 :   ///  This is lazily created.  This is intentionally not serialized.
     110                 :   llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> ASTRecordLayouts;
     111                 :   llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*> ObjCLayouts;
     112                 : 
     113                 :   /// KeyFunctions - A cache mapping from CXXRecordDecls to key functions.
     114                 :   llvm::DenseMap<const CXXRecordDecl*, const CXXMethodDecl*> KeyFunctions;
     115                 :   
     116                 :   /// \brief Mapping from ObjCContainers to their ObjCImplementations.
     117                 :   llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
     118                 : 
     119                 :   /// BuiltinVaListType - built-in va list type.
     120                 :   /// This is initially null and set by Sema::LazilyCreateBuiltin when
     121                 :   /// a builtin that takes a valist is encountered.
     122                 :   QualType BuiltinVaListType;
     123                 : 
     124                 :   /// ObjCIdType - a pseudo built-in typedef type (set by Sema).
     125                 :   QualType ObjCIdTypedefType;
     126                 : 
     127                 :   /// ObjCSelType - another pseudo built-in typedef type (set by Sema).
     128                 :   QualType ObjCSelTypedefType;
     129                 : 
     130                 :   /// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
     131                 :   QualType ObjCProtoType;
     132                 :   const RecordType *ProtoStructType;
     133                 : 
     134                 :   /// ObjCClassType - another pseudo built-in typedef type (set by Sema).
     135                 :   QualType ObjCClassTypedefType;
     136                 : 
     137                 :   QualType ObjCConstantStringType;
     138                 :   RecordDecl *CFConstantStringTypeDecl;
     139                 : 
     140                 :   RecordDecl *ObjCFastEnumerationStateTypeDecl;
     141                 : 
     142                 :   /// \brief The type for the C FILE type.
     143                 :   TypeDecl *FILEDecl;
     144                 : 
     145                 :   /// \brief The type for the C jmp_buf type.
     146                 :   TypeDecl *jmp_bufDecl;
     147                 : 
     148                 :   /// \brief The type for the C sigjmp_buf type.
     149                 :   TypeDecl *sigjmp_bufDecl;
     150                 : 
     151                 :   /// \brief Type for the Block descriptor for Blocks CodeGen.
     152                 :   RecordDecl *BlockDescriptorType;
     153                 : 
     154                 :   /// \brief Type for the Block descriptor for Blocks CodeGen.
     155                 :   RecordDecl *BlockDescriptorExtendedType;
     156                 : 
     157                 :   /// \brief Keeps track of all declaration attributes.
     158                 :   ///
     159                 :   /// Since so few decls have attrs, we keep them in a hash map instead of
     160                 :   /// wasting space in the Decl class.
     161                 :   llvm::DenseMap<const Decl*, Attr*> DeclAttrs;
     162                 : 
     163                 :   /// \brief Keeps track of the static data member templates from which
     164                 :   /// static data members of class template specializations were instantiated.
     165                 :   ///
     166                 :   /// This data structure stores the mapping from instantiations of static
     167                 :   /// data members to the static data member representations within the
     168                 :   /// class template from which they were instantiated along with the kind
     169                 :   /// of instantiation or specialization (a TemplateSpecializationKind - 1).
     170                 :   ///
     171                 :   /// Given the following example:
     172                 :   ///
     173                 :   /// \code
     174                 :   /// template<typename T>
     175                 :   /// struct X {
     176                 :   ///   static T value;
     177                 :   /// };
     178                 :   ///
     179                 :   /// template<typename T>
     180                 :   ///   T X<T>::value = T(17);
     181                 :   ///
     182                 :   /// int *x = &X<int>::value;
     183                 :   /// \endcode
     184                 :   ///
     185                 :   /// This mapping will contain an entry that maps from the VarDecl for
     186                 :   /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
     187                 :   /// class template X) and will be marked TSK_ImplicitInstantiation.
     188                 :   llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *> 
     189                 :     InstantiatedFromStaticDataMember;
     190                 : 
     191                 :   /// \brief Keeps track of the declaration from which a UsingDecl was
     192                 :   /// created during instantiation.  The source declaration is always
     193                 :   /// a UsingDecl, an UnresolvedUsingValueDecl, or an
     194                 :   /// UnresolvedUsingTypenameDecl.
     195                 :   ///
     196                 :   /// For example:
     197                 :   /// \code
     198                 :   /// template<typename T>
     199                 :   /// struct A {
     200                 :   ///   void f();
     201                 :   /// };
     202                 :   ///
     203                 :   /// template<typename T>
     204                 :   /// struct B : A<T> {
     205                 :   ///   using A<T>::f;
     206                 :   /// };
     207                 :   ///
     208                 :   /// template struct B<int>;
     209                 :   /// \endcode
     210                 :   ///
     211                 :   /// This mapping will contain an entry that maps from the UsingDecl in
     212                 :   /// B<int> to the UnresolvedUsingDecl in B<T>.
     213                 :   llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl;
     214                 : 
     215                 :   llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
     216                 :     InstantiatedFromUsingShadowDecl;
     217                 : 
     218                 :   llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
     219                 : 
     220                 :   TranslationUnitDecl *TUDecl;
     221                 : 
     222                 :   /// SourceMgr - The associated SourceManager object.
     223                 :   SourceManager &SourceMgr;
     224                 : 
     225                 :   /// LangOpts - The language options used to create the AST associated with
     226                 :   ///  this ASTContext object.
     227                 :   LangOptions LangOpts;
     228                 : 
     229                 :   /// \brief Whether we have already loaded comment source ranges from an
     230                 :   /// external source.
     231                 :   bool LoadedExternalComments;
     232                 : 
     233                 :   /// MallocAlloc/BumpAlloc - The allocator objects used to create AST objects.
     234                 :   bool FreeMemory;
     235                 :   llvm::MallocAllocator MallocAlloc;
     236                 :   llvm::BumpPtrAllocator BumpAlloc;
     237                 : 
     238                 :   /// \brief Mapping from declarations to their comments, once we have
     239                 :   /// already looked up the comment associated with a given declaration.
     240                 :   llvm::DenseMap<const Decl *, std::string> DeclComments;
     241                 : 
     242                 : public:
     243                 :   const TargetInfo &Target;
     244                 :   IdentifierTable &Idents;
     245                 :   SelectorTable &Selectors;
     246                 :   Builtin::Context &BuiltinInfo;
     247                 :   DeclarationNameTable DeclarationNames;
     248                 :   llvm::OwningPtr<ExternalASTSource> ExternalSource;
     249                 :   clang::PrintingPolicy PrintingPolicy;
     250                 : 
     251                 :   // Typedefs which may be provided defining the structure of Objective-C
     252                 :   // pseudo-builtins
     253                 :   QualType ObjCIdRedefinitionType;
     254                 :   QualType ObjCClassRedefinitionType;
     255                 :   QualType ObjCSelRedefinitionType;
     256                 : 
     257                 :   /// \brief Source ranges for all of the comments in the source file,
     258                 :   /// sorted in order of appearance in the translation unit.
     259                 :   std::vector<SourceRange> Comments;
     260                 : 
     261           101612:   SourceManager& getSourceManager() { return SourceMgr; }
     262                 :   const SourceManager& getSourceManager() const { return SourceMgr; }
     263           488119:   void *Allocate(unsigned Size, unsigned Align = 8) {
     264                 :     return FreeMemory ? MallocAlloc.Allocate(Size, Align) :
                   441291: branch 0 taken
                    46828: branch 1 taken
     265           488119:                         BumpAlloc.Allocate(Size, Align);
     266                 :   }
     267           138455:   void Deallocate(void *Ptr) {
                        0: branch 0 not taken
                        0: branch 1 not taken
     268           138455:     if (FreeMemory)
     269           138010:       MallocAlloc.Deallocate(Ptr);
     270           138455:   }
     271           281409:   const LangOptions& getLangOptions() const { return LangOpts; }
     272                 : 
     273              154:   FullSourceLoc getFullLoc(SourceLocation Loc) const {
     274              154:     return FullSourceLoc(Loc,SourceMgr);
     275                 :   }
     276                 : 
     277                 :   /// \brief Retrieve the attributes for the given declaration.
     278            30254:   Attr*& getDeclAttrs(const Decl *D) { return DeclAttrs[D]; }
     279                 : 
     280                 :   /// \brief Erase the attributes corresponding to the given declaration.
     281                0:   void eraseDeclAttrs(const Decl *D) { DeclAttrs.erase(D); }
     282                 : 
     283                 :   /// \brief If this variable is an instantiated static data member of a
     284                 :   /// class template specialization, returns the templated static data member
     285                 :   /// from which it was instantiated.
     286                 :   MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
     287                 :                                                            const VarDecl *Var);
     288                 : 
     289                 :   /// \brief Note that the static data member \p Inst is an instantiation of
     290                 :   /// the static data member template \p Tmpl of a class template.
     291                 :   void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
     292                 :                                            TemplateSpecializationKind TSK);
     293                 : 
     294                 :   /// \brief If the given using decl is an instantiation of a
     295                 :   /// (possibly unresolved) using decl from a template instantiation,
     296                 :   /// return it.
     297                 :   NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
     298                 : 
     299                 :   /// \brief Remember that the using decl \p Inst is an instantiation
     300                 :   /// of the using decl \p Pattern of a class template.
     301                 :   void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
     302                 : 
     303                 :   void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
     304                 :                                           UsingShadowDecl *Pattern);
     305                 :   UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
     306                 : 
     307                 :   FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
     308                 : 
     309                 :   void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
     310                 : 
     311            38143:   TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
     312                 : 
     313                 : 
     314                 :   const char *getCommentForDecl(const Decl *D);
     315                 : 
     316                 :   // Builtin Types.
     317                 :   CanQualType VoidTy;
     318                 :   CanQualType BoolTy;
     319                 :   CanQualType CharTy;
     320                 :   CanQualType WCharTy;  // [C++ 3.9.1p5], integer type in C99.
     321                 :   CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
     322                 :   CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
     323                 :   CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
     324                 :   CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
     325                 :   CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
     326                 :   CanQualType FloatTy, DoubleTy, LongDoubleTy;
     327                 :   CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
     328                 :   CanQualType VoidPtrTy, NullPtrTy;
     329                 :   CanQualType OverloadTy;
     330                 :   CanQualType DependentTy;
     331                 :   CanQualType UndeducedAutoTy;
     332                 :   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
     333                 : 
     334                 :   ASTContext(const LangOptions& LOpts, SourceManager &SM, const TargetInfo &t,
     335                 :              IdentifierTable &idents, SelectorTable &sels,
     336                 :              Builtin::Context &builtins,
     337                 :              bool FreeMemory = true, unsigned size_reserve=0);
     338                 : 
     339                 :   ~ASTContext();
     340                 : 
     341                 :   /// \brief Attach an external AST source to the AST context.
     342                 :   ///
     343                 :   /// The external AST source provides the ability to load parts of
     344                 :   /// the abstract syntax tree as needed from some external storage,
     345                 :   /// e.g., a precompiled header.
     346                 :   void setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source);
     347                 : 
     348                 :   /// \brief Retrieve a pointer to the external AST source associated
     349                 :   /// with this AST context, if any.
     350            23217:   ExternalASTSource *getExternalSource() const { return ExternalSource.get(); }
     351                 : 
     352                 :   void PrintStats() const;
     353                 :   const std::vector<Type*>& getTypes() const { return Types; }
     354                 : 
     355                 :   //===--------------------------------------------------------------------===//
     356                 :   //                           Type Constructors
     357                 :   //===--------------------------------------------------------------------===//
     358                 : 
     359                 : private:
     360                 :   /// getExtQualType - Return a type with extended qualifiers.
     361                 :   QualType getExtQualType(const Type *Base, Qualifiers Quals);
     362                 : 
     363                 : public:
     364                 :   /// getAddSpaceQualType - Return the uniqued reference to the type for an
     365                 :   /// address space qualified type with the specified type and address space.
     366                 :   /// The resulting type has a union of the qualifiers from T and the address
     367                 :   /// space. If T already has an address space specifier, it is silently
     368                 :   /// replaced.
     369                 :   QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace);
     370                 : 
     371                 :   /// getObjCGCQualType - Returns the uniqued reference to the type for an
     372                 :   /// objc gc qualified type. The retulting type has a union of the qualifiers
     373                 :   /// from T and the gc attribute.
     374                 :   QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr);
     375                 : 
     376                 :   /// getRestrictType - Returns the uniqued reference to the type for a
     377                 :   /// 'restrict' qualified type.  The resulting type has a union of the
     378                 :   /// qualifiers from T and 'restrict'.
     379                 :   QualType getRestrictType(QualType T) {
     380                 :     return T.withFastQualifiers(Qualifiers::Restrict);
     381                 :   }
     382                 : 
     383                 :   /// getVolatileType - Returns the uniqued reference to the type for a
     384                 :   /// 'volatile' qualified type.  The resulting type has a union of the
     385                 :   /// qualifiers from T and 'volatile'.
     386                 :   QualType getVolatileType(QualType T);
     387                 : 
     388                 :   /// getConstType - Returns the uniqued reference to the type for a
     389                 :   /// 'const' qualified type.  The resulting type has a union of the
     390                 :   /// qualifiers from T and 'const'.
     391                 :   ///
     392                 :   /// It can be reasonably expected that this will always be
     393                 :   /// equivalent to calling T.withConst().
     394                 :   QualType getConstType(QualType T) { return T.withConst(); }
     395                 : 
     396                 :   /// getNoReturnType - Add or remove the noreturn attribute to the given type 
     397                 :   /// which must be a FunctionType or a pointer to an allowable type or a 
     398                 :   /// BlockPointer.
     399                 :   QualType getNoReturnType(QualType T, bool AddNoReturn = true);
     400                 : 
     401                 :   /// getCallConvType - Adds the specified calling convention attribute to
     402                 :   /// the given type, which must be a FunctionType or a pointer to an
     403                 :   /// allowable type.
     404                 :   QualType getCallConvType(QualType T, CallingConv CallConv);
     405                 : 
     406                 :   /// getComplexType - Return the uniqued reference to the type for a complex
     407                 :   /// number with the specified element type.
     408                 :   QualType getComplexType(QualType T);
     409             6750:   CanQualType getComplexType(CanQualType T) {
     410             6750:     return CanQualType::CreateUnsafe(getComplexType((QualType) T));
     411                 :   }
     412                 : 
     413                 :   /// getPointerType - Return the uniqued reference to the type for a pointer to
     414                 :   /// the specified type.
     415                 :   QualType getPointerType(QualType T);
     416             6527:   CanQualType getPointerType(CanQualType T) {
     417             6527:     return CanQualType::CreateUnsafe(getPointerType((QualType) T));
     418                 :   }
     419                 : 
     420                 :   /// getBlockPointerType - Return the uniqued reference to the type for a block
     421                 :   /// of the specified type.
     422                 :   QualType getBlockPointerType(QualType T);
     423                 : 
     424                 :   /// This gets the struct used to keep track of the descriptor for pointer to
     425                 :   /// blocks.
     426                 :   QualType getBlockDescriptorType();
     427                 : 
     428                 :   // Set the type for a Block descriptor type.
     429                 :   void setBlockDescriptorType(QualType T);
     430                 :   /// Get the BlockDescriptorType type, or NULL if it hasn't yet been built.
     431               44:   QualType getRawBlockdescriptorType() {
     432               44:     if (BlockDescriptorType)
     433                0:       return getTagDeclType(BlockDescriptorType);
     434               44:     return QualType();
     435                 :   }
     436                 : 
     437                 :   /// This gets the struct used to keep track of the extended descriptor for
     438                 :   /// pointer to blocks.
     439                 :   QualType getBlockDescriptorExtendedType();
     440                 : 
     441                 :   // Set the type for a Block descriptor extended type.
     442                 :   void setBlockDescriptorExtendedType(QualType T);
     443                 :   /// Get the BlockDescriptorExtendedType type, or NULL if it hasn't yet been
     444                 :   /// built.
     445               44:   QualType getRawBlockdescriptorExtendedType() {
     446               44:     if (BlockDescriptorExtendedType)
     447                0:       return getTagDeclType(BlockDescriptorExtendedType);
     448               44:     return QualType();
     449                 :   }
     450                 : 
     451                 :   /// This gets the struct used to keep track of pointer to blocks, complete
     452                 :   /// with captured variables.
     453                 :   QualType getBlockParmType(bool BlockHasCopyDispose,
     454                 :                             llvm::SmallVector<const Expr *, 8> &BDRDs);
     455                 : 
     456                 :   /// This builds the struct used for __block variables.
     457                 :   QualType BuildByRefType(const char *DeclName, QualType Ty);
     458                 : 
     459                 :   /// Returns true iff we need copy/dispose helpers for the given type.
     460                 :   bool BlockRequiresCopying(QualType Ty);
     461                 : 
     462                 :   /// getLValueReferenceType - Return the uniqued reference to the type for an
     463                 :   /// lvalue reference to the specified type.
     464                 :   QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true);
     465                 : 
     466                 :   /// getRValueReferenceType - Return the uniqued reference to the type for an
     467                 :   /// rvalue reference to the specified type.
     468                 :   QualType getRValueReferenceType(QualType T);
     469                 : 
     470                 :   /// getMemberPointerType - Return the uniqued reference to the type for a
     471                 :   /// member pointer to the specified type in the specified class. The class
     472                 :   /// is a Type because it could be a dependent name.
     473                 :   QualType getMemberPointerType(QualType T, const Type *Cls);
     474                 : 
     475                 :   /// getVariableArrayType - Returns a non-unique reference to the type for a
     476                 :   /// variable array of the specified element type.
     477                 :   QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
     478                 :                                 ArrayType::ArraySizeModifier ASM,
     479                 :                                 unsigned EltTypeQuals,
     480                 :                                 SourceRange Brackets);
     481                 : 
     482                 :   /// getDependentSizedArrayType - Returns a non-unique reference to
     483                 :   /// the type for a dependently-sized array of the specified element
     484                 :   /// type. FIXME: We will need these to be uniqued, or at least
     485                 :   /// comparable, at some point.
     486                 :   QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
     487                 :                                       ArrayType::ArraySizeModifier ASM,
     488                 :                                       unsigned EltTypeQuals,
     489                 :                                       SourceRange Brackets);
     490                 : 
     491                 :   /// getIncompleteArrayType - Returns a unique reference to the type for a
     492                 :   /// incomplete array of the specified element type.
     493                 :   QualType getIncompleteArrayType(QualType EltTy,
     494                 :                                   ArrayType::ArraySizeModifier ASM,
     495                 :                                   unsigned EltTypeQuals);
     496                 : 
     497                 :   /// getConstantArrayType - Return the unique reference to the type for a
     498                 :   /// constant array of the specified element type.
     499                 :   QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
     500                 :                                 ArrayType::ArraySizeModifier ASM,
     501                 :                                 unsigned EltTypeQuals);
     502                 : 
     503                 :   /// getVectorType - Return the unique reference to a vector type of
     504                 :   /// the specified element type and size. VectorType must be a built-in type.
     505                 :   QualType getVectorType(QualType VectorType, unsigned NumElts,
     506                 :                          bool AltiVec, bool IsPixel);
     507                 : 
     508                 :   /// getExtVectorType - Return the unique reference to an extended vector type
     509                 :   /// of the specified element type and size.  VectorType must be a built-in
     510                 :   /// type.
     511                 :   QualType getExtVectorType(QualType VectorType, unsigned NumElts);
     512                 : 
     513                 :   /// getDependentSizedExtVectorType - Returns a non-unique reference to
     514                 :   /// the type for a dependently-sized vector of the specified element
     515                 :   /// type. FIXME: We will need these to be uniqued, or at least
     516                 :   /// comparable, at some point.
     517                 :   QualType getDependentSizedExtVectorType(QualType VectorType,
     518                 :                                           Expr *SizeExpr,
     519                 :                                           SourceLocation AttrLoc);
     520                 : 
     521                 :   /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'.
     522                 :   ///
     523                 :   QualType getFunctionNoProtoType(QualType ResultTy, bool NoReturn = false,
     524                 :                                   CallingConv CallConv = CC_Default);
     525                 : 
     526                 :   /// getFunctionType - Return a normal function type with a typed argument
     527                 :   /// list.  isVariadic indicates whether the argument list includes '...'.
     528                 :   QualType getFunctionType(QualType ResultTy, const QualType *ArgArray,
     529                 :                            unsigned NumArgs, bool isVariadic,
     530                 :                            unsigned TypeQuals, bool hasExceptionSpec = false,
     531                 :                            bool hasAnyExceptionSpec = false,
     532                 :                            unsigned NumExs = 0, const QualType *ExArray = 0,
     533                 :                            bool NoReturn = false,
     534                 :                            CallingConv CallConv = CC_Default);
     535                 : 
     536                 :   /// getTypeDeclType - Return the unique reference to the type for
     537                 :   /// the specified type declaration.
     538                 :   QualType getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl=0);
     539                 : 
     540                 :   /// getTypedefType - Return the unique reference to the type for the
     541                 :   /// specified typename decl.
     542                 :   QualType getTypedefType(TypedefDecl *Decl);
     543                 : 
     544                 :   QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
     545                 :                                         QualType Replacement);
     546                 : 
     547                 :   QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
     548                 :                                    bool ParameterPack,
     549                 :                                    IdentifierInfo *Name = 0);
     550                 : 
     551                 :   QualType getTemplateSpecializationType(TemplateName T,
     552                 :                                          const TemplateArgument *Args,
     553                 :                                          unsigned NumArgs,
     554                 :                                          QualType Canon = QualType());
     555                 : 
     556                 :   QualType getTemplateSpecializationType(TemplateName T,
     557                 :                                          const TemplateArgumentListInfo &Args,
     558                 :                                          QualType Canon = QualType());
     559                 : 
     560                 :   QualType getQualifiedNameType(NestedNameSpecifier *NNS,
     561                 :                                 QualType NamedType);
     562                 :   QualType getTypenameType(NestedNameSpecifier *NNS,
     563                 :                            const IdentifierInfo *Name,
     564                 :                            QualType Canon = QualType());
     565                 :   QualType getTypenameType(NestedNameSpecifier *NNS,
     566                 :                            const TemplateSpecializationType *TemplateId,
     567                 :                            QualType Canon = QualType());
     568                 :   QualType getElaboratedType(QualType UnderlyingType,
     569                 :                              ElaboratedType::TagKind Tag);
     570                 : 
     571                 :   QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
     572                 :                                 ObjCProtocolDecl **Protocols = 0,
     573                 :                                 unsigned NumProtocols = 0);
     574                 : 
     575                 :   /// getObjCObjectPointerType - Return a ObjCObjectPointerType type for the
     576                 :   /// given interface decl and the conforming protocol list.
     577                 :   QualType getObjCObjectPointerType(QualType OIT,
     578                 :                                     ObjCProtocolDecl **ProtocolList = 0,
     579                 :                                     unsigned NumProtocols = 0);
     580                 : 
     581                 :   /// getTypeOfType - GCC extension.
     582                 :   QualType getTypeOfExprType(Expr *e);
     583                 :   QualType getTypeOfType(QualType t);
     584                 : 
     585                 :   /// getDecltypeType - C++0x decltype.
     586                 :   QualType getDecltypeType(Expr *e);
     587                 : 
     588                 :   /// getTagDeclType - Return the unique reference to the type for the
     589                 :   /// specified TagDecl (struct/union/class/enum) decl.
     590                 :   QualType getTagDeclType(const TagDecl *Decl);
     591                 : 
     592                 :   /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
     593                 :   /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
     594                 :   CanQualType getSizeType() const;
     595                 : 
     596                 :   /// getWCharType - In C++, this returns the unique wchar_t type.  In C99, this
     597                 :   /// returns a type compatible with the type defined in <stddef.h> as defined
     598                 :   /// by the target.
     599               37:   QualType getWCharType() const { return WCharTy; }
     600                 : 
     601                 :   /// getSignedWCharType - Return the type of "signed wchar_t".
     602                 :   /// Used when in C++, as a GCC extension.
     603                 :   QualType getSignedWCharType() const;
     604                 : 
     605                 :   /// getUnsignedWCharType - Return the type of "unsigned wchar_t".
     606                 :   /// Used when in C++, as a GCC extension.
     607                 :   QualType getUnsignedWCharType() const;
     608                 : 
     609                 :   /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
     610                 :   /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
     611                 :   QualType getPointerDiffType() const;
     612                 : 
     613                 :   // getCFConstantStringType - Return the C structure type used to represent
     614                 :   // constant CFStrings.
     615                 :   QualType getCFConstantStringType();
     616                 : 
     617                 :   /// Get the structure type used to representation CFStrings, or NULL
     618                 :   /// if it hasn't yet been built.
     619               44:   QualType getRawCFConstantStringType() {
     620               44:     if (CFConstantStringTypeDecl)
     621                0:       return getTagDeclType(CFConstantStringTypeDecl);
     622               44:     return QualType();
     623                 :   }
     624                 :   void setCFConstantStringType(QualType T);
     625                 : 
     626                 :   // This setter/getter represents the ObjC type for an NSConstantString.
     627                 :   void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
     628              253:   QualType getObjCConstantStringInterface() const {
     629              253:     return ObjCConstantStringType;
     630                 :   }
     631                 : 
     632                 :   //// This gets the struct used to keep track of fast enumerations.
     633                 :   QualType getObjCFastEnumerationStateType();
     634                 : 
     635                 :   /// Get the ObjCFastEnumerationState type, or NULL if it hasn't yet
     636                 :   /// been built.
     637               44:   QualType getRawObjCFastEnumerationStateType() {
     638               44:     if (ObjCFastEnumerationStateTypeDecl)
     639                0:       return getTagDeclType(ObjCFastEnumerationStateTypeDecl);
     640               44:     return QualType();
     641                 :   }
     642                 : 
     643                 :   void setObjCFastEnumerationStateType(QualType T);
     644                 : 
     645                 :   /// \brief Set the type for the C FILE type.
     646                6:   void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
     647                 : 
     648                 :   /// \brief Retrieve the C FILE type.
     649               50:   QualType getFILEType() {
                        0: branch 0 not taken
     650               50:     if (FILEDecl)
     651                5:       return getTypeDeclType(FILEDecl);
     652               45:     return QualType();
     653                 :   }
     654                 : 
     655                 :   /// \brief Set the type for the C jmp_buf type.
     656                1:   void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
     657                1:     this->jmp_bufDecl = jmp_bufDecl;
     658                1:   }
     659                 : 
     660                 :   /// \brief Retrieve the C jmp_buf type.
     661               46:   QualType getjmp_bufType() {
     662               46:     if (jmp_bufDecl)
     663                2:       return getTypeDeclType(jmp_bufDecl);
     664               44:     return QualType();
     665                 :   }
     666                 : 
     667                 :   /// \brief Set the type for the C sigjmp_buf type.
     668                1:   void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
     669                1:     this->sigjmp_bufDecl = sigjmp_bufDecl;
     670                1:   }
     671                 : 
     672                 :   /// \brief Retrieve the C sigjmp_buf type.
     673               45:   QualType getsigjmp_bufType() {
     674               45:     if (sigjmp_bufDecl)
     675                1:       return getTypeDeclType(sigjmp_bufDecl);
     676               44:     return QualType();
     677                 :   }
     678                 : 
     679                 :   /// getObjCEncodingForType - Emit the ObjC type encoding for the
     680                 :   /// given type into \arg S. If \arg NameFields is specified then
     681                 :   /// record field names are also encoded.
     682                 :   void getObjCEncodingForType(QualType t, std::string &S,
     683                 :                               const FieldDecl *Field=0);
     684                 : 
     685                 :   void getLegacyIntegralTypeEncoding(QualType &t) const;
     686                 : 
     687                 :   // Put the string version of type qualifiers into S.
     688                 :   void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
     689                 :                                        std::string &S) const;
     690                 : 
     691                 :   /// getObjCEncodingForMethodDecl - Return the encoded type for this method
     692                 :   /// declaration.
     693                 :   void getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S);
     694                 : 
     695                 :   /// getObjCEncodingForBlockDecl - Return the encoded type for this block
     696                 :   /// declaration.
     697                 :   void getObjCEncodingForBlock(const BlockExpr *Expr, std::string& S);
     698                 :   
     699                 :   /// getObjCEncodingForPropertyDecl - Return the encoded type for
     700                 :   /// this method declaration. If non-NULL, Container must be either
     701                 :   /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
     702                 :   /// only be NULL when getting encodings for protocol properties.
     703                 :   void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
     704                 :                                       const Decl *Container,
     705                 :                                       std::string &S);
     706                 : 
     707                 :   bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
     708                 :                                       ObjCProtocolDecl *rProto);
     709                 : 
     710                 :   /// getObjCEncodingTypeSize returns size of type for objective-c encoding
     711                 :   /// purpose in characters.
     712                 :   CharUnits getObjCEncodingTypeSize(QualType t);
     713                 : 
     714                 :   /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by
     715                 :   /// Sema.  id is always a (typedef for a) pointer type, a pointer to a struct.
     716             5597:   QualType getObjCIdType() const { return ObjCIdTypedefType; }
     717                 :   void setObjCIdType(QualType T);
     718                 : 
     719                 :   void setObjCSelType(QualType T);
     720             6609:   QualType getObjCSelType() const { return ObjCSelTypedefType; }
     721                 : 
     722                 :   void setObjCProtoType(QualType QT);
     723             3822:   QualType getObjCProtoType() const { return ObjCProtoType; }
     724                 : 
     725                 :   /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
     726                 :   /// Sema.  'Class' is always a (typedef for a) pointer type, a pointer to a
     727                 :   /// struct.
     728             4688:   QualType getObjCClassType() const { return ObjCClassTypedefType; }
     729                 :   void setObjCClassType(QualType T);
     730                 : 
     731                 :   void setBuiltinVaListType(QualType T);
     732             3229:   QualType getBuiltinVaListType() const { return BuiltinVaListType; }
     733                 : 
     734                 :   /// getCVRQualifiedType - Returns a type with additional const,
     735                 :   /// volatile, or restrict qualifiers.
     736            11175:   QualType getCVRQualifiedType(QualType T, unsigned CVR) {
     737            11175:     return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
     738                 :   }
     739                 : 
     740                 :   /// getQualifiedType - Returns a type with additional qualifiers.
     741            78752:   QualType getQualifiedType(QualType T, Qualifiers Qs) {
     742            78752:     if (!Qs.hasNonFastQualifiers())
     743            69033:       return T.withFastQualifiers(Qs.getFastQualifiers());
     744             9719:     QualifierCollector Qc(Qs);
     745             9719:     const Type *Ptr = Qc.strip(T);
     746             9719:     return getExtQualType(Ptr, Qc);
     747                 :   }
     748                 : 
     749                 :   /// getQualifiedType - Returns a type with additional qualifiers.
     750                1:   QualType getQualifiedType(const Type *T, Qualifiers Qs) {
     751                1:     if (!Qs.hasNonFastQualifiers())
     752                1:       return QualType(T, Qs.getFastQualifiers());
     753                0:     return getExtQualType(T, Qs);
     754                 :   }
     755                 : 
     756                 :   DeclarationName getNameForTemplate(TemplateName Name);
     757                 : 
     758                 :   TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
     759                 :                                          UnresolvedSetIterator End);
     760                 : 
     761                 :   TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
     762                 :                                         bool TemplateKeyword,
     763                 :                                         TemplateDecl *Template);
     764                 : 
     765                 :   TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
     766                 :                                         const IdentifierInfo *Name);
     767                 :   TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
     768                 :                                         OverloadedOperatorKind Operator);
     769                 : 
     770                 :   enum GetBuiltinTypeError {
     771                 :     GE_None,              //< No error
     772                 :     GE_Missing_stdio,     //< Missing a type from <stdio.h>
     773                 :     GE_Missing_setjmp     //< Missing a type from <setjmp.h>
     774                 :   };
     775                 : 
     776                 :   /// GetBuiltinType - Return the type for the specified builtin.
     777                 :   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error);
     778                 : 
     779                 : private:
     780                 :   CanQualType getFromTargetType(unsigned Type) const;
     781                 : 
     782                 :   //===--------------------------------------------------------------------===//
     783                 :   //                         Type Predicates.
     784                 :   //===--------------------------------------------------------------------===//
     785                 : 
     786                 : public:
     787                 :   /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
     788                 :   /// garbage collection attribute.
     789                 :   ///
     790                 :   Qualifiers::GC getObjCGCAttrKind(const QualType &Ty) const;
     791                 : 
     792                 :   /// isObjCNSObjectType - Return true if this is an NSObject object with
     793                 :   /// its NSObject attribute set.
     794                 :   bool isObjCNSObjectType(QualType Ty) const;
     795                 : 
     796                 :   //===--------------------------------------------------------------------===//
     797                 :   //                         Type Sizing and Analysis
     798                 :   //===--------------------------------------------------------------------===//
     799                 : 
     800                 :   /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified
     801                 :   /// scalar floating point type.
     802                 :   const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
     803                 : 
     804                 :   /// getTypeInfo - Get the size and alignment of the specified complete type in
     805                 :   /// bits.
     806                 :   std::pair<uint64_t, unsigned> getTypeInfo(const Type *T);
     807           107574:   std::pair<uint64_t, unsigned> getTypeInfo(QualType T) {
     808           107574:     return getTypeInfo(T.getTypePtr());
     809                 :   }
     810                 : 
     811                 :   /// getTypeSize - Return the size of the specified type, in bits.  This method
     812                 :   /// does not work on incomplete types.
     813            97001:   uint64_t getTypeSize(QualType T) {
     814            97001:     return getTypeInfo(T).first;
     815                 :   }
     816              182:   uint64_t getTypeSize(const Type *T) {
     817              182:     return getTypeInfo(T).first;
     818                 :   }
     819                 : 
     820                 :   /// getCharWidth - Return the size of the character type, in bits
     821             6450:   uint64_t getCharWidth() {
     822             6450:     return getTypeSize(CharTy);
     823                 :   }
     824                 :   
     825                 :   /// getTypeSizeInChars - Return the size of the specified type, in characters.
     826                 :   /// This method does not work on incomplete types.
     827                 :   CharUnits getTypeSizeInChars(QualType T);
     828                 :   CharUnits getTypeSizeInChars(const Type *T);
     829                 : 
     830                 :   /// getTypeAlign - Return the ABI-specified alignment of a type, in bits.
     831                 :   /// This method does not work on incomplete types.
     832             3567:   unsigned getTypeAlign(QualType T) {
     833             3567:     return getTypeInfo(T).second;
     834                 :   }
     835             2296:   unsigned getTypeAlign(const Type *T) {
     836             2296:     return getTypeInfo(T).second;
     837                 :   }
     838                 : 
     839                 :   /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in 
     840                 :   /// characters. This method does not work on incomplete types.
     841                 :   CharUnits getTypeAlignInChars(QualType T);
     842                 :   CharUnits getTypeAlignInChars(const Type *T);
     843                 : 
     844                 :   /// getPreferredTypeAlign - Return the "preferred" alignment of the specified
     845                 :   /// type for the current target in bits.  This can be different than the ABI
     846                 :   /// alignment in cases where it is beneficial for performance to overalign
     847                 :   /// a data type.
     848                 :   unsigned getPreferredTypeAlign(const Type *T);
     849                 : 
     850                 :   /// getDeclAlign - Return a conservative estimate of the alignment of
     851                 :   /// the specified decl.  Note that bitfields do not have a valid alignment, so
     852                 :   /// this method will assert on them.
     853                 :   /// If @p RefAsPointee, references are treated like their underlying type
     854                 :   /// (for alignof), else they're treated like pointers (for CodeGen).
     855                 :   CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false);
     856                 : 
     857                 :   /// getASTRecordLayout - Get or compute information about the layout of the
     858                 :   /// specified record (struct/union/class), which indicates its size and field
     859                 :   /// position information.
     860                 :   const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D);
     861                 : 
     862                 :   /// getASTObjCInterfaceLayout - Get or compute information about the
     863                 :   /// layout of the specified Objective-C interface.
     864                 :   const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D);
     865                 : 
     866                 :   /// getASTObjCImplementationLayout - Get or compute information about
     867                 :   /// the layout of the specified Objective-C implementation. This may
     868                 :   /// differ from the interface if synthesized ivars are present.
     869                 :   const ASTRecordLayout &
     870                 :   getASTObjCImplementationLayout(const ObjCImplementationDecl *D);
     871                 : 
     872                 :   /// getKeyFunction - Get the key function for the given record decl. 
     873                 :   /// The key function is, according to the Itanium C++ ABI section 5.2.3:
     874                 :   ///
     875                 :   /// ...the first non-pure virtual function that is not inline at the point
     876                 :   /// of class definition.
     877                 :   const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD);
     878                 : 
     879                 :   void CollectObjCIvars(const ObjCInterfaceDecl *OI,
     880                 :                         llvm::SmallVectorImpl<FieldDecl*> &Fields);
     881                 : 
     882                 :   void ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
     883                 :                                llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
     884                 :                                bool CollectSynthesized = true);
     885                 :   void CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
     886                 :                                llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
     887                 :   void CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
     888                 :                                llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
     889                 :   unsigned CountSynthesizedIvars(const ObjCInterfaceDecl *OI);
     890                 :   unsigned CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD);
     891                 :   void CollectInheritedProtocols(const Decl *CDecl,
     892                 :                           llvm::SmallVectorImpl<ObjCProtocolDecl*> &Protocols);
     893                 : 
     894                 :   //===--------------------------------------------------------------------===//
     895                 :   //                            Type Operators
     896                 :   //===--------------------------------------------------------------------===//
     897                 : 
     898                 :   /// getCanonicalType - Return the canonical (structural) type corresponding to
     899                 :   /// the specified potentially non-canonical type.  The non-canonical version
     900                 :   /// of a type may have many "decorated" versions of types.  Decorators can
     901                 :   /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
     902                 :   /// to be free of any of these, allowing two canonical types to be compared
     903                 :   /// for exact equality with a simple pointer comparison.
     904                 :   CanQualType getCanonicalType(QualType T);
     905              654:   const Type *getCanonicalType(const Type *T) {
     906              654:     return T->getCanonicalTypeInternal().getTypePtr();
     907                 :   }
     908                 : 
     909                 :   /// getCanonicalParamType - Return the canonical parameter type
     910                 :   /// corresponding to the specific potentially non-canonical one.
     911                 :   /// Qualifiers are stripped off, functions are turned into function
     912                 :   /// pointers, and arrays decay one level into pointers.
     913                 :   CanQualType getCanonicalParamType(QualType T);
     914                 : 
     915                 :   /// \brief Determine whether the given types are equivalent.
     916            24260:   bool hasSameType(QualType T1, QualType T2) {
     917            24260:     return getCanonicalType(T1) == getCanonicalType(T2);
     918                 :   }
     919                 : 
     920                 :   /// \brief Returns this type as a completely-unqualified array type,
     921                 :   /// capturing the qualifiers in Quals. This will remove the minimal amount of
     922                 :   /// sugaring from the types, similar to the behavior of
     923                 :   /// QualType::getUnqualifiedType().
     924                 :   ///
     925                 :   /// \param T is the qualified type, which may be an ArrayType
     926                 :   ///
     927                 :   /// \param Quals will receive the full set of qualifiers that were
     928                 :   /// applied to the array.
     929                 :   ///
     930                 :   /// \returns if this is an array type, the completely unqualified array type
     931                 :   /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
     932                 :   QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
     933                 : 
     934                 :   /// \brief Determine whether the given types are equivalent after
     935                 :   /// cvr-qualifiers have been removed.
     936            67282:   bool hasSameUnqualifiedType(QualType T1, QualType T2) {
     937            67282:     CanQualType CT1 = getCanonicalType(T1);
     938            67282:     CanQualType CT2 = getCanonicalType(T2);
     939                 : 
     940            67282:     Qualifiers Quals;
     941            67282:     QualType UnqualT1 = getUnqualifiedArrayType(CT1, Quals);
     942            67282:     QualType UnqualT2 = getUnqualifiedArrayType(CT2, Quals);
     943            67282:     return UnqualT1 == UnqualT2;
     944                 :   }
     945                 : 
     946                 :   /// \brief Retrieves the "canonical" declaration of
     947                 : 
     948                 :   /// \brief Retrieves the "canonical" nested name specifier for a
     949                 :   /// given nested name specifier.
     950                 :   ///
     951                 :   /// The canonical nested name specifier is a nested name specifier
     952                 :   /// that uniquely identifies a type or namespace within the type
     953                 :   /// system. For example, given:
     954                 :   ///
     955                 :   /// \code
     956                 :   /// namespace N {
     957                 :   ///   struct S {
     958                 :   ///     template<typename T> struct X { typename T* type; };
     959                 :   ///   };
     960                 :   /// }
     961                 :   ///
     962                 :   /// template<typename T> struct Y {
     963                 :   ///   typename N::S::X<T>::type member;
     964                 :   /// };
     965                 :   /// \endcode
     966                 :   ///
     967                 :   /// Here, the nested-name-specifier for N::S::X<T>:: will be
     968                 :   /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined
     969                 :   /// by declarations in the type system and the canonical type for
     970                 :   /// the template type parameter 'T' is template-param-0-0.
     971                 :   NestedNameSpecifier *
     972                 :   getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS);
     973                 : 
     974                 :   /// \brief Retrieves the canonical representation of the given
     975                 :   /// calling convention.
     976            23420:   CallingConv getCanonicalCallConv(CallingConv CC) {
     977            23420:     if (CC == CC_C)
     978                4:       return CC_Default;
     979            23416:     return CC;
     980                 :   }
     981                 : 
     982                 :   /// \brief Determines whether two calling conventions name the same
     983                 :   /// calling convention.
     984              919:   bool isSameCallConv(CallingConv lcc, CallingConv rcc) {
     985              919:     return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc));
     986                 :   }
     987                 : 
     988                 :   /// \brief Retrieves the "canonical" template name that refers to a
     989                 :   /// given template.
     990                 :   ///
     991                 :   /// The canonical template name is the simplest expression that can
     992                 :   /// be used to refer to a given template. For most templates, this
     993                 :   /// expression is just the template declaration itself. For example,
     994                 :   /// the template std::vector can be referred to via a variety of
     995                 :   /// names---std::vector, ::std::vector, vector (if vector is in
     996                 :   /// scope), etc.---but all of these names map down to the same
     997                 :   /// TemplateDecl, which is used to form the canonical template name.
     998                 :   ///
     999                 :   /// Dependent template names are more interesting. Here, the
    1000                 :   /// template name could be something like T::template apply or
    1001                 :   /// std::allocator<T>::template rebind, where the nested name
    1002                 :   /// specifier itself is dependent. In this case, the canonical
    1003                 :   /// template name uses the shortest form of the dependent
    1004                 :   /// nested-name-specifier, which itself contains all canonical
    1005                 :   /// types, values, and templates.
    1006                 :   TemplateName getCanonicalTemplateName(TemplateName Name);
    1007                 : 
    1008                 :   /// \brief Determine whether the given template names refer to the same
    1009                 :   /// template.
    1010                 :   bool hasSameTemplateName(TemplateName X, TemplateName Y);
    1011                 :   
    1012                 :   /// \brief Retrieve the "canonical" template argument.
    1013                 :   ///
    1014                 :   /// The canonical template argument is the simplest template argument
    1015                 :   /// (which may be a type, value, expression, or declaration) that
    1016                 :   /// expresses the value of the argument.
    1017                 :   TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg);
    1018                 : 
    1019                 :   /// Type Query functions.  If the type is an instance of the specified class,
    1020                 :   /// return the Type pointer for the underlying maximally pretty type.  This
    1021                 :   /// is a member of ASTContext because this may need to do some amount of
    1022                 :   /// canonicalization, e.g. to move type qualifiers into the element type.
    1023                 :   const ArrayType *getAsArrayType(QualType T);
    1024             9700:   const ConstantArrayType *getAsConstantArrayType(QualType T) {
    1025             9700:     return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
    1026                 :   }
    1027            10934:   const VariableArrayType *getAsVariableArrayType(QualType T) {
    1028            10934:     return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
    1029                 :   }
    1030             7345:   const IncompleteArrayType *getAsIncompleteArrayType(QualType T) {
    1031             7345:     return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
    1032                 :   }
    1033               27:   const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T) {
    1034               27:     return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
    1035                 :   }
    1036                 :   
    1037                 :   /// getBaseElementType - Returns the innermost element type of an array type.
    1038                 :   /// For example, will return "int" for int[m][n]
    1039                 :   QualType getBaseElementType(const ArrayType *VAT);
    1040                 : 
    1041                 :   /// getBaseElementType - Returns the innermost element type of a type
    1042                 :   /// (which needn't actually be an array type).
    1043                 :   QualType getBaseElementType(QualType QT);
    1044                 : 
    1045                 :   /// getConstantArrayElementCount - Returns number of constant array elements.
    1046                 :   uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
    1047                 : 
    1048                 :   /// getArrayDecayedType - Return the properly qualified result of decaying the
    1049                 :   /// specified array type to a pointer.  This operation is non-trivial when
    1050                 :   /// handling typedefs etc.  The canonical type of "T" must be an array type,
    1051                 :   /// this returns a pointer to a properly qualified element of the array.
    1052                 :   ///
    1053                 :   /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
    1054                 :   QualType getArrayDecayedType(QualType T);
    1055                 : 
    1056                 :   /// getPromotedIntegerType - Returns the type that Promotable will
    1057                 :   /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable
    1058                 :   /// integer type.
    1059                 :   QualType getPromotedIntegerType(QualType PromotableType);
    1060                 : 
    1061                 :   /// \brief Whether this is a promotable bitfield reference according
    1062                 :   /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
    1063                 :   ///
    1064                 :   /// \returns the type this bit-field will promote to, or NULL if no
    1065                 :   /// promotion occurs.
    1066                 :   QualType isPromotableBitField(Expr *E);
    1067                 : 
    1068                 :   /// getIntegerTypeOrder - Returns the highest ranked integer type:
    1069                 :   /// C99 6.3.1.8p1.  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
    1070                 :   /// LHS < RHS, return -1.
    1071                 :   int getIntegerTypeOrder(QualType LHS, QualType RHS);
    1072                 : 
    1073                 :   /// getFloatingTypeOrder - Compare the rank of the two specified floating
    1074                 :   /// point types, ignoring the domain of the type (i.e. 'double' ==
    1075                 :   /// '_Complex double').  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
    1076                 :   /// LHS < RHS, return -1.
    1077                 :   int getFloatingTypeOrder(QualType LHS, QualType RHS);
    1078                 : 
    1079                 :   /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
    1080                 :   /// point or a complex type (based on typeDomain/typeSize).
    1081                 :   /// 'typeDomain' is a real floating point or complex type.
    1082                 :   /// 'typeSize' is a real floating point or complex type.
    1083                 :   QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
    1084                 :                                              QualType typeDomain) const;
    1085                 : 
    1086                 : private:
    1087                 :   // Helper for integer ordering
    1088                 :   unsigned getIntegerRank(Type* T);
    1089                 : 
    1090                 : public:
    1091                 : 
    1092                 :   //===--------------------------------------------------------------------===//
    1093                 :   //                    Type Compatibility Predicates
    1094                 :   //===--------------------------------------------------------------------===//
    1095                 : 
    1096                 :   /// Compatibility predicates used to check assignment expressions.
    1097                 :   bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
    1098                 : 
    1099                 :   bool isObjCIdType(QualType T) const {
    1100                 :     return T == ObjCIdTypedefType;
    1101                 :   }
    1102                 :   bool isObjCClassType(QualType T) const {
    1103                 :     return T == ObjCClassTypedefType;
    1104                 :   }
    1105             2395:   bool isObjCSelType(QualType T) const {
    1106             2395:     return T == ObjCSelTypedefType;
    1107                 :   }
    1108                 :   bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
    1109                 :   bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
    1110                 :                                          bool ForCompare);
    1111                 : 
    1112                 :   // Check the safety of assignment from LHS to RHS
    1113                 :   bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
    1114                 :                                const ObjCObjectPointerType *RHSOPT);
    1115                 :   bool canAssignObjCInterfaces(const ObjCInterfaceType *LHS,
    1116                 :                                const ObjCInterfaceType *RHS);
    1117                 :   bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
    1118                 :   QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
    1119                 :                                    const ObjCObjectPointerType *RHSOPT);
    1120                 :   
    1121                 :   // Functions for calculating composite types
    1122                 :   QualType mergeTypes(QualType, QualType);
    1123                 :   QualType mergeFunctionTypes(QualType, QualType);
    1124                 : 
    1125                 :   /// UsualArithmeticConversionsType - handles the various conversions
    1126                 :   /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
    1127                 :   /// and returns the result type of that conversion.
    1128                 :   QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
    1129                 : 
    1130                 :   //===--------------------------------------------------------------------===//
    1131                 :   //                    Integer Predicates
    1132                 :   //===--------------------------------------------------------------------===//
    1133                 : 
    1134                 :   // The width of an integer, as defined in C99 6.2.6.2. This is the number
    1135                 :   // of bits in an integer type excluding any padding bits.
    1136                 :   unsigned getIntWidth(QualType T);
    1137                 : 
    1138                 :   // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
    1139                 :   // unsigned integer type.  This method takes a signed type, and returns the
    1140                 :   // corresponding unsigned integer type.
    1141                 :   QualType getCorrespondingUnsignedType(QualType T);
    1142                 : 
    1143                 :   //===--------------------------------------------------------------------===//
    1144                 :   //                    Type Iterators.
    1145                 :   //===--------------------------------------------------------------------===//
    1146                 : 
    1147                 :   typedef std::vector<Type*>::iterator       type_iterator;
    1148                 :   typedef std::vector<Type*>::const_iterator const_type_iterator;
    1149                 : 
    1150                1:   type_iterator types_begin() { return Types.begin(); }
    1151                1:   type_iterator types_end() { return Types.end(); }
    1152                 :   const_type_iterator types_begin() const { return Types.begin(); }
    1153                 :   const_type_iterator types_end() const { return Types.end(); }
    1154                 : 
    1155                 :   //===--------------------------------------------------------------------===//
    1156                 :   //                    Integer Values
    1157                 :   //===--------------------------------------------------------------------===//
    1158                 : 
    1159                 :   /// MakeIntValue - Make an APSInt of the appropriate width and
    1160                 :   /// signedness for the given \arg Value and integer \arg Type.
    1161             2779:   llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) {
    1162             2779:     llvm::APSInt Res(getIntWidth(Type), !Type->isSignedIntegerType());
    1163             2779:     Res = Value;
    1164                 :     return Res;
    1165                 :   }
    1166                 : 
    1167                 :   /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists.
    1168                 :   ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
    1169                 :   /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists.
    1170                 :   ObjCCategoryImplDecl   *getObjCImplementation(ObjCCategoryDecl *D);
    1171                 : 
    1172                 :   /// \brief Set the implementation of ObjCInterfaceDecl.
    1173                 :   void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
    1174                 :                              ObjCImplementationDecl *ImplD);
    1175                 :   /// \brief Set the implementation of ObjCCategoryDecl.
    1176                 :   void setObjCImplementation(ObjCCategoryDecl *CatD,
    1177                 :                              ObjCCategoryImplDecl *ImplD);
    1178                 : 
    1179                 :   /// \brief Allocate an uninitialized TypeSourceInfo.
    1180                 :   ///
    1181                 :   /// The caller should initialize the memory held by TypeSourceInfo using
    1182                 :   /// the TypeLoc wrappers.
    1183                 :   ///
    1184                 :   /// \param T the type that will be the basis for type source info. This type
    1185                 :   /// should refer to how the declarator was written in source code, not to
    1186                 :   /// what type semantic analysis resolved the declarator to.
    1187                 :   ///
    1188                 :   /// \param Size the size of the type info to create, or 0 if the size
    1189                 :   /// should be calculated based on the type.
    1190                 :   TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0);
    1191                 : 
    1192                 :   /// \brief Allocate a TypeSourceInfo where all locations have been
    1193                 :   /// initialized to a given location, which defaults to the empty
    1194                 :   /// location.
    1195                 :   TypeSourceInfo *
    1196                 :   getTrivialTypeSourceInfo(QualType T, SourceLocation Loc = SourceLocation());
    1197                 : 
    1198                 : private:
    1199                 :   ASTContext(const ASTContext&); // DO NOT IMPLEMENT
    1200                 :   void operator=(const ASTContext&); // DO NOT IMPLEMENT
    1201                 : 
    1202                 :   void InitBuiltinTypes();
    1203                 :   void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
    1204                 : 
    1205                 :   // Return the ObjC type encoding for a given type.
    1206                 :   void getObjCEncodingForTypeImpl(QualType t, std::string &S,
    1207                 :                                   bool ExpandPointedToStructures,
    1208                 :                                   bool ExpandStructures,
    1209                 :                                   const FieldDecl *Field,
    1210                 :                                   bool OutermostType = false,
    1211                 :                                   bool EncodingProperty = false);
    1212                 : 
    1213                 :   const ASTRecordLayout &getObjCLayout(const ObjCInterfaceDecl *D,
    1214                 :                                        const ObjCImplementationDecl *Impl);
    1215                 : };
    1216                 :   
    1217                 : /// @brief Utility function for constructing a nullary selector.
    1218            47466: static inline Selector GetNullarySelector(const char* name, ASTContext& Ctx) {
    1219            47466:   IdentifierInfo* II = &Ctx.Idents.get(name);
    1220            47466:   return Ctx.Selectors.getSelector(0, &II);
    1221                 : }
    1222                 : 
    1223                 : /// @brief Utility function for constructing an unary selector.
    1224             4276: static inline Selector GetUnarySelector(const char* name, ASTContext& Ctx) {
    1225             4276:   IdentifierInfo* II = &Ctx.Idents.get(name);
    1226             4276:   return Ctx.Selectors.getSelector(1, &II);
    1227                 : }
    1228                 : 
    1229                 : }  // end namespace clang
    1230                 : 
    1231                 : // operator new and delete aren't allowed inside namespaces.
    1232                 : // The throw specifications are mandated by the standard.
    1233                 : /// @brief Placement new for using the ASTContext's allocator.
    1234                 : ///
    1235                 : /// This placement form of operator new uses the ASTContext's allocator for
    1236                 : /// obtaining memory. It is a non-throwing new, which means that it returns
    1237                 : /// null on error. (If that is what the allocator does. The current does, so if
    1238                 : /// this ever changes, this operator will have to be changed, too.)
    1239                 : /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
    1240                 : /// @code
    1241                 : /// // Default alignment (16)
    1242                 : /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
    1243                 : /// // Specific alignment
    1244                 : /// IntegerLiteral *Ex2 = new (Context, 8) IntegerLiteral(arguments);
    1245                 : /// @endcode
    1246                 : /// Please note that you cannot use delete on the pointer; it must be
    1247                 : /// deallocated using an explicit destructor call followed by
    1248                 : /// @c Context.Deallocate(Ptr).
    1249                 : ///
    1250                 : /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
    1251                 : /// @param C The ASTContext that provides the allocator.
    1252                 : /// @param Alignment The alignment of the allocated memory (if the underlying
    1253                 : ///                  allocator supports it).
    1254                 : /// @return The allocated memory. Could be NULL.
    1255                 : inline void *operator new(size_t Bytes, clang::ASTContext &C,
    1256           368701:                           size_t Alignment) throw () {
    1257           368701:   return C.Allocate(Bytes, Alignment);
    1258                 : }
    1259                 : /// @brief Placement delete companion to the new above.
    1260                 : ///
    1261                 : /// This operator is just a companion to the new above. There is no way of
    1262                 : /// invoking it directly; see the new operator for more details. This operator
    1263                 : /// is called implicitly by the compiler if a placement new expression using
    1264                 : /// the ASTContext throws in the object constructor.
    1265                 : inline void operator delete(void *Ptr, clang::ASTContext &C, size_t)
    1266                 :               throw () {
    1267                 :   C.Deallocate(Ptr);
    1268                 : }
    1269                 : 
    1270                 : /// This placement form of operator new[] uses the ASTContext's allocator for
    1271                 : /// obtaining memory. It is a non-throwing new[], which means that it returns
    1272                 : /// null on error.
    1273                 : /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
    1274                 : /// @code
    1275                 : /// // Default alignment (16)
    1276                 : /// char *data = new (Context) char[10];
    1277                 : /// // Specific alignment
    1278                 : /// char *data = new (Context, 8) char[10];
    1279                 : /// @endcode
    1280                 : /// Please note that you cannot use delete on the pointer; it must be
    1281                 : /// deallocated using an explicit destructor call followed by
    1282                 : /// @c Context.Deallocate(Ptr).
    1283                 : ///
    1284                 : /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
    1285                 : /// @param C The ASTContext that provides the allocator.
    1286                 : /// @param Alignment The alignment of the allocated memory (if the underlying
    1287                 : ///                  allocator supports it).
    1288                 : /// @return The allocated memory. Could be NULL.
    1289                 : inline void *operator new[](size_t Bytes, clang::ASTContext& C,
    1290            33681:                             size_t Alignment = 16) throw () {
    1291            33681:   return C.Allocate(Bytes, Alignment);
    1292                 : }
    1293                 : 
    1294                 : /// @brief Placement delete[] companion to the new[] above.
    1295                 : ///
    1296                 : /// This operator is just a companion to the new[] above. There is no way of
    1297                 : /// invoking it directly; see the new[] operator for more details. This operator
    1298                 : /// is called implicitly by the compiler if a placement new[] expression using
    1299                 : /// the ASTContext throws in the object constructor.
    1300                 : inline void operator delete[](void *Ptr, clang::ASTContext &C, size_t)
    1301                 :               throw () {
    1302                 :   C.Deallocate(Ptr);
    1303                 : }
    1304                 : 
    1305                 : #endif

Generated: 2010-02-10 01:31 by zcov