ASTContext.h revision ca1bdd7c269a2390d43c040a60511edd017ee130
106a59bb8260ce3d52de761865dee90f90054a5ccSebastian Redl//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===//
2aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//
3aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//                     The LLVM Compiler Infrastructure
4aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//
5aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// This file is distributed under the University of Illinois Open Source
6aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// License. See LICENSE.TXT for details.
7aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//
8aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//===----------------------------------------------------------------------===//
9aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//
10aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//  This file defines the ASTContext interface.
11aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//
12aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//===----------------------------------------------------------------------===//
13aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor
14aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#ifndef LLVM_CLANG_AST_ASTCONTEXT_H
15aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#define LLVM_CLANG_AST_ASTCONTEXT_H
1655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
17b95cc97b2023d00cd3fbae8455bc9d728eab5e5dDouglas Gregor#include "clang/Basic/IdentifierTable.h"
18aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/Basic/LangOptions.h"
19833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall#include "clang/Basic/OperatorKinds.h"
20bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis#include "clang/AST/Attr.h"
21aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/Decl.h"
22aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
23910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor#include "clang/AST/PrettyPrinter.h"
24aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/TemplateName.h"
25aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/Type.h"
26aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/CanonicalType.h"
27aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "llvm/ADT/DenseMap.h"
28aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "llvm/ADT/FoldingSet.h"
29aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "llvm/ADT/OwningPtr.h"
30ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor#include "llvm/Support/Allocator.h"
31ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor#include <vector>
32bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor
33ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregornamespace llvm {
34ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  struct fltSemantics;
35ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor}
36aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor
37aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregornamespace clang {
38aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class FileManager;
39aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class ASTRecordLayout;
40aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class Expr;
414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  class ExternalASTSource;
42bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor  class IdentifierTable;
43ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  class SelectorTable;
44bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor  class SourceManager;
45bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor  class TargetInfo;
46aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  // Decls
47aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class Decl;
481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  class FieldDecl;
49ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  class ObjCIvarDecl;
50aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class ObjCIvarRefExpr;
51aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class ObjCPropertyDecl;
5262cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  class RecordDecl;
5362cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  class TagDecl;
541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  class TemplateTypeParmDecl;
5562cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  class TranslationUnitDecl;
5662cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  class TypeDecl;
5762cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  class TypedefDecl;
581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  class UnresolvedUsingDecl;
590ceffb51b28b09db67404058c642dcb1f877f6e8Anders Carlsson  class UsingDecl;
601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6162cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  namespace Builtin { class Context; }
6262cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor
6362cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor/// ASTContext - This class holds long-lived AST nodes (such as types and
6462cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor/// decls) that can be referred to throughout the semantic analysis of a file.
6562cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregorclass ASTContext {
6662cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  std::vector<Type*> Types;
671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  llvm::FoldingSet<ExtQuals> ExtQualNodes;
6862cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  llvm::FoldingSet<ComplexType> ComplexTypes;
6962cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  llvm::FoldingSet<PointerType> PointerTypes;
7062cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
7162cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
7262cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
7362cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor  llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
74ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
75ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
76ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  std::vector<VariableArrayType*> VariableArrayTypes;
77ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
78ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<DependentSizedExtVectorType> DependentSizedExtVectorTypes;
79ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<VectorType> VectorTypes;
80ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
81ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<FunctionProtoType> FunctionProtoTypes;
82ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
83ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
84ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
85ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<SubstTemplateTypeParmType> SubstTemplateTypeParmTypes;
86ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<TemplateSpecializationType> TemplateSpecializationTypes;
87ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<QualifiedNameType> QualifiedNameTypes;
88ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  llvm::FoldingSet<TypenameType> TypenameTypes;
89aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  llvm::FoldingSet<ObjCInterfaceType> ObjCInterfaceTypes;
909eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
919eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
929eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne
939eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
949eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
959eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne
969eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  /// \brief The set of nested name specifiers.
979eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  ///
986b5415196327fa8ef00f028ba175fafef1738ae1Argyrios Kyrtzidis  /// This set is managed by the NestedNameSpecifier class.
999eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
1008a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  NestedNameSpecifier *GlobalNestedNameSpecifier;
1019eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  friend class NestedNameSpecifier;
1029eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne
1039eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
1049eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  ///  This is lazily created.  This is intentionally not serialized.
1059eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> ASTRecordLayouts;
1069eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*> ObjCLayouts;
1079eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne
1089eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  /// \brief Mapping from ObjCContainers to their ObjCImplementations.
1099eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
1109eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne
1119eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::DenseMap<unsigned, FixedWidthIntType*> SignedFixedWidthIntTypes;
1129eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  llvm::DenseMap<unsigned, FixedWidthIntType*> UnsignedFixedWidthIntTypes;
1138a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne
1148a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  /// BuiltinVaListType - built-in va list type.
1158a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  /// This is initially null and set by Sema::LazilyCreateBuiltin when
1168a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  /// a builtin that takes a valist is encountered.
1178a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  QualType BuiltinVaListType;
1188a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne
1198a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  /// ObjCIdType - a pseudo built-in typedef type (set by Sema).
1208a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  QualType ObjCIdTypedefType;
1218a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne
1228a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  /// ObjCSelType - another pseudo built-in typedef type (set by Sema).
1238a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  QualType ObjCSelType;
1248a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne  const RecordType *SelStructType;
125f88718ea0ca0d64b7fd31d109f1d9ec769a9c45fPeter Collingbourne
126f88718ea0ca0d64b7fd31d109f1d9ec769a9c45fPeter Collingbourne  /// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
127f88718ea0ca0d64b7fd31d109f1d9ec769a9c45fPeter Collingbourne  QualType ObjCProtoType;
128f88718ea0ca0d64b7fd31d109f1d9ec769a9c45fPeter Collingbourne  const RecordType *ProtoStructType;
129f88718ea0ca0d64b7fd31d109f1d9ec769a9c45fPeter Collingbourne
130f88718ea0ca0d64b7fd31d109f1d9ec769a9c45fPeter Collingbourne  /// ObjCClassType - another pseudo built-in typedef type (set by Sema).
131f88718ea0ca0d64b7fd31d109f1d9ec769a9c45fPeter Collingbourne  QualType ObjCClassTypedefType;
1324048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne
1334048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  QualType ObjCConstantStringType;
1344048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  RecordDecl *CFConstantStringTypeDecl;
1354048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne
1364048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  RecordDecl *ObjCFastEnumerationStateTypeDecl;
1374048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne
1384048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  /// \brief The type for the C FILE type.
1394048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  TypeDecl *FILEDecl;
1404048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne
1414048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  /// \brief The type for the C jmp_buf type.
1424048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  TypeDecl *jmp_bufDecl;
1434048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne
1444048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  /// \brief The type for the C sigjmp_buf type.
1459eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  TypeDecl *sigjmp_bufDecl;
146aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor
147aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// \brief Type for the Block descriptor for Blocks CodeGen.
148aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  RecordDecl *BlockDescriptorType;
1490054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor
1500054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor  /// \brief Type for the Block descriptor for Blocks CodeGen.
1510054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor  RecordDecl *BlockDescriptorExtendedType;
1520054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor
153aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// \brief Keeps track of all declaration attributes.
154aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  ///
155aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// Since so few decls have attrs, we keep them in a hash map instead of
156aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// wasting space in the Decl class.
157127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor  llvm::DenseMap<const Decl*, Attr*> DeclAttrs;
158aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor
159aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// \brief Keeps track of the static data member templates from which
160aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// static data members of class template specializations were instantiated.
161aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  ///
1626b5415196327fa8ef00f028ba175fafef1738ae1Argyrios Kyrtzidis  /// This data structure stores the mapping from instantiations of static
1636b5415196327fa8ef00f028ba175fafef1738ae1Argyrios Kyrtzidis  /// data members to the static data member representations within the
1646b5415196327fa8ef00f028ba175fafef1738ae1Argyrios Kyrtzidis  /// class template from which they were instantiated along with the kind
1656b5415196327fa8ef00f028ba175fafef1738ae1Argyrios Kyrtzidis  /// of instantiation or specialization (a TemplateSpecializationKind - 1).
1669eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  ///
1679eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  /// Given the following example:
1689eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  ///
1692c853e401ca406d417eb916e867226050e7be06bArgyrios Kyrtzidis  /// \code
1702c853e401ca406d417eb916e867226050e7be06bArgyrios Kyrtzidis  /// template<typename T>
1712c853e401ca406d417eb916e867226050e7be06bArgyrios Kyrtzidis  /// struct X {
1724048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  ///   static T value;
1732c853e401ca406d417eb916e867226050e7be06bArgyrios Kyrtzidis  /// };
1742c853e401ca406d417eb916e867226050e7be06bArgyrios Kyrtzidis  ///
175aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// template<typename T>
176aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  ///   T X<T>::value = T(17);
177aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  ///
178aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// int *x = &X<int>::value;
1790054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor  /// \endcode
1800054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor  ///
1810054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor  /// This mapping will contain an entry that maps from the VarDecl for
1820054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor  /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
1838731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// class template X) and will be marked TSK_ImplicitInstantiation.
1848731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *>
1858731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis    InstantiatedFromStaticDataMember;
1868731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
1878731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Keeps track of the UnresolvedUsingDecls from which UsingDecls
1888731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// where created during instantiation.
1898731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  ///
1908731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// For example:
1915bf1bdc2fedb0c29b5fcdb4abc852aa85b4fe26aArgyrios Kyrtzidis  /// \code
1928731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// template<typename T>
1935953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// struct A {
1945953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  ///   void f();
195c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// };
196c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  ///
197c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// template<typename T>
198c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// struct B : A<T> {
199c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  ///   using A<T>::f;
200c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// };
201c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  ///
202c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// template struct B<int>;
203c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// \endcode
204c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  ///
205c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// This mapping will contain an entry that maps from the UsingDecl in
206c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// B<int> to the UnresolvedUsingDecl in B<T>.
207c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  llvm::DenseMap<UsingDecl *, UnresolvedUsingDecl *>
208c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor    InstantiatedFromUnresolvedUsingDecl;
209c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor
210c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
211c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor
212c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  TranslationUnitDecl *TUDecl;
213c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor
214c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// SourceMgr - The associated SourceManager object.
215c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  SourceManager &SourceMgr;
216c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor
217c8e5cf8f725e111965debb7130ef7466c0c73884Douglas Gregor  /// LangOpts - The language options used to create the AST associated with
2186b5415196327fa8ef00f028ba175fafef1738ae1Argyrios Kyrtzidis  ///  this ASTContext object.
2196b5415196327fa8ef00f028ba175fafef1738ae1Argyrios Kyrtzidis  LangOptions LangOpts;
2206b5415196327fa8ef00f028ba175fafef1738ae1Argyrios Kyrtzidis
2216b5415196327fa8ef00f028ba175fafef1738ae1Argyrios Kyrtzidis  /// \brief Whether we have already loaded comment source ranges from an
2229eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  /// external source.
2239eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne  bool LoadedExternalComments;
2249eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne
225cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  /// MallocAlloc/BumpAlloc - The allocator objects used to create AST objects.
226cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  bool FreeMemory;
227cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  llvm::MallocAllocator MallocAlloc;
2284048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  llvm::BumpPtrAllocator BumpAlloc;
229cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis
230cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  /// \brief Mapping from declarations to their comments, once we have
231bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  /// already looked up the comment associated with a given declaration.
232bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  llvm::DenseMap<const Decl *, std::string> DeclComments;
233bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis
234bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidispublic:
235bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  TargetInfo &Target;
236bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  IdentifierTable &Idents;
237bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  SelectorTable &Selectors;
238cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  Builtin::Context &BuiltinInfo;
239cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  DeclarationNameTable DeclarationNames;
240cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  llvm::OwningPtr<ExternalASTSource> ExternalSource;
241cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  clang::PrintingPolicy PrintingPolicy;
2424048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne
2434048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne  // Typedefs which may be provided defining the structure of Objective-C
244cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  // pseudo-builtins
245cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  QualType ObjCIdRedefinitionType;
246bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  QualType ObjCClassRedefinitionType;
247bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis
248bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  /// \brief Source ranges for all of the comments in the source file,
249bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  /// sorted in order of appearance in the translation unit.
250bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  std::vector<SourceRange> Comments;
251bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis
252bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  SourceManager& getSourceManager() { return SourceMgr; }
253bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis  const SourceManager& getSourceManager() const { return SourceMgr; }
254dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor  void *Allocate(unsigned Size, unsigned Align = 8) {
255dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor    return FreeMemory ? MallocAlloc.Allocate(Size, Align) :
256dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor                        BumpAlloc.Allocate(Size, Align);
2575bf1bdc2fedb0c29b5fcdb4abc852aa85b4fe26aArgyrios Kyrtzidis  }
258dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor  void Deallocate(void *Ptr) {
259dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor    if (FreeMemory)
260dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor      MallocAlloc.Deallocate(Ptr);
261dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor  }
262dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor  const LangOptions& getLangOptions() const { return LangOpts; }
263dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor
264cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  FullSourceLoc getFullLoc(SourceLocation Loc) const {
265dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor    return FullSourceLoc(Loc,SourceMgr);
266dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor  }
267dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor
268b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor  /// \brief Retrieve the attributes for the given declaration.
269b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor  Attr*& getDeclAttrs(const Decl *D) { return DeclAttrs[D]; }
270b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor
271b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor  /// \brief Erase the attributes corresponding to the given declaration.
272b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor  void eraseDeclAttrs(const Decl *D) { DeclAttrs.erase(D); }
273b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor
274b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor  /// \brief If this variable is an instantiated static data member of a
275b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor  /// class template specialization, returns the templated static data member
27631f17ecbef57b5679c017c375db330546b7b5145John McCall  /// from which it was instantiated.
277cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
278cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis                                                           const VarDecl *Var);
279cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis
280cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  /// \brief Note that the static data member \p Inst is an instantiation of
281cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  /// the static data member template \p Tmpl of a class template.
282cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
283cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis                                           TemplateSpecializationKind TSK);
284cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis
285cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  /// \brief If this using decl is instantiated from an unresolved using decl,
286cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  /// return it.
287cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  UnresolvedUsingDecl *getInstantiatedFromUnresolvedUsingDecl(UsingDecl *UUD);
288cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis
289cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  /// \brief Note that the using decl \p Inst is an instantiation of
290cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  /// the unresolved using decl \p Tmpl of a class template.
291cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis  void setInstantiatedFromUnresolvedUsingDecl(UsingDecl *Inst,
292cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis                                              UnresolvedUsingDecl *Tmpl);
293b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor
2941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
295b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor  FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
296b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor
297b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor  void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
2983cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
29924bae92f08ae098cc50a602d8cf1273b423e14daDouglas Gregor  TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
3005bf1bdc2fedb0c29b5fcdb4abc852aa85b4fe26aArgyrios Kyrtzidis
3017da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor
3027da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  const char *getCommentForDecl(const Decl *D);
3037da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor
304b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  // Builtin Types.
305b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  CanQualType VoidTy;
306b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  CanQualType BoolTy;
307b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  CanQualType CharTy;
308b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  CanQualType WCharTy;  // [C++ 3.9.1p5], integer type in C99.
309b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
310b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
31124bae92f08ae098cc50a602d8cf1273b423e14daDouglas Gregor  CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
3127da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
3137da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
3147da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  CanQualType FloatTy, DoubleTy, LongDoubleTy;
3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
3161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CanQualType VoidPtrTy, NullPtrTy;
3177da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  CanQualType OverloadTy;
318b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  CanQualType DependentTy;
319b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  CanQualType UndeducedAutoTy;
320b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy;
321b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor
322b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
323b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor             IdentifierTable &idents, SelectorTable &sels,
324b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor             Builtin::Context &builtins,
3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump             bool FreeMemory = true, unsigned size_reserve=0);
3267da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor
327b7de181d912690958e82c01f1b3d752d3d4ab43bChandler Carruth  ~ASTContext();
3286398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor
329f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// \brief Attach an external AST source to the AST context.
3300da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  ///
331b95cc97b2023d00cd3fbae8455bc9d728eab5e5dDouglas Gregor  /// The external AST source provides the ability to load parts of
332b95cc97b2023d00cd3fbae8455bc9d728eab5e5dDouglas Gregor  /// the abstract syntax tree as needed from some external storage,
333b95cc97b2023d00cd3fbae8455bc9d728eab5e5dDouglas Gregor  /// e.g., a precompiled header.
334b95cc97b2023d00cd3fbae8455bc9d728eab5e5dDouglas Gregor  void setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source);
335b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor
3361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve a pointer to the external AST source associated
3377da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  /// with this AST context, if any.
338ba68eca7582a62e3e2ff4b0eba1b2b73a6b80895Douglas Gregor  ExternalASTSource *getExternalSource() const { return ExternalSource.get(); }
3397da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor
340b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  void PrintStats() const;
341203e6a322ae29d577acafcb1572a57ec16e1e730Douglas Gregor  const std::vector<Type*>& getTypes() const { return Types; }
342203e6a322ae29d577acafcb1572a57ec16e1e730Douglas Gregor
343b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  //===--------------------------------------------------------------------===//
344b7d09d627c8576b9bc85f44f05befdd44fedc7edDouglas Gregor  //                           Type Constructors
3457da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  //===--------------------------------------------------------------------===//
3467da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor
3477da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregorprivate:
3481275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor  /// getExtQualType - Return a type with extended qualifiers.
3497da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  QualType getExtQualType(const Type *Base, Qualifiers Quals);
3501275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor
3517da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregorpublic:
3527da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  /// getAddSpaceQualType - Return the uniqued reference to the type for an
3537da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  /// address space qualified type with the specified type and address space.
354aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// The resulting type has a union of the qualifiers from T and the address
355aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// space. If T already has an address space specifier, it is silently
356aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// replaced.
357aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace);
358aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor
3594ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  /// getObjCGCQualType - Returns the uniqued reference to the type for an
360aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// objc gc qualified type. The retulting type has a union of the qualifiers
3616d845ae1baf77691bca080e0762a1d45ee017f70Anders Carlsson  /// from T and the gc attribute.
3626d845ae1baf77691bca080e0762a1d45ee017f70Anders Carlsson  QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr);
363efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor
364efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  /// getRestrictType - Returns the uniqued reference to the type for a
365aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// 'restrict' qualified type.  The resulting type has a union of the
366aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// qualifiers from T and 'restrict'.
367b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis  QualType getRestrictType(QualType T) {
3684ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad    return T.withFastQualifiers(Qualifiers::Restrict);
369b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis  }
370b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis
371b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis  /// getVolatileType - Returns the uniqued reference to the type for a
372b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis  /// 'volatile' qualified type.  The resulting type has a union of the
373833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// qualifiers from T and 'volatile'.
374bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  QualType getVolatileType(QualType T);
375833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
376833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// getConstType - Returns the uniqued reference to the type for a
377ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  /// 'const' qualified type.  The resulting type has a union of the
378ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  /// qualifiers from T and 'const'.
379ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  ///
380ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  /// It can be reasonably expected that this will always be
381ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  /// equivalent to calling T.withConst().
382ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  QualType getConstType(QualType T) { return T.withConst(); }
383ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor
384ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor  /// getNoReturnType - Add the noreturn attribute to the given type which must
385aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// be a FunctionType or a pointer to an allowable type or a BlockPointer.
386aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  QualType getNoReturnType(QualType T);
387aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor
388aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// getComplexType - Return the uniqued reference to the type for a complex
389aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// number with the specified element type.
3904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType getComplexType(QualType T);
391aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  CanQualType getComplexType(CanQualType T) {
392aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor    return CanQualType::CreateUnsafe(getComplexType((QualType) T));
39310738d36b150aa65206890c1c845cdba076e4200Douglas Gregor  }
39410738d36b150aa65206890c1c845cdba076e4200Douglas Gregor
39510738d36b150aa65206890c1c845cdba076e4200Douglas Gregor  /// getPointerType - Return the uniqued reference to the type for a pointer to
396aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// the specified type.
397aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  QualType getPointerType(QualType T);
398d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor  CanQualType getPointerType(CanQualType T) {
399d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara    return CanQualType::CreateUnsafe(getPointerType((QualType) T));
400d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara  }
401d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara
402d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor  /// getBlockPointerType - Return the uniqued reference to the type for a block
403d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor  /// of the specified type.
404aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  QualType getBlockPointerType(QualType T);
405aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor
406aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// This gets the struct used to keep track of the descriptor for pointer to
407aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// blocks.
408aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  QualType getBlockDescriptorType();
4094ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
410aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  // Set the type for a Block descriptor type.
41161c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor  void setBlockDescriptorType(QualType T);
412aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  /// Get the BlockDescriptorType type, or NULL if it hasn't yet been built.
41361c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor  QualType getRawBlockdescriptorType() {
41461c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor    if (BlockDescriptorType)
415aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor      return getTagDeclType(BlockDescriptorType);
416aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor    return QualType();
4173e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor  }
4187e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor
4197e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor  /// This gets the struct used to keep track of the extended descriptor for
420910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  /// pointer to blocks.
421910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  QualType getBlockDescriptorExtendedType();
422910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
423910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  // Set the type for a Block descriptor extended type.
424910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  void setBlockDescriptorExtendedType(QualType T);
425910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  /// Get the BlockDescriptorExtendedType type, or NULL if it hasn't yet been
426910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  /// built.
427910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  QualType getRawBlockdescriptorExtendedType() {
428910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    if (BlockDescriptorExtendedType)
429910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor      return getTagDeclType(BlockDescriptorExtendedType);
430910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    return QualType();
431910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  }
43294d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis
43394d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  /// This gets the struct used to keep track of pointer to blocks, complete
4347e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor  /// with captured variables.
4353e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor  QualType getBlockParmType(bool BlockHasCopyDispose,
4363e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor                            llvm::SmallVector<const Expr *, 8> &BDRDs);
4373e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor
43813c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor  /// This builds the struct used for __block variables.
4397e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor  QualType BuildByRefType(const char *DeclName, QualType Ty);
4403e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor
441910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  /// Returns true iff we need copy/dispose helpers for the given type.
442910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  bool BlockRequiresCopying(QualType Ty);
4438e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor
44413c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor  /// getLValueReferenceType - Return the uniqued reference to the type for an
4458e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor  /// lvalue reference to the specified type.
4468e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor  QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true);
4473e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor
448c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara  /// getRValueReferenceType - Return the uniqued reference to the type for an
449910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  /// rvalue reference to the specified type.
4507e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor  QualType getRValueReferenceType(QualType T);
4513e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor
4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getMemberPointerType - Return the uniqued reference to the type for a
45394d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  /// member pointer to the specified type in the specified class. The class
45494d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  /// is a Type because it could be a dependent name.
45594d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  QualType getMemberPointerType(QualType T, const Type *Cls);
45694d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis
45794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  /// getVariableArrayType - Returns a non-unique reference to the type for a
45894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  /// variable array of the specified element type.
4593e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor  QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
46013c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor                                ArrayType::ArraySizeModifier ASM,
4613e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor                                unsigned EltTypeQuals,
4623e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor                                SourceRange Brackets);
463910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
464910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  /// getDependentSizedArrayType - Returns a non-unique reference to
465cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor  /// the type for a dependently-sized array of the specified element
466cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor  /// type. FIXME: We will need these to be uniqued, or at least
4671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// comparable, at some point.
468c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor  QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
46913c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor                                      ArrayType::ArraySizeModifier ASM,
4707e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor                                      unsigned EltTypeQuals,
471910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                      SourceRange Brackets);
4728e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor
473cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor  /// getIncompleteArrayType - Returns a unique reference to the type for a
474cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor  /// incomplete array of the specified element type.
4753e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor  QualType getIncompleteArrayType(QualType EltTy,
476c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor                                  ArrayType::ArraySizeModifier ASM,
47794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis                                  unsigned EltTypeQuals);
478b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis
47994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  /// getConstantArrayType - Return the unique reference to the type for a
48094d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  /// constant array of the specified element type.
48194d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
48294d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis                                ArrayType::ArraySizeModifier ASM,
483136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall                                unsigned EltTypeQuals);
484136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall
485136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall  /// getVectorType - Return the unique reference to a vector type of
486136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall  /// the specified element type and size. VectorType must be a built-in type.
487136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall  QualType getVectorType(QualType VectorType, unsigned NumElts);
488136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall
489136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall  /// getExtVectorType - Return the unique reference to an extended vector type
490136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall  /// of the specified element type and size.  VectorType must be a built-in
491910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  /// type.
492910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor  QualType getExtVectorType(QualType VectorType, unsigned NumElts);
493136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall
494136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall  /// getDependentSizedExtVectorType - Returns a non-unique reference to
495136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall  /// the type for a dependently-sized vector of the specified element
49637d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor  /// type. FIXME: We will need these to be uniqued, or at least
4971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// comparable, at some point.
4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType getDependentSizedExtVectorType(QualType VectorType,
49937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor                                          Expr *SizeExpr,
50037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor                                          SourceLocation AttrLoc);
50137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor
50237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor  /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'.
50337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor  ///
504c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor  QualType getFunctionNoProtoType(QualType ResultTy, bool NoReturn = false);
505c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor
506c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor  /// getFunctionType - Return a normal function type with a typed argument
507c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor  /// list.  isVariadic indicates whether the argument list includes '...'.
508c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor  QualType getFunctionType(QualType ResultTy, const QualType *ArgArray,
50913c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor                           unsigned NumArgs, bool isVariadic,
510c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor                           unsigned TypeQuals, bool hasExceptionSpec = false,
511c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor                           bool hasAnyExceptionSpec = false,
512910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                           unsigned NumExs = 0, const QualType *ExArray = 0,
513910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                           bool NoReturn = false);
514d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
5153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  /// getTypeDeclType - Return the unique reference to the type for
516dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor  /// the specified type declaration.
517dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor  QualType getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl=0);
518d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
519833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// getTypedefType - Return the unique reference to the type for the
520833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// specified typename decl.
521833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  QualType getTypedefType(TypedefDecl *Decl);
522833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
523c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor  QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
52413c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor                                        QualType Replacement);
525c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor
526c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor  QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
527910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                   bool ParameterPack,
528833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                   IdentifierInfo *Name = 0);
529dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor
530dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor  QualType getTemplateSpecializationType(TemplateName T,
531c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor                                         const TemplateArgument *Args,
5323cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         unsigned NumArgs,
5333cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         QualType Canon = QualType());
534c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor
535c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor  QualType getTemplateSpecializationType(TemplateName T,
536dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall                                         const TemplateArgumentLoc *Args,
53794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis                                         unsigned NumArgs,
538b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis                                         QualType Canon = QualType());
539b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis
54094d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  QualType getQualifiedNameType(NestedNameSpecifier *NNS,
54194d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis                                QualType NamedType);
54294d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis  QualType getTypenameType(NestedNameSpecifier *NNS,
543dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall                           const IdentifierInfo *Name,
544dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall                           QualType Canon = QualType());
545dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall  QualType getTypenameType(NestedNameSpecifier *NNS,
546dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall                           const TemplateSpecializationType *TemplateId,
547dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall                           QualType Canon = QualType());
548dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall  QualType getElaboratedType(QualType UnderlyingType,
549dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall                             ElaboratedType::TagKind Tag);
550dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall
551dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall  QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
552dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall                                ObjCProtocolDecl **Protocols = 0,
553dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall                                unsigned NumProtocols = 0);
554dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall
555dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall  /// getObjCObjectPointerType - Return a ObjCObjectPointerType type for the
556dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall  /// given interface decl and the conforming protocol list.
557dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall  QualType getObjCObjectPointerType(QualType OIT,
558554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis                                    ObjCProtocolDecl **ProtocolList = 0,
559554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis                                    unsigned NumProtocols = 0);
560554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis
561554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis  /// getTypeOfType - GCC extension.
562554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis  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