Skip to content

Commit a505a3d

Browse files
committed
xml work
1 parent 5d610a6 commit a505a3d

File tree

12 files changed

+230
-184
lines changed

12 files changed

+230
-184
lines changed

NOTES.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ cmake --install . --prefix "C:\Users\vinnie\src\llvm-install\Debug" --config Deb
1515
# MrDox
1616
cmake -G "Visual Studio 17 2022" -A x64 -B bin64 -DCMAKE_PREFIX_PATH="C:\Users\vinnie\src\llvm-install\RelWithDebInfo" -DCMAKE_TOOLCHAIN_FILE="C:\Users\vinnie\src\mrdox\toolchain.cmake"
1717
```
18+
19+
== Implementation notes
20+
21+
Namespaces do not have a source location. This is because there
22+
can be many namespaces. We probably don't want to store any
23+
javadocs for namespaces either.

include/mrdox/Corpus.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ namespace mrdox {
2323

2424
/** The collection of declarations in extracted form.
2525
*/
26-
struct Corpus
26+
class Corpus
2727
{
28+
public:
2829
/** Index of all emitted symbols.
2930
*/
3031
Index Idx;

source/lib/Asciidoc.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ struct AsciidocGenerator : Generator
7171
Corpus const& corpus,
7272
Config const& config,
7373
Reporter& R) const;
74-
75-
llvm::Error
76-
generateDocForInfo(
77-
Info* I,
78-
llvm::raw_ostream& os,
79-
Config const& config);
8074
};
8175

8276
//------------------------------------------------

source/lib/Symbol.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
namespace clang {
2020
namespace mrdox {
2121

22-
// Info for symbols.
23-
struct SymbolInfo
24-
: public Info
22+
/** Base class for Info that have source locations.
23+
*/
24+
struct SymbolInfo : Info
2525
{
26+
llvm::Optional<Location> DefLoc; // Location where this decl is defined.
27+
llvm::SmallVector<Location, 2> Loc; // Locations where this decl is declared.
28+
29+
//--------------------------------------------
30+
2631
explicit
2732
SymbolInfo(
2833
InfoType IT,
@@ -34,9 +39,6 @@ struct SymbolInfo
3439
}
3540

3641
void merge(SymbolInfo&& I);
37-
38-
llvm::Optional<Location> DefLoc; // Location where this decl is defined.
39-
llvm::SmallVector<Location, 2> Loc; // Locations where this decl is declared.
4042
};
4143

4244
} // mrdox

source/lib/Visitor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ mapDecl(T const* D)
106106
config_.PublicOnly,
107107
R_);
108108

109-
// A null in place of I indicates that the serializer is skipping this decl
110-
// for some reason (e.g. we're only reporting public decls).
109+
// A null in place of I indicates that the
110+
// serializer is skipping this decl for some
111+
// reason (e.g. we're only reporting public decls).
111112
if (I.first)
112113
Corpus::reportResult(exc_, *I.first);
113114
if (I.second)
@@ -159,8 +160,6 @@ VisitFunctionDecl(
159160
return mapDecl(D);
160161
}
161162

162-
// https://github.com/llvm/llvm-project/blob/466d554dcab39c3d42fe0c5b588b795e0e4b9d0d/clang/include/clang/AST/Type.h#L1566
163-
164163
bool
165164
Visitor::
166165
VisitTypedefDecl(TypedefDecl const* D)

source/lib/XML.cpp

Lines changed: 58 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ buildOne(
4646
}
4747

4848
Writer w(corpus, config, R);
49-
return w.build(os);
49+
return w.write(os);
5050
}
5151

5252
bool
@@ -60,7 +60,7 @@ buildString(
6060
dest.clear();
6161
llvm::raw_string_ostream os(dest);
6262
Writer w(corpus, config, R);
63-
return w.build(os);
63+
return w.write(os);
6464
}
6565

6666
//------------------------------------------------
@@ -69,9 +69,20 @@ buildString(
6969
//
7070
//------------------------------------------------
7171

72+
Writer::
73+
Writer(
74+
Corpus const& corpus,
75+
Config const& config,
76+
Reporter& R) noexcept
77+
: corpus_(corpus)
78+
, config_(config)
79+
, R_(R)
80+
{
81+
}
82+
7283
bool
7384
Writer::
74-
build(
85+
write(
7586
llvm::raw_ostream& os)
7687
{
7788
auto const ns = findGlobalNamespace();
@@ -178,8 +189,6 @@ Writer::
178189
write(
179190
NamespaceInfo const& I)
180191
{
181-
assertExists(I);
182-
183192
openTag("namespace", {
184193
{ "name", I.Name },
185194
{ I.USR }
@@ -198,8 +207,6 @@ Writer::
198207
write(
199208
RecordInfo const& I)
200209
{
201-
assertExists(I);
202-
203210
llvm::StringRef tag;
204211
switch(I.TagType)
205212
{
@@ -226,21 +233,17 @@ Writer::
226233
write(
227234
FunctionInfo const& I)
228235
{
229-
//assertExists(I);
230-
231236
openTag("function", {
232237
{ "name", I.Name },
233-
{ "access", toString(I.Access) },
238+
{ I.Access },
234239
{ I.USR }
235240
});
236241
writeSymbolInfo(I);
237242
writeTag("return", {
238243
{ "name", I.ReturnType.Type.Name },
239244
{ I.ReturnType.Type.USR }
240245
});
241-
242246
write(I.Params);
243-
244247
write(I.ReturnType.Type);
245248
if(I.Template)
246249
{
@@ -250,7 +253,6 @@ write(
250253
{ "n", tp.Contents }
251254
});
252255
}
253-
write(I.Loc);
254256

255257
closeTag("function");
256258
}
@@ -260,8 +262,6 @@ Writer::
260262
write(
261263
EnumInfo const& I)
262264
{
263-
//assertExists(I);
264-
265265
openTag("enum", {
266266
{ "name", I.Name },
267267
{ I.USR }
@@ -282,18 +282,36 @@ Writer::
282282
write(
283283
TypedefInfo const& I)
284284
{
285-
//assertExists(I);
286-
285+
writeSymbolInfo(I);
287286
openTag("typedef", {
288287
{ "name", I.Name },
289288
{ I.USR }
290289
});
291-
writeSymbolInfo(I);
292290
if(I.Underlying.Type.USR != EmptySID)
293291
writeTagLine("qualusr", toBase64(I.Underlying.Type.USR));
294292
closeTag("typedef");
295293
}
296294

295+
void
296+
Writer::
297+
writeSymbolInfo(
298+
SymbolInfo const& I)
299+
{
300+
writeInfo(I);
301+
// VFALCO Why so many Location?
302+
if(I.DefLoc)
303+
write(*I.DefLoc);
304+
for(auto const& loc : I.Loc)
305+
write(loc);
306+
}
307+
308+
void
309+
Writer::
310+
writeInfo(
311+
Info const& I)
312+
{
313+
}
314+
297315
//------------------------------------------------
298316

299317
void
@@ -337,57 +355,22 @@ write(
337355
//});
338356
//writeTagLine("relpath", ref.getRelativeFilePath());
339357
//writeTagLine("basename",I.getFileBaseName());
340-
writeTagLine("name", I.Name);
341-
writeTagLine("tag", std::to_string(static_cast<int>(I.RefType)));
342-
writeTagLine("path", I.Path);
358+
//writeTagLine("name", I.Name);
359+
//writeTagLine("tag", std::to_string(static_cast<int>(I.RefType)));
360+
//writeTagLine("path", I.Path);
343361
//closeTag("ref");
344362
}
345363

346364
//------------------------------------------------
347365

348-
void
349-
Writer::
350-
writeInfo(
351-
Info const& I)
352-
{
353-
#if 0
354-
writeTagLine("extract-name", I.extractName());
355-
auto relPath = I.getRelativeFilePath(config_.SourceRoot);
356-
if(! relPath.empty())
357-
writeTagLine("rel-path", relPath);
358-
writeTagLine("base-name", I.getFileBaseName());
359-
#endif
360-
}
361-
362-
void
363-
Writer::
364-
writeSymbolInfo(
365-
SymbolInfo const& I)
366-
{
367-
writeInfo(I);
368-
if(I.DefLoc)
369-
write(*I.DefLoc);
370-
write(I.Loc);
371-
}
372-
373-
void
374-
Writer::
375-
write(
376-
llvm::ArrayRef<Location> const& locs)
377-
{
378-
for(auto const& loc : locs)
379-
write(loc);
380-
}
381-
382366
void
383367
Writer::
384368
write(
385369
Location const& loc)
386370
{
387-
*os_ << level_ <<
388-
"<file>" << escape(loc.Filename) <<
389-
"</file><line>" << std::to_string(loc.LineNumber) <<
390-
"</line>\n";
371+
writeTag("file", {
372+
{ "path", loc.Filename },
373+
{ "line", std::to_string(loc.LineNumber) }});
391374
}
392375

393376
//------------------------------------------------
@@ -494,6 +477,22 @@ outdent()
494477

495478
//------------------------------------------------
496479

480+
NamespaceInfo const*
481+
Writer::
482+
findGlobalNamespace()
483+
{
484+
auto p = corpus_.find(EmptySID);
485+
if(p != nullptr)
486+
{
487+
assert(p->Name.empty());
488+
assert(p->IT == InfoType::IT_namespace);
489+
return static_cast<NamespaceInfo const*>(p);
490+
}
491+
return nullptr;
492+
}
493+
494+
//------------------------------------------------
495+
497496
std::string
498497
Writer::
499498
toString(
@@ -521,32 +520,6 @@ toString(
521520
}
522521
}
523522

524-
//------------------------------------------------
525-
526-
NamespaceInfo const*
527-
Writer::
528-
findGlobalNamespace()
529-
{
530-
auto p = corpus_.find(EmptySID);
531-
if(p != nullptr)
532-
{
533-
assert(p->Name.empty());
534-
assert(p->IT == InfoType::IT_namespace);
535-
return static_cast<NamespaceInfo const*>(p);
536-
}
537-
return nullptr;
538-
}
539-
540-
#ifndef NDEBUG
541-
void
542-
Writer::
543-
assertExists(
544-
Info const& I)
545-
{
546-
assert(corpus_.exists(I.USR));
547-
}
548-
#endif
549-
550523
llvm::StringRef
551524
Writer::
552525
toString(
@@ -567,16 +540,6 @@ toString(
567540

568541
//------------------------------------------------
569542

570-
llvm::Error
571-
Writer::
572-
generateDocForInfo(
573-
clang::mrdox::Info* I,
574-
llvm::raw_ostream& os,
575-
clang::mrdox::Config const& config)
576-
{
577-
return llvm::Error::success();
578-
}
579-
580543
} // (anon)
581544

582545
//------------------------------------------------

0 commit comments

Comments
 (0)