Skip to content

Commit

Permalink
chore: enum and adoc template work
Browse files Browse the repository at this point in the history
vinniefalco committed Jun 21, 2023

Verified

This commit was signed with the committer’s verified signature.
BeardedPlatypus Maarten Tegelaers
1 parent 88146bd commit 246cd12
Showing 16 changed files with 140 additions and 28 deletions.
4 changes: 3 additions & 1 deletion addons/generator/asciidoc/layouts/single-symbol.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{{>symbol symbol=symbol}}
{{#with symbol}}
{{> (lookup . 'kind') symbol=.}}
{{/with}}
1 change: 1 addition & 0 deletions addons/generator/asciidoc/partials/data.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{!-- data --}}
32 changes: 32 additions & 0 deletions addons/generator/asciidoc/partials/enum.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{!-- enum --}}
[#{{symbol.id}}]
== {{symbol.name}}

{{symbol.doc.brief}}

=== Synopsis

[source,cpp,subs=+macros]
----
enum {{name}};
----
{{>source symbol.loc}}
{{#if symbol.members}}
=== Members
[,cols=2]
|===
|Name |Description
{{#each symbol.members}}
|{{name}} |{{doc.brief}}
{{/each}}
|===
{{/if}}
{{#if symbol.doc.description}}
=== Description
{{symbol.doc.description}}
{{/if}}
7 changes: 0 additions & 7 deletions addons/generator/asciidoc/partials/symbol.adoc.hbs

This file was deleted.

1 change: 1 addition & 0 deletions addons/generator/asciidoc/partials/typedef.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{!-- typedef --}}
1 change: 1 addition & 0 deletions addons/generator/asciidoc/partials/undefined.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{!-- undefined --}}
1 change: 1 addition & 0 deletions addons/generator/asciidoc/partials/variable.adoc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{!-- variable --}}
2 changes: 1 addition & 1 deletion include/mrdox/Dom/DomArray.hpp
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ template<class T, class U>
class MRDOX_DECL
DomArray : public dom::Array
{
std::vector<T> list_;
std::vector<T> const& list_;
Corpus const& corpus_;

public:
9 changes: 9 additions & 0 deletions source/-adoc/Builder.cpp
Original file line number Diff line number Diff line change
@@ -233,6 +233,15 @@ operator()(FunctionInfo const& I)
createContext(I.id));
}

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

} // adoc
} // mrdox
} // clang
2 changes: 1 addition & 1 deletion source/-adoc/Builder.hpp
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ class Builder
Expected<std::string> operator()(NamespaceInfo const&);
Expected<std::string> operator()(RecordInfo const&);
Expected<std::string> operator()(FunctionInfo const&);

Expected<std::string> operator()(EnumInfo const&);
};

} // adoc
7 changes: 7 additions & 0 deletions source/-adoc/SinglePageVisitor.cpp
Original file line number Diff line number Diff line change
@@ -57,6 +57,13 @@ operator()(FunctionInfo const& I)
renderPage(I, numPages_++);
}

void
SinglePageVisitor::
operator()(EnumInfo const& I)
{
renderPage(I, numPages_++);
}

// pageNumber is zero-based
void
SinglePageVisitor::
1 change: 1 addition & 0 deletions source/-adoc/SinglePageVisitor.hpp
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ class SinglePageVisitor
void operator()(NamespaceInfo const& I);
void operator()(RecordInfo const& I);
void operator()(FunctionInfo const& I);
void operator()(EnumInfo const& I);
void operator()(Info const&) {}

void renderPage(auto const& I, std::size_t pageNumber);
70 changes: 70 additions & 0 deletions source/Dom/DomSymbol.cpp
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
//

#include "Support/Radix.hpp"
#include <mrdox/Dom/DomArray.hpp>
#include <mrdox/Dom/DomBase.hpp>
#include <mrdox/Dom/DomBaseArray.hpp>
#include <mrdox/Dom/DomFnSpecs.hpp>
@@ -28,6 +29,56 @@
namespace clang {
namespace mrdox {

//------------------------------------------------

class DomEnumValue : public dom::Object
{
EnumValueInfo const& I_;
Corpus const& corpus_;

public:
DomEnumValue(
EnumValueInfo const& I,
Corpus const& corpus) noexcept
: I_(I)
, corpus_(corpus)
{
}

dom::Value
get(std::string_view key) const override
{
if(key == "name")
return I_.Name;
if(key == "value")
return I_.Value;
if(key == "expr")
return I_.ValueExpr;
if(key == "doc")
{
if(I_.javadoc)
return dom::create<DomJavadoc>(
*I_.javadoc, corpus_);
return nullptr;
}
return nullptr;
}

std::vector<std::string_view>
props() const override
{
return {
"name",
"value",
"expr",
"doc",
};
}
};


//------------------------------------------------

template<class T>
DomSymbol<T>::
DomSymbol(
@@ -136,6 +187,19 @@ get(std::string_view key) const
}
if constexpr(T::isEnum())
{
if(key == "type")
{
if(I_.BaseType)
return dom::create<DomType>(
*I_.BaseType, corpus_);
return nullptr;
}
if(key == "members")
return dom::create<DomArray<
EnumValueInfo, DomEnumValue>>(
I_.Members, corpus_);
if(key == "isScoped")
return I_.Scoped;
}
if constexpr(T::isTypedef())
{
@@ -207,6 +271,12 @@ props() const ->
"specs",
"template"
});
if constexpr(T::isEnum())
v.insert(v.end(), {
"type",
"members",
"isScoped"
});
if constexpr(T::isVariable())
v.insert(v.end(), {
"template"
1 change: 0 additions & 1 deletion source/Metadata/Info.cpp
Original file line number Diff line number Diff line change
@@ -104,7 +104,6 @@ toString(InfoKind kind) noexcept
case InfoKind::Variable:
return "variable";
default:
// unknown InfoKind
MRDOX_UNREACHABLE();
}
}
1 change: 0 additions & 1 deletion source/Metadata/Record.cpp
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ toString(RecordKeyKind kind) noexcept
case RecordKeyKind::Union:
return "union";
default:
// unknown RecordKeyKind
MRDOX_UNREACHABLE();
}
}
28 changes: 12 additions & 16 deletions test-files/adoc/test.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
template<class X, class Y, typename Z>
class V {};

struct A {};
struct B {};
struct C {};

struct S0 : A, B {};
struct S1 : S0, C {};

template<class T>
struct U {};

struct Z : U<S0> {};

struct Q : protected A, virtual B{};
struct T {};

enum E
{
/** hmm
*/
a,

b=2,
c,
d
};

0 comments on commit 246cd12

Please sign in to comment.