Skip to content

Commit 2f73713

Browse files
committed
javadoc ref parser supports function parameters
#feat
1 parent ff33c4b commit 2f73713

File tree

16 files changed

+2347
-285
lines changed

16 files changed

+2347
-285
lines changed

include/mrdocs/ADT/Optional.hpp

+15-16
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,34 @@ class Optional
6464
constexpr Optional() = default;
6565
constexpr Optional(Optional const& other) = default;
6666

67-
constexpr Optional& operator=(Optional const& other) = default;
68-
constexpr Optional& operator=(Optional&& other) = default;
69-
constexpr Optional& operator=(T const& t)
67+
template<class U>
68+
requires std::is_constructible_v<T, U>
69+
constexpr explicit
70+
Optional(U&& u)
71+
: t_(std::forward<U>(u))
7072
{
71-
t_ = t;
72-
return *this;
7373
}
7474

75-
constexpr Optional& operator=(T&& t)
75+
constexpr Optional& operator=(Optional const& other) = default;
76+
constexpr Optional& operator=(Optional&& other) = default;
77+
78+
template <class U>
79+
requires std::is_constructible_v<T, U>
80+
constexpr
81+
Optional& operator=(U&& u)
7682
{
77-
t_ = std::move(t);
83+
t_ = std::forward<U>(u);
7884
return *this;
7985
}
8086

81-
constexpr Optional& operator=(std::nullptr_t)
87+
constexpr
88+
Optional& operator=(std::nullptr_t)
8289
{
8390
t_ = T();
8491
MRDOCS_ASSERT(!this->operator bool());
8592
return *this;
8693
}
8794

88-
template<class U>
89-
requires std::is_constructible_v<T, U>
90-
constexpr explicit
91-
Optional(U&& u)
92-
: t_(std::forward<U>(u))
93-
{
94-
}
95-
9695
constexpr void reset()
9796
{
9897
*this = Optional();

include/mrdocs/ADT/Polymorphic.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ class Polymorphic
599599
600600
@pre bool(*this) is true.
601601
*/
602+
constexpr
602603
Base const&
603604
operator*() const noexcept(noexcept(*std::declval<Base*>()))
604605
{
@@ -612,6 +613,7 @@ class Polymorphic
612613
613614
@pre bool(*this) is true.
614615
*/
616+
constexpr
615617
Base&
616618
operator*() noexcept(noexcept(*std::declval<Base*>()))
617619
{
@@ -625,6 +627,7 @@ class Polymorphic
625627
626628
@pre bool(*this) is true.
627629
*/
630+
constexpr
628631
Base const*
629632
operator->() const noexcept
630633
{
@@ -637,6 +640,7 @@ class Polymorphic
637640
638641
@pre bool(*this) is true.
639642
*/
643+
constexpr
640644
Base*
641645
operator->() noexcept
642646
{
@@ -647,6 +651,7 @@ class Polymorphic
647651
648652
@return true if the Polymorphic owns an object, otherwise false.
649653
*/
654+
constexpr
650655
explicit
651656
operator
652657
bool() const noexcept

include/mrdocs/Metadata/Info/Function.hpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,19 @@ tag_invoke(
9898
// KRYSTIAN TODO: attributes (nodiscard, deprecated, and carries_dependency)
9999
// KRYSTIAN TODO: flag to indicate whether this is a function parameter pack
100100
/** Represents a single function parameter */
101-
struct Param
101+
struct Param final
102102
{
103-
/** The type of this parameter */
103+
/** The type of this parameter
104+
*/
104105
Polymorphic<TypeInfo> Type;
105106

106107
/** The parameter name.
108+
*/
109+
Optional<std::string> Name;
107110

108-
Unnamed parameters are represented by empty strings.
109-
*/
110-
std::string Name;
111-
112-
/** The default argument for this parameter, if any */
113-
std::string Default;
111+
/** The default argument for this parameter, if any
112+
*/
113+
Optional<std::string> Default;
114114

115115
Param() = default;
116116

@@ -123,7 +123,8 @@ struct Param
123123
, Default(std::move(def_arg))
124124
{}
125125

126-
auto operator<=>(Param const&) const = default;
126+
auto
127+
operator<=>(Param const&) const = default;
127128
};
128129

129130
/** Return the Param as a @ref dom::Value object.

include/mrdocs/Metadata/Type.hpp

+46-62
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ struct TypeInfo
111111
*/
112112
bool IsPackExpansion = false;
113113

114+
/** The const qualifier
115+
*/
116+
bool IsConst = false;
117+
118+
/** The volatile qualifier
119+
*/
120+
bool IsVolatile = false;
121+
114122
/** The constraints associated with the type
115123
116124
This represents the constraints associated with the type,
@@ -135,25 +143,6 @@ struct TypeInfo
135143
constexpr bool isArray() const noexcept { return Kind == TypeKind::Array; }
136144
constexpr bool isFunction() const noexcept { return Kind == TypeKind::Function; }
137145

138-
/** Return the inner type.
139-
140-
The inner type is the type which is modified
141-
by a specifier (e.g. "int" in "pointer to int".
142-
*/
143-
virtual
144-
TypeInfo*
145-
innerType() noexcept
146-
{
147-
return nullptr;
148-
}
149-
150-
virtual
151-
TypeInfo const*
152-
cInnerType() const noexcept
153-
{
154-
return const_cast<TypeInfo*>(this)->innerType();
155-
}
156-
157146
/** Return the symbol named by this type.
158147
*/
159148
SymbolID
@@ -222,7 +211,6 @@ struct TypeInfoCommonBase : TypeInfo
222211
struct NamedTypeInfo final
223212
: TypeInfoCommonBase<TypeKind::Named>
224213
{
225-
QualifierKind CVQualifiers = QualifierKind::None;
226214
Polymorphic<NameInfo> Name;
227215

228216
std::strong_ordering
@@ -232,7 +220,6 @@ struct NamedTypeInfo final
232220
struct DecltypeTypeInfo final
233221
: TypeInfoCommonBase<TypeKind::Decltype>
234222
{
235-
QualifierKind CVQualifiers = QualifierKind::None;
236223
ExprInfo Operand;
237224

238225
auto operator<=>(DecltypeTypeInfo const&) const = default;
@@ -241,7 +228,6 @@ struct DecltypeTypeInfo final
241228
struct AutoTypeInfo final
242229
: TypeInfoCommonBase<TypeKind::Auto>
243230
{
244-
QualifierKind CVQualifiers = QualifierKind::None;
245231
AutoKind Keyword = AutoKind::Auto;
246232
Polymorphic<NameInfo> Constraint;
247233

@@ -254,12 +240,6 @@ struct LValueReferenceTypeInfo final
254240
{
255241
Polymorphic<TypeInfo> PointeeType;
256242

257-
TypeInfo*
258-
innerType() noexcept override
259-
{
260-
return PointeeType.operator->();
261-
}
262-
263243
std::strong_ordering
264244
operator<=>(LValueReferenceTypeInfo const&) const;
265245
};
@@ -269,46 +249,25 @@ struct RValueReferenceTypeInfo final
269249
{
270250
Polymorphic<TypeInfo> PointeeType;
271251

272-
TypeInfo*
273-
innerType() noexcept override
274-
{
275-
return PointeeType.operator->();
276-
}
277-
278252
std::strong_ordering
279253
operator<=>(RValueReferenceTypeInfo const&) const;
280254
};
281255

282256
struct PointerTypeInfo final
283257
: TypeInfoCommonBase<TypeKind::Pointer>
284258
{
285-
QualifierKind CVQualifiers = QualifierKind::None;
286259
Polymorphic<TypeInfo> PointeeType;
287260

288-
TypeInfo*
289-
innerType() noexcept override
290-
{
291-
return PointeeType.operator->();
292-
}
293-
294261
std::strong_ordering
295262
operator<=>(PointerTypeInfo const&) const;
296263
};
297264

298265
struct MemberPointerTypeInfo final
299266
: TypeInfoCommonBase<TypeKind::MemberPointer>
300267
{
301-
QualifierKind CVQualifiers = QualifierKind::None;
302268
Polymorphic<TypeInfo> ParentType;
303269
Polymorphic<TypeInfo> PointeeType;
304270

305-
TypeInfo*
306-
innerType() noexcept override
307-
{
308-
return PointeeType.operator->();
309-
}
310-
311-
312271
std::strong_ordering
313272
operator<=>(MemberPointerTypeInfo const&) const;
314273
};
@@ -319,12 +278,6 @@ struct ArrayTypeInfo final
319278
Polymorphic<TypeInfo> ElementType;
320279
ConstantExprInfo<std::uint64_t> Bounds;
321280

322-
TypeInfo*
323-
innerType() noexcept override
324-
{
325-
return ElementType.operator->();
326-
}
327-
328281
std::strong_ordering
329282
operator<=>(ArrayTypeInfo const&) const;
330283
};
@@ -334,17 +287,10 @@ struct FunctionTypeInfo final
334287
{
335288
Polymorphic<TypeInfo> ReturnType;
336289
std::vector<Polymorphic<TypeInfo>> ParamTypes;
337-
QualifierKind CVQualifiers = QualifierKind::None;
338290
ReferenceKind RefQualifier = ReferenceKind::None;
339291
NoexceptInfo ExceptionSpec;
340292
bool IsVariadic = false;
341293

342-
TypeInfo*
343-
innerType() noexcept override
344-
{
345-
return ReturnType.operator->();
346-
}
347-
348294
std::strong_ordering
349295
operator<=>(FunctionTypeInfo const&) const;
350296
};
@@ -413,6 +359,44 @@ operator==(Polymorphic<TypeInfo> const& lhs, Polymorphic<TypeInfo> const& rhs) {
413359
return lhs <=> rhs == std::strong_ordering::equal;
414360
}
415361

362+
/** Return the inner type.
363+
364+
The inner type is the type which is modified
365+
by a specifier (e.g. "int" in "pointer to int".
366+
*/
367+
MRDOCS_DECL
368+
std::optional<std::reference_wrapper<Polymorphic<TypeInfo> const>>
369+
innerType(TypeInfo const& TI) noexcept;
370+
371+
/// @copydoc innerType(TypeInfo const&)
372+
MRDOCS_DECL
373+
std::optional<std::reference_wrapper<Polymorphic<TypeInfo>>>
374+
innerType(TypeInfo& TI) noexcept;
375+
376+
/// @copydoc innerType(TypeInfo const&)
377+
MRDOCS_DECL
378+
TypeInfo const*
379+
innerTypePtr(TypeInfo const& TI) noexcept;
380+
381+
/// @copydoc innerTypePtr(TypeInfo const&)
382+
MRDOCS_DECL
383+
TypeInfo*
384+
innerTypePtr(TypeInfo& TI) noexcept;
385+
386+
/** Return the innermost type.
387+
388+
The innermost type is the type which is not
389+
modified by any specifiers (e.g. "int" in
390+
"pointer to const int").
391+
*/
392+
MRDOCS_DECL
393+
std::optional<std::reference_wrapper<Polymorphic<TypeInfo> const>>
394+
innermostType(TypeInfo const& TI) noexcept;
395+
396+
/// @copydoc innermostType(TypeInfo const&)
397+
MRDOCS_DECL
398+
std::optional<std::reference_wrapper<Polymorphic<TypeInfo>>>
399+
innermostType(TypeInfo& TI) noexcept;
416400

417401
// VFALCO maybe we should rename this to `renderType` or something?
418402
MRDOCS_DECL

0 commit comments

Comments
 (0)