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