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