diff options
Diffstat (limited to 'include/clang/AST/ASTContext.h')
-rw-r--r-- | include/clang/AST/ASTContext.h | 311 |
1 files changed, 208 insertions, 103 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 1526f36ba2fb..c4ffac5341e7 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -37,7 +37,6 @@ namespace llvm { struct fltSemantics; - class raw_ostream; } namespace clang { @@ -45,7 +44,7 @@ namespace clang { class ASTRecordLayout; class BlockExpr; class CharUnits; - class Diagnostic; + class DiagnosticsEngine; class Expr; class ExternalASTSource; class ASTMutationListener; @@ -64,6 +63,7 @@ namespace clang { class ObjCIvarDecl; class ObjCIvarRefExpr; class ObjCPropertyDecl; + class ParmVarDecl; class RecordDecl; class StoredDeclsMap; class TagDecl; @@ -120,6 +120,7 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> { 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; @@ -149,10 +150,19 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> { /// \brief Mapping from ObjCContainers to their ObjCImplementations. llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls; + + /// \brief Mapping from ObjCMethod to its duplicate declaration in the same + /// interface. + llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls; /// \brief Mapping from __block VarDecls to their copy initialization expr. llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits; + /// \brief Mapping from class scope functions specialization to their + /// template patterns. + llvm::DenseMap<const FunctionDecl*, FunctionDecl*> + ClassScopeSpecializationPattern; + /// \brief Representation of a "canonical" template template parameter that /// is used in canonical template names. class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode { @@ -175,34 +185,41 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> { TemplateTemplateParmDecl * getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const; - /// \brief Whether __[u]int128_t identifier is installed. - bool IsInt128Installed; + /// \brief The typedef for the __int128_t type. + mutable TypedefDecl *Int128Decl; + /// \brief The typedef for the __uint128_t type. + mutable TypedefDecl *UInt128Decl; + /// BuiltinVaListType - built-in va list type. /// This is initially null and set by Sema::LazilyCreateBuiltin when /// a builtin that takes a valist is encountered. QualType BuiltinVaListType; - /// ObjCIdType - a pseudo built-in typedef type (set by Sema). - QualType ObjCIdTypedefType; - - /// ObjCSelType - another pseudo built-in typedef type (set by Sema). - QualType ObjCSelTypedefType; + /// \brief The typedef for the predefined 'id' type. + mutable TypedefDecl *ObjCIdDecl; + + /// \brief The typedef for the predefined 'SEL' type. + mutable TypedefDecl *ObjCSelDecl; - /// ObjCProtoType - another pseudo built-in typedef type (set by Sema). QualType ObjCProtoType; const RecordType *ProtoStructType; - /// ObjCClassType - another pseudo built-in typedef type (set by Sema). - QualType ObjCClassTypedefType; + /// \brief The typedef for the predefined 'Class' type. + mutable TypedefDecl *ObjCClassDecl; + + // Typedefs which may be provided defining the structure of Objective-C + // pseudo-builtins + QualType ObjCIdRedefinitionType; + QualType ObjCClassRedefinitionType; + QualType ObjCSelRedefinitionType; QualType ObjCConstantStringType; mutable RecordDecl *CFConstantStringTypeDecl; - mutable RecordDecl *NSConstantStringTypeDecl; - - mutable RecordDecl *ObjCFastEnumerationStateTypeDecl; - + /// \brief The typedef declaration for the Objective-C "instancetype" type. + TypedefDecl *ObjCInstanceTypeDecl; + /// \brief The type for the C FILE type. TypeDecl *FILEDecl; @@ -213,9 +230,15 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> { TypeDecl *sigjmp_bufDecl; /// \brief Type for the Block descriptor for Blocks CodeGen. + /// + /// Since this is only used for generation of debug info, it is not + /// serialized. mutable RecordDecl *BlockDescriptorType; /// \brief Type for the Block descriptor for Blocks CodeGen. + /// + /// Since this is only used for generation of debug info, it is not + /// serialized. mutable RecordDecl *BlockDescriptorExtendedType; /// \brief Declaration for the CUDA cudaConfigureCall function. @@ -295,6 +318,12 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> { typedef UsuallyTinyPtrVector<const CXXMethodDecl> CXXMethodVector; llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods; + /// \brief Mapping that stores parameterIndex values for ParmVarDecls + /// when that value exceeds the bitfield size of + /// ParmVarDeclBits.ParameterIndex. + typedef llvm::DenseMap<const VarDecl *, unsigned> ParameterIndexTable; + ParameterIndexTable ParamIndices; + TranslationUnitDecl *TUDecl; /// SourceMgr - The associated SourceManager object. @@ -302,7 +331,7 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> { /// LangOpts - The language options used to create the AST associated with /// this ASTContext object. - LangOptions LangOpts; + LangOptions &LangOpts; /// \brief The allocator used to create AST objects. /// @@ -318,26 +347,29 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> { CXXABI *createCXXABI(const TargetInfo &T); /// \brief The logical -> physical address space map. - const LangAS::Map &AddrSpaceMap; + const LangAS::Map *AddrSpaceMap; friend class ASTDeclReader; - + friend class ASTReader; + friend class ASTWriter; + + const TargetInfo *Target; + clang::PrintingPolicy PrintingPolicy; + public: - const TargetInfo &Target; IdentifierTable &Idents; SelectorTable &Selectors; Builtin::Context &BuiltinInfo; mutable DeclarationNameTable DeclarationNames; llvm::OwningPtr<ExternalASTSource> ExternalSource; ASTMutationListener *Listener; - clang::PrintingPolicy PrintingPolicy; - // Typedefs which may be provided defining the structure of Objective-C - // pseudo-builtins - QualType ObjCIdRedefinitionType; - QualType ObjCClassRedefinitionType; - QualType ObjCSelRedefinitionType; + clang::PrintingPolicy getPrintingPolicy() const { return PrintingPolicy; } + void setPrintingPolicy(clang::PrintingPolicy Policy) { + PrintingPolicy = Policy; + } + SourceManager& getSourceManager() { return SourceMgr; } const SourceManager& getSourceManager() const { return SourceMgr; } void *Allocate(unsigned Size, unsigned Align = 8) const { @@ -357,9 +389,11 @@ public: return DiagAllocator; } + const TargetInfo &getTargetInfo() const { return *Target; } + const LangOptions& getLangOptions() const { return LangOpts; } - Diagnostic &getDiagnostics() const; + DiagnosticsEngine &getDiagnostics() const; FullSourceLoc getFullLoc(SourceLocation Loc) const { return FullSourceLoc(Loc,SourceMgr); @@ -377,6 +411,11 @@ public: MemberSpecializationInfo *getInstantiatedFromStaticDataMember( const VarDecl *Var); + FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD); + + void setClassScopeSpecializationPattern(FunctionDecl *FD, + FunctionDecl *Pattern); + /// \brief Note that the static data member \p Inst is an instantiation of /// the static data member template \p Tmpl of a class template. void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, @@ -413,17 +452,17 @@ public: /// BitfieldFollowsBitfield - return 'true" if 'FD' is a /// bitfield which follows the bitfield 'LastFD'. bool BitfieldFollowsBitfield(const FieldDecl *FD, - const FieldDecl *LastFD) const; + const FieldDecl *LastFD) const; - /// NoneBitfieldFollowsBitfield - return 'true" if 'FD' is not a + /// NonBitfieldFollowsBitfield - return 'true" if 'FD' is not a /// bitfield which follows the bitfield 'LastFD'. - bool NoneBitfieldFollowsBitfield(const FieldDecl *FD, - const FieldDecl *LastFD) const; + bool NonBitfieldFollowsBitfield(const FieldDecl *FD, + const FieldDecl *LastFD) const; - /// BitfieldFollowsNoneBitfield - return 'true" if 'FD' is a + /// BitfieldFollowsNonBitfield - return 'true" if 'FD' is a /// bitfield which follows the none bitfield 'LastFD'. - bool BitfieldFollowsNoneBitfield(const FieldDecl *FD, - const FieldDecl *LastFD) const; + bool BitfieldFollowsNonBitfield(const FieldDecl *FD, + const FieldDecl *LastFD) const; // Access to the set of methods overridden by the given C++ method. typedef CXXMethodVector::iterator overridden_cxx_method_iterator; @@ -454,6 +493,7 @@ public: CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; CanQualType UnsignedLongLongTy, UnsignedInt128Ty; CanQualType FloatTy, DoubleTy, LongDoubleTy; + CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; CanQualType VoidPtrTy, NullPtrTy; CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy; @@ -463,10 +503,11 @@ public: mutable QualType AutoDeductTy; // Deduction against 'auto'. mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'. - ASTContext(const LangOptions& LOpts, SourceManager &SM, const TargetInfo &t, + ASTContext(LangOptions& LOpts, SourceManager &SM, const TargetInfo *t, IdentifierTable &idents, SelectorTable &sels, Builtin::Context &builtins, - unsigned size_reserve); + unsigned size_reserve, + bool DelayInitialization = false); ~ASTContext(); @@ -497,6 +538,12 @@ public: void PrintStats() const; const std::vector<Type*>& getTypes() const { return Types; } + /// \brief Retrieve the declaration for the 128-bit signed integer type. + TypedefDecl *getInt128Decl() const; + + /// \brief Retrieve the declaration for the 128-bit unsigned integer type. + TypedefDecl *getUInt128Decl() const; + //===--------------------------------------------------------------------===// // Type Constructors //===--------------------------------------------------------------------===// @@ -560,6 +607,10 @@ public: return CanQualType::CreateUnsafe(getPointerType((QualType) T)); } + /// getAtomicType - Return the uniqued reference to the atomic type for + /// the specified type. + QualType getAtomicType(QualType T) const; + /// getBlockPointerType - Return the uniqued reference to the type for a block /// of the specified type. QualType getBlockPointerType(QualType T) const; @@ -568,29 +619,10 @@ public: /// blocks. QualType getBlockDescriptorType() const; - // Set the type for a Block descriptor type. - void setBlockDescriptorType(QualType T); - /// Get the BlockDescriptorType type, or NULL if it hasn't yet been built. - QualType getRawBlockdescriptorType() { - if (BlockDescriptorType) - return getTagDeclType(BlockDescriptorType); - return QualType(); - } - /// This gets the struct used to keep track of the extended descriptor for /// pointer to blocks. QualType getBlockDescriptorExtendedType() const; - // Set the type for a Block descriptor extended type. - void setBlockDescriptorExtendedType(QualType T); - /// Get the BlockDescriptorExtendedType type, or NULL if it hasn't yet been - /// built. - QualType getRawBlockdescriptorExtendedType() const { - if (BlockDescriptorExtendedType) - return getTagDeclType(BlockDescriptorExtendedType); - return QualType(); - } - void setcudaConfigureCallDecl(FunctionDecl *FD) { cudaConfigureCallDecl = FD; } @@ -599,7 +631,7 @@ public: } /// This builds the struct used for __block variables. - QualType BuildByRefType(llvm::StringRef DeclName, QualType Ty) const; + QualType BuildByRefType(StringRef DeclName, QualType Ty) const; /// Returns true iff we need copy/dispose helpers for the given type. bool BlockRequiresCopying(QualType Ty) const; @@ -824,19 +856,6 @@ public: // constant CFStrings. QualType getCFConstantStringType() const; - // getNSConstantStringType - Return the C structure type used to represent - // constant NSStrings. - QualType getNSConstantStringType() const; - /// Get the structure type used to representation NSStrings, or NULL - /// if it hasn't yet been built. - QualType getRawNSConstantStringType() const { - if (NSConstantStringTypeDecl) - return getTagDeclType(NSConstantStringTypeDecl); - return QualType(); - } - void setNSConstantStringType(QualType T); - - /// Get the structure type used to representation CFStrings, or NULL /// if it hasn't yet been built. QualType getRawCFConstantStringType() const { @@ -852,19 +871,56 @@ public: return ObjCConstantStringType; } - //// This gets the struct used to keep track of fast enumerations. - QualType getObjCFastEnumerationStateType() const; + /// \brief Retrieve the type that 'id' has been defined to, which may be + /// different from the built-in 'id' if 'id' has been typedef'd. + QualType getObjCIdRedefinitionType() const { + if (ObjCIdRedefinitionType.isNull()) + return getObjCIdType(); + return ObjCIdRedefinitionType; + } + + /// \brief Set the user-written type that redefines 'id'. + void setObjCIdRedefinitionType(QualType RedefType) { + ObjCIdRedefinitionType = RedefType; + } - /// Get the ObjCFastEnumerationState type, or NULL if it hasn't yet - /// been built. - QualType getRawObjCFastEnumerationStateType() const { - if (ObjCFastEnumerationStateTypeDecl) - return getTagDeclType(ObjCFastEnumerationStateTypeDecl); - return QualType(); + /// \brief Retrieve the type that 'Class' has been defined to, which may be + /// different from the built-in 'Class' if 'Class' has been typedef'd. + QualType getObjCClassRedefinitionType() const { + if (ObjCClassRedefinitionType.isNull()) + return getObjCClassType(); + return ObjCClassRedefinitionType; + } + + /// \brief Set the user-written type that redefines 'SEL'. + void setObjCClassRedefinitionType(QualType RedefType) { + ObjCClassRedefinitionType = RedefType; + } + + /// \brief Retrieve the type that 'SEL' has been defined to, which may be + /// different from the built-in 'SEL' if 'SEL' has been typedef'd. + QualType getObjCSelRedefinitionType() const { + if (ObjCSelRedefinitionType.isNull()) + return getObjCSelType(); + return ObjCSelRedefinitionType; + } + + + /// \brief Set the user-written type that redefines 'SEL'. + void setObjCSelRedefinitionType(QualType RedefType) { + ObjCSelRedefinitionType = RedefType; } - void setObjCFastEnumerationStateType(QualType T); + /// \brief Retrieve the Objective-C "instancetype" type, if already known; + /// otherwise, returns a NULL type; + QualType getObjCInstanceType() { + return getTypeDeclType(getObjCInstanceTypeDecl()); + } + /// \brief Retrieve the typedef declaration corresponding to the Objective-C + /// "instancetype" type. + TypedefDecl *getObjCInstanceTypeDecl(); + /// \brief Set the type for the C FILE type. void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; } @@ -950,26 +1006,39 @@ public: /// purpose in characters. CharUnits getObjCEncodingTypeSize(QualType t) const; - /// \brief Whether __[u]int128_t identifier is installed. - bool isInt128Installed() const { return IsInt128Installed; } - void setInt128Installed() { IsInt128Installed = true; } - + /// \brief Retrieve the typedef corresponding to the predefined 'id' type + /// in Objective-C. + TypedefDecl *getObjCIdDecl() const; + /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by /// Sema. id is always a (typedef for a) pointer type, a pointer to a struct. - QualType getObjCIdType() const { return ObjCIdTypedefType; } - void setObjCIdType(QualType T); + QualType getObjCIdType() const { + return getTypeDeclType(getObjCIdDecl()); + } - void setObjCSelType(QualType T); - QualType getObjCSelType() const { return ObjCSelTypedefType; } + /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type + /// in Objective-C. + TypedefDecl *getObjCSelDecl() const; + + /// \brief Retrieve the type that corresponds to the predefined Objective-C + /// 'SEL' type. + QualType getObjCSelType() const { + return getTypeDeclType(getObjCSelDecl()); + } void setObjCProtoType(QualType QT); QualType getObjCProtoType() const { return ObjCProtoType; } + /// \brief Retrieve the typedef declaration corresponding to the predefined + /// Objective-C 'Class' type. + TypedefDecl *getObjCClassDecl() const; + /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by /// Sema. 'Class' is always a (typedef for a) pointer type, a pointer to a /// struct. - QualType getObjCClassType() const { return ObjCClassTypedefType; } - void setObjCClassType(QualType T); + QualType getObjCClassType() const { + return getTypeDeclType(getObjCClassDecl()); + } void setBuiltinVaListType(QualType T); QualType getBuiltinVaListType() const { return BuiltinVaListType; } @@ -1145,7 +1214,7 @@ public: const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const; - void DumpRecordLayout(const RecordDecl *RD, llvm::raw_ostream &OS) const; + void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS) const; /// getASTObjCImplementationLayout - Get or compute information about /// the layout of the specified Objective-C implementation. This may @@ -1164,13 +1233,9 @@ public: bool isNearlyEmpty(const CXXRecordDecl *RD) const; MangleContext *createMangleContext(); - - void ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI, - llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) - const; void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, - llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) const; + SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const; unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const; void CollectInheritedProtocols(const Decl *CDecl, @@ -1261,7 +1326,7 @@ public: /// \brief Retrieves the canonical representation of the given /// calling convention. CallingConv getCanonicalCallConv(CallingConv CC) const { - if (CC == CC_C) + if (!LangOpts.MRTD && CC == CC_C) return CC_Default; return CC; } @@ -1400,7 +1465,7 @@ public: if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count) return AS; else - return AddrSpaceMap[AS - LangAS::Offset]; + return (*AddrSpaceMap)[AS - LangAS::Offset]; } private: @@ -1421,13 +1486,13 @@ public: bool typesAreBlockPointerCompatible(QualType, QualType); bool isObjCIdType(QualType T) const { - return T == ObjCIdTypedefType; + return T == getObjCIdType(); } bool isObjCClassType(QualType T) const { - return T == ObjCClassTypedefType; + return T == getObjCClassType(); } bool isObjCSelType(QualType T) const { - return T == ObjCSelTypedefType; + return T == getObjCSelType(); } bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS); bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, @@ -1462,6 +1527,10 @@ public: bool Unqualified = false); QualType mergeObjCGCQualifiers(QualType, QualType); + + bool FunctionTypesMatchOnNSConsumedAttrs( + const FunctionProtoType *FromFunctionType, + const FunctionProtoType *ToFunctionType); void ResetObjCLayout(const ObjCContainerDecl *CD) { ObjCLayouts[CD] = 0; @@ -1521,6 +1590,22 @@ public: /// \brief Set the implementation of ObjCCategoryDecl. void setObjCImplementation(ObjCCategoryDecl *CatD, ObjCCategoryImplDecl *ImplD); + + /// \brief Get the duplicate declaration of a ObjCMethod in the same + /// interface, or null if non exists. + const ObjCMethodDecl *getObjCMethodRedeclaration( + const ObjCMethodDecl *MD) const { + llvm::DenseMap<const ObjCMethodDecl*, const ObjCMethodDecl*>::const_iterator + I = ObjCMethodRedecls.find(MD); + if (I == ObjCMethodRedecls.end()) + return 0; + return I->second; + } + + void setObjCMethodRedeclaration(const ObjCMethodDecl *MD, + const ObjCMethodDecl *Redecl) { + ObjCMethodRedecls[MD] = Redecl; + } /// \brief Set the copy inialization expression of a block var decl. void setBlockVarCopyInits(VarDecl*VD, Expr* Init); @@ -1570,6 +1655,15 @@ public: /// it is not used. bool DeclMustBeEmitted(const Decl *D); + + /// \brief Used by ParmVarDecl to store on the side the + /// index of the parameter when it exceeds the size of the normal bitfield. + void setParameterIndex(const ParmVarDecl *D, unsigned index); + + /// \brief Used by ParmVarDecl to retrieve on the side the + /// index of the parameter when it exceeds the size of the normal bitfield. + unsigned getParameterIndex(const ParmVarDecl *D) const; + //===--------------------------------------------------------------------===// // Statistics //===--------------------------------------------------------------------===// @@ -1620,7 +1714,18 @@ private: ASTContext(const ASTContext&); // DO NOT IMPLEMENT void operator=(const ASTContext&); // DO NOT IMPLEMENT - void InitBuiltinTypes(); +public: + /// \brief Initialize built-in types. + /// + /// This routine may only be invoked once for a given ASTContext object. + /// It is normally invoked by the ASTContext constructor. However, the + /// constructor can be asked to delay initialization, which places the burden + /// of calling this function on the user of that object. + /// + /// \param Target The target + void InitBuiltinTypes(const TargetInfo &Target); + +private: void InitBuiltinType(CanQualType &R, BuiltinType::Kind K); // Return the ObjC type encoding for a given type. @@ -1644,7 +1749,7 @@ private: private: /// \brief A set of deallocations that should be performed when the /// ASTContext is destroyed. - llvm::SmallVector<std::pair<void (*)(void*), void *>, 16> Deallocations; + SmallVector<std::pair<void (*)(void*), void *>, 16> Deallocations; // FIXME: This currently contains the set of StoredDeclMaps used // by DeclContext objects. This probably should not be in ASTContext, @@ -1660,13 +1765,13 @@ private: }; /// @brief Utility function for constructing a nullary selector. -static inline Selector GetNullarySelector(llvm::StringRef name, ASTContext& Ctx) { +static inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) { IdentifierInfo* II = &Ctx.Idents.get(name); return Ctx.Selectors.getSelector(0, &II); } /// @brief Utility function for constructing an unary selector. -static inline Selector GetUnarySelector(llvm::StringRef name, ASTContext& Ctx) { +static inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) { IdentifierInfo* II = &Ctx.Idents.get(name); return Ctx.Selectors.getSelector(1, &II); } |