diff options
author | Zixu Wang <zixu_wang@apple.com> | 2022-03-24 18:19:30 -0700 |
---|---|---|
committer | Zixu Wang <zixu_wang@apple.com> | 2022-03-29 14:29:39 -0700 |
commit | 9b36e126fdb1da4d7e255e089ef225dfb130ef63 (patch) | |
tree | 1b7b71ed8d09993adad441b97bb918d16bbb75b0 /clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp | |
parent | 686dcbe8b018759b5443c05bfeeb7abf4d9cf09c (diff) | |
download | llvm-9b36e126fdb1da4d7e255e089ef225dfb130ef63.zip llvm-9b36e126fdb1da4d7e255e089ef225dfb130ef63.tar.gz llvm-9b36e126fdb1da4d7e255e089ef225dfb130ef63.tar.bz2 |
[clang][extract-api] Add Objective-C interface support
Add support for Objective-C interface declarations in ExtractAPI.
Depends on D122495
Differential Revision: https://reviews.llvm.org/D122446
Diffstat (limited to 'clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp')
-rw-r--r-- | clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp | 84 |
1 files changed, 82 insertions, 2 deletions
diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp index cde81ec..3faf9cd 100644 --- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp +++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp @@ -372,6 +372,27 @@ Object serializeSymbolKind(const APIRecord &Record, Language Lang) { Kind["identifier"] = AddLangPrefix("struct"); Kind["displayName"] = "Structure"; break; + case APIRecord::RK_ObjCIvar: + Kind["identifier"] = AddLangPrefix("ivar"); + Kind["displayName"] = "Instance Variable"; + break; + case APIRecord::RK_ObjCMethod: + if (dyn_cast<ObjCMethodRecord>(&Record)->IsInstanceMethod) { + Kind["identifier"] = AddLangPrefix("method"); + Kind["displayName"] = "Instance Method"; + } else { + Kind["identifier"] = AddLangPrefix("type.method"); + Kind["displayName"] = "Type Method"; + } + break; + case APIRecord::RK_ObjCProperty: + Kind["identifier"] = AddLangPrefix("property"); + Kind["displayName"] = "Instance Property"; + break; + case APIRecord::RK_ObjCInterface: + Kind["identifier"] = AddLangPrefix("class"); + Kind["displayName"] = "Class"; + break; } return Kind; @@ -435,13 +456,17 @@ StringRef SymbolGraphSerializer::getRelationshipString(RelationshipKind Kind) { switch (Kind) { case RelationshipKind::MemberOf: return "memberOf"; + case RelationshipKind::InheritsFrom: + return "inheritsFrom"; + case RelationshipKind::ConformsTo: + return "conformsTo"; } llvm_unreachable("Unhandled relationship kind"); } void SymbolGraphSerializer::serializeRelationship(RelationshipKind Kind, - const APIRecord &Source, - const APIRecord &Target) { + SymbolReference Source, + SymbolReference Target) { Object Relationship; Relationship["source"] = Source.USR; Relationship["target"] = Target.USR; @@ -496,6 +521,57 @@ void SymbolGraphSerializer::serializeStructRecord(const StructRecord &Record) { } } +void SymbolGraphSerializer::serializeObjCContainerRecord( + const ObjCContainerRecord &Record) { + auto ObjCContainer = serializeAPIRecord(Record); + if (!ObjCContainer) + return; + + Symbols.emplace_back(std::move(*ObjCContainer)); + + // Record instance variables and that the instance variables are members of + // the container. + for (const auto &Ivar : Record.Ivars) { + auto ObjCIvar = serializeAPIRecord(*Ivar); + if (!ObjCIvar) + continue; + + Symbols.emplace_back(std::move(*ObjCIvar)); + serializeRelationship(RelationshipKind::MemberOf, *Ivar, Record); + } + + // Record methods and that the methods are members of the container. + for (const auto &Method : Record.Methods) { + auto ObjCMethod = serializeAPIRecord(*Method); + if (!ObjCMethod) + continue; + + Symbols.emplace_back(std::move(*ObjCMethod)); + serializeRelationship(RelationshipKind::MemberOf, *Method, Record); + } + + // Record properties and that the properties are members of the container. + for (const auto &Property : Record.Properties) { + auto ObjCProperty = serializeAPIRecord(*Property); + if (!ObjCProperty) + continue; + + Symbols.emplace_back(std::move(*ObjCProperty)); + serializeRelationship(RelationshipKind::MemberOf, *Property, Record); + } + + for (const auto &Protocol : Record.Protocols) + // Record that Record conforms to Protocol. + serializeRelationship(RelationshipKind::ConformsTo, Record, Protocol); + + if (auto *ObjCInterface = dyn_cast<ObjCInterfaceRecord>(&Record)) + if (!ObjCInterface->SuperClass.empty()) + // If Record is an Objective-C interface record and it has a super class, + // record that Record is inherited from SuperClass. + serializeRelationship(RelationshipKind::InheritsFrom, Record, + ObjCInterface->SuperClass); +} + Object SymbolGraphSerializer::serialize() { Object Root; serializeObject(Root, "metadata", serializeMetadata()); @@ -513,6 +589,10 @@ Object SymbolGraphSerializer::serialize() { for (const auto &Struct : API.getStructs()) serializeStructRecord(*Struct.second); + // Serialize Objective-C interface records in the API set. + for (const auto &ObjCInterface : API.getObjCInterfaces()) + serializeObjCContainerRecord(*ObjCInterface.second); + Root["symbols"] = std::move(Symbols); Root["relationhips"] = std::move(Relationships); |