Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deduction guides are represeted with GuideInfo #504

Merged
merged 2 commits into from
Dec 1, 2023
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
5 changes: 5 additions & 0 deletions include/mrdocs/Corpus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ traverseOverloads(
auto first_func = std::ranges::find_if(
lookup, [this](const SymbolID& elem)
{
#if 0
const Info& I = get(elem);
return I.isFunction() || I.isGuide();
#else
return get(elem).isFunction();
#endif
});
if(lookup.size() == 1 ||
first_func == lookup.end())
Expand Down
1 change: 1 addition & 0 deletions include/mrdocs/Metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <mrdocs/Metadata/Field.hpp>
#include <mrdocs/Metadata/Friend.hpp>
#include <mrdocs/Metadata/Function.hpp>
#include <mrdocs/Metadata/Guide.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Interface.hpp>
#include <mrdocs/Metadata/Javadoc.hpp>
Expand Down
6 changes: 3 additions & 3 deletions include/mrdocs/Metadata/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ enum class FunctionClass
Constructor,
// conversion function
Conversion,
Destructor,
// deduction guide
Deduction,
Destructor
};

MRDOCS_DECL dom::String toString(FunctionClass kind) noexcept;
Expand Down Expand Up @@ -157,6 +155,8 @@ struct FunctionInfo
FnFlags0 specs0{.raw{0}};
FnFlags1 specs1{.raw{0}};

NoexceptInfo Noexcept;

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

explicit FunctionInfo(SymbolID ID) noexcept
Expand Down
62 changes: 62 additions & 0 deletions include/mrdocs/Metadata/Guide.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#ifndef MRDOCS_API_METADATA_GUIDE_HPP
#define MRDOCS_API_METADATA_GUIDE_HPP

#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Function.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Source.hpp>
#include <mrdocs/Metadata/Template.hpp>
#include <mrdocs/Metadata/Type.hpp>
#include <memory>
#include <utility>
#include <vector>

namespace clang {
namespace mrdocs {

/** Info for deduction guides.
*/
struct GuideInfo
: IsInfo<InfoKind::Guide>
, SourceInfo
{
/** The pattern for the deduced specialization.

This is always a SpecializationTypeInfo.
*/
std::unique_ptr<TypeInfo> Deduced;

/** Template head, if any.
*/
std::unique_ptr<TemplateInfo> Template;

/** The parameters of the deduction guide.
*/
std::vector<Param> Params;

/** The explicit-specifier, if any.
*/
ExplicitKind Explicit = ExplicitKind::None;

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

explicit GuideInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
};

} // mrdocs
} // clang

#endif
8 changes: 7 additions & 1 deletion include/mrdocs/Metadata/Info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct VariableInfo;
struct SpecializationInfo;
struct FriendInfo;
struct EnumeratorInfo;
struct GuideInfo;

/** Info variant discriminator
*/
Expand All @@ -51,7 +52,8 @@ enum class InfoKind
Field,
Specialization,
Friend,
Enumerator
Enumerator,
Guide
};

MRDOCS_DECL dom::String toString(InfoKind kind) noexcept;
Expand Down Expand Up @@ -130,6 +132,7 @@ struct MRDOCS_VISIBLE
constexpr bool isSpecialization() const noexcept { return Kind == InfoKind::Specialization; }
constexpr bool isFriend() const noexcept { return Kind == InfoKind::Friend; }
constexpr bool isEnumerator() const noexcept { return Kind == InfoKind::Enumerator; }
constexpr bool isGuide() const noexcept { return Kind == InfoKind::Guide; }
};

//------------------------------------------------
Expand Down Expand Up @@ -157,6 +160,7 @@ struct IsInfo : Info
static constexpr bool isSpecialization() noexcept { return K == InfoKind::Specialization; }
static constexpr bool isFriend() noexcept { return K == InfoKind::Friend; }
static constexpr bool isEnumerator() noexcept { return K == InfoKind::Enumerator; }
static constexpr bool isGuide() noexcept { return K == InfoKind::Guide; }

protected:
constexpr explicit IsInfo(SymbolID ID)
Expand Down Expand Up @@ -203,6 +207,8 @@ visit(
return visitor.template visit<FriendInfo>();
case InfoKind::Enumerator:
return visitor.template visit<EnumeratorInfo>();
case InfoKind::Guide:
return visitor.template visit<GuideInfo>();
default:
MRDOCS_UNREACHABLE();
}
Expand Down
1 change: 1 addition & 0 deletions include/mrdocs/Metadata/Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct Tranche
std::vector<SymbolID> StaticFunctions;
std::vector<SymbolID> Variables;
std::vector<SymbolID> Friends;
std::vector<SymbolID> Guides;

ScopeInfo Overloads;
ScopeInfo StaticOverloads;
Expand Down
65 changes: 41 additions & 24 deletions include/mrdocs/Metadata/Specifiers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <mrdocs/Platform.hpp>
#include <mrdocs/Dom.hpp>
#include <string>
#include <string_view>

namespace clang {
Expand Down Expand Up @@ -70,30 +71,31 @@ enum class ExplicitKind
*/
enum class NoexceptKind
{
None = 0,
// throw()
ThrowNone,
// throw(type-id-list)
Throw,
// throw(...) (microsoft extension)
ThrowAny,
// __declspec(nothrow) (microsoft extension)
NoThrow,
// noexcept-specifier, no constant-expression
Noexcept,
// noexcept-specifier, constant-expression evaluates to false
NoexceptFalse,
// noexcept-specifier, constant-expression evaluates to true
NoexceptTrue,
// noexcept-specifier, dependent constant-expression
NoexceptDependent,

// not evaluated yet, for special member function
Unevaluated,
// not instantiated yet
Uninstantiated,
// not parsed yet
Unparsed
/** Potentially-throwing exception specification
*/
False = 0,
/** Non-throwing exception specification
*/
True,
/** Dependent exception specification
*/
Dependent
};

// KRYSTIAN FIXME: this needs to be improved (a lot)
struct NoexceptInfo
{
/** Whether a noexcept-specifier was user-written.
*/
bool Implicit = true;

/** The evaluated exception specification.
*/
NoexceptKind Kind = NoexceptKind::False;

/** The operand of the noexcept-specifier, if any.
*/
std::string Operand;
};

/** Operator kinds
Expand Down Expand Up @@ -183,6 +185,21 @@ MRDOCS_DECL dom::String toString(NoexceptKind kind) noexcept;
MRDOCS_DECL dom::String toString(ReferenceKind kind) noexcept;
MRDOCS_DECL dom::String toString(StorageClassKind kind) noexcept;

/** Convert NoexceptInfo to a string.

@param resolved If true, the operand is not shown when
the exception specification is non-dependent.

@param implicit If true, implicit exception specifications
are shown.
*/
MRDOCS_DECL
dom::String
toString(
NoexceptInfo info,
bool resolved = false,
bool implicit = false);

} // mrdocs
} // clang

Expand Down
2 changes: 1 addition & 1 deletion include/mrdocs/Metadata/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ struct FunctionTypeInfo
std::vector<std::unique_ptr<TypeInfo>> ParamTypes;
QualifierKind CVQualifiers = QualifierKind::None;
ReferenceKind RefQualifier = ReferenceKind::None;
NoexceptKind ExceptionSpec = NoexceptKind::None;
NoexceptInfo ExceptionSpec;

TypeInfo* innerType() const noexcept override
{
Expand Down
1 change: 1 addition & 0 deletions include/mrdocs/MetadataFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct EnumeratorInfo;
struct FieldInfo;
struct FriendInfo;
struct FunctionInfo;
struct GuideInfo;
struct Info;
class Javadoc;
struct Location;
Expand Down
29 changes: 28 additions & 1 deletion mrdocs.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ grammar
Name,
Access?,
ID,
attribute class { "constructor"|"destructor"|"conversion"|"deduction" } ?,
attribute class { "constructor"|"destructor"|"conversion" } ?,
attribute exception-spec { text } ?,
Location *,
(
Attr * |
Expand All @@ -92,6 +93,29 @@ grammar

#---------------------------------------------

Guide =
element guide
{
Name,
Access?,
attribute explicit { "1" } ?,
ID,
Location *,
(
element deduced { TypeInfo } |
element param
{
Name?,
attribute default { text } ?,
ID ?,
TypeInfo
} * |
Javadoc ?
) *
}

#---------------------------------------------

Enum =
element enum
{
Expand Down Expand Up @@ -213,6 +237,7 @@ grammar
Function |
Typedef |
Var |
Guide |
Template
)
}
Expand Down Expand Up @@ -274,6 +299,7 @@ grammar
Typedef |
Enum |
Var |
Guide |
Template |
Specialization
)*
Expand All @@ -286,6 +312,7 @@ grammar
Enum |
Field |
Var |
Guide |
Template |
Friend |
Specialization
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{#if (and (eq kind "function") (eq class "conversion"))~}}
operator {{>declarator return nolink=nolink~}}
{{else if (eq kind "guide")~}}
{{>declarator deduced nolink=nolink~}}
{{else~}}
{{#if (and link.ref (not nolink))}}xref:{{link.ref}}[{{name}}]{{else}}{{name}}{{/if~}}
{{#if (or (eq template.kind "explicit") (eq template.kind "partial"))~}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#unless (contains @root.symbol.namespace symbol)~}}
{{#unless (or (contains @root.symbol.namespace symbol) (eq @root.symbol symbol))~}}
{{#if symbol.parent~}}
{{>qualified-path symbol=symbol.parent nolink=nolink~}}
{{else~}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{~#if symbol.isConst}} const{{/if~}}
{{#if symbol.isVolatile}} volatile{{/if~}}
{{#if symbol.refQualifier}} {{symbol.refQualifier}}{{/if~}}
{{#if (eq symbol.exceptionSpec "noexcept")}} noexcept{{/if~}}
{{#if symbol.exceptionSpec}} {{symbol.exceptionSpec}}{{/if~}}
{{#if (eq symbol.class "normal")}}{{>declarator-after symbol.return}}{{/if~}}
{{#if symbol.hasOverrideAttr}} override{{/if~}}
{{#if symbol.isFinal}} final{{/if~}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{#if symbol.template}}{{>template-head symbol.template}}
{{/if~}}
{{>declarator-id symbol}}
({{#each symbol.params}}{{#unless (and @first @last)}}
{{/unless}}{{>declarator type decl-name=name~}}
{{#if default}} = {{default}}{{/if~}}
{{#unless @last}},{{/unless~}}
{{/each~}}) -> {{>declarator symbol.deduced}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{!-- guides --}}
= Deduction guide {{>nested-name-specifier symbol=symbol.parent}}{{symbol.name}}

{{symbol.doc.brief}}

== Synopsis

{{>source dcl=(primary_location symbol)}}

[source,cpp,subs="verbatim,macros,-callouts"]
----
{{>signature/guide symbol=symbol}};
----

{{#if symbol.doc.description}}
== Description

{{symbol.doc.description}}

{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
{{>info-list members=tranche.variables title=(concat label " " "Static Data Members")}}
{{>info-list members=tranche.friends title=(concat label " " "Friends")}}
{{/if}}
{{>info-list members=tranche.guides title=(concat label " " "Deduction Guides")}}
Loading