@@ -25,7 +25,6 @@ void generateIndex(Info *I) {
2525 switch (I->IT ) {
2626 case InfoType::IT_namespace: {
2727 const NamespaceInfo& N = *static_cast <clang::doc::NamespaceInfo *>(I);
28- SmallString<16 > Name = N.getFileBaseName ();
2928 std::string HexId = llvm::toHex (llvm::toStringRef (N.USR ));
3029 Index[HexId] = HexId;
3130 for (const EnumInfo& E : N.Children .Enums )
@@ -36,15 +35,12 @@ void generateIndex(Info *I) {
3635 }
3736 case InfoType::IT_record: {
3837 const RecordInfo& R = *static_cast <clang::doc::RecordInfo *>(I);
39- SmallString<16 > Name = R.getFileBaseName ();
4038 std::string HexId = llvm::toHex (llvm::toStringRef (R.USR ));
4139 Index[HexId] = HexId;
42- for (const EnumInfo& E : R.Children .Enums ) {
40+ for (const EnumInfo& E : R.Children .Enums )
4341 Index[llvm::toHex (llvm::toStringRef (E.USR ))] = HexId;
44- }
45- for (const TypedefInfo& T : R.Children .Typedefs ) {
42+ for (const TypedefInfo& T : R.Children .Typedefs )
4643 Index[llvm::toHex (llvm::toStringRef (T.USR ))] = HexId;
47- }
4844 break ;
4945 }
5046 case InfoType::IT_enum:
@@ -127,10 +123,12 @@ setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) {
127123 auto CommentFilePath = CDCtx.MustacheTemplates .lookup (" comments-template" );
128124 auto FunctionFilePath = CDCtx.MustacheTemplates .lookup (" function-template" );
129125 auto EnumFilePath = CDCtx.MustacheTemplates .lookup (" enum-template" );
126+ auto TypeDefFilePath = CDCtx.MustacheTemplates .lookup (" typedef-template" );
130127 std::vector<std::pair<StringRef, StringRef>> Partials = {
131128 {" Comments" , CommentFilePath},
132129 {" FunctionPartial" , FunctionFilePath},
133- {" EnumPartial" , EnumFilePath}
130+ {" EnumPartial" , EnumFilePath},
131+ {" TypedefPartial" , TypeDefFilePath}
134132 };
135133
136134 auto Err = setupTemplate (NamespaceTemplate, NamespaceFilePath, Partials);
@@ -152,8 +150,6 @@ MustacheHTMLGenerator::generateDocs(llvm::StringRef RootDir,
152150 const clang::doc::ClangDocContext &CDCtx) {
153151 if (auto Err = setupTemplateFiles (CDCtx))
154152 return Err;
155- // Track which directories we already tried to create.
156- llvm::StringSet<> CreatedDirs;
157153 // Collect all output by file name and create the necessary directories.
158154 llvm::StringMap<std::vector<doc::Info *>> FileToInfos;
159155 for (const auto &Group : Infos) {
@@ -182,41 +178,6 @@ MustacheHTMLGenerator::generateDocs(llvm::StringRef RootDir,
182178 return llvm::Error::success ();
183179}
184180
185- Value extractValue (const Location &L,
186- std::optional<StringRef> RepositoryUrl = std::nullopt ) {
187- Object Obj = Object ();
188- Obj.insert ({" LineNumber" , L.LineNumber });
189- Obj.insert ({" Filename" , L.Filename });
190-
191- if (!L.IsFileInRootDir || !RepositoryUrl)
192- return Obj;
193-
194- SmallString<128 > FileURL (*RepositoryUrl);
195- llvm::sys::path::append (FileURL, llvm::sys::path::Style::posix, L.Filename );
196- FileURL += " #" + std::to_string (L.LineNumber );
197- Obj.insert ({" FileURL" , FileURL});
198-
199- return Obj;
200- }
201-
202- Value extractValue (const Reference &I, StringRef CurrentDirectory) {
203- llvm::SmallString<64 > Path = I.getRelativeFilePath (CurrentDirectory);
204- llvm::sys::path::append (Path, I.getFileBaseName () + " .html" );
205- llvm::sys::path::native (Path, llvm::sys::path::Style::posix);
206- Object Obj = Object ();
207- Obj.insert ({" Link" , Path});
208- Obj.insert ({" Name" , I.Name });
209- Obj.insert ({" QualName" , I.QualName });
210- Obj.insert ({" ID" , llvm::toHex (llvm::toStringRef (I.USR ))});
211- return Obj;
212- }
213-
214-
215- Value extractValue (const TypedefInfo &I) {
216- // Not Supported
217- return nullptr ;
218- }
219-
220181Value extractValue (const CommentInfo &I) {
221182 Object Obj = Object ();
222183 Value Child = Object ();
@@ -238,6 +199,7 @@ Value extractValue(const CommentInfo &I) {
238199 if (I.Kind == " BlockCommandComment" ) {
239200 Child.getAsObject ()->insert ({" Command" , I.Name });
240201 Value ChildArr = Array ();
202+
241203 for (const auto & C: I.Children )
242204 ChildArr.getAsArray ()->emplace_back (extractValue (*C));
243205 Child.getAsObject ()->insert ({" Children" , ChildArr});
@@ -250,6 +212,56 @@ Value extractValue(const CommentInfo &I) {
250212}
251213
252214
215+ Value extractValue (const std::optional<Location> &Loc,
216+ std::optional<StringRef> RepositoryUrl = std::nullopt ) {
217+
218+ Object Obj = Object ();
219+ if (Loc.has_value ()) {
220+ Location L = *Loc;
221+ SmallString<128 > Filename (llvm::sys::path::filename (L.Filename ));
222+ Obj.insert ({" LineNumber" , L.LineNumber });
223+ Obj.insert ({" Filename" , Filename});
224+ if (!RepositoryUrl)
225+ return Obj;
226+ // This link only works specifically for github
227+ SmallString<128 > FileURL (*RepositoryUrl);
228+ llvm::sys::path::append (FileURL, llvm::sys::path::Style::posix, " blob/main" );
229+ llvm::sys::path::append (FileURL, llvm::sys::path::Style::posix, L.Filename );
230+ FileURL += " #L" + std::to_string (L.LineNumber );
231+ Obj.insert ({" FileURL" , FileURL});
232+ }
233+ return Obj;
234+ }
235+
236+ Value extractValue (const Reference &I, StringRef CurrentDirectory) {
237+ llvm::SmallString<64 > Path = I.getRelativeFilePath (CurrentDirectory);
238+ llvm::sys::path::append (Path, I.getFileBaseName () + " .html" );
239+ llvm::sys::path::native (Path, llvm::sys::path::Style::posix);
240+ Object Obj = Object ();
241+ Obj.insert ({" Link" , Path});
242+ Obj.insert ({" Name" , I.Name });
243+ Obj.insert ({" QualName" , I.QualName });
244+ Obj.insert ({" ID" , llvm::toHex (llvm::toStringRef (I.USR ))});
245+ return Obj;
246+ }
247+
248+
249+ Value extractValue (const TypedefInfo &I, const ClangDocContext& CDCtx) {
250+ Object Obj = Object ();
251+ Obj.insert ({" ID" , llvm::toHex (llvm::toStringRef (I.USR ))});
252+ Obj.insert ({" TypeDeclaration" , I.TypeDeclaration });
253+ Obj.insert ({" Name" , I.Name });
254+ Obj.insert ({" IsAlias" , I.IsUsing });
255+ Obj.insert ({" Location" , extractValue (I.DefLoc , CDCtx.RepositoryUrl )});
256+ if (!I.Description .empty ()) {
257+ Value ArrDesc = Array ();
258+ for (const CommentInfo& Child : I.Description )
259+ ArrDesc.getAsArray ()->emplace_back (extractValue (Child));
260+ Obj.insert ({" TypeDefComments" , ArrDesc});
261+ }
262+ return Obj;
263+ }
264+
253265// Function to replace a substring within a SmallString with another SmallString
254266void replaceSubstring (llvm::SmallString<256 > &Input,
255267 const llvm::SmallString<16 > &From,
@@ -383,14 +395,7 @@ Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir,
383395 ArrDesc.getAsArray ()->emplace_back (extractValue (Child));
384396 Obj.insert ({" FunctionComments" , ArrDesc});
385397 }
386- if (I.DefLoc .has_value ()) {
387- Location L = *I.DefLoc ;
388- if (CDCtx.RepositoryUrl .has_value ())
389- Obj.insert ({" Location" , extractValue (L,
390- StringRef{*CDCtx.RepositoryUrl })});
391- else
392- Obj.insert ({" Location" , extractValue (L)});
393- }
398+ Obj.insert ({" Location" , extractValue (I.DefLoc , CDCtx.RepositoryUrl )});
394399 return Obj;
395400}
396401
@@ -429,16 +434,7 @@ Value extractValue(const EnumInfo &I, const ClangDocContext &CDCtx) {
429434 ArrDesc.getAsArray ()->emplace_back (extractValue (Child));
430435 Obj.insert ({" EnumComments" , ArrDesc});
431436 }
432-
433- if (I.DefLoc .has_value ()) {
434- Location L = *I.DefLoc ;
435- if (CDCtx.RepositoryUrl .has_value ())
436- Obj.insert ({" Location" , extractValue (L,
437- StringRef{*CDCtx.RepositoryUrl })});
438- else
439- Obj.insert ({" Location" , extractValue (L)});
440- }
441-
437+ Obj.insert ({" Location" , extractValue (I.DefLoc , CDCtx.RepositoryUrl )});
442438 return Obj;
443439}
444440
@@ -493,10 +489,15 @@ void extractScopeChildren(const ScopeChildren &S, Object &Obj,
493489
494490 Value ArrTypedefs = Array ();
495491 for (const TypedefInfo& Child : S.Typedefs )
496- ArrTypedefs.getAsArray ()->emplace_back (extractValue (Child));
492+ ArrTypedefs.getAsArray ()->emplace_back (extractValue (Child, CDCtx ));
497493
498494 if (!ArrTypedefs.getAsArray ()->empty ())
499495 Obj.insert ({" Typedefs" , Object{{" Obj" , ArrTypedefs }}});
496+
497+
498+ llvm::raw_fd_ostream os (1 , false );
499+ llvm::json::OStream jStream (os, /* Indent=*/ 2 );
500+ jStream.value (ArrTypedefs);
500501}
501502
502503Value extractValue (const NamespaceInfo &I, const ClangDocContext &CDCtx) {
@@ -536,16 +537,7 @@ Value extractValue(const RecordInfo &I, const ClangDocContext &CDCtx) {
536537 I.VirtualParents )});
537538
538539 RecordValue.insert ({" RecordType" , getTagType (I.TagType )});
539-
540- if (I.DefLoc .has_value ()) {
541- Location L = *I.DefLoc ;
542- if (CDCtx.RepositoryUrl .has_value ())
543- RecordValue.insert ({" Location" , extractValue (L,
544- StringRef{*CDCtx.RepositoryUrl })});
545- else
546- RecordValue.insert ({" Location" , extractValue (L)});
547- }
548-
540+ RecordValue.insert ({" Location" , extractValue (I.DefLoc , CDCtx.RepositoryUrl )});
549541 StringRef BasePath = I.getRelativeFilePath (" " );
550542 extractScopeChildren (I.Children , RecordValue, BasePath, CDCtx);
551543 Value PublicMembers = Array ();
0 commit comments