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