Skip to content

Commit f0adca7

Browse files
committed
Info ExtractionMode
#feat
1 parent ed78539 commit f0adca7

File tree

7 files changed

+151
-22
lines changed

7 files changed

+151
-22
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//
2+
// This is a derivative work. originally part of the LLVM Project.
3+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
// Copyright (c) 2023 Vinnie Falco ([email protected])
8+
//
9+
// Official repository: https://github.com/cppalliance/mrdocs
10+
//
11+
12+
#ifndef MRDOCS_API_METADATA_EXTRACTIONMODE_HPP
13+
#define MRDOCS_API_METADATA_EXTRACTIONMODE_HPP
14+
15+
#include <mrdocs/Platform.hpp>
16+
#include <mrdocs/Dom.hpp>
17+
#include <string_view>
18+
19+
namespace clang::mrdocs {
20+
21+
/** Determine why a symbol is extracted
22+
23+
The enum constants are ordered by specificity, with
24+
the least specific at the beginning and the most
25+
specific at the end.
26+
27+
*/
28+
enum class ExtractionMode
29+
{
30+
/// We're extracting the current symbol even though it
31+
/// doesn't pass all filters because it's a direct dependency
32+
/// of a symbol that does pass all filters and needs
33+
/// information about it (e.g.: base classes outside the filters)
34+
Dependency,
35+
36+
/// We're extracting the current symbol because it passes
37+
/// all filters
38+
Regular,
39+
40+
/// We're extracting the current symbol because it passes
41+
/// all filters, but we should also tag it as see-below
42+
/// because it passes one of the see-below filters
43+
SeeBelow,
44+
45+
/// We're extracting the current symbol because it passes
46+
/// all filters, but we should also tag it as
47+
/// implementation-defined because one of its parents
48+
/// matches the implementation-defined filter
49+
ImplementationDefined,
50+
};
51+
52+
/** Return the name of the InfoKind as a string.
53+
*/
54+
constexpr
55+
std::string_view
56+
toString(ExtractionMode kind) noexcept
57+
{
58+
switch(kind)
59+
{
60+
case ExtractionMode::Dependency:
61+
return "dependency";
62+
case ExtractionMode::Regular:
63+
return "regular";
64+
case ExtractionMode::SeeBelow:
65+
return "see-below";
66+
case ExtractionMode::ImplementationDefined:
67+
return "implementation-defined";
68+
}
69+
MRDOCS_UNREACHABLE();
70+
}
71+
72+
/** Return the InfoKind from a @ref dom::Value string.
73+
*/
74+
inline
75+
void
76+
tag_invoke(
77+
dom::ValueFromTag,
78+
dom::Value& v,
79+
ExtractionMode kind)
80+
{
81+
v = toString(kind);
82+
}
83+
84+
/** Compare ExtractionModes and returns the least specific
85+
86+
This function returns the least specific of the two
87+
ExtractionModes in terms of number of filters passed.
88+
*/
89+
constexpr
90+
ExtractionMode
91+
leastSpecific(ExtractionMode const a, ExtractionMode const b) noexcept
92+
{
93+
using IT = std::underlying_type_t<ExtractionMode>;
94+
return static_cast<ExtractionMode>(
95+
std::min(static_cast<IT>(a), static_cast<IT>(b)));
96+
}
97+
98+
/** Compare ExtractionModes and returns the most specific
99+
100+
This function returns the most specific of the two
101+
ExtractionModes in terms of number of filters passed.
102+
*/
103+
constexpr
104+
ExtractionMode
105+
mostSpecific(ExtractionMode const a, ExtractionMode const b) noexcept
106+
{
107+
using IT = std::underlying_type_t<ExtractionMode>;
108+
return static_cast<ExtractionMode>(
109+
std::max(static_cast<IT>(a), static_cast<IT>(b)));
110+
}
111+
112+
} // clang::mrdocs
113+
114+
#endif

include/mrdocs/Metadata/Info.hpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
#include <mrdocs/Metadata/Javadoc.hpp>
1818
#include <mrdocs/Metadata/Specifiers.hpp>
1919
#include <mrdocs/Metadata/Symbols.hpp>
20+
#include <mrdocs/Metadata/ExtractionMode.hpp>
2021
#include <mrdocs/Support/Visitor.hpp>
21-
#include <array>
2222
#include <memory>
2323
#include <string>
24-
#include <string_view>
25-
#include <vector>
2624

27-
namespace clang {
28-
namespace mrdocs {
25+
namespace clang::mrdocs {
2926

3027
/* Forward declarations
3128
*/
@@ -74,7 +71,7 @@ struct MRDOCS_VISIBLE
7471

7572
/** Kind of declaration.
7673
*/
77-
InfoKind Kind;
74+
InfoKind Kind = InfoKind::None;
7875

7976
/** Declaration access.
8077
@@ -87,18 +84,19 @@ struct MRDOCS_VISIBLE
8784
*/
8885
AccessKind Access = AccessKind::None;
8986

90-
/** Implicitly extracted flag.
87+
/** Determine why a symbol is extracted.
9188
92-
This flag distinguishes primary `Info` from its dependencies.
89+
This flag distinguishes `Info` from its dependencies and
90+
indicates why it was extracted.
9391
94-
A primary `Info` is one which was extracted during AST traversal
95-
because it satisfied all configured conditions to be extracted.
92+
Non-dependencies can be extracted in normal mode,
93+
see-below mode, or implementation-defined mode.
9694
97-
An `Info` dependency is one which does not meet the configured
95+
A dependency is a symbol which does not meet the configured
9896
conditions for extraction, but had to be extracted due to it
9997
being used transitively by a primary `Info`.
10098
*/
101-
bool Implicit = false;
99+
ExtractionMode Extraction = ExtractionMode::Dependency;
102100

103101
/** The parent symbol, if any.
104102
@@ -228,7 +226,14 @@ tag_invoke(
228226
Info const& I,
229227
DomCorpus const* domCorpus);
230228

231-
} // mrdocs
232-
} // clang
229+
/** Compare two Info objects
230+
*/
231+
MRDOCS_DECL
232+
bool
233+
operator<(
234+
Info const& lhs,
235+
Info const& rhs) noexcept;
236+
237+
} // clang::mrdocs
233238

234239
#endif

share/mrdocs/addons/generator/adoc/partials/symbol.adoc.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
[,cols=2]
5454
|===
5555
|Name |Description
56-
{{#each symbol.members}}
56+
{{#each (filter_by symbol.members "isRegular" "isSeeBelow")}}
5757
{{#if (ne kind "enum-constant")}}
5858
|xref:{{{anchor}}}[`{{>symbol/name . nolink=true}}`]
5959
{{else}}
@@ -145,7 +145,7 @@
145145
{{else}}
146146
{{#with (flattenUnique symbol.members "doc.tparams" "name") as |allTParams|}}
147147
{{#if (ne (len allTParams) 0)}}
148-
{{#> markup/dynamic-level-h }}Parameters{{/markup/dynamic-level-h}}
148+
{{#> markup/dynamic-level-h }}Template Parameters{{/markup/dynamic-level-h}}
149149

150150
|===
151151
| Name | Description

share/mrdocs/addons/generator/common/partials/symbol/members-table.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
See: https://mrdocs.com/docs/mrdocs/develop/generators.html#dom_reference
1313
--}}
14-
{{#if members}}
14+
{{#if (any_of_by members "isRegular" "isSeeBelow")}}
1515
{{#>markup/h level=(select @root.config.multipage 1 2)}}{{title}}{{/markup/h}}
1616
{{#>markup/table cols=2}}
1717
{{#>markup/thead}}
@@ -21,7 +21,7 @@
2121
{{/markup/tr}}
2222
{{/markup/thead}}
2323
{{#>markup/tbody}}
24-
{{#each (sort_by members "name")}}
24+
{{#each (filter_by (sort_by members "name") "isRegular" "isSeeBelow")}}
2525
{{> symbol/detail/members-table-row .}}
2626
{{/each}}
2727
{{/markup/tbody}}

share/mrdocs/addons/generator/common/partials/symbol/name-info.hbs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{{!--
22
Renders a Name Info object.
33
4+
Name Info objects are typically fields of a Type Object.
5+
They carry information about the Symbol the type
6+
refers to.
7+
48
Expected Context: {Name Info Object}
59
610
Optional parameters:
@@ -14,9 +18,11 @@
1418
{{#if prefix~}}
1519
{{> symbol/name-info prefix nolink=nolink~}}::
1620
{{~/if~}}
17-
{{#if (contains (arr "see-below" "implementation-defined") name)~}}
21+
{{#if symbol.isSeeBelow ~}}
22+
{{ str '_'}}see-below{{ str '_'~}}
23+
{{else if symbol.isImplementationDefined~}}
1824
{{! These are special names that should not be linked. }}
19-
{{ str '_'}}{{name}}{{ str '_'~}}
25+
{{ str '_'}}implementation-defined{{ str '_'~}}
2026
{{else~}}
2127
{{! Render the name of the symbol. ~}}
2228
{{#if (and symbol.url (not nolink))~}}

share/mrdocs/addons/generator/html/partials/symbol.html.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</tr>
6666
</thead>
6767
<tbody>
68-
{{#each symbol.members}}
68+
{{#each (filter_by symbol.members "isRegular" "isSeeBelow")}}
6969
<tr>
7070
{{#if (ne kind "enum-constant")}}
7171
<td><a href="#{{anchor}}">{{>symbol/name . nolink=true}}</a></td>

src/lib/Metadata/Info.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ tag_invoke(
7171
}
7272
io.map("kind", I.Kind);
7373
io.map("access", I.Access);
74-
io.map("implicit", I.Implicit);
74+
io.map("extraction", I.Extraction);
75+
io.map("isRegular", I.Extraction == ExtractionMode::Regular);
76+
io.map("isSeeBelow", I.Extraction == ExtractionMode::SeeBelow);
77+
io.map("isImplementationDefined", I.Extraction == ExtractionMode::ImplementationDefined);
78+
io.map("isDependency", I.Extraction == ExtractionMode::Dependency);
7579
if (I.Parent)
7680
{
7781
io.map("parent", I.Parent);

0 commit comments

Comments
 (0)