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