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