Skip to content

Commit e43f92e

Browse files
committed
tidy
1 parent 53993ca commit e43f92e

File tree

2 files changed

+104
-67
lines changed

2 files changed

+104
-67
lines changed

source/lib/Serialize.cpp

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "llvm/ADT/StringExtras.h"
2525
#include "llvm/Support/SHA1.h"
2626

27+
#include "xml/base64.hpp"
28+
2729
using clang::comments::FullComment;
2830

2931
namespace clang {
@@ -132,23 +134,27 @@ static RecordDecl* getRecordDeclForType(const QualType& T) {
132134
return nullptr;
133135
}
134136

135-
TypeInfo getTypeInfoForType(const QualType& T) {
136-
const TagDecl* TD = getTagDeclForType(T);
137+
TypeInfo
138+
getTypeInfoForType(
139+
QualType const& T)
140+
{
141+
TagDecl const* TD = getTagDeclForType(T);
137142
if (!TD)
138-
return TypeInfo(Reference(SymbolID(), T.getAsString()));
139-
143+
return TypeInfo(Reference(
144+
SymbolID(), T.getAsString()));
140145
InfoType IT;
141-
if (dyn_cast<EnumDecl>(TD)) {
146+
if (dyn_cast<EnumDecl>(TD))
142147
IT = InfoType::IT_enum;
143-
}
144-
else if (dyn_cast<RecordDecl>(TD)) {
148+
else if (dyn_cast<RecordDecl>(TD))
145149
IT = InfoType::IT_record;
146-
}
147-
else {
150+
else
148151
IT = InfoType::IT_default;
149-
}
150-
return TypeInfo(Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
151-
T.getAsString(), getInfoRelativePath(TD)));
152+
return TypeInfo(Reference(
153+
getUSRForDecl(TD),
154+
TD->getNameAsString(),
155+
IT,
156+
T.getAsString(),
157+
getInfoRelativePath(TD)));
152158
}
153159

154160
static
@@ -471,13 +477,31 @@ static void populateSymbolInfo(SymbolInfo& I, const T* D, const FullComment* C,
471477
I.Loc.emplace_back(LineNumber, Filename, IsFileInRootDir);
472478
}
473479

474-
static void populateFunctionInfo(FunctionInfo& I, const FunctionDecl* D,
475-
const FullComment* FC, int LineNumber,
476-
StringRef Filename, bool IsFileInRootDir,
477-
bool& IsInAnonymousNamespace) {
478-
populateSymbolInfo(I, D, FC, LineNumber, Filename, IsFileInRootDir,
480+
static
481+
void
482+
populateFunctionInfo(
483+
FunctionInfo& I,
484+
FunctionDecl const* D,
485+
FullComment const* FC,
486+
int LineNumber,
487+
StringRef Filename,
488+
bool IsFileInRootDir,
489+
bool& IsInAnonymousNamespace)
490+
{
491+
populateSymbolInfo(
492+
I, D, FC,
493+
LineNumber, Filename,
494+
IsFileInRootDir,
479495
IsInAnonymousNamespace);
480-
496+
{
497+
llvm::SmallString<32> tmp;
498+
index::generateUSRForType(
499+
D->getReturnType(),
500+
D->getASTContext(),
501+
tmp);
502+
auto s = xml::toBase64(hashUSR(tmp));
503+
auto s2 = s;
504+
}
481505
I.ReturnType = getTypeInfoForType(D->getReturnType());
482506
parseParameters(I, D);
483507

source/lib/xml/XML.cpp

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "xml/base64.hpp"
1717
#include "xml/escape.hpp"
1818
#include <mrdox/Config.hpp>
19+
#include <clang/Index/USRGeneration.h>
1920
#include <clang/Tooling/Execution.h>
2021
#include <clang/Tooling/Tooling.h>
2122
#include <llvm/ADT/StringExtras.h>
@@ -36,6 +37,11 @@ namespace path = llvm::sys::path;
3637
class XMLGenerator
3738
: public clang::mrdox::Generator
3839
{
40+
Config const& cfg_;
41+
std::string level_;
42+
llvm::raw_ostream* os_ = nullptr;
43+
InfoMap const* infos_ = nullptr;
44+
3945
using Attrs =
4046
std::initializer_list<
4147
std::pair<
@@ -62,19 +68,16 @@ class XMLGenerator
6268
//--------------------------------------------
6369

6470
void write(llvm::ArrayRef<FieldTypeInfo> const& v);
65-
66-
//--------------------------------------------
67-
6871
void write(FieldTypeInfo const& I);
72+
void writeNamespaceRefs(llvm::SmallVector<Reference, 4> const& v);
6973
void write(Reference const& ref);
7074

7175
//--------------------------------------------
7276

7377
void writeInfo(Info const& I);
7478
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);
7881

7982
//--------------------------------------------
8083

@@ -85,6 +88,8 @@ class XMLGenerator
8588
void writeTag(llvm::StringRef, Attrs);
8689
void writeTagLine(llvm::StringRef tag, llvm::StringRef value);
8790
void writeTagLine(llvm::StringRef tag, llvm::StringRef value, Attrs);
91+
void indent();
92+
void outdent();
8893

8994
//--------------------------------------------
9095

@@ -100,13 +105,6 @@ class XMLGenerator
100105

101106
static llvm::StringRef toString(InfoType) noexcept;
102107

103-
//--------------------------------------------
104-
105-
Config const& cfg_;
106-
std::string level_;
107-
llvm::raw_ostream* os_ = nullptr;
108-
InfoMap const* infos_ = nullptr;
109-
110108
public:
111109
static char const* Format;
112110

@@ -275,14 +273,20 @@ write(
275273
{ "usr", toBase64(I.USR) }
276274
});
277275
writeSymbolInfo(I);
276+
writeTag("return", {
277+
{ "name", I.ReturnType.Type.Name },
278+
{ "usr", toString(I.ReturnType.Type.USR) }
279+
});
278280

279-
#if 1
280-
281+
282+
#if 0
281283
writeTag("return", {
282284
{ "name", I.ReturnType.Type.Name },
283285
{ "usr", toString(I.ReturnType.Type.USR) }
284286
});
285-
#else
287+
#endif
288+
289+
#if 0
286290
auto it = infos_->find(llvm::toHex(llvm::toStringRef(
287291
I.ReturnType.Type.USR)));
288292
assert(it != infos_->end());
@@ -326,7 +330,6 @@ write(
326330
{ "value", v.Value },
327331
});
328332
}
329-
writeLoc(I.Loc);
330333
closeTag("enum");
331334
}
332335

@@ -342,7 +345,6 @@ write(
342345
writeSymbolInfo(I);
343346
writeTagLine("qualname", I.Underlying.Type.QualName);
344347
writeTagLine("qualusr", toBase64(I.Underlying.Type.USR));
345-
writeLoc(I.DefLoc);
346348
closeTag("typedef");
347349
}
348350

@@ -357,8 +359,6 @@ write(
357359
write(I);
358360
}
359361

360-
//------------------------------------------------
361-
362362
void
363363
XMLGenerator::
364364
write(FieldTypeInfo const& I)
@@ -373,6 +373,15 @@ write(FieldTypeInfo const& I)
373373
});
374374
}
375375

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+
376385
void
377386
XMLGenerator::
378387
write(
@@ -398,6 +407,9 @@ XMLGenerator::
398407
writeInfo(
399408
Info const& I)
400409
{
410+
writeTagLine("extract-name", I.extractName());
411+
writeTagLine("rel-path", I.getRelativeFilePath(cfg_.SourceRoot));
412+
writeTagLine("base-name", I.getFileBaseName());
401413
}
402414

403415
void
@@ -406,42 +418,29 @@ writeSymbolInfo(
406418
SymbolInfo const& I)
407419
{
408420
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);
420424
}
421425

422426
void
423427
XMLGenerator::
424-
writeLoc(
425-
llvm::ArrayRef<Location> const& loc)
428+
write(
429+
llvm::ArrayRef<Location> const& locs)
426430
{
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);
433433
}
434434

435435
void
436436
XMLGenerator::
437-
writeLoc(
438-
std::optional<Location> const& opt)
437+
write(
438+
Location const& loc)
439439
{
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";
445444
}
446445

447446
//------------------------------------------------
@@ -452,7 +451,7 @@ openTag(
452451
llvm::StringRef tag)
453452
{
454453
*os_ << level_ << '<' << tag << ">\n";
455-
level_.push_back(' ');
454+
indent();
456455
}
457456

458457
void
@@ -467,15 +466,15 @@ openTag(
467466
' ' << attr.first << '=' <<
468467
"\"" << escape(attr.second) << "\"";
469468
*os_ << ">\n";
470-
level_.push_back(' ');
469+
indent();
471470
}
472471

473472
void
474473
XMLGenerator::
475474
closeTag(
476475
llvm::StringRef tag)
477476
{
478-
level_.pop_back();
477+
outdent();
479478
*os_ << level_ << "</" << tag << ">\n";
480479
}
481480

@@ -530,6 +529,20 @@ writeTagLine(
530529
*os_ << ">" << escape(value) << "</" << tag << ">" << "\n";
531530
}
532531

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+
533546
//------------------------------------------------
534547

535548
std::string

0 commit comments

Comments
 (0)