@@ -25,7 +25,6 @@ void generateIndex(Info *I) {
25
25
switch (I->IT ) {
26
26
case InfoType::IT_namespace: {
27
27
const NamespaceInfo& N = *static_cast <clang::doc::NamespaceInfo *>(I);
28
- SmallString<16 > Name = N.getFileBaseName ();
29
28
std::string HexId = llvm::toHex (llvm::toStringRef (N.USR ));
30
29
Index[HexId] = HexId;
31
30
for (const EnumInfo& E : N.Children .Enums )
@@ -36,15 +35,12 @@ void generateIndex(Info *I) {
36
35
}
37
36
case InfoType::IT_record: {
38
37
const RecordInfo& R = *static_cast <clang::doc::RecordInfo *>(I);
39
- SmallString<16 > Name = R.getFileBaseName ();
40
38
std::string HexId = llvm::toHex (llvm::toStringRef (R.USR ));
41
39
Index[HexId] = HexId;
42
- for (const EnumInfo& E : R.Children .Enums ) {
40
+ for (const EnumInfo& E : R.Children .Enums )
43
41
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 )
46
43
Index[llvm::toHex (llvm::toStringRef (T.USR ))] = HexId;
47
- }
48
44
break ;
49
45
}
50
46
case InfoType::IT_enum:
@@ -127,10 +123,12 @@ setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) {
127
123
auto CommentFilePath = CDCtx.MustacheTemplates .lookup (" comments-template" );
128
124
auto FunctionFilePath = CDCtx.MustacheTemplates .lookup (" function-template" );
129
125
auto EnumFilePath = CDCtx.MustacheTemplates .lookup (" enum-template" );
126
+ auto TypeDefFilePath = CDCtx.MustacheTemplates .lookup (" typedef-template" );
130
127
std::vector<std::pair<StringRef, StringRef>> Partials = {
131
128
{" Comments" , CommentFilePath},
132
129
{" FunctionPartial" , FunctionFilePath},
133
- {" EnumPartial" , EnumFilePath}
130
+ {" EnumPartial" , EnumFilePath},
131
+ {" TypedefPartial" , TypeDefFilePath}
134
132
};
135
133
136
134
auto Err = setupTemplate (NamespaceTemplate, NamespaceFilePath, Partials);
@@ -152,8 +150,6 @@ MustacheHTMLGenerator::generateDocs(llvm::StringRef RootDir,
152
150
const clang::doc::ClangDocContext &CDCtx) {
153
151
if (auto Err = setupTemplateFiles (CDCtx))
154
152
return Err;
155
- // Track which directories we already tried to create.
156
- llvm::StringSet<> CreatedDirs;
157
153
// Collect all output by file name and create the necessary directories.
158
154
llvm::StringMap<std::vector<doc::Info *>> FileToInfos;
159
155
for (const auto &Group : Infos) {
@@ -182,41 +178,6 @@ MustacheHTMLGenerator::generateDocs(llvm::StringRef RootDir,
182
178
return llvm::Error::success ();
183
179
}
184
180
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
-
220
181
Value extractValue (const CommentInfo &I) {
221
182
Object Obj = Object ();
222
183
Value Child = Object ();
@@ -238,6 +199,7 @@ Value extractValue(const CommentInfo &I) {
238
199
if (I.Kind == " BlockCommandComment" ) {
239
200
Child.getAsObject ()->insert ({" Command" , I.Name });
240
201
Value ChildArr = Array ();
202
+
241
203
for (const auto & C: I.Children )
242
204
ChildArr.getAsArray ()->emplace_back (extractValue (*C));
243
205
Child.getAsObject ()->insert ({" Children" , ChildArr});
@@ -250,6 +212,56 @@ Value extractValue(const CommentInfo &I) {
250
212
}
251
213
252
214
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
+
253
265
// Function to replace a substring within a SmallString with another SmallString
254
266
void replaceSubstring (llvm::SmallString<256 > &Input,
255
267
const llvm::SmallString<16 > &From,
@@ -383,14 +395,7 @@ Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir,
383
395
ArrDesc.getAsArray ()->emplace_back (extractValue (Child));
384
396
Obj.insert ({" FunctionComments" , ArrDesc});
385
397
}
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 )});
394
399
return Obj;
395
400
}
396
401
@@ -429,16 +434,7 @@ Value extractValue(const EnumInfo &I, const ClangDocContext &CDCtx) {
429
434
ArrDesc.getAsArray ()->emplace_back (extractValue (Child));
430
435
Obj.insert ({" EnumComments" , ArrDesc});
431
436
}
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 )});
442
438
return Obj;
443
439
}
444
440
@@ -493,10 +489,15 @@ void extractScopeChildren(const ScopeChildren &S, Object &Obj,
493
489
494
490
Value ArrTypedefs = Array ();
495
491
for (const TypedefInfo& Child : S.Typedefs )
496
- ArrTypedefs.getAsArray ()->emplace_back (extractValue (Child));
492
+ ArrTypedefs.getAsArray ()->emplace_back (extractValue (Child, CDCtx ));
497
493
498
494
if (!ArrTypedefs.getAsArray ()->empty ())
499
495
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);
500
501
}
501
502
502
503
Value extractValue (const NamespaceInfo &I, const ClangDocContext &CDCtx) {
@@ -536,16 +537,7 @@ Value extractValue(const RecordInfo &I, const ClangDocContext &CDCtx) {
536
537
I.VirtualParents )});
537
538
538
539
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 )});
549
541
StringRef BasePath = I.getRelativeFilePath (" " );
550
542
extractScopeChildren (I.Children , RecordValue, BasePath, CDCtx);
551
543
Value PublicMembers = Array ();
0 commit comments