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