llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Egor Zhdan (egorzhdan) <details> <summary>Changes</summary> API Notes now support in C++. In preparation for supporting C++ methods in API Notes, this change renames the remaining usages of `ObjCContextABC` into `ContextABC` to make it clear that those contexts might actually be C++, not Objective-C. This is NFC-ish. --- Patch is 28.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/98201.diff 9 Files Affected: - (modified) clang/include/clang/APINotes/APINotesReader.h (+2-2) - (modified) clang/include/clang/APINotes/APINotesWriter.h (+4-4) - (modified) clang/include/clang/APINotes/Types.h (+10-9) - (modified) clang/lib/APINotes/APINotesFormat.h (+8-8) - (modified) clang/lib/APINotes/APINotesReader.cpp (+46-47) - (modified) clang/lib/APINotes/APINotesTypes.cpp (+1-1) - (modified) clang/lib/APINotes/APINotesWriter.cpp (+36-36) - (modified) clang/lib/APINotes/APINotesYAMLCompiler.cpp (+5-5) - (modified) clang/lib/Sema/SemaAPINotes.cpp (+2-2) ``````````diff diff --git a/clang/include/clang/APINotes/APINotesReader.h b/clang/include/clang/APINotes/APINotesReader.h index 1c5aab0959550..37a4ff7a69712 100644 --- a/clang/include/clang/APINotes/APINotesReader.h +++ b/clang/include/clang/APINotes/APINotesReader.h @@ -101,7 +101,7 @@ class APINotesReader { /// \param Name The name of the class we're looking for. /// /// \returns The information about the class, if known. - VersionedInfo<ObjCContextInfo> lookupObjCClassInfo(llvm::StringRef Name); + VersionedInfo<ContextInfo> lookupObjCClassInfo(llvm::StringRef Name); /// Look for the context ID of the given Objective-C protocol. /// @@ -115,7 +115,7 @@ class APINotesReader { /// \param Name The name of the protocol we're looking for. /// /// \returns The information about the protocol, if known. - VersionedInfo<ObjCContextInfo> lookupObjCProtocolInfo(llvm::StringRef Name); + VersionedInfo<ContextInfo> lookupObjCProtocolInfo(llvm::StringRef Name); /// Look for information regarding the given Objective-C property in /// the given context. diff --git a/clang/include/clang/APINotes/APINotesWriter.h b/clang/include/clang/APINotes/APINotesWriter.h index c5ca3e4617796..e82dbc7c9540e 100644 --- a/clang/include/clang/APINotes/APINotesWriter.h +++ b/clang/include/clang/APINotes/APINotesWriter.h @@ -53,10 +53,10 @@ class APINotesWriter { /// /// \returns the ID of the class, protocol, or namespace, which can be used to /// add properties and methods to the class/protocol/namespace. - ContextID addObjCContext(std::optional<ContextID> ParentCtxID, - llvm::StringRef Name, ContextKind Kind, - const ObjCContextInfo &Info, - llvm::VersionTuple SwiftVersion); + ContextID addContext(std::optional<ContextID> ParentCtxID, + llvm::StringRef Name, ContextKind Kind, + const ContextInfo &Info, + llvm::VersionTuple SwiftVersion); /// Add information about a specific Objective-C property. /// diff --git a/clang/include/clang/APINotes/Types.h b/clang/include/clang/APINotes/Types.h index 026a4a431e734..daf2f1897f46b 100644 --- a/clang/include/clang/APINotes/Types.h +++ b/clang/include/clang/APINotes/Types.h @@ -192,8 +192,9 @@ inline bool operator!=(const CommonTypeInfo &LHS, const CommonTypeInfo &RHS) { return !(LHS == RHS); } -/// Describes API notes data for an Objective-C class or protocol. -class ObjCContextInfo : public CommonTypeInfo { +/// Describes API notes data for an Objective-C class or protocol or a C++ +/// namespace. +class ContextInfo : public CommonTypeInfo { /// Whether this class has a default nullability. LLVM_PREFERRED_TYPE(bool) unsigned HasDefaultNullability : 1; @@ -217,7 +218,7 @@ class ObjCContextInfo : public CommonTypeInfo { unsigned SwiftObjCMembers : 1; public: - ObjCContextInfo() + ContextInfo() : HasDefaultNullability(0), DefaultNullability(0), HasDesignatedInits(0), SwiftImportAsNonGenericSpecified(false), SwiftImportAsNonGeneric(false), SwiftObjCMembersSpecified(false), SwiftObjCMembers(false) {} @@ -269,9 +270,9 @@ class ObjCContextInfo : public CommonTypeInfo { DefaultNullability = 0; } - friend bool operator==(const ObjCContextInfo &, const ObjCContextInfo &); + friend bool operator==(const ContextInfo &, const ContextInfo &); - ObjCContextInfo &operator|=(const ObjCContextInfo &RHS) { + ContextInfo &operator|=(const ContextInfo &RHS) { // Merge inherited info. static_cast<CommonTypeInfo &>(*this) |= RHS; @@ -294,7 +295,7 @@ class ObjCContextInfo : public CommonTypeInfo { LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS); }; -inline bool operator==(const ObjCContextInfo &LHS, const ObjCContextInfo &RHS) { +inline bool operator==(const ContextInfo &LHS, const ContextInfo &RHS) { return static_cast<const CommonTypeInfo &>(LHS) == RHS && LHS.getDefaultNullability() == RHS.getDefaultNullability() && LHS.HasDesignatedInits == RHS.HasDesignatedInits && @@ -302,7 +303,7 @@ inline bool operator==(const ObjCContextInfo &LHS, const ObjCContextInfo &RHS) { LHS.getSwiftObjCMembers() == RHS.getSwiftObjCMembers(); } -inline bool operator!=(const ObjCContextInfo &LHS, const ObjCContextInfo &RHS) { +inline bool operator!=(const ContextInfo &LHS, const ContextInfo &RHS) { return !(LHS == RHS); } @@ -387,7 +388,7 @@ class ObjCPropertyInfo : public VariableInfo { friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &); /// Merge class-wide information into the given property. - ObjCPropertyInfo &operator|=(const ObjCContextInfo &RHS) { + ObjCPropertyInfo &operator|=(const ContextInfo &RHS) { static_cast<CommonEntityInfo &>(*this) |= RHS; // Merge nullability. @@ -626,7 +627,7 @@ class ObjCMethodInfo : public FunctionInfo { friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &); - ObjCMethodInfo &operator|=(const ObjCContextInfo &RHS) { + ObjCMethodInfo &operator|=(const ContextInfo &RHS) { // Merge Nullability. if (!NullabilityAudited) { if (auto Nullable = RHS.getDefaultNullability()) { diff --git a/clang/lib/APINotes/APINotesFormat.h b/clang/lib/APINotes/APINotesFormat.h index 97e630e97fdcc..3cbe890eb31da 100644 --- a/clang/lib/APINotes/APINotesFormat.h +++ b/clang/lib/APINotes/APINotesFormat.h @@ -132,26 +132,26 @@ using IdentifierDataLayout = llvm::BCRecordLayout< >; } // namespace identifier_block -namespace objc_context_block { +namespace context_block { enum { - OBJC_CONTEXT_ID_DATA = 1, - OBJC_CONTEXT_INFO_DATA = 2, + CONTEXT_ID_DATA = 1, + CONTEXT_INFO_DATA = 2, }; -using ObjCContextIDLayout = - llvm::BCRecordLayout<OBJC_CONTEXT_ID_DATA, // record ID +using ContextIDLayout = + llvm::BCRecordLayout<CONTEXT_ID_DATA, // record ID llvm::BCVBR<16>, // table offset within the blob (see // below) llvm::BCBlob // map from ObjC class names/protocol (as // IDs) to context IDs >; -using ObjCContextInfoLayout = llvm::BCRecordLayout< - OBJC_CONTEXT_INFO_DATA, // record ID +using ContextInfoLayout = llvm::BCRecordLayout< + CONTEXT_INFO_DATA, // record ID llvm::BCVBR<16>, // table offset within the blob (see below) llvm::BCBlob // map from ObjC context IDs to context information. >; -} // namespace objc_context_block +} // namespace context_block namespace objc_property_block { enum { diff --git a/clang/lib/APINotes/APINotesReader.cpp b/clang/lib/APINotes/APINotesReader.cpp index b60ca685f62c9..8454e092b55ac 100644 --- a/clang/lib/APINotes/APINotesReader.cpp +++ b/clang/lib/APINotes/APINotesReader.cpp @@ -176,8 +176,9 @@ class IdentifierTableInfo { } }; -/// Used to deserialize the on-disk Objective-C class table. -class ObjCContextIDTableInfo { +/// Used to deserialize the on-disk table of Objective-C classes and C++ +/// namespaces. +class ContextIDTableInfo { public: using internal_key_type = ContextTableKey; using external_key_type = internal_key_type; @@ -221,9 +222,8 @@ class ObjCContextIDTableInfo { }; /// Used to deserialize the on-disk Objective-C property table. -class ObjCContextInfoTableInfo - : public VersionedTableInfo<ObjCContextInfoTableInfo, unsigned, - ObjCContextInfo> { +class ContextInfoTableInfo + : public VersionedTableInfo<ContextInfoTableInfo, unsigned, ContextInfo> { public: static internal_key_type ReadKey(const uint8_t *Data, unsigned Length) { return endian::readNext<uint32_t, llvm::endianness::little>(Data); @@ -233,9 +233,9 @@ class ObjCContextInfoTableInfo return static_cast<size_t>(llvm::hash_value(Key)); } - static ObjCContextInfo readUnversioned(internal_key_type Key, - const uint8_t *&Data) { - ObjCContextInfo Info; + static ContextInfo readUnversioned(internal_key_type Key, + const uint8_t *&Data) { + ContextInfo Info; ReadCommonTypeInfo(Data, Info); uint8_t Payload = *Data++; @@ -614,17 +614,17 @@ class APINotesReader::Implementation { /// The identifier table. std::unique_ptr<SerializedIdentifierTable> IdentifierTable; - using SerializedObjCContextIDTable = - llvm::OnDiskIterableChainedHashTable<ObjCContextIDTableInfo>; + using SerializedContextIDTable = + llvm::OnDiskIterableChainedHashTable<ContextIDTableInfo>; - /// The Objective-C context ID table. - std::unique_ptr<SerializedObjCContextIDTable> ObjCContextIDTable; + /// The Objective-C / C++ context ID table. + std::unique_ptr<SerializedContextIDTable> ContextIDTable; - using SerializedObjCContextInfoTable = - llvm::OnDiskIterableChainedHashTable<ObjCContextInfoTableInfo>; + using SerializedContextInfoTable = + llvm::OnDiskIterableChainedHashTable<ContextInfoTableInfo>; /// The Objective-C context info table. - std::unique_ptr<SerializedObjCContextInfoTable> ObjCContextInfoTable; + std::unique_ptr<SerializedContextInfoTable> ContextInfoTable; using SerializedObjCPropertyTable = llvm::OnDiskIterableChainedHashTable<ObjCPropertyTableInfo>; @@ -685,8 +685,8 @@ class APINotesReader::Implementation { llvm::SmallVectorImpl<uint64_t> &Scratch); bool readIdentifierBlock(llvm::BitstreamCursor &Cursor, llvm::SmallVectorImpl<uint64_t> &Scratch); - bool readObjCContextBlock(llvm::BitstreamCursor &Cursor, - llvm::SmallVectorImpl<uint64_t> &Scratch); + bool readContextBlock(llvm::BitstreamCursor &Cursor, + llvm::SmallVectorImpl<uint64_t> &Scratch); bool readObjCPropertyBlock(llvm::BitstreamCursor &Cursor, llvm::SmallVectorImpl<uint64_t> &Scratch); bool readObjCMethodBlock(llvm::BitstreamCursor &Cursor, @@ -906,7 +906,7 @@ bool APINotesReader::Implementation::readIdentifierBlock( return false; } -bool APINotesReader::Implementation::readObjCContextBlock( +bool APINotesReader::Implementation::readContextBlock( llvm::BitstreamCursor &Cursor, llvm::SmallVectorImpl<uint64_t> &Scratch) { if (Cursor.EnterSubBlock(OBJC_CONTEXT_BLOCK_ID)) return true; @@ -950,31 +950,30 @@ bool APINotesReader::Implementation::readObjCContextBlock( } unsigned Kind = MaybeKind.get(); switch (Kind) { - case objc_context_block::OBJC_CONTEXT_ID_DATA: { - // Already saw Objective-C context ID table. - if (ObjCContextIDTable) + case context_block::CONTEXT_ID_DATA: { + // Already saw Objective-C / C++ context ID table. + if (ContextIDTable) return true; uint32_t tableOffset; - objc_context_block::ObjCContextIDLayout::readRecord(Scratch, tableOffset); + context_block::ContextIDLayout::readRecord(Scratch, tableOffset); auto base = reinterpret_cast<const uint8_t *>(BlobData.data()); - ObjCContextIDTable.reset(SerializedObjCContextIDTable::Create( + ContextIDTable.reset(SerializedContextIDTable::Create( base + tableOffset, base + sizeof(uint32_t), base)); break; } - case objc_context_block::OBJC_CONTEXT_INFO_DATA: { - // Already saw Objective-C context info table. - if (ObjCContextInfoTable) + case context_block::CONTEXT_INFO_DATA: { + // Already saw Objective-C / C++ context info table. + if (ContextInfoTable) return true; uint32_t tableOffset; - objc_context_block::ObjCContextInfoLayout::readRecord(Scratch, - tableOffset); + context_block::ContextInfoLayout::readRecord(Scratch, tableOffset); auto base = reinterpret_cast<const uint8_t *>(BlobData.data()); - ObjCContextInfoTable.reset(SerializedObjCContextInfoTable::Create( + ContextInfoTable.reset(SerializedContextInfoTable::Create( base + tableOffset, base + sizeof(uint32_t), base)); break; } @@ -1678,7 +1677,7 @@ APINotesReader::APINotesReader(llvm::MemoryBuffer *InputBuffer, case OBJC_CONTEXT_BLOCK_ID: if (!HasValidControlBlock || - Implementation->readObjCContextBlock(Cursor, Scratch)) { + Implementation->readContextBlock(Cursor, Scratch)) { Failed = true; return; } @@ -1815,7 +1814,7 @@ APINotesReader::VersionedInfo<T>::VersionedInfo( auto APINotesReader::lookupObjCClassID(llvm::StringRef Name) -> std::optional<ContextID> { - if (!Implementation->ObjCContextIDTable) + if (!Implementation->ContextIDTable) return std::nullopt; std::optional<IdentifierID> ClassID = Implementation->getIdentifier(Name); @@ -1824,25 +1823,25 @@ auto APINotesReader::lookupObjCClassID(llvm::StringRef Name) // ObjC classes can't be declared in C++ namespaces, so use -1 as the global // context. - auto KnownID = Implementation->ObjCContextIDTable->find( + auto KnownID = Implementation->ContextIDTable->find( ContextTableKey(-1, (uint8_t)ContextKind::ObjCClass, *ClassID)); - if (KnownID == Implementation->ObjCContextIDTable->end()) + if (KnownID == Implementation->ContextIDTable->end()) return std::nullopt; return ContextID(*KnownID); } auto APINotesReader::lookupObjCClassInfo(llvm::StringRef Name) - -> VersionedInfo<ObjCContextInfo> { - if (!Implementation->ObjCContextInfoTable) + -> VersionedInfo<ContextInfo> { + if (!Implementation->ContextInfoTable) return std::nullopt; std::optional<ContextID> CtxID = lookupObjCClassID(Name); if (!CtxID) return std::nullopt; - auto KnownInfo = Implementation->ObjCContextInfoTable->find(CtxID->Value); - if (KnownInfo == Implementation->ObjCContextInfoTable->end()) + auto KnownInfo = Implementation->ContextInfoTable->find(CtxID->Value); + if (KnownInfo == Implementation->ContextInfoTable->end()) return std::nullopt; return {Implementation->SwiftVersion, *KnownInfo}; @@ -1850,7 +1849,7 @@ auto APINotesReader::lookupObjCClassInfo(llvm::StringRef Name) auto APINotesReader::lookupObjCProtocolID(llvm::StringRef Name) -> std::optional<ContextID> { - if (!Implementation->ObjCContextIDTable) + if (!Implementation->ContextIDTable) return std::nullopt; std::optional<IdentifierID> classID = Implementation->getIdentifier(Name); @@ -1859,25 +1858,25 @@ auto APINotesReader::lookupObjCProtocolID(llvm::StringRef Name) // ObjC classes can't be declared in C++ namespaces, so use -1 as the global // context. - auto KnownID = Implementation->ObjCContextIDTable->find( + auto KnownID = Implementation->ContextIDTable->find( ContextTableKey(-1, (uint8_t)ContextKind::ObjCProtocol, *classID)); - if (KnownID == Implementation->ObjCContextIDTable->end()) + if (KnownID == Implementation->ContextIDTable->end()) return std::nullopt; return ContextID(*KnownID); } auto APINotesReader::lookupObjCProtocolInfo(llvm::StringRef Name) - -> VersionedInfo<ObjCContextInfo> { - if (!Implementation->ObjCContextInfoTable) + -> VersionedInfo<ContextInfo> { + if (!Implementation->ContextInfoTable) return std::nullopt; std::optional<ContextID> CtxID = lookupObjCProtocolID(Name); if (!CtxID) return std::nullopt; - auto KnownInfo = Implementation->ObjCContextInfoTable->find(CtxID->Value); - if (KnownInfo == Implementation->ObjCContextInfoTable->end()) + auto KnownInfo = Implementation->ContextInfoTable->find(CtxID->Value); + if (KnownInfo == Implementation->ContextInfoTable->end()) return std::nullopt; return {Implementation->SwiftVersion, *KnownInfo}; @@ -2014,7 +2013,7 @@ auto APINotesReader::lookupTypedef(llvm::StringRef Name, auto APINotesReader::lookupNamespaceID( llvm::StringRef Name, std::optional<ContextID> ParentNamespaceID) -> std::optional<ContextID> { - if (!Implementation->ObjCContextIDTable) + if (!Implementation->ContextIDTable) return std::nullopt; std::optional<IdentifierID> NamespaceID = Implementation->getIdentifier(Name); @@ -2023,9 +2022,9 @@ auto APINotesReader::lookupNamespaceID( uint32_t RawParentNamespaceID = ParentNamespaceID ? ParentNamespaceID->Value : -1; - auto KnownID = Implementation->ObjCContextIDTable->find( + auto KnownID = Implementation->ContextIDTable->find( {RawParentNamespaceID, (uint8_t)ContextKind::Namespace, *NamespaceID}); - if (KnownID == Implementation->ObjCContextIDTable->end()) + if (KnownID == Implementation->ContextIDTable->end()) return std::nullopt; return ContextID(*KnownID); diff --git a/clang/lib/APINotes/APINotesTypes.cpp b/clang/lib/APINotes/APINotesTypes.cpp index c0bb726ea72be..a87ecb3bc30ee 100644 --- a/clang/lib/APINotes/APINotesTypes.cpp +++ b/clang/lib/APINotes/APINotesTypes.cpp @@ -32,7 +32,7 @@ LLVM_DUMP_METHOD void CommonTypeInfo::dump(llvm::raw_ostream &OS) const { OS << '\n'; } -LLVM_DUMP_METHOD void ObjCContextInfo::dump(llvm::raw_ostream &OS) { +LLVM_DUMP_METHOD void ContextInfo::dump(llvm::raw_ostream &OS) { static_cast<CommonTypeInfo &>(*this).dump(OS); if (HasDefaultNullability) OS << "DefaultNullability: " << DefaultNullability << ' '; diff --git a/clang/lib/APINotes/APINotesWriter.cpp b/clang/lib/APINotes/APINotesWriter.cpp index 3e61597631509..0eea4f139a3e3 100644 --- a/clang/lib/APINotes/APINotesWriter.cpp +++ b/clang/lib/APINotes/APINotesWriter.cpp @@ -42,8 +42,8 @@ class APINotesWriter::Implementation { /// this context and provides both the context ID and information describing /// the context within that module. llvm::DenseMap<ContextTableKey, - std::pair<unsigned, VersionedSmallVector<ObjCContextInfo>>> - ObjCContexts; + std::pair<unsigned, VersionedSmallVector<ContextInfo>>> + Contexts; /// Information about parent contexts for each context. /// @@ -51,7 +51,7 @@ class APINotesWriter::Implementation { llvm::DenseMap<uint32_t, uint32_t> ParentContexts; /// Mapping from context IDs to the identifier ID holding the name. - llvm::DenseMap<unsigned, unsigned> ObjCContextNames; + llvm::DenseMap<unsigned, unsigned> ContextNames; /// Information about Objective-C properties. /// @@ -147,7 +147,7 @@ class APINotesWriter::Implementation { void writeBlockInfoBlock(llvm::BitstreamWriter &Stream); void writeControlBlock(llvm::BitstreamWriter &Stream); void writeIdentifierBlock(llvm::BitstreamWriter &Stream); - void writeObjCContextBlock(llvm::BitstreamWriter &Stream); + void writeContextBlock(llvm::BitstreamWriter &Stream); void writeObjCPropertyBlock(llvm::BitstreamWriter &Stream); void writeObjCMethodBlock(llvm::BitstreamWriter &Stream); void writeObjCSelectorBlock(llvm::BitstreamWriter &Stream); @@ -178,7 +178,7 @@ void APINotesWriter::Implementation::writeToStream(llvm::raw_ostream &OS) { writeBlockInfoBlock(Stream); writeControlBlock(Stream); writeIdentifierBlock(Stream); - writeObjCContextBlock(Stream); + writeContextBlock(Stream); writeObjCPropertyBlock(Stream); writeObjCMethodBlock(Stream); writeObjCSelectorBlock(Stream); @@ -240,7 +240,7 @@ void APINotesWriter::Implementation::writeBlockInfoBlock( BLOCK_RECORD(identifier_block, IDENTIFIER_DATA); BLOCK(OBJC_CONTEXT_BLOCK); - BLOCK_RECORD(objc_context_block, OBJC_CONTEXT_ID_DATA); + BLOCK_RECORD(context_block, CONTEXT_ID_DATA); BLOCK(OBJC_PROPERTY_BLOCK); BLOCK_RECORD(objc_property_block, OBJC_PROPERTY_DATA); @@ -337,7 +337,7 @@ void APINotesWriter::Implementation::writeIdentifierBlock( namespace { /// Used to serialize the on-disk Objective-C context table. -class ObjCContextIDTableInfo { +class ContextIDTableInfo { public: using key_type = ContextTableKey; using key_type_ref = key_type; @@ -552,9 +552,9 @@ void emitCommonTypeInfo(raw_ostream &OS, const CommonTypeInfo &CTI) { } /// Used to serialize the on-disk Objective-C property table. -class ObjCContextInfoTableInfo - : public VersionedTableInfo<ObjCContextInfoTableInfo, unsigned, - ObjCContextInfo> { +class ContextInfoTableInfo + : public VersionedTableInfo<ContextInfoTableInfo, unsigned, + ... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/98201 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits