ASTContext.h revision ffe37fdda5b4b4f162a45155c30d9f60ce110c12
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/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"
36#include <vector>
37
38namespace llvm {
39  struct fltSemantics;
40  class raw_ostream;
41}
42
43namespace clang {
44  class FileManager;
45  class ASTRecordLayout;
46  class BlockExpr;
47  class CharUnits;
48  class Diagnostic;
49  class Expr;
50  class ExternalASTSource;
51  class ASTMutationListener;
52  class IdentifierTable;
53  class SelectorTable;
54  class SourceManager;
55  class TargetInfo;
56  class CXXABI;
57  // Decls
58  class DeclContext;
59  class CXXMethodDecl;
60  class CXXRecordDecl;
61  class Decl;
62  class FieldDecl;
63  class MangleContext;
64  class ObjCIvarDecl;
65  class ObjCIvarRefExpr;
66  class ObjCPropertyDecl;
67  class RecordDecl;
68  class StoredDeclsMap;
69  class TagDecl;
70  class TemplateTemplateParmDecl;
71  class TemplateTypeParmDecl;
72  class TranslationUnitDecl;
73  class TypeDecl;
74  class TypedefNameDecl;
75  class UsingDecl;
76  class UsingShadowDecl;
77  class UnresolvedSetIterator;
78
79  namespace Builtin { class Context; }
80
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.
83class ASTContext : public llvm::RefCountedBase<ASTContext> {
84  ASTContext &this_() { return *this; }
85
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&>
103    FunctionProtoTypes;
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,
117                                     ASTContext&>
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  llvm::FoldingSet<AttributedType> AttributedTypes;
124
125  mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
126  mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
127  mutable llvm::FoldingSet<SubstTemplateTemplateParmPackStorage>
128    SubstTemplateTemplateParmPacks;
129
130  /// \brief The set of nested name specifiers.
131  ///
132  /// This set is managed by the NestedNameSpecifier class.
133  mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
134  mutable NestedNameSpecifier *GlobalNestedNameSpecifier;
135  friend class NestedNameSpecifier;
136
137  /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
138  ///  This is lazily created.  This is intentionally not serialized.
139  mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>
140    ASTRecordLayouts;
141  mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>
142    ObjCLayouts;
143
144  /// KeyFunctions - A cache mapping from CXXRecordDecls to key functions.
145  llvm::DenseMap<const CXXRecordDecl*, const CXXMethodDecl*> KeyFunctions;
146
147  /// \brief Mapping from ObjCContainers to their ObjCImplementations.
148  llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
149
150  /// \brief Mapping from __block VarDecls to their copy initialization expr.
151  llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits;
152
153  /// \brief Representation of a "canonical" template template parameter that
154  /// is used in canonical template names.
155  class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
156    TemplateTemplateParmDecl *Parm;
157
158  public:
159    CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm)
160      : Parm(Parm) { }
161
162    TemplateTemplateParmDecl *getParam() const { return Parm; }
163
164    void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); }
165
166    static void Profile(llvm::FoldingSetNodeID &ID,
167                        TemplateTemplateParmDecl *Parm);
168  };
169  mutable llvm::FoldingSet<CanonicalTemplateTemplateParm>
170    CanonTemplateTemplateParms;
171
172  TemplateTemplateParmDecl *
173    getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const;
174
175  /// \brief Whether __[u]int128_t identifier is installed.
176  bool IsInt128Installed;
177
178  /// BuiltinVaListType - built-in va list type.
179  /// This is initially null and set by Sema::LazilyCreateBuiltin when
180  /// a builtin that takes a valist is encountered.
181  QualType BuiltinVaListType;
182
183  /// ObjCIdType - a pseudo built-in typedef type (set by Sema).
184  QualType ObjCIdTypedefType;
185
186  /// ObjCSelType - another pseudo built-in typedef type (set by Sema).
187  QualType ObjCSelTypedefType;
188
189  /// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
190  QualType ObjCProtoType;
191  const RecordType *ProtoStructType;
192
193  /// ObjCClassType - another pseudo built-in typedef type (set by Sema).
194  QualType ObjCClassTypedefType;
195
196  QualType ObjCConstantStringType;
197  mutable RecordDecl *CFConstantStringTypeDecl;
198
199  mutable RecordDecl *NSConstantStringTypeDecl;
200
201  mutable RecordDecl *ObjCFastEnumerationStateTypeDecl;
202
203  /// \brief The type for the C FILE type.
204  TypeDecl *FILEDecl;
205
206  /// \brief The type for the C jmp_buf type.
207  TypeDecl *jmp_bufDecl;
208
209  /// \brief The type for the C sigjmp_buf type.
210  TypeDecl *sigjmp_bufDecl;
211
212  /// \brief Type for the Block descriptor for Blocks CodeGen.
213  mutable RecordDecl *BlockDescriptorType;
214
215  /// \brief Type for the Block descriptor for Blocks CodeGen.
216  mutable RecordDecl *BlockDescriptorExtendedType;
217
218  /// \brief Declaration for the CUDA cudaConfigureCall function.
219  FunctionDecl *cudaConfigureCallDecl;
220
221  TypeSourceInfo NullTypeSourceInfo;
222
223  /// \brief Keeps track of all declaration attributes.
224  ///
225  /// Since so few decls have attrs, we keep them in a hash map instead of
226  /// wasting space in the Decl class.
227  llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs;
228
229  /// \brief Keeps track of the static data member templates from which
230  /// static data members of class template specializations were instantiated.
231  ///
232  /// This data structure stores the mapping from instantiations of static
233  /// data members to the static data member representations within the
234  /// class template from which they were instantiated along with the kind
235  /// of instantiation or specialization (a TemplateSpecializationKind - 1).
236  ///
237  /// Given the following example:
238  ///
239  /// \code
240  /// template<typename T>
241  /// struct X {
242  ///   static T value;
243  /// };
244  ///
245  /// template<typename T>
246  ///   T X<T>::value = T(17);
247  ///
248  /// int *x = &X<int>::value;
249  /// \endcode
250  ///
251  /// This mapping will contain an entry that maps from the VarDecl for
252  /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
253  /// class template X) and will be marked TSK_ImplicitInstantiation.
254  llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *>
255    InstantiatedFromStaticDataMember;
256
257  /// \brief Keeps track of the declaration from which a UsingDecl was
258  /// created during instantiation.  The source declaration is always
259  /// a UsingDecl, an UnresolvedUsingValueDecl, or an
260  /// UnresolvedUsingTypenameDecl.
261  ///
262  /// For example:
263  /// \code
264  /// template<typename T>
265  /// struct A {
266  ///   void f();
267  /// };
268  ///
269  /// template<typename T>
270  /// struct B : A<T> {
271  ///   using A<T>::f;
272  /// };
273  ///
274  /// template struct B<int>;
275  /// \endcode
276  ///
277  /// This mapping will contain an entry that maps from the UsingDecl in
278  /// B<int> to the UnresolvedUsingDecl in B<T>.
279  llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl;
280
281  llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
282    InstantiatedFromUsingShadowDecl;
283
284  llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
285
286  /// \brief Mapping that stores the methods overridden by a given C++
287  /// member function.
288  ///
289  /// Since most C++ member functions aren't virtual and therefore
290  /// don't override anything, we store the overridden functions in
291  /// this map on the side rather than within the CXXMethodDecl structure.
292  typedef UsuallyTinyPtrVector<const CXXMethodDecl> CXXMethodVector;
293  llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
294
295  TranslationUnitDecl *TUDecl;
296
297  /// SourceMgr - The associated SourceManager object.
298  SourceManager &SourceMgr;
299
300  /// LangOpts - The language options used to create the AST associated with
301  ///  this ASTContext object.
302  LangOptions LangOpts;
303
304  /// \brief The allocator used to create AST objects.
305  ///
306  /// AST objects are never destructed; rather, all memory associated with the
307  /// AST objects will be released when the ASTContext itself is destroyed.
308  mutable llvm::BumpPtrAllocator BumpAlloc;
309
310  /// \brief Allocator for partial diagnostics.
311  PartialDiagnostic::StorageAllocator DiagAllocator;
312
313  /// \brief The current C++ ABI.
314  llvm::OwningPtr<CXXABI> ABI;
315  CXXABI *createCXXABI(const TargetInfo &T);
316
317  /// \brief The logical -> physical address space map.
318  const LangAS::Map &AddrSpaceMap;
319
320  friend class ASTDeclReader;
321
322public:
323  const TargetInfo &Target;
324  IdentifierTable &Idents;
325  SelectorTable &Selectors;
326  Builtin::Context &BuiltinInfo;
327  mutable DeclarationNameTable DeclarationNames;
328  llvm::OwningPtr<ExternalASTSource> ExternalSource;
329  ASTMutationListener *Listener;
330  clang::PrintingPolicy PrintingPolicy;
331
332  // Typedefs which may be provided defining the structure of Objective-C
333  // pseudo-builtins
334  QualType ObjCIdRedefinitionType;
335  QualType ObjCClassRedefinitionType;
336  QualType ObjCSelRedefinitionType;
337
338  SourceManager& getSourceManager() { return SourceMgr; }
339  const SourceManager& getSourceManager() const { return SourceMgr; }
340  void *Allocate(unsigned Size, unsigned Align = 8) const {
341    return BumpAlloc.Allocate(Size, Align);
342  }
343  void Deallocate(void *Ptr) const { }
344
345  /// Return the total amount of physical memory allocated for representing
346  /// AST nodes and type information.
347  size_t getASTAllocatedMemory() const {
348    return BumpAlloc.getTotalMemory();
349  }
350  /// Return the total memory used for various side tables.
351  size_t getSideTableAllocatedMemory() const;
352
353  PartialDiagnostic::StorageAllocator &getDiagAllocator() {
354    return DiagAllocator;
355  }
356
357  const LangOptions& getLangOptions() const { return LangOpts; }
358
359  Diagnostic &getDiagnostics() const;
360
361  FullSourceLoc getFullLoc(SourceLocation Loc) const {
362    return FullSourceLoc(Loc,SourceMgr);
363  }
364
365  /// \brief Retrieve the attributes for the given declaration.
366  AttrVec& getDeclAttrs(const Decl *D);
367
368  /// \brief Erase the attributes corresponding to the given declaration.
369  void eraseDeclAttrs(const Decl *D);
370
371  /// \brief If this variable is an instantiated static data member of a
372  /// class template specialization, returns the templated static data member
373  /// from which it was instantiated.
374  MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
375                                                           const VarDecl *Var);
376
377  /// \brief Note that the static data member \p Inst is an instantiation of
378  /// the static data member template \p Tmpl of a class template.
379  void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
380                                           TemplateSpecializationKind TSK,
381                        SourceLocation PointOfInstantiation = SourceLocation());
382
383  /// \brief If the given using decl is an instantiation of a
384  /// (possibly unresolved) using decl from a template instantiation,
385  /// return it.
386  NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
387
388  /// \brief Remember that the using decl \p Inst is an instantiation
389  /// of the using decl \p Pattern of a class template.
390  void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
391
392  void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
393                                          UsingShadowDecl *Pattern);
394  UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
395
396  FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
397
398  void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
399
400  /// ZeroBitfieldFollowsNonBitfield - return 'true" if 'FD' is a zero-length
401  /// bitfield which follows the non-bitfield 'LastFD'.
402  bool ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD,
403                                      const FieldDecl *LastFD) const;
404
405  /// ZeroBitfieldFollowsBitfield - return 'true" if 'FD' is a zero-length
406  /// bitfield which follows the bitfield 'LastFD'.
407  bool ZeroBitfieldFollowsBitfield(const FieldDecl *FD,
408                                   const FieldDecl *LastFD) const;
409
410  /// BitfieldFollowsBitfield - return 'true" if 'FD' is a
411  /// bitfield which follows the bitfield 'LastFD'.
412  bool BitfieldFollowsBitfield(const FieldDecl *FD,
413                                   const FieldDecl *LastFD) const;
414
415  /// NoneBitfieldFollowsBitfield - return 'true" if 'FD' is not a
416  /// bitfield which follows the bitfield 'LastFD'.
417  bool NoneBitfieldFollowsBitfield(const FieldDecl *FD,
418                                   const FieldDecl *LastFD) const;
419
420  /// BitfieldFollowsNoneBitfield - return 'true" if 'FD' is a
421  /// bitfield which follows the none bitfield 'LastFD'.
422  bool BitfieldFollowsNoneBitfield(const FieldDecl *FD,
423                                   const FieldDecl *LastFD) const;
424
425  // Access to the set of methods overridden by the given C++ method.
426  typedef CXXMethodVector::iterator overridden_cxx_method_iterator;
427  overridden_cxx_method_iterator
428  overridden_methods_begin(const CXXMethodDecl *Method) const;
429
430  overridden_cxx_method_iterator
431  overridden_methods_end(const CXXMethodDecl *Method) const;
432
433  unsigned overridden_methods_size(const CXXMethodDecl *Method) const;
434
435  /// \brief Note that the given C++ \p Method overrides the given \p
436  /// Overridden method.
437  void addOverriddenMethod(const CXXMethodDecl *Method,
438                           const CXXMethodDecl *Overridden);
439
440  TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
441
442
443  // Builtin Types.
444  CanQualType VoidTy;
445  CanQualType BoolTy;
446  CanQualType CharTy;
447  CanQualType WCharTy;  // [C++ 3.9.1p5], integer type in C99.
448  CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
449  CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
450  CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
451  CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
452  CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
453  CanQualType FloatTy, DoubleTy, LongDoubleTy;
454  CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
455  CanQualType VoidPtrTy, NullPtrTy;
456  CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
457  CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
458
459  // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
460  mutable QualType AutoDeductTy;     // Deduction against 'auto'.
461  mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'.
462
463  ASTContext(const LangOptions& LOpts, SourceManager &SM, const TargetInfo &t,
464             IdentifierTable &idents, SelectorTable &sels,
465             Builtin::Context &builtins,
466             unsigned size_reserve);
467
468  ~ASTContext();
469
470  /// \brief Attach an external AST source to the AST context.
471  ///
472  /// The external AST source provides the ability to load parts of
473  /// the abstract syntax tree as needed from some external storage,
474  /// e.g., a precompiled header.
475  void setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source);
476
477  /// \brief Retrieve a pointer to the external AST source associated
478  /// with this AST context, if any.
479  ExternalASTSource *getExternalSource() const { return ExternalSource.get(); }
480
481  /// \brief Attach an AST mutation listener to the AST context.
482  ///
483  /// The AST mutation listener provides the ability to track modifications to
484  /// the abstract syntax tree entities committed after they were initially
485  /// created.
486  void setASTMutationListener(ASTMutationListener *Listener) {
487    this->Listener = Listener;
488  }
489
490  /// \brief Retrieve a pointer to the AST mutation listener associated
491  /// with this AST context, if any.
492  ASTMutationListener *getASTMutationListener() const { return Listener; }
493
494  void PrintStats() const;
495  const std::vector<Type*>& getTypes() const { return Types; }
496
497  //===--------------------------------------------------------------------===//
498  //                           Type Constructors
499  //===--------------------------------------------------------------------===//
500
501private:
502  /// getExtQualType - Return a type with extended qualifiers.
503  QualType getExtQualType(const Type *Base, Qualifiers Quals) const;
504
505  QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;
506
507public:
508  /// getAddSpaceQualType - Return the uniqued reference to the type for an
509  /// address space qualified type with the specified type and address space.
510  /// The resulting type has a union of the qualifiers from T and the address
511  /// space. If T already has an address space specifier, it is silently
512  /// replaced.
513  QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const;
514
515  /// getObjCGCQualType - Returns the uniqued reference to the type for an
516  /// objc gc qualified type. The retulting type has a union of the qualifiers
517  /// from T and the gc attribute.
518  QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
519
520  /// getRestrictType - Returns the uniqued reference to the type for a
521  /// 'restrict' qualified type.  The resulting type has a union of the
522  /// qualifiers from T and 'restrict'.
523  QualType getRestrictType(QualType T) const {
524    return T.withFastQualifiers(Qualifiers::Restrict);
525  }
526
527  /// getVolatileType - Returns the uniqued reference to the type for a
528  /// 'volatile' qualified type.  The resulting type has a union of the
529  /// qualifiers from T and 'volatile'.
530  QualType getVolatileType(QualType T) const {
531    return T.withFastQualifiers(Qualifiers::Volatile);
532  }
533
534  /// getConstType - Returns the uniqued reference to the type for a
535  /// 'const' qualified type.  The resulting type has a union of the
536  /// qualifiers from T and 'const'.
537  ///
538  /// It can be reasonably expected that this will always be
539  /// equivalent to calling T.withConst().
540  QualType getConstType(QualType T) const { return T.withConst(); }
541
542  /// adjustFunctionType - Change the ExtInfo on a function type.
543  const FunctionType *adjustFunctionType(const FunctionType *Fn,
544                                         FunctionType::ExtInfo EInfo);
545
546  /// getComplexType - Return the uniqued reference to the type for a complex
547  /// number with the specified element type.
548  QualType getComplexType(QualType T) const;
549  CanQualType getComplexType(CanQualType T) const {
550    return CanQualType::CreateUnsafe(getComplexType((QualType) T));
551  }
552
553  /// getPointerType - Return the uniqued reference to the type for a pointer to
554  /// the specified type.
555  QualType getPointerType(QualType T) const;
556  CanQualType getPointerType(CanQualType T) const {
557    return CanQualType::CreateUnsafe(getPointerType((QualType) T));
558  }
559
560  /// getBlockPointerType - Return the uniqued reference to the type for a block
561  /// of the specified type.
562  QualType getBlockPointerType(QualType T) const;
563
564  /// This gets the struct used to keep track of the descriptor for pointer to
565  /// blocks.
566  QualType getBlockDescriptorType() const;
567
568  // Set the type for a Block descriptor type.
569  void setBlockDescriptorType(QualType T);
570  /// Get the BlockDescriptorType type, or NULL if it hasn't yet been built.
571  QualType getRawBlockdescriptorType() {
572    if (BlockDescriptorType)
573      return getTagDeclType(BlockDescriptorType);
574    return QualType();
575  }
576
577  /// This gets the struct used to keep track of the extended descriptor for
578  /// pointer to blocks.
579  QualType getBlockDescriptorExtendedType() const;
580
581  // Set the type for a Block descriptor extended type.
582  void setBlockDescriptorExtendedType(QualType T);
583  /// Get the BlockDescriptorExtendedType type, or NULL if it hasn't yet been
584  /// built.
585  QualType getRawBlockdescriptorExtendedType() const {
586    if (BlockDescriptorExtendedType)
587      return getTagDeclType(BlockDescriptorExtendedType);
588    return QualType();
589  }
590
591  void setcudaConfigureCallDecl(FunctionDecl *FD) {
592    cudaConfigureCallDecl = FD;
593  }
594  FunctionDecl *getcudaConfigureCallDecl() {
595    return cudaConfigureCallDecl;
596  }
597
598  /// This builds the struct used for __block variables.
599  QualType BuildByRefType(llvm::StringRef DeclName, QualType Ty) const;
600
601  /// Returns true iff we need copy/dispose helpers for the given type.
602  bool BlockRequiresCopying(QualType Ty) const;
603
604  /// getLValueReferenceType - Return the uniqued reference to the type for an
605  /// lvalue reference to the specified type.
606  QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true)
607    const;
608
609  /// getRValueReferenceType - Return the uniqued reference to the type for an
610  /// rvalue reference to the specified type.
611  QualType getRValueReferenceType(QualType T) const;
612
613  /// getMemberPointerType - Return the uniqued reference to the type for a
614  /// member pointer to the specified type in the specified class. The class
615  /// is a Type because it could be a dependent name.
616  QualType getMemberPointerType(QualType T, const Type *Cls) const;
617
618  /// getVariableArrayType - Returns a non-unique reference to the type for a
619  /// variable array of the specified element type.
620  QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
621                                ArrayType::ArraySizeModifier ASM,
622                                unsigned IndexTypeQuals,
623                                SourceRange Brackets) const;
624
625  /// getDependentSizedArrayType - Returns a non-unique reference to
626  /// the type for a dependently-sized array of the specified element
627  /// type. FIXME: We will need these to be uniqued, or at least
628  /// comparable, at some point.
629  QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
630                                      ArrayType::ArraySizeModifier ASM,
631                                      unsigned IndexTypeQuals,
632                                      SourceRange Brackets) const;
633
634  /// getIncompleteArrayType - Returns a unique reference to the type for a
635  /// incomplete array of the specified element type.
636  QualType getIncompleteArrayType(QualType EltTy,
637                                  ArrayType::ArraySizeModifier ASM,
638                                  unsigned IndexTypeQuals) const;
639
640  /// getConstantArrayType - Return the unique reference to the type for a
641  /// constant array of the specified element type.
642  QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
643                                ArrayType::ArraySizeModifier ASM,
644                                unsigned IndexTypeQuals) const;
645
646  /// getVariableArrayDecayedType - Returns a vla type where known sizes
647  /// are replaced with [*].
648  QualType getVariableArrayDecayedType(QualType Ty) const;
649
650  /// getVectorType - Return the unique reference to a vector type of
651  /// the specified element type and size. VectorType must be a built-in type.
652  QualType getVectorType(QualType VectorType, unsigned NumElts,
653                         VectorType::VectorKind VecKind) const;
654
655  /// getExtVectorType - Return the unique reference to an extended vector type
656  /// of the specified element type and size.  VectorType must be a built-in
657  /// type.
658  QualType getExtVectorType(QualType VectorType, unsigned NumElts) const;
659
660  /// getDependentSizedExtVectorType - Returns a non-unique reference to
661  /// the type for a dependently-sized vector of the specified element
662  /// type. FIXME: We will need these to be uniqued, or at least
663  /// comparable, at some point.
664  QualType getDependentSizedExtVectorType(QualType VectorType,
665                                          Expr *SizeExpr,
666                                          SourceLocation AttrLoc) const;
667
668  /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'.
669  ///
670  QualType getFunctionNoProtoType(QualType ResultTy,
671                                  const FunctionType::ExtInfo &Info) const;
672
673  QualType getFunctionNoProtoType(QualType ResultTy) const {
674    return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo());
675  }
676
677  /// getFunctionType - Return a normal function type with a typed
678  /// argument list.
679  QualType getFunctionType(QualType ResultTy,
680                           const QualType *Args, unsigned NumArgs,
681                           const FunctionProtoType::ExtProtoInfo &EPI) const;
682
683  /// getTypeDeclType - Return the unique reference to the type for
684  /// the specified type declaration.
685  QualType getTypeDeclType(const TypeDecl *Decl,
686                           const TypeDecl *PrevDecl = 0) const {
687    assert(Decl && "Passed null for Decl param");
688    if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
689
690    if (PrevDecl) {
691      assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
692      Decl->TypeForDecl = PrevDecl->TypeForDecl;
693      return QualType(PrevDecl->TypeForDecl, 0);
694    }
695
696    return getTypeDeclTypeSlow(Decl);
697  }
698
699  /// getTypedefType - Return the unique reference to the type for the
700  /// specified typedef-name decl.
701  QualType getTypedefType(const TypedefNameDecl *Decl,
702                          QualType Canon = QualType()) const;
703
704  QualType getRecordType(const RecordDecl *Decl) const;
705
706  QualType getEnumType(const EnumDecl *Decl) const;
707
708  QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
709
710  QualType getAttributedType(AttributedType::Kind attrKind,
711                             QualType modifiedType,
712                             QualType equivalentType);
713
714  QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
715                                        QualType Replacement) const;
716  QualType getSubstTemplateTypeParmPackType(
717                                          const TemplateTypeParmType *Replaced,
718                                            const TemplateArgument &ArgPack);
719
720  QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
721                                   bool ParameterPack,
722                                   TemplateTypeParmDecl *ParmDecl = 0) const;
723
724  QualType getTemplateSpecializationType(TemplateName T,
725                                         const TemplateArgument *Args,
726                                         unsigned NumArgs,
727                                         QualType Canon = QualType()) const;
728
729  QualType getCanonicalTemplateSpecializationType(TemplateName T,
730                                                  const TemplateArgument *Args,
731                                                  unsigned NumArgs) const;
732
733  QualType getTemplateSpecializationType(TemplateName T,
734                                         const TemplateArgumentListInfo &Args,
735                                         QualType Canon = QualType()) const;
736
737  TypeSourceInfo *
738  getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc,
739                                    const TemplateArgumentListInfo &Args,
740                                    QualType Canon = QualType()) const;
741
742  QualType getParenType(QualType NamedType) const;
743
744  QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
745                             NestedNameSpecifier *NNS,
746                             QualType NamedType) const;
747  QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
748                                NestedNameSpecifier *NNS,
749                                const IdentifierInfo *Name,
750                                QualType Canon = QualType()) const;
751
752  QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
753                                                  NestedNameSpecifier *NNS,
754                                                  const IdentifierInfo *Name,
755                                    const TemplateArgumentListInfo &Args) const;
756  QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
757                                                  NestedNameSpecifier *NNS,
758                                                  const IdentifierInfo *Name,
759                                                  unsigned NumArgs,
760                                            const TemplateArgument *Args) const;
761
762  QualType getPackExpansionType(QualType Pattern,
763                                llvm::Optional<unsigned> NumExpansions);
764
765  QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl) const;
766
767  QualType getObjCObjectType(QualType Base,
768                             ObjCProtocolDecl * const *Protocols,
769                             unsigned NumProtocols) const;
770
771  /// getObjCObjectPointerType - Return a ObjCObjectPointerType type
772  /// for the given ObjCObjectType.
773  QualType getObjCObjectPointerType(QualType OIT) const;
774
775  /// getTypeOfType - GCC extension.
776  QualType getTypeOfExprType(Expr *e) const;
777  QualType getTypeOfType(QualType t) const;
778
779  /// getDecltypeType - C++0x decltype.
780  QualType getDecltypeType(Expr *e) const;
781
782  /// getUnaryTransformType - unary type transforms
783  QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType,
784                                 UnaryTransformType::UTTKind UKind) const;
785
786  /// getAutoType - C++0x deduced auto type.
787  QualType getAutoType(QualType DeducedType) const;
788
789  /// getAutoDeductType - C++0x deduction pattern for 'auto' type.
790  QualType getAutoDeductType() const;
791
792  /// getAutoRRefDeductType - C++0x deduction pattern for 'auto &&' type.
793  QualType getAutoRRefDeductType() const;
794
795  /// getTagDeclType - Return the unique reference to the type for the
796  /// specified TagDecl (struct/union/class/enum) decl.
797  QualType getTagDeclType(const TagDecl *Decl) const;
798
799  /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
800  /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
801  CanQualType getSizeType() const;
802
803  /// getWCharType - In C++, this returns the unique wchar_t type.  In C99, this
804  /// returns a type compatible with the type defined in <stddef.h> as defined
805  /// by the target.
806  QualType getWCharType() const { return WCharTy; }
807
808  /// getSignedWCharType - Return the type of "signed wchar_t".
809  /// Used when in C++, as a GCC extension.
810  QualType getSignedWCharType() const;
811
812  /// getUnsignedWCharType - Return the type of "unsigned wchar_t".
813  /// Used when in C++, as a GCC extension.
814  QualType getUnsignedWCharType() const;
815
816  /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
817  /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
818  QualType getPointerDiffType() const;
819
820  // getCFConstantStringType - Return the C structure type used to represent
821  // constant CFStrings.
822  QualType getCFConstantStringType() const;
823
824  // getNSConstantStringType - Return the C structure type used to represent
825  // constant NSStrings.
826  QualType getNSConstantStringType() const;
827  /// Get the structure type used to representation NSStrings, or NULL
828  /// if it hasn't yet been built.
829  QualType getRawNSConstantStringType() const {
830    if (NSConstantStringTypeDecl)
831      return getTagDeclType(NSConstantStringTypeDecl);
832    return QualType();
833  }
834  void setNSConstantStringType(QualType T);
835
836
837  /// Get the structure type used to representation CFStrings, or NULL
838  /// if it hasn't yet been built.
839  QualType getRawCFConstantStringType() const {
840    if (CFConstantStringTypeDecl)
841      return getTagDeclType(CFConstantStringTypeDecl);
842    return QualType();
843  }
844  void setCFConstantStringType(QualType T);
845
846  // This setter/getter represents the ObjC type for an NSConstantString.
847  void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
848  QualType getObjCConstantStringInterface() const {
849    return ObjCConstantStringType;
850  }
851
852  //// This gets the struct used to keep track of fast enumerations.
853  QualType getObjCFastEnumerationStateType() const;
854
855  /// Get the ObjCFastEnumerationState type, or NULL if it hasn't yet
856  /// been built.
857  QualType getRawObjCFastEnumerationStateType() const {
858    if (ObjCFastEnumerationStateTypeDecl)
859      return getTagDeclType(ObjCFastEnumerationStateTypeDecl);
860    return QualType();
861  }
862
863  void setObjCFastEnumerationStateType(QualType T);
864
865  /// \brief Set the type for the C FILE type.
866  void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
867
868  /// \brief Retrieve the C FILE type.
869  QualType getFILEType() const {
870    if (FILEDecl)
871      return getTypeDeclType(FILEDecl);
872    return QualType();
873  }
874
875  /// \brief Set the type for the C jmp_buf type.
876  void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
877    this->jmp_bufDecl = jmp_bufDecl;
878  }
879
880  /// \brief Retrieve the C jmp_buf type.
881  QualType getjmp_bufType() const {
882    if (jmp_bufDecl)
883      return getTypeDeclType(jmp_bufDecl);
884    return QualType();
885  }
886
887  /// \brief Set the type for the C sigjmp_buf type.
888  void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
889    this->sigjmp_bufDecl = sigjmp_bufDecl;
890  }
891
892  /// \brief Retrieve the C sigjmp_buf type.
893  QualType getsigjmp_bufType() const {
894    if (sigjmp_bufDecl)
895      return getTypeDeclType(sigjmp_bufDecl);
896    return QualType();
897  }
898
899  /// \brief The result type of logical operations, '<', '>', '!=', etc.
900  QualType getLogicalOperationType() const {
901    return getLangOptions().CPlusPlus ? BoolTy : IntTy;
902  }
903
904  /// getObjCEncodingForType - Emit the ObjC type encoding for the
905  /// given type into \arg S. If \arg NameFields is specified then
906  /// record field names are also encoded.
907  void getObjCEncodingForType(QualType t, std::string &S,
908                              const FieldDecl *Field=0) const;
909
910  void getLegacyIntegralTypeEncoding(QualType &t) const;
911
912  // Put the string version of type qualifiers into S.
913  void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
914                                       std::string &S) const;
915
916  /// getObjCEncodingForFunctionDecl - Returns the encoded type for this
917  //function.  This is in the same format as Objective-C method encodings.
918  void getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S);
919
920  /// getObjCEncodingForMethodDecl - Return the encoded type for this method
921  /// declaration.
922  void getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S)
923    const;
924
925  /// getObjCEncodingForBlock - Return the encoded type for this block
926  /// declaration.
927  std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
928
929  /// getObjCEncodingForPropertyDecl - Return the encoded type for
930  /// this method declaration. If non-NULL, Container must be either
931  /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
932  /// only be NULL when getting encodings for protocol properties.
933  void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
934                                      const Decl *Container,
935                                      std::string &S) const;
936
937  bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
938                                      ObjCProtocolDecl *rProto) const;
939
940  /// getObjCEncodingTypeSize returns size of type for objective-c encoding
941  /// purpose in characters.
942  CharUnits getObjCEncodingTypeSize(QualType t) const;
943
944  /// \brief Whether __[u]int128_t identifier is installed.
945  bool isInt128Installed() const { return IsInt128Installed; }
946  void setInt128Installed() { IsInt128Installed = true; }
947
948  /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by
949  /// Sema.  id is always a (typedef for a) pointer type, a pointer to a struct.
950  QualType getObjCIdType() const { return ObjCIdTypedefType; }
951  void setObjCIdType(QualType T);
952
953  void setObjCSelType(QualType T);
954  QualType getObjCSelType() const { return ObjCSelTypedefType; }
955
956  void setObjCProtoType(QualType QT);
957  QualType getObjCProtoType() const { return ObjCProtoType; }
958
959  /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
960  /// Sema.  'Class' is always a (typedef for a) pointer type, a pointer to a
961  /// struct.
962  QualType getObjCClassType() const { return ObjCClassTypedefType; }
963  void setObjCClassType(QualType T);
964
965  void setBuiltinVaListType(QualType T);
966  QualType getBuiltinVaListType() const { return BuiltinVaListType; }
967
968  /// getCVRQualifiedType - Returns a type with additional const,
969  /// volatile, or restrict qualifiers.
970  QualType getCVRQualifiedType(QualType T, unsigned CVR) const {
971    return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
972  }
973
974  /// getQualifiedType - Returns a type with additional qualifiers.
975  QualType getQualifiedType(QualType T, Qualifiers Qs) const {
976    if (!Qs.hasNonFastQualifiers())
977      return T.withFastQualifiers(Qs.getFastQualifiers());
978    QualifierCollector Qc(Qs);
979    const Type *Ptr = Qc.strip(T);
980    return getExtQualType(Ptr, Qc);
981  }
982
983  /// getQualifiedType - Returns a type with additional qualifiers.
984  QualType getQualifiedType(const Type *T, Qualifiers Qs) const {
985    if (!Qs.hasNonFastQualifiers())
986      return QualType(T, Qs.getFastQualifiers());
987    return getExtQualType(T, Qs);
988  }
989
990  DeclarationNameInfo getNameForTemplate(TemplateName Name,
991                                         SourceLocation NameLoc) const;
992
993  TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
994                                         UnresolvedSetIterator End) const;
995
996  TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
997                                        bool TemplateKeyword,
998                                        TemplateDecl *Template) const;
999
1000  TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
1001                                        const IdentifierInfo *Name) const;
1002  TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
1003                                        OverloadedOperatorKind Operator) const;
1004  TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param,
1005                                        const TemplateArgument &ArgPack) const;
1006
1007  enum GetBuiltinTypeError {
1008    GE_None,              //< No error
1009    GE_Missing_stdio,     //< Missing a type from <stdio.h>
1010    GE_Missing_setjmp     //< Missing a type from <setjmp.h>
1011  };
1012
1013  /// GetBuiltinType - Return the type for the specified builtin.  If
1014  /// IntegerConstantArgs is non-null, it is filled in with a bitmask of
1015  /// arguments to the builtin that are required to be integer constant
1016  /// expressions.
1017  QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
1018                          unsigned *IntegerConstantArgs = 0) const;
1019
1020private:
1021  CanQualType getFromTargetType(unsigned Type) const;
1022
1023  //===--------------------------------------------------------------------===//
1024  //                         Type Predicates.
1025  //===--------------------------------------------------------------------===//
1026
1027public:
1028  /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
1029  /// garbage collection attribute.
1030  ///
1031  Qualifiers::GC getObjCGCAttrKind(QualType Ty) const;
1032
1033  /// areCompatibleVectorTypes - Return true if the given vector types
1034  /// are of the same unqualified type or if they are equivalent to the same
1035  /// GCC vector type, ignoring whether they are target-specific (AltiVec or
1036  /// Neon) types.
1037  bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
1038
1039  /// isObjCNSObjectType - Return true if this is an NSObject object with
1040  /// its NSObject attribute set.
1041  bool isObjCNSObjectType(QualType Ty) const;
1042
1043  //===--------------------------------------------------------------------===//
1044  //                         Type Sizing and Analysis
1045  //===--------------------------------------------------------------------===//
1046
1047  /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified
1048  /// scalar floating point type.
1049  const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
1050
1051  /// getTypeInfo - Get the size and alignment of the specified complete type in
1052  /// bits.
1053  std::pair<uint64_t, unsigned> getTypeInfo(const Type *T) const;
1054  std::pair<uint64_t, unsigned> getTypeInfo(QualType T) const {
1055    return getTypeInfo(T.getTypePtr());
1056  }
1057
1058  /// getTypeSize - Return the size of the specified type, in bits.  This method
1059  /// does not work on incomplete types.
1060  uint64_t getTypeSize(QualType T) const {
1061    return getTypeInfo(T).first;
1062  }
1063  uint64_t getTypeSize(const Type *T) const {
1064    return getTypeInfo(T).first;
1065  }
1066
1067  /// getCharWidth - Return the size of the character type, in bits
1068  uint64_t getCharWidth() const {
1069    return getTypeSize(CharTy);
1070  }
1071
1072  /// toCharUnitsFromBits - Convert a size in bits to a size in characters.
1073  CharUnits toCharUnitsFromBits(int64_t BitSize) const;
1074
1075  /// toBits - Convert a size in characters to a size in bits.
1076  int64_t toBits(CharUnits CharSize) const;
1077
1078  /// getTypeSizeInChars - Return the size of the specified type, in characters.
1079  /// This method does not work on incomplete types.
1080  CharUnits getTypeSizeInChars(QualType T) const;
1081  CharUnits getTypeSizeInChars(const Type *T) const;
1082
1083  /// getTypeAlign - Return the ABI-specified alignment of a type, in bits.
1084  /// This method does not work on incomplete types.
1085  unsigned getTypeAlign(QualType T) const {
1086    return getTypeInfo(T).second;
1087  }
1088  unsigned getTypeAlign(const Type *T) const {
1089    return getTypeInfo(T).second;
1090  }
1091
1092  /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in
1093  /// characters. This method does not work on incomplete types.
1094  CharUnits getTypeAlignInChars(QualType T) const;
1095  CharUnits getTypeAlignInChars(const Type *T) const;
1096
1097  std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const;
1098  std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const;
1099
1100  /// getPreferredTypeAlign - Return the "preferred" alignment of the specified
1101  /// type for the current target in bits.  This can be different than the ABI
1102  /// alignment in cases where it is beneficial for performance to overalign
1103  /// a data type.
1104  unsigned getPreferredTypeAlign(const Type *T) const;
1105
1106  /// getDeclAlign - Return a conservative estimate of the alignment of
1107  /// the specified decl.  Note that bitfields do not have a valid alignment, so
1108  /// this method will assert on them.
1109  /// If @p RefAsPointee, references are treated like their underlying type
1110  /// (for alignof), else they're treated like pointers (for CodeGen).
1111  CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false) const;
1112
1113  /// getASTRecordLayout - Get or compute information about the layout of the
1114  /// specified record (struct/union/class), which indicates its size and field
1115  /// position information.
1116  const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const;
1117
1118  /// getASTObjCInterfaceLayout - Get or compute information about the
1119  /// layout of the specified Objective-C interface.
1120  const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D)
1121    const;
1122
1123  void DumpRecordLayout(const RecordDecl *RD, llvm::raw_ostream &OS) const;
1124
1125  /// getASTObjCImplementationLayout - Get or compute information about
1126  /// the layout of the specified Objective-C implementation. This may
1127  /// differ from the interface if synthesized ivars are present.
1128  const ASTRecordLayout &
1129  getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const;
1130
1131  /// getKeyFunction - Get the key function for the given record decl, or NULL
1132  /// if there isn't one.  The key function is, according to the Itanium C++ ABI
1133  /// section 5.2.3:
1134  ///
1135  /// ...the first non-pure virtual function that is not inline at the point
1136  /// of class definition.
1137  const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD);
1138
1139  bool isNearlyEmpty(const CXXRecordDecl *RD) const;
1140
1141  MangleContext *createMangleContext();
1142
1143  void ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
1144                               llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars)
1145    const;
1146
1147  void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
1148                            llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) const;
1149
1150  unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const;
1151  void CollectInheritedProtocols(const Decl *CDecl,
1152                          llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
1153
1154  //===--------------------------------------------------------------------===//
1155  //                            Type Operators
1156  //===--------------------------------------------------------------------===//
1157
1158  /// getCanonicalType - Return the canonical (structural) type corresponding to
1159  /// the specified potentially non-canonical type.  The non-canonical version
1160  /// of a type may have many "decorated" versions of types.  Decorators can
1161  /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
1162  /// to be free of any of these, allowing two canonical types to be compared
1163  /// for exact equality with a simple pointer comparison.
1164  CanQualType getCanonicalType(QualType T) const {
1165    return CanQualType::CreateUnsafe(T.getCanonicalType());
1166  }
1167
1168  const Type *getCanonicalType(const Type *T) const {
1169    return T->getCanonicalTypeInternal().getTypePtr();
1170  }
1171
1172  /// getCanonicalParamType - Return the canonical parameter type
1173  /// corresponding to the specific potentially non-canonical one.
1174  /// Qualifiers are stripped off, functions are turned into function
1175  /// pointers, and arrays decay one level into pointers.
1176  CanQualType getCanonicalParamType(QualType T) const;
1177
1178  /// \brief Determine whether the given types are equivalent.
1179  bool hasSameType(QualType T1, QualType T2) {
1180    return getCanonicalType(T1) == getCanonicalType(T2);
1181  }
1182
1183  /// \brief Returns this type as a completely-unqualified array type,
1184  /// capturing the qualifiers in Quals. This will remove the minimal amount of
1185  /// sugaring from the types, similar to the behavior of
1186  /// QualType::getUnqualifiedType().
1187  ///
1188  /// \param T is the qualified type, which may be an ArrayType
1189  ///
1190  /// \param Quals will receive the full set of qualifiers that were
1191  /// applied to the array.
1192  ///
1193  /// \returns if this is an array type, the completely unqualified array type
1194  /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
1195  QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
1196
1197  /// \brief Determine whether the given types are equivalent after
1198  /// cvr-qualifiers have been removed.
1199  bool hasSameUnqualifiedType(QualType T1, QualType T2) {
1200    return getCanonicalType(T1).getTypePtr() ==
1201           getCanonicalType(T2).getTypePtr();
1202  }
1203
1204  bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2);
1205
1206  /// \brief Retrieves the "canonical" nested name specifier for a
1207  /// given nested name specifier.
1208  ///
1209  /// The canonical nested name specifier is a nested name specifier
1210  /// that uniquely identifies a type or namespace within the type
1211  /// system. For example, given:
1212  ///
1213  /// \code
1214  /// namespace N {
1215  ///   struct S {
1216  ///     template<typename T> struct X { typename T* type; };
1217  ///   };
1218  /// }
1219  ///
1220  /// template<typename T> struct Y {
1221  ///   typename N::S::X<T>::type member;
1222  /// };
1223  /// \endcode
1224  ///
1225  /// Here, the nested-name-specifier for N::S::X<T>:: will be
1226  /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined
1227  /// by declarations in the type system and the canonical type for
1228  /// the template type parameter 'T' is template-param-0-0.
1229  NestedNameSpecifier *
1230  getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const;
1231
1232  /// \brief Retrieves the default calling convention to use for
1233  /// C++ instance methods.
1234  CallingConv getDefaultMethodCallConv();
1235
1236  /// \brief Retrieves the canonical representation of the given
1237  /// calling convention.
1238  CallingConv getCanonicalCallConv(CallingConv CC) const {
1239    if (CC == CC_C)
1240      return CC_Default;
1241    return CC;
1242  }
1243
1244  /// \brief Determines whether two calling conventions name the same
1245  /// calling convention.
1246  bool isSameCallConv(CallingConv lcc, CallingConv rcc) {
1247    return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc));
1248  }
1249
1250  /// \brief Retrieves the "canonical" template name that refers to a
1251  /// given template.
1252  ///
1253  /// The canonical template name is the simplest expression that can
1254  /// be used to refer to a given template. For most templates, this
1255  /// expression is just the template declaration itself. For example,
1256  /// the template std::vector can be referred to via a variety of
1257  /// names---std::vector, ::std::vector, vector (if vector is in
1258  /// scope), etc.---but all of these names map down to the same
1259  /// TemplateDecl, which is used to form the canonical template name.
1260  ///
1261  /// Dependent template names are more interesting. Here, the
1262  /// template name could be something like T::template apply or
1263  /// std::allocator<T>::template rebind, where the nested name
1264  /// specifier itself is dependent. In this case, the canonical
1265  /// template name uses the shortest form of the dependent
1266  /// nested-name-specifier, which itself contains all canonical
1267  /// types, values, and templates.
1268  TemplateName getCanonicalTemplateName(TemplateName Name) const;
1269
1270  /// \brief Determine whether the given template names refer to the same
1271  /// template.
1272  bool hasSameTemplateName(TemplateName X, TemplateName Y);
1273
1274  /// \brief Retrieve the "canonical" template argument.
1275  ///
1276  /// The canonical template argument is the simplest template argument
1277  /// (which may be a type, value, expression, or declaration) that
1278  /// expresses the value of the argument.
1279  TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg)
1280    const;
1281
1282  /// Type Query functions.  If the type is an instance of the specified class,
1283  /// return the Type pointer for the underlying maximally pretty type.  This
1284  /// is a member of ASTContext because this may need to do some amount of
1285  /// canonicalization, e.g. to move type qualifiers into the element type.
1286  const ArrayType *getAsArrayType(QualType T) const;
1287  const ConstantArrayType *getAsConstantArrayType(QualType T) const {
1288    return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
1289  }
1290  const VariableArrayType *getAsVariableArrayType(QualType T) const {
1291    return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
1292  }
1293  const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const {
1294    return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
1295  }
1296  const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T)
1297    const {
1298    return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
1299  }
1300
1301  /// getBaseElementType - Returns the innermost element type of an array type.
1302  /// For example, will return "int" for int[m][n]
1303  QualType getBaseElementType(const ArrayType *VAT) const;
1304
1305  /// getBaseElementType - Returns the innermost element type of a type
1306  /// (which needn't actually be an array type).
1307  QualType getBaseElementType(QualType QT) const;
1308
1309  /// getConstantArrayElementCount - Returns number of constant array elements.
1310  uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
1311
1312  /// getArrayDecayedType - Return the properly qualified result of decaying the
1313  /// specified array type to a pointer.  This operation is non-trivial when
1314  /// handling typedefs etc.  The canonical type of "T" must be an array type,
1315  /// this returns a pointer to a properly qualified element of the array.
1316  ///
1317  /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
1318  QualType getArrayDecayedType(QualType T) const;
1319
1320  /// getPromotedIntegerType - Returns the type that Promotable will
1321  /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable
1322  /// integer type.
1323  QualType getPromotedIntegerType(QualType PromotableType) const;
1324
1325  /// \brief Whether this is a promotable bitfield reference according
1326  /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
1327  ///
1328  /// \returns the type this bit-field will promote to, or NULL if no
1329  /// promotion occurs.
1330  QualType isPromotableBitField(Expr *E) const;
1331
1332  /// getIntegerTypeOrder - Returns the highest ranked integer type:
1333  /// C99 6.3.1.8p1.  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
1334  /// LHS < RHS, return -1.
1335  int getIntegerTypeOrder(QualType LHS, QualType RHS) const;
1336
1337  /// getFloatingTypeOrder - Compare the rank of the two specified floating
1338  /// point types, ignoring the domain of the type (i.e. 'double' ==
1339  /// '_Complex double').  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
1340  /// LHS < RHS, return -1.
1341  int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
1342
1343  /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
1344  /// point or a complex type (based on typeDomain/typeSize).
1345  /// 'typeDomain' is a real floating point or complex type.
1346  /// 'typeSize' is a real floating point or complex type.
1347  QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
1348                                             QualType typeDomain) const;
1349
1350  unsigned getTargetAddressSpace(QualType T) const {
1351    return getTargetAddressSpace(T.getQualifiers());
1352  }
1353
1354  unsigned getTargetAddressSpace(Qualifiers Q) const {
1355    return getTargetAddressSpace(Q.getAddressSpace());
1356  }
1357
1358  unsigned getTargetAddressSpace(unsigned AS) const {
1359    if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count)
1360      return AS;
1361    else
1362      return AddrSpaceMap[AS - LangAS::Offset];
1363  }
1364
1365private:
1366  // Helper for integer ordering
1367  unsigned getIntegerRank(const Type *T) const;
1368
1369public:
1370
1371  //===--------------------------------------------------------------------===//
1372  //                    Type Compatibility Predicates
1373  //===--------------------------------------------------------------------===//
1374
1375  /// Compatibility predicates used to check assignment expressions.
1376  bool typesAreCompatible(QualType T1, QualType T2,
1377                          bool CompareUnqualified = false); // C99 6.2.7p1
1378
1379  bool typesAreBlockPointerCompatible(QualType, QualType);
1380
1381  bool isObjCIdType(QualType T) const {
1382    return T == ObjCIdTypedefType;
1383  }
1384  bool isObjCClassType(QualType T) const {
1385    return T == ObjCClassTypedefType;
1386  }
1387  bool isObjCSelType(QualType T) const {
1388    return T == ObjCSelTypedefType;
1389  }
1390  bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
1391  bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
1392                                         bool ForCompare);
1393
1394  bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS);
1395
1396  // Check the safety of assignment from LHS to RHS
1397  bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
1398                               const ObjCObjectPointerType *RHSOPT);
1399  bool canAssignObjCInterfaces(const ObjCObjectType *LHS,
1400                               const ObjCObjectType *RHS);
1401  bool canAssignObjCInterfacesInBlockPointer(
1402                                          const ObjCObjectPointerType *LHSOPT,
1403                                          const ObjCObjectPointerType *RHSOPT,
1404                                          bool BlockReturnType);
1405  bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
1406  QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
1407                                   const ObjCObjectPointerType *RHSOPT);
1408  bool canBindObjCObjectType(QualType To, QualType From);
1409
1410  // Functions for calculating composite types
1411  QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false,
1412                      bool Unqualified = false, bool BlockReturnType = false);
1413  QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false,
1414                              bool Unqualified = false);
1415  QualType mergeFunctionArgumentTypes(QualType, QualType,
1416                                      bool OfBlockPointer=false,
1417                                      bool Unqualified = false);
1418  QualType mergeTransparentUnionType(QualType, QualType,
1419                                     bool OfBlockPointer=false,
1420                                     bool Unqualified = false);
1421
1422  QualType mergeObjCGCQualifiers(QualType, QualType);
1423
1424  void ResetObjCLayout(const ObjCContainerDecl *CD) {
1425    ObjCLayouts[CD] = 0;
1426  }
1427
1428  //===--------------------------------------------------------------------===//
1429  //                    Integer Predicates
1430  //===--------------------------------------------------------------------===//
1431
1432  // The width of an integer, as defined in C99 6.2.6.2. This is the number
1433  // of bits in an integer type excluding any padding bits.
1434  unsigned getIntWidth(QualType T) const;
1435
1436  // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
1437  // unsigned integer type.  This method takes a signed type, and returns the
1438  // corresponding unsigned integer type.
1439  QualType getCorrespondingUnsignedType(QualType T);
1440
1441  //===--------------------------------------------------------------------===//
1442  //                    Type Iterators.
1443  //===--------------------------------------------------------------------===//
1444
1445  typedef std::vector<Type*>::iterator       type_iterator;
1446  typedef std::vector<Type*>::const_iterator const_type_iterator;
1447
1448  type_iterator types_begin() { return Types.begin(); }
1449  type_iterator types_end() { return Types.end(); }
1450  const_type_iterator types_begin() const { return Types.begin(); }
1451  const_type_iterator types_end() const { return Types.end(); }
1452
1453  //===--------------------------------------------------------------------===//
1454  //                    Integer Values
1455  //===--------------------------------------------------------------------===//
1456
1457  /// MakeIntValue - Make an APSInt of the appropriate width and
1458  /// signedness for the given \arg Value and integer \arg Type.
1459  llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const {
1460    llvm::APSInt Res(getIntWidth(Type),
1461                     !Type->isSignedIntegerOrEnumerationType());
1462    Res = Value;
1463    return Res;
1464  }
1465
1466  /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists.
1467  ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
1468  /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists.
1469  ObjCCategoryImplDecl   *getObjCImplementation(ObjCCategoryDecl *D);
1470
1471  /// \brief returns true if there is at lease one @implementation in TU.
1472  bool AnyObjCImplementation() {
1473    return !ObjCImpls.empty();
1474  }
1475
1476  /// \brief Set the implementation of ObjCInterfaceDecl.
1477  void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
1478                             ObjCImplementationDecl *ImplD);
1479  /// \brief Set the implementation of ObjCCategoryDecl.
1480  void setObjCImplementation(ObjCCategoryDecl *CatD,
1481                             ObjCCategoryImplDecl *ImplD);
1482
1483  /// \brief Set the copy inialization expression of a block var decl.
1484  void setBlockVarCopyInits(VarDecl*VD, Expr* Init);
1485  /// \brief Get the copy initialization expression of VarDecl,or NULL if
1486  /// none exists.
1487  Expr *getBlockVarCopyInits(const VarDecl*VD);
1488
1489  /// \brief Allocate an uninitialized TypeSourceInfo.
1490  ///
1491  /// The caller should initialize the memory held by TypeSourceInfo using
1492  /// the TypeLoc wrappers.
1493  ///
1494  /// \param T the type that will be the basis for type source info. This type
1495  /// should refer to how the declarator was written in source code, not to
1496  /// what type semantic analysis resolved the declarator to.
1497  ///
1498  /// \param Size the size of the type info to create, or 0 if the size
1499  /// should be calculated based on the type.
1500  TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const;
1501
1502  /// \brief Allocate a TypeSourceInfo where all locations have been
1503  /// initialized to a given location, which defaults to the empty
1504  /// location.
1505  TypeSourceInfo *
1506  getTrivialTypeSourceInfo(QualType T,
1507                           SourceLocation Loc = SourceLocation()) const;
1508
1509  TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; }
1510
1511  /// \brief Add a deallocation callback that will be invoked when the
1512  /// ASTContext is destroyed.
1513  ///
1514  /// \brief Callback A callback function that will be invoked on destruction.
1515  ///
1516  /// \brief Data Pointer data that will be provided to the callback function
1517  /// when it is called.
1518  void AddDeallocation(void (*Callback)(void*), void *Data);
1519
1520  GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD);
1521  GVALinkage GetGVALinkageForVariable(const VarDecl *VD);
1522
1523  /// \brief Determines if the decl can be CodeGen'ed or deserialized from PCH
1524  /// lazily, only when used; this is only relevant for function or file scoped
1525  /// var definitions.
1526  ///
1527  /// \returns true if the function/var must be CodeGen'ed/deserialized even if
1528  /// it is not used.
1529  bool DeclMustBeEmitted(const Decl *D);
1530
1531  //===--------------------------------------------------------------------===//
1532  //                    Statistics
1533  //===--------------------------------------------------------------------===//
1534
1535  /// \brief The number of implicitly-declared default constructors.
1536  static unsigned NumImplicitDefaultConstructors;
1537
1538  /// \brief The number of implicitly-declared default constructors for
1539  /// which declarations were built.
1540  static unsigned NumImplicitDefaultConstructorsDeclared;
1541
1542  /// \brief The number of implicitly-declared copy constructors.
1543  static unsigned NumImplicitCopyConstructors;
1544
1545  /// \brief The number of implicitly-declared copy constructors for
1546  /// which declarations were built.
1547  static unsigned NumImplicitCopyConstructorsDeclared;
1548
1549  /// \brief The number of implicitly-declared move constructors.
1550  static unsigned NumImplicitMoveConstructors;
1551
1552  /// \brief The number of implicitly-declared move constructors for
1553  /// which declarations were built.
1554  static unsigned NumImplicitMoveConstructorsDeclared;
1555
1556  /// \brief The number of implicitly-declared copy assignment operators.
1557  static unsigned NumImplicitCopyAssignmentOperators;
1558
1559  /// \brief The number of implicitly-declared copy assignment operators for
1560  /// which declarations were built.
1561  static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
1562
1563  /// \brief The number of implicitly-declared move assignment operators.
1564  static unsigned NumImplicitMoveAssignmentOperators;
1565
1566  /// \brief The number of implicitly-declared move assignment operators for
1567  /// which declarations were built.
1568  static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
1569
1570  /// \brief The number of implicitly-declared destructors.
1571  static unsigned NumImplicitDestructors;
1572
1573  /// \brief The number of implicitly-declared destructors for which
1574  /// declarations were built.
1575  static unsigned NumImplicitDestructorsDeclared;
1576
1577private:
1578  ASTContext(const ASTContext&); // DO NOT IMPLEMENT
1579  void operator=(const ASTContext&); // DO NOT IMPLEMENT
1580
1581  void InitBuiltinTypes();
1582  void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
1583
1584  // Return the ObjC type encoding for a given type.
1585  void getObjCEncodingForTypeImpl(QualType t, std::string &S,
1586                                  bool ExpandPointedToStructures,
1587                                  bool ExpandStructures,
1588                                  const FieldDecl *Field,
1589                                  bool OutermostType = false,
1590                                  bool EncodingProperty = false,
1591                                  bool StructField = false) const;
1592
1593  // Adds the encoding of the structure's members.
1594  void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S,
1595                                       const FieldDecl *Field,
1596                                       bool includeVBases = true) const;
1597
1598  const ASTRecordLayout &
1599  getObjCLayout(const ObjCInterfaceDecl *D,
1600                const ObjCImplementationDecl *Impl) const;
1601
1602private:
1603  /// \brief A set of deallocations that should be performed when the
1604  /// ASTContext is destroyed.
1605  llvm::SmallVector<std::pair<void (*)(void*), void *>, 16> Deallocations;
1606
1607  // FIXME: This currently contains the set of StoredDeclMaps used
1608  // by DeclContext objects.  This probably should not be in ASTContext,
1609  // but we include it here so that ASTContext can quickly deallocate them.
1610  llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM;
1611
1612  /// \brief A counter used to uniquely identify "blocks".
1613  mutable unsigned int UniqueBlockByRefTypeID;
1614
1615  friend class DeclContext;
1616  friend class DeclarationNameTable;
1617  void ReleaseDeclContextMaps();
1618};
1619
1620/// @brief Utility function for constructing a nullary selector.
1621static inline Selector GetNullarySelector(llvm::StringRef name, ASTContext& Ctx) {
1622  IdentifierInfo* II = &Ctx.Idents.get(name);
1623  return Ctx.Selectors.getSelector(0, &II);
1624}
1625
1626/// @brief Utility function for constructing an unary selector.
1627static inline Selector GetUnarySelector(llvm::StringRef name, ASTContext& Ctx) {
1628  IdentifierInfo* II = &Ctx.Idents.get(name);
1629  return Ctx.Selectors.getSelector(1, &II);
1630}
1631
1632}  // end namespace clang
1633
1634// operator new and delete aren't allowed inside namespaces.
1635// The throw specifications are mandated by the standard.
1636/// @brief Placement new for using the ASTContext's allocator.
1637///
1638/// This placement form of operator new uses the ASTContext's allocator for
1639/// obtaining memory. It is a non-throwing new, which means that it returns
1640/// null on error. (If that is what the allocator does. The current does, so if
1641/// this ever changes, this operator will have to be changed, too.)
1642/// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
1643/// @code
1644/// // Default alignment (8)
1645/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
1646/// // Specific alignment
1647/// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
1648/// @endcode
1649/// Please note that you cannot use delete on the pointer; it must be
1650/// deallocated using an explicit destructor call followed by
1651/// @c Context.Deallocate(Ptr).
1652///
1653/// @param Bytes The number of bytes to allocate. Calculated by the compiler.
1654/// @param C The ASTContext that provides the allocator.
1655/// @param Alignment The alignment of the allocated memory (if the underlying
1656///                  allocator supports it).
1657/// @return The allocated memory. Could be NULL.
1658inline void *operator new(size_t Bytes, const clang::ASTContext &C,
1659                          size_t Alignment) throw () {
1660  return C.Allocate(Bytes, Alignment);
1661}
1662/// @brief Placement delete companion to the new above.
1663///
1664/// This operator is just a companion to the new above. There is no way of
1665/// invoking it directly; see the new operator for more details. This operator
1666/// is called implicitly by the compiler if a placement new expression using
1667/// the ASTContext throws in the object constructor.
1668inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t)
1669              throw () {
1670  C.Deallocate(Ptr);
1671}
1672
1673/// This placement form of operator new[] uses the ASTContext's allocator for
1674/// obtaining memory. It is a non-throwing new[], which means that it returns
1675/// null on error.
1676/// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
1677/// @code
1678/// // Default alignment (8)
1679/// char *data = new (Context) char[10];
1680/// // Specific alignment
1681/// char *data = new (Context, 4) char[10];
1682/// @endcode
1683/// Please note that you cannot use delete on the pointer; it must be
1684/// deallocated using an explicit destructor call followed by
1685/// @c Context.Deallocate(Ptr).
1686///
1687/// @param Bytes The number of bytes to allocate. Calculated by the compiler.
1688/// @param C The ASTContext that provides the allocator.
1689/// @param Alignment The alignment of the allocated memory (if the underlying
1690///                  allocator supports it).
1691/// @return The allocated memory. Could be NULL.
1692inline void *operator new[](size_t Bytes, const clang::ASTContext& C,
1693                            size_t Alignment = 8) throw () {
1694  return C.Allocate(Bytes, Alignment);
1695}
1696
1697/// @brief Placement delete[] companion to the new[] above.
1698///
1699/// This operator is just a companion to the new[] above. There is no way of
1700/// invoking it directly; see the new[] operator for more details. This operator
1701/// is called implicitly by the compiler if a placement new[] expression using
1702/// the ASTContext throws in the object constructor.
1703inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t)
1704              throw () {
1705  C.Deallocate(Ptr);
1706}
1707
1708#endif
1709