#ifndef LLVM_CLANG_AST_ASTCONTEXT_H
#define LLVM_CLANG_AST_ASTCONTEXT_H
#include "clang/Basic/AddressSpaces.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/OperatorKinds.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/VersionTuple.h"
#include "clang/AST/Decl.h"
#include "clang/AST/LambdaMangleContext.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
#include "clang/AST/CanonicalType.h"
#include "clang/AST/RawCommentList.h"
#include "clang/AST/CommentCommandTraits.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Support/Allocator.h"
#include <vector>
namespace llvm {
struct fltSemantics;
}
namespace clang {
class FileManager;
class ASTRecordLayout;
class BlockExpr;
class CharUnits;
class DiagnosticsEngine;
class Expr;
class ExternalASTSource;
class ASTMutationListener;
class IdentifierTable;
class SelectorTable;
class TargetInfo;
class CXXABI;
class DeclContext;
class CXXConversionDecl;
class CXXMethodDecl;
class CXXRecordDecl;
class Decl;
class FieldDecl;
class MangleContext;
class ObjCIvarDecl;
class ObjCIvarRefExpr;
class ObjCPropertyDecl;
class ParmVarDecl;
class RecordDecl;
class StoredDeclsMap;
class TagDecl;
class TemplateTemplateParmDecl;
class TemplateTypeParmDecl;
class TranslationUnitDecl;
class TypeDecl;
class TypedefNameDecl;
class UsingDecl;
class UsingShadowDecl;
class UnresolvedSetIterator;
namespace Builtin { class Context; }
namespace comments {
class FullComment;
}
class ASTContext : public RefCountedBase<ASTContext> {
ASTContext &this_() { return *this; }
mutable std::vector<Type*> Types;
mutable llvm::FoldingSet<ExtQuals> ExtQualNodes;
mutable llvm::FoldingSet<ComplexType> ComplexTypes;
mutable llvm::FoldingSet<PointerType> PointerTypes;
mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
mutable llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
mutable std::vector<VariableArrayType*> VariableArrayTypes;
mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
mutable llvm::FoldingSet<DependentSizedExtVectorType>
DependentSizedExtVectorTypes;
mutable llvm::FoldingSet<VectorType> VectorTypes;
mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&>
FunctionProtoTypes;
mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
mutable llvm::FoldingSet<SubstTemplateTypeParmType>
SubstTemplateTypeParmTypes;
mutable llvm::FoldingSet<SubstTemplateTypeParmPackType>
SubstTemplateTypeParmPackTypes;
mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
TemplateSpecializationTypes;
mutable llvm::FoldingSet<ParenType> ParenTypes;
mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
mutable llvm::FoldingSet<DependentNameType> DependentNameTypes;
mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType,
ASTContext&>
DependentTemplateSpecializationTypes;
llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
mutable llvm::FoldingSet<AutoType> AutoTypes;
mutable llvm::FoldingSet<AtomicType> AtomicTypes;
llvm::FoldingSet<AttributedType> AttributedTypes;
mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage>
SubstTemplateTemplateParms;
mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage,
ASTContext&>
SubstTemplateTemplateParmPacks;
mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
mutable NestedNameSpecifier *GlobalNestedNameSpecifier;
friend class NestedNameSpecifier;
mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>
ASTRecordLayouts;
mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>
ObjCLayouts;
typedef llvm::DenseMap<const Type*,
std::pair<uint64_t, unsigned> > TypeInfoMap;
mutable TypeInfoMap MemoizedTypeInfo;
llvm::DenseMap<const CXXRecordDecl*, const CXXMethodDecl*> KeyFunctions;
llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls;
llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits;
llvm::DenseMap<const FunctionDecl*, FunctionDecl*>
ClassScopeSpecializationPattern;
class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
TemplateTemplateParmDecl *Parm;
public:
CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm)
: Parm(Parm) { }
TemplateTemplateParmDecl *getParam() const { return Parm; }
void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); }
static void Profile(llvm::FoldingSetNodeID &ID,
TemplateTemplateParmDecl *Parm);
};
mutable llvm::FoldingSet<CanonicalTemplateTemplateParm>
CanonTemplateTemplateParms;
TemplateTemplateParmDecl *
getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const;
mutable TypedefDecl *Int128Decl;
mutable TypedefDecl *UInt128Decl;
mutable TypedefDecl *BuiltinVaListDecl;
mutable TypedefDecl *ObjCIdDecl;
mutable TypedefDecl *ObjCSelDecl;
mutable TypedefDecl *ObjCClassDecl;
mutable ObjCInterfaceDecl *ObjCProtocolClassDecl;
mutable TypedefDecl *BOOLDecl;
QualType ObjCIdRedefinitionType;
QualType ObjCClassRedefinitionType;
QualType ObjCSelRedefinitionType;
QualType ObjCConstantStringType;
mutable RecordDecl *CFConstantStringTypeDecl;
QualType ObjCNSStringType;
TypedefDecl *ObjCInstanceTypeDecl;
TypeDecl *FILEDecl;
TypeDecl *jmp_bufDecl;
TypeDecl *sigjmp_bufDecl;
TypeDecl *ucontext_tDecl;
mutable RecordDecl *BlockDescriptorType;
mutable RecordDecl *BlockDescriptorExtendedType;
FunctionDecl *cudaConfigureCallDecl;
TypeSourceInfo NullTypeSourceInfo;
llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs;
llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *>
InstantiatedFromStaticDataMember;
llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl;
llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
InstantiatedFromUsingShadowDecl;
llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
typedef llvm::TinyPtrVector<const CXXMethodDecl*> CXXMethodVector;
llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
llvm::DenseMap<const DeclContext *, LambdaMangleContext> LambdaMangleContexts;
typedef llvm::DenseMap<const VarDecl *, unsigned> ParameterIndexTable;
ParameterIndexTable ParamIndices;
ImportDecl *FirstLocalImport;
ImportDecl *LastLocalImport;
TranslationUnitDecl *TUDecl;
SourceManager &SourceMgr;
LangOptions &LangOpts;
mutable llvm::BumpPtrAllocator BumpAlloc;
PartialDiagnostic::StorageAllocator DiagAllocator;
OwningPtr<CXXABI> ABI;
CXXABI *createCXXABI(const TargetInfo &T);
const LangAS::Map *AddrSpaceMap;
friend class ASTDeclReader;
friend class ASTReader;
friend class ASTWriter;
friend class CXXRecordDecl;
const TargetInfo *Target;
clang::PrintingPolicy PrintingPolicy;
public:
IdentifierTable &Idents;
SelectorTable &Selectors;
Builtin::Context &BuiltinInfo;
mutable DeclarationNameTable DeclarationNames;
OwningPtr<ExternalASTSource> ExternalSource;
ASTMutationListener *Listener;
const clang::PrintingPolicy &getPrintingPolicy() const {
return PrintingPolicy;
}
void setPrintingPolicy(const clang::PrintingPolicy &Policy) {
PrintingPolicy = Policy;
}
SourceManager& getSourceManager() { return SourceMgr; }
const SourceManager& getSourceManager() const { return SourceMgr; }
llvm::BumpPtrAllocator &getAllocator() const {
return BumpAlloc;
}
void *Allocate(unsigned Size, unsigned Align = 8) const {
return BumpAlloc.Allocate(Size, Align);
}
void Deallocate(void *Ptr) const { }
size_t getASTAllocatedMemory() const {
return BumpAlloc.getTotalMemory();
}
size_t getSideTableAllocatedMemory() const;
PartialDiagnostic::StorageAllocator &getDiagAllocator() {
return DiagAllocator;
}
const TargetInfo &getTargetInfo() const { return *Target; }
const LangOptions& getLangOpts() const { return LangOpts; }
DiagnosticsEngine &getDiagnostics() const;
FullSourceLoc getFullLoc(SourceLocation Loc) const {
return FullSourceLoc(Loc,SourceMgr);
}
RawCommentList Comments;
mutable bool CommentsLoaded;
class RawCommentAndCacheFlags {
public:
enum Kind {
NoCommentInDecl = 0,
FromDecl,
FromRedecl
};
Kind getKind() const LLVM_READONLY {
return Data.getInt();
}
void setKind(Kind K) {
Data.setInt(K);
}
const RawComment *getRaw() const LLVM_READONLY {
return Data.getPointer();
}
void setRaw(const RawComment *RC) {
Data.setPointer(RC);
}
const Decl *getOriginalDecl() const LLVM_READONLY {
return OriginalDecl;
}
void setOriginalDecl(const Decl *Orig) {
OriginalDecl = Orig;
}
private:
llvm::PointerIntPair<const RawComment *, 2, Kind> Data;
const Decl *OriginalDecl;
};
mutable llvm::DenseMap<const Decl *, RawCommentAndCacheFlags> RedeclComments;
mutable llvm::DenseMap<const Decl *, comments::FullComment *> ParsedComments;
RawComment *getRawCommentForDeclNoCache(const Decl *D) const;
public:
RawCommentList &getRawCommentList() {
return Comments;
}
void addComment(const RawComment &RC) {
assert(LangOpts.RetainCommentsFromSystemHeaders ||
!SourceMgr.isInSystemHeader(RC.getSourceRange().getBegin()));
Comments.addComment(RC, BumpAlloc);
}
const RawComment *getRawCommentForAnyRedecl(
const Decl *D,
const Decl **OriginalDecl = NULL) const;
comments::FullComment *getCommentForDecl(const Decl *D,
const Preprocessor *PP) const;
private:
mutable comments::CommandTraits CommentCommandTraits;
public:
comments::CommandTraits &getCommentCommandTraits() const {
return CommentCommandTraits;
}
AttrVec& getDeclAttrs(const Decl *D);
void eraseDeclAttrs(const Decl *D);
MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
const VarDecl *Var);
FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD);
void setClassScopeSpecializationPattern(FunctionDecl *FD,
FunctionDecl *Pattern);
void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
TemplateSpecializationKind TSK,
SourceLocation PointOfInstantiation = SourceLocation());
NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
UsingShadowDecl *Pattern);
UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
bool ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD,
const FieldDecl *LastFD) const;
bool ZeroBitfieldFollowsBitfield(const FieldDecl *FD,
const FieldDecl *LastFD) const;
bool BitfieldFollowsBitfield(const FieldDecl *FD,
const FieldDecl *LastFD) const;
bool NonBitfieldFollowsBitfield(const FieldDecl *FD,
const FieldDecl *LastFD) const;
bool BitfieldFollowsNonBitfield(const FieldDecl *FD,
const FieldDecl *LastFD) const;
typedef CXXMethodVector::const_iterator overridden_cxx_method_iterator;
overridden_cxx_method_iterator
overridden_methods_begin(const CXXMethodDecl *Method) const;
overridden_cxx_method_iterator
overridden_methods_end(const CXXMethodDecl *Method) const;
unsigned overridden_methods_size(const CXXMethodDecl *Method) const;
void addOverriddenMethod(const CXXMethodDecl *Method,
const CXXMethodDecl *Overridden);
void getOverriddenMethods(const NamedDecl *Method,
SmallVectorImpl<const NamedDecl *> &Overridden);
void addedLocalImportDecl(ImportDecl *Import);
static ImportDecl *getNextLocalImport(ImportDecl *Import) {
return Import->NextLocalImport;
}
class import_iterator {
ImportDecl *Import;
public:
typedef ImportDecl *value_type;
typedef ImportDecl *reference;
typedef ImportDecl *pointer;
typedef int difference_type;
typedef std::forward_iterator_tag iterator_category;
import_iterator() : Import() { }
explicit import_iterator(ImportDecl *Import) : Import(Import) { }
reference operator*() const { return Import; }
pointer operator->() const { return Import; }
import_iterator &operator++() {
Import = ASTContext::getNextLocalImport(Import);
return *this;
}
import_iterator operator++(int) {
import_iterator Other(*this);
++(*this);
return Other;
}
friend bool operator==(import_iterator X, import_iterator Y) {
return X.Import == Y.Import;
}
friend bool operator!=(import_iterator X, import_iterator Y) {
return X.Import != Y.Import;
}
};
import_iterator local_import_begin() const {
return import_iterator(FirstLocalImport);
}
import_iterator local_import_end() const { return import_iterator(); }
TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
CanQualType VoidTy;
CanQualType BoolTy;
CanQualType CharTy;
CanQualType WCharTy; CanQualType WIntTy; CanQualType Char16Ty; CanQualType Char32Ty; CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
CanQualType FloatTy, DoubleTy, LongDoubleTy;
CanQualType HalfTy; CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
CanQualType VoidPtrTy, NullPtrTy;
CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
CanQualType BuiltinFnTy;
CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
CanQualType ObjCBuiltinBoolTy;
mutable QualType AutoDeductTy; mutable QualType AutoRRefDeductTy;
mutable QualType VaListTagTy;
ASTContext(LangOptions& LOpts, SourceManager &SM, const TargetInfo *t,
IdentifierTable &idents, SelectorTable &sels,
Builtin::Context &builtins,
unsigned size_reserve,
bool DelayInitialization = false);
~ASTContext();
void setExternalSource(OwningPtr<ExternalASTSource> &Source);
ExternalASTSource *getExternalSource() const { return ExternalSource.get(); }
void setASTMutationListener(ASTMutationListener *Listener) {
this->Listener = Listener;
}
ASTMutationListener *getASTMutationListener() const { return Listener; }
void PrintStats() const;
const std::vector<Type*>& getTypes() const { return Types; }
TypedefDecl *getInt128Decl() const;
TypedefDecl *getUInt128Decl() const;
private:
QualType getExtQualType(const Type *Base, Qualifiers Quals) const;
QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;
public:
QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const;
QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
QualType getRestrictType(QualType T) const {
return T.withFastQualifiers(Qualifiers::Restrict);
}
QualType getVolatileType(QualType T) const {
return T.withFastQualifiers(Qualifiers::Volatile);
}
QualType getConstType(QualType T) const { return T.withConst(); }
const FunctionType *adjustFunctionType(const FunctionType *Fn,
FunctionType::ExtInfo EInfo);
QualType getComplexType(QualType T) const;
CanQualType getComplexType(CanQualType T) const {
return CanQualType::CreateUnsafe(getComplexType((QualType) T));
}
QualType getPointerType(QualType T) const;
CanQualType getPointerType(CanQualType T) const {
return CanQualType::CreateUnsafe(getPointerType((QualType) T));
}
QualType getAtomicType(QualType T) const;
QualType getBlockPointerType(QualType T) const;
QualType getBlockDescriptorType() const;
QualType getBlockDescriptorExtendedType() const;
void setcudaConfigureCallDecl(FunctionDecl *FD) {
cudaConfigureCallDecl = FD;
}
FunctionDecl *getcudaConfigureCallDecl() {
return cudaConfigureCallDecl;
}
QualType BuildByRefType(StringRef DeclName, QualType Ty) const;
bool BlockRequiresCopying(QualType Ty) const;
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true)
const;
QualType getRValueReferenceType(QualType T) const;
QualType getMemberPointerType(QualType T, const Type *Cls) const;
QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
ArrayType::ArraySizeModifier ASM,
unsigned IndexTypeQuals,
SourceRange Brackets) const;
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
ArrayType::ArraySizeModifier ASM,
unsigned IndexTypeQuals,
SourceRange Brackets) const;
QualType getIncompleteArrayType(QualType EltTy,
ArrayType::ArraySizeModifier ASM,
unsigned IndexTypeQuals) const;
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
ArrayType::ArraySizeModifier ASM,
unsigned IndexTypeQuals) const;
QualType getVariableArrayDecayedType(QualType Ty) const;
QualType getVectorType(QualType VectorType, unsigned NumElts,
VectorType::VectorKind VecKind) const;
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const;
QualType getDependentSizedExtVectorType(QualType VectorType,
Expr *SizeExpr,
SourceLocation AttrLoc) const;
QualType getFunctionNoProtoType(QualType ResultTy,
const FunctionType::ExtInfo &Info) const;
QualType getFunctionNoProtoType(QualType ResultTy) const {
return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo());
}
QualType getFunctionType(QualType ResultTy,
const QualType *Args, unsigned NumArgs,
const FunctionProtoType::ExtProtoInfo &EPI) const;
QualType getTypeDeclType(const TypeDecl *Decl,
const TypeDecl *PrevDecl = 0) const {
assert(Decl && "Passed null for Decl param");
if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
if (PrevDecl) {
assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
Decl->TypeForDecl = PrevDecl->TypeForDecl;
return QualType(PrevDecl->TypeForDecl, 0);
}
return getTypeDeclTypeSlow(Decl);
}
QualType getTypedefType(const TypedefNameDecl *Decl,
QualType Canon = QualType()) const;
QualType getRecordType(const RecordDecl *Decl) const;
QualType getEnumType(const EnumDecl *Decl) const;
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
QualType getAttributedType(AttributedType::Kind attrKind,
QualType modifiedType,
QualType equivalentType);
QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
QualType Replacement) const;
QualType getSubstTemplateTypeParmPackType(
const TemplateTypeParmType *Replaced,
const TemplateArgument &ArgPack);
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
bool ParameterPack,
TemplateTypeParmDecl *ParmDecl = 0) const;
QualType getTemplateSpecializationType(TemplateName T,
const TemplateArgument *Args,
unsigned NumArgs,
QualType Canon = QualType()) const;
QualType getCanonicalTemplateSpecializationType(TemplateName T,
const TemplateArgument *Args,
unsigned NumArgs) const;
QualType getTemplateSpecializationType(TemplateName T,
const TemplateArgumentListInfo &Args,
QualType Canon = QualType()) const;
TypeSourceInfo *
getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc,
const TemplateArgumentListInfo &Args,
QualType Canon = QualType()) const;
QualType getParenType(QualType NamedType) const;
QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *NNS,
QualType NamedType) const;
QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *NNS,
const IdentifierInfo *Name,
QualType Canon = QualType()) const;
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *NNS,
const IdentifierInfo *Name,
const TemplateArgumentListInfo &Args) const;
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *NNS,
const IdentifierInfo *Name,
unsigned NumArgs,
const TemplateArgument *Args) const;
QualType getPackExpansionType(QualType Pattern,
llvm::Optional<unsigned> NumExpansions);
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
ObjCInterfaceDecl *PrevDecl = 0) const;
QualType getObjCObjectType(QualType Base,
ObjCProtocolDecl * const *Protocols,
unsigned NumProtocols) const;
QualType getObjCObjectPointerType(QualType OIT) const;
QualType getTypeOfExprType(Expr *e) const;
QualType getTypeOfType(QualType t) const;
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const;
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType,
UnaryTransformType::UTTKind UKind) const;
QualType getAutoType(QualType DeducedType) const;
QualType getAutoDeductType() const;
QualType getAutoRRefDeductType() const;
QualType getTagDeclType(const TagDecl *Decl) const;
CanQualType getSizeType() const;
CanQualType getIntMaxType() const;
CanQualType getUIntMaxType() const;
QualType getWCharType() const { return WCharTy; }
QualType getSignedWCharType() const;
QualType getUnsignedWCharType() const;
QualType getWIntType() const { return WIntTy; }
QualType getPointerDiffType() const;
QualType getCFConstantStringType() const;
QualType getRawCFConstantStringType() const {
if (CFConstantStringTypeDecl)
return getTagDeclType(CFConstantStringTypeDecl);
return QualType();
}
void setCFConstantStringType(QualType T);
void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
QualType getObjCConstantStringInterface() const {
return ObjCConstantStringType;
}
QualType getObjCNSStringType() const {
return ObjCNSStringType;
}
void setObjCNSStringType(QualType T) {
ObjCNSStringType = T;
}
QualType getObjCIdRedefinitionType() const {
if (ObjCIdRedefinitionType.isNull())
return getObjCIdType();
return ObjCIdRedefinitionType;
}
void setObjCIdRedefinitionType(QualType RedefType) {
ObjCIdRedefinitionType = RedefType;
}
QualType getObjCClassRedefinitionType() const {
if (ObjCClassRedefinitionType.isNull())
return getObjCClassType();
return ObjCClassRedefinitionType;
}
void setObjCClassRedefinitionType(QualType RedefType) {
ObjCClassRedefinitionType = RedefType;
}
QualType getObjCSelRedefinitionType() const {
if (ObjCSelRedefinitionType.isNull())
return getObjCSelType();
return ObjCSelRedefinitionType;
}
void setObjCSelRedefinitionType(QualType RedefType) {
ObjCSelRedefinitionType = RedefType;
}
QualType getObjCInstanceType() {
return getTypeDeclType(getObjCInstanceTypeDecl());
}
TypedefDecl *getObjCInstanceTypeDecl();
void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
QualType getFILEType() const {
if (FILEDecl)
return getTypeDeclType(FILEDecl);
return QualType();
}
void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
this->jmp_bufDecl = jmp_bufDecl;
}
QualType getjmp_bufType() const {
if (jmp_bufDecl)
return getTypeDeclType(jmp_bufDecl);
return QualType();
}
void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
this->sigjmp_bufDecl = sigjmp_bufDecl;
}
QualType getsigjmp_bufType() const {
if (sigjmp_bufDecl)
return getTypeDeclType(sigjmp_bufDecl);
return QualType();
}
void setucontext_tDecl(TypeDecl *ucontext_tDecl) {
this->ucontext_tDecl = ucontext_tDecl;
}
QualType getucontext_tType() const {
if (ucontext_tDecl)
return getTypeDeclType(ucontext_tDecl);
return QualType();
}
QualType getLogicalOperationType() const {
return getLangOpts().CPlusPlus ? BoolTy : IntTy;
}
void getObjCEncodingForType(QualType T, std::string &S,
const FieldDecl *Field=0) const;
void getLegacyIntegralTypeEncoding(QualType &t) const;
void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
std::string &S) const;
bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S);
bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S,
bool Extended = false)
const;
std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
const Decl *Container,
std::string &S) const;
bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
ObjCProtocolDecl *rProto) const;
CharUnits getObjCEncodingTypeSize(QualType T) const;
TypedefDecl *getObjCIdDecl() const;
QualType getObjCIdType() const {
return getTypeDeclType(getObjCIdDecl());
}
TypedefDecl *getObjCSelDecl() const;
QualType getObjCSelType() const {
return getTypeDeclType(getObjCSelDecl());
}
TypedefDecl *getObjCClassDecl() const;
QualType getObjCClassType() const {
return getTypeDeclType(getObjCClassDecl());
}
ObjCInterfaceDecl *getObjCProtocolDecl() const;
TypedefDecl *getBOOLDecl() const {
return BOOLDecl;
}
void setBOOLDecl(TypedefDecl *TD) {
BOOLDecl = TD;
}
QualType getBOOLType() const {
return getTypeDeclType(getBOOLDecl());
}
QualType getObjCProtoType() const {
return getObjCInterfaceType(getObjCProtocolDecl());
}
TypedefDecl *getBuiltinVaListDecl() const;
QualType getBuiltinVaListType() const {
return getTypeDeclType(getBuiltinVaListDecl());
}
QualType getVaListTagType() const;
QualType getCVRQualifiedType(QualType T, unsigned CVR) const {
return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
}
QualType getQualifiedType(SplitQualType split) const {
return getQualifiedType(split.Ty, split.Quals);
}
QualType getQualifiedType(QualType T, Qualifiers Qs) const {
if (!Qs.hasNonFastQualifiers())
return T.withFastQualifiers(Qs.getFastQualifiers());
QualifierCollector Qc(Qs);
const Type *Ptr = Qc.strip(T);
return getExtQualType(Ptr, Qc);
}
QualType getQualifiedType(const Type *T, Qualifiers Qs) const {
if (!Qs.hasNonFastQualifiers())
return QualType(T, Qs.getFastQualifiers());
return getExtQualType(T, Qs);
}
QualType getLifetimeQualifiedType(QualType type,
Qualifiers::ObjCLifetime lifetime) {
assert(type.getObjCLifetime() == Qualifiers::OCL_None);
assert(lifetime != Qualifiers::OCL_None);
Qualifiers qs;
qs.addObjCLifetime(lifetime);
return getQualifiedType(type, qs);
}
DeclarationNameInfo getNameForTemplate(TemplateName Name,
SourceLocation NameLoc) const;
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
UnresolvedSetIterator End) const;
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
bool TemplateKeyword,
TemplateDecl *Template) const;
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
const IdentifierInfo *Name) const;
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
OverloadedOperatorKind Operator) const;
TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param,
TemplateName replacement) const;
TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param,
const TemplateArgument &ArgPack) const;
enum GetBuiltinTypeError {
GE_None, GE_Missing_stdio, GE_Missing_setjmp, GE_Missing_ucontext };
QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
unsigned *IntegerConstantArgs = 0) const;
private:
CanQualType getFromTargetType(unsigned Type) const;
std::pair<uint64_t, unsigned> getTypeInfoImpl(const Type *T) const;
public:
Qualifiers::GC getObjCGCAttrKind(QualType Ty) const;
bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
static bool isObjCNSObjectType(QualType Ty) {
return Ty->isObjCNSObjectType();
}
const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
std::pair<uint64_t, unsigned> getTypeInfo(const Type *T) const;
std::pair<uint64_t, unsigned> getTypeInfo(QualType T) const {
return getTypeInfo(T.getTypePtr());
}
uint64_t getTypeSize(QualType T) const {
return getTypeInfo(T).first;
}
uint64_t getTypeSize(const Type *T) const {
return getTypeInfo(T).first;
}
uint64_t getCharWidth() const {
return getTypeSize(CharTy);
}
CharUnits toCharUnitsFromBits(int64_t BitSize) const;
int64_t toBits(CharUnits CharSize) const;
CharUnits getTypeSizeInChars(QualType T) const;
CharUnits getTypeSizeInChars(const Type *T) const;
unsigned getTypeAlign(QualType T) const {
return getTypeInfo(T).second;
}
unsigned getTypeAlign(const Type *T) const {
return getTypeInfo(T).second;
}
CharUnits getTypeAlignInChars(QualType T) const;
CharUnits getTypeAlignInChars(const Type *T) const;
std::pair<CharUnits, CharUnits> getTypeInfoDataSizeInChars(QualType T) const;
std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const;
std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const;
unsigned getPreferredTypeAlign(const Type *T) const;
CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false) const;
const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const;
const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D)
const;
void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS,
bool Simple = false) const;
const ASTRecordLayout &
getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const;
const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD);
uint64_t getFieldOffset(const ValueDecl *FD) const;
bool isNearlyEmpty(const CXXRecordDecl *RD) const;
MangleContext *createMangleContext();
void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const;
unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const;
void CollectInheritedProtocols(const Decl *CDecl,
llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
CanQualType getCanonicalType(QualType T) const {
return CanQualType::CreateUnsafe(T.getCanonicalType());
}
const Type *getCanonicalType(const Type *T) const {
return T->getCanonicalTypeInternal().getTypePtr();
}
CanQualType getCanonicalParamType(QualType T) const;
bool hasSameType(QualType T1, QualType T2) const {
return getCanonicalType(T1) == getCanonicalType(T2);
}
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
bool hasSameUnqualifiedType(QualType T1, QualType T2) const {
return getCanonicalType(T1).getTypePtr() ==
getCanonicalType(T2).getTypePtr();
}
bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2);
NestedNameSpecifier *
getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const;
CallingConv getDefaultCXXMethodCallConv(bool isVariadic);
CallingConv getCanonicalCallConv(CallingConv CC) const;
bool isSameCallConv(CallingConv lcc, CallingConv rcc) {
return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc));
}
TemplateName getCanonicalTemplateName(TemplateName Name) const;
bool hasSameTemplateName(TemplateName X, TemplateName Y);
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg)
const;
const ArrayType *getAsArrayType(QualType T) const;
const ConstantArrayType *getAsConstantArrayType(QualType T) const {
return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
}
const VariableArrayType *getAsVariableArrayType(QualType T) const {
return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
}
const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const {
return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
}
const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T)
const {
return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
}
QualType getBaseElementType(const ArrayType *VAT) const;
QualType getBaseElementType(QualType QT) const;
uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
QualType getAdjustedParameterType(QualType T) const;
QualType getSignatureParameterType(QualType T) const;
QualType getArrayDecayedType(QualType T) const;
QualType getPromotedIntegerType(QualType PromotableType) const;
Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const;
QualType isPromotableBitField(Expr *E) const;
int getIntegerTypeOrder(QualType LHS, QualType RHS) const;
int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
QualType typeDomain) const;
unsigned getTargetAddressSpace(QualType T) const {
return getTargetAddressSpace(T.getQualifiers());
}
unsigned getTargetAddressSpace(Qualifiers Q) const {
return getTargetAddressSpace(Q.getAddressSpace());
}
unsigned getTargetAddressSpace(unsigned AS) const {
if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count)
return AS;
else
return (*AddrSpaceMap)[AS - LangAS::Offset];
}
private:
unsigned getIntegerRank(const Type *T) const;
public:
bool typesAreCompatible(QualType T1, QualType T2,
bool CompareUnqualified = false);
bool propertyTypesAreCompatible(QualType, QualType);
bool typesAreBlockPointerCompatible(QualType, QualType);
bool isObjCIdType(QualType T) const {
return T == getObjCIdType();
}
bool isObjCClassType(QualType T) const {
return T == getObjCClassType();
}
bool isObjCSelType(QualType T) const {
return T == getObjCSelType();
}
bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
bool ForCompare);
bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS);
bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
const ObjCObjectPointerType *RHSOPT);
bool canAssignObjCInterfaces(const ObjCObjectType *LHS,
const ObjCObjectType *RHS);
bool canAssignObjCInterfacesInBlockPointer(
const ObjCObjectPointerType *LHSOPT,
const ObjCObjectPointerType *RHSOPT,
bool BlockReturnType);
bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
const ObjCObjectPointerType *RHSOPT);
bool canBindObjCObjectType(QualType To, QualType From);
QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false,
bool Unqualified = false, bool BlockReturnType = false);
QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false,
bool Unqualified = false);
QualType mergeFunctionArgumentTypes(QualType, QualType,
bool OfBlockPointer=false,
bool Unqualified = false);
QualType mergeTransparentUnionType(QualType, QualType,
bool OfBlockPointer=false,
bool Unqualified = false);
QualType mergeObjCGCQualifiers(QualType, QualType);
bool FunctionTypesMatchOnNSConsumedAttrs(
const FunctionProtoType *FromFunctionType,
const FunctionProtoType *ToFunctionType);
void ResetObjCLayout(const ObjCContainerDecl *CD) {
ObjCLayouts[CD] = 0;
}
unsigned getIntWidth(QualType T) const;
QualType getCorrespondingUnsignedType(QualType T) const;
typedef std::vector<Type*>::iterator type_iterator;
typedef std::vector<Type*>::const_iterator const_type_iterator;
type_iterator types_begin() { return Types.begin(); }
type_iterator types_end() { return Types.end(); }
const_type_iterator types_begin() const { return Types.begin(); }
const_type_iterator types_end() const { return Types.end(); }
llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const {
llvm::APSInt Res(getIntWidth(Type),
!Type->isSignedIntegerOrEnumerationType());
Res = Value;
return Res;
}
bool isSentinelNullExpr(const Expr *E);
ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D);
bool AnyObjCImplementation() {
return !ObjCImpls.empty();
}
void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
ObjCImplementationDecl *ImplD);
void setObjCImplementation(ObjCCategoryDecl *CatD,
ObjCCategoryImplDecl *ImplD);
const ObjCMethodDecl *getObjCMethodRedeclaration(
const ObjCMethodDecl *MD) const {
return ObjCMethodRedecls.lookup(MD);
}
void setObjCMethodRedeclaration(const ObjCMethodDecl *MD,
const ObjCMethodDecl *Redecl) {
assert(!getObjCMethodRedeclaration(MD) && "MD already has a redeclaration");
ObjCMethodRedecls[MD] = Redecl;
}
ObjCInterfaceDecl *getObjContainingInterface(NamedDecl *ND) const;
void setBlockVarCopyInits(VarDecl*VD, Expr* Init);
Expr *getBlockVarCopyInits(const VarDecl* VD);
TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const;
TypeSourceInfo *
getTrivialTypeSourceInfo(QualType T,
SourceLocation Loc = SourceLocation()) const;
TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; }
void AddDeallocation(void (*Callback)(void*), void *Data);
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD);
GVALinkage GetGVALinkageForVariable(const VarDecl *VD);
bool DeclMustBeEmitted(const Decl *D);
unsigned getLambdaManglingNumber(CXXMethodDecl *CallOperator);
void setParameterIndex(const ParmVarDecl *D, unsigned index);
unsigned getParameterIndex(const ParmVarDecl *D) const;
static unsigned NumImplicitDefaultConstructors;
static unsigned NumImplicitDefaultConstructorsDeclared;
static unsigned NumImplicitCopyConstructors;
static unsigned NumImplicitCopyConstructorsDeclared;
static unsigned NumImplicitMoveConstructors;
static unsigned NumImplicitMoveConstructorsDeclared;
static unsigned NumImplicitCopyAssignmentOperators;
static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
static unsigned NumImplicitMoveAssignmentOperators;
static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
static unsigned NumImplicitDestructors;
static unsigned NumImplicitDestructorsDeclared;
private:
ASTContext(const ASTContext &) LLVM_DELETED_FUNCTION;
void operator=(const ASTContext &) LLVM_DELETED_FUNCTION;
public:
void InitBuiltinTypes(const TargetInfo &Target);
private:
void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
void getObjCEncodingForTypeImpl(QualType t, std::string &S,
bool ExpandPointedToStructures,
bool ExpandStructures,
const FieldDecl *Field,
bool OutermostType = false,
bool EncodingProperty = false,
bool StructField = false,
bool EncodeBlockParameters = false,
bool EncodeClassNames = false) const;
void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S,
const FieldDecl *Field,
bool includeVBases = true) const;
void getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT,
QualType T, std::string& S,
bool Extended) const;
const ASTRecordLayout &
getObjCLayout(const ObjCInterfaceDecl *D,
const ObjCImplementationDecl *Impl) const;
private:
SmallVector<std::pair<void (*)(void*), void *>, 16> Deallocations;
llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM;
mutable unsigned int UniqueBlockByRefTypeID;
friend class DeclContext;
friend class DeclarationNameTable;
void ReleaseDeclContextMaps();
};
static inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) {
IdentifierInfo* II = &Ctx.Idents.get(name);
return Ctx.Selectors.getSelector(0, &II);
}
static inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) {
IdentifierInfo* II = &Ctx.Idents.get(name);
return Ctx.Selectors.getSelector(1, &II);
}
}
inline void *operator new(size_t Bytes, const clang::ASTContext &C,
size_t Alignment) {
return C.Allocate(Bytes, Alignment);
}
inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) {
C.Deallocate(Ptr);
}
inline void *operator new[](size_t Bytes, const clang::ASTContext& C,
size_t Alignment = 8) {
return C.Allocate(Bytes, Alignment);
}
inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) {
C.Deallocate(Ptr);
}
#endif