16
16
#include " xml/base64.hpp"
17
17
#include " xml/escape.hpp"
18
18
#include < mrdox/Config.hpp>
19
+ #include < clang/Index/USRGeneration.h>
19
20
#include < clang/Tooling/Execution.h>
20
21
#include < clang/Tooling/Tooling.h>
21
22
#include < llvm/ADT/StringExtras.h>
@@ -36,6 +37,11 @@ namespace path = llvm::sys::path;
36
37
class XMLGenerator
37
38
: public clang::mrdox::Generator
38
39
{
40
+ Config const & cfg_;
41
+ std::string level_;
42
+ llvm::raw_ostream* os_ = nullptr ;
43
+ InfoMap const * infos_ = nullptr ;
44
+
39
45
using Attrs =
40
46
std::initializer_list<
41
47
std::pair<
@@ -62,19 +68,16 @@ class XMLGenerator
62
68
// --------------------------------------------
63
69
64
70
void write (llvm::ArrayRef<FieldTypeInfo> const & v);
65
-
66
- // --------------------------------------------
67
-
68
71
void write (FieldTypeInfo const & I);
72
+ void writeNamespaceRefs (llvm::SmallVector<Reference, 4 > const & v);
69
73
void write (Reference const & ref);
70
74
71
75
// --------------------------------------------
72
76
73
77
void writeInfo (Info const & I);
74
78
void writeSymbolInfo (SymbolInfo const & I);
75
- void writeList (llvm::SmallVector<Reference, 4 > const & v);
76
- void writeLoc (llvm::ArrayRef<Location> const & loc);
77
- void writeLoc (std::optional<Location> const & loc);
79
+ void write (llvm::ArrayRef<Location> const & locs);
80
+ void write (Location const & loc);
78
81
79
82
// --------------------------------------------
80
83
@@ -85,6 +88,8 @@ class XMLGenerator
85
88
void writeTag (llvm::StringRef, Attrs);
86
89
void writeTagLine (llvm::StringRef tag, llvm::StringRef value);
87
90
void writeTagLine (llvm::StringRef tag, llvm::StringRef value, Attrs);
91
+ void indent ();
92
+ void outdent ();
88
93
89
94
// --------------------------------------------
90
95
@@ -100,13 +105,6 @@ class XMLGenerator
100
105
101
106
static llvm::StringRef toString (InfoType) noexcept ;
102
107
103
- // --------------------------------------------
104
-
105
- Config const & cfg_;
106
- std::string level_;
107
- llvm::raw_ostream* os_ = nullptr ;
108
- InfoMap const * infos_ = nullptr ;
109
-
110
108
public:
111
109
static char const * Format;
112
110
@@ -275,14 +273,20 @@ write(
275
273
{ " usr" , toBase64 (I.USR ) }
276
274
});
277
275
writeSymbolInfo (I);
276
+ writeTag (" return" , {
277
+ { " name" , I.ReturnType .Type .Name },
278
+ { " usr" , toString (I.ReturnType .Type .USR ) }
279
+ });
278
280
279
- # if 1
280
-
281
+
282
+ # if 0
281
283
writeTag("return", {
282
284
{ "name", I.ReturnType.Type.Name },
283
285
{ "usr", toString(I.ReturnType.Type.USR) }
284
286
});
285
- #else
287
+ #endif
288
+
289
+ #if 0
286
290
auto it = infos_->find(llvm::toHex(llvm::toStringRef(
287
291
I.ReturnType.Type.USR)));
288
292
assert(it != infos_->end());
@@ -326,7 +330,6 @@ write(
326
330
{ " value" , v.Value },
327
331
});
328
332
}
329
- writeLoc (I.Loc );
330
333
closeTag (" enum" );
331
334
}
332
335
@@ -342,7 +345,6 @@ write(
342
345
writeSymbolInfo (I);
343
346
writeTagLine (" qualname" , I.Underlying .Type .QualName );
344
347
writeTagLine (" qualusr" , toBase64 (I.Underlying .Type .USR ));
345
- writeLoc (I.DefLoc );
346
348
closeTag (" typedef" );
347
349
}
348
350
@@ -357,8 +359,6 @@ write(
357
359
write (I);
358
360
}
359
361
360
- // ------------------------------------------------
361
-
362
362
void
363
363
XMLGenerator::
364
364
write (FieldTypeInfo const & I)
@@ -373,6 +373,15 @@ write(FieldTypeInfo const& I)
373
373
});
374
374
}
375
375
376
+ void
377
+ XMLGenerator::
378
+ writeNamespaceRefs (
379
+ llvm::SmallVector<Reference, 4 > const & v)
380
+ {
381
+ for (auto const & ns : v)
382
+ writeTagLine (" ns" , ns.QualName );
383
+ }
384
+
376
385
void
377
386
XMLGenerator::
378
387
write (
@@ -398,6 +407,9 @@ XMLGenerator::
398
407
writeInfo (
399
408
Info const & I)
400
409
{
410
+ writeTagLine (" extract-name" , I.extractName ());
411
+ writeTagLine (" rel-path" , I.getRelativeFilePath (cfg_.SourceRoot ));
412
+ writeTagLine (" base-name" , I.getFileBaseName ());
401
413
}
402
414
403
415
void
@@ -406,42 +418,29 @@ writeSymbolInfo(
406
418
SymbolInfo const & I)
407
419
{
408
420
writeInfo (I);
409
- // I.DefLoc
410
- // I.Loc[]
411
- }
412
-
413
- void
414
- XMLGenerator::
415
- writeList (
416
- llvm::SmallVector<Reference, 4 > const & v)
417
- {
418
- for (auto const & ns : v)
419
- writeTagLine (" ns" , ns.QualName );
421
+ if (I.DefLoc )
422
+ write (*I.DefLoc );
423
+ write (I.Loc );
420
424
}
421
425
422
426
void
423
427
XMLGenerator::
424
- writeLoc (
425
- llvm::ArrayRef<Location> const & loc )
428
+ write (
429
+ llvm::ArrayRef<Location> const & locs )
426
430
{
427
- return ;
428
- if (loc.size () > 0 )
429
- *os_ << level_ <<
430
- " <file>" << escape (loc[0 ].Filename ) <<
431
- " </file><line>" << std::to_string (loc[0 ].LineNumber ) <<
432
- " </line>\n " ;
431
+ for (auto const & loc : locs)
432
+ write (loc);
433
433
}
434
434
435
435
void
436
436
XMLGenerator::
437
- writeLoc (
438
- std::optional< Location> const & opt )
437
+ write (
438
+ Location const & loc )
439
439
{
440
- return ;
441
- if (! opt)
442
- return ;
443
- Location const & loc (*opt);
444
- writeLoc (llvm::ArrayRef<Location>(&loc, &loc+1 ));
440
+ *os_ << level_ <<
441
+ " <file>" << escape (loc.Filename ) <<
442
+ " </file><line>" << std::to_string (loc.LineNumber ) <<
443
+ " </line>\n " ;
445
444
}
446
445
447
446
// ------------------------------------------------
@@ -452,7 +451,7 @@ openTag(
452
451
llvm::StringRef tag)
453
452
{
454
453
*os_ << level_ << ' <' << tag << " >\n " ;
455
- level_. push_back ( ' ' );
454
+ indent ( );
456
455
}
457
456
458
457
void
@@ -467,15 +466,15 @@ openTag(
467
466
' ' << attr.first << ' =' <<
468
467
" \" " << escape (attr.second ) << " \" " ;
469
468
*os_ << " >\n " ;
470
- level_. push_back ( ' ' );
469
+ indent ( );
471
470
}
472
471
473
472
void
474
473
XMLGenerator::
475
474
closeTag (
476
475
llvm::StringRef tag)
477
476
{
478
- level_. pop_back ();
477
+ outdent ();
479
478
*os_ << level_ << " </" << tag << " >\n " ;
480
479
}
481
480
@@ -530,6 +529,20 @@ writeTagLine(
530
529
*os_ << " >" << escape (value) << " </" << tag << " >" << " \n " ;
531
530
}
532
531
532
+ void
533
+ XMLGenerator::
534
+ indent ()
535
+ {
536
+ level_.append (" " );
537
+ }
538
+
539
+ void
540
+ XMLGenerator::
541
+ outdent ()
542
+ {
543
+ level_.resize (level_.size () - 4 );
544
+ }
545
+
533
546
// ------------------------------------------------
534
547
535
548
std::string
0 commit comments