https://github.com/egorzhdan updated https://github.com/llvm/llvm-project/pull/98201
>From d90ff1e2ff914a6086fe06578594de7cfc11b2af Mon Sep 17 00:00:00 2001 From: Egor Zhdan <e_zh...@apple.com> Date: Tue, 9 Jul 2024 19:53:08 +0100 Subject: [PATCH] [APINotes] Refactor: remove references to `ObjCContext...` 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. --- clang/include/clang/APINotes/APINotesReader.h | 4 +- clang/include/clang/APINotes/APINotesWriter.h | 8 +- clang/include/clang/APINotes/Types.h | 19 ++-- clang/lib/APINotes/APINotesFormat.h | 20 ++-- clang/lib/APINotes/APINotesReader.cpp | 93 +++++++++---------- clang/lib/APINotes/APINotesTypes.cpp | 2 +- clang/lib/APINotes/APINotesWriter.cpp | 71 +++++++------- clang/lib/APINotes/APINotesYAMLCompiler.cpp | 10 +- clang/lib/Sema/SemaAPINotes.cpp | 4 +- 9 files changed, 115 insertions(+), 116 deletions(-) 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..e3aa76df8316c 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 - llvm::BCVBR<16>, // table offset within the blob (see below) - llvm::BCBlob // map from ObjC context IDs to context information. +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..4053d515ef426 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,8 @@ 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, ContextInfo> { public: unsigned getKeyLength(key_type_ref) { return sizeof(uint32_t); } @@ -567,11 +566,11 @@ class ObjCContextInfoTableInfo return static_cast<size_t>(llvm::hash_value(Key)); } - unsigned getUnversionedInfoSize(const ObjCContextInfo &OCI) { + unsigned getUnversionedInfoSize(const ContextInfo &OCI) { return getCommonTypeInfoSize(OCI) + 1; } - void emitUnversionedInfo(raw_ostream &OS, const ObjCContextInfo &OCI) { + void emitUnversionedInfo(raw_ostream &OS, const ContextInfo &OCI) { emitCommonTypeInfo(OS, OCI); uint8_t payload = 0; @@ -590,19 +589,19 @@ class ObjCContextInfoTableInfo }; } // namespace -void APINotesWriter::Implementation::writeObjCContextBlock( +void APINotesWriter::Implementation::writeContextBlock( llvm::BitstreamWriter &Stream) { llvm::BCBlockRAII restoreBlock(Stream, OBJC_CONTEXT_BLOCK_ID, 3); - if (ObjCContexts.empty()) + if (Contexts.empty()) return; { llvm::SmallString<4096> HashTableBlob; uint32_t Offset; { - llvm::OnDiskChainedHashTableGenerator<ObjCContextIDTableInfo> Generator; - for (auto &OC : ObjCContexts) + llvm::OnDiskChainedHashTableGenerator<ContextIDTableInfo> Generator; + for (auto &OC : Contexts) Generator.insert(OC.first, OC.second.first); llvm::raw_svector_ostream BlobStream(HashTableBlob); @@ -612,16 +611,16 @@ void APINotesWriter::Implementation::writeObjCContextBlock( Offset = Generator.Emit(BlobStream); } - objc_context_block::ObjCContextIDLayout ObjCContextID(Stream); - ObjCContextID.emit(Scratch, Offset, HashTableBlob); + context_block::ContextIDLayout ContextID(Stream); + ContextID.emit(Scratch, Offset, HashTableBlob); } { llvm::SmallString<4096> HashTableBlob; uint32_t Offset; { - llvm::OnDiskChainedHashTableGenerator<ObjCContextInfoTableInfo> Generator; - for (auto &OC : ObjCContexts) + llvm::OnDiskChainedHashTableGenerator<ContextInfoTableInfo> Generator; + for (auto &OC : Contexts) Generator.insert(OC.second.first, OC.second.second); llvm::raw_svector_ostream BlobStream(HashTableBlob); @@ -631,8 +630,8 @@ void APINotesWriter::Implementation::writeObjCContextBlock( Offset = Generator.Emit(BlobStream); } - objc_context_block::ObjCContextInfoLayout ObjCContextInfo(Stream); - ObjCContextInfo.emit(Scratch, Offset, HashTableBlob); + context_block::ContextInfoLayout ContextInfo(Stream); + ContextInfo.emit(Scratch, Offset, HashTableBlob); } } @@ -1263,25 +1262,25 @@ void APINotesWriter::writeToStream(llvm::raw_ostream &OS) { Implementation->writeToStream(OS); } -ContextID APINotesWriter::addObjCContext(std::optional<ContextID> ParentCtxID, - StringRef Name, ContextKind Kind, - const ObjCContextInfo &Info, - VersionTuple SwiftVersion) { +ContextID APINotesWriter::addContext(std::optional<ContextID> ParentCtxID, + llvm::StringRef Name, ContextKind Kind, + const ContextInfo &Info, + llvm::VersionTuple SwiftVersion) { IdentifierID NameID = Implementation->getIdentifier(Name); uint32_t RawParentCtxID = ParentCtxID ? ParentCtxID->Value : -1; ContextTableKey Key(RawParentCtxID, static_cast<uint8_t>(Kind), NameID); - auto Known = Implementation->ObjCContexts.find(Key); - if (Known == Implementation->ObjCContexts.end()) { - unsigned NextID = Implementation->ObjCContexts.size() + 1; + auto Known = Implementation->Contexts.find(Key); + if (Known == Implementation->Contexts.end()) { + unsigned NextID = Implementation->Contexts.size() + 1; - Implementation::VersionedSmallVector<ObjCContextInfo> EmptyVersionedInfo; - Known = Implementation->ObjCContexts + Implementation::VersionedSmallVector<ContextInfo> EmptyVersionedInfo; + Known = Implementation->Contexts .insert(std::make_pair( Key, std::make_pair(NextID, EmptyVersionedInfo))) .first; - Implementation->ObjCContextNames[NextID] = NameID; + Implementation->ContextNames[NextID] = NameID; Implementation->ParentContexts[NextID] = RawParentCtxID; } @@ -1328,9 +1327,9 @@ void APINotesWriter::addObjCMethod(ContextID CtxID, ObjCSelectorRef Selector, uint32_t ParentCtxID = Implementation->ParentContexts[CtxID.Value]; ContextTableKey CtxKey(ParentCtxID, static_cast<uint8_t>(ContextKind::ObjCClass), - Implementation->ObjCContextNames[CtxID.Value]); - assert(Implementation->ObjCContexts.contains(CtxKey)); - auto &VersionedVec = Implementation->ObjCContexts[CtxKey].second; + Implementation->ContextNames[CtxID.Value]); + assert(Implementation->Contexts.contains(CtxKey)); + auto &VersionedVec = Implementation->Contexts[CtxKey].second; bool Found = false; for (auto &Versioned : VersionedVec) { if (Versioned.first == SwiftVersion) { @@ -1341,7 +1340,7 @@ void APINotesWriter::addObjCMethod(ContextID CtxID, ObjCSelectorRef Selector, } if (!Found) { - VersionedVec.push_back({SwiftVersion, ObjCContextInfo()}); + VersionedVec.push_back({SwiftVersion, ContextInfo()}); VersionedVec.back().second.setHasDesignatedInits(true); } } diff --git a/clang/lib/APINotes/APINotesYAMLCompiler.cpp b/clang/lib/APINotes/APINotesYAMLCompiler.cpp index 2295d769d344b..870b64e3b7a9b 100644 --- a/clang/lib/APINotes/APINotesYAMLCompiler.cpp +++ b/clang/lib/APINotes/APINotesYAMLCompiler.cpp @@ -786,7 +786,7 @@ class YAMLConverter { void convertContext(std::optional<ContextID> ParentContextID, const Class &C, ContextKind Kind, VersionTuple SwiftVersion) { // Write the class. - ObjCContextInfo CI; + ContextInfo CI; convertCommonType(C, CI, C.Name); if (C.AuditedForNullability) @@ -797,7 +797,7 @@ class YAMLConverter { CI.setSwiftObjCMembers(*C.SwiftObjCMembers); ContextID CtxID = - Writer.addObjCContext(ParentContextID, C.Name, Kind, CI, SwiftVersion); + Writer.addContext(ParentContextID, C.Name, Kind, CI, SwiftVersion); // Write all methods. llvm::StringMap<std::pair<bool, bool>> KnownMethods; @@ -863,12 +863,12 @@ class YAMLConverter { const Namespace &TheNamespace, VersionTuple SwiftVersion) { // Write the namespace. - ObjCContextInfo CI; + ContextInfo CI; convertCommonEntity(TheNamespace, CI, TheNamespace.Name); ContextID CtxID = - Writer.addObjCContext(ParentContextID, TheNamespace.Name, - ContextKind::Namespace, CI, SwiftVersion); + Writer.addContext(ParentContextID, TheNamespace.Name, + ContextKind::Namespace, CI, SwiftVersion); convertTopLevelItems(Context(CtxID, ContextKind::Namespace), TheNamespace.Items, SwiftVersion); diff --git a/clang/lib/Sema/SemaAPINotes.cpp b/clang/lib/Sema/SemaAPINotes.cpp index d535cb35cfbc8..3482f3741fce6 100644 --- a/clang/lib/Sema/SemaAPINotes.cpp +++ b/clang/lib/Sema/SemaAPINotes.cpp @@ -674,7 +674,7 @@ static void ProcessAPINotes(Sema &S, TypedefNameDecl *D, /// Process API notes for an Objective-C class or protocol. static void ProcessAPINotes(Sema &S, ObjCContainerDecl *D, - const api_notes::ObjCContextInfo &Info, + const api_notes::ContextInfo &Info, VersionedInfoMetadata Metadata) { // Handle common type information. ProcessAPINotes(S, D, static_cast<const api_notes::CommonTypeInfo &>(Info), @@ -683,7 +683,7 @@ static void ProcessAPINotes(Sema &S, ObjCContainerDecl *D, /// Process API notes for an Objective-C class. static void ProcessAPINotes(Sema &S, ObjCInterfaceDecl *D, - const api_notes::ObjCContextInfo &Info, + const api_notes::ContextInfo &Info, VersionedInfoMetadata Metadata) { if (auto AsNonGeneric = Info.getSwiftImportAsNonGeneric()) { handleAPINotedAttribute<SwiftImportAsNonGenericAttr>( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits