diff options
Diffstat (limited to 'contrib/llvm-project/clang/include/clang/AST/DeclObjC.h')
-rw-r--r-- | contrib/llvm-project/clang/include/clang/AST/DeclObjC.h | 156 |
1 files changed, 109 insertions, 47 deletions
diff --git a/contrib/llvm-project/clang/include/clang/AST/DeclObjC.h b/contrib/llvm-project/clang/include/clang/AST/DeclObjC.h index 6bb9cdf67034..f8f894b4b10d 100644 --- a/contrib/llvm-project/clang/include/clang/AST/DeclObjC.h +++ b/contrib/llvm-project/clang/include/clang/AST/DeclObjC.h @@ -25,9 +25,8 @@ #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Specifiers.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" -#include "llvm/ADT/None.h" +#include "llvm/ADT/MapVector.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" @@ -116,6 +115,8 @@ public: const SourceLocation *Locs, ASTContext &Ctx); }; +enum class ObjCImplementationControl { None, Required, Optional }; + /// ObjCMethodDecl - Represents an instance or class method declaration. /// ObjC methods can be declared within 4 contexts: class interfaces, /// categories, protocols, and class implementations. While C++ member @@ -140,10 +141,6 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext { // This class stores some data in DeclContext::ObjCMethodDeclBits // to save some space. Use the provided accessors to access it. -public: - enum ImplementationControl { None, Required, Optional }; - -private: /// Return type of this method. QualType MethodDeclType; @@ -169,14 +166,14 @@ private: /// constructed by createImplicitParams. ImplicitParamDecl *CmdDecl = nullptr; - ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc, - Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, - DeclContext *contextDecl, bool isInstance = true, - bool isVariadic = false, bool isPropertyAccessor = false, - bool isSynthesizedAccessorStub = false, - bool isImplicitlyDeclared = false, bool isDefined = false, - ImplementationControl impControl = None, - bool HasRelatedResultType = false); + ObjCMethodDecl( + SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, + QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, + bool isInstance = true, bool isVariadic = false, + bool isPropertyAccessor = false, bool isSynthesizedAccessorStub = false, + bool isImplicitlyDeclared = false, bool isDefined = false, + ObjCImplementationControl impControl = ObjCImplementationControl::None, + bool HasRelatedResultType = false); SelectorLocationsKind getSelLocsKind() const { return static_cast<SelectorLocationsKind>(ObjCMethodDeclBits.SelLocsKind); @@ -236,7 +233,7 @@ public: bool isVariadic = false, bool isPropertyAccessor = false, bool isSynthesizedAccessorStub = false, bool isImplicitlyDeclared = false, bool isDefined = false, - ImplementationControl impControl = None, + ObjCImplementationControl impControl = ObjCImplementationControl::None, bool HasRelatedResultType = false); static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); @@ -374,8 +371,7 @@ public: // ArrayRef access to formal parameters. This should eventually // replace the iterator interface above. ArrayRef<ParmVarDecl*> parameters() const { - return llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()), - NumParams); + return llvm::ArrayRef(const_cast<ParmVarDecl **>(getParams()), NumParams); } ParmVarDecl *getParamDecl(unsigned Idx) { @@ -389,9 +385,8 @@ public: /// Sets the method's parameters and selector source locations. /// If the method is implicit (not coming from source) \p SelLocs is /// ignored. - void setMethodParams(ASTContext &C, - ArrayRef<ParmVarDecl*> Params, - ArrayRef<SourceLocation> SelLocs = llvm::None); + void setMethodParams(ASTContext &C, ArrayRef<ParmVarDecl *> Params, + ArrayRef<SourceLocation> SelLocs = std::nullopt); // Iterator access to parameter types. struct GetTypeFn { @@ -487,6 +482,9 @@ public: /// True if the method is tagged as objc_direct bool isDirectMethod() const; + /// True if the method has a parameter that's destroyed in the callee. + bool hasParamDestroyedInCallee() const; + /// Returns the property associated with this method's selector. /// /// Note that even if this particular method is not marked as a property @@ -495,16 +493,17 @@ public: const ObjCPropertyDecl *findPropertyDecl(bool CheckOverrides = true) const; // Related to protocols declared in \@protocol - void setDeclImplementation(ImplementationControl ic) { - ObjCMethodDeclBits.DeclImplementation = ic; + void setDeclImplementation(ObjCImplementationControl ic) { + ObjCMethodDeclBits.DeclImplementation = llvm::to_underlying(ic); } - ImplementationControl getImplementationControl() const { - return ImplementationControl(ObjCMethodDeclBits.DeclImplementation); + ObjCImplementationControl getImplementationControl() const { + return static_cast<ObjCImplementationControl>( + ObjCMethodDeclBits.DeclImplementation); } bool isOptional() const { - return getImplementationControl() == Optional; + return getImplementationControl() == ObjCImplementationControl::Optional; } /// Returns true if this specific method declaration is marked with the @@ -581,6 +580,7 @@ class ObjCTypeParamDecl : public TypedefNameDecl { unsigned Index : 14; /// The variance of the type parameter. + LLVM_PREFERRED_TYPE(ObjCTypeParamVariance) unsigned Variance : 2; /// The location of the variance, if any. @@ -742,10 +742,13 @@ private: QualType DeclType; TypeSourceInfo *DeclTypeSourceInfo; + LLVM_PREFERRED_TYPE(ObjCPropertyAttribute::Kind) unsigned PropertyAttributes : NumObjCPropertyAttrsBits; + LLVM_PREFERRED_TYPE(ObjCPropertyAttribute::Kind) unsigned PropertyAttributesAsWritten : NumObjCPropertyAttrsBits; // \@required/\@optional + LLVM_PREFERRED_TYPE(PropertyControl) unsigned PropertyImplementation : 2; // getter name of NULL if no getter @@ -776,17 +779,13 @@ private: LParenLoc(LParenLocation), DeclType(T), DeclTypeSourceInfo(TSI), PropertyAttributes(ObjCPropertyAttribute::kind_noattr), PropertyAttributesAsWritten(ObjCPropertyAttribute::kind_noattr), - PropertyImplementation(propControl), GetterName(Selector()), - SetterName(Selector()) {} + PropertyImplementation(propControl) {} public: - static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC, - SourceLocation L, - IdentifierInfo *Id, SourceLocation AtLocation, - SourceLocation LParenLocation, - QualType T, - TypeSourceInfo *TSI, - PropertyControl propControl = None); + static ObjCPropertyDecl * + Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, + SourceLocation AtLocation, SourceLocation LParenLocation, QualType T, + TypeSourceInfo *TSI, PropertyControl propControl = None); static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); @@ -1072,21 +1071,23 @@ public: bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const; ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const; + ObjCPropertyDecl *getProperty(const IdentifierInfo *Id, + bool IsInstance) const; + ObjCPropertyDecl * FindPropertyDeclaration(const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const; using PropertyMap = - llvm::DenseMap<std::pair<IdentifierInfo *, unsigned/*isClassProperty*/>, - ObjCPropertyDecl *>; + llvm::MapVector<std::pair<IdentifierInfo *, unsigned /*isClassProperty*/>, + ObjCPropertyDecl *>; using ProtocolPropertySet = llvm::SmallDenseSet<const ObjCProtocolDecl *, 8>; using PropertyDeclOrder = llvm::SmallVector<ObjCPropertyDecl *, 8>; /// This routine collects list of properties to be implemented in the class. /// This includes, class's and its conforming protocols' properties. /// Note, the superclass's properties are not included in the list. - virtual void collectPropertiesToImplement(PropertyMap &PM, - PropertyDeclOrder &PO) const {} + virtual void collectPropertiesToImplement(PropertyMap &PM) const {} SourceLocation getAtStartLoc() const { return ObjCContainerDeclBits.AtStart; } @@ -1148,6 +1149,7 @@ public: class ObjCInterfaceDecl : public ObjCContainerDecl , public Redeclarable<ObjCInterfaceDecl> { friend class ASTContext; + friend class ODRDiagsEmitter; /// TypeForDecl - This indicates the Type object that represents this /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType @@ -1180,14 +1182,17 @@ class ObjCInterfaceDecl : public ObjCContainerDecl /// Indicates that the contents of this Objective-C class will be /// completed by the external AST source when required. + LLVM_PREFERRED_TYPE(bool) mutable unsigned ExternallyCompleted : 1; /// Indicates that the ivar cache does not yet include ivars /// declared in the implementation. + LLVM_PREFERRED_TYPE(bool) mutable unsigned IvarListMissingImplementation : 1; /// Indicates that this interface decl contains at least one initializer /// marked with the 'objc_designated_initializer' attribute. + LLVM_PREFERRED_TYPE(bool) unsigned HasDesignatedInitializers : 1; enum InheritedDesignatedInitializersState { @@ -1203,8 +1208,16 @@ class ObjCInterfaceDecl : public ObjCContainerDecl }; /// One of the \c InheritedDesignatedInitializersState enumeratos. + LLVM_PREFERRED_TYPE(InheritedDesignatedInitializersState) mutable unsigned InheritedDesignatedInitializers : 2; + /// Tracks whether a ODR hash has been computed for this interface. + LLVM_PREFERRED_TYPE(bool) + unsigned HasODRHash : 1; + + /// A hash of parts of the class to help in ODR checking. + unsigned ODRHash = 0; + /// The location of the last location in this declaration, before /// the properties/methods. For example, this will be the '>', '}', or /// identifier, @@ -1213,7 +1226,7 @@ class ObjCInterfaceDecl : public ObjCContainerDecl DefinitionData() : ExternallyCompleted(false), IvarListMissingImplementation(true), HasDesignatedInitializers(false), - InheritedDesignatedInitializers(IDI_Unknown) {} + InheritedDesignatedInitializers(IDI_Unknown), HasODRHash(false) {} }; /// The type parameters associated with this class, if any. @@ -1537,6 +1550,13 @@ public: /// a forward declaration (\@class) to a definition (\@interface). void startDefinition(); + /// Starts the definition without sharing it with other redeclarations. + /// Such definition shouldn't be used for anything but only to compare if + /// a duplicate is compatible with previous definition or if it is + /// a distinct duplicate. + void startDuplicateDefinitionForComparison(); + void mergeDuplicateDefinitionWithCommon(const ObjCInterfaceDecl *Definition); + /// Retrieve the superclass type. const ObjCObjectType *getSuperClassType() const { if (TypeSourceInfo *TInfo = getSuperClassTInfo()) @@ -1778,8 +1798,7 @@ public: *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const; - void collectPropertiesToImplement(PropertyMap &PM, - PropertyDeclOrder &PO) const override; + void collectPropertiesToImplement(PropertyMap &PM) const override; /// isSuperClassOf - Return true if this class is the specified class or is a /// super class of the specified interface class. @@ -1895,10 +1914,17 @@ public: const Type *getTypeForDecl() const { return TypeForDecl; } void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; } + /// Get precomputed ODRHash or add a new one. + unsigned getODRHash(); + static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == ObjCInterface; } private: + /// True if a valid hash is stored in ODRHash. + bool hasODRHash() const; + void setHasODRHash(bool HasHash); + const ObjCInterfaceDecl *findInterfaceWithDesignatedInitializers() const; bool inheritsDesignatedInitializers() const; }; @@ -1949,12 +1975,22 @@ public: /// in; this is either the interface where the ivar was declared, or the /// interface the ivar is conceptually a part of in the case of synthesized /// ivars. - const ObjCInterfaceDecl *getContainingInterface() const; + ObjCInterfaceDecl *getContainingInterface(); + const ObjCInterfaceDecl *getContainingInterface() const { + return const_cast<ObjCIvarDecl *>(this)->getContainingInterface(); + } ObjCIvarDecl *getNextIvar() { return NextIvar; } const ObjCIvarDecl *getNextIvar() const { return NextIvar; } void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; } + ObjCIvarDecl *getCanonicalDecl() override { + return cast<ObjCIvarDecl>(FieldDecl::getCanonicalDecl()); + } + const ObjCIvarDecl *getCanonicalDecl() const { + return const_cast<ObjCIvarDecl *>(this)->getCanonicalDecl(); + } + void setAccessControl(AccessControl ac) { DeclAccess = ac; } AccessControl getAccessControl() const { return AccessControl(DeclAccess); } @@ -1980,7 +2016,9 @@ private: ObjCIvarDecl *NextIvar = nullptr; // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum + LLVM_PREFERRED_TYPE(AccessControl) unsigned DeclAccess : 3; + LLVM_PREFERRED_TYPE(bool) unsigned Synthesized : 1; }; @@ -2045,6 +2083,13 @@ class ObjCProtocolDecl : public ObjCContainerDecl, /// Referenced protocols ObjCProtocolList ReferencedProtocols; + + /// Tracks whether a ODR hash has been computed for this protocol. + LLVM_PREFERRED_TYPE(bool) + unsigned HasODRHash : 1; + + /// A hash of parts of the class to help in ODR checking. + unsigned ODRHash = 0; }; /// Contains a pointer to the data associated with this class, @@ -2081,10 +2126,15 @@ class ObjCProtocolDecl : public ObjCContainerDecl, return getMostRecentDecl(); } + /// True if a valid hash is stored in ODRHash. + bool hasODRHash() const; + void setHasODRHash(bool HasHash); + public: friend class ASTDeclReader; friend class ASTDeclWriter; friend class ASTReader; + friend class ODRDiagsEmitter; static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, @@ -2209,6 +2259,13 @@ public: /// Starts the definition of this Objective-C protocol. void startDefinition(); + /// Starts the definition without sharing it with other redeclarations. + /// Such definition shouldn't be used for anything but only to compare if + /// a duplicate is compatible with previous definition or if it is + /// a distinct duplicate. + void startDuplicateDefinitionForComparison(); + void mergeDuplicateDefinitionWithCommon(const ObjCProtocolDecl *Definition); + /// Produce a name to be used for protocol's metadata. It comes either via /// objc_runtime_name attribute or protocol name. StringRef getObjCRuntimeNameAsString() const; @@ -2234,13 +2291,15 @@ public: ObjCProtocolDecl *getCanonicalDecl() override { return getFirstDecl(); } const ObjCProtocolDecl *getCanonicalDecl() const { return getFirstDecl(); } - void collectPropertiesToImplement(PropertyMap &PM, - PropertyDeclOrder &PO) const override; + void collectPropertiesToImplement(PropertyMap &PM) const override; void collectInheritedProtocolProperties(const ObjCPropertyDecl *Property, ProtocolPropertySet &PS, PropertyDeclOrder &PO) const; + /// Get precomputed ODRHash or add a new one. + unsigned getODRHash(); + static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == ObjCProtocol; } }; @@ -2549,9 +2608,11 @@ class ObjCImplementationDecl : public ObjCImplDecl { /// Do the ivars of this class require initialization other than /// zero-initialization? + LLVM_PREFERRED_TYPE(bool) bool HasNonZeroConstructors : 1; /// Do the ivars of this class require non-trivial destruction? + LLVM_PREFERRED_TYPE(bool) bool HasDestructors : 1; ObjCImplementationDecl(DeclContext *DC, @@ -2876,15 +2937,16 @@ ObjCInterfaceDecl::filtered_category_iterator<Filter>::operator++() { } inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) { - return Cat->isUnconditionallyVisible(); + return !Cat->isInvalidDecl() && Cat->isUnconditionallyVisible(); } inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) { - return Cat->IsClassExtension() && Cat->isUnconditionallyVisible(); + return !Cat->isInvalidDecl() && Cat->IsClassExtension() && + Cat->isUnconditionallyVisible(); } inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) { - return Cat->IsClassExtension(); + return !Cat->isInvalidDecl() && Cat->IsClassExtension(); } } // namespace clang |