clang API Documentation
00001 //===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 /// 00010 /// \file 00011 /// \brief Defines the clang::ASTContext interface. 00012 /// 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CLANG_AST_ASTCONTEXT_H 00016 #define LLVM_CLANG_AST_ASTCONTEXT_H 00017 00018 #include "clang/AST/ASTTypeTraits.h" 00019 #include "clang/AST/CanonicalType.h" 00020 #include "clang/AST/CommentCommandTraits.h" 00021 #include "clang/AST/Decl.h" 00022 #include "clang/AST/ExternalASTSource.h" 00023 #include "clang/AST/NestedNameSpecifier.h" 00024 #include "clang/AST/PrettyPrinter.h" 00025 #include "clang/AST/RawCommentList.h" 00026 #include "clang/AST/TemplateName.h" 00027 #include "clang/AST/Type.h" 00028 #include "clang/Basic/AddressSpaces.h" 00029 #include "clang/Basic/IdentifierTable.h" 00030 #include "clang/Basic/LangOptions.h" 00031 #include "clang/Basic/OperatorKinds.h" 00032 #include "clang/Basic/PartialDiagnostic.h" 00033 #include "clang/Basic/SanitizerBlacklist.h" 00034 #include "clang/Basic/VersionTuple.h" 00035 #include "llvm/ADT/DenseMap.h" 00036 #include "llvm/ADT/FoldingSet.h" 00037 #include "llvm/ADT/IntrusiveRefCntPtr.h" 00038 #include "llvm/ADT/SmallPtrSet.h" 00039 #include "llvm/ADT/TinyPtrVector.h" 00040 #include "llvm/Support/Allocator.h" 00041 #include <memory> 00042 #include <vector> 00043 00044 namespace llvm { 00045 struct fltSemantics; 00046 } 00047 00048 namespace clang { 00049 class FileManager; 00050 class AtomicExpr; 00051 class ASTRecordLayout; 00052 class BlockExpr; 00053 class CharUnits; 00054 class DiagnosticsEngine; 00055 class Expr; 00056 class ASTMutationListener; 00057 class IdentifierTable; 00058 class MaterializeTemporaryExpr; 00059 class SelectorTable; 00060 class TargetInfo; 00061 class CXXABI; 00062 class MangleNumberingContext; 00063 // Decls 00064 class MangleContext; 00065 class ObjCIvarDecl; 00066 class ObjCPropertyDecl; 00067 class UnresolvedSetIterator; 00068 class UsingDecl; 00069 class UsingShadowDecl; 00070 class VTableContextBase; 00071 00072 namespace Builtin { class Context; } 00073 00074 namespace comments { 00075 class FullComment; 00076 } 00077 00078 struct TypeInfo { 00079 uint64_t Width; 00080 unsigned Align; 00081 bool AlignIsRequired : 1; 00082 TypeInfo() : Width(0), Align(0), AlignIsRequired(false) {} 00083 TypeInfo(uint64_t Width, unsigned Align, bool AlignIsRequired) 00084 : Width(Width), Align(Align), AlignIsRequired(AlignIsRequired) {} 00085 }; 00086 00087 /// \brief Holds long-lived AST nodes (such as types and decls) that can be 00088 /// referred to throughout the semantic analysis of a file. 00089 class ASTContext : public RefCountedBase<ASTContext> { 00090 ASTContext &this_() { return *this; } 00091 00092 mutable SmallVector<Type *, 0> Types; 00093 mutable llvm::FoldingSet<ExtQuals> ExtQualNodes; 00094 mutable llvm::FoldingSet<ComplexType> ComplexTypes; 00095 mutable llvm::FoldingSet<PointerType> PointerTypes; 00096 mutable llvm::FoldingSet<AdjustedType> AdjustedTypes; 00097 mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes; 00098 mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes; 00099 mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes; 00100 mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes; 00101 mutable llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes; 00102 mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes; 00103 mutable std::vector<VariableArrayType*> VariableArrayTypes; 00104 mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes; 00105 mutable llvm::FoldingSet<DependentSizedExtVectorType> 00106 DependentSizedExtVectorTypes; 00107 mutable llvm::FoldingSet<VectorType> VectorTypes; 00108 mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes; 00109 mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&> 00110 FunctionProtoTypes; 00111 mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes; 00112 mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes; 00113 mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes; 00114 mutable llvm::FoldingSet<SubstTemplateTypeParmType> 00115 SubstTemplateTypeParmTypes; 00116 mutable llvm::FoldingSet<SubstTemplateTypeParmPackType> 00117 SubstTemplateTypeParmPackTypes; 00118 mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&> 00119 TemplateSpecializationTypes; 00120 mutable llvm::FoldingSet<ParenType> ParenTypes; 00121 mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes; 00122 mutable llvm::FoldingSet<DependentNameType> DependentNameTypes; 00123 mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType, 00124 ASTContext&> 00125 DependentTemplateSpecializationTypes; 00126 llvm::FoldingSet<PackExpansionType> PackExpansionTypes; 00127 mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes; 00128 mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes; 00129 mutable llvm::FoldingSet<AutoType> AutoTypes; 00130 mutable llvm::FoldingSet<AtomicType> AtomicTypes; 00131 llvm::FoldingSet<AttributedType> AttributedTypes; 00132 00133 mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames; 00134 mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames; 00135 mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage> 00136 SubstTemplateTemplateParms; 00137 mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage, 00138 ASTContext&> 00139 SubstTemplateTemplateParmPacks; 00140 00141 /// \brief The set of nested name specifiers. 00142 /// 00143 /// This set is managed by the NestedNameSpecifier class. 00144 mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers; 00145 mutable NestedNameSpecifier *GlobalNestedNameSpecifier; 00146 friend class NestedNameSpecifier; 00147 00148 /// \brief A cache mapping from RecordDecls to ASTRecordLayouts. 00149 /// 00150 /// This is lazily created. This is intentionally not serialized. 00151 mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> 00152 ASTRecordLayouts; 00153 mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*> 00154 ObjCLayouts; 00155 00156 /// \brief A cache from types to size and alignment information. 00157 typedef llvm::DenseMap<const Type *, struct TypeInfo> TypeInfoMap; 00158 mutable TypeInfoMap MemoizedTypeInfo; 00159 00160 /// \brief A cache mapping from CXXRecordDecls to key functions. 00161 llvm::DenseMap<const CXXRecordDecl*, LazyDeclPtr> KeyFunctions; 00162 00163 /// \brief Mapping from ObjCContainers to their ObjCImplementations. 00164 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls; 00165 00166 /// \brief Mapping from ObjCMethod to its duplicate declaration in the same 00167 /// interface. 00168 llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls; 00169 00170 /// \brief Mapping from __block VarDecls to their copy initialization expr. 00171 llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits; 00172 00173 /// \brief Mapping from class scope functions specialization to their 00174 /// template patterns. 00175 llvm::DenseMap<const FunctionDecl*, FunctionDecl*> 00176 ClassScopeSpecializationPattern; 00177 00178 /// \brief Mapping from materialized temporaries with static storage duration 00179 /// that appear in constant initializers to their evaluated values. 00180 llvm::DenseMap<const MaterializeTemporaryExpr*, APValue> 00181 MaterializedTemporaryValues; 00182 00183 /// \brief Representation of a "canonical" template template parameter that 00184 /// is used in canonical template names. 00185 class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode { 00186 TemplateTemplateParmDecl *Parm; 00187 00188 public: 00189 CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm) 00190 : Parm(Parm) { } 00191 00192 TemplateTemplateParmDecl *getParam() const { return Parm; } 00193 00194 void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); } 00195 00196 static void Profile(llvm::FoldingSetNodeID &ID, 00197 TemplateTemplateParmDecl *Parm); 00198 }; 00199 mutable llvm::FoldingSet<CanonicalTemplateTemplateParm> 00200 CanonTemplateTemplateParms; 00201 00202 TemplateTemplateParmDecl * 00203 getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const; 00204 00205 /// \brief The typedef for the __int128_t type. 00206 mutable TypedefDecl *Int128Decl; 00207 00208 /// \brief The typedef for the __uint128_t type. 00209 mutable TypedefDecl *UInt128Decl; 00210 00211 /// \brief The typedef for the __float128 stub type. 00212 mutable TypeDecl *Float128StubDecl; 00213 00214 /// \brief The typedef for the target specific predefined 00215 /// __builtin_va_list type. 00216 mutable TypedefDecl *BuiltinVaListDecl; 00217 00218 /// \brief The typedef for the predefined \c id type. 00219 mutable TypedefDecl *ObjCIdDecl; 00220 00221 /// \brief The typedef for the predefined \c SEL type. 00222 mutable TypedefDecl *ObjCSelDecl; 00223 00224 /// \brief The typedef for the predefined \c Class type. 00225 mutable TypedefDecl *ObjCClassDecl; 00226 00227 /// \brief The typedef for the predefined \c Protocol class in Objective-C. 00228 mutable ObjCInterfaceDecl *ObjCProtocolClassDecl; 00229 00230 /// \brief The typedef for the predefined 'BOOL' type. 00231 mutable TypedefDecl *BOOLDecl; 00232 00233 // Typedefs which may be provided defining the structure of Objective-C 00234 // pseudo-builtins 00235 QualType ObjCIdRedefinitionType; 00236 QualType ObjCClassRedefinitionType; 00237 QualType ObjCSelRedefinitionType; 00238 00239 QualType ObjCConstantStringType; 00240 mutable RecordDecl *CFConstantStringTypeDecl; 00241 00242 mutable QualType ObjCSuperType; 00243 00244 QualType ObjCNSStringType; 00245 00246 /// \brief The typedef declaration for the Objective-C "instancetype" type. 00247 TypedefDecl *ObjCInstanceTypeDecl; 00248 00249 /// \brief The type for the C FILE type. 00250 TypeDecl *FILEDecl; 00251 00252 /// \brief The type for the C jmp_buf type. 00253 TypeDecl *jmp_bufDecl; 00254 00255 /// \brief The type for the C sigjmp_buf type. 00256 TypeDecl *sigjmp_bufDecl; 00257 00258 /// \brief The type for the C ucontext_t type. 00259 TypeDecl *ucontext_tDecl; 00260 00261 /// \brief Type for the Block descriptor for Blocks CodeGen. 00262 /// 00263 /// Since this is only used for generation of debug info, it is not 00264 /// serialized. 00265 mutable RecordDecl *BlockDescriptorType; 00266 00267 /// \brief Type for the Block descriptor for Blocks CodeGen. 00268 /// 00269 /// Since this is only used for generation of debug info, it is not 00270 /// serialized. 00271 mutable RecordDecl *BlockDescriptorExtendedType; 00272 00273 /// \brief Declaration for the CUDA cudaConfigureCall function. 00274 FunctionDecl *cudaConfigureCallDecl; 00275 00276 TypeSourceInfo NullTypeSourceInfo; 00277 00278 /// \brief Keeps track of all declaration attributes. 00279 /// 00280 /// Since so few decls have attrs, we keep them in a hash map instead of 00281 /// wasting space in the Decl class. 00282 llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs; 00283 00284 /// \brief A mapping from non-redeclarable declarations in modules that were 00285 /// merged with other declarations to the canonical declaration that they were 00286 /// merged into. 00287 llvm::DenseMap<Decl*, Decl*> MergedDecls; 00288 00289 public: 00290 /// \brief A type synonym for the TemplateOrInstantiation mapping. 00291 typedef llvm::PointerUnion<VarTemplateDecl *, MemberSpecializationInfo *> 00292 TemplateOrSpecializationInfo; 00293 00294 private: 00295 00296 /// \brief A mapping to contain the template or declaration that 00297 /// a variable declaration describes or was instantiated from, 00298 /// respectively. 00299 /// 00300 /// For non-templates, this value will be NULL. For variable 00301 /// declarations that describe a variable template, this will be a 00302 /// pointer to a VarTemplateDecl. For static data members 00303 /// of class template specializations, this will be the 00304 /// MemberSpecializationInfo referring to the member variable that was 00305 /// instantiated or specialized. Thus, the mapping will keep track of 00306 /// the static data member templates from which static data members of 00307 /// class template specializations were instantiated. 00308 /// 00309 /// Given the following example: 00310 /// 00311 /// \code 00312 /// template<typename T> 00313 /// struct X { 00314 /// static T value; 00315 /// }; 00316 /// 00317 /// template<typename T> 00318 /// T X<T>::value = T(17); 00319 /// 00320 /// int *x = &X<int>::value; 00321 /// \endcode 00322 /// 00323 /// This mapping will contain an entry that maps from the VarDecl for 00324 /// X<int>::value to the corresponding VarDecl for X<T>::value (within the 00325 /// class template X) and will be marked TSK_ImplicitInstantiation. 00326 llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo> 00327 TemplateOrInstantiation; 00328 00329 /// \brief Keeps track of the declaration from which a UsingDecl was 00330 /// created during instantiation. 00331 /// 00332 /// The source declaration is always a UsingDecl, an UnresolvedUsingValueDecl, 00333 /// or an UnresolvedUsingTypenameDecl. 00334 /// 00335 /// For example: 00336 /// \code 00337 /// template<typename T> 00338 /// struct A { 00339 /// void f(); 00340 /// }; 00341 /// 00342 /// template<typename T> 00343 /// struct B : A<T> { 00344 /// using A<T>::f; 00345 /// }; 00346 /// 00347 /// template struct B<int>; 00348 /// \endcode 00349 /// 00350 /// This mapping will contain an entry that maps from the UsingDecl in 00351 /// B<int> to the UnresolvedUsingDecl in B<T>. 00352 llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl; 00353 00354 llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*> 00355 InstantiatedFromUsingShadowDecl; 00356 00357 llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl; 00358 00359 /// \brief Mapping that stores the methods overridden by a given C++ 00360 /// member function. 00361 /// 00362 /// Since most C++ member functions aren't virtual and therefore 00363 /// don't override anything, we store the overridden functions in 00364 /// this map on the side rather than within the CXXMethodDecl structure. 00365 typedef llvm::TinyPtrVector<const CXXMethodDecl*> CXXMethodVector; 00366 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods; 00367 00368 /// \brief Mapping from each declaration context to its corresponding 00369 /// mangling numbering context (used for constructs like lambdas which 00370 /// need to be consistently numbered for the mangler). 00371 llvm::DenseMap<const DeclContext *, MangleNumberingContext *> 00372 MangleNumberingContexts; 00373 00374 /// \brief Side-table of mangling numbers for declarations which rarely 00375 /// need them (like static local vars). 00376 llvm::DenseMap<const NamedDecl *, unsigned> MangleNumbers; 00377 llvm::DenseMap<const VarDecl *, unsigned> StaticLocalNumbers; 00378 00379 /// \brief Mapping that stores parameterIndex values for ParmVarDecls when 00380 /// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex. 00381 typedef llvm::DenseMap<const VarDecl *, unsigned> ParameterIndexTable; 00382 ParameterIndexTable ParamIndices; 00383 00384 ImportDecl *FirstLocalImport; 00385 ImportDecl *LastLocalImport; 00386 00387 TranslationUnitDecl *TUDecl; 00388 00389 /// \brief The associated SourceManager object.a 00390 SourceManager &SourceMgr; 00391 00392 /// \brief The language options used to create the AST associated with 00393 /// this ASTContext object. 00394 LangOptions &LangOpts; 00395 00396 /// \brief Blacklist object that is used by sanitizers to decide which 00397 /// entities should not be instrumented. 00398 std::unique_ptr<SanitizerBlacklist> SanitizerBL; 00399 00400 /// \brief The allocator used to create AST objects. 00401 /// 00402 /// AST objects are never destructed; rather, all memory associated with the 00403 /// AST objects will be released when the ASTContext itself is destroyed. 00404 mutable llvm::BumpPtrAllocator BumpAlloc; 00405 00406 /// \brief Allocator for partial diagnostics. 00407 PartialDiagnostic::StorageAllocator DiagAllocator; 00408 00409 /// \brief The current C++ ABI. 00410 std::unique_ptr<CXXABI> ABI; 00411 CXXABI *createCXXABI(const TargetInfo &T); 00412 00413 /// \brief The logical -> physical address space map. 00414 const LangAS::Map *AddrSpaceMap; 00415 00416 /// \brief Address space map mangling must be used with language specific 00417 /// address spaces (e.g. OpenCL/CUDA) 00418 bool AddrSpaceMapMangling; 00419 00420 friend class ASTDeclReader; 00421 friend class ASTReader; 00422 friend class ASTWriter; 00423 friend class CXXRecordDecl; 00424 00425 const TargetInfo *Target; 00426 clang::PrintingPolicy PrintingPolicy; 00427 00428 public: 00429 IdentifierTable &Idents; 00430 SelectorTable &Selectors; 00431 Builtin::Context &BuiltinInfo; 00432 mutable DeclarationNameTable DeclarationNames; 00433 IntrusiveRefCntPtr<ExternalASTSource> ExternalSource; 00434 ASTMutationListener *Listener; 00435 00436 /// \brief Contains parents of a node. 00437 typedef llvm::SmallVector<ast_type_traits::DynTypedNode, 2> ParentVector; 00438 00439 /// \brief Maps from a node to its parents. 00440 typedef llvm::DenseMap<const void *, 00441 llvm::PointerUnion<ast_type_traits::DynTypedNode *, 00442 ParentVector *>> ParentMap; 00443 00444 /// \brief Returns the parents of the given node. 00445 /// 00446 /// Note that this will lazily compute the parents of all nodes 00447 /// and store them for later retrieval. Thus, the first call is O(n) 00448 /// in the number of AST nodes. 00449 /// 00450 /// Caveats and FIXMEs: 00451 /// Calculating the parent map over all AST nodes will need to load the 00452 /// full AST. This can be undesirable in the case where the full AST is 00453 /// expensive to create (for example, when using precompiled header 00454 /// preambles). Thus, there are good opportunities for optimization here. 00455 /// One idea is to walk the given node downwards, looking for references 00456 /// to declaration contexts - once a declaration context is found, compute 00457 /// the parent map for the declaration context; if that can satisfy the 00458 /// request, loading the whole AST can be avoided. Note that this is made 00459 /// more complex by statements in templates having multiple parents - those 00460 /// problems can be solved by building closure over the templated parts of 00461 /// the AST, which also avoids touching large parts of the AST. 00462 /// Additionally, we will want to add an interface to already give a hint 00463 /// where to search for the parents, for example when looking at a statement 00464 /// inside a certain function. 00465 /// 00466 /// 'NodeT' can be one of Decl, Stmt, Type, TypeLoc, 00467 /// NestedNameSpecifier or NestedNameSpecifierLoc. 00468 template <typename NodeT> 00469 ArrayRef<ast_type_traits::DynTypedNode> getParents(const NodeT &Node) { 00470 return getParents(ast_type_traits::DynTypedNode::create(Node)); 00471 } 00472 00473 ArrayRef<ast_type_traits::DynTypedNode> 00474 getParents(const ast_type_traits::DynTypedNode &Node); 00475 00476 const clang::PrintingPolicy &getPrintingPolicy() const { 00477 return PrintingPolicy; 00478 } 00479 00480 void setPrintingPolicy(const clang::PrintingPolicy &Policy) { 00481 PrintingPolicy = Policy; 00482 } 00483 00484 SourceManager& getSourceManager() { return SourceMgr; } 00485 const SourceManager& getSourceManager() const { return SourceMgr; } 00486 00487 llvm::BumpPtrAllocator &getAllocator() const { 00488 return BumpAlloc; 00489 } 00490 00491 void *Allocate(size_t Size, unsigned Align = 8) const { 00492 return BumpAlloc.Allocate(Size, Align); 00493 } 00494 void Deallocate(void *Ptr) const { } 00495 00496 /// Return the total amount of physical memory allocated for representing 00497 /// AST nodes and type information. 00498 size_t getASTAllocatedMemory() const { 00499 return BumpAlloc.getTotalMemory(); 00500 } 00501 /// Return the total memory used for various side tables. 00502 size_t getSideTableAllocatedMemory() const; 00503 00504 PartialDiagnostic::StorageAllocator &getDiagAllocator() { 00505 return DiagAllocator; 00506 } 00507 00508 const TargetInfo &getTargetInfo() const { return *Target; } 00509 00510 /// getIntTypeForBitwidth - 00511 /// sets integer QualTy according to specified details: 00512 /// bitwidth, signed/unsigned. 00513 /// Returns empty type if there is no appropriate target types. 00514 QualType getIntTypeForBitwidth(unsigned DestWidth, 00515 unsigned Signed) const; 00516 /// getRealTypeForBitwidth - 00517 /// sets floating point QualTy according to specified bitwidth. 00518 /// Returns empty type if there is no appropriate target types. 00519 QualType getRealTypeForBitwidth(unsigned DestWidth) const; 00520 00521 bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const; 00522 00523 const LangOptions& getLangOpts() const { return LangOpts; } 00524 00525 const SanitizerBlacklist &getSanitizerBlacklist() const { 00526 return *SanitizerBL; 00527 } 00528 00529 DiagnosticsEngine &getDiagnostics() const; 00530 00531 FullSourceLoc getFullLoc(SourceLocation Loc) const { 00532 return FullSourceLoc(Loc,SourceMgr); 00533 } 00534 00535 /// \brief All comments in this translation unit. 00536 RawCommentList Comments; 00537 00538 /// \brief True if comments are already loaded from ExternalASTSource. 00539 mutable bool CommentsLoaded; 00540 00541 class RawCommentAndCacheFlags { 00542 public: 00543 enum Kind { 00544 /// We searched for a comment attached to the particular declaration, but 00545 /// didn't find any. 00546 /// 00547 /// getRaw() == 0. 00548 NoCommentInDecl = 0, 00549 00550 /// We have found a comment attached to this particular declaration. 00551 /// 00552 /// getRaw() != 0. 00553 FromDecl, 00554 00555 /// This declaration does not have an attached comment, and we have 00556 /// searched the redeclaration chain. 00557 /// 00558 /// If getRaw() == 0, the whole redeclaration chain does not have any 00559 /// comments. 00560 /// 00561 /// If getRaw() != 0, it is a comment propagated from other 00562 /// redeclaration. 00563 FromRedecl 00564 }; 00565 00566 Kind getKind() const LLVM_READONLY { 00567 return Data.getInt(); 00568 } 00569 00570 void setKind(Kind K) { 00571 Data.setInt(K); 00572 } 00573 00574 const RawComment *getRaw() const LLVM_READONLY { 00575 return Data.getPointer(); 00576 } 00577 00578 void setRaw(const RawComment *RC) { 00579 Data.setPointer(RC); 00580 } 00581 00582 const Decl *getOriginalDecl() const LLVM_READONLY { 00583 return OriginalDecl; 00584 } 00585 00586 void setOriginalDecl(const Decl *Orig) { 00587 OriginalDecl = Orig; 00588 } 00589 00590 private: 00591 llvm::PointerIntPair<const RawComment *, 2, Kind> Data; 00592 const Decl *OriginalDecl; 00593 }; 00594 00595 /// \brief Mapping from declarations to comments attached to any 00596 /// redeclaration. 00597 /// 00598 /// Raw comments are owned by Comments list. This mapping is populated 00599 /// lazily. 00600 mutable llvm::DenseMap<const Decl *, RawCommentAndCacheFlags> RedeclComments; 00601 00602 /// \brief Mapping from declarations to parsed comments attached to any 00603 /// redeclaration. 00604 mutable llvm::DenseMap<const Decl *, comments::FullComment *> ParsedComments; 00605 00606 /// \brief Return the documentation comment attached to a given declaration, 00607 /// without looking into cache. 00608 RawComment *getRawCommentForDeclNoCache(const Decl *D) const; 00609 00610 public: 00611 RawCommentList &getRawCommentList() { 00612 return Comments; 00613 } 00614 00615 void addComment(const RawComment &RC) { 00616 assert(LangOpts.RetainCommentsFromSystemHeaders || 00617 !SourceMgr.isInSystemHeader(RC.getSourceRange().getBegin())); 00618 Comments.addComment(RC, BumpAlloc); 00619 } 00620 00621 /// \brief Return the documentation comment attached to a given declaration. 00622 /// Returns NULL if no comment is attached. 00623 /// 00624 /// \param OriginalDecl if not NULL, is set to declaration AST node that had 00625 /// the comment, if the comment we found comes from a redeclaration. 00626 const RawComment * 00627 getRawCommentForAnyRedecl(const Decl *D, 00628 const Decl **OriginalDecl = nullptr) const; 00629 00630 /// Return parsed documentation comment attached to a given declaration. 00631 /// Returns NULL if no comment is attached. 00632 /// 00633 /// \param PP the Preprocessor used with this TU. Could be NULL if 00634 /// preprocessor is not available. 00635 comments::FullComment *getCommentForDecl(const Decl *D, 00636 const Preprocessor *PP) const; 00637 00638 /// Return parsed documentation comment attached to a given declaration. 00639 /// Returns NULL if no comment is attached. Does not look at any 00640 /// redeclarations of the declaration. 00641 comments::FullComment *getLocalCommentForDeclUncached(const Decl *D) const; 00642 00643 comments::FullComment *cloneFullComment(comments::FullComment *FC, 00644 const Decl *D) const; 00645 00646 private: 00647 mutable comments::CommandTraits CommentCommandTraits; 00648 00649 /// \brief Iterator that visits import declarations. 00650 class import_iterator { 00651 ImportDecl *Import; 00652 00653 public: 00654 typedef ImportDecl *value_type; 00655 typedef ImportDecl *reference; 00656 typedef ImportDecl *pointer; 00657 typedef int difference_type; 00658 typedef std::forward_iterator_tag iterator_category; 00659 00660 import_iterator() : Import() {} 00661 explicit import_iterator(ImportDecl *Import) : Import(Import) {} 00662 00663 reference operator*() const { return Import; } 00664 pointer operator->() const { return Import; } 00665 00666 import_iterator &operator++() { 00667 Import = ASTContext::getNextLocalImport(Import); 00668 return *this; 00669 } 00670 00671 import_iterator operator++(int) { 00672 import_iterator Other(*this); 00673 ++(*this); 00674 return Other; 00675 } 00676 00677 friend bool operator==(import_iterator X, import_iterator Y) { 00678 return X.Import == Y.Import; 00679 } 00680 00681 friend bool operator!=(import_iterator X, import_iterator Y) { 00682 return X.Import != Y.Import; 00683 } 00684 }; 00685 00686 public: 00687 comments::CommandTraits &getCommentCommandTraits() const { 00688 return CommentCommandTraits; 00689 } 00690 00691 /// \brief Retrieve the attributes for the given declaration. 00692 AttrVec& getDeclAttrs(const Decl *D); 00693 00694 /// \brief Erase the attributes corresponding to the given declaration. 00695 void eraseDeclAttrs(const Decl *D); 00696 00697 /// \brief If this variable is an instantiated static data member of a 00698 /// class template specialization, returns the templated static data member 00699 /// from which it was instantiated. 00700 // FIXME: Remove ? 00701 MemberSpecializationInfo *getInstantiatedFromStaticDataMember( 00702 const VarDecl *Var); 00703 00704 TemplateOrSpecializationInfo 00705 getTemplateOrSpecializationInfo(const VarDecl *Var); 00706 00707 FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD); 00708 00709 void setClassScopeSpecializationPattern(FunctionDecl *FD, 00710 FunctionDecl *Pattern); 00711 00712 /// \brief Note that the static data member \p Inst is an instantiation of 00713 /// the static data member template \p Tmpl of a class template. 00714 void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, 00715 TemplateSpecializationKind TSK, 00716 SourceLocation PointOfInstantiation = SourceLocation()); 00717 00718 void setTemplateOrSpecializationInfo(VarDecl *Inst, 00719 TemplateOrSpecializationInfo TSI); 00720 00721 /// \brief If the given using decl \p Inst is an instantiation of a 00722 /// (possibly unresolved) using decl from a template instantiation, 00723 /// return it. 00724 NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst); 00725 00726 /// \brief Remember that the using decl \p Inst is an instantiation 00727 /// of the using decl \p Pattern of a class template. 00728 void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern); 00729 00730 void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, 00731 UsingShadowDecl *Pattern); 00732 UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst); 00733 00734 FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field); 00735 00736 void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl); 00737 00738 // Access to the set of methods overridden by the given C++ method. 00739 typedef CXXMethodVector::const_iterator overridden_cxx_method_iterator; 00740 overridden_cxx_method_iterator 00741 overridden_methods_begin(const CXXMethodDecl *Method) const; 00742 00743 overridden_cxx_method_iterator 00744 overridden_methods_end(const CXXMethodDecl *Method) const; 00745 00746 unsigned overridden_methods_size(const CXXMethodDecl *Method) const; 00747 00748 /// \brief Note that the given C++ \p Method overrides the given \p 00749 /// Overridden method. 00750 void addOverriddenMethod(const CXXMethodDecl *Method, 00751 const CXXMethodDecl *Overridden); 00752 00753 /// \brief Return C++ or ObjC overridden methods for the given \p Method. 00754 /// 00755 /// An ObjC method is considered to override any method in the class's 00756 /// base classes, its protocols, or its categories' protocols, that has 00757 /// the same selector and is of the same kind (class or instance). 00758 /// A method in an implementation is not considered as overriding the same 00759 /// method in the interface or its categories. 00760 void getOverriddenMethods( 00761 const NamedDecl *Method, 00762 SmallVectorImpl<const NamedDecl *> &Overridden) const; 00763 00764 /// \brief Notify the AST context that a new import declaration has been 00765 /// parsed or implicitly created within this translation unit. 00766 void addedLocalImportDecl(ImportDecl *Import); 00767 00768 static ImportDecl *getNextLocalImport(ImportDecl *Import) { 00769 return Import->NextLocalImport; 00770 } 00771 00772 typedef llvm::iterator_range<import_iterator> import_range; 00773 import_range local_imports() const { 00774 return import_range(import_iterator(FirstLocalImport), import_iterator()); 00775 } 00776 00777 Decl *getPrimaryMergedDecl(Decl *D) { 00778 Decl *Result = MergedDecls.lookup(D); 00779 return Result ? Result : D; 00780 } 00781 void setPrimaryMergedDecl(Decl *D, Decl *Primary) { 00782 MergedDecls[D] = Primary; 00783 } 00784 00785 TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; } 00786 00787 00788 // Builtin Types. 00789 CanQualType VoidTy; 00790 CanQualType BoolTy; 00791 CanQualType CharTy; 00792 CanQualType WCharTy; // [C++ 3.9.1p5]. 00793 CanQualType WideCharTy; // Same as WCharTy in C++, integer type in C99. 00794 CanQualType WIntTy; // [C99 7.24.1], integer type unchanged by default promotions. 00795 CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99. 00796 CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99. 00797 CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty; 00798 CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; 00799 CanQualType UnsignedLongLongTy, UnsignedInt128Ty; 00800 CanQualType FloatTy, DoubleTy, LongDoubleTy; 00801 CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON 00802 CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; 00803 CanQualType VoidPtrTy, NullPtrTy; 00804 CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy; 00805 CanQualType BuiltinFnTy; 00806 CanQualType PseudoObjectTy, ARCUnbridgedCastTy; 00807 CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy; 00808 CanQualType ObjCBuiltinBoolTy; 00809 CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy; 00810 CanQualType OCLImage2dTy, OCLImage2dArrayTy; 00811 CanQualType OCLImage3dTy; 00812 CanQualType OCLSamplerTy, OCLEventTy; 00813 00814 // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. 00815 mutable QualType AutoDeductTy; // Deduction against 'auto'. 00816 mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'. 00817 00818 // Type used to help define __builtin_va_list for some targets. 00819 // The type is built when constructing 'BuiltinVaListDecl'. 00820 mutable QualType VaListTagTy; 00821 00822 ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents, 00823 SelectorTable &sels, Builtin::Context &builtins); 00824 00825 ~ASTContext(); 00826 00827 /// \brief Attach an external AST source to the AST context. 00828 /// 00829 /// The external AST source provides the ability to load parts of 00830 /// the abstract syntax tree as needed from some external storage, 00831 /// e.g., a precompiled header. 00832 void setExternalSource(IntrusiveRefCntPtr<ExternalASTSource> Source); 00833 00834 /// \brief Retrieve a pointer to the external AST source associated 00835 /// with this AST context, if any. 00836 ExternalASTSource *getExternalSource() const { 00837 return ExternalSource.get(); 00838 } 00839 00840 /// \brief Attach an AST mutation listener to the AST context. 00841 /// 00842 /// The AST mutation listener provides the ability to track modifications to 00843 /// the abstract syntax tree entities committed after they were initially 00844 /// created. 00845 void setASTMutationListener(ASTMutationListener *Listener) { 00846 this->Listener = Listener; 00847 } 00848 00849 /// \brief Retrieve a pointer to the AST mutation listener associated 00850 /// with this AST context, if any. 00851 ASTMutationListener *getASTMutationListener() const { return Listener; } 00852 00853 void PrintStats() const; 00854 const SmallVectorImpl<Type *>& getTypes() const { return Types; } 00855 00856 /// \brief Create a new implicit TU-level CXXRecordDecl or RecordDecl 00857 /// declaration. 00858 RecordDecl *buildImplicitRecord(StringRef Name, 00859 RecordDecl::TagKind TK = TTK_Struct) const; 00860 00861 /// \brief Create a new implicit TU-level typedef declaration. 00862 TypedefDecl *buildImplicitTypedef(QualType T, StringRef Name) const; 00863 00864 /// \brief Retrieve the declaration for the 128-bit signed integer type. 00865 TypedefDecl *getInt128Decl() const; 00866 00867 /// \brief Retrieve the declaration for the 128-bit unsigned integer type. 00868 TypedefDecl *getUInt128Decl() const; 00869 00870 /// \brief Retrieve the declaration for a 128-bit float stub type. 00871 TypeDecl *getFloat128StubType() const; 00872 00873 //===--------------------------------------------------------------------===// 00874 // Type Constructors 00875 //===--------------------------------------------------------------------===// 00876 00877 private: 00878 /// \brief Return a type with extended qualifiers. 00879 QualType getExtQualType(const Type *Base, Qualifiers Quals) const; 00880 00881 QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const; 00882 00883 public: 00884 /// \brief Return the uniqued reference to the type for an address space 00885 /// qualified type with the specified type and address space. 00886 /// 00887 /// The resulting type has a union of the qualifiers from T and the address 00888 /// space. If T already has an address space specifier, it is silently 00889 /// replaced. 00890 QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const; 00891 00892 /// \brief Return the uniqued reference to the type for an Objective-C 00893 /// gc-qualified type. 00894 /// 00895 /// The retulting type has a union of the qualifiers from T and the gc 00896 /// attribute. 00897 QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const; 00898 00899 /// \brief Return the uniqued reference to the type for a \c restrict 00900 /// qualified type. 00901 /// 00902 /// The resulting type has a union of the qualifiers from \p T and 00903 /// \c restrict. 00904 QualType getRestrictType(QualType T) const { 00905 return T.withFastQualifiers(Qualifiers::Restrict); 00906 } 00907 00908 /// \brief Return the uniqued reference to the type for a \c volatile 00909 /// qualified type. 00910 /// 00911 /// The resulting type has a union of the qualifiers from \p T and 00912 /// \c volatile. 00913 QualType getVolatileType(QualType T) const { 00914 return T.withFastQualifiers(Qualifiers::Volatile); 00915 } 00916 00917 /// \brief Return the uniqued reference to the type for a \c const 00918 /// qualified type. 00919 /// 00920 /// The resulting type has a union of the qualifiers from \p T and \c const. 00921 /// 00922 /// It can be reasonably expected that this will always be equivalent to 00923 /// calling T.withConst(). 00924 QualType getConstType(QualType T) const { return T.withConst(); } 00925 00926 /// \brief Change the ExtInfo on a function type. 00927 const FunctionType *adjustFunctionType(const FunctionType *Fn, 00928 FunctionType::ExtInfo EInfo); 00929 00930 /// \brief Change the result type of a function type once it is deduced. 00931 void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType); 00932 00933 /// \brief Change the exception specification on a function once it is 00934 /// delay-parsed, instantiated, or computed. 00935 void adjustExceptionSpec(FunctionDecl *FD, 00936 const FunctionProtoType::ExceptionSpecInfo &ESI, 00937 bool AsWritten = false); 00938 00939 /// \brief Return the uniqued reference to the type for a complex 00940 /// number with the specified element type. 00941 QualType getComplexType(QualType T) const; 00942 CanQualType getComplexType(CanQualType T) const { 00943 return CanQualType::CreateUnsafe(getComplexType((QualType) T)); 00944 } 00945 00946 /// \brief Return the uniqued reference to the type for a pointer to 00947 /// the specified type. 00948 QualType getPointerType(QualType T) const; 00949 CanQualType getPointerType(CanQualType T) const { 00950 return CanQualType::CreateUnsafe(getPointerType((QualType) T)); 00951 } 00952 00953 /// \brief Return the uniqued reference to a type adjusted from the original 00954 /// type to a new type. 00955 QualType getAdjustedType(QualType Orig, QualType New) const; 00956 CanQualType getAdjustedType(CanQualType Orig, CanQualType New) const { 00957 return CanQualType::CreateUnsafe( 00958 getAdjustedType((QualType)Orig, (QualType)New)); 00959 } 00960 00961 /// \brief Return the uniqued reference to the decayed version of the given 00962 /// type. Can only be called on array and function types which decay to 00963 /// pointer types. 00964 QualType getDecayedType(QualType T) const; 00965 CanQualType getDecayedType(CanQualType T) const { 00966 return CanQualType::CreateUnsafe(getDecayedType((QualType) T)); 00967 } 00968 00969 /// \brief Return the uniqued reference to the atomic type for the specified 00970 /// type. 00971 QualType getAtomicType(QualType T) const; 00972 00973 /// \brief Return the uniqued reference to the type for a block of the 00974 /// specified type. 00975 QualType getBlockPointerType(QualType T) const; 00976 00977 /// Gets the struct used to keep track of the descriptor for pointer to 00978 /// blocks. 00979 QualType getBlockDescriptorType() const; 00980 00981 /// Gets the struct used to keep track of the extended descriptor for 00982 /// pointer to blocks. 00983 QualType getBlockDescriptorExtendedType() const; 00984 00985 void setcudaConfigureCallDecl(FunctionDecl *FD) { 00986 cudaConfigureCallDecl = FD; 00987 } 00988 FunctionDecl *getcudaConfigureCallDecl() { 00989 return cudaConfigureCallDecl; 00990 } 00991 00992 /// Returns true iff we need copy/dispose helpers for the given type. 00993 bool BlockRequiresCopying(QualType Ty, const VarDecl *D); 00994 00995 00996 /// Returns true, if given type has a known lifetime. HasByrefExtendedLayout is set 00997 /// to false in this case. If HasByrefExtendedLayout returns true, byref variable 00998 /// has extended lifetime. 00999 bool getByrefLifetime(QualType Ty, 01000 Qualifiers::ObjCLifetime &Lifetime, 01001 bool &HasByrefExtendedLayout) const; 01002 01003 /// \brief Return the uniqued reference to the type for an lvalue reference 01004 /// to the specified type. 01005 QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true) 01006 const; 01007 01008 /// \brief Return the uniqued reference to the type for an rvalue reference 01009 /// to the specified type. 01010 QualType getRValueReferenceType(QualType T) const; 01011 01012 /// \brief Return the uniqued reference to the type for a member pointer to 01013 /// the specified type in the specified class. 01014 /// 01015 /// The class \p Cls is a \c Type because it could be a dependent name. 01016 QualType getMemberPointerType(QualType T, const Type *Cls) const; 01017 01018 /// \brief Return a non-unique reference to the type for a variable array of 01019 /// the specified element type. 01020 QualType getVariableArrayType(QualType EltTy, Expr *NumElts, 01021 ArrayType::ArraySizeModifier ASM, 01022 unsigned IndexTypeQuals, 01023 SourceRange Brackets) const; 01024 01025 /// \brief Return a non-unique reference to the type for a dependently-sized 01026 /// array of the specified element type. 01027 /// 01028 /// FIXME: We will need these to be uniqued, or at least comparable, at some 01029 /// point. 01030 QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, 01031 ArrayType::ArraySizeModifier ASM, 01032 unsigned IndexTypeQuals, 01033 SourceRange Brackets) const; 01034 01035 /// \brief Return a unique reference to the type for an incomplete array of 01036 /// the specified element type. 01037 QualType getIncompleteArrayType(QualType EltTy, 01038 ArrayType::ArraySizeModifier ASM, 01039 unsigned IndexTypeQuals) const; 01040 01041 /// \brief Return the unique reference to the type for a constant array of 01042 /// the specified element type. 01043 QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, 01044 ArrayType::ArraySizeModifier ASM, 01045 unsigned IndexTypeQuals) const; 01046 01047 /// \brief Returns a vla type where known sizes are replaced with [*]. 01048 QualType getVariableArrayDecayedType(QualType Ty) const; 01049 01050 /// \brief Return the unique reference to a vector type of the specified 01051 /// element type and size. 01052 /// 01053 /// \pre \p VectorType must be a built-in type. 01054 QualType getVectorType(QualType VectorType, unsigned NumElts, 01055 VectorType::VectorKind VecKind) const; 01056 01057 /// \brief Return the unique reference to an extended vector type 01058 /// of the specified element type and size. 01059 /// 01060 /// \pre \p VectorType must be a built-in type. 01061 QualType getExtVectorType(QualType VectorType, unsigned NumElts) const; 01062 01063 /// \pre Return a non-unique reference to the type for a dependently-sized 01064 /// vector of the specified element type. 01065 /// 01066 /// FIXME: We will need these to be uniqued, or at least comparable, at some 01067 /// point. 01068 QualType getDependentSizedExtVectorType(QualType VectorType, 01069 Expr *SizeExpr, 01070 SourceLocation AttrLoc) const; 01071 01072 /// \brief Return a K&R style C function type like 'int()'. 01073 QualType getFunctionNoProtoType(QualType ResultTy, 01074 const FunctionType::ExtInfo &Info) const; 01075 01076 QualType getFunctionNoProtoType(QualType ResultTy) const { 01077 return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo()); 01078 } 01079 01080 /// \brief Return a normal function type with a typed argument list. 01081 QualType getFunctionType(QualType ResultTy, ArrayRef<QualType> Args, 01082 const FunctionProtoType::ExtProtoInfo &EPI) const; 01083 01084 /// \brief Return the unique reference to the type for the specified type 01085 /// declaration. 01086 QualType getTypeDeclType(const TypeDecl *Decl, 01087 const TypeDecl *PrevDecl = nullptr) const { 01088 assert(Decl && "Passed null for Decl param"); 01089 if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 01090 01091 if (PrevDecl) { 01092 assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl"); 01093 Decl->TypeForDecl = PrevDecl->TypeForDecl; 01094 return QualType(PrevDecl->TypeForDecl, 0); 01095 } 01096 01097 return getTypeDeclTypeSlow(Decl); 01098 } 01099 01100 /// \brief Return the unique reference to the type for the specified 01101 /// typedef-name decl. 01102 QualType getTypedefType(const TypedefNameDecl *Decl, 01103 QualType Canon = QualType()) const; 01104 01105 QualType getRecordType(const RecordDecl *Decl) const; 01106 01107 QualType getEnumType(const EnumDecl *Decl) const; 01108 01109 QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const; 01110 01111 QualType getAttributedType(AttributedType::Kind attrKind, 01112 QualType modifiedType, 01113 QualType equivalentType); 01114 01115 QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, 01116 QualType Replacement) const; 01117 QualType getSubstTemplateTypeParmPackType( 01118 const TemplateTypeParmType *Replaced, 01119 const TemplateArgument &ArgPack); 01120 01121 QualType 01122 getTemplateTypeParmType(unsigned Depth, unsigned Index, 01123 bool ParameterPack, 01124 TemplateTypeParmDecl *ParmDecl = nullptr) const; 01125 01126 QualType getTemplateSpecializationType(TemplateName T, 01127 const TemplateArgument *Args, 01128 unsigned NumArgs, 01129 QualType Canon = QualType()) const; 01130 01131 QualType getCanonicalTemplateSpecializationType(TemplateName T, 01132 const TemplateArgument *Args, 01133 unsigned NumArgs) const; 01134 01135 QualType getTemplateSpecializationType(TemplateName T, 01136 const TemplateArgumentListInfo &Args, 01137 QualType Canon = QualType()) const; 01138 01139 TypeSourceInfo * 01140 getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc, 01141 const TemplateArgumentListInfo &Args, 01142 QualType Canon = QualType()) const; 01143 01144 QualType getParenType(QualType NamedType) const; 01145 01146 QualType getElaboratedType(ElaboratedTypeKeyword Keyword, 01147 NestedNameSpecifier *NNS, 01148 QualType NamedType) const; 01149 QualType getDependentNameType(ElaboratedTypeKeyword Keyword, 01150 NestedNameSpecifier *NNS, 01151 const IdentifierInfo *Name, 01152 QualType Canon = QualType()) const; 01153 01154 QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 01155 NestedNameSpecifier *NNS, 01156 const IdentifierInfo *Name, 01157 const TemplateArgumentListInfo &Args) const; 01158 QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 01159 NestedNameSpecifier *NNS, 01160 const IdentifierInfo *Name, 01161 unsigned NumArgs, 01162 const TemplateArgument *Args) const; 01163 01164 QualType getPackExpansionType(QualType Pattern, 01165 Optional<unsigned> NumExpansions); 01166 01167 QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, 01168 ObjCInterfaceDecl *PrevDecl = nullptr) const; 01169 01170 QualType getObjCObjectType(QualType Base, 01171 ObjCProtocolDecl * const *Protocols, 01172 unsigned NumProtocols) const; 01173 01174 bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl); 01175 /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in 01176 /// QT's qualified-id protocol list adopt all protocols in IDecl's list 01177 /// of protocols. 01178 bool QIdProtocolsAdoptObjCObjectProtocols(QualType QT, 01179 ObjCInterfaceDecl *IDecl); 01180 01181 /// \brief Return a ObjCObjectPointerType type for the given ObjCObjectType. 01182 QualType getObjCObjectPointerType(QualType OIT) const; 01183 01184 /// \brief GCC extension. 01185 QualType getTypeOfExprType(Expr *e) const; 01186 QualType getTypeOfType(QualType t) const; 01187 01188 /// \brief C++11 decltype. 01189 QualType getDecltypeType(Expr *e, QualType UnderlyingType) const; 01190 01191 /// \brief Unary type transforms 01192 QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, 01193 UnaryTransformType::UTTKind UKind) const; 01194 01195 /// \brief C++11 deduced auto type. 01196 QualType getAutoType(QualType DeducedType, bool IsDecltypeAuto, 01197 bool IsDependent) const; 01198 01199 /// \brief C++11 deduction pattern for 'auto' type. 01200 QualType getAutoDeductType() const; 01201 01202 /// \brief C++11 deduction pattern for 'auto &&' type. 01203 QualType getAutoRRefDeductType() const; 01204 01205 /// \brief Return the unique reference to the type for the specified TagDecl 01206 /// (struct/union/class/enum) decl. 01207 QualType getTagDeclType(const TagDecl *Decl) const; 01208 01209 /// \brief Return the unique type for "size_t" (C99 7.17), defined in 01210 /// <stddef.h>. 01211 /// 01212 /// The sizeof operator requires this (C99 6.5.3.4p4). 01213 CanQualType getSizeType() const; 01214 01215 /// \brief Return the unique type for "intmax_t" (C99 7.18.1.5), defined in 01216 /// <stdint.h>. 01217 CanQualType getIntMaxType() const; 01218 01219 /// \brief Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in 01220 /// <stdint.h>. 01221 CanQualType getUIntMaxType() const; 01222 01223 /// \brief Return the unique wchar_t type available in C++ (and available as 01224 /// __wchar_t as a Microsoft extension). 01225 QualType getWCharType() const { return WCharTy; } 01226 01227 /// \brief Return the type of wide characters. In C++, this returns the 01228 /// unique wchar_t type. In C99, this returns a type compatible with the type 01229 /// defined in <stddef.h> as defined by the target. 01230 QualType getWideCharType() const { return WideCharTy; } 01231 01232 /// \brief Return the type of "signed wchar_t". 01233 /// 01234 /// Used when in C++, as a GCC extension. 01235 QualType getSignedWCharType() const; 01236 01237 /// \brief Return the type of "unsigned wchar_t". 01238 /// 01239 /// Used when in C++, as a GCC extension. 01240 QualType getUnsignedWCharType() const; 01241 01242 /// \brief In C99, this returns a type compatible with the type 01243 /// defined in <stddef.h> as defined by the target. 01244 QualType getWIntType() const { return WIntTy; } 01245 01246 /// \brief Return a type compatible with "intptr_t" (C99 7.18.1.4), 01247 /// as defined by the target. 01248 QualType getIntPtrType() const; 01249 01250 /// \brief Return a type compatible with "uintptr_t" (C99 7.18.1.4), 01251 /// as defined by the target. 01252 QualType getUIntPtrType() const; 01253 01254 /// \brief Return the unique type for "ptrdiff_t" (C99 7.17) defined in 01255 /// <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 01256 QualType getPointerDiffType() const; 01257 01258 /// \brief Return the unique type for "pid_t" defined in 01259 /// <sys/types.h>. We need this to compute the correct type for vfork(). 01260 QualType getProcessIDType() const; 01261 01262 /// \brief Return the C structure type used to represent constant CFStrings. 01263 QualType getCFConstantStringType() const; 01264 01265 /// \brief Returns the C struct type for objc_super 01266 QualType getObjCSuperType() const; 01267 void setObjCSuperType(QualType ST) { ObjCSuperType = ST; } 01268 01269 /// Get the structure type used to representation CFStrings, or NULL 01270 /// if it hasn't yet been built. 01271 QualType getRawCFConstantStringType() const { 01272 if (CFConstantStringTypeDecl) 01273 return getTagDeclType(CFConstantStringTypeDecl); 01274 return QualType(); 01275 } 01276 void setCFConstantStringType(QualType T); 01277 01278 // This setter/getter represents the ObjC type for an NSConstantString. 01279 void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl); 01280 QualType getObjCConstantStringInterface() const { 01281 return ObjCConstantStringType; 01282 } 01283 01284 QualType getObjCNSStringType() const { 01285 return ObjCNSStringType; 01286 } 01287 01288 void setObjCNSStringType(QualType T) { 01289 ObjCNSStringType = T; 01290 } 01291 01292 /// \brief Retrieve the type that \c id has been defined to, which may be 01293 /// different from the built-in \c id if \c id has been typedef'd. 01294 QualType getObjCIdRedefinitionType() const { 01295 if (ObjCIdRedefinitionType.isNull()) 01296 return getObjCIdType(); 01297 return ObjCIdRedefinitionType; 01298 } 01299 01300 /// \brief Set the user-written type that redefines \c id. 01301 void setObjCIdRedefinitionType(QualType RedefType) { 01302 ObjCIdRedefinitionType = RedefType; 01303 } 01304 01305 /// \brief Retrieve the type that \c Class has been defined to, which may be 01306 /// different from the built-in \c Class if \c Class has been typedef'd. 01307 QualType getObjCClassRedefinitionType() const { 01308 if (ObjCClassRedefinitionType.isNull()) 01309 return getObjCClassType(); 01310 return ObjCClassRedefinitionType; 01311 } 01312 01313 /// \brief Set the user-written type that redefines 'SEL'. 01314 void setObjCClassRedefinitionType(QualType RedefType) { 01315 ObjCClassRedefinitionType = RedefType; 01316 } 01317 01318 /// \brief Retrieve the type that 'SEL' has been defined to, which may be 01319 /// different from the built-in 'SEL' if 'SEL' has been typedef'd. 01320 QualType getObjCSelRedefinitionType() const { 01321 if (ObjCSelRedefinitionType.isNull()) 01322 return getObjCSelType(); 01323 return ObjCSelRedefinitionType; 01324 } 01325 01326 01327 /// \brief Set the user-written type that redefines 'SEL'. 01328 void setObjCSelRedefinitionType(QualType RedefType) { 01329 ObjCSelRedefinitionType = RedefType; 01330 } 01331 01332 /// \brief Retrieve the Objective-C "instancetype" type, if already known; 01333 /// otherwise, returns a NULL type; 01334 QualType getObjCInstanceType() { 01335 return getTypeDeclType(getObjCInstanceTypeDecl()); 01336 } 01337 01338 /// \brief Retrieve the typedef declaration corresponding to the Objective-C 01339 /// "instancetype" type. 01340 TypedefDecl *getObjCInstanceTypeDecl(); 01341 01342 /// \brief Set the type for the C FILE type. 01343 void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; } 01344 01345 /// \brief Retrieve the C FILE type. 01346 QualType getFILEType() const { 01347 if (FILEDecl) 01348 return getTypeDeclType(FILEDecl); 01349 return QualType(); 01350 } 01351 01352 /// \brief Set the type for the C jmp_buf type. 01353 void setjmp_bufDecl(TypeDecl *jmp_bufDecl) { 01354 this->jmp_bufDecl = jmp_bufDecl; 01355 } 01356 01357 /// \brief Retrieve the C jmp_buf type. 01358 QualType getjmp_bufType() const { 01359 if (jmp_bufDecl) 01360 return getTypeDeclType(jmp_bufDecl); 01361 return QualType(); 01362 } 01363 01364 /// \brief Set the type for the C sigjmp_buf type. 01365 void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) { 01366 this->sigjmp_bufDecl = sigjmp_bufDecl; 01367 } 01368 01369 /// \brief Retrieve the C sigjmp_buf type. 01370 QualType getsigjmp_bufType() const { 01371 if (sigjmp_bufDecl) 01372 return getTypeDeclType(sigjmp_bufDecl); 01373 return QualType(); 01374 } 01375 01376 /// \brief Set the type for the C ucontext_t type. 01377 void setucontext_tDecl(TypeDecl *ucontext_tDecl) { 01378 this->ucontext_tDecl = ucontext_tDecl; 01379 } 01380 01381 /// \brief Retrieve the C ucontext_t type. 01382 QualType getucontext_tType() const { 01383 if (ucontext_tDecl) 01384 return getTypeDeclType(ucontext_tDecl); 01385 return QualType(); 01386 } 01387 01388 /// \brief The result type of logical operations, '<', '>', '!=', etc. 01389 QualType getLogicalOperationType() const { 01390 return getLangOpts().CPlusPlus ? BoolTy : IntTy; 01391 } 01392 01393 /// \brief Emit the Objective-CC type encoding for the given type \p T into 01394 /// \p S. 01395 /// 01396 /// If \p Field is specified then record field names are also encoded. 01397 void getObjCEncodingForType(QualType T, std::string &S, 01398 const FieldDecl *Field=nullptr, 01399 QualType *NotEncodedT=nullptr) const; 01400 01401 /// \brief Emit the Objective-C property type encoding for the given 01402 /// type \p T into \p S. 01403 void getObjCEncodingForPropertyType(QualType T, std::string &S) const; 01404 01405 void getLegacyIntegralTypeEncoding(QualType &t) const; 01406 01407 /// \brief Put the string version of the type qualifiers \p QT into \p S. 01408 void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 01409 std::string &S) const; 01410 01411 /// \brief Emit the encoded type for the function \p Decl into \p S. 01412 /// 01413 /// This is in the same format as Objective-C method encodings. 01414 /// 01415 /// \returns true if an error occurred (e.g., because one of the parameter 01416 /// types is incomplete), false otherwise. 01417 bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S); 01418 01419 /// \brief Emit the encoded type for the method declaration \p Decl into 01420 /// \p S. 01421 /// 01422 /// \returns true if an error occurred (e.g., because one of the parameter 01423 /// types is incomplete), false otherwise. 01424 bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S, 01425 bool Extended = false) 01426 const; 01427 01428 /// \brief Return the encoded type for this block declaration. 01429 std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const; 01430 01431 /// getObjCEncodingForPropertyDecl - Return the encoded type for 01432 /// this method declaration. If non-NULL, Container must be either 01433 /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should 01434 /// only be NULL when getting encodings for protocol properties. 01435 void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 01436 const Decl *Container, 01437 std::string &S) const; 01438 01439 bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 01440 ObjCProtocolDecl *rProto) const; 01441 01442 ObjCPropertyImplDecl *getObjCPropertyImplDeclForPropertyDecl( 01443 const ObjCPropertyDecl *PD, 01444 const Decl *Container) const; 01445 01446 /// \brief Return the size of type \p T for Objective-C encoding purpose, 01447 /// in characters. 01448 CharUnits getObjCEncodingTypeSize(QualType T) const; 01449 01450 /// \brief Retrieve the typedef corresponding to the predefined \c id type 01451 /// in Objective-C. 01452 TypedefDecl *getObjCIdDecl() const; 01453 01454 /// \brief Represents the Objective-CC \c id type. 01455 /// 01456 /// This is set up lazily, by Sema. \c id is always a (typedef for a) 01457 /// pointer type, a pointer to a struct. 01458 QualType getObjCIdType() const { 01459 return getTypeDeclType(getObjCIdDecl()); 01460 } 01461 01462 /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type 01463 /// in Objective-C. 01464 TypedefDecl *getObjCSelDecl() const; 01465 01466 /// \brief Retrieve the type that corresponds to the predefined Objective-C 01467 /// 'SEL' type. 01468 QualType getObjCSelType() const { 01469 return getTypeDeclType(getObjCSelDecl()); 01470 } 01471 01472 /// \brief Retrieve the typedef declaration corresponding to the predefined 01473 /// Objective-C 'Class' type. 01474 TypedefDecl *getObjCClassDecl() const; 01475 01476 /// \brief Represents the Objective-C \c Class type. 01477 /// 01478 /// This is set up lazily, by Sema. \c Class is always a (typedef for a) 01479 /// pointer type, a pointer to a struct. 01480 QualType getObjCClassType() const { 01481 return getTypeDeclType(getObjCClassDecl()); 01482 } 01483 01484 /// \brief Retrieve the Objective-C class declaration corresponding to 01485 /// the predefined \c Protocol class. 01486 ObjCInterfaceDecl *getObjCProtocolDecl() const; 01487 01488 /// \brief Retrieve declaration of 'BOOL' typedef 01489 TypedefDecl *getBOOLDecl() const { 01490 return BOOLDecl; 01491 } 01492 01493 /// \brief Save declaration of 'BOOL' typedef 01494 void setBOOLDecl(TypedefDecl *TD) { 01495 BOOLDecl = TD; 01496 } 01497 01498 /// \brief type of 'BOOL' type. 01499 QualType getBOOLType() const { 01500 return getTypeDeclType(getBOOLDecl()); 01501 } 01502 01503 /// \brief Retrieve the type of the Objective-C \c Protocol class. 01504 QualType getObjCProtoType() const { 01505 return getObjCInterfaceType(getObjCProtocolDecl()); 01506 } 01507 01508 /// \brief Retrieve the C type declaration corresponding to the predefined 01509 /// \c __builtin_va_list type. 01510 TypedefDecl *getBuiltinVaListDecl() const; 01511 01512 /// \brief Retrieve the type of the \c __builtin_va_list type. 01513 QualType getBuiltinVaListType() const { 01514 return getTypeDeclType(getBuiltinVaListDecl()); 01515 } 01516 01517 /// \brief Retrieve the C type declaration corresponding to the predefined 01518 /// \c __va_list_tag type used to help define the \c __builtin_va_list type 01519 /// for some targets. 01520 QualType getVaListTagType() const; 01521 01522 /// \brief Return a type with additional \c const, \c volatile, or 01523 /// \c restrict qualifiers. 01524 QualType getCVRQualifiedType(QualType T, unsigned CVR) const { 01525 return getQualifiedType(T, Qualifiers::fromCVRMask(CVR)); 01526 } 01527 01528 /// \brief Un-split a SplitQualType. 01529 QualType getQualifiedType(SplitQualType split) const { 01530 return getQualifiedType(split.Ty, split.Quals); 01531 } 01532 01533 /// \brief Return a type with additional qualifiers. 01534 QualType getQualifiedType(QualType T, Qualifiers Qs) const { 01535 if (!Qs.hasNonFastQualifiers()) 01536 return T.withFastQualifiers(Qs.getFastQualifiers()); 01537 QualifierCollector Qc(Qs); 01538 const Type *Ptr = Qc.strip(T); 01539 return getExtQualType(Ptr, Qc); 01540 } 01541 01542 /// \brief Return a type with additional qualifiers. 01543 QualType getQualifiedType(const Type *T, Qualifiers Qs) const { 01544 if (!Qs.hasNonFastQualifiers()) 01545 return QualType(T, Qs.getFastQualifiers()); 01546 return getExtQualType(T, Qs); 01547 } 01548 01549 /// \brief Return a type with the given lifetime qualifier. 01550 /// 01551 /// \pre Neither type.ObjCLifetime() nor \p lifetime may be \c OCL_None. 01552 QualType getLifetimeQualifiedType(QualType type, 01553 Qualifiers::ObjCLifetime lifetime) { 01554 assert(type.getObjCLifetime() == Qualifiers::OCL_None); 01555 assert(lifetime != Qualifiers::OCL_None); 01556 01557 Qualifiers qs; 01558 qs.addObjCLifetime(lifetime); 01559 return getQualifiedType(type, qs); 01560 } 01561 01562 /// getUnqualifiedObjCPointerType - Returns version of 01563 /// Objective-C pointer type with lifetime qualifier removed. 01564 QualType getUnqualifiedObjCPointerType(QualType type) const { 01565 if (!type.getTypePtr()->isObjCObjectPointerType() || 01566 !type.getQualifiers().hasObjCLifetime()) 01567 return type; 01568 Qualifiers Qs = type.getQualifiers(); 01569 Qs.removeObjCLifetime(); 01570 return getQualifiedType(type.getUnqualifiedType(), Qs); 01571 } 01572 01573 DeclarationNameInfo getNameForTemplate(TemplateName Name, 01574 SourceLocation NameLoc) const; 01575 01576 TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, 01577 UnresolvedSetIterator End) const; 01578 01579 TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, 01580 bool TemplateKeyword, 01581 TemplateDecl *Template) const; 01582 01583 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 01584 const IdentifierInfo *Name) const; 01585 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 01586 OverloadedOperatorKind Operator) const; 01587 TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, 01588 TemplateName replacement) const; 01589 TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, 01590 const TemplateArgument &ArgPack) const; 01591 01592 enum GetBuiltinTypeError { 01593 GE_None, ///< No error 01594 GE_Missing_stdio, ///< Missing a type from <stdio.h> 01595 GE_Missing_setjmp, ///< Missing a type from <setjmp.h> 01596 GE_Missing_ucontext ///< Missing a type from <ucontext.h> 01597 }; 01598 01599 /// \brief Return the type for the specified builtin. 01600 /// 01601 /// If \p IntegerConstantArgs is non-null, it is filled in with a bitmask of 01602 /// arguments to the builtin that are required to be integer constant 01603 /// expressions. 01604 QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, 01605 unsigned *IntegerConstantArgs = nullptr) const; 01606 01607 private: 01608 CanQualType getFromTargetType(unsigned Type) const; 01609 TypeInfo getTypeInfoImpl(const Type *T) const; 01610 01611 //===--------------------------------------------------------------------===// 01612 // Type Predicates. 01613 //===--------------------------------------------------------------------===// 01614 01615 public: 01616 /// \brief Return one of the GCNone, Weak or Strong Objective-C garbage 01617 /// collection attributes. 01618 Qualifiers::GC getObjCGCAttrKind(QualType Ty) const; 01619 01620 /// \brief Return true if the given vector types are of the same unqualified 01621 /// type or if they are equivalent to the same GCC vector type. 01622 /// 01623 /// \note This ignores whether they are target-specific (AltiVec or Neon) 01624 /// types. 01625 bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec); 01626 01627 /// \brief Return true if this is an \c NSObject object with its \c NSObject 01628 /// attribute set. 01629 static bool isObjCNSObjectType(QualType Ty) { 01630 return Ty->isObjCNSObjectType(); 01631 } 01632 01633 //===--------------------------------------------------------------------===// 01634 // Type Sizing and Analysis 01635 //===--------------------------------------------------------------------===// 01636 01637 /// \brief Return the APFloat 'semantics' for the specified scalar floating 01638 /// point type. 01639 const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const; 01640 01641 /// \brief Get the size and alignment of the specified complete type in bits. 01642 TypeInfo getTypeInfo(const Type *T) const; 01643 TypeInfo getTypeInfo(QualType T) const { return getTypeInfo(T.getTypePtr()); } 01644 01645 /// \brief Return the size of the specified (complete) type \p T, in bits. 01646 uint64_t getTypeSize(QualType T) const { return getTypeInfo(T).Width; } 01647 uint64_t getTypeSize(const Type *T) const { return getTypeInfo(T).Width; } 01648 01649 /// \brief Return the size of the character type, in bits. 01650 uint64_t getCharWidth() const { 01651 return getTypeSize(CharTy); 01652 } 01653 01654 /// \brief Convert a size in bits to a size in characters. 01655 CharUnits toCharUnitsFromBits(int64_t BitSize) const; 01656 01657 /// \brief Convert a size in characters to a size in bits. 01658 int64_t toBits(CharUnits CharSize) const; 01659 01660 /// \brief Return the size of the specified (complete) type \p T, in 01661 /// characters. 01662 CharUnits getTypeSizeInChars(QualType T) const; 01663 CharUnits getTypeSizeInChars(const Type *T) const; 01664 01665 /// \brief Return the ABI-specified alignment of a (complete) type \p T, in 01666 /// bits. 01667 unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; } 01668 unsigned getTypeAlign(const Type *T) const { return getTypeInfo(T).Align; } 01669 01670 /// \brief Return the ABI-specified alignment of a (complete) type \p T, in 01671 /// characters. 01672 CharUnits getTypeAlignInChars(QualType T) const; 01673 CharUnits getTypeAlignInChars(const Type *T) const; 01674 01675 // getTypeInfoDataSizeInChars - Return the size of a type, in chars. If the 01676 // type is a record, its data size is returned. 01677 std::pair<CharUnits, CharUnits> getTypeInfoDataSizeInChars(QualType T) const; 01678 01679 std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const; 01680 std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const; 01681 01682 /// \brief Determine if the alignment the type has was required using an 01683 /// alignment attribute. 01684 bool isAlignmentRequired(const Type *T) const; 01685 bool isAlignmentRequired(QualType T) const; 01686 01687 /// \brief Return the "preferred" alignment of the specified type \p T for 01688 /// the current target, in bits. 01689 /// 01690 /// This can be different than the ABI alignment in cases where it is 01691 /// beneficial for performance to overalign a data type. 01692 unsigned getPreferredTypeAlign(const Type *T) const; 01693 01694 /// \brief Return the alignment in bits that should be given to a 01695 /// global variable with type \p T. 01696 unsigned getAlignOfGlobalVar(QualType T) const; 01697 01698 /// \brief Return the alignment in characters that should be given to a 01699 /// global variable with type \p T. 01700 CharUnits getAlignOfGlobalVarInChars(QualType T) const; 01701 01702 /// \brief Return a conservative estimate of the alignment of the specified 01703 /// decl \p D. 01704 /// 01705 /// \pre \p D must not be a bitfield type, as bitfields do not have a valid 01706 /// alignment. 01707 /// 01708 /// If \p ForAlignof, references are treated like their underlying type 01709 /// and large arrays don't get any special treatment. If not \p ForAlignof 01710 /// it computes the value expected by CodeGen: references are treated like 01711 /// pointers and large arrays get extra alignment. 01712 CharUnits getDeclAlign(const Decl *D, bool ForAlignof = false) const; 01713 01714 /// \brief Get or compute information about the layout of the specified 01715 /// record (struct/union/class) \p D, which indicates its size and field 01716 /// position information. 01717 const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const; 01718 const ASTRecordLayout *BuildMicrosoftASTRecordLayout(const RecordDecl *D) const; 01719 01720 /// \brief Get or compute information about the layout of the specified 01721 /// Objective-C interface. 01722 const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) 01723 const; 01724 01725 void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS, 01726 bool Simple = false) const; 01727 01728 /// \brief Get or compute information about the layout of the specified 01729 /// Objective-C implementation. 01730 /// 01731 /// This may differ from the interface if synthesized ivars are present. 01732 const ASTRecordLayout & 01733 getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const; 01734 01735 /// \brief Get our current best idea for the key function of the 01736 /// given record decl, or NULL if there isn't one. 01737 /// 01738 /// The key function is, according to the Itanium C++ ABI section 5.2.3: 01739 /// ...the first non-pure virtual function that is not inline at the 01740 /// point of class definition. 01741 /// 01742 /// Other ABIs use the same idea. However, the ARM C++ ABI ignores 01743 /// virtual functions that are defined 'inline', which means that 01744 /// the result of this computation can change. 01745 const CXXMethodDecl *getCurrentKeyFunction(const CXXRecordDecl *RD); 01746 01747 /// \brief Observe that the given method cannot be a key function. 01748 /// Checks the key-function cache for the method's class and clears it 01749 /// if matches the given declaration. 01750 /// 01751 /// This is used in ABIs where out-of-line definitions marked 01752 /// inline are not considered to be key functions. 01753 /// 01754 /// \param method should be the declaration from the class definition 01755 void setNonKeyFunction(const CXXMethodDecl *method); 01756 01757 /// Get the offset of a FieldDecl or IndirectFieldDecl, in bits. 01758 uint64_t getFieldOffset(const ValueDecl *FD) const; 01759 01760 bool isNearlyEmpty(const CXXRecordDecl *RD) const; 01761 01762 VTableContextBase *getVTableContext(); 01763 01764 MangleContext *createMangleContext(); 01765 01766 void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, 01767 SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const; 01768 01769 unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const; 01770 void CollectInheritedProtocols(const Decl *CDecl, 01771 llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols); 01772 01773 //===--------------------------------------------------------------------===// 01774 // Type Operators 01775 //===--------------------------------------------------------------------===// 01776 01777 /// \brief Return the canonical (structural) type corresponding to the 01778 /// specified potentially non-canonical type \p T. 01779 /// 01780 /// The non-canonical version of a type may have many "decorated" versions of 01781 /// types. Decorators can include typedefs, 'typeof' operators, etc. The 01782 /// returned type is guaranteed to be free of any of these, allowing two 01783 /// canonical types to be compared for exact equality with a simple pointer 01784 /// comparison. 01785 CanQualType getCanonicalType(QualType T) const { 01786 return CanQualType::CreateUnsafe(T.getCanonicalType()); 01787 } 01788 01789 const Type *getCanonicalType(const Type *T) const { 01790 return T->getCanonicalTypeInternal().getTypePtr(); 01791 } 01792 01793 /// \brief Return the canonical parameter type corresponding to the specific 01794 /// potentially non-canonical one. 01795 /// 01796 /// Qualifiers are stripped off, functions are turned into function 01797 /// pointers, and arrays decay one level into pointers. 01798 CanQualType getCanonicalParamType(QualType T) const; 01799 01800 /// \brief Determine whether the given types \p T1 and \p T2 are equivalent. 01801 bool hasSameType(QualType T1, QualType T2) const { 01802 return getCanonicalType(T1) == getCanonicalType(T2); 01803 } 01804 01805 bool hasSameType(const Type *T1, const Type *T2) const { 01806 return getCanonicalType(T1) == getCanonicalType(T2); 01807 } 01808 01809 /// \brief Return this type as a completely-unqualified array type, 01810 /// capturing the qualifiers in \p Quals. 01811 /// 01812 /// This will remove the minimal amount of sugaring from the types, similar 01813 /// to the behavior of QualType::getUnqualifiedType(). 01814 /// 01815 /// \param T is the qualified type, which may be an ArrayType 01816 /// 01817 /// \param Quals will receive the full set of qualifiers that were 01818 /// applied to the array. 01819 /// 01820 /// \returns if this is an array type, the completely unqualified array type 01821 /// that corresponds to it. Otherwise, returns T.getUnqualifiedType(). 01822 QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals); 01823 01824 /// \brief Determine whether the given types are equivalent after 01825 /// cvr-qualifiers have been removed. 01826 bool hasSameUnqualifiedType(QualType T1, QualType T2) const { 01827 return getCanonicalType(T1).getTypePtr() == 01828 getCanonicalType(T2).getTypePtr(); 01829 } 01830 01831 bool ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl, 01832 const ObjCMethodDecl *MethodImp); 01833 01834 bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2); 01835 01836 /// \brief Retrieves the "canonical" nested name specifier for a 01837 /// given nested name specifier. 01838 /// 01839 /// The canonical nested name specifier is a nested name specifier 01840 /// that uniquely identifies a type or namespace within the type 01841 /// system. For example, given: 01842 /// 01843 /// \code 01844 /// namespace N { 01845 /// struct S { 01846 /// template<typename T> struct X { typename T* type; }; 01847 /// }; 01848 /// } 01849 /// 01850 /// template<typename T> struct Y { 01851 /// typename N::S::X<T>::type member; 01852 /// }; 01853 /// \endcode 01854 /// 01855 /// Here, the nested-name-specifier for N::S::X<T>:: will be 01856 /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined 01857 /// by declarations in the type system and the canonical type for 01858 /// the template type parameter 'T' is template-param-0-0. 01859 NestedNameSpecifier * 01860 getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const; 01861 01862 /// \brief Retrieves the default calling convention for the current target. 01863 CallingConv getDefaultCallingConvention(bool isVariadic, 01864 bool IsCXXMethod) const; 01865 01866 /// \brief Retrieves the "canonical" template name that refers to a 01867 /// given template. 01868 /// 01869 /// The canonical template name is the simplest expression that can 01870 /// be used to refer to a given template. For most templates, this 01871 /// expression is just the template declaration itself. For example, 01872 /// the template std::vector can be referred to via a variety of 01873 /// names---std::vector, \::std::vector, vector (if vector is in 01874 /// scope), etc.---but all of these names map down to the same 01875 /// TemplateDecl, which is used to form the canonical template name. 01876 /// 01877 /// Dependent template names are more interesting. Here, the 01878 /// template name could be something like T::template apply or 01879 /// std::allocator<T>::template rebind, where the nested name 01880 /// specifier itself is dependent. In this case, the canonical 01881 /// template name uses the shortest form of the dependent 01882 /// nested-name-specifier, which itself contains all canonical 01883 /// types, values, and templates. 01884 TemplateName getCanonicalTemplateName(TemplateName Name) const; 01885 01886 /// \brief Determine whether the given template names refer to the same 01887 /// template. 01888 bool hasSameTemplateName(TemplateName X, TemplateName Y); 01889 01890 /// \brief Retrieve the "canonical" template argument. 01891 /// 01892 /// The canonical template argument is the simplest template argument 01893 /// (which may be a type, value, expression, or declaration) that 01894 /// expresses the value of the argument. 01895 TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) 01896 const; 01897 01898 /// Type Query functions. If the type is an instance of the specified class, 01899 /// return the Type pointer for the underlying maximally pretty type. This 01900 /// is a member of ASTContext because this may need to do some amount of 01901 /// canonicalization, e.g. to move type qualifiers into the element type. 01902 const ArrayType *getAsArrayType(QualType T) const; 01903 const ConstantArrayType *getAsConstantArrayType(QualType T) const { 01904 return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T)); 01905 } 01906 const VariableArrayType *getAsVariableArrayType(QualType T) const { 01907 return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T)); 01908 } 01909 const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const { 01910 return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T)); 01911 } 01912 const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T) 01913 const { 01914 return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T)); 01915 } 01916 01917 /// \brief Return the innermost element type of an array type. 01918 /// 01919 /// For example, will return "int" for int[m][n] 01920 QualType getBaseElementType(const ArrayType *VAT) const; 01921 01922 /// \brief Return the innermost element type of a type (which needn't 01923 /// actually be an array type). 01924 QualType getBaseElementType(QualType QT) const; 01925 01926 /// \brief Return number of constant array elements. 01927 uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const; 01928 01929 /// \brief Perform adjustment on the parameter type of a function. 01930 /// 01931 /// This routine adjusts the given parameter type @p T to the actual 01932 /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8], 01933 /// C++ [dcl.fct]p3). The adjusted parameter type is returned. 01934 QualType getAdjustedParameterType(QualType T) const; 01935 01936 /// \brief Retrieve the parameter type as adjusted for use in the signature 01937 /// of a function, decaying array and function types and removing top-level 01938 /// cv-qualifiers. 01939 QualType getSignatureParameterType(QualType T) const; 01940 01941 /// \brief Return the properly qualified result of decaying the specified 01942 /// array type to a pointer. 01943 /// 01944 /// This operation is non-trivial when handling typedefs etc. The canonical 01945 /// type of \p T must be an array type, this returns a pointer to a properly 01946 /// qualified element of the array. 01947 /// 01948 /// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 01949 QualType getArrayDecayedType(QualType T) const; 01950 01951 /// \brief Return the type that \p PromotableType will promote to: C99 01952 /// 6.3.1.1p2, assuming that \p PromotableType is a promotable integer type. 01953 QualType getPromotedIntegerType(QualType PromotableType) const; 01954 01955 /// \brief Recurses in pointer/array types until it finds an Objective-C 01956 /// retainable type and returns its ownership. 01957 Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const; 01958 01959 /// \brief Whether this is a promotable bitfield reference according 01960 /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 01961 /// 01962 /// \returns the type this bit-field will promote to, or NULL if no 01963 /// promotion occurs. 01964 QualType isPromotableBitField(Expr *E) const; 01965 01966 /// \brief Return the highest ranked integer type, see C99 6.3.1.8p1. 01967 /// 01968 /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If 01969 /// \p LHS < \p RHS, return -1. 01970 int getIntegerTypeOrder(QualType LHS, QualType RHS) const; 01971 01972 /// \brief Compare the rank of the two specified floating point types, 01973 /// ignoring the domain of the type (i.e. 'double' == '_Complex double'). 01974 /// 01975 /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If 01976 /// \p LHS < \p RHS, return -1. 01977 int getFloatingTypeOrder(QualType LHS, QualType RHS) const; 01978 01979 /// \brief Return a real floating point or a complex type (based on 01980 /// \p typeDomain/\p typeSize). 01981 /// 01982 /// \param typeDomain a real floating point or complex type. 01983 /// \param typeSize a real floating point or complex type. 01984 QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize, 01985 QualType typeDomain) const; 01986 01987 unsigned getTargetAddressSpace(QualType T) const { 01988 return getTargetAddressSpace(T.getQualifiers()); 01989 } 01990 01991 unsigned getTargetAddressSpace(Qualifiers Q) const { 01992 return getTargetAddressSpace(Q.getAddressSpace()); 01993 } 01994 01995 unsigned getTargetAddressSpace(unsigned AS) const { 01996 if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count) 01997 return AS; 01998 else 01999 return (*AddrSpaceMap)[AS - LangAS::Offset]; 02000 } 02001 02002 bool addressSpaceMapManglingFor(unsigned AS) const { 02003 return AddrSpaceMapMangling || 02004 AS < LangAS::Offset || 02005 AS >= LangAS::Offset + LangAS::Count; 02006 } 02007 02008 private: 02009 // Helper for integer ordering 02010 unsigned getIntegerRank(const Type *T) const; 02011 02012 public: 02013 02014 //===--------------------------------------------------------------------===// 02015 // Type Compatibility Predicates 02016 //===--------------------------------------------------------------------===// 02017 02018 /// Compatibility predicates used to check assignment expressions. 02019 bool typesAreCompatible(QualType T1, QualType T2, 02020 bool CompareUnqualified = false); // C99 6.2.7p1 02021 02022 bool propertyTypesAreCompatible(QualType, QualType); 02023 bool typesAreBlockPointerCompatible(QualType, QualType); 02024 02025 bool isObjCIdType(QualType T) const { 02026 return T == getObjCIdType(); 02027 } 02028 bool isObjCClassType(QualType T) const { 02029 return T == getObjCClassType(); 02030 } 02031 bool isObjCSelType(QualType T) const { 02032 return T == getObjCSelType(); 02033 } 02034 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, 02035 bool ForCompare); 02036 02037 bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS); 02038 02039 // Check the safety of assignment from LHS to RHS 02040 bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 02041 const ObjCObjectPointerType *RHSOPT); 02042 bool canAssignObjCInterfaces(const ObjCObjectType *LHS, 02043 const ObjCObjectType *RHS); 02044 bool canAssignObjCInterfacesInBlockPointer( 02045 const ObjCObjectPointerType *LHSOPT, 02046 const ObjCObjectPointerType *RHSOPT, 02047 bool BlockReturnType); 02048 bool areComparableObjCPointerTypes(QualType LHS, QualType RHS); 02049 QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT, 02050 const ObjCObjectPointerType *RHSOPT); 02051 bool canBindObjCObjectType(QualType To, QualType From); 02052 02053 // Functions for calculating composite types 02054 QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, 02055 bool Unqualified = false, bool BlockReturnType = false); 02056 QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false, 02057 bool Unqualified = false); 02058 QualType mergeFunctionParameterTypes(QualType, QualType, 02059 bool OfBlockPointer = false, 02060 bool Unqualified = false); 02061 QualType mergeTransparentUnionType(QualType, QualType, 02062 bool OfBlockPointer=false, 02063 bool Unqualified = false); 02064 02065 QualType mergeObjCGCQualifiers(QualType, QualType); 02066 02067 bool FunctionTypesMatchOnNSConsumedAttrs( 02068 const FunctionProtoType *FromFunctionType, 02069 const FunctionProtoType *ToFunctionType); 02070 02071 void ResetObjCLayout(const ObjCContainerDecl *CD) { 02072 ObjCLayouts[CD] = nullptr; 02073 } 02074 02075 //===--------------------------------------------------------------------===// 02076 // Integer Predicates 02077 //===--------------------------------------------------------------------===// 02078 02079 // The width of an integer, as defined in C99 6.2.6.2. This is the number 02080 // of bits in an integer type excluding any padding bits. 02081 unsigned getIntWidth(QualType T) const; 02082 02083 // Per C99 6.2.5p6, for every signed integer type, there is a corresponding 02084 // unsigned integer type. This method takes a signed type, and returns the 02085 // corresponding unsigned integer type. 02086 QualType getCorrespondingUnsignedType(QualType T) const; 02087 02088 //===--------------------------------------------------------------------===// 02089 // Type Iterators. 02090 //===--------------------------------------------------------------------===// 02091 typedef llvm::iterator_range<SmallVectorImpl<Type *>::const_iterator> 02092 type_const_range; 02093 02094 type_const_range types() const { 02095 return type_const_range(Types.begin(), Types.end()); 02096 } 02097 02098 //===--------------------------------------------------------------------===// 02099 // Integer Values 02100 //===--------------------------------------------------------------------===// 02101 02102 /// \brief Make an APSInt of the appropriate width and signedness for the 02103 /// given \p Value and integer \p Type. 02104 llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const { 02105 llvm::APSInt Res(getIntWidth(Type), 02106 !Type->isSignedIntegerOrEnumerationType()); 02107 Res = Value; 02108 return Res; 02109 } 02110 02111 bool isSentinelNullExpr(const Expr *E); 02112 02113 /// \brief Get the implementation of the ObjCInterfaceDecl \p D, or NULL if 02114 /// none exists. 02115 ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D); 02116 /// \brief Get the implementation of the ObjCCategoryDecl \p D, or NULL if 02117 /// none exists. 02118 ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D); 02119 02120 /// \brief Return true if there is at least one \@implementation in the TU. 02121 bool AnyObjCImplementation() { 02122 return !ObjCImpls.empty(); 02123 } 02124 02125 /// \brief Set the implementation of ObjCInterfaceDecl. 02126 void setObjCImplementation(ObjCInterfaceDecl *IFaceD, 02127 ObjCImplementationDecl *ImplD); 02128 /// \brief Set the implementation of ObjCCategoryDecl. 02129 void setObjCImplementation(ObjCCategoryDecl *CatD, 02130 ObjCCategoryImplDecl *ImplD); 02131 02132 /// \brief Get the duplicate declaration of a ObjCMethod in the same 02133 /// interface, or null if none exists. 02134 const ObjCMethodDecl *getObjCMethodRedeclaration( 02135 const ObjCMethodDecl *MD) const { 02136 return ObjCMethodRedecls.lookup(MD); 02137 } 02138 02139 void setObjCMethodRedeclaration(const ObjCMethodDecl *MD, 02140 const ObjCMethodDecl *Redecl) { 02141 assert(!getObjCMethodRedeclaration(MD) && "MD already has a redeclaration"); 02142 ObjCMethodRedecls[MD] = Redecl; 02143 } 02144 02145 /// \brief Returns the Objective-C interface that \p ND belongs to if it is 02146 /// an Objective-C method/property/ivar etc. that is part of an interface, 02147 /// otherwise returns null. 02148 const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const; 02149 02150 /// \brief Set the copy inialization expression of a block var decl. 02151 void setBlockVarCopyInits(VarDecl*VD, Expr* Init); 02152 /// \brief Get the copy initialization expression of the VarDecl \p VD, or 02153 /// NULL if none exists. 02154 Expr *getBlockVarCopyInits(const VarDecl* VD); 02155 02156 /// \brief Allocate an uninitialized TypeSourceInfo. 02157 /// 02158 /// The caller should initialize the memory held by TypeSourceInfo using 02159 /// the TypeLoc wrappers. 02160 /// 02161 /// \param T the type that will be the basis for type source info. This type 02162 /// should refer to how the declarator was written in source code, not to 02163 /// what type semantic analysis resolved the declarator to. 02164 /// 02165 /// \param Size the size of the type info to create, or 0 if the size 02166 /// should be calculated based on the type. 02167 TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const; 02168 02169 /// \brief Allocate a TypeSourceInfo where all locations have been 02170 /// initialized to a given location, which defaults to the empty 02171 /// location. 02172 TypeSourceInfo * 02173 getTrivialTypeSourceInfo(QualType T, 02174 SourceLocation Loc = SourceLocation()) const; 02175 02176 TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; } 02177 02178 /// \brief Add a deallocation callback that will be invoked when the 02179 /// ASTContext is destroyed. 02180 /// 02181 /// \param Callback A callback function that will be invoked on destruction. 02182 /// 02183 /// \param Data Pointer data that will be provided to the callback function 02184 /// when it is called. 02185 void AddDeallocation(void (*Callback)(void*), void *Data); 02186 02187 GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const; 02188 GVALinkage GetGVALinkageForVariable(const VarDecl *VD); 02189 02190 /// \brief Determines if the decl can be CodeGen'ed or deserialized from PCH 02191 /// lazily, only when used; this is only relevant for function or file scoped 02192 /// var definitions. 02193 /// 02194 /// \returns true if the function/var must be CodeGen'ed/deserialized even if 02195 /// it is not used. 02196 bool DeclMustBeEmitted(const Decl *D); 02197 02198 void setManglingNumber(const NamedDecl *ND, unsigned Number); 02199 unsigned getManglingNumber(const NamedDecl *ND) const; 02200 02201 void setStaticLocalNumber(const VarDecl *VD, unsigned Number); 02202 unsigned getStaticLocalNumber(const VarDecl *VD) const; 02203 02204 /// \brief Retrieve the context for computing mangling numbers in the given 02205 /// DeclContext. 02206 MangleNumberingContext &getManglingNumberContext(const DeclContext *DC); 02207 02208 MangleNumberingContext *createMangleNumberingContext() const; 02209 02210 /// \brief Used by ParmVarDecl to store on the side the 02211 /// index of the parameter when it exceeds the size of the normal bitfield. 02212 void setParameterIndex(const ParmVarDecl *D, unsigned index); 02213 02214 /// \brief Used by ParmVarDecl to retrieve on the side the 02215 /// index of the parameter when it exceeds the size of the normal bitfield. 02216 unsigned getParameterIndex(const ParmVarDecl *D) const; 02217 02218 /// \brief Get the storage for the constant value of a materialized temporary 02219 /// of static storage duration. 02220 APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E, 02221 bool MayCreate); 02222 02223 //===--------------------------------------------------------------------===// 02224 // Statistics 02225 //===--------------------------------------------------------------------===// 02226 02227 /// \brief The number of implicitly-declared default constructors. 02228 static unsigned NumImplicitDefaultConstructors; 02229 02230 /// \brief The number of implicitly-declared default constructors for 02231 /// which declarations were built. 02232 static unsigned NumImplicitDefaultConstructorsDeclared; 02233 02234 /// \brief The number of implicitly-declared copy constructors. 02235 static unsigned NumImplicitCopyConstructors; 02236 02237 /// \brief The number of implicitly-declared copy constructors for 02238 /// which declarations were built. 02239 static unsigned NumImplicitCopyConstructorsDeclared; 02240 02241 /// \brief The number of implicitly-declared move constructors. 02242 static unsigned NumImplicitMoveConstructors; 02243 02244 /// \brief The number of implicitly-declared move constructors for 02245 /// which declarations were built. 02246 static unsigned NumImplicitMoveConstructorsDeclared; 02247 02248 /// \brief The number of implicitly-declared copy assignment operators. 02249 static unsigned NumImplicitCopyAssignmentOperators; 02250 02251 /// \brief The number of implicitly-declared copy assignment operators for 02252 /// which declarations were built. 02253 static unsigned NumImplicitCopyAssignmentOperatorsDeclared; 02254 02255 /// \brief The number of implicitly-declared move assignment operators. 02256 static unsigned NumImplicitMoveAssignmentOperators; 02257 02258 /// \brief The number of implicitly-declared move assignment operators for 02259 /// which declarations were built. 02260 static unsigned NumImplicitMoveAssignmentOperatorsDeclared; 02261 02262 /// \brief The number of implicitly-declared destructors. 02263 static unsigned NumImplicitDestructors; 02264 02265 /// \brief The number of implicitly-declared destructors for which 02266 /// declarations were built. 02267 static unsigned NumImplicitDestructorsDeclared; 02268 02269 private: 02270 ASTContext(const ASTContext &) LLVM_DELETED_FUNCTION; 02271 void operator=(const ASTContext &) LLVM_DELETED_FUNCTION; 02272 02273 public: 02274 /// \brief Initialize built-in types. 02275 /// 02276 /// This routine may only be invoked once for a given ASTContext object. 02277 /// It is normally invoked after ASTContext construction. 02278 /// 02279 /// \param Target The target 02280 void InitBuiltinTypes(const TargetInfo &Target); 02281 02282 private: 02283 void InitBuiltinType(CanQualType &R, BuiltinType::Kind K); 02284 02285 // Return the Objective-C type encoding for a given type. 02286 void getObjCEncodingForTypeImpl(QualType t, std::string &S, 02287 bool ExpandPointedToStructures, 02288 bool ExpandStructures, 02289 const FieldDecl *Field, 02290 bool OutermostType = false, 02291 bool EncodingProperty = false, 02292 bool StructField = false, 02293 bool EncodeBlockParameters = false, 02294 bool EncodeClassNames = false, 02295 bool EncodePointerToObjCTypedef = false, 02296 QualType *NotEncodedT=nullptr) const; 02297 02298 // Adds the encoding of the structure's members. 02299 void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S, 02300 const FieldDecl *Field, 02301 bool includeVBases = true, 02302 QualType *NotEncodedT=nullptr) const; 02303 public: 02304 // Adds the encoding of a method parameter or return type. 02305 void getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT, 02306 QualType T, std::string& S, 02307 bool Extended) const; 02308 02309 /// \brief Returns true if this is an inline-initialized static data member 02310 /// which is treated as a definition for MSVC compatibility. 02311 bool isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const; 02312 02313 private: 02314 const ASTRecordLayout & 02315 getObjCLayout(const ObjCInterfaceDecl *D, 02316 const ObjCImplementationDecl *Impl) const; 02317 02318 /// \brief A set of deallocations that should be performed when the 02319 /// ASTContext is destroyed. 02320 typedef llvm::SmallDenseMap<void(*)(void*), llvm::SmallVector<void*, 16> > 02321 DeallocationMap; 02322 DeallocationMap Deallocations; 02323 02324 // FIXME: This currently contains the set of StoredDeclMaps used 02325 // by DeclContext objects. This probably should not be in ASTContext, 02326 // but we include it here so that ASTContext can quickly deallocate them. 02327 llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM; 02328 02329 friend class DeclContext; 02330 friend class DeclarationNameTable; 02331 void ReleaseDeclContextMaps(); 02332 void ReleaseParentMapEntries(); 02333 02334 std::unique_ptr<ParentMap> AllParents; 02335 02336 std::unique_ptr<VTableContextBase> VTContext; 02337 02338 public: 02339 enum PragmaSectionFlag : unsigned { 02340 PSF_None = 0, 02341 PSF_Read = 0x1, 02342 PSF_Write = 0x2, 02343 PSF_Execute = 0x4, 02344 PSF_Implicit = 0x8, 02345 PSF_Invalid = 0x80000000U, 02346 }; 02347 02348 struct SectionInfo { 02349 DeclaratorDecl *Decl; 02350 SourceLocation PragmaSectionLocation; 02351 int SectionFlags; 02352 SectionInfo() {} 02353 SectionInfo(DeclaratorDecl *Decl, 02354 SourceLocation PragmaSectionLocation, 02355 int SectionFlags) 02356 : Decl(Decl), 02357 PragmaSectionLocation(PragmaSectionLocation), 02358 SectionFlags(SectionFlags) {} 02359 }; 02360 02361 llvm::StringMap<SectionInfo> SectionInfos; 02362 }; 02363 02364 /// \brief Utility function for constructing a nullary selector. 02365 static inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) { 02366 IdentifierInfo* II = &Ctx.Idents.get(name); 02367 return Ctx.Selectors.getSelector(0, &II); 02368 } 02369 02370 /// \brief Utility function for constructing an unary selector. 02371 static inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) { 02372 IdentifierInfo* II = &Ctx.Idents.get(name); 02373 return Ctx.Selectors.getSelector(1, &II); 02374 } 02375 02376 } // end namespace clang 02377 02378 // operator new and delete aren't allowed inside namespaces. 02379 02380 /// @brief Placement new for using the ASTContext's allocator. 02381 /// 02382 /// This placement form of operator new uses the ASTContext's allocator for 02383 /// obtaining memory. 02384 /// 02385 /// IMPORTANT: These are also declared in clang/AST/AttrIterator.h! Any changes 02386 /// here need to also be made there. 02387 /// 02388 /// We intentionally avoid using a nothrow specification here so that the calls 02389 /// to this operator will not perform a null check on the result -- the 02390 /// underlying allocator never returns null pointers. 02391 /// 02392 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 02393 /// @code 02394 /// // Default alignment (8) 02395 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments); 02396 /// // Specific alignment 02397 /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments); 02398 /// @endcode 02399 /// Memory allocated through this placement new operator does not need to be 02400 /// explicitly freed, as ASTContext will free all of this memory when it gets 02401 /// destroyed. Please note that you cannot use delete on the pointer. 02402 /// 02403 /// @param Bytes The number of bytes to allocate. Calculated by the compiler. 02404 /// @param C The ASTContext that provides the allocator. 02405 /// @param Alignment The alignment of the allocated memory (if the underlying 02406 /// allocator supports it). 02407 /// @return The allocated memory. Could be NULL. 02408 inline void *operator new(size_t Bytes, const clang::ASTContext &C, 02409 size_t Alignment) { 02410 return C.Allocate(Bytes, Alignment); 02411 } 02412 /// @brief Placement delete companion to the new above. 02413 /// 02414 /// This operator is just a companion to the new above. There is no way of 02415 /// invoking it directly; see the new operator for more details. This operator 02416 /// is called implicitly by the compiler if a placement new expression using 02417 /// the ASTContext throws in the object constructor. 02418 inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) { 02419 C.Deallocate(Ptr); 02420 } 02421 02422 /// This placement form of operator new[] uses the ASTContext's allocator for 02423 /// obtaining memory. 02424 /// 02425 /// We intentionally avoid using a nothrow specification here so that the calls 02426 /// to this operator will not perform a null check on the result -- the 02427 /// underlying allocator never returns null pointers. 02428 /// 02429 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 02430 /// @code 02431 /// // Default alignment (8) 02432 /// char *data = new (Context) char[10]; 02433 /// // Specific alignment 02434 /// char *data = new (Context, 4) char[10]; 02435 /// @endcode 02436 /// Memory allocated through this placement new[] operator does not need to be 02437 /// explicitly freed, as ASTContext will free all of this memory when it gets 02438 /// destroyed. Please note that you cannot use delete on the pointer. 02439 /// 02440 /// @param Bytes The number of bytes to allocate. Calculated by the compiler. 02441 /// @param C The ASTContext that provides the allocator. 02442 /// @param Alignment The alignment of the allocated memory (if the underlying 02443 /// allocator supports it). 02444 /// @return The allocated memory. Could be NULL. 02445 inline void *operator new[](size_t Bytes, const clang::ASTContext& C, 02446 size_t Alignment = 8) { 02447 return C.Allocate(Bytes, Alignment); 02448 } 02449 02450 /// @brief Placement delete[] companion to the new[] above. 02451 /// 02452 /// This operator is just a companion to the new[] above. There is no way of 02453 /// invoking it directly; see the new[] operator for more details. This operator 02454 /// is called implicitly by the compiler if a placement new[] expression using 02455 /// the ASTContext throws in the object constructor. 02456 inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) { 02457 C.Deallocate(Ptr); 02458 } 02459 02460 /// \brief Create the representation of a LazyGenerationalUpdatePtr. 02461 template <typename Owner, typename T, 02462 void (clang::ExternalASTSource::*Update)(Owner)> 02463 typename clang::LazyGenerationalUpdatePtr<Owner, T, Update>::ValueType 02464 clang::LazyGenerationalUpdatePtr<Owner, T, Update>::makeValue( 02465 const clang::ASTContext &Ctx, T Value) { 02466 // Note, this is implemented here so that ExternalASTSource.h doesn't need to 02467 // include ASTContext.h. We explicitly instantiate it for all relevant types 02468 // in ASTContext.cpp. 02469 if (auto *Source = Ctx.getExternalSource()) 02470 return new (Ctx) LazyData(Source, Value); 02471 return Value; 02472 } 02473 02474 #endif