Skip to content

Commit 2b90a02

Browse files
committed
feat: enum dom and adoc work
1 parent 246cd12 commit 2b90a02

File tree

10 files changed

+111
-42
lines changed

10 files changed

+111
-42
lines changed

addons/generator/asciidoc/partials/enum.adoc.hbs

+9
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,14 @@ enum {{name}};
2828
=== Description
2929
3030
{{symbol.doc.description}}
31+
{{/if}}
32+
33+
{{#if symbol.members}}
34+
{{#each symbol.members}}
35+
{{#if doc.description}}
36+
==== {{name}}
3137
38+
{{doc.description}}
39+
{{/if}}
40+
{{/each}}
3241
{{/if}}

include/mrdox/Metadata/Enum.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
namespace clang {
2525
namespace mrdox {
2626

27-
// FIXME: this does not store javadocs...
2827
// Information for a single possible value of an enumeration.
2928
struct EnumValueInfo
3029
{

source/-XML/XMLWriter.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,25 @@ writeEnum(
285285

286286
writeSourceInfo(I);
287287

288-
for(auto const& v : I.Members)
289-
tags_.write("value", {}, {
290-
{ "name", v.Name },
291-
{ "value", v.Value },
288+
for(auto const& V : I.Members)
289+
{
290+
if(! V.javadoc)
291+
{
292+
tags_.write("value", {}, {
293+
{ "name", V.Name },
294+
{ "value", V.Value },
295+
});
296+
}
297+
else
298+
{
299+
tags_.open("value", {
300+
{ "name", V.Name },
301+
{ "value", V.Value }
292302
});
303+
writeJavadoc(V.javadoc);
304+
tags_.close("value");
305+
}
306+
}
293307

294308
writeJavadoc(I.javadoc);
295309

source/-adoc/Builder.cpp

+11-26
Original file line numberDiff line numberDiff line change
@@ -206,41 +206,26 @@ createContext(
206206
}));
207207
}
208208

209+
template<class T>
209210
Expected<std::string>
210211
Builder::
211-
operator()(NamespaceInfo const& I)
212+
operator()(T const& I)
212213
{
213214
return callTemplate(
214215
"single-symbol.adoc.hbs",
215216
createContext(I.id));
216217
}
217218

218-
Expected<std::string>
219-
Builder::
220-
operator()(RecordInfo const& I)
221-
{
222-
return callTemplate(
223-
"single-symbol.adoc.hbs",
224-
createContext(I.id));
225-
}
226-
227-
Expected<std::string>
228-
Builder::
229-
operator()(FunctionInfo const& I)
230-
{
231-
return callTemplate(
232-
"single-symbol.adoc.hbs",
233-
createContext(I.id));
234-
}
219+
#define DEFINE(T) template Expected<std::string> \
220+
Builder::operator()<T>(T const&)
235221

236-
Expected<std::string>
237-
Builder::
238-
operator()(EnumInfo const& I)
239-
{
240-
return callTemplate(
241-
"single-symbol.adoc.hbs",
242-
createContext(I.id));
243-
}
222+
DEFINE(NamespaceInfo);
223+
DEFINE(RecordInfo);
224+
DEFINE(FunctionInfo);
225+
DEFINE(EnumInfo);
226+
DEFINE(TypedefInfo);
227+
DEFINE(VariableInfo);
228+
DEFINE(FieldInfo);
244229

245230
} // adoc
246231
} // mrdox

source/-adoc/Builder.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ class Builder
4949
dom::ObjectPtr getSymbol(SymbolID const& id);
5050
dom::ObjectPtr createContext(SymbolID const& id);
5151

52-
Expected<std::string> operator()(NamespaceInfo const&);
53-
Expected<std::string> operator()(RecordInfo const&);
54-
Expected<std::string> operator()(FunctionInfo const&);
55-
Expected<std::string> operator()(EnumInfo const&);
52+
template<class T>
53+
Expected<std::string> operator()(T const&);
5654
};
5755

5856
} // adoc

source/AST/ASTVisitor.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,12 @@ parseEnumerators(
576576

577577
SmallString<16> ValueStr;
578578
E->getInitVal().toString(ValueStr);
579-
I.Members.emplace_back(E->getNameAsString(), ValueStr.str(), ValueExpr);
579+
580+
I.Members.emplace_back(
581+
E->getNameAsString(),
582+
ValueStr.str(),
583+
ValueExpr);
584+
parseRawComment(I.Members.back().javadoc, E);
580585
}
581586
}
582587

source/AST/AnyBlock.hpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -932,11 +932,14 @@ class TypedefBlock
932932
class EnumValueBlock : public BitcodeReader::AnyBlock
933933
{
934934
EnumValueInfo& I_;
935+
BitcodeReader& br_;
935936

936937
public:
937938
EnumValueBlock(
938-
EnumValueInfo& I) noexcept
939+
EnumValueInfo& I,
940+
BitcodeReader& br) noexcept
939941
: I_(I)
942+
, br_(br)
940943
{
941944
}
942945

@@ -956,6 +959,22 @@ class EnumValueBlock : public BitcodeReader::AnyBlock
956959
return AnyBlock::parseRecord(R, ID, Blob);
957960
}
958961
}
962+
963+
Error
964+
readSubBlock(
965+
unsigned ID) override
966+
{
967+
switch(ID)
968+
{
969+
case BI_JAVADOC_BLOCK_ID:
970+
{
971+
JavadocBlock B(I_.javadoc, br_);
972+
return br_.readBlock(B, ID);
973+
}
974+
default:
975+
return AnyBlock::readSubBlock(ID);
976+
}
977+
}
959978
};
960979

961980
class EnumBlock
@@ -997,7 +1016,7 @@ class EnumBlock
9971016
case BI_ENUM_VALUE_BLOCK_ID:
9981017
{
9991018
I->Members.emplace_back();
1000-
EnumValueBlock B(I->Members.back());
1019+
EnumValueBlock B(I->Members.back(), br_);
10011020
return br_.readBlock(B, ID);
10021021
}
10031022
default:

source/AST/BitcodeWriter.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ emitBlock(
788788
emitRecord(I.Name, ENUM_VALUE_NAME);
789789
emitRecord(I.Value, ENUM_VALUE_VALUE);
790790
emitRecord(I.ValueExpr, ENUM_VALUE_EXPR);
791+
emitBlock(I.javadoc);
791792
}
792793

793794
void

test-files/adoc/test.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
struct T {};
22

3+
/** This is an enum
4+
5+
Good enum.
6+
*/
37
enum E
48
{
59
/** hmm

test-files/adoc/test.xml

+39-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,44 @@
55
<struct name="T" id="CgGNdHpW5mG/i5741WPYQDw28OQ=">
66
<file path="test.cpp" line="1" class="def"/>
77
</struct>
8-
<function name="f" id="sgP6K1YoLuQEErJPRWdhzK0NBdQ=">
9-
<file path="test.cpp" line="2"/>
10-
<param name="t" type="const T &amp;" id="CgGNdHpW5mG/i5741WPYQDw28OQ="/>
11-
</function>
8+
<enum name="E" id="xf6YhxRw8JpsHMwP6Tgyroti2gw=">
9+
<file path="test.cpp" line="7" class="def"/>
10+
<value name="a" value="0">
11+
<doc>
12+
<para>
13+
<text> hmm</text>
14+
</para>
15+
</doc>
16+
</value>
17+
<value name="b" value="2">
18+
<doc>
19+
<para>
20+
<text> hmm</text>
21+
</para>
22+
</doc>
23+
</value>
24+
<value name="c" value="3">
25+
<doc>
26+
<para>
27+
<text> hmm</text>
28+
</para>
29+
</doc>
30+
</value>
31+
<value name="d" value="4">
32+
<doc>
33+
<para>
34+
<text> hmm</text>
35+
</para>
36+
</doc>
37+
</value>
38+
<doc>
39+
<brief>
40+
<text> This is an enum</text>
41+
</brief>
42+
<para>
43+
<text> Good enum.</text>
44+
</para>
45+
</doc>
46+
</enum>
1247
</namespace>
1348
</mrdox>

0 commit comments

Comments
 (0)