Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions include/mrdocs/ADT/Optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,34 @@ class Optional
constexpr Optional() = default;
constexpr Optional(Optional const& other) = default;

constexpr Optional& operator=(Optional const& other) = default;
constexpr Optional& operator=(Optional&& other) = default;
constexpr Optional& operator=(T const& t)
template<class U>
requires std::is_constructible_v<T, U>
constexpr explicit
Optional(U&& u)
: t_(std::forward<U>(u))
{
t_ = t;
return *this;
}

constexpr Optional& operator=(T&& t)
constexpr Optional& operator=(Optional const& other) = default;
constexpr Optional& operator=(Optional&& other) = default;

template <class U>
requires std::is_constructible_v<T, U>
constexpr
Optional& operator=(U&& u)
{
t_ = std::move(t);
t_ = std::forward<U>(u);
return *this;
}

constexpr Optional& operator=(std::nullptr_t)
constexpr
Optional& operator=(std::nullptr_t)
{
t_ = T();
MRDOCS_ASSERT(!this->operator bool());
return *this;
}

template<class U>
requires std::is_constructible_v<T, U>
constexpr explicit
Optional(U&& u)
: t_(std::forward<U>(u))
{
}

constexpr void reset()
{
*this = Optional();
Expand Down
5 changes: 5 additions & 0 deletions include/mrdocs/ADT/Polymorphic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ class Polymorphic

@pre bool(*this) is true.
*/
constexpr
Base const&
operator*() const noexcept(noexcept(*std::declval<Base*>()))
{
Expand All @@ -612,6 +613,7 @@ class Polymorphic

@pre bool(*this) is true.
*/
constexpr
Base&
operator*() noexcept(noexcept(*std::declval<Base*>()))
{
Expand All @@ -625,6 +627,7 @@ class Polymorphic

@pre bool(*this) is true.
*/
constexpr
Base const*
operator->() const noexcept
{
Expand All @@ -637,6 +640,7 @@ class Polymorphic

@pre bool(*this) is true.
*/
constexpr
Base*
operator->() noexcept
{
Expand All @@ -647,6 +651,7 @@ class Polymorphic

@return true if the Polymorphic owns an object, otherwise false.
*/
constexpr
explicit
operator
bool() const noexcept
Expand Down
19 changes: 10 additions & 9 deletions include/mrdocs/Metadata/Info/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ tag_invoke(
// KRYSTIAN TODO: attributes (nodiscard, deprecated, and carries_dependency)
// KRYSTIAN TODO: flag to indicate whether this is a function parameter pack
/** Represents a single function parameter */
struct Param
struct Param final
{
/** The type of this parameter */
/** The type of this parameter
*/
Polymorphic<TypeInfo> Type;

/** The parameter name.
*/
Optional<std::string> Name;

Unnamed parameters are represented by empty strings.
*/
std::string Name;

/** The default argument for this parameter, if any */
std::string Default;
/** The default argument for this parameter, if any
*/
Optional<std::string> Default;

Param() = default;

Expand All @@ -123,7 +123,8 @@ struct Param
, Default(std::move(def_arg))
{}

auto operator<=>(Param const&) const = default;
auto
operator<=>(Param const&) const = default;
};

/** Return the Param as a @ref dom::Value object.
Expand Down
108 changes: 46 additions & 62 deletions include/mrdocs/Metadata/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ struct TypeInfo
*/
bool IsPackExpansion = false;

/** The const qualifier
*/
bool IsConst = false;

/** The volatile qualifier
*/
bool IsVolatile = false;

/** The constraints associated with the type

This represents the constraints associated with the type,
Expand All @@ -135,25 +143,6 @@ struct TypeInfo
constexpr bool isArray() const noexcept { return Kind == TypeKind::Array; }
constexpr bool isFunction() const noexcept { return Kind == TypeKind::Function; }

/** Return the inner type.

The inner type is the type which is modified
by a specifier (e.g. "int" in "pointer to int".
*/
virtual
TypeInfo*
innerType() noexcept
{
return nullptr;
}

virtual
TypeInfo const*
cInnerType() const noexcept
{
return const_cast<TypeInfo*>(this)->innerType();
}

/** Return the symbol named by this type.
*/
SymbolID
Expand Down Expand Up @@ -222,7 +211,6 @@ struct TypeInfoCommonBase : TypeInfo
struct NamedTypeInfo final
: TypeInfoCommonBase<TypeKind::Named>
{
QualifierKind CVQualifiers = QualifierKind::None;
Polymorphic<NameInfo> Name;

std::strong_ordering
Expand All @@ -232,7 +220,6 @@ struct NamedTypeInfo final
struct DecltypeTypeInfo final
: TypeInfoCommonBase<TypeKind::Decltype>
{
QualifierKind CVQualifiers = QualifierKind::None;
ExprInfo Operand;

auto operator<=>(DecltypeTypeInfo const&) const = default;
Expand All @@ -241,7 +228,6 @@ struct DecltypeTypeInfo final
struct AutoTypeInfo final
: TypeInfoCommonBase<TypeKind::Auto>
{
QualifierKind CVQualifiers = QualifierKind::None;
AutoKind Keyword = AutoKind::Auto;
Polymorphic<NameInfo> Constraint;

Expand All @@ -254,12 +240,6 @@ struct LValueReferenceTypeInfo final
{
Polymorphic<TypeInfo> PointeeType;

TypeInfo*
innerType() noexcept override
{
return PointeeType.operator->();
}

std::strong_ordering
operator<=>(LValueReferenceTypeInfo const&) const;
};
Expand All @@ -269,46 +249,25 @@ struct RValueReferenceTypeInfo final
{
Polymorphic<TypeInfo> PointeeType;

TypeInfo*
innerType() noexcept override
{
return PointeeType.operator->();
}

std::strong_ordering
operator<=>(RValueReferenceTypeInfo const&) const;
};

struct PointerTypeInfo final
: TypeInfoCommonBase<TypeKind::Pointer>
{
QualifierKind CVQualifiers = QualifierKind::None;
Polymorphic<TypeInfo> PointeeType;

TypeInfo*
innerType() noexcept override
{
return PointeeType.operator->();
}

std::strong_ordering
operator<=>(PointerTypeInfo const&) const;
};

struct MemberPointerTypeInfo final
: TypeInfoCommonBase<TypeKind::MemberPointer>
{
QualifierKind CVQualifiers = QualifierKind::None;
Polymorphic<TypeInfo> ParentType;
Polymorphic<TypeInfo> PointeeType;

TypeInfo*
innerType() noexcept override
{
return PointeeType.operator->();
}


std::strong_ordering
operator<=>(MemberPointerTypeInfo const&) const;
};
Expand All @@ -319,12 +278,6 @@ struct ArrayTypeInfo final
Polymorphic<TypeInfo> ElementType;
ConstantExprInfo<std::uint64_t> Bounds;

TypeInfo*
innerType() noexcept override
{
return ElementType.operator->();
}

std::strong_ordering
operator<=>(ArrayTypeInfo const&) const;
};
Expand All @@ -334,17 +287,10 @@ struct FunctionTypeInfo final
{
Polymorphic<TypeInfo> ReturnType;
std::vector<Polymorphic<TypeInfo>> ParamTypes;
QualifierKind CVQualifiers = QualifierKind::None;
ReferenceKind RefQualifier = ReferenceKind::None;
NoexceptInfo ExceptionSpec;
bool IsVariadic = false;

TypeInfo*
innerType() noexcept override
{
return ReturnType.operator->();
}

std::strong_ordering
operator<=>(FunctionTypeInfo const&) const;
};
Expand Down Expand Up @@ -413,6 +359,44 @@ operator==(Polymorphic<TypeInfo> const& lhs, Polymorphic<TypeInfo> const& rhs) {
return lhs <=> rhs == std::strong_ordering::equal;
}

/** Return the inner type.

The inner type is the type which is modified
by a specifier (e.g. "int" in "pointer to int".
*/
MRDOCS_DECL
std::optional<std::reference_wrapper<Polymorphic<TypeInfo> const>>
innerType(TypeInfo const& TI) noexcept;

/// @copydoc innerType(TypeInfo const&)
MRDOCS_DECL
std::optional<std::reference_wrapper<Polymorphic<TypeInfo>>>
innerType(TypeInfo& TI) noexcept;

/// @copydoc innerType(TypeInfo const&)
MRDOCS_DECL
TypeInfo const*
innerTypePtr(TypeInfo const& TI) noexcept;

/// @copydoc innerTypePtr(TypeInfo const&)
MRDOCS_DECL
TypeInfo*
innerTypePtr(TypeInfo& TI) noexcept;

/** Return the innermost type.

The innermost type is the type which is not
modified by any specifiers (e.g. "int" in
"pointer to const int").
*/
MRDOCS_DECL
std::optional<std::reference_wrapper<Polymorphic<TypeInfo> const>>
innermostType(TypeInfo const& TI) noexcept;

/// @copydoc innermostType(TypeInfo const&)
MRDOCS_DECL
std::optional<std::reference_wrapper<Polymorphic<TypeInfo>>>
innermostType(TypeInfo& TI) noexcept;

// VFALCO maybe we should rename this to `renderType` or something?
MRDOCS_DECL
Expand Down
Loading