Skip to content

Commit ca1ce30

Browse files
committed
adoc work
1 parent 7890557 commit ca1ce30

File tree

10 files changed

+231
-49
lines changed

10 files changed

+231
-49
lines changed

include/mrdox/Corpus.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class MRDOX_VISIBLE
104104
*/
105105
/** @{ */
106106
MRDOX_DECL bool visit(SymbolID id, Visitor& f) const;
107+
MRDOX_DECL bool visit(std::vector<Reference> const& R, Visitor& f) const;
108+
MRDOX_DECL bool visit(std::vector<SymbolID> const& R, Visitor& f) const;
107109
MRDOX_DECL bool visit(Scope const& I, Visitor& f) const;
108110
MRDOX_DECL bool visitWithOverloads(Scope const& I, Visitor& f) const;
109111
MRDOX_DECL bool visit(Info const& I, Visitor& f) const;

source/lib/Metadata/Corpus.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,28 @@ visit(SymbolID id, Visitor& f) const
137137
return visit(get<Info>(id), f);
138138
}
139139

140+
bool
141+
Corpus::
142+
visit(
143+
std::vector<Reference> const& R, Visitor& f) const
144+
{
145+
for(auto const& ref : R)
146+
if(! visit(get<Info>(ref.id), f))
147+
return false;
148+
return true;
149+
}
150+
151+
bool
152+
Corpus::
153+
visit(
154+
std::vector<SymbolID> const& R, Visitor& f) const
155+
{
156+
for(auto const& id : R)
157+
if(! visit(get<Info>(id), f))
158+
return false;
159+
return true;
160+
}
161+
140162
bool
141163
Corpus::
142164
visit(Scope const& I, Visitor& f) const

source/lib/_adoc/AdocGenerator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ buildSinglePage(
4343
Reporter& R,
4444
llvm::raw_fd_ostream* fd_os) const
4545
{
46-
AdocSinglePageWriter w(os, fd_os, corpus, R);
47-
return w.build();
46+
return AdocSinglePageWriter(os, fd_os, corpus, R).build();
4847
}
4948

5049
} // adoc

source/lib/_adoc/AdocMultiPageWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ AdocMultiPageWriter(
2222
Corpus const& corpus,
2323
SafeNames const& names,
2424
Reporter& R) noexcept
25-
: AdocWriter(os, fd_os, corpus, R)
25+
: AdocWriter(os, fd_os, names, corpus, R)
2626
, names_(names)
2727
{
2828
}

source/lib/_adoc/AdocSinglePageWriter.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ AdocSinglePageWriter(
2121
llvm::raw_fd_ostream* fd_os,
2222
Corpus const& corpus,
2323
Reporter& R) noexcept
24-
: AdocWriter(os, fd_os, corpus, R)
24+
: AdocWriter(os, fd_os, names_, corpus, R)
25+
, names_(corpus)
2526
{
2627
}
2728

@@ -45,7 +46,28 @@ AdocSinglePageWriter::
4546
visit(
4647
NamespaceInfo const& I)
4748
{
48-
return corpus_.visit(I.Children, *this);
49+
write(I);
50+
if(! corpus_.visit(I.Children.Namespaces, *this))
51+
return false;
52+
53+
// Visit records in alphabetical display order
54+
std::vector<RecordInfo const*> list;
55+
list.reserve(I.Children.Records.size());
56+
for(auto const& ref : I.Children.Records)
57+
list.push_back(&corpus_.get<RecordInfo>(ref.id));
58+
std::string s0, s1;
59+
llvm::sort(list,
60+
[&s0, &s1](Info const* I0, Info const* I1)
61+
{
62+
return compareSymbolNames(
63+
I0->getFullyQualifiedName(s0),
64+
I1->getFullyQualifiedName(s1)) < 0;
65+
});
66+
for(auto const I : list)
67+
if(! visit(*I))
68+
return false;
69+
70+
return true;
4971
}
5072

5173
bool
@@ -54,7 +76,7 @@ visit(
5476
RecordInfo const& I)
5577
{
5678
write(I);
57-
return corpus_.visit(I.Children, *this);
79+
return true;
5880
}
5981

6082
bool

source/lib/_adoc/AdocSinglePageWriter.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define MRDOX_LIB_ADOC_ADOCSINGLEPAGEWRITER_HPP
1313

1414
#include "AdocWriter.hpp"
15+
#include "SafeNames.hpp"
1516
#include <mrdox/Corpus.hpp>
1617

1718
namespace clang {
@@ -22,6 +23,8 @@ class AdocSinglePageWriter
2223
: public AdocWriter
2324
, public Corpus::Visitor
2425
{
26+
SafeNames names_;
27+
2528
public:
2629
AdocSinglePageWriter(
2730
llvm::raw_ostream& os,

source/lib/_adoc/AdocWriter.cpp

Lines changed: 142 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ struct AdocWriter::FormalParam
3535
llvm::raw_ostream& os,
3636
FormalParam const& t)
3737
{
38-
t.w.writeFormalParam(t, os);
38+
os << t.I.Type.Name << ' ' << t.I.Name;
3939
return os;
4040
}
4141
};
4242

4343
struct AdocWriter::TypeName
4444
{
4545
TypeInfo const& I;
46+
Corpus const& corpus;
4647
AdocWriter& w;
4748

4849
friend
@@ -51,7 +52,21 @@ struct AdocWriter::TypeName
5152
llvm::raw_ostream& os,
5253
TypeName const& t)
5354
{
54-
t.w.writeTypeName(t, os);
55+
if(t.I.Type.id == globalNamespaceID)
56+
{
57+
os << t.I.Type.Name;
58+
return os;
59+
}
60+
if(t.corpus.exists(t.I.Type.id))
61+
{
62+
auto const& J = t.corpus.get<RecordInfo>(t.I.Type.id);
63+
// VFALCO add namespace qualifiers if I is in
64+
// a different namesapce
65+
os << J.Name << "::" << J.Name;
66+
return os;
67+
}
68+
auto const& T = t.I.Type;
69+
os << T.Name << "::" << T.Name;
5570
return os;
5671
}
5772
};
@@ -66,27 +81,19 @@ AdocWriter::
6681
AdocWriter(
6782
llvm::raw_ostream& os,
6883
llvm::raw_fd_ostream* fd_os,
84+
SafeNames const& names,
6985
Corpus const& corpus,
7086
Reporter& R) noexcept
7187
: os_(os)
7288
, fd_os_(fd_os)
89+
, names_(names)
7390
, corpus_(corpus)
7491
, R_(R)
7592
{
7693
}
7794

7895
//------------------------------------------------
7996

80-
void
81-
AdocWriter::
82-
writeFormalParam(
83-
FormalParam const& t,
84-
llvm::raw_ostream& os)
85-
{
86-
auto const& I = t.I;
87-
os << I.Type.Name << ' ' << I.Name;
88-
}
89-
9097
auto
9198
AdocWriter::
9299
formalParam(
@@ -98,12 +105,95 @@ formalParam(
98105

99106
//------------------------------------------------
100107

108+
/* Write a namespace.
109+
110+
This will list individual symbols by group.
111+
*/
112+
void
113+
AdocWriter::
114+
write(
115+
NamespaceInfo const& I)
116+
{
117+
if( I.Children.Records.empty() &&
118+
I.Children.Functions.empty() &&
119+
I.Children.Typedefs.empty() &&
120+
I.Children.Enums.empty())
121+
return;
122+
123+
std::string s;
124+
I.getFullyQualifiedName(s);
125+
s = "namespace " + s;
126+
127+
openSection(s);
128+
129+
if(! I.Children.Records.empty())
130+
{
131+
openSection("Classes");
132+
os_ << "\n"
133+
"[cols=1]\n"
134+
"|===\n";
135+
for(auto const& ref : I.Children.Records)
136+
{
137+
auto const& I = corpus_.get<RecordInfo>(ref.id);
138+
os_ << "\n|" << linkFor(I) << '\n';
139+
};
140+
os_ <<
141+
"|===\n";
142+
closeSection();
143+
}
144+
145+
if(! I.Children.Functions.empty())
146+
{
147+
openSection("Functions");
148+
os_ << '\n';
149+
for(auto const& ref : I.Children.Functions)
150+
{
151+
auto const& I = corpus_.get<FunctionInfo>(ref.id);
152+
os_ << linkFor(I) << '\n';
153+
};
154+
closeSection();
155+
}
156+
157+
if(! I.Children.Typedefs.empty())
158+
{
159+
openSection("Types");
160+
os_ << '\n';
161+
for(auto const& ref : I.Children.Typedefs)
162+
{
163+
auto const& I = corpus_.get<TypedefInfo>(ref.id);
164+
os_ << linkFor(I) << '\n';
165+
};
166+
closeSection();
167+
}
168+
169+
if(! I.Children.Enums.empty())
170+
{
171+
openSection("Constants");
172+
os_ << '\n';
173+
for(auto const& ref : I.Children.Enums)
174+
{
175+
auto const& I = corpus_.get<EnumInfo>(ref.id);
176+
os_ << linkFor(I) << '\n';
177+
};
178+
closeSection();
179+
}
180+
181+
closeSection();
182+
}
183+
184+
//------------------------------------------------
185+
186+
/* Write a class/union/struct.
187+
188+
This will show the synopsis, description, and
189+
tables for members which link to individual sections.
190+
*/
101191
void
102192
AdocWriter::
103193
write(
104194
RecordInfo const& I)
105195
{
106-
openSection(I.Name);
196+
openSection(I);
107197

108198
// Brief
109199
writeBrief(I.javadoc);
@@ -274,7 +364,13 @@ AdocWriter::
274364
linkFor(
275365
Info const& I)
276366
{
277-
return I.Name;
367+
static thread_local std::string temp;
368+
temp.clear();
369+
llvm::raw_string_ostream os(temp);
370+
os << "xref:#" <<
371+
names_.get(I.id) << "[" <<
372+
I.Name << "]";
373+
return temp;
278374
}
279375

280376
void
@@ -627,40 +723,33 @@ writeNode(
627723

628724
//------------------------------------------------
629725

630-
void
631-
AdocWriter::
632-
writeTypeName(
633-
TypeName const& t,
634-
llvm::raw_ostream& os)
635-
{
636-
if(t.I.Type.id == globalNamespaceID)
637-
{
638-
os_ << t.I.Type.Name;
639-
return;
640-
}
641-
if(corpus_.exists(t.I.Type.id))
642-
{
643-
auto const& J = corpus_.get<RecordInfo>(t.I.Type.id);
644-
// VFALCO add namespace qualifiers if I is in
645-
// a different namesapce
646-
os_ << J.Name << "::" << J.Name;
647-
return;
648-
}
649-
auto const& T = t.I.Type;
650-
os_ << T.Name << "::" << T.Name;
651-
}
652-
653726
auto
654727
AdocWriter::
655728
typeName(
656729
TypeInfo const& t) ->
657730
TypeName
658731
{
659-
return TypeName{ t, *this };
732+
return TypeName{ t, corpus_, *this };
660733
}
661734

662735
//------------------------------------------------
663736

737+
void
738+
AdocWriter::
739+
openSection(
740+
Info const& I)
741+
{
742+
Assert(validSectionID(names_.get(I.id)));
743+
744+
sect_.level++;
745+
if(sect_.level <= 6)
746+
sect_.markup.push_back('=');
747+
os_ <<
748+
"\n" <<
749+
"[\"#" << names_.get(I.id) << "\"]\n" <<
750+
sect_.markup << ' ' << I.Name << "\n";
751+
}
752+
664753
void
665754
AdocWriter::
666755
openSection(
@@ -686,6 +775,21 @@ closeSection()
686775

687776
//------------------------------------------------
688777

778+
bool
779+
AdocWriter::
780+
validSectionID(
781+
llvm::StringRef s) noexcept
782+
{
783+
if(s.empty())
784+
return false;
785+
return
786+
s[0] == '_' ||
787+
s[0] == ':' ||
788+
isalpha(s[0]);
789+
}
790+
791+
//------------------------------------------------
792+
689793
llvm::StringRef
690794
AdocWriter::
691795
toString(TagTypeKind k) noexcept

0 commit comments

Comments
 (0)