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