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