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