@@ -42,11 +42,31 @@ class XMLGenerator
42
42
std::string level_;
43
43
llvm::raw_ostream* os_ = nullptr ;
44
44
45
- using Attrs =
46
- std::initializer_list<
47
- std::pair<
48
- llvm::StringRef,
49
- llvm::StringRef>>;
45
+ struct Attr
46
+ {
47
+ llvm::StringRef name;
48
+ std::string value;
49
+ bool pred;
50
+
51
+ Attr (
52
+ llvm::StringRef name_,
53
+ llvm::StringRef value_,
54
+ bool pred_ = true ) noexcept
55
+ : name(name_)
56
+ , value(value_)
57
+ , pred(pred_)
58
+ {
59
+ }
60
+
61
+ Attr (SymbolID USR)
62
+ : name(" usr" )
63
+ , value(toBase64(USR))
64
+ , pred(USR != EmptySID)
65
+ {
66
+ }
67
+ };
68
+
69
+ using Attrs = std::initializer_list<Attr>;
50
70
51
71
void writeAllSymbols ();
52
72
@@ -89,6 +109,7 @@ class XMLGenerator
89
109
void writeTag (llvm::StringRef, Attrs);
90
110
void writeTagLine (llvm::StringRef tag, llvm::StringRef value);
91
111
void writeTagLine (llvm::StringRef tag, llvm::StringRef value, Attrs);
112
+ void writeAttrs (Attrs attrs);
92
113
void indent ();
93
114
void outdent ();
94
115
@@ -146,7 +167,7 @@ writeAllSymbols()
146
167
auto const & I = corpus_->at (id);
147
168
writeTag (" symbol" , {
148
169
{ " name" , I.getFullyQualifiedName (temp) },
149
- { " usr " , toBase64 ( I.USR ) }
170
+ { I.USR }
150
171
});
151
172
}
152
173
closeTag (" all" );
@@ -210,7 +231,7 @@ write(
210
231
211
232
openTag (" namespace" , {
212
233
{ " name" , I.Name },
213
- { " usr " , toBase64 ( I.USR ) }
234
+ { I.USR }
214
235
});
215
236
writeInfo (I);
216
237
writeNamespaces (I.Children .Namespaces );
@@ -239,7 +260,7 @@ write(
239
260
}
240
261
openTag (tag, {
241
262
{ " name" , I.Name },
242
- { " usr " , toBase64 ( I.USR ) }
263
+ { I.USR }
243
264
});
244
265
writeSymbolInfo (I);
245
266
writeRecords (I.Children .Records );
@@ -259,12 +280,12 @@ write(
259
280
openTag (" function" , {
260
281
{ " name" , I.Name },
261
282
{ " access" , toString (I.Access ) },
262
- { " usr " , toBase64 ( I.USR ) }
283
+ { I.USR }
263
284
});
264
285
writeSymbolInfo (I);
265
286
writeTag (" return" , {
266
287
{ " name" , I.ReturnType .Type .Name },
267
- { " usr " , toString ( I.ReturnType .Type .USR ) }
288
+ { I.ReturnType .Type .USR }
268
289
});
269
290
270
291
write (I.Params );
@@ -292,7 +313,7 @@ write(
292
313
293
314
openTag (" enum" , {
294
315
{ " name" , I.Name },
295
- { " usr " , toBase64 ( I.USR ) },
316
+ { I.USR }
296
317
});
297
318
writeInfo (I);
298
319
for (auto const & v : I.Members )
@@ -314,7 +335,7 @@ write(
314
335
315
336
openTag (" typedef" , {
316
337
{ " name" , I.Name },
317
- { " usr " , toString ( I.USR ) }
338
+ { I.USR }
318
339
});
319
340
writeSymbolInfo (I);
320
341
writeTagLine (" qualname" , I.Underlying .Type .QualName );
@@ -343,7 +364,7 @@ write(FieldTypeInfo const& I)
343
364
{ " type" , I.Type .Name },
344
365
{ " qualname" , I.Type .QualName },
345
366
{ " reftype" , toString (I.Type .RefType ) },
346
- { " usr " , toString ( I.Type .USR ) }
367
+ { I.Type .USR }
347
368
});
348
369
}
349
370
@@ -434,13 +455,10 @@ void
434
455
XMLGenerator::
435
456
openTag (
436
457
llvm::StringRef tag,
437
- Attrs init )
458
+ Attrs attrs )
438
459
{
439
460
*os_ << level_ << ' <' << tag;
440
- for (auto const & attr : init)
441
- *os_ <<
442
- ' ' << attr.first << ' =' <<
443
- " \" " << escape (attr.second ) << " \" " ;
461
+ writeAttrs (attrs);
444
462
*os_ << " >\n " ;
445
463
indent ();
446
464
}
@@ -466,13 +484,10 @@ void
466
484
XMLGenerator::
467
485
writeTag (
468
486
llvm::StringRef tag,
469
- Attrs init )
487
+ Attrs attrs )
470
488
{
471
489
*os_ << level_ << " <" << tag;
472
- for (auto const & attr : init)
473
- *os_ <<
474
- ' ' << attr.first << ' =' <<
475
- " \" " << escape (attr.second ) << " \" " ;
490
+ writeAttrs (attrs);
476
491
*os_ << " />\n " ;
477
492
}
478
493
@@ -494,17 +509,25 @@ XMLGenerator::
494
509
writeTagLine (
495
510
llvm::StringRef tag,
496
511
llvm::StringRef value,
497
- Attrs init )
512
+ Attrs attrs )
498
513
{
499
- *os_ << level_ <<
500
- " <" << tag;
501
- for (auto const & attr : init)
502
- *os_ <<
503
- ' ' << attr.first << ' =' <<
504
- " \" " << escape (attr.second ) << " \" " ;
514
+ *os_ << level_ << " <" << tag;
515
+ writeAttrs (attrs);
505
516
*os_ << " >" << escape (value) << " </" << tag << " >" << " \n " ;
506
517
}
507
518
519
+ void
520
+ XMLGenerator::
521
+ writeAttrs (
522
+ Attrs attrs)
523
+ {
524
+ for (auto const & attr : attrs)
525
+ if (attr.pred )
526
+ *os_ <<
527
+ ' ' << attr.name << ' =' <<
528
+ " \" " << escape (attr.value ) << " \" " ;
529
+ }
530
+
508
531
void
509
532
XMLGenerator::
510
533
indent ()
0 commit comments