diff --git a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h --- a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h +++ b/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. diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp --- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp +++ b/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(&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); diff --git a/clang/test/ExtractAPI/objc_module_category.m b/clang/test/ExtractAPI/objc_module_category.m --- a/clang/test/ExtractAPI/objc_module_category.m +++ b/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", diff --git a/clang/test/ExtractAPI/objc_various_categories.m b/clang/test/ExtractAPI/objc_various_categories.m --- a/clang/test/ExtractAPI/objc_various_categories.m +++ b/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",