Skip to content

Commit 84b3b28

Browse files
committed
refactor: describe AccessKind, ConstexprKind, ParamDirection, StorageClassKind
Replace manual toString and tag_invoke overloads with MRDOCS_DESCRIBE_ENUM for four enums whose kebab-case names match the existing string representations. The XML writer now emits these fields (e.g. <access>public</access>, <constexpr>constexpr</constexpr>) where they were previously silently skipped. None/none sentinel values are suppressed via a generic has_none_enumerator check. TypeKind stays manual because toKebabCase("LValueReference") produces "l-value-reference", not the established "lvalue-reference".
1 parent f9c8611 commit 84b3b28

179 files changed

Lines changed: 1720 additions & 313 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/mrdocs/Metadata/DocComment/Block/ParamDirection.hpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <mrdocs/Platform.hpp>
1818
#include <mrdocs/Dom.hpp>
19+
#include <mrdocs/Support/Describe.hpp>
1920

2021
namespace mrdocs::doc {
2122

@@ -33,23 +34,7 @@ enum class ParamDirection
3334
inout
3435
};
3536

36-
/** Return the name of the ParamDirection as a string.
37-
*/
38-
MRDOCS_DECL
39-
dom::String
40-
toString(ParamDirection kind) noexcept;
41-
42-
/** Return the ParamDirection from a @ref dom::Value string.
43-
*/
44-
inline
45-
void
46-
tag_invoke(
47-
dom::ValueFromTag,
48-
dom::Value& v,
49-
ParamDirection const kind)
50-
{
51-
v = toString(kind);
52-
}
37+
MRDOCS_DESCRIBE_ENUM(ParamDirection, none, in, out, inout)
5338

5439
} // mrdocs::doc
5540

include/mrdocs/Metadata/Specifiers/AccessKind.hpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <mrdocs/Platform.hpp>
1616
#include <mrdocs/Dom.hpp>
17-
#include <string>
17+
#include <mrdocs/Support/Describe.hpp>
1818

1919
namespace mrdocs {
2020

@@ -41,25 +41,7 @@ enum class AccessKind
4141
Private,
4242
};
4343

44-
/** Convert access specifier to its string form.
45-
*/
46-
MRDOCS_DECL
47-
dom::String
48-
toString(AccessKind kind) noexcept;
49-
50-
/** Return the AccessKind as a @ref dom::Value string.
51-
*/
52-
inline
53-
void
54-
tag_invoke(
55-
dom::ValueFromTag,
56-
dom::Value& v,
57-
AccessKind const kind)
58-
{
59-
v = toString(kind);
60-
}
61-
62-
44+
MRDOCS_DESCRIBE_ENUM(AccessKind, None, Public, Protected, Private)
6345

6446
} // mrdocs
6547

include/mrdocs/Metadata/Specifiers/ConstexprKind.hpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define MRDOCS_API_METADATA_SPECIFIERS_CONSTEXPRKIND_HPP
1414

1515
#include <mrdocs/Platform.hpp>
16-
#include <string>
16+
#include <mrdocs/Support/Describe.hpp>
1717

1818
namespace mrdocs {
1919

@@ -33,23 +33,7 @@ enum class ConstexprKind
3333
Consteval,
3434
};
3535

36-
/** Convert a constexpr/consteval specifier kind to a string.
37-
*/
38-
MRDOCS_DECL
39-
dom::String
40-
toString(ConstexprKind kind) noexcept;
41-
42-
/** Return the ConstexprKind as a @ref dom::Value string.
43-
*/
44-
inline
45-
void
46-
tag_invoke(
47-
dom::ValueFromTag,
48-
dom::Value& v,
49-
ConstexprKind const kind)
50-
{
51-
v = toString(kind);
52-
}
36+
MRDOCS_DESCRIBE_ENUM(ConstexprKind, None, Constexpr, Consteval)
5337

5438
} // mrdocs
5539

include/mrdocs/Metadata/Specifiers/StorageClassKind.hpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <mrdocs/Platform.hpp>
1616
#include <mrdocs/Dom.hpp>
17-
#include <string>
17+
#include <mrdocs/Support/Describe.hpp>
1818

1919
namespace mrdocs {
2020

@@ -40,23 +40,7 @@ enum class StorageClassKind
4040
Register
4141
};
4242

43-
/** Convert a storage class kind to its string form.
44-
*/
45-
MRDOCS_DECL
46-
dom::String
47-
toString(StorageClassKind kind) noexcept;
48-
49-
/** Return the StorageClassKind as a @ref dom::Value string.
50-
*/
51-
inline
52-
void
53-
tag_invoke(
54-
dom::ValueFromTag,
55-
dom::Value& v,
56-
StorageClassKind const kind)
57-
{
58-
v = toString(kind);
59-
}
43+
MRDOCS_DESCRIBE_ENUM(StorageClassKind, None, Extern, Static, Auto, Register)
6044

6145
} // mrdocs
6246

include/mrdocs/Metadata/Type/TypeKind.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ MRDOCS_DECL
2929
dom::String
3030
toString(TypeKind kind) noexcept;
3131

32-
inline
3332
/** Map a TypeKind into a DOM value.
3433
*/
34+
inline
3535
void
3636
tag_invoke(
3737
dom::ValueFromTag,

include/mrdocs/Support/MapReflectedType.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <mrdocs/Dom/LazyArray.hpp>
1616
#include <mrdocs/Dom/LazyObject.hpp>
1717
#include <mrdocs/Metadata/Expression.hpp>
18+
#include <mrdocs/Metadata/DocComment/Block/ParamDirection.hpp>
19+
#include <mrdocs/Metadata/Specifiers/AccessKind.hpp>
1820
#include <mrdocs/Metadata/Specifiers/ConstexprKind.hpp>
1921
#include <mrdocs/Metadata/Specifiers/ReferenceKind.hpp>
2022
#include <mrdocs/Metadata/Specifiers/StorageClassKind.hpp>
@@ -114,6 +116,10 @@ shouldMapValue(T const& value)
114116
{
115117
return !value.empty();
116118
}
119+
else if constexpr (std::is_same_v<T, AccessKind>)
120+
{
121+
return value != AccessKind::None;
122+
}
117123
else if constexpr (std::is_same_v<T, ConstexprKind>)
118124
{
119125
return value != ConstexprKind::None;
@@ -126,6 +132,10 @@ shouldMapValue(T const& value)
126132
{
127133
return value != StorageClassKind::None;
128134
}
135+
else if constexpr (std::is_same_v<T, doc::ParamDirection>)
136+
{
137+
return value != doc::ParamDirection::none;
138+
}
129139
else if constexpr (std::is_same_v<T, ExprInfo>)
130140
{
131141
return !value.Written.empty();

src/lib/Gen/xml/XMLWriter.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ std::string tagName()
5555
return toKebabCase(name);
5656
}
5757

58+
/** True if the described enum has an enumerator named "None" or "none". */
59+
template <typename E>
60+
constexpr bool has_none_enumerator()
61+
{
62+
bool result = false;
63+
describe::for_each(
64+
describe::describe_enumerators<E>{},
65+
[&](auto const& D)
66+
{
67+
std::string_view name(D.name);
68+
if (name == "None" || name == "none")
69+
{
70+
result = true;
71+
}
72+
});
73+
return result;
74+
}
75+
5876
} // unnamed namespace
5977

6078
//------------------------------------------------
@@ -175,6 +193,16 @@ XMLWriter::writeElement(std::string_view tag, T const& value)
175193
{ if (value.empty()) return; }
176194
else if constexpr (std::is_base_of_v<ExprInfo, Type>)
177195
{ if (value.Written.empty()) return; }
196+
else if constexpr (describe::has_describe_enumerators<Type>::value)
197+
{
198+
if constexpr (has_none_enumerator<Type>())
199+
{
200+
if (toString(value) == "none")
201+
{
202+
return;
203+
}
204+
}
205+
}
178206

179207
// Primitives inline, compounds wrapped.
180208
if constexpr (std::is_base_of_v<ExprInfo, Type>)

src/lib/Metadata/DocComment.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ toString(AdmonitionKind kind) noexcept
4646
}
4747
}
4848

49-
dom::String
50-
toString(ParamDirection kind) noexcept
51-
{
52-
switch(kind)
53-
{
54-
case ParamDirection::none:
55-
return "";
56-
case ParamDirection::in:
57-
return "in";
58-
case ParamDirection::out:
59-
return "out";
60-
case ParamDirection::inout:
61-
return "inout";
62-
default:
63-
MRDOCS_UNREACHABLE();
64-
}
65-
}
66-
6749
dom::String
6850
toString(Parts kind) noexcept
6951
{

src/lib/Metadata/Specifiers.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,6 @@
1515

1616
namespace mrdocs {
1717

18-
dom::String toString(AccessKind kind) noexcept
19-
{
20-
switch(kind)
21-
{
22-
case AccessKind::Public: return "public";
23-
case AccessKind::Private: return "private";
24-
case AccessKind::Protected: return "protected";
25-
case AccessKind::None: return "";
26-
default:
27-
MRDOCS_UNREACHABLE();
28-
}
29-
}
30-
31-
dom::String toString(StorageClassKind kind) noexcept
32-
{
33-
switch(kind)
34-
{
35-
case StorageClassKind::None: return "";
36-
case StorageClassKind::Extern: return "extern";
37-
case StorageClassKind::Static: return "static";
38-
case StorageClassKind::Auto: return "auto";
39-
case StorageClassKind::Register: return "register";
40-
default:
41-
MRDOCS_UNREACHABLE();
42-
}
43-
}
44-
45-
dom::String toString(ConstexprKind kind) noexcept
46-
{
47-
switch(kind)
48-
{
49-
case ConstexprKind::None: return "";
50-
case ConstexprKind::Constexpr: return "constexpr";
51-
case ConstexprKind::Consteval: return "consteval";
52-
default:
53-
MRDOCS_UNREACHABLE();
54-
}
55-
}
56-
5718
dom::String toString(ExplicitKind kind) noexcept
5819
{
5920
switch(kind)

src/lib/Support/Debug.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct std::formatter<mrdocs::AccessKind> : std::formatter<std::string> {
4747
template <class FmtContext>
4848
std::format_context::iterator format(mrdocs::AccessKind a,
4949
FmtContext &ctx) const {
50-
return std::formatter<std::string>::format(toString(a).str(), ctx);
50+
return std::formatter<std::string>::format(toString(a), ctx);
5151
}
5252
};
5353

0 commit comments

Comments
 (0)