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