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