Skip to content

Commit d7b9851

Browse files
committed
[WIP] add AttributeKind
1 parent 2d5e6a1 commit d7b9851

File tree

21 files changed

+142
-87
lines changed

21 files changed

+142
-87
lines changed

docs/modules/ROOT/pages/generators.adoc

+4-32
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ The `Symbol` object represents a symbol extracted from the source code.The symbo
189189
| `Any`
190190
| The documentation for the symbol.
191191

192+
| `attributes`
193+
| `string[]`
194+
| The attributes of the symbol.
195+
192196
|===
193197

194198
Handlebars generators extend each symbol with the following fields:
@@ -326,10 +330,6 @@ When the symbol kind is `function`, the symbol object has the following addition
326330
| `bool`
327331
| Whether the function is deleted as written.
328332

329-
| `isNoReturn`
330-
| `bool`
331-
| Whether the function is noreturn.
332-
333333
| `isOverride`
334334
| `bool`
335335
| Whether the function is override.
@@ -350,10 +350,6 @@ When the symbol kind is `function`, the symbol object has the following addition
350350
| `bool`
351351
| Whether the function is final.
352352

353-
| `isNodiscard`
354-
| `bool`
355-
| Whether the function is nodiscard.
356-
357353
| `isExplicitObjectMemberFunction`
358354
| `bool`
359355
| Whether the function is an explicit object member function.
@@ -401,10 +397,6 @@ When the symbol kind is `function`, the symbol object has the following addition
401397
| `requires`
402398
| `string`
403399
| The `requires` expression of the function.
404-
405-
| `attributes`
406-
| `string[]`
407-
| The attributes of the function.
408400
|===
409401

410402
When the symbol kind is `typedef`, the symbol object has the following additional properties:
@@ -461,10 +453,6 @@ When the symbol kind is `variable`, the symbol object has the following addition
461453
| `initializer`
462454
| `string`
463455
| The initializer of the variable.
464-
465-
| `attributes`
466-
| `string[]`
467-
| The attributes of the variable.
468456
|===
469457

470458
When the symbol kind is `field` (i.e. non-static data members), the symbol object has the following additional properties:
@@ -480,14 +468,6 @@ When the symbol kind is `field` (i.e. non-static data members), the symbol objec
480468
| `string`
481469
| The default value of the field.
482470

483-
| `isMaybeUnused`
484-
| `bool`
485-
| Whether the field is maybe unused.
486-
487-
| `isDeprecated`
488-
| `bool`
489-
| Whether the field is deprecated.
490-
491471
| `isVariant`
492472
| `bool`
493473
| Whether the field is a variant.
@@ -500,17 +480,9 @@ When the symbol kind is `field` (i.e. non-static data members), the symbol objec
500480
| `bool`
501481
| Whether the field is a bitfield.
502482

503-
| `hasNoUniqueAddress`
504-
| `string`
505-
| Whether the field has the `[[no_unique_address]]` attribute.
506-
507483
| `bitfieldWidth`
508484
| `string`
509485
| The width of the bitfield.
510-
511-
| `attributes`
512-
| `string[]`
513-
| The attributes of the field.
514486
|===
515487

516488
When the symbol kind is `friend`, the symbol object has the following additional properties:

include/mrdocs/Metadata/Info.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <mrdocs/Platform.hpp>
1616
#include <mrdocs/Dom.hpp>
17+
#include <mrdocs/Dom/LazyArray.hpp>
1718
#include <mrdocs/Dom/LazyObject.hpp>
1819
#include <mrdocs/Metadata/ExtractionMode.hpp>
1920
#include <mrdocs/Metadata/Javadoc.hpp>
@@ -112,6 +113,10 @@ struct MRDOCS_VISIBLE Info
112113
*/
113114
std::optional<Javadoc> javadoc;
114115

116+
/** The attributes appertaining to this declaration.
117+
*/
118+
std::vector<AttributeKind> Attributes;
119+
115120
//--------------------------------------------
116121

117122
~Info() override = default;
@@ -298,6 +303,8 @@ tag_invoke(
298303
{
299304
io.map("doc", *I.javadoc);
300305
}
306+
307+
io.map("attributes", dom::LazyArray(I.Attributes));
301308
io.map("loc", dynamic_cast<SourceInfo const&>(I));
302309
}
303310

include/mrdocs/Metadata/Info/Field.hpp

-14
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ struct FieldInfo final
4848
/** The width of the bitfield */
4949
ConstantExprInfo<std::uint64_t> BitfieldWidth;
5050

51-
// KRYSTIAN FIXME: nodiscard cannot be applied to fields; this should
52-
// instead be IsMaybeUnused. we should also store the spelling
53-
bool IsMaybeUnused = false;
54-
55-
bool IsDeprecated = false;
56-
57-
bool HasNoUniqueAddress = false;
58-
59-
std::vector<std::string> Attributes;
60-
6151
//--------------------------------------------
6252

6353
explicit FieldInfo(SymbolID ID) noexcept
@@ -86,17 +76,13 @@ tag_invoke(
8676
{
8777
io.map("default", I.Default.Written);
8878
}
89-
io.map("isMaybeUnused", I.IsMaybeUnused);
90-
io.map("isDeprecated", I.IsDeprecated);
9179
io.map("isVariant", I.IsVariant);
9280
io.map("isMutable", I.IsMutable);
9381
io.map("isBitfield", I.IsBitfield);
94-
io.map("hasNoUniqueAddress", I.HasNoUniqueAddress);
9582
if (I.IsBitfield)
9683
{
9784
io.map("bitfieldWidth", I.BitfieldWidth.Written);
9885
}
99-
io.map("attributes", dom::LazyArray(I.Attributes));
10086
}
10187

10288
/** Map the FieldInfo to a @ref dom::Value object.

include/mrdocs/Metadata/Info/Function.hpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ struct FunctionInfo final
160160
bool IsExplicitlyDefaulted = false;
161161
bool IsDeleted = false;
162162
bool IsDeletedAsWritten = false;
163-
bool IsNoReturn = false;
164-
bool IsOverride = false;
165163
bool HasTrailingReturn = false;
166-
bool IsNodiscard = false;
167164
bool IsExplicitObjectMemberFunction = false;
168165
ConstexprKind Constexpr = ConstexprKind::None;
169166
OperatorKind OverloadedOperator = OperatorKind::None;
@@ -178,6 +175,7 @@ struct FunctionInfo final
178175
bool IsConst = false;
179176
bool IsVolatile = false;
180177
bool IsFinal = false;
178+
bool IsOverride = false;
181179
ReferenceKind RefQualifier = ReferenceKind::None;
182180
ExplicitInfo Explicit;
183181

@@ -215,13 +213,11 @@ tag_invoke(
215213
io.map("isExplicitlyDefaulted", I.IsExplicitlyDefaulted);
216214
io.map("isDeleted", I.IsDeleted);
217215
io.map("isDeletedAsWritten", I.IsDeletedAsWritten);
218-
io.map("isNoReturn", I.IsNoReturn);
219-
io.map("isOverride", I.IsOverride);
220216
io.map("hasTrailingReturn", I.HasTrailingReturn);
221217
io.map("isConst", I.IsConst);
222218
io.map("isVolatile", I.IsVolatile);
223219
io.map("isFinal", I.IsFinal);
224-
io.map("isNodiscard", I.IsNodiscard);
220+
io.map("isOverride", I.IsOverride);
225221
io.map("isExplicitObjectMemberFunction", I.IsExplicitObjectMemberFunction);
226222
if (I.Constexpr != ConstexprKind::None)
227223
{
@@ -246,7 +242,6 @@ tag_invoke(
246242
{
247243
io.map("requires", I.Requires.Written);
248244
}
249-
io.map("attributes", dom::LazyArray(I.Attributes));
250245
}
251246

252247
/** Map the FunctionInfo to a @ref dom::Value object.

include/mrdocs/Metadata/Info/Variable.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <mrdocs/Metadata/Template.hpp>
1818
#include <mrdocs/Metadata/Info.hpp>
1919
#include <mrdocs/Metadata/Type.hpp>
20-
#include <mrdocs/Dom/LazyArray.hpp>
2120
#include <mrdocs/ADT/Polymorphic.hpp>
2221

2322
namespace clang::mrdocs {
@@ -89,7 +88,6 @@ tag_invoke(
8988
{
9089
io.map("initializer", I.Initializer.Written);
9190
}
92-
io.map("attributes", dom::LazyArray(I.Attributes));
9391
}
9492

9593
/** Map the VariableInfo to a @ref dom::Value object.

include/mrdocs/Metadata/Specifiers.hpp

+24
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ enum class AccessKind
3636
Private,
3737
};
3838

39+
/** Attribute kinds.
40+
*/
41+
enum class AttributeKind
42+
{
43+
Deprecated,
44+
MaybeUnused,
45+
Nodiscard,
46+
Noreturn,
47+
NoUniqueAddress
48+
};
49+
3950
/** `constexpr`/`consteval` specifier kinds
4051
4152
[dcl.spec.general] p2: At most one of the `constexpr`, `consteval`,
@@ -209,6 +220,7 @@ enum class StorageClassKind
209220
};
210221

211222
MRDOCS_DECL dom::String toString(AccessKind kind) noexcept;
223+
MRDOCS_DECL dom::String toString(AttributeKind kind) noexcept;
212224
MRDOCS_DECL dom::String toString(ConstexprKind kind) noexcept;
213225
MRDOCS_DECL dom::String toString(ExplicitKind kind) noexcept;
214226
MRDOCS_DECL dom::String toString(NoexceptKind kind) noexcept;
@@ -278,6 +290,18 @@ tag_invoke(
278290
v = toString(kind);
279291
}
280292

293+
/** Return the AttributeKind as a @ref dom::Value string.
294+
*/
295+
inline
296+
void
297+
tag_invoke(
298+
dom::ValueFromTag,
299+
dom::Value& v,
300+
AttributeKind kind)
301+
{
302+
v = toString(kind);
303+
}
304+
281305
/** Return the ConstexprKind as a @ref dom::Value string.
282306
*/
283307
inline
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{!-- Renders the symbol attributes. --}}
2+
{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{>template/head template}}
22

3-
concept {{>symbol/name symbol}} = {{constraint}};
3+
concept {{>symbol/name symbol}}{{#if attributes}} {{>symbol/attributes symbol}}{{/if}} = {{constraint}};
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
enum {{#if isScoped}}class {{/if}}{{>symbol/name .~}}
1+
enum {{#if isScoped}}class {{/if}}{{#if attributes}} {{>symbol/attributes symbol}}{{/if}} {{>symbol/name .~}}
22
{{#if type}} : {{>type/declarator type}}{{/if}};

share/mrdocs/addons/generator/common/partials/symbol/signature/field.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{{#if attributes}}{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
2-
{{/if}}
1+
{{#if attributes}}{{>symbol/attributes symbol}}
2+
{{/if~}}
33
{{#if isMutable}}mutable
44
{{/if~}}
55
{{>type/declarator-prefix type}} {{>symbol/name symbol~}}

share/mrdocs/addons/generator/common/partials/symbol/signature/function.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{/if~}}
33
{{#if isFriend}}friend
44
{{/if~}}
5-
{{#if attributes}}{{#unless isFriend}}{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
5+
{{#if attributes}}{{#unless isFriend}}{{>symbol/attributes symbol}}
66
{{/unless}}{{/if~}}
77
{{#if constexprKind}}{{constexprKind}}
88
{{/if~}}

share/mrdocs/addons/generator/common/partials/symbol/signature/record.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{#if template}}{{>template/head template}}
22
{{/if~}}
3-
{{#if isFriend}}friend {{/if}}{{tag}} {{>symbol/name symbol link=(select link link template.primary)~}}
3+
{{#if isFriend}}friend {{/if}}{{tag}}{{#if attributes}} {{>symbol/attributes symbol}}{{/if}} {{>symbol/name symbol link=(select link link template.primary)~}}
44
{{#unless bases~}}
55
{{else if isFriend~}}
66
{{else}}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{{#if isUsing~}}
22
{{#if template}}{{>template/head template}}
33
{{/if~}}
4-
using {{name}} = {{>type/declarator type}}
4+
using {{name}}{{#if attributes}} {{>symbol/attributes symbol}}{{/if}} = {{>type/declarator type}}
55
{{~else~}}
6+
{{#if attributes}}{{>symbol/attributes symbol}}
7+
{{/if~}}
68
typedef {{>type/declarator type decl-name=name}}
79
{{~/if}};

share/mrdocs/addons/generator/common/partials/symbol/signature/variable.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{{#if template}}{{>template/head template}}
22
{{/if~}}
3+
{{#if attributes}}{{>symbol/attributes symbol}}
4+
{{/if~}}
35
{{#if isInline}}inline {{/if~}}
46
{{#if isConstexpr}}constexpr {{/if~}}
57
{{#if storageClass}}{{storageClass}}

0 commit comments

Comments
 (0)