@@ -43,6 +43,30 @@ static auto SerializeReferenceLambda = [](const auto &Ref, Object &Object) {
4343 serializeReference (Ref, Object);
4444};
4545
46+ static std::string infoTypeToString (InfoType IT) {
47+ switch (IT) {
48+ case InfoType::IT_default:
49+ return " default" ;
50+ case InfoType::IT_namespace:
51+ return " namespace" ;
52+ case InfoType::IT_record:
53+ return " record" ;
54+ case InfoType::IT_function:
55+ return " function" ;
56+ case InfoType::IT_enum:
57+ return " enum" ;
58+ case InfoType::IT_typedef:
59+ return " typedef" ;
60+ case InfoType::IT_concept:
61+ return " concept" ;
62+ case InfoType::IT_variable:
63+ return " variable" ;
64+ case InfoType::IT_friend:
65+ return " friend" ;
66+ }
67+ llvm_unreachable (" Unknown InfoType encountered." );
68+ }
69+
4670static json::Object
4771serializeLocation (const Location &Loc,
4872 const std::optional<StringRef> RepositoryUrl) {
@@ -172,6 +196,9 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
172196 const std::optional<StringRef> RepositoryUrl) {
173197 Obj[" Name" ] = I.Name ;
174198 Obj[" USR" ] = toHex (toStringRef (I.USR ));
199+ Obj[" InfoType" ] = infoTypeToString (I.IT );
200+ if (!I.DocumentationFileName .empty ())
201+ Obj[" DocumentationFileName" ] = I.DocumentationFileName ;
175202
176203 if (!I.Path .empty ())
177204 Obj[" Path" ] = I.Path ;
@@ -205,6 +232,8 @@ static void serializeReference(const Reference &Ref, Object &ReferenceObj) {
205232 ReferenceObj[" Name" ] = Ref.Name ;
206233 ReferenceObj[" QualName" ] = Ref.QualName ;
207234 ReferenceObj[" USR" ] = toHex (toStringRef (Ref.USR ));
235+ if (!Ref.DocumentationFileName .empty ())
236+ ReferenceObj[" DocumentationFileName" ] = Ref.DocumentationFileName ;
208237}
209238
210239// Although namespaces and records both have ScopeChildren, they serialize them
@@ -217,14 +246,18 @@ serializeCommonChildren(const ScopeChildren &Children, json::Object &Obj,
217246 serializeInfo (Info, Object, RepositoryUrl);
218247 };
219248
220- if (!Children.Enums .empty ())
249+ if (!Children.Enums .empty ()) {
221250 serializeArray (Children.Enums , Obj, " Enums" , SerializeInfo);
251+ Obj[" HasEnums" ] = true ;
252+ }
222253
223254 if (!Children.Typedefs .empty ())
224255 serializeArray (Children.Typedefs , Obj, " Typedefs" , SerializeInfo);
225256
226- if (!Children.Records .empty ())
257+ if (!Children.Records .empty ()) {
227258 serializeArray (Children.Records , Obj, " Records" , SerializeReferenceLambda);
259+ Obj[" HasRecords" ] = true ;
260+ }
228261}
229262
230263template <typename Container, typename SerializationFunc>
@@ -234,10 +267,12 @@ static void serializeArray(const Container &Records, Object &Obj,
234267 json::Value RecordsArray = Array ();
235268 auto &RecordsArrayRef = *RecordsArray.getAsArray ();
236269 RecordsArrayRef.reserve (Records.size ());
237- for (const auto &Item : Records) {
270+ for (size_t Index = 0 ; Index < Records. size (); ++Index ) {
238271 json::Value ItemVal = Object ();
239272 auto &ItemObj = *ItemVal.getAsObject ();
240- SerializeInfo (Item, ItemObj);
273+ SerializeInfo (Records[Index], ItemObj);
274+ if (Index == Records.size () - 1 )
275+ ItemObj[" End" ] = true ;
241276 RecordsArrayRef.push_back (ItemVal);
242277 }
243278 Obj[Key] = RecordsArray;
@@ -405,8 +440,10 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj,
405440 ProtFunctionsArrayRef.push_back (FunctionVal);
406441 }
407442
408- if (!PubFunctionsArrayRef.empty ())
443+ if (!PubFunctionsArrayRef.empty ()) {
409444 Obj[" PublicFunctions" ] = PubFunctionsArray;
445+ Obj[" HasPublicFunctions" ] = true ;
446+ }
410447 if (!ProtFunctionsArrayRef.empty ())
411448 Obj[" ProtectedFunctions" ] = ProtFunctionsArray;
412449 }
@@ -429,8 +466,10 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj,
429466 ProtMembersArrayRef.push_back (MemberVal);
430467 }
431468
432- if (!PubMembersArrayRef.empty ())
469+ if (!PubMembersArrayRef.empty ()) {
433470 Obj[" PublicMembers" ] = PublicMembersArray;
471+ Obj[" HasPublicMembers" ] = true ;
472+ }
434473 if (!ProtMembersArrayRef.empty ())
435474 Obj[" ProtectedMembers" ] = ProtectedMembersArray;
436475 }
@@ -496,10 +535,7 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
496535 SmallString<16 > FileName;
497536 if (I->IT == InfoType::IT_record) {
498537 auto *RecordSymbolInfo = static_cast <SymbolInfo *>(I);
499- if (RecordSymbolInfo->MangledName .size () < 255 )
500- FileName = RecordSymbolInfo->MangledName ;
501- else
502- FileName = toStringRef (toHex (RecordSymbolInfo->USR ));
538+ FileName = RecordSymbolInfo->MangledName ;
503539 } else if (I->IT == InfoType::IT_namespace && I->Name != " " )
504540 // Serialize the global namespace as index.json
505541 FileName = I->Name ;
@@ -527,7 +563,10 @@ Error JSONGenerator::generateDocs(
527563 }
528564
529565 SmallString<16 > FileName = determineFileName (Info, Path);
566+ if (FileToInfos.contains (Path))
567+ continue ;
530568 FileToInfos[Path].push_back (Info);
569+ Info->DocumentationFileName = FileName;
531570 }
532571
533572 for (const auto &Group : FileToInfos) {
0 commit comments