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