ASTContext.h revision 3e9704981d7691fdd44913bf1786e8d760d8a627
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/Builtins.h"
20#include "clang/AST/DeclarationName.h"
21#include "clang/AST/DeclBase.h"
22#include "clang/AST/Type.h"
23#include "clang/Basic/SourceLocation.h"
24#include "llvm/ADT/DenseMap.h"
25#include "llvm/ADT/FoldingSet.h"
26#include "llvm/Bitcode/SerializationFwd.h"
27#include "llvm/Support/Allocator.h"
28#include <vector>
29
30namespace llvm {
31  struct fltSemantics;
32}
33
34namespace clang {
35  class ASTRecordLayout;
36  class Expr;
37  class IdentifierTable;
38  class SelectorTable;
39  class SourceManager;
40  class TargetInfo;
41  // Decls
42  class Decl;
43  class ObjCPropertyDecl;
44  class RecordDecl;
45  class TagDecl;
46  class TranslationUnitDecl;
47  class TypeDecl;
48  class TypedefDecl;
49  class TemplateTypeParmDecl;
50  class FieldDecl;
51  class ObjCIvarRefExpr;
52  class ObjCIvarDecl;
53
54/// ASTContext - This class holds long-lived AST nodes (such as types and
55/// decls) that can be referred to throughout the semantic analysis of a file.
56class ASTContext {
57  std::vector<Type*> Types;
58  llvm::FoldingSet<ASQualType> ASQualTypes;
59  llvm::FoldingSet<ComplexType> ComplexTypes;
60  llvm::FoldingSet<PointerType> PointerTypes;
61  llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
62  llvm::FoldingSet<ReferenceType> ReferenceTypes;
63  llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
64  llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
65  llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
66  std::vector<VariableArrayType*> VariableArrayTypes;
67  std::vector<DependentSizedArrayType*> DependentSizedArrayTypes;
68  llvm::FoldingSet<VectorType> VectorTypes;
69  llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos;
70  llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
71  llvm::FoldingSet<ObjCQualifiedInterfaceType> ObjCQualifiedInterfaceTypes;
72  llvm::FoldingSet<ObjCQualifiedIdType> ObjCQualifiedIdTypes;
73  /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
74  ///  This is lazily created.  This is intentionally not serialized.
75  llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> ASTRecordLayouts;
76  llvm::DenseMap<const ObjCInterfaceDecl*,
77                 const ASTRecordLayout*> ASTObjCInterfaces;
78
79  // FIXME: Shouldn't ASTRecordForInterface/ASTFieldForIvarRef and
80  // addRecordToClass/getFieldDecl be part of the backend (i.e. CodeGenTypes and
81  // CodeGenFunction)?
82  llvm::DenseMap<const ObjCInterfaceDecl*,
83                 const RecordDecl*> ASTRecordForInterface;
84  llvm::DenseMap<const ObjCIvarRefExpr*, const FieldDecl*> ASTFieldForIvarRef;
85
86  /// BuiltinVaListType - built-in va list type.
87  /// This is initially null and set by Sema::LazilyCreateBuiltin when
88  /// a builtin that takes a valist is encountered.
89  QualType BuiltinVaListType;
90
91  /// ObjCIdType - a pseudo built-in typedef type (set by Sema).
92  QualType ObjCIdType;
93  const RecordType *IdStructType;
94
95  /// ObjCSelType - another pseudo built-in typedef type (set by Sema).
96  QualType ObjCSelType;
97  const RecordType *SelStructType;
98
99  /// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
100  QualType ObjCProtoType;
101  const RecordType *ProtoStructType;
102
103  /// ObjCClassType - another pseudo built-in typedef type (set by Sema).
104  QualType ObjCClassType;
105  const RecordType *ClassStructType;
106
107  QualType ObjCConstantStringType;
108  RecordDecl *CFConstantStringTypeDecl;
109
110  RecordDecl *ObjCFastEnumerationStateTypeDecl;
111
112  TranslationUnitDecl *TUDecl;
113
114  /// SourceMgr - The associated SourceManager object.
115  SourceManager &SourceMgr;
116
117  /// LangOpts - The language options used to create the AST associated with
118  ///  this ASTContext object.
119  LangOptions LangOpts;
120
121  /// Allocator - The allocator object used to create AST objects.
122  llvm::MallocAllocator Allocator;
123
124public:
125  TargetInfo &Target;
126  IdentifierTable &Idents;
127  SelectorTable &Selectors;
128  DeclarationNameTable DeclarationNames;
129
130  SourceManager& getSourceManager() { return SourceMgr; }
131  llvm::MallocAllocator &getAllocator() { return Allocator; }
132  void Deallocate(void *Ptr) { Allocator.Deallocate(Ptr); }
133
134  const LangOptions& getLangOptions() const { return LangOpts; }
135
136  FullSourceLoc getFullLoc(SourceLocation Loc) const {
137    return FullSourceLoc(Loc,SourceMgr);
138  }
139
140  TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
141
142  /// This is intentionally not serialized.  It is populated by the
143  /// ASTContext ctor, and there are no external pointers/references to
144  /// internal variables of BuiltinInfo.
145  Builtin::Context BuiltinInfo;
146
147  // Builtin Types.
148  QualType VoidTy;
149  QualType BoolTy;
150  QualType CharTy;
151  QualType WCharTy; // [C++ 3.9.1p5]
152  QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy;
153  QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
154  QualType UnsignedLongLongTy;
155  QualType FloatTy, DoubleTy, LongDoubleTy;
156  QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
157  QualType VoidPtrTy;
158  QualType OverloadTy;
159  QualType DependentTy;
160
161  ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
162             IdentifierTable &idents, SelectorTable &sels,
163             unsigned size_reserve=0);
164
165  ~ASTContext();
166
167  void PrintStats() const;
168  const std::vector<Type*>& getTypes() const { return Types; }
169
170  //===--------------------------------------------------------------------===//
171  //                           Type Constructors
172  //===--------------------------------------------------------------------===//
173
174  /// getASQualType - Return the uniqued reference to the type for an address
175  /// space qualified type with the specified type and address space.  The
176  /// resulting type has a union of the qualifiers from T and the address space.
177  // If T already has an address space specifier, it is silently replaced.
178  QualType getASQualType(QualType T, unsigned AddressSpace);
179
180  /// getComplexType - Return the uniqued reference to the type for a complex
181  /// number with the specified element type.
182  QualType getComplexType(QualType T);
183
184  /// getPointerType - Return the uniqued reference to the type for a pointer to
185  /// the specified type.
186  QualType getPointerType(QualType T);
187
188  /// getBlockPointerType - Return the uniqued reference to the type for a block
189  /// of the specified type.
190  QualType getBlockPointerType(QualType T);
191
192  /// getReferenceType - Return the uniqued reference to the type for a
193  /// reference to the specified type.
194  QualType getReferenceType(QualType T);
195
196  /// getMemberPointerType - Return the uniqued reference to the type for a
197  /// member pointer to the specified type in the specified class. The class
198  /// is a Type because it could be a dependent name.
199  QualType getMemberPointerType(QualType T, const Type *Cls);
200
201  /// getVariableArrayType - Returns a non-unique reference to the type for a
202  /// variable array of the specified element type.
203  QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
204                                ArrayType::ArraySizeModifier ASM,
205                                unsigned EltTypeQuals);
206
207  /// getDependentSizedArrayType - Returns a non-unique reference to
208  /// the type for a dependently-sized array of the specified element
209  /// type. FIXME: We will need these to be uniqued, or at least
210  /// comparable, at some point.
211  QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
212                                      ArrayType::ArraySizeModifier ASM,
213                                      unsigned EltTypeQuals);
214
215  /// getIncompleteArrayType - Returns a unique reference to the type for a
216  /// incomplete array of the specified element type.
217  QualType getIncompleteArrayType(QualType EltTy,
218                                  ArrayType::ArraySizeModifier ASM,
219                                  unsigned EltTypeQuals);
220
221  /// getConstantArrayType - Return the unique reference to the type for a
222  /// constant array of the specified element type.
223  QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
224                                ArrayType::ArraySizeModifier ASM,
225                                unsigned EltTypeQuals);
226
227  /// getVectorType - Return the unique reference to a vector type of
228  /// the specified element type and size. VectorType must be a built-in type.
229  QualType getVectorType(QualType VectorType, unsigned NumElts);
230
231  /// getExtVectorType - Return the unique reference to an extended vector type
232  /// of the specified element type and size.  VectorType must be a built-in
233  /// type.
234  QualType getExtVectorType(QualType VectorType, unsigned NumElts);
235
236  /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'.
237  ///
238  QualType getFunctionTypeNoProto(QualType ResultTy);
239
240  /// getFunctionType - Return a normal function type with a typed argument
241  /// list.  isVariadic indicates whether the argument list includes '...'.
242  QualType getFunctionType(QualType ResultTy, const QualType *ArgArray,
243                           unsigned NumArgs, bool isVariadic,
244                           unsigned TypeQuals);
245
246  /// getTypeDeclType - Return the unique reference to the type for
247  /// the specified type declaration.
248  QualType getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl=0);
249
250  /// getTypedefType - Return the unique reference to the type for the
251  /// specified typename decl.
252  QualType getTypedefType(TypedefDecl *Decl);
253  QualType getTemplateTypeParmType(TemplateTypeParmDecl *Decl);
254  QualType getObjCInterfaceType(ObjCInterfaceDecl *Decl);
255
256  /// getObjCQualifiedInterfaceType - Return a
257  /// ObjCQualifiedInterfaceType type for the given interface decl and
258  /// the conforming protocol list.
259  QualType getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl,
260             ObjCProtocolDecl **ProtocolList, unsigned NumProtocols);
261
262  /// getObjCQualifiedIdType - Return an ObjCQualifiedIdType for a
263  /// given 'id' and conforming protocol list.
264  QualType getObjCQualifiedIdType(ObjCProtocolDecl **ProtocolList,
265                                  unsigned NumProtocols);
266
267
268  /// getTypeOfType - GCC extension.
269  QualType getTypeOfExpr(Expr *e);
270  QualType getTypeOfType(QualType t);
271
272  /// getTagDeclType - Return the unique reference to the type for the
273  /// specified TagDecl (struct/union/class/enum) decl.
274  QualType getTagDeclType(TagDecl *Decl);
275
276  /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
277  /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
278  QualType getSizeType() const;
279
280  /// getWCharType - Return the unique type for "wchar_t" (C99 7.17), defined
281  /// in <stddef.h>. Wide strings require this (C99 6.4.5p5).
282  QualType getWCharType() const;
283
284  /// getSignedWCharType - Return the type of "signed wchar_t".
285  /// Used when in C++, as a GCC extension.
286  QualType getSignedWCharType() const;
287
288  /// getUnsignedWCharType - Return the type of "unsigned wchar_t".
289  /// Used when in C++, as a GCC extension.
290  QualType getUnsignedWCharType() const;
291
292  /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
293  /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
294  QualType getPointerDiffType() const;
295
296  // getCFConstantStringType - Return the C structure type used to represent
297  // constant CFStrings.
298  QualType getCFConstantStringType();
299
300  // This setter/getter represents the ObjC type for an NSConstantString.
301  void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
302  QualType getObjCConstantStringInterface() const {
303    return ObjCConstantStringType;
304  }
305
306  //// This gets the struct used to keep track of fast enumerations.
307  QualType getObjCFastEnumerationStateType();
308
309  /// getObjCEncodingForType - Emit the ObjC type encoding for the
310  /// given type into \arg S. If \arg NameFields is specified then
311  /// record field names are also encoded.
312  void getObjCEncodingForType(QualType t, std::string &S,
313                              FieldDecl *Field=NULL) const;
314
315  void getLegacyIntegralTypeEncoding(QualType &t) const;
316
317  // Put the string version of type qualifiers into S.
318  void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
319                                       std::string &S) const;
320
321  /// getObjCEncodingForMethodDecl - Return the encoded type for this method
322  /// declaration.
323  void getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S);
324
325  /// getObjCEncodingForPropertyDecl - Return the encoded type for
326  /// this method declaration. If non-NULL, Container must be either
327  /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
328  /// only be NULL when getting encodings for protocol properties.
329  void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
330                                      const Decl *Container,
331                                      std::string &S);
332
333  /// getObjCEncodingTypeSize returns size of type for objective-c encoding
334  /// purpose.
335  int getObjCEncodingTypeSize(QualType t);
336
337  /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by
338  /// Sema.  id is always a (typedef for a) pointer type, a pointer to a struct.
339  QualType getObjCIdType() const { return ObjCIdType; }
340  void setObjCIdType(TypedefDecl *Decl);
341
342  void setObjCSelType(TypedefDecl *Decl);
343  QualType getObjCSelType() const { return ObjCSelType; }
344
345  void setObjCProtoType(QualType QT);
346  QualType getObjCProtoType() const { return ObjCProtoType; }
347
348  /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
349  /// Sema.  'Class' is always a (typedef for a) pointer type, a pointer to a
350  /// struct.
351  QualType getObjCClassType() const { return ObjCClassType; }
352  void setObjCClassType(TypedefDecl *Decl);
353
354  void setBuiltinVaListType(QualType T);
355  QualType getBuiltinVaListType() const { return BuiltinVaListType; }
356
357private:
358  QualType getFromTargetType(unsigned Type) const;
359
360  //===--------------------------------------------------------------------===//
361  //                         Type Predicates.
362  //===--------------------------------------------------------------------===//
363
364public:
365  /// isObjCObjectPointerType - Returns true if type is an Objective-C pointer
366  /// to an object type.  This includes "id" and "Class" (two 'special' pointers
367  /// to struct), Interface* (pointer to ObjCInterfaceType) and id<P> (qualified
368  /// ID type).
369  bool isObjCObjectPointerType(QualType Ty) const;
370
371  /// isObjCNSObjectType - Return true if this is an NSObject object with
372  /// its NSObject attribute set.
373  bool isObjCNSObjectType(QualType Ty) const;
374
375  //===--------------------------------------------------------------------===//
376  //                         Type Sizing and Analysis
377  //===--------------------------------------------------------------------===//
378
379  /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified
380  /// scalar floating point type.
381  const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
382
383  /// getTypeInfo - Get the size and alignment of the specified complete type in
384  /// bits.
385  std::pair<uint64_t, unsigned> getTypeInfo(const Type *T);
386  std::pair<uint64_t, unsigned> getTypeInfo(QualType T) {
387    return getTypeInfo(T.getTypePtr());
388  }
389
390  /// getTypeSize - Return the size of the specified type, in bits.  This method
391  /// does not work on incomplete types.
392  uint64_t getTypeSize(QualType T) {
393    return getTypeInfo(T).first;
394  }
395  uint64_t getTypeSize(const Type *T) {
396    return getTypeInfo(T).first;
397  }
398
399  /// getTypeAlign - Return the ABI-specified alignment of a type, in bits.
400  /// This method does not work on incomplete types.
401  unsigned getTypeAlign(QualType T) {
402    return getTypeInfo(T).second;
403  }
404  unsigned getTypeAlign(const Type *T) {
405    return getTypeInfo(T).second;
406  }
407
408  /// getPreferredTypeAlign - Return the "preferred" alignment of the specified
409  /// type for the current target in bits.  This can be different than the ABI
410  /// alignment in cases where it is beneficial for performance to overalign
411  /// a data type.
412  unsigned getPreferredTypeAlign(const Type *T);
413
414  /// getDeclAlign - Return the alignment of the specified decl that should be
415  /// returned by __alignof().  Note that bitfields do not have a valid
416  /// alignment, so this method will assert on them.
417  unsigned getDeclAlign(const Decl *D);
418
419  /// getASTRecordLayout - Get or compute information about the layout of the
420  /// specified record (struct/union/class), which indicates its size and field
421  /// position information.
422  const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D);
423
424  const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D);
425  const RecordDecl *addRecordToClass(const ObjCInterfaceDecl *D);
426  const FieldDecl *getFieldDecl(const ObjCIvarRefExpr *MRef) {
427    llvm::DenseMap<const ObjCIvarRefExpr *, const FieldDecl*>::iterator I
428      = ASTFieldForIvarRef.find(MRef);
429    assert (I != ASTFieldForIvarRef.end()  && "Unable to find field_decl");
430    return I->second;
431  }
432  void setFieldDecl(const ObjCInterfaceDecl *OI,
433                    const ObjCIvarDecl *Ivar,
434                    const ObjCIvarRefExpr *MRef);
435  //===--------------------------------------------------------------------===//
436  //                            Type Operators
437  //===--------------------------------------------------------------------===//
438
439  /// getCanonicalType - Return the canonical (structural) type corresponding to
440  /// the specified potentially non-canonical type.  The non-canonical version
441  /// of a type may have many "decorated" versions of types.  Decorators can
442  /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
443  /// to be free of any of these, allowing two canonical types to be compared
444  /// for exact equality with a simple pointer comparison.
445  QualType getCanonicalType(QualType T);
446  const Type *getCanonicalType(const Type *T) {
447    return T->getCanonicalTypeInternal().getTypePtr();
448  }
449
450  /// Type Query functions.  If the type is an instance of the specified class,
451  /// return the Type pointer for the underlying maximally pretty type.  This
452  /// is a member of ASTContext because this may need to do some amount of
453  /// canonicalization, e.g. to move type qualifiers into the element type.
454  const ArrayType *getAsArrayType(QualType T);
455  const ConstantArrayType *getAsConstantArrayType(QualType T) {
456    return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
457  }
458  const VariableArrayType *getAsVariableArrayType(QualType T) {
459    return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
460  }
461  const IncompleteArrayType *getAsIncompleteArrayType(QualType T) {
462    return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
463  }
464
465  /// getBaseElementType - Returns the innermost element type of a variable
466  /// length array type. For example, will return "int" for int[m][n]
467  QualType getBaseElementType(const VariableArrayType *VAT);
468
469  /// getArrayDecayedType - Return the properly qualified result of decaying the
470  /// specified array type to a pointer.  This operation is non-trivial when
471  /// handling typedefs etc.  The canonical type of "T" must be an array type,
472  /// this returns a pointer to a properly qualified element of the array.
473  ///
474  /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
475  QualType getArrayDecayedType(QualType T);
476
477  /// getIntegerTypeOrder - Returns the highest ranked integer type:
478  /// C99 6.3.1.8p1.  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
479  /// LHS < RHS, return -1.
480  int getIntegerTypeOrder(QualType LHS, QualType RHS);
481
482  /// getFloatingTypeOrder - Compare the rank of the two specified floating
483  /// point types, ignoring the domain of the type (i.e. 'double' ==
484  /// '_Complex double').  If LHS > RHS, return 1.  If LHS == RHS, return 0. If
485  /// LHS < RHS, return -1.
486  int getFloatingTypeOrder(QualType LHS, QualType RHS);
487
488  /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
489  /// point or a complex type (based on typeDomain/typeSize).
490  /// 'typeDomain' is a real floating point or complex type.
491  /// 'typeSize' is a real floating point or complex type.
492  QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
493                                             QualType typeDomain) const;
494
495  //===--------------------------------------------------------------------===//
496  //                    Type Compatibility Predicates
497  //===--------------------------------------------------------------------===//
498
499  /// Compatibility predicates used to check assignment expressions.
500  bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
501  bool typesAreBlockCompatible(QualType lhs, QualType rhs);
502
503  bool isObjCIdType(QualType T) const {
504    if (!IdStructType) // ObjC isn't enabled
505      return false;
506    return T->getAsStructureType() == IdStructType;
507  }
508  bool isObjCClassType(QualType T) const {
509    if (!ClassStructType) // ObjC isn't enabled
510      return false;
511    return T->getAsStructureType() == ClassStructType;
512  }
513  bool isObjCSelType(QualType T) const {
514    assert(SelStructType && "isObjCSelType used before 'SEL' type is built");
515    return T->getAsStructureType() == SelStructType;
516  }
517
518  // Check the safety of assignment from LHS to RHS
519  bool canAssignObjCInterfaces(const ObjCInterfaceType *LHS,
520                               const ObjCInterfaceType *RHS);
521
522  // Functions for calculating composite types
523  QualType mergeTypes(QualType, QualType);
524  QualType mergeFunctionTypes(QualType, QualType);
525
526  //===--------------------------------------------------------------------===//
527  //                    Integer Predicates
528  //===--------------------------------------------------------------------===//
529
530  // The width of an integer, as defined in C99 6.2.6.2. This is the number
531  // of bits in an integer type excluding any padding bits.
532  unsigned getIntWidth(QualType T);
533
534  // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
535  // unsigned integer type.  This method takes a signed type, and returns the
536  // corresponding unsigned integer type.
537  QualType getCorrespondingUnsignedType(QualType T);
538
539  //===--------------------------------------------------------------------===//
540  //                    Type Iterators.
541  //===--------------------------------------------------------------------===//
542
543  typedef std::vector<Type*>::iterator       type_iterator;
544  typedef std::vector<Type*>::const_iterator const_type_iterator;
545
546  type_iterator types_begin() { return Types.begin(); }
547  type_iterator types_end() { return Types.end(); }
548  const_type_iterator types_begin() const { return Types.begin(); }
549  const_type_iterator types_end() const { return Types.end(); }
550
551  //===--------------------------------------------------------------------===//
552  //                    Serialization
553  //===--------------------------------------------------------------------===//
554
555  void Emit(llvm::Serializer& S) const;
556  static ASTContext* Create(llvm::Deserializer& D);
557
558private:
559  ASTContext(const ASTContext&); // DO NOT IMPLEMENT
560  void operator=(const ASTContext&); // DO NOT IMPLEMENT
561
562  void InitBuiltinTypes();
563  void InitBuiltinType(QualType &R, BuiltinType::Kind K);
564
565  // Return the ObjC type encoding for a given type.
566  void getObjCEncodingForTypeImpl(QualType t, std::string &S,
567                                  bool ExpandPointedToStructures,
568                                  bool ExpandStructures,
569                                  FieldDecl *Field,
570                                  bool OutermostType = false,
571                                  bool EncodingProperty = false) const;
572
573};
574
575}  // end namespace clang
576
577// operator new and delete aren't allowed inside namespaces.
578// The throw specifications are mandated by the standard.
579/// @brief Placement new for using the ASTContext's allocator.
580///
581/// This placement form of operator new uses the ASTContext's allocator for
582/// obtaining memory. It is a non-throwing new, which means that it returns
583/// null on error. (If that is what the allocator does. The current does, so if
584/// this ever changes, this operator will have to be changed, too.)
585/// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
586/// @code
587/// // Default alignment (16)
588/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
589/// // Specific alignment
590/// IntegerLiteral *Ex2 = new (Context, 8) IntegerLiteral(arguments);
591/// @endcode
592/// Please note that you cannot use delete on the pointer; it must be
593/// deallocated using an explicit destructor call followed by
594/// @c Context.getAllocator().Deallocate(Ptr)
595///
596/// @param Bytes The number of bytes to allocate. Calculated by the compiler.
597/// @param C The ASTContext that provides the allocator.
598/// @param Alignment The alignment of the allocated memory (if the allocator
599///                  supports it, which the current one doesn't).
600/// @return The allocated memory. Could be NULL.
601inline void *operator new(size_t Bytes, clang::ASTContext &C,
602                          size_t Alignment = 16) throw () {
603  return C.getAllocator().Allocate(Bytes, Alignment);
604}
605/// @brief Placement delete companion to the new above.
606///
607/// This operator is just a companion to the new above. There is no way of
608/// invoking it directly; see the new operator for more details. This operator
609/// is called implicitly by the compiler if a placement new expression using
610/// the ASTContext throws in the object constructor.
611inline void operator delete(void *Ptr, clang::ASTContext &C)
612              throw () {
613  C.getAllocator().Deallocate(Ptr);
614}
615
616#endif
617