Skip to content

Commit dd044d2

Browse files
committed
base class work
1 parent 9995520 commit dd044d2

File tree

7 files changed

+85
-70
lines changed

7 files changed

+85
-70
lines changed

include/mrdox/Corpus.hpp

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@
1717
#include <mrdox/Reporter.hpp>
1818
#include <clang/Tooling/Execution.h>
1919
#include <llvm/Support/Mutex.h>
20+
#include <type_traits>
2021

2122
namespace clang {
2223
namespace mrdox {
2324

25+
struct Info;
26+
struct NamespaceInfo;
27+
struct RecordInfo;
28+
struct FunctionInfo;
29+
struct EnumInfo;
30+
struct TypedefInfo;
31+
2432
/** The collection of declarations in extracted form.
2533
*/
2634
class Corpus
@@ -45,41 +53,53 @@ class Corpus
4553
//
4654
//--------------------------------------------
4755

48-
/** Return a pointer to the Info with the specified symbol ID, or nullptr.
49-
*/
50-
Info const*
51-
find(
52-
SymbolID const& id) const noexcept;
53-
5456
/** Return true if an Info with the specified symbol ID exists.
5557
*/
5658
bool
5759
exists(SymbolID const& id) const noexcept
5860
{
59-
return find(id) != nullptr;
61+
return find<Info>(id) != nullptr;
6062
}
6163

62-
/** Return the Info with the specified symbol ID.
63-
64-
If the id does not exist, the behavior is undefined.
64+
/** Return a pointer to the Info with the specified symbol ID, or nullptr.
6565
*/
66-
Info const&
67-
at(
68-
SymbolID const& id) const noexcept;
66+
template<class T>
67+
T const*
68+
find(
69+
SymbolID const& id) const noexcept
70+
{
71+
auto it = InfoMap.find(llvm::toStringRef(id));
72+
if(it != InfoMap.end())
73+
{
74+
auto const t = static_cast<
75+
T const*>(it->getValue().get());
76+
if constexpr(std::is_same_v<T, NamespaceInfo>)
77+
assert(t->IT == InfoType::IT_namespace);
78+
else if constexpr(std::is_same_v<T, RecordInfo>)
79+
assert(t->IT == InfoType::IT_record);
80+
else if constexpr(std::is_same_v<T, FunctionInfo>)
81+
assert(t->IT == InfoType::IT_function);
82+
else if constexpr(std::is_same_v<T, EnumInfo>)
83+
assert(t->IT == InfoType::IT_enum);
84+
else if constexpr(std::is_same_v<T, TypedefInfo>)
85+
assert(t->IT == InfoType::IT_typedef);
86+
return t;
87+
}
88+
return nullptr;
89+
}
6990

70-
/** Return the T with the specified symbol ID.
91+
/** Return the Info with the specified symbol ID.
7192
72-
If the id does not exist, or the type of the
73-
Info doesn't match T, the behavior is undefined.
93+
If the id does not exist, the behavior is undefined.
7494
*/
7595
template<class T>
7696
T const&
7797
get(
7898
SymbolID const& id) const noexcept
7999
{
80-
auto const& I = at(id);
81-
assert(I.IT == T::type_id);
82-
return static_cast<T const&>(I);
100+
auto p = find<T>(id);
101+
assert(p != nullptr);
102+
return *p;
83103
}
84104

85105
//--------------------------------------------

mrdox.dtd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!ELEMENT mrdox (all, namespace)>
2+
<!ELEMENT all (symbol)>
3+
<!ATTLIST symbol name usr #REQUIRED>
4+
<!ELEMENT namespace>
5+
<!ATTLIST namespace name #REQUIRED>

source/lib/Asciidoc.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ writeAllSymbols()
153153
{
154154
for(auto const& id : corpus_.allSymbols)
155155
{
156-
auto const& I = corpus_.at(id);
156+
auto const& I = corpus_.get<Info>(id);
157157
switch(I.IT)
158158
{
159159
case InfoType::IT_record:
@@ -220,14 +220,14 @@ write(
220220
"[,cpp]\n"
221221
"----\n" <<
222222
toString(I.TagType) << " " << I.Name;
223-
if(! I.Parents.empty())
223+
if(! I.Bases.empty())
224224
{
225225
*os_ << "\n : ";
226-
writeBase(corpus_.get<RecordInfo>(I.Parents[0].USR));
227-
for(std::size_t i = 1; i < I.Parents.size(); ++i)
226+
writeBase(I.Bases[0]);
227+
for(std::size_t i = 1; i < I.Bases.size(); ++i)
228228
{
229229
*os_ << "\n , ";
230-
writeBase(corpus_.get<RecordInfo>(I.Parents[i].USR));
230+
writeBase(I.Bases[i]);
231231
}
232232
}
233233
*os_ <<
@@ -251,9 +251,9 @@ void
251251
AsciidocGenerator::
252252
Writer::
253253
writeBase(
254-
RecordInfo const& I)
254+
BaseRecordInfo const& I)
255255
{
256-
*os_ << I.Name;
256+
*os_ << I.FullName;
257257
}
258258

259259
//------------------------------------------------
@@ -349,10 +349,16 @@ write(
349349
*os_ << t.I.Type.Name;
350350
return;
351351
}
352-
auto const& I = corpus_.get<RecordInfo>(t.I.Type.USR);
353-
// VFALCO add namespace qualifiers if I is in
354-
// a different namesapce
355-
*os_ << I.Name;
352+
auto p = corpus_.find<RecordInfo>(t.I.Type.USR);
353+
if(p != nullptr)
354+
{
355+
// VFALCO add namespace qualifiers if I is in
356+
// a different namesapce
357+
*os_ << p->Path << "::" << p->Name;
358+
return;
359+
}
360+
auto const& T = t.I.Type;
361+
*os_ << T.Path << "::" << T.Name;
356362
}
357363

358364
auto

source/lib/Asciidoc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class AsciidocGenerator::Writer
8989
void writeAllSymbols();
9090

9191
void write(RecordInfo const& I);
92-
void writeBase(RecordInfo const& I);
92+
void writeBase(BaseRecordInfo const& I);
9393

9494
void write(FunctionInfo const& I);
9595

source/lib/Corpus.cpp

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,6 @@
2222
namespace clang {
2323
namespace mrdox {
2424

25-
//------------------------------------------------
26-
//
27-
// Observers
28-
//
29-
//------------------------------------------------
30-
31-
Info const*
32-
Corpus::
33-
find(
34-
SymbolID const& id) const noexcept
35-
{
36-
auto it = InfoMap.find(llvm::toStringRef(id));
37-
if(it != InfoMap.end())
38-
return it->second.get();
39-
return nullptr;
40-
}
41-
42-
Info const&
43-
Corpus::
44-
at(
45-
SymbolID const& id) const noexcept
46-
{
47-
auto it = InfoMap.find(llvm::toStringRef(id));
48-
assert(it != InfoMap.end());
49-
return *it->second.get();
50-
}
51-
5225
//------------------------------------------------
5326
//
5427
// Implementation
@@ -274,8 +247,8 @@ build(
274247
[&](SymbolID const& id0,
275248
SymbolID const& id1) noexcept
276249
{
277-
auto s0 = corpus.at(id0).getFullyQualifiedName(temp[0]);
278-
auto s1 = corpus.at(id1).getFullyQualifiedName(temp[1]);
250+
auto s0 = corpus.get<Info>(id0).getFullyQualifiedName(temp[0]);
251+
auto s1 = corpus.get<Info>(id1).getFullyQualifiedName(temp[1]);
279252
int rv = s0.compare_insensitive(s1);
280253
if(rv < 0)
281254
return true;

source/lib/XML.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,14 @@ write(
101101
}
102102
os_ = &os;
103103
level_ = {};
104-
#if 0
105104
*os_ <<
106105
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" <<
107106
"<!DOCTYPE mrdox SYSTEM \"mrdox.dtd\">\n" <<
108107
"<mrdox>\n";
109-
#endif
110108
writeAllSymbols();
111109
write(*ns);
112-
#if 0
113110
*os_ <<
114111
"</mrdox>\n";
115-
#endif
116112
return true;
117113
}
118114

@@ -126,7 +122,7 @@ writeAllSymbols()
126122
std::string temp;
127123
for(auto const& id : corpus_.allSymbols)
128124
{
129-
auto const& I = corpus_.at(id);
125+
auto const& I = corpus_.get<Info>(id);
130126
writeTag("symbol", {
131127
{ "name", I.getFullyQualifiedName(temp) },
132128
{ I.USR }
@@ -221,6 +217,8 @@ write(
221217
{ I.USR }
222218
});
223219
writeSymbolInfo(I);
220+
for(auto const& t : I.Bases)
221+
write(t);
224222
writeRecords(I.Children.Records);
225223
writeFunctions(I.Children.Functions);
226224
write(I.Children.Enums);
@@ -292,6 +290,19 @@ write(
292290
closeTag("typedef");
293291
}
294292

293+
void
294+
Writer::
295+
write(
296+
BaseRecordInfo const& I)
297+
{
298+
writeTag("base", {
299+
{ "name", I.Name },
300+
{ I.USR }});
301+
if(! corpus_.exists(I.USR))
302+
return;
303+
auto const& B = corpus_.get<RecordInfo>(I.USR);
304+
}
305+
295306
void
296307
Writer::
297308
writeSymbolInfo(
@@ -464,14 +475,14 @@ void
464475
Writer::
465476
indent()
466477
{
467-
level_.append(" ");
478+
level_.append(" ");
468479
}
469480

470481
void
471482
Writer::
472483
outdent()
473484
{
474-
level_.resize(level_.size() - 4);
485+
level_.resize(level_.size() - 2);
475486
}
476487

477488
//------------------------------------------------
@@ -480,12 +491,11 @@ NamespaceInfo const*
480491
Writer::
481492
findGlobalNamespace()
482493
{
483-
auto p = corpus_.find(EmptySID);
494+
auto p = corpus_.find<NamespaceInfo>(EmptySID);
484495
if(p != nullptr)
485496
{
486497
assert(p->Name.empty());
487-
assert(p->IT == InfoType::IT_namespace);
488-
return static_cast<NamespaceInfo const*>(p);
498+
return p;
489499
}
490500
return nullptr;
491501
}

source/lib/XML.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class Writer
9595
void write(FunctionInfo const& I);
9696
void write(EnumInfo const& I);
9797
void write(TypedefInfo const& I);
98+
void write(BaseRecordInfo const& I);
9899
void writeSymbolInfo(SymbolInfo const& I);
99100
void writeInfo(Info const& I);
100101

0 commit comments

Comments
 (0)