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