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