Skip to content

Commit

Permalink
feat: enum dom and adoc work
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Jun 21, 2023
1 parent 246cd12 commit 2b90a02
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 42 deletions.
9 changes: 9 additions & 0 deletions addons/generator/asciidoc/partials/enum.adoc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ enum {{name}};
=== Description
{{symbol.doc.description}}
{{/if}}
{{#if symbol.members}}
{{#each symbol.members}}
{{#if doc.description}}
==== {{name}}
{{doc.description}}
{{/if}}
{{/each}}
{{/if}}
1 change: 0 additions & 1 deletion include/mrdox/Metadata/Enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
namespace clang {
namespace mrdox {

// FIXME: this does not store javadocs...
// Information for a single possible value of an enumeration.
struct EnumValueInfo
{
Expand Down
22 changes: 18 additions & 4 deletions source/-XML/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,25 @@ writeEnum(

writeSourceInfo(I);

for(auto const& v : I.Members)
tags_.write("value", {}, {
{ "name", v.Name },
{ "value", v.Value },
for(auto const& V : I.Members)
{
if(! V.javadoc)
{
tags_.write("value", {}, {
{ "name", V.Name },
{ "value", V.Value },
});
}
else
{
tags_.open("value", {
{ "name", V.Name },
{ "value", V.Value }
});
writeJavadoc(V.javadoc);
tags_.close("value");
}
}

writeJavadoc(I.javadoc);

Expand Down
37 changes: 11 additions & 26 deletions source/-adoc/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,41 +206,26 @@ createContext(
}));
}

template<class T>
Expected<std::string>
Builder::
operator()(NamespaceInfo const& I)
operator()(T const& I)
{
return callTemplate(
"single-symbol.adoc.hbs",
createContext(I.id));
}

Expected<std::string>
Builder::
operator()(RecordInfo const& I)
{
return callTemplate(
"single-symbol.adoc.hbs",
createContext(I.id));
}

Expected<std::string>
Builder::
operator()(FunctionInfo const& I)
{
return callTemplate(
"single-symbol.adoc.hbs",
createContext(I.id));
}
#define DEFINE(T) template Expected<std::string> \
Builder::operator()<T>(T const&)

Expected<std::string>
Builder::
operator()(EnumInfo const& I)
{
return callTemplate(
"single-symbol.adoc.hbs",
createContext(I.id));
}
DEFINE(NamespaceInfo);
DEFINE(RecordInfo);
DEFINE(FunctionInfo);
DEFINE(EnumInfo);
DEFINE(TypedefInfo);
DEFINE(VariableInfo);
DEFINE(FieldInfo);

} // adoc
} // mrdox
Expand Down
6 changes: 2 additions & 4 deletions source/-adoc/Builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ class Builder
dom::ObjectPtr getSymbol(SymbolID const& id);
dom::ObjectPtr createContext(SymbolID const& id);

Expected<std::string> operator()(NamespaceInfo const&);
Expected<std::string> operator()(RecordInfo const&);
Expected<std::string> operator()(FunctionInfo const&);
Expected<std::string> operator()(EnumInfo const&);
template<class T>
Expected<std::string> operator()(T const&);
};

} // adoc
Expand Down
7 changes: 6 additions & 1 deletion source/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,12 @@ parseEnumerators(

SmallString<16> ValueStr;
E->getInitVal().toString(ValueStr);
I.Members.emplace_back(E->getNameAsString(), ValueStr.str(), ValueExpr);

I.Members.emplace_back(
E->getNameAsString(),
ValueStr.str(),
ValueExpr);
parseRawComment(I.Members.back().javadoc, E);
}
}

Expand Down
23 changes: 21 additions & 2 deletions source/AST/AnyBlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,14 @@ class TypedefBlock
class EnumValueBlock : public BitcodeReader::AnyBlock
{
EnumValueInfo& I_;
BitcodeReader& br_;

public:
EnumValueBlock(
EnumValueInfo& I) noexcept
EnumValueInfo& I,
BitcodeReader& br) noexcept
: I_(I)
, br_(br)
{
}

Expand All @@ -956,6 +959,22 @@ class EnumValueBlock : public BitcodeReader::AnyBlock
return AnyBlock::parseRecord(R, ID, Blob);
}
}

Error
readSubBlock(
unsigned ID) override
{
switch(ID)
{
case BI_JAVADOC_BLOCK_ID:
{
JavadocBlock B(I_.javadoc, br_);
return br_.readBlock(B, ID);
}
default:
return AnyBlock::readSubBlock(ID);
}
}
};

class EnumBlock
Expand Down Expand Up @@ -997,7 +1016,7 @@ class EnumBlock
case BI_ENUM_VALUE_BLOCK_ID:
{
I->Members.emplace_back();
EnumValueBlock B(I->Members.back());
EnumValueBlock B(I->Members.back(), br_);
return br_.readBlock(B, ID);
}
default:
Expand Down
1 change: 1 addition & 0 deletions source/AST/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ emitBlock(
emitRecord(I.Name, ENUM_VALUE_NAME);
emitRecord(I.Value, ENUM_VALUE_VALUE);
emitRecord(I.ValueExpr, ENUM_VALUE_EXPR);
emitBlock(I.javadoc);
}

void
Expand Down
4 changes: 4 additions & 0 deletions test-files/adoc/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
struct T {};

/** This is an enum
Good enum.
*/
enum E
{
/** hmm
Expand Down
43 changes: 39 additions & 4 deletions test-files/adoc/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,44 @@
<struct name="T" id="CgGNdHpW5mG/i5741WPYQDw28OQ=">
<file path="test.cpp" line="1" class="def"/>
</struct>
<function name="f" id="sgP6K1YoLuQEErJPRWdhzK0NBdQ=">
<file path="test.cpp" line="2"/>
<param name="t" type="const T &amp;" id="CgGNdHpW5mG/i5741WPYQDw28OQ="/>
</function>
<enum name="E" id="xf6YhxRw8JpsHMwP6Tgyroti2gw=">
<file path="test.cpp" line="7" class="def"/>
<value name="a" value="0">
<doc>
<para>
<text> hmm</text>
</para>
</doc>
</value>
<value name="b" value="2">
<doc>
<para>
<text> hmm</text>
</para>
</doc>
</value>
<value name="c" value="3">
<doc>
<para>
<text> hmm</text>
</para>
</doc>
</value>
<value name="d" value="4">
<doc>
<para>
<text> hmm</text>
</para>
</doc>
</value>
<doc>
<brief>
<text> This is an enum</text>
</brief>
<para>
<text> Good enum.</text>
</para>
</doc>
</enum>
</namespace>
</mrdox>

0 comments on commit 2b90a02

Please sign in to comment.