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