Ruturaj4 updated this revision to Diff 546682.
Ruturaj4 marked 4 inline comments as done.
Ruturaj4 added a comment.
1. Updating D152770 <https://reviews.llvm.org/D152770>: [clang][ExtractAPI] Add
support for Objective-C categories #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create
Made all the changes according to comments.
1. Removed check on line #219 to include unique USR for categories.
2. Explained how multiple categories to the same type are supported.
3. Added new relationship "extensionTo".
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152770/new/
https://reviews.llvm.org/D152770
Files:
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/test/ExtractAPI/objc_module_category.m
clang/test/ExtractAPI/objc_various_categories.m
Index: clang/test/ExtractAPI/objc_various_categories.m
===================================================================
--- clang/test/ExtractAPI/objc_various_categories.m
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -77,7 +77,7 @@
"targetFallback": "MyClass1"
},
{
- "kind": "memberOf",
+ "kind": "extensionTo",
"source": "c:objc(cy)MyClass2@MyCategory2",
"target": "c:objc(cs)MyClass2",
"targetFallback": "MyClass2"
@@ -89,7 +89,7 @@
"targetFallback": "MyCategory2"
},
{
- "kind": "memberOf",
+ "kind": "extensionTo",
"source": "c:objc(cy)NSString@Category1",
"target": "c:objc(cs)NSString",
"targetFallback": "NSString"
@@ -101,7 +101,7 @@
"targetFallback": "Category1"
},
{
- "kind": "memberOf",
+ "kind": "extensionTo",
"source": "c:objc(cy)NSString@Category2",
"target": "c:objc(cs)NSString",
"targetFallback": "NSString"
@@ -241,7 +241,7 @@
"accessLevel": "public",
"identifier": {
"interfaceLanguage": "objective-c",
- "precise": "c:objc(cs)MyClass2"
+ "precise": "c:objc(cy)MyClass2@MyCategory2"
},
"kind": {
"displayName": "Module Extension",
@@ -279,7 +279,7 @@
],
"identifier": {
"interfaceLanguage": "objective-c",
- "precise": "c:objc(cs)MyClass2"
+ "precise": "c:objc(cy)MyClass2@MyCategory2"
},
"kind": {
"displayName": "Class Extension",
@@ -388,7 +388,7 @@
"accessLevel": "public",
"identifier": {
"interfaceLanguage": "objective-c",
- "precise": "c:objc(cs)NSString"
+ "precise": "c:objc(cy)NSString@Category1"
},
"kind": {
"displayName": "Module Extension",
@@ -426,7 +426,7 @@
],
"identifier": {
"interfaceLanguage": "objective-c",
- "precise": "c:objc(cs)NSString"
+ "precise": "c:objc(cy)NSString@Category1"
},
"kind": {
"displayName": "Class Extension",
@@ -562,7 +562,7 @@
],
"identifier": {
"interfaceLanguage": "objective-c",
- "precise": "c:objc(cs)NSString"
+ "precise": "c:objc(cy)NSString@Category2"
},
"kind": {
"displayName": "Class Extension",
Index: clang/test/ExtractAPI/objc_module_category.m
===================================================================
--- clang/test/ExtractAPI/objc_module_category.m
+++ clang/test/ExtractAPI/objc_module_category.m
@@ -53,7 +53,7 @@
},
"relationships": [
{
- "kind": "memberOf",
+ "kind": "extensionTo",
"source": "c:objc(cy)NSString@Category1",
"target": "c:objc(cs)NSString",
"targetFallback": "NSString"
@@ -65,7 +65,7 @@
"targetFallback": "Category1"
},
{
- "kind": "memberOf",
+ "kind": "extensionTo",
"source": "c:objc(cy)NSString@Category2",
"target": "c:objc(cs)NSString",
"targetFallback": "NSString"
@@ -82,7 +82,7 @@
"accessLevel": "public",
"identifier": {
"interfaceLanguage": "objective-c",
- "precise": "c:objc(cs)NSString"
+ "precise": "c:objc(cy)NSString@Category1"
},
"kind": {
"displayName": "Module Extension",
@@ -137,7 +137,7 @@
},
"identifier": {
"interfaceLanguage": "objective-c",
- "precise": "c:objc(cs)NSString"
+ "precise": "c:objc(cy)NSString@Category1"
},
"kind": {
"displayName": "Class Extension",
@@ -290,7 +290,7 @@
},
"identifier": {
"interfaceLanguage": "objective-c",
- "precise": "c:objc(cs)NSString"
+ "precise": "c:objc(cy)NSString@Category2"
},
"kind": {
"displayName": "Class Extension",
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===================================================================
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -216,11 +216,7 @@
/// references, and the interface language name.
Object serializeIdentifier(const APIRecord &Record, Language Lang) {
Object Identifier;
- if (auto *CategoryRecord =
- dyn_cast_or_null<const ObjCCategoryRecord>(&Record))
- Identifier["precise"] = CategoryRecord->Interface.USR;
- else
- Identifier["precise"] = Record.USR;
+ Identifier["precise"] = Record.USR;
Identifier["interfaceLanguage"] = getLanguageName(Lang);
return Identifier;
@@ -661,6 +657,8 @@
return "inheritsFrom";
case RelationshipKind::ConformsTo:
return "conformsTo";
+ case RelationshipKind::ExtensionTo:
+ return "extensionTo";
}
llvm_unreachable("Unhandled relationship kind");
}
@@ -755,7 +753,7 @@
if (!Record.IsFromExternalModule)
return;
- // Check if the current Category Record has been visited before, if not add.
+ // Check if the current Category' parent has been visited before, if so skip.
if (!(visitedCategories.contains(Record.Interface.Name) > 0)) {
visitedCategories.insert(Record.Interface.Name);
Object Obj;
@@ -772,7 +770,7 @@
Relationship["source"] = Record.USR;
Relationship["target"] = Record.Interface.USR;
Relationship["targetFallback"] = Record.Interface.Name;
- Relationship["kind"] = getRelationshipString(RelationshipKind::MemberOf);
+ Relationship["kind"] = getRelationshipString(RelationshipKind::ExtensionTo);
Relationships.emplace_back(std::move(Relationship));
auto ObjCCategory = serializeAPIRecord(Record);
Index: clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
===================================================================
--- clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
+++ clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
@@ -88,6 +88,10 @@
/// The source symbol conforms to the target symbol.
/// For example Objective-C protocol conformances.
ConformsTo,
+
+ /// The source symbol is an extension to the target symbol.
+ /// For example Objective-C categories extending an external type.
+ ExtensionTo,
};
/// Get the string representation of the relationship kind.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits