Skip to content

Commit 82ee7ae

Browse files
authored
[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.
1 parent 2b1b4e3 commit 82ee7ae

File tree

9 files changed

+115
-116
lines changed

9 files changed

+115
-116
lines changed

clang/include/clang/APINotes/APINotesReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class APINotesReader {
101101
/// \param Name The name of the class we're looking for.
102102
///
103103
/// \returns The information about the class, if known.
104-
VersionedInfo<ObjCContextInfo> lookupObjCClassInfo(llvm::StringRef Name);
104+
VersionedInfo<ContextInfo> lookupObjCClassInfo(llvm::StringRef Name);
105105

106106
/// Look for the context ID of the given Objective-C protocol.
107107
///
@@ -115,7 +115,7 @@ class APINotesReader {
115115
/// \param Name The name of the protocol we're looking for.
116116
///
117117
/// \returns The information about the protocol, if known.
118-
VersionedInfo<ObjCContextInfo> lookupObjCProtocolInfo(llvm::StringRef Name);
118+
VersionedInfo<ContextInfo> lookupObjCProtocolInfo(llvm::StringRef Name);
119119

120120
/// Look for information regarding the given Objective-C property in
121121
/// the given context.

clang/include/clang/APINotes/APINotesWriter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class APINotesWriter {
5353
///
5454
/// \returns the ID of the class, protocol, or namespace, which can be used to
5555
/// add properties and methods to the class/protocol/namespace.
56-
ContextID addObjCContext(std::optional<ContextID> ParentCtxID,
57-
llvm::StringRef Name, ContextKind Kind,
58-
const ObjCContextInfo &Info,
59-
llvm::VersionTuple SwiftVersion);
56+
ContextID addContext(std::optional<ContextID> ParentCtxID,
57+
llvm::StringRef Name, ContextKind Kind,
58+
const ContextInfo &Info,
59+
llvm::VersionTuple SwiftVersion);
6060

6161
/// Add information about a specific Objective-C property.
6262
///

clang/include/clang/APINotes/Types.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ inline bool operator!=(const CommonTypeInfo &LHS, const CommonTypeInfo &RHS) {
192192
return !(LHS == RHS);
193193
}
194194

195-
/// Describes API notes data for an Objective-C class or protocol.
196-
class ObjCContextInfo : public CommonTypeInfo {
195+
/// Describes API notes data for an Objective-C class or protocol or a C++
196+
/// namespace.
197+
class ContextInfo : public CommonTypeInfo {
197198
/// Whether this class has a default nullability.
198199
LLVM_PREFERRED_TYPE(bool)
199200
unsigned HasDefaultNullability : 1;
@@ -217,7 +218,7 @@ class ObjCContextInfo : public CommonTypeInfo {
217218
unsigned SwiftObjCMembers : 1;
218219

219220
public:
220-
ObjCContextInfo()
221+
ContextInfo()
221222
: HasDefaultNullability(0), DefaultNullability(0), HasDesignatedInits(0),
222223
SwiftImportAsNonGenericSpecified(false), SwiftImportAsNonGeneric(false),
223224
SwiftObjCMembersSpecified(false), SwiftObjCMembers(false) {}
@@ -269,9 +270,9 @@ class ObjCContextInfo : public CommonTypeInfo {
269270
DefaultNullability = 0;
270271
}
271272

272-
friend bool operator==(const ObjCContextInfo &, const ObjCContextInfo &);
273+
friend bool operator==(const ContextInfo &, const ContextInfo &);
273274

274-
ObjCContextInfo &operator|=(const ObjCContextInfo &RHS) {
275+
ContextInfo &operator|=(const ContextInfo &RHS) {
275276
// Merge inherited info.
276277
static_cast<CommonTypeInfo &>(*this) |= RHS;
277278

@@ -294,15 +295,15 @@ class ObjCContextInfo : public CommonTypeInfo {
294295
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
295296
};
296297

297-
inline bool operator==(const ObjCContextInfo &LHS, const ObjCContextInfo &RHS) {
298+
inline bool operator==(const ContextInfo &LHS, const ContextInfo &RHS) {
298299
return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
299300
LHS.getDefaultNullability() == RHS.getDefaultNullability() &&
300301
LHS.HasDesignatedInits == RHS.HasDesignatedInits &&
301302
LHS.getSwiftImportAsNonGeneric() == RHS.getSwiftImportAsNonGeneric() &&
302303
LHS.getSwiftObjCMembers() == RHS.getSwiftObjCMembers();
303304
}
304305

305-
inline bool operator!=(const ObjCContextInfo &LHS, const ObjCContextInfo &RHS) {
306+
inline bool operator!=(const ContextInfo &LHS, const ContextInfo &RHS) {
306307
return !(LHS == RHS);
307308
}
308309

@@ -387,7 +388,7 @@ class ObjCPropertyInfo : public VariableInfo {
387388
friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &);
388389

389390
/// Merge class-wide information into the given property.
390-
ObjCPropertyInfo &operator|=(const ObjCContextInfo &RHS) {
391+
ObjCPropertyInfo &operator|=(const ContextInfo &RHS) {
391392
static_cast<CommonEntityInfo &>(*this) |= RHS;
392393

393394
// Merge nullability.
@@ -626,7 +627,7 @@ class ObjCMethodInfo : public FunctionInfo {
626627

627628
friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
628629

629-
ObjCMethodInfo &operator|=(const ObjCContextInfo &RHS) {
630+
ObjCMethodInfo &operator|=(const ContextInfo &RHS) {
630631
// Merge Nullability.
631632
if (!NullabilityAudited) {
632633
if (auto Nullable = RHS.getDefaultNullability()) {

clang/lib/APINotes/APINotesFormat.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,26 @@ using IdentifierDataLayout = llvm::BCRecordLayout<
132132
>;
133133
} // namespace identifier_block
134134

135-
namespace objc_context_block {
135+
namespace context_block {
136136
enum {
137-
OBJC_CONTEXT_ID_DATA = 1,
138-
OBJC_CONTEXT_INFO_DATA = 2,
137+
CONTEXT_ID_DATA = 1,
138+
CONTEXT_INFO_DATA = 2,
139139
};
140140

141-
using ObjCContextIDLayout =
142-
llvm::BCRecordLayout<OBJC_CONTEXT_ID_DATA, // record ID
141+
using ContextIDLayout =
142+
llvm::BCRecordLayout<CONTEXT_ID_DATA, // record ID
143143
llvm::BCVBR<16>, // table offset within the blob (see
144144
// below)
145145
llvm::BCBlob // map from ObjC class names/protocol (as
146146
// IDs) to context IDs
147147
>;
148148

149-
using ObjCContextInfoLayout = llvm::BCRecordLayout<
150-
OBJC_CONTEXT_INFO_DATA, // record ID
151-
llvm::BCVBR<16>, // table offset within the blob (see below)
152-
llvm::BCBlob // map from ObjC context IDs to context information.
149+
using ContextInfoLayout = llvm::BCRecordLayout<
150+
CONTEXT_INFO_DATA, // record ID
151+
llvm::BCVBR<16>, // table offset within the blob (see below)
152+
llvm::BCBlob // map from ObjC context IDs to context information.
153153
>;
154-
} // namespace objc_context_block
154+
} // namespace context_block
155155

156156
namespace objc_property_block {
157157
enum {

clang/lib/APINotes/APINotesReader.cpp

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ class IdentifierTableInfo {
176176
}
177177
};
178178

179-
/// Used to deserialize the on-disk Objective-C class table.
180-
class ObjCContextIDTableInfo {
179+
/// Used to deserialize the on-disk table of Objective-C classes and C++
180+
/// namespaces.
181+
class ContextIDTableInfo {
181182
public:
182183
using internal_key_type = ContextTableKey;
183184
using external_key_type = internal_key_type;
@@ -221,9 +222,8 @@ class ObjCContextIDTableInfo {
221222
};
222223

223224
/// Used to deserialize the on-disk Objective-C property table.
224-
class ObjCContextInfoTableInfo
225-
: public VersionedTableInfo<ObjCContextInfoTableInfo, unsigned,
226-
ObjCContextInfo> {
225+
class ContextInfoTableInfo
226+
: public VersionedTableInfo<ContextInfoTableInfo, unsigned, ContextInfo> {
227227
public:
228228
static internal_key_type ReadKey(const uint8_t *Data, unsigned Length) {
229229
return endian::readNext<uint32_t, llvm::endianness::little>(Data);
@@ -233,9 +233,9 @@ class ObjCContextInfoTableInfo
233233
return static_cast<size_t>(llvm::hash_value(Key));
234234
}
235235

236-
static ObjCContextInfo readUnversioned(internal_key_type Key,
237-
const uint8_t *&Data) {
238-
ObjCContextInfo Info;
236+
static ContextInfo readUnversioned(internal_key_type Key,
237+
const uint8_t *&Data) {
238+
ContextInfo Info;
239239
ReadCommonTypeInfo(Data, Info);
240240
uint8_t Payload = *Data++;
241241

@@ -614,17 +614,17 @@ class APINotesReader::Implementation {
614614
/// The identifier table.
615615
std::unique_ptr<SerializedIdentifierTable> IdentifierTable;
616616

617-
using SerializedObjCContextIDTable =
618-
llvm::OnDiskIterableChainedHashTable<ObjCContextIDTableInfo>;
617+
using SerializedContextIDTable =
618+
llvm::OnDiskIterableChainedHashTable<ContextIDTableInfo>;
619619

620-
/// The Objective-C context ID table.
621-
std::unique_ptr<SerializedObjCContextIDTable> ObjCContextIDTable;
620+
/// The Objective-C / C++ context ID table.
621+
std::unique_ptr<SerializedContextIDTable> ContextIDTable;
622622

623-
using SerializedObjCContextInfoTable =
624-
llvm::OnDiskIterableChainedHashTable<ObjCContextInfoTableInfo>;
623+
using SerializedContextInfoTable =
624+
llvm::OnDiskIterableChainedHashTable<ContextInfoTableInfo>;
625625

626626
/// The Objective-C context info table.
627-
std::unique_ptr<SerializedObjCContextInfoTable> ObjCContextInfoTable;
627+
std::unique_ptr<SerializedContextInfoTable> ContextInfoTable;
628628

629629
using SerializedObjCPropertyTable =
630630
llvm::OnDiskIterableChainedHashTable<ObjCPropertyTableInfo>;
@@ -685,8 +685,8 @@ class APINotesReader::Implementation {
685685
llvm::SmallVectorImpl<uint64_t> &Scratch);
686686
bool readIdentifierBlock(llvm::BitstreamCursor &Cursor,
687687
llvm::SmallVectorImpl<uint64_t> &Scratch);
688-
bool readObjCContextBlock(llvm::BitstreamCursor &Cursor,
689-
llvm::SmallVectorImpl<uint64_t> &Scratch);
688+
bool readContextBlock(llvm::BitstreamCursor &Cursor,
689+
llvm::SmallVectorImpl<uint64_t> &Scratch);
690690
bool readObjCPropertyBlock(llvm::BitstreamCursor &Cursor,
691691
llvm::SmallVectorImpl<uint64_t> &Scratch);
692692
bool readObjCMethodBlock(llvm::BitstreamCursor &Cursor,
@@ -906,7 +906,7 @@ bool APINotesReader::Implementation::readIdentifierBlock(
906906
return false;
907907
}
908908

909-
bool APINotesReader::Implementation::readObjCContextBlock(
909+
bool APINotesReader::Implementation::readContextBlock(
910910
llvm::BitstreamCursor &Cursor, llvm::SmallVectorImpl<uint64_t> &Scratch) {
911911
if (Cursor.EnterSubBlock(OBJC_CONTEXT_BLOCK_ID))
912912
return true;
@@ -950,31 +950,30 @@ bool APINotesReader::Implementation::readObjCContextBlock(
950950
}
951951
unsigned Kind = MaybeKind.get();
952952
switch (Kind) {
953-
case objc_context_block::OBJC_CONTEXT_ID_DATA: {
954-
// Already saw Objective-C context ID table.
955-
if (ObjCContextIDTable)
953+
case context_block::CONTEXT_ID_DATA: {
954+
// Already saw Objective-C / C++ context ID table.
955+
if (ContextIDTable)
956956
return true;
957957

958958
uint32_t tableOffset;
959-
objc_context_block::ObjCContextIDLayout::readRecord(Scratch, tableOffset);
959+
context_block::ContextIDLayout::readRecord(Scratch, tableOffset);
960960
auto base = reinterpret_cast<const uint8_t *>(BlobData.data());
961961

962-
ObjCContextIDTable.reset(SerializedObjCContextIDTable::Create(
962+
ContextIDTable.reset(SerializedContextIDTable::Create(
963963
base + tableOffset, base + sizeof(uint32_t), base));
964964
break;
965965
}
966966

967-
case objc_context_block::OBJC_CONTEXT_INFO_DATA: {
968-
// Already saw Objective-C context info table.
969-
if (ObjCContextInfoTable)
967+
case context_block::CONTEXT_INFO_DATA: {
968+
// Already saw Objective-C / C++ context info table.
969+
if (ContextInfoTable)
970970
return true;
971971

972972
uint32_t tableOffset;
973-
objc_context_block::ObjCContextInfoLayout::readRecord(Scratch,
974-
tableOffset);
973+
context_block::ContextInfoLayout::readRecord(Scratch, tableOffset);
975974
auto base = reinterpret_cast<const uint8_t *>(BlobData.data());
976975

977-
ObjCContextInfoTable.reset(SerializedObjCContextInfoTable::Create(
976+
ContextInfoTable.reset(SerializedContextInfoTable::Create(
978977
base + tableOffset, base + sizeof(uint32_t), base));
979978
break;
980979
}
@@ -1678,7 +1677,7 @@ APINotesReader::APINotesReader(llvm::MemoryBuffer *InputBuffer,
16781677

16791678
case OBJC_CONTEXT_BLOCK_ID:
16801679
if (!HasValidControlBlock ||
1681-
Implementation->readObjCContextBlock(Cursor, Scratch)) {
1680+
Implementation->readContextBlock(Cursor, Scratch)) {
16821681
Failed = true;
16831682
return;
16841683
}
@@ -1815,7 +1814,7 @@ APINotesReader::VersionedInfo<T>::VersionedInfo(
18151814

18161815
auto APINotesReader::lookupObjCClassID(llvm::StringRef Name)
18171816
-> std::optional<ContextID> {
1818-
if (!Implementation->ObjCContextIDTable)
1817+
if (!Implementation->ContextIDTable)
18191818
return std::nullopt;
18201819

18211820
std::optional<IdentifierID> ClassID = Implementation->getIdentifier(Name);
@@ -1824,33 +1823,33 @@ auto APINotesReader::lookupObjCClassID(llvm::StringRef Name)
18241823

18251824
// ObjC classes can't be declared in C++ namespaces, so use -1 as the global
18261825
// context.
1827-
auto KnownID = Implementation->ObjCContextIDTable->find(
1826+
auto KnownID = Implementation->ContextIDTable->find(
18281827
ContextTableKey(-1, (uint8_t)ContextKind::ObjCClass, *ClassID));
1829-
if (KnownID == Implementation->ObjCContextIDTable->end())
1828+
if (KnownID == Implementation->ContextIDTable->end())
18301829
return std::nullopt;
18311830

18321831
return ContextID(*KnownID);
18331832
}
18341833

18351834
auto APINotesReader::lookupObjCClassInfo(llvm::StringRef Name)
1836-
-> VersionedInfo<ObjCContextInfo> {
1837-
if (!Implementation->ObjCContextInfoTable)
1835+
-> VersionedInfo<ContextInfo> {
1836+
if (!Implementation->ContextInfoTable)
18381837
return std::nullopt;
18391838

18401839
std::optional<ContextID> CtxID = lookupObjCClassID(Name);
18411840
if (!CtxID)
18421841
return std::nullopt;
18431842

1844-
auto KnownInfo = Implementation->ObjCContextInfoTable->find(CtxID->Value);
1845-
if (KnownInfo == Implementation->ObjCContextInfoTable->end())
1843+
auto KnownInfo = Implementation->ContextInfoTable->find(CtxID->Value);
1844+
if (KnownInfo == Implementation->ContextInfoTable->end())
18461845
return std::nullopt;
18471846

18481847
return {Implementation->SwiftVersion, *KnownInfo};
18491848
}
18501849

18511850
auto APINotesReader::lookupObjCProtocolID(llvm::StringRef Name)
18521851
-> std::optional<ContextID> {
1853-
if (!Implementation->ObjCContextIDTable)
1852+
if (!Implementation->ContextIDTable)
18541853
return std::nullopt;
18551854

18561855
std::optional<IdentifierID> classID = Implementation->getIdentifier(Name);
@@ -1859,25 +1858,25 @@ auto APINotesReader::lookupObjCProtocolID(llvm::StringRef Name)
18591858

18601859
// ObjC classes can't be declared in C++ namespaces, so use -1 as the global
18611860
// context.
1862-
auto KnownID = Implementation->ObjCContextIDTable->find(
1861+
auto KnownID = Implementation->ContextIDTable->find(
18631862
ContextTableKey(-1, (uint8_t)ContextKind::ObjCProtocol, *classID));
1864-
if (KnownID == Implementation->ObjCContextIDTable->end())
1863+
if (KnownID == Implementation->ContextIDTable->end())
18651864
return std::nullopt;
18661865

18671866
return ContextID(*KnownID);
18681867
}
18691868

18701869
auto APINotesReader::lookupObjCProtocolInfo(llvm::StringRef Name)
1871-
-> VersionedInfo<ObjCContextInfo> {
1872-
if (!Implementation->ObjCContextInfoTable)
1870+
-> VersionedInfo<ContextInfo> {
1871+
if (!Implementation->ContextInfoTable)
18731872
return std::nullopt;
18741873

18751874
std::optional<ContextID> CtxID = lookupObjCProtocolID(Name);
18761875
if (!CtxID)
18771876
return std::nullopt;
18781877

1879-
auto KnownInfo = Implementation->ObjCContextInfoTable->find(CtxID->Value);
1880-
if (KnownInfo == Implementation->ObjCContextInfoTable->end())
1878+
auto KnownInfo = Implementation->ContextInfoTable->find(CtxID->Value);
1879+
if (KnownInfo == Implementation->ContextInfoTable->end())
18811880
return std::nullopt;
18821881

18831882
return {Implementation->SwiftVersion, *KnownInfo};
@@ -2014,7 +2013,7 @@ auto APINotesReader::lookupTypedef(llvm::StringRef Name,
20142013
auto APINotesReader::lookupNamespaceID(
20152014
llvm::StringRef Name, std::optional<ContextID> ParentNamespaceID)
20162015
-> std::optional<ContextID> {
2017-
if (!Implementation->ObjCContextIDTable)
2016+
if (!Implementation->ContextIDTable)
20182017
return std::nullopt;
20192018

20202019
std::optional<IdentifierID> NamespaceID = Implementation->getIdentifier(Name);
@@ -2023,9 +2022,9 @@ auto APINotesReader::lookupNamespaceID(
20232022

20242023
uint32_t RawParentNamespaceID =
20252024
ParentNamespaceID ? ParentNamespaceID->Value : -1;
2026-
auto KnownID = Implementation->ObjCContextIDTable->find(
2025+
auto KnownID = Implementation->ContextIDTable->find(
20272026
{RawParentNamespaceID, (uint8_t)ContextKind::Namespace, *NamespaceID});
2028-
if (KnownID == Implementation->ObjCContextIDTable->end())
2027+
if (KnownID == Implementation->ContextIDTable->end())
20292028
return std::nullopt;
20302029

20312030
return ContextID(*KnownID);

clang/lib/APINotes/APINotesTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ LLVM_DUMP_METHOD void CommonTypeInfo::dump(llvm::raw_ostream &OS) const {
3232
OS << '\n';
3333
}
3434

35-
LLVM_DUMP_METHOD void ObjCContextInfo::dump(llvm::raw_ostream &OS) {
35+
LLVM_DUMP_METHOD void ContextInfo::dump(llvm::raw_ostream &OS) {
3636
static_cast<CommonTypeInfo &>(*this).dump(OS);
3737
if (HasDefaultNullability)
3838
OS << "DefaultNullability: " << DefaultNullability << ' ';

0 commit comments

Comments
 (0)