1 //===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ASTContext interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_ASTCONTEXT_H
15 #define LLVM_CLANG_AST_ASTCONTEXT_H
17 #include "clang/Basic/AddressSpaces.h"
18 #include "clang/Basic/IdentifierTable.h"
19 #include "clang/Basic/LangOptions.h"
20 #include "clang/Basic/OperatorKinds.h"
21 #include "clang/Basic/PartialDiagnostic.h"
22 #include "clang/Basic/VersionTuple.h"
23 #include "clang/AST/Decl.h"
24 #include "clang/AST/NestedNameSpecifier.h"
25 #include "clang/AST/PrettyPrinter.h"
26 #include "clang/AST/TemplateName.h"
27 #include "clang/AST/Type.h"
28 #include "clang/AST/CanonicalType.h"
29 #include "clang/AST/UsuallyTinyPtrVector.h"
30 #include "llvm/ADT/DenseMap.h"
31 #include "llvm/ADT/FoldingSet.h"
32 #include "llvm/ADT/IntrusiveRefCntPtr.h"
33 #include "llvm/ADT/OwningPtr.h"
34 #include "llvm/ADT/SmallPtrSet.h"
35 #include "llvm/Support/Allocator.h"
44 class ASTRecordLayout;
47 class DiagnosticsEngine;
49 class ExternalASTSource;
50 class ASTMutationListener;
51 class IdentifierTable;
64 class ObjCIvarRefExpr;
65 class ObjCPropertyDecl;
70 class TemplateTemplateParmDecl;
71 class TemplateTypeParmDecl;
72 class TranslationUnitDecl;
74 class TypedefNameDecl;
76 class UsingShadowDecl;
77 class UnresolvedSetIterator;
79 namespace Builtin { class Context; }
81 /// ASTContext - This class holds long-lived AST nodes (such as types and
82 /// decls) that can be referred to throughout the semantic analysis of a file.
83 class ASTContext : public llvm::RefCountedBase<ASTContext> {
84 ASTContext &this_() { return *this; }
86 mutable std::vector<Type*> Types;
87 mutable llvm::FoldingSet<ExtQuals> ExtQualNodes;
88 mutable llvm::FoldingSet<ComplexType> ComplexTypes;
89 mutable llvm::FoldingSet<PointerType> PointerTypes;
90 mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
91 mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
92 mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
93 mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
94 mutable llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
95 mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
96 mutable std::vector<VariableArrayType*> VariableArrayTypes;
97 mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
98 mutable llvm::FoldingSet<DependentSizedExtVectorType>
99 DependentSizedExtVectorTypes;
100 mutable llvm::FoldingSet<VectorType> VectorTypes;
101 mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
102 mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&>
104 mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
105 mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
106 mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
107 mutable llvm::FoldingSet<SubstTemplateTypeParmType>
108 SubstTemplateTypeParmTypes;
109 mutable llvm::FoldingSet<SubstTemplateTypeParmPackType>
110 SubstTemplateTypeParmPackTypes;
111 mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
112 TemplateSpecializationTypes;
113 mutable llvm::FoldingSet<ParenType> ParenTypes;
114 mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
115 mutable llvm::FoldingSet<DependentNameType> DependentNameTypes;
116 mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType,
118 DependentTemplateSpecializationTypes;
119 llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
120 mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
121 mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
122 mutable llvm::FoldingSet<AutoType> AutoTypes;
123 mutable llvm::FoldingSet<AtomicType> AtomicTypes;
124 llvm::FoldingSet<AttributedType> AttributedTypes;
126 mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
127 mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
128 mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage>
129 SubstTemplateTemplateParms;
130 mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage,
132 SubstTemplateTemplateParmPacks;
134 /// \brief The set of nested name specifiers.
136 /// This set is managed by the NestedNameSpecifier class.
137 mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
138 mutable NestedNameSpecifier *GlobalNestedNameSpecifier;
139 friend class NestedNameSpecifier;
141 /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
142 /// This is lazily created. This is intentionally not serialized.
143 mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>
145 mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>
148 /// KeyFunctions - A cache mapping from CXXRecordDecls to key functions.
149 llvm::DenseMap<const CXXRecordDecl*, const CXXMethodDecl*> KeyFunctions;
151 /// \brief Mapping from ObjCContainers to their ObjCImplementations.
152 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
154 /// \brief Mapping from ObjCMethod to its duplicate declaration in the same
156 llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls;
158 /// \brief Mapping from __block VarDecls to their copy initialization expr.
159 llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits;
161 /// \brief Mapping from class scope functions specialization to their
162 /// template patterns.
163 llvm::DenseMap<const FunctionDecl*, FunctionDecl*>
164 ClassScopeSpecializationPattern;
166 /// \brief Representation of a "canonical" template template parameter that
167 /// is used in canonical template names.
168 class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
169 TemplateTemplateParmDecl *Parm;
172 CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm)
175 TemplateTemplateParmDecl *getParam() const { return Parm; }
177 void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); }
179 static void Profile(llvm::FoldingSetNodeID &ID,
180 TemplateTemplateParmDecl *Parm);
182 mutable llvm::FoldingSet<CanonicalTemplateTemplateParm>
183 CanonTemplateTemplateParms;
185 TemplateTemplateParmDecl *
186 getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const;
188 /// \brief The typedef for the __int128_t type.
189 mutable TypedefDecl *Int128Decl;
191 /// \brief The typedef for the __uint128_t type.
192 mutable TypedefDecl *UInt128Decl;
194 /// BuiltinVaListType - built-in va list type.
195 /// This is initially null and set by Sema::LazilyCreateBuiltin when
196 /// a builtin that takes a valist is encountered.
197 QualType BuiltinVaListType;
199 /// \brief The typedef for the predefined 'id' type.
200 mutable TypedefDecl *ObjCIdDecl;
202 /// \brief The typedef for the predefined 'SEL' type.
203 mutable TypedefDecl *ObjCSelDecl;
205 QualType ObjCProtoType;
206 const RecordType *ProtoStructType;
208 /// \brief The typedef for the predefined 'Class' type.
209 mutable TypedefDecl *ObjCClassDecl;
211 // Typedefs which may be provided defining the structure of Objective-C
213 QualType ObjCIdRedefinitionType;
214 QualType ObjCClassRedefinitionType;
215 QualType ObjCSelRedefinitionType;
217 QualType ObjCConstantStringType;
218 mutable RecordDecl *CFConstantStringTypeDecl;
220 /// \brief The typedef declaration for the Objective-C "instancetype" type.
221 TypedefDecl *ObjCInstanceTypeDecl;
223 /// \brief The type for the C FILE type.
226 /// \brief The type for the C jmp_buf type.
227 TypeDecl *jmp_bufDecl;
229 /// \brief The type for the C sigjmp_buf type.
230 TypeDecl *sigjmp_bufDecl;
232 /// \brief Type for the Block descriptor for Blocks CodeGen.
234 /// Since this is only used for generation of debug info, it is not
236 mutable RecordDecl *BlockDescriptorType;
238 /// \brief Type for the Block descriptor for Blocks CodeGen.
240 /// Since this is only used for generation of debug info, it is not
242 mutable RecordDecl *BlockDescriptorExtendedType;
244 /// \brief Declaration for the CUDA cudaConfigureCall function.
245 FunctionDecl *cudaConfigureCallDecl;
247 TypeSourceInfo NullTypeSourceInfo;
249 /// \brief Keeps track of all declaration attributes.
251 /// Since so few decls have attrs, we keep them in a hash map instead of
252 /// wasting space in the Decl class.
253 llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs;
255 /// \brief Keeps track of the static data member templates from which
256 /// static data members of class template specializations were instantiated.
258 /// This data structure stores the mapping from instantiations of static
259 /// data members to the static data member representations within the
260 /// class template from which they were instantiated along with the kind
261 /// of instantiation or specialization (a TemplateSpecializationKind - 1).
263 /// Given the following example:
266 /// template<typename T>
271 /// template<typename T>
272 /// T X<T>::value = T(17);
274 /// int *x = &X<int>::value;
277 /// This mapping will contain an entry that maps from the VarDecl for
278 /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
279 /// class template X) and will be marked TSK_ImplicitInstantiation.
280 llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *>
281 InstantiatedFromStaticDataMember;
283 /// \brief Keeps track of the declaration from which a UsingDecl was
284 /// created during instantiation. The source declaration is always
285 /// a UsingDecl, an UnresolvedUsingValueDecl, or an
286 /// UnresolvedUsingTypenameDecl.
290 /// template<typename T>
295 /// template<typename T>
296 /// struct B : A<T> {
300 /// template struct B<int>;
303 /// This mapping will contain an entry that maps from the UsingDecl in
304 /// B<int> to the UnresolvedUsingDecl in B<T>.
305 llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl;
307 llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
308 InstantiatedFromUsingShadowDecl;
310 llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
312 /// \brief Mapping that stores the methods overridden by a given C++
315 /// Since most C++ member functions aren't virtual and therefore
316 /// don't override anything, we store the overridden functions in
317 /// this map on the side rather than within the CXXMethodDecl structure.
318 typedef UsuallyTinyPtrVector<const CXXMethodDecl> CXXMethodVector;
319 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
321 /// \brief Mapping that stores parameterIndex values for ParmVarDecls
322 /// when that value exceeds the bitfield size of
323 /// ParmVarDeclBits.ParameterIndex.
324 typedef llvm::DenseMap<const VarDecl *, unsigned> ParameterIndexTable;
325 ParameterIndexTable ParamIndices;
327 TranslationUnitDecl *TUDecl;
329 /// SourceMgr - The associated SourceManager object.
330 SourceManager &SourceMgr;
332 /// LangOpts - The language options used to create the AST associated with
333 /// this ASTContext object.
334 LangOptions &LangOpts;
336 /// \brief The allocator used to create AST objects.
338 /// AST objects are never destructed; rather, all memory associated with the
339 /// AST objects will be released when the ASTContext itself is destroyed.
340 mutable llvm::BumpPtrAllocator BumpAlloc;
342 /// \brief Allocator for partial diagnostics.
343 PartialDiagnostic::StorageAllocator DiagAllocator;
345 /// \brief The current C++ ABI.
346 llvm::OwningPtr<CXXABI> ABI;
347 CXXABI *createCXXABI(const TargetInfo &T);
349 /// \brief The logical -> physical address space map.
350 const LangAS::Map *AddrSpaceMap;
352 friend class ASTDeclReader;
353 friend class ASTReader;
354 friend class ASTWriter;
356 const TargetInfo *Target;
357 clang::PrintingPolicy PrintingPolicy;
360 IdentifierTable &Idents;
361 SelectorTable &Selectors;
362 Builtin::Context &BuiltinInfo;
363 mutable DeclarationNameTable DeclarationNames;
364 llvm::OwningPtr<ExternalASTSource> ExternalSource;
365 ASTMutationListener *Listener;
367 clang::PrintingPolicy getPrintingPolicy() const { return PrintingPolicy; }
369 void setPrintingPolicy(clang::PrintingPolicy Policy) {
370 PrintingPolicy = Policy;
373 SourceManager& getSourceManager() { return SourceMgr; }
374 const SourceManager& getSourceManager() const { return SourceMgr; }
375 void *Allocate(unsigned Size, unsigned Align = 8) const {
376 return BumpAlloc.Allocate(Size, Align);
378 void Deallocate(void *Ptr) const { }
380 /// Return the total amount of physical memory allocated for representing
381 /// AST nodes and type information.
382 size_t getASTAllocatedMemory() const {
383 return BumpAlloc.getTotalMemory();
385 /// Return the total memory used for various side tables.
386 size_t getSideTableAllocatedMemory() const;
388 PartialDiagnostic::StorageAllocator &getDiagAllocator() {
389 return DiagAllocator;
392 const TargetInfo &getTargetInfo() const { return *Target; }
394 const LangOptions& getLangOptions() const { return LangOpts; }
396 DiagnosticsEngine &getDiagnostics() const;
398 FullSourceLoc getFullLoc(SourceLocation Loc) const {
399 return FullSourceLoc(Loc,SourceMgr);
402 /// \brief Retrieve the attributes for the given declaration.
403 AttrVec& getDeclAttrs(const Decl *D);
405 /// \brief Erase the attributes corresponding to the given declaration.
406 void eraseDeclAttrs(const Decl *D);
408 /// \brief If this variable is an instantiated static data member of a
409 /// class template specialization, returns the templated static data member
410 /// from which it was instantiated.
411 MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
414 FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD);
416 void setClassScopeSpecializationPattern(FunctionDecl *FD,
417 FunctionDecl *Pattern);
419 /// \brief Note that the static data member \p Inst is an instantiation of
420 /// the static data member template \p Tmpl of a class template.
421 void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
422 TemplateSpecializationKind TSK,
423 SourceLocation PointOfInstantiation = SourceLocation());
425 /// \brief If the given using decl is an instantiation of a
426 /// (possibly unresolved) using decl from a template instantiation,
428 NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
430 /// \brief Remember that the using decl \p Inst is an instantiation
431 /// of the using decl \p Pattern of a class template.
432 void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
434 void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
435 UsingShadowDecl *Pattern);
436 UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
438 FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
440 void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
442 /// ZeroBitfieldFollowsNonBitfield - return 'true" if 'FD' is a zero-length
443 /// bitfield which follows the non-bitfield 'LastFD'.
444 bool ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD,
445 const FieldDecl *LastFD) const;
447 /// ZeroBitfieldFollowsBitfield - return 'true" if 'FD' is a zero-length
448 /// bitfield which follows the bitfield 'LastFD'.
449 bool ZeroBitfieldFollowsBitfield(const FieldDecl *FD,
450 const FieldDecl *LastFD) const;
452 /// BitfieldFollowsBitfield - return 'true" if 'FD' is a
453 /// bitfield which follows the bitfield 'LastFD'.
454 bool BitfieldFollowsBitfield(const FieldDecl *FD,
455 const FieldDecl *LastFD) const;
457 /// NonBitfieldFollowsBitfield - return 'true" if 'FD' is not a
458 /// bitfield which follows the bitfield 'LastFD'.
459 bool NonBitfieldFollowsBitfield(const FieldDecl *FD,
460 const FieldDecl *LastFD) const;
462 /// BitfieldFollowsNonBitfield - return 'true" if 'FD' is a
463 /// bitfield which follows the none bitfield 'LastFD'.
464 bool BitfieldFollowsNonBitfield(const FieldDecl *FD,
465 const FieldDecl *LastFD) const;
467 // Access to the set of methods overridden by the given C++ method.
468 typedef CXXMethodVector::iterator overridden_cxx_method_iterator;
469 overridden_cxx_method_iterator
470 overridden_methods_begin(const CXXMethodDecl *Method) const;
472 overridden_cxx_method_iterator
473 overridden_methods_end(const CXXMethodDecl *Method) const;
475 unsigned overridden_methods_size(const CXXMethodDecl *Method) const;
477 /// \brief Note that the given C++ \p Method overrides the given \p
478 /// Overridden method.
479 void addOverriddenMethod(const CXXMethodDecl *Method,
480 const CXXMethodDecl *Overridden);
482 TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
489 CanQualType WCharTy; // [C++ 3.9.1p5], integer type in C99.
490 CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
491 CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
492 CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
493 CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
494 CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
495 CanQualType FloatTy, DoubleTy, LongDoubleTy;
496 CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
497 CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
498 CanQualType VoidPtrTy, NullPtrTy;
499 CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
500 CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
502 // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
503 mutable QualType AutoDeductTy; // Deduction against 'auto'.
504 mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'.
506 ASTContext(LangOptions& LOpts, SourceManager &SM, const TargetInfo *t,
507 IdentifierTable &idents, SelectorTable &sels,
508 Builtin::Context &builtins,
509 unsigned size_reserve,
510 bool DelayInitialization = false);
514 /// \brief Attach an external AST source to the AST context.
516 /// The external AST source provides the ability to load parts of
517 /// the abstract syntax tree as needed from some external storage,
518 /// e.g., a precompiled header.
519 void setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source);
521 /// \brief Retrieve a pointer to the external AST source associated
522 /// with this AST context, if any.
523 ExternalASTSource *getExternalSource() const { return ExternalSource.get(); }
525 /// \brief Attach an AST mutation listener to the AST context.
527 /// The AST mutation listener provides the ability to track modifications to
528 /// the abstract syntax tree entities committed after they were initially
530 void setASTMutationListener(ASTMutationListener *Listener) {
531 this->Listener = Listener;
534 /// \brief Retrieve a pointer to the AST mutation listener associated
535 /// with this AST context, if any.
536 ASTMutationListener *getASTMutationListener() const { return Listener; }
538 void PrintStats() const;
539 const std::vector<Type*>& getTypes() const { return Types; }
541 /// \brief Retrieve the declaration for the 128-bit signed integer type.
542 TypedefDecl *getInt128Decl() const;
544 /// \brief Retrieve the declaration for the 128-bit unsigned integer type.
545 TypedefDecl *getUInt128Decl() const;
547 //===--------------------------------------------------------------------===//
549 //===--------------------------------------------------------------------===//
552 /// getExtQualType - Return a type with extended qualifiers.
553 QualType getExtQualType(const Type *Base, Qualifiers Quals) const;
555 QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;
558 /// getAddSpaceQualType - Return the uniqued reference to the type for an
559 /// address space qualified type with the specified type and address space.
560 /// The resulting type has a union of the qualifiers from T and the address
561 /// space. If T already has an address space specifier, it is silently
563 QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const;
565 /// getObjCGCQualType - Returns the uniqued reference to the type for an
566 /// objc gc qualified type. The retulting type has a union of the qualifiers
567 /// from T and the gc attribute.
568 QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
570 /// getRestrictType - Returns the uniqued reference to the type for a
571 /// 'restrict' qualified type. The resulting type has a union of the
572 /// qualifiers from T and 'restrict'.
573 QualType getRestrictType(QualType T) const {
574 return T.withFastQualifiers(Qualifiers::Restrict);
577 /// getVolatileType - Returns the uniqued reference to the type for a
578 /// 'volatile' qualified type. The resulting type has a union of the
579 /// qualifiers from T and 'volatile'.
580 QualType getVolatileType(QualType T) const {
581 return T.withFastQualifiers(Qualifiers::Volatile);
584 /// getConstType - Returns the uniqued reference to the type for a
585 /// 'const' qualified type. The resulting type has a union of the
586 /// qualifiers from T and 'const'.
588 /// It can be reasonably expected that this will always be
589 /// equivalent to calling T.withConst().
590 QualType getConstType(QualType T) const { return T.withConst(); }
592 /// adjustFunctionType - Change the ExtInfo on a function type.
593 const FunctionType *adjustFunctionType(const FunctionType *Fn,
594 FunctionType::ExtInfo EInfo);
596 /// getComplexType - Return the uniqued reference to the type for a complex
597 /// number with the specified element type.
598 QualType getComplexType(QualType T) const;
599 CanQualType getComplexType(CanQualType T) const {
600 return CanQualType::CreateUnsafe(getComplexType((QualType) T));
603 /// getPointerType - Return the uniqued reference to the type for a pointer to
604 /// the specified type.
605 QualType getPointerType(QualType T) const;
606 CanQualType getPointerType(CanQualType T) const {
607 return CanQualType::CreateUnsafe(getPointerType((QualType) T));
610 /// getAtomicType - Return the uniqued reference to the atomic type for
611 /// the specified type.
612 QualType getAtomicType(QualType T) const;
614 /// getBlockPointerType - Return the uniqued reference to the type for a block
615 /// of the specified type.
616 QualType getBlockPointerType(QualType T) const;
618 /// This gets the struct used to keep track of the descriptor for pointer to
620 QualType getBlockDescriptorType() const;
622 /// This gets the struct used to keep track of the extended descriptor for
623 /// pointer to blocks.
624 QualType getBlockDescriptorExtendedType() const;
626 void setcudaConfigureCallDecl(FunctionDecl *FD) {
627 cudaConfigureCallDecl = FD;
629 FunctionDecl *getcudaConfigureCallDecl() {
630 return cudaConfigureCallDecl;
633 /// This builds the struct used for __block variables.
634 QualType BuildByRefType(StringRef DeclName, QualType Ty) const;
636 /// Returns true iff we need copy/dispose helpers for the given type.
637 bool BlockRequiresCopying(QualType Ty) const;
639 /// getLValueReferenceType - Return the uniqued reference to the type for an
640 /// lvalue reference to the specified type.
641 QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true)
644 /// getRValueReferenceType - Return the uniqued reference to the type for an
645 /// rvalue reference to the specified type.
646 QualType getRValueReferenceType(QualType T) const;
648 /// getMemberPointerType - Return the uniqued reference to the type for a
649 /// member pointer to the specified type in the specified class. The class
650 /// is a Type because it could be a dependent name.
651 QualType getMemberPointerType(QualType T, const Type *Cls) const;
653 /// getVariableArrayType - Returns a non-unique reference to the type for a
654 /// variable array of the specified element type.
655 QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
656 ArrayType::ArraySizeModifier ASM,
657 unsigned IndexTypeQuals,
658 SourceRange Brackets) const;
660 /// getDependentSizedArrayType - Returns a non-unique reference to
661 /// the type for a dependently-sized array of the specified element
662 /// type. FIXME: We will need these to be uniqued, or at least
663 /// comparable, at some point.
664 QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
665 ArrayType::ArraySizeModifier ASM,
666 unsigned IndexTypeQuals,
667 SourceRange Brackets) const;
669 /// getIncompleteArrayType - Returns a unique reference to the type for a
670 /// incomplete array of the specified element type.
671 QualType getIncompleteArrayType(QualType EltTy,
672 ArrayType::ArraySizeModifier ASM,
673 unsigned IndexTypeQuals) const;
675 /// getConstantArrayType - Return the unique reference to the type for a
676 /// constant array of the specified element type.
677 QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
678 ArrayType::ArraySizeModifier ASM,
679 unsigned IndexTypeQuals) const;
681 /// getVariableArrayDecayedType - Returns a vla type where known sizes
682 /// are replaced with [*].
683 QualType getVariableArrayDecayedType(QualType Ty) const;
685 /// getVectorType - Return the unique reference to a vector type of
686 /// the specified element type and size. VectorType must be a built-in type.
687 QualType getVectorType(QualType VectorType, unsigned NumElts,
688 VectorType::VectorKind VecKind) const;
690 /// getExtVectorType - Return the unique reference to an extended vector type
691 /// of the specified element type and size. VectorType must be a built-in
693 QualType getExtVectorType(QualType VectorType, unsigned NumElts) const;
695 /// getDependentSizedExtVectorType - Returns a non-unique reference to
696 /// the type for a dependently-sized vector of the specified element
697 /// type. FIXME: We will need these to be uniqued, or at least
698 /// comparable, at some point.
699 QualType getDependentSizedExtVectorType(QualType VectorType,
701 SourceLocation AttrLoc) const;
703 /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'.
705 QualType getFunctionNoProtoType(QualType ResultTy,
706 const FunctionType::ExtInfo &Info) const;
708 QualType getFunctionNoProtoType(QualType ResultTy) const {
709 return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo());
712 /// getFunctionType - Return a normal function type with a typed
714 QualType getFunctionType(QualType ResultTy,
715 const QualType *Args, unsigned NumArgs,
716 const FunctionProtoType::ExtProtoInfo &EPI) const;
718 /// getTypeDeclType - Return the unique reference to the type for
719 /// the specified type declaration.
720 QualType getTypeDeclType(const TypeDecl *Decl,
721 const TypeDecl *PrevDecl = 0) const {
722 assert(Decl && "Passed null for Decl param");
723 if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
726 assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
727 Decl->TypeForDecl = PrevDecl->TypeForDecl;
728 return QualType(PrevDecl->TypeForDecl, 0);
731 return getTypeDeclTypeSlow(Decl);
734 /// getTypedefType - Return the unique reference to the type for the
735 /// specified typedef-name decl.
736 QualType getTypedefType(const TypedefNameDecl *Decl,
737 QualType Canon = QualType()) const;
739 QualType getRecordType(const RecordDecl *Decl) const;
741 QualType getEnumType(const EnumDecl *Decl) const;
743 QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
745 QualType getAttributedType(AttributedType::Kind attrKind,
746 QualType modifiedType,
747 QualType equivalentType);
749 QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
750 QualType Replacement) const;
751 QualType getSubstTemplateTypeParmPackType(
752 const TemplateTypeParmType *Replaced,
753 const TemplateArgument &ArgPack);
755 QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
757 TemplateTypeParmDecl *ParmDecl = 0) const;
759 QualType getTemplateSpecializationType(TemplateName T,
760 const TemplateArgument *Args,
762 QualType Canon = QualType()) const;
764 QualType getCanonicalTemplateSpecializationType(TemplateName T,
765 const TemplateArgument *Args,
766 unsigned NumArgs) const;
768 QualType getTemplateSpecializationType(TemplateName T,
769 const TemplateArgumentListInfo &Args,
770 QualType Canon = QualType()) const;
773 getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc,
774 const TemplateArgumentListInfo &Args,
775 QualType Canon = QualType()) const;
777 QualType getParenType(QualType NamedType) const;
779 QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
780 NestedNameSpecifier *NNS,
781 QualType NamedType) const;
782 QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
783 NestedNameSpecifier *NNS,
784 const IdentifierInfo *Name,
785 QualType Canon = QualType()) const;
787 QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
788 NestedNameSpecifier *NNS,
789 const IdentifierInfo *Name,
790 const TemplateArgumentListInfo &Args) const;
791 QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
792 NestedNameSpecifier *NNS,
793 const IdentifierInfo *Name,
795 const TemplateArgument *Args) const;
797 QualType getPackExpansionType(QualType Pattern,
798 llvm::Optional<unsigned> NumExpansions);
800 QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl) const;
802 QualType getObjCObjectType(QualType Base,
803 ObjCProtocolDecl * const *Protocols,
804 unsigned NumProtocols) const;
806 /// getObjCObjectPointerType - Return a ObjCObjectPointerType type
807 /// for the given ObjCObjectType.
808 QualType getObjCObjectPointerType(QualType OIT) const;
810 /// getTypeOfType - GCC extension.
811 QualType getTypeOfExprType(Expr *e) const;
812 QualType getTypeOfType(QualType t) const;
814 /// getDecltypeType - C++0x decltype.
815 QualType getDecltypeType(Expr *e) const;
817 /// getUnaryTransformType - unary type transforms
818 QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType,
819 UnaryTransformType::UTTKind UKind) const;
821 /// getAutoType - C++0x deduced auto type.
822 QualType getAutoType(QualType DeducedType) const;
824 /// getAutoDeductType - C++0x deduction pattern for 'auto' type.
825 QualType getAutoDeductType() const;
827 /// getAutoRRefDeductType - C++0x deduction pattern for 'auto &&' type.
828 QualType getAutoRRefDeductType() const;
830 /// getTagDeclType - Return the unique reference to the type for the
831 /// specified TagDecl (struct/union/class/enum) decl.
832 QualType getTagDeclType(const TagDecl *Decl) const;
834 /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
835 /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
836 CanQualType getSizeType() const;
838 /// getWCharType - In C++, this returns the unique wchar_t type. In C99, this
839 /// returns a type compatible with the type defined in <stddef.h> as defined
841 QualType getWCharType() const { return WCharTy; }
843 /// getSignedWCharType - Return the type of "signed wchar_t".
844 /// Used when in C++, as a GCC extension.
845 QualType getSignedWCharType() const;
847 /// getUnsignedWCharType - Return the type of "unsigned wchar_t".
848 /// Used when in C++, as a GCC extension.
849 QualType getUnsignedWCharType() const;
851 /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
852 /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
853 QualType getPointerDiffType() const;
855 // getCFConstantStringType - Return the C structure type used to represent
856 // constant CFStrings.
857 QualType getCFConstantStringType() const;
859 /// Get the structure type used to representation CFStrings, or NULL
860 /// if it hasn't yet been built.
861 QualType getRawCFConstantStringType() const {
862 if (CFConstantStringTypeDecl)
863 return getTagDeclType(CFConstantStringTypeDecl);
866 void setCFConstantStringType(QualType T);
868 // This setter/getter represents the ObjC type for an NSConstantString.
869 void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
870 QualType getObjCConstantStringInterface() const {
871 return ObjCConstantStringType;
874 /// \brief Retrieve the type that 'id' has been defined to, which may be
875 /// different from the built-in 'id' if 'id' has been typedef'd.
876 QualType getObjCIdRedefinitionType() const {
877 if (ObjCIdRedefinitionType.isNull())
878 return getObjCIdType();
879 return ObjCIdRedefinitionType;
882 /// \brief Set the user-written type that redefines 'id'.
883 void setObjCIdRedefinitionType(QualType RedefType) {
884 ObjCIdRedefinitionType = RedefType;
887 /// \brief Retrieve the type that 'Class' has been defined to, which may be
888 /// different from the built-in 'Class' if 'Class' has been typedef'd.
889 QualType getObjCClassRedefinitionType() const {
890 if (ObjCClassRedefinitionType.isNull())
891 return getObjCClassType();
892 return ObjCClassRedefinitionType;
895 /// \brief Set the user-written type that redefines 'SEL'.
896 void setObjCClassRedefinitionType(QualType RedefType) {
897 ObjCClassRedefinitionType = RedefType;
900 /// \brief Retrieve the type that 'SEL' has been defined to, which may be
901 /// different from the built-in 'SEL' if 'SEL' has been typedef'd.
902 QualType getObjCSelRedefinitionType() const {
903 if (ObjCSelRedefinitionType.isNull())
904 return getObjCSelType();
905 return ObjCSelRedefinitionType;
909 /// \brief Set the user-written type that redefines 'SEL'.
910 void setObjCSelRedefinitionType(QualType RedefType) {
911 ObjCSelRedefinitionType = RedefType;
914 /// \brief Retrieve the Objective-C "instancetype" type, if already known;
915 /// otherwise, returns a NULL type;
916 QualType getObjCInstanceType() {
917 return getTypeDeclType(getObjCInstanceTypeDecl());
920 /// \brief Retrieve the typedef declaration corresponding to the Objective-C
921 /// "instancetype" type.
922 TypedefDecl *getObjCInstanceTypeDecl();
924 /// \brief Set the type for the C FILE type.
925 void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
927 /// \brief Retrieve the C FILE type.
928 QualType getFILEType() const {
930 return getTypeDeclType(FILEDecl);
934 /// \brief Set the type for the C jmp_buf type.
935 void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
936 this->jmp_bufDecl = jmp_bufDecl;
939 /// \brief Retrieve the C jmp_buf type.
940 QualType getjmp_bufType() const {
942 return getTypeDeclType(jmp_bufDecl);
946 /// \brief Set the type for the C sigjmp_buf type.
947 void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
948 this->sigjmp_bufDecl = sigjmp_bufDecl;
951 /// \brief Retrieve the C sigjmp_buf type.
952 QualType getsigjmp_bufType() const {
954 return getTypeDeclType(sigjmp_bufDecl);
958 /// \brief The result type of logical operations, '<', '>', '!=', etc.
959 QualType getLogicalOperationType() const {
960 return getLangOptions().CPlusPlus ? BoolTy : IntTy;
963 /// getObjCEncodingForType - Emit the ObjC type encoding for the
964 /// given type into \arg S. If \arg NameFields is specified then
965 /// record field names are also encoded.
966 void getObjCEncodingForType(QualType t, std::string &S,
967 const FieldDecl *Field=0) const;
969 void getLegacyIntegralTypeEncoding(QualType &t) const;
971 // Put the string version of type qualifiers into S.
972 void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
973 std::string &S) const;
975 /// getObjCEncodingForFunctionDecl - Returns the encoded type for this
976 /// function. This is in the same format as Objective-C method encodings.
978 /// \returns true if an error occurred (e.g., because one of the parameter
979 /// types is incomplete), false otherwise.
980 bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S);
982 /// getObjCEncodingForMethodDecl - Return the encoded type for this method
985 /// \returns true if an error occurred (e.g., because one of the parameter
986 /// types is incomplete), false otherwise.
987 bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S)
990 /// getObjCEncodingForBlock - Return the encoded type for this block
992 std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
994 /// getObjCEncodingForPropertyDecl - Return the encoded type for
995 /// this method declaration. If non-NULL, Container must be either
996 /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
997 /// only be NULL when getting encodings for protocol properties.
998 void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
999 const Decl *Container,
1000 std::string &S) const;
1002 bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
1003 ObjCProtocolDecl *rProto) const;
1005 /// getObjCEncodingTypeSize returns size of type for objective-c encoding
1006 /// purpose in characters.
1007 CharUnits getObjCEncodingTypeSize(QualType t) const;
1009 /// \brief Retrieve the typedef corresponding to the predefined 'id' type
1011 TypedefDecl *getObjCIdDecl() const;
1013 /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by
1014 /// Sema. id is always a (typedef for a) pointer type, a pointer to a struct.
1015 QualType getObjCIdType() const {
1016 return getTypeDeclType(getObjCIdDecl());
1019 /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type
1021 TypedefDecl *getObjCSelDecl() const;
1023 /// \brief Retrieve the type that corresponds to the predefined Objective-C
1025 QualType getObjCSelType() const {
1026 return getTypeDeclType(getObjCSelDecl());
1029 void setObjCProtoType(QualType QT);
1030 QualType getObjCProtoType() const { return ObjCProtoType; }
1032 /// \brief Retrieve the typedef declaration corresponding to the predefined
1033 /// Objective-C 'Class' type.
1034 TypedefDecl *getObjCClassDecl() const;
1036 /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
1037 /// Sema. 'Class' is always a (typedef for a) pointer type, a pointer to a
1039 QualType getObjCClassType() const {
1040 return getTypeDeclType(getObjCClassDecl());
1043 void setBuiltinVaListType(QualType T);
1044 QualType getBuiltinVaListType() const { return BuiltinVaListType; }
1046 /// getCVRQualifiedType - Returns a type with additional const,
1047 /// volatile, or restrict qualifiers.
1048 QualType getCVRQualifiedType(QualType T, unsigned CVR) const {
1049 return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
1052 /// getQualifiedType - Returns a type with additional qualifiers.
1053 QualType getQualifiedType(QualType T, Qualifiers Qs) const {
1054 if (!Qs.hasNonFastQualifiers())
1055 return T.withFastQualifiers(Qs.getFastQualifiers());
1056 QualifierCollector Qc(Qs);
1057 const Type *Ptr = Qc.strip(T);
1058 return getExtQualType(Ptr, Qc);
1061 /// getQualifiedType - Returns a type with additional qualifiers.
1062 QualType getQualifiedType(const Type *T, Qualifiers Qs) const {
1063 if (!Qs.hasNonFastQualifiers())
1064 return QualType(T, Qs.getFastQualifiers());
1065 return getExtQualType(T, Qs);
1068 /// getLifetimeQualifiedType - Returns a type with the given
1069 /// lifetime qualifier.
1070 QualType getLifetimeQualifiedType(QualType type,
1071 Qualifiers::ObjCLifetime lifetime) {
1072 assert(type.getObjCLifetime() == Qualifiers::OCL_None);
1073 assert(lifetime != Qualifiers::OCL_None);
1076 qs.addObjCLifetime(lifetime);
1077 return getQualifiedType(type, qs);
1080 DeclarationNameInfo getNameForTemplate(TemplateName Name,
1081 SourceLocation NameLoc) const;
1083 TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
1084 UnresolvedSetIterator End) const;
1086 TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
1087 bool TemplateKeyword,
1088 TemplateDecl *Template) const;
1090 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
1091 const IdentifierInfo *Name) const;
1092 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
1093 OverloadedOperatorKind Operator) const;
1094 TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param,
1095 TemplateName replacement) const;
1096 TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param,
1097 const TemplateArgument &ArgPack) const;
1099 enum GetBuiltinTypeError {
1100 GE_None, //< No error
1101 GE_Missing_stdio, //< Missing a type from <stdio.h>
1102 GE_Missing_setjmp //< Missing a type from <setjmp.h>
1105 /// GetBuiltinType - Return the type for the specified builtin. If
1106 /// IntegerConstantArgs is non-null, it is filled in with a bitmask of
1107 /// arguments to the builtin that are required to be integer constant
1109 QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
1110 unsigned *IntegerConstantArgs = 0) const;
1113 CanQualType getFromTargetType(unsigned Type) const;
1115 //===--------------------------------------------------------------------===//
1117 //===--------------------------------------------------------------------===//
1120 /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
1121 /// garbage collection attribute.
1123 Qualifiers::GC getObjCGCAttrKind(QualType Ty) const;
1125 /// areCompatibleVectorTypes - Return true if the given vector types
1126 /// are of the same unqualified type or if they are equivalent to the same
1127 /// GCC vector type, ignoring whether they are target-specific (AltiVec or
1129 bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
1131 /// isObjCNSObjectType - Return true if this is an NSObject object with
1132 /// its NSObject attribute set.
1133 static bool isObjCNSObjectType(QualType Ty) {
1134 return Ty->isObjCNSObjectType();
1137 //===--------------------------------------------------------------------===//
1138 // Type Sizing and Analysis
1139 //===--------------------------------------------------------------------===//
1141 /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified
1142 /// scalar floating point type.
1143 const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
1145 /// getTypeInfo - Get the size and alignment of the specified complete type in
1147 std::pair<uint64_t, unsigned> getTypeInfo(const Type *T) const;
1148 std::pair<uint64_t, unsigned> getTypeInfo(QualType T) const {
1149 return getTypeInfo(T.getTypePtr());
1152 /// getTypeSize - Return the size of the specified type, in bits. This method
1153 /// does not work on incomplete types.
1154 uint64_t getTypeSize(QualType T) const {
1155 return getTypeInfo(T).first;
1157 uint64_t getTypeSize(const Type *T) const {
1158 return getTypeInfo(T).first;
1161 /// getCharWidth - Return the size of the character type, in bits
1162 uint64_t getCharWidth() const {
1163 return getTypeSize(CharTy);
1166 /// toCharUnitsFromBits - Convert a size in bits to a size in characters.
1167 CharUnits toCharUnitsFromBits(int64_t BitSize) const;
1169 /// toBits - Convert a size in characters to a size in bits.
1170 int64_t toBits(CharUnits CharSize) const;
1172 /// getTypeSizeInChars - Return the size of the specified type, in characters.
1173 /// This method does not work on incomplete types.
1174 CharUnits getTypeSizeInChars(QualType T) const;
1175 CharUnits getTypeSizeInChars(const Type *T) const;
1177 /// getTypeAlign - Return the ABI-specified alignment of a type, in bits.
1178 /// This method does not work on incomplete types.
1179 unsigned getTypeAlign(QualType T) const {
1180 return getTypeInfo(T).second;
1182 unsigned getTypeAlign(const Type *T) const {
1183 return getTypeInfo(T).second;
1186 /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in
1187 /// characters. This method does not work on incomplete types.
1188 CharUnits getTypeAlignInChars(QualType T) const;
1189 CharUnits getTypeAlignInChars(const Type *T) const;
1191 std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const;
1192 std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const;
1194 /// getPreferredTypeAlign - Return the "preferred" alignment of the specified
1195 /// type for the current target in bits. This can be different than the ABI
1196 /// alignment in cases where it is beneficial for performance to overalign
1198 unsigned getPreferredTypeAlign(const Type *T) const;
1200 /// getDeclAlign - Return a conservative estimate of the alignment of
1201 /// the specified decl. Note that bitfields do not have a valid alignment, so
1202 /// this method will assert on them.
1203 /// If @p RefAsPointee, references are treated like their underlying type
1204 /// (for alignof), else they're treated like pointers (for CodeGen).
1205 CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false) const;
1207 /// getASTRecordLayout - Get or compute information about the layout of the
1208 /// specified record (struct/union/class), which indicates its size and field
1209 /// position information.
1210 const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const;
1212 /// getASTObjCInterfaceLayout - Get or compute information about the
1213 /// layout of the specified Objective-C interface.
1214 const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D)
1217 void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS) const;
1219 /// getASTObjCImplementationLayout - Get or compute information about
1220 /// the layout of the specified Objective-C implementation. This may
1221 /// differ from the interface if synthesized ivars are present.
1222 const ASTRecordLayout &
1223 getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const;
1225 /// getKeyFunction - Get the key function for the given record decl, or NULL
1226 /// if there isn't one. The key function is, according to the Itanium C++ ABI
1229 /// ...the first non-pure virtual function that is not inline at the point
1230 /// of class definition.
1231 const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD);
1233 bool isNearlyEmpty(const CXXRecordDecl *RD) const;
1235 MangleContext *createMangleContext();
1237 void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
1238 SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const;
1240 unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const;
1241 void CollectInheritedProtocols(const Decl *CDecl,
1242 llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
1244 //===--------------------------------------------------------------------===//
1246 //===--------------------------------------------------------------------===//
1248 /// getCanonicalType - Return the canonical (structural) type corresponding to
1249 /// the specified potentially non-canonical type. The non-canonical version
1250 /// of a type may have many "decorated" versions of types. Decorators can
1251 /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
1252 /// to be free of any of these, allowing two canonical types to be compared
1253 /// for exact equality with a simple pointer comparison.
1254 CanQualType getCanonicalType(QualType T) const {
1255 return CanQualType::CreateUnsafe(T.getCanonicalType());
1258 const Type *getCanonicalType(const Type *T) const {
1259 return T->getCanonicalTypeInternal().getTypePtr();
1262 /// getCanonicalParamType - Return the canonical parameter type
1263 /// corresponding to the specific potentially non-canonical one.
1264 /// Qualifiers are stripped off, functions are turned into function
1265 /// pointers, and arrays decay one level into pointers.
1266 CanQualType getCanonicalParamType(QualType T) const;
1268 /// \brief Determine whether the given types are equivalent.
1269 bool hasSameType(QualType T1, QualType T2) {
1270 return getCanonicalType(T1) == getCanonicalType(T2);
1273 /// \brief Returns this type as a completely-unqualified array type,
1274 /// capturing the qualifiers in Quals. This will remove the minimal amount of
1275 /// sugaring from the types, similar to the behavior of
1276 /// QualType::getUnqualifiedType().
1278 /// \param T is the qualified type, which may be an ArrayType
1280 /// \param Quals will receive the full set of qualifiers that were
1281 /// applied to the array.
1283 /// \returns if this is an array type, the completely unqualified array type
1284 /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
1285 QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
1287 /// \brief Determine whether the given types are equivalent after
1288 /// cvr-qualifiers have been removed.
1289 bool hasSameUnqualifiedType(QualType T1, QualType T2) {
1290 return getCanonicalType(T1).getTypePtr() ==
1291 getCanonicalType(T2).getTypePtr();
1294 bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2);
1296 /// \brief Retrieves the "canonical" nested name specifier for a
1297 /// given nested name specifier.
1299 /// The canonical nested name specifier is a nested name specifier
1300 /// that uniquely identifies a type or namespace within the type
1301 /// system. For example, given:
1306 /// template<typename T> struct X { typename T* type; };
1310 /// template<typename T> struct Y {
1311 /// typename N::S::X<T>::type member;
1315 /// Here, the nested-name-specifier for N::S::X<T>:: will be
1316 /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined
1317 /// by declarations in the type system and the canonical type for
1318 /// the template type parameter 'T' is template-param-0-0.
1319 NestedNameSpecifier *
1320 getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const;
1322 /// \brief Retrieves the default calling convention to use for
1323 /// C++ instance methods.
1324 CallingConv getDefaultMethodCallConv();
1326 /// \brief Retrieves the canonical representation of the given
1327 /// calling convention.
1328 CallingConv getCanonicalCallConv(CallingConv CC) const {
1329 if (!LangOpts.MRTD && CC == CC_C)
1334 /// \brief Determines whether two calling conventions name the same
1335 /// calling convention.
1336 bool isSameCallConv(CallingConv lcc, CallingConv rcc) {
1337 return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc));
1340 /// \brief Retrieves the "canonical" template name that refers to a
1343 /// The canonical template name is the simplest expression that can
1344 /// be used to refer to a given template. For most templates, this
1345 /// expression is just the template declaration itself. For example,
1346 /// the template std::vector can be referred to via a variety of
1347 /// names---std::vector, ::std::vector, vector (if vector is in
1348 /// scope), etc.---but all of these names map down to the same
1349 /// TemplateDecl, which is used to form the canonical template name.
1351 /// Dependent template names are more interesting. Here, the
1352 /// template name could be something like T::template apply or
1353 /// std::allocator<T>::template rebind, where the nested name
1354 /// specifier itself is dependent. In this case, the canonical
1355 /// template name uses the shortest form of the dependent
1356 /// nested-name-specifier, which itself contains all canonical
1357 /// types, values, and templates.
1358 TemplateName getCanonicalTemplateName(TemplateName Name) const;
1360 /// \brief Determine whether the given template names refer to the same
1362 bool hasSameTemplateName(TemplateName X, TemplateName Y);
1364 /// \brief Retrieve the "canonical" template argument.
1366 /// The canonical template argument is the simplest template argument
1367 /// (which may be a type, value, expression, or declaration) that
1368 /// expresses the value of the argument.
1369 TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg)
1372 /// Type Query functions. If the type is an instance of the specified class,
1373 /// return the Type pointer for the underlying maximally pretty type. This
1374 /// is a member of ASTContext because this may need to do some amount of
1375 /// canonicalization, e.g. to move type qualifiers into the element type.
1376 const ArrayType *getAsArrayType(QualType T) const;
1377 const ConstantArrayType *getAsConstantArrayType(QualType T) const {
1378 return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
1380 const VariableArrayType *getAsVariableArrayType(QualType T) const {
1381 return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
1383 const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const {
1384 return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
1386 const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T)
1388 return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
1391 /// getBaseElementType - Returns the innermost element type of an array type.
1392 /// For example, will return "int" for int[m][n]
1393 QualType getBaseElementType(const ArrayType *VAT) const;
1395 /// getBaseElementType - Returns the innermost element type of a type
1396 /// (which needn't actually be an array type).
1397 QualType getBaseElementType(QualType QT) const;
1399 /// getConstantArrayElementCount - Returns number of constant array elements.
1400 uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
1402 /// \brief Perform adjustment on the parameter type of a function.
1404 /// This routine adjusts the given parameter type @p T to the actual
1405 /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8],
1406 /// C++ [dcl.fct]p3). The adjusted parameter type is returned.
1407 QualType getAdjustedParameterType(QualType T);
1409 /// \brief Retrieve the parameter type as adjusted for use in the signature
1410 /// of a function, decaying array and function types and removing top-level
1412 QualType getSignatureParameterType(QualType T);
1414 /// getArrayDecayedType - Return the properly qualified result of decaying the
1415 /// specified array type to a pointer. This operation is non-trivial when
1416 /// handling typedefs etc. The canonical type of "T" must be an array type,
1417 /// this returns a pointer to a properly qualified element of the array.
1419 /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
1420 QualType getArrayDecayedType(QualType T) const;
1422 /// getPromotedIntegerType - Returns the type that Promotable will
1423 /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable
1425 QualType getPromotedIntegerType(QualType PromotableType) const;
1427 /// \brief Recurses in pointer/array types until it finds an objc retainable
1428 /// type and returns its ownership.
1429 Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const;
1431 /// \brief Whether this is a promotable bitfield reference according
1432 /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
1434 /// \returns the type this bit-field will promote to, or NULL if no
1435 /// promotion occurs.
1436 QualType isPromotableBitField(Expr *E) const;
1438 /// getIntegerTypeOrder - Returns the highest ranked integer type:
1439 /// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If
1440 /// LHS < RHS, return -1.
1441 int getIntegerTypeOrder(QualType LHS, QualType RHS) const;
1443 /// getFloatingTypeOrder - Compare the rank of the two specified floating
1444 /// point types, ignoring the domain of the type (i.e. 'double' ==
1445 /// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If
1446 /// LHS < RHS, return -1.
1447 int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
1449 /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
1450 /// point or a complex type (based on typeDomain/typeSize).
1451 /// 'typeDomain' is a real floating point or complex type.
1452 /// 'typeSize' is a real floating point or complex type.
1453 QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
1454 QualType typeDomain) const;
1456 unsigned getTargetAddressSpace(QualType T) const {
1457 return getTargetAddressSpace(T.getQualifiers());
1460 unsigned getTargetAddressSpace(Qualifiers Q) const {
1461 return getTargetAddressSpace(Q.getAddressSpace());
1464 unsigned getTargetAddressSpace(unsigned AS) const {
1465 if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count)
1468 return (*AddrSpaceMap)[AS - LangAS::Offset];
1472 // Helper for integer ordering
1473 unsigned getIntegerRank(const Type *T) const;
1477 //===--------------------------------------------------------------------===//
1478 // Type Compatibility Predicates
1479 //===--------------------------------------------------------------------===//
1481 /// Compatibility predicates used to check assignment expressions.
1482 bool typesAreCompatible(QualType T1, QualType T2,
1483 bool CompareUnqualified = false); // C99 6.2.7p1
1485 bool propertyTypesAreCompatible(QualType, QualType);
1486 bool typesAreBlockPointerCompatible(QualType, QualType);
1488 bool isObjCIdType(QualType T) const {
1489 return T == getObjCIdType();
1491 bool isObjCClassType(QualType T) const {
1492 return T == getObjCClassType();
1494 bool isObjCSelType(QualType T) const {
1495 return T == getObjCSelType();
1497 bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
1498 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
1501 bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS);
1503 // Check the safety of assignment from LHS to RHS
1504 bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
1505 const ObjCObjectPointerType *RHSOPT);
1506 bool canAssignObjCInterfaces(const ObjCObjectType *LHS,
1507 const ObjCObjectType *RHS);
1508 bool canAssignObjCInterfacesInBlockPointer(
1509 const ObjCObjectPointerType *LHSOPT,
1510 const ObjCObjectPointerType *RHSOPT,
1511 bool BlockReturnType);
1512 bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
1513 QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
1514 const ObjCObjectPointerType *RHSOPT);
1515 bool canBindObjCObjectType(QualType To, QualType From);
1517 // Functions for calculating composite types
1518 QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false,
1519 bool Unqualified = false, bool BlockReturnType = false);
1520 QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false,
1521 bool Unqualified = false);
1522 QualType mergeFunctionArgumentTypes(QualType, QualType,
1523 bool OfBlockPointer=false,
1524 bool Unqualified = false);
1525 QualType mergeTransparentUnionType(QualType, QualType,
1526 bool OfBlockPointer=false,
1527 bool Unqualified = false);
1529 QualType mergeObjCGCQualifiers(QualType, QualType);
1531 bool FunctionTypesMatchOnNSConsumedAttrs(
1532 const FunctionProtoType *FromFunctionType,
1533 const FunctionProtoType *ToFunctionType);
1535 void ResetObjCLayout(const ObjCContainerDecl *CD) {
1536 ObjCLayouts[CD] = 0;
1539 //===--------------------------------------------------------------------===//
1540 // Integer Predicates
1541 //===--------------------------------------------------------------------===//
1543 // The width of an integer, as defined in C99 6.2.6.2. This is the number
1544 // of bits in an integer type excluding any padding bits.
1545 unsigned getIntWidth(QualType T) const;
1547 // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
1548 // unsigned integer type. This method takes a signed type, and returns the
1549 // corresponding unsigned integer type.
1550 QualType getCorrespondingUnsignedType(QualType T);
1552 //===--------------------------------------------------------------------===//
1554 //===--------------------------------------------------------------------===//
1556 typedef std::vector<Type*>::iterator type_iterator;
1557 typedef std::vector<Type*>::const_iterator const_type_iterator;
1559 type_iterator types_begin() { return Types.begin(); }
1560 type_iterator types_end() { return Types.end(); }
1561 const_type_iterator types_begin() const { return Types.begin(); }
1562 const_type_iterator types_end() const { return Types.end(); }
1564 //===--------------------------------------------------------------------===//
1566 //===--------------------------------------------------------------------===//
1568 /// MakeIntValue - Make an APSInt of the appropriate width and
1569 /// signedness for the given \arg Value and integer \arg Type.
1570 llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const {
1571 llvm::APSInt Res(getIntWidth(Type),
1572 !Type->isSignedIntegerOrEnumerationType());
1577 /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists.
1578 ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
1579 /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists.
1580 ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D);
1582 /// \brief returns true if there is at lease one @implementation in TU.
1583 bool AnyObjCImplementation() {
1584 return !ObjCImpls.empty();
1587 /// \brief Set the implementation of ObjCInterfaceDecl.
1588 void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
1589 ObjCImplementationDecl *ImplD);
1590 /// \brief Set the implementation of ObjCCategoryDecl.
1591 void setObjCImplementation(ObjCCategoryDecl *CatD,
1592 ObjCCategoryImplDecl *ImplD);
1594 /// \brief Get the duplicate declaration of a ObjCMethod in the same
1595 /// interface, or null if non exists.
1596 const ObjCMethodDecl *getObjCMethodRedeclaration(
1597 const ObjCMethodDecl *MD) const {
1598 llvm::DenseMap<const ObjCMethodDecl*, const ObjCMethodDecl*>::const_iterator
1599 I = ObjCMethodRedecls.find(MD);
1600 if (I == ObjCMethodRedecls.end())
1605 void setObjCMethodRedeclaration(const ObjCMethodDecl *MD,
1606 const ObjCMethodDecl *Redecl) {
1607 ObjCMethodRedecls[MD] = Redecl;
1610 /// \brief Set the copy inialization expression of a block var decl.
1611 void setBlockVarCopyInits(VarDecl*VD, Expr* Init);
1612 /// \brief Get the copy initialization expression of VarDecl,or NULL if
1614 Expr *getBlockVarCopyInits(const VarDecl*VD);
1616 /// \brief Allocate an uninitialized TypeSourceInfo.
1618 /// The caller should initialize the memory held by TypeSourceInfo using
1619 /// the TypeLoc wrappers.
1621 /// \param T the type that will be the basis for type source info. This type
1622 /// should refer to how the declarator was written in source code, not to
1623 /// what type semantic analysis resolved the declarator to.
1625 /// \param Size the size of the type info to create, or 0 if the size
1626 /// should be calculated based on the type.
1627 TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const;
1629 /// \brief Allocate a TypeSourceInfo where all locations have been
1630 /// initialized to a given location, which defaults to the empty
1633 getTrivialTypeSourceInfo(QualType T,
1634 SourceLocation Loc = SourceLocation()) const;
1636 TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; }
1638 /// \brief Add a deallocation callback that will be invoked when the
1639 /// ASTContext is destroyed.
1641 /// \brief Callback A callback function that will be invoked on destruction.
1643 /// \brief Data Pointer data that will be provided to the callback function
1644 /// when it is called.
1645 void AddDeallocation(void (*Callback)(void*), void *Data);
1647 GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD);
1648 GVALinkage GetGVALinkageForVariable(const VarDecl *VD);
1650 /// \brief Determines if the decl can be CodeGen'ed or deserialized from PCH
1651 /// lazily, only when used; this is only relevant for function or file scoped
1652 /// var definitions.
1654 /// \returns true if the function/var must be CodeGen'ed/deserialized even if
1656 bool DeclMustBeEmitted(const Decl *D);
1659 /// \brief Used by ParmVarDecl to store on the side the
1660 /// index of the parameter when it exceeds the size of the normal bitfield.
1661 void setParameterIndex(const ParmVarDecl *D, unsigned index);
1663 /// \brief Used by ParmVarDecl to retrieve on the side the
1664 /// index of the parameter when it exceeds the size of the normal bitfield.
1665 unsigned getParameterIndex(const ParmVarDecl *D) const;
1667 //===--------------------------------------------------------------------===//
1669 //===--------------------------------------------------------------------===//
1671 /// \brief The number of implicitly-declared default constructors.
1672 static unsigned NumImplicitDefaultConstructors;
1674 /// \brief The number of implicitly-declared default constructors for
1675 /// which declarations were built.
1676 static unsigned NumImplicitDefaultConstructorsDeclared;
1678 /// \brief The number of implicitly-declared copy constructors.
1679 static unsigned NumImplicitCopyConstructors;
1681 /// \brief The number of implicitly-declared copy constructors for
1682 /// which declarations were built.
1683 static unsigned NumImplicitCopyConstructorsDeclared;
1685 /// \brief The number of implicitly-declared move constructors.
1686 static unsigned NumImplicitMoveConstructors;
1688 /// \brief The number of implicitly-declared move constructors for
1689 /// which declarations were built.
1690 static unsigned NumImplicitMoveConstructorsDeclared;
1692 /// \brief The number of implicitly-declared copy assignment operators.
1693 static unsigned NumImplicitCopyAssignmentOperators;
1695 /// \brief The number of implicitly-declared copy assignment operators for
1696 /// which declarations were built.
1697 static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
1699 /// \brief The number of implicitly-declared move assignment operators.
1700 static unsigned NumImplicitMoveAssignmentOperators;
1702 /// \brief The number of implicitly-declared move assignment operators for
1703 /// which declarations were built.
1704 static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
1706 /// \brief The number of implicitly-declared destructors.
1707 static unsigned NumImplicitDestructors;
1709 /// \brief The number of implicitly-declared destructors for which
1710 /// declarations were built.
1711 static unsigned NumImplicitDestructorsDeclared;
1714 ASTContext(const ASTContext&); // DO NOT IMPLEMENT
1715 void operator=(const ASTContext&); // DO NOT IMPLEMENT
1718 /// \brief Initialize built-in types.
1720 /// This routine may only be invoked once for a given ASTContext object.
1721 /// It is normally invoked by the ASTContext constructor. However, the
1722 /// constructor can be asked to delay initialization, which places the burden
1723 /// of calling this function on the user of that object.
1725 /// \param Target The target
1726 void InitBuiltinTypes(const TargetInfo &Target);
1729 void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
1731 // Return the ObjC type encoding for a given type.
1732 void getObjCEncodingForTypeImpl(QualType t, std::string &S,
1733 bool ExpandPointedToStructures,
1734 bool ExpandStructures,
1735 const FieldDecl *Field,
1736 bool OutermostType = false,
1737 bool EncodingProperty = false,
1738 bool StructField = false) const;
1740 // Adds the encoding of the structure's members.
1741 void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S,
1742 const FieldDecl *Field,
1743 bool includeVBases = true) const;
1745 const ASTRecordLayout &
1746 getObjCLayout(const ObjCInterfaceDecl *D,
1747 const ObjCImplementationDecl *Impl) const;
1750 /// \brief A set of deallocations that should be performed when the
1751 /// ASTContext is destroyed.
1752 SmallVector<std::pair<void (*)(void*), void *>, 16> Deallocations;
1754 // FIXME: This currently contains the set of StoredDeclMaps used
1755 // by DeclContext objects. This probably should not be in ASTContext,
1756 // but we include it here so that ASTContext can quickly deallocate them.
1757 llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM;
1759 /// \brief A counter used to uniquely identify "blocks".
1760 mutable unsigned int UniqueBlockByRefTypeID;
1762 friend class DeclContext;
1763 friend class DeclarationNameTable;
1764 void ReleaseDeclContextMaps();
1767 /// @brief Utility function for constructing a nullary selector.
1768 static inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) {
1769 IdentifierInfo* II = &Ctx.Idents.get(name);
1770 return Ctx.Selectors.getSelector(0, &II);
1773 /// @brief Utility function for constructing an unary selector.
1774 static inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) {
1775 IdentifierInfo* II = &Ctx.Idents.get(name);
1776 return Ctx.Selectors.getSelector(1, &II);
1779 } // end namespace clang
1781 // operator new and delete aren't allowed inside namespaces.
1782 // The throw specifications are mandated by the standard.
1783 /// @brief Placement new for using the ASTContext's allocator.
1785 /// This placement form of operator new uses the ASTContext's allocator for
1786 /// obtaining memory. It is a non-throwing new, which means that it returns
1787 /// null on error. (If that is what the allocator does. The current does, so if
1788 /// this ever changes, this operator will have to be changed, too.)
1789 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
1791 /// // Default alignment (8)
1792 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
1793 /// // Specific alignment
1794 /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
1796 /// Please note that you cannot use delete on the pointer; it must be
1797 /// deallocated using an explicit destructor call followed by
1798 /// @c Context.Deallocate(Ptr).
1800 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
1801 /// @param C The ASTContext that provides the allocator.
1802 /// @param Alignment The alignment of the allocated memory (if the underlying
1803 /// allocator supports it).
1804 /// @return The allocated memory. Could be NULL.
1805 inline void *operator new(size_t Bytes, const clang::ASTContext &C,
1806 size_t Alignment) throw () {
1807 return C.Allocate(Bytes, Alignment);
1809 /// @brief Placement delete companion to the new above.
1811 /// This operator is just a companion to the new above. There is no way of
1812 /// invoking it directly; see the new operator for more details. This operator
1813 /// is called implicitly by the compiler if a placement new expression using
1814 /// the ASTContext throws in the object constructor.
1815 inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t)
1820 /// This placement form of operator new[] uses the ASTContext's allocator for
1821 /// obtaining memory. It is a non-throwing new[], which means that it returns
1823 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
1825 /// // Default alignment (8)
1826 /// char *data = new (Context) char[10];
1827 /// // Specific alignment
1828 /// char *data = new (Context, 4) char[10];
1830 /// Please note that you cannot use delete on the pointer; it must be
1831 /// deallocated using an explicit destructor call followed by
1832 /// @c Context.Deallocate(Ptr).
1834 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
1835 /// @param C The ASTContext that provides the allocator.
1836 /// @param Alignment The alignment of the allocated memory (if the underlying
1837 /// allocator supports it).
1838 /// @return The allocated memory. Could be NULL.
1839 inline void *operator new[](size_t Bytes, const clang::ASTContext& C,
1840 size_t Alignment = 8) throw () {
1841 return C.Allocate(Bytes, Alignment);
1844 /// @brief Placement delete[] companion to the new[] above.
1846 /// This operator is just a companion to the new[] above. There is no way of
1847 /// invoking it directly; see the new[] operator for more details. This operator
1848 /// is called implicitly by the compiler if a placement new[] expression using
1849 /// the ASTContext throws in the object constructor.
1850 inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t)