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