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

Attribute improvements #863

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
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
40 changes: 6 additions & 34 deletions docs/modules/ROOT/pages/generators.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ The `Symbol` object represents a symbol extracted from the source code.The symbo
| `Any`
| The documentation for the symbol.

| `attributes`
| `string[]`
| The attributes of the symbol.

|===

Handlebars generators extend each symbol with the following fields:
Expand Down Expand Up @@ -326,13 +330,9 @@ When the symbol kind is `function`, the symbol object has the following addition
| `bool`
| Whether the function is deleted as written.

| `isNoReturn`
| `isOverride`
| `bool`
| Whether the function is noreturn.

| `hasOverrideAttr`
| `bool`
| Whether the function has the override attribute.
| Whether the function is override.

| `hasTrailingReturn`
| `bool`
Expand All @@ -350,10 +350,6 @@ When the symbol kind is `function`, the symbol object has the following addition
| `bool`
| Whether the function is final.

| `isNodiscard`
| `bool`
| Whether the function is nodiscard.

| `isExplicitObjectMemberFunction`
| `bool`
| Whether the function is an explicit object member function.
Expand Down Expand Up @@ -401,10 +397,6 @@ When the symbol kind is `function`, the symbol object has the following addition
| `requires`
| `string`
| The `requires` expression of the function.

| `attributes`
| `string[]`
| The attributes of the function.
|===

When the symbol kind is `typedef`, the symbol object has the following additional properties:
Expand Down Expand Up @@ -461,10 +453,6 @@ When the symbol kind is `variable`, the symbol object has the following addition
| `initializer`
| `string`
| The initializer of the variable.

| `attributes`
| `string[]`
| The attributes of the variable.
|===

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

| `isMaybeUnused`
| `bool`
| Whether the field is maybe unused.

| `isDeprecated`
| `bool`
| Whether the field is deprecated.

| `isVariant`
| `bool`
| Whether the field is a variant.
Expand All @@ -500,17 +480,9 @@ When the symbol kind is `field` (i.e. non-static data members), the symbol objec
| `bool`
| Whether the field is a bitfield.

| `hasNoUniqueAddress`
| `string`
| Whether the field has the `[[no_unique_address]]` attribute.

| `bitfieldWidth`
| `string`
| The width of the bitfield.

| `attributes`
| `string[]`
| The attributes of the field.
|===

When the symbol kind is `friend`, the symbol object has the following additional properties:
Expand Down
7 changes: 7 additions & 0 deletions include/mrdocs/Metadata/Info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <mrdocs/Platform.hpp>
#include <mrdocs/Dom.hpp>
#include <mrdocs/Dom/LazyArray.hpp>
#include <mrdocs/Dom/LazyObject.hpp>
#include <mrdocs/Metadata/ExtractionMode.hpp>
#include <mrdocs/Metadata/Javadoc.hpp>
Expand Down Expand Up @@ -112,6 +113,10 @@ struct MRDOCS_VISIBLE Info
*/
std::optional<Javadoc> javadoc;

/** The attributes appertaining to this declaration.
*/
std::vector<AttributeKind> Attributes;

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

~Info() override = default;
Expand Down Expand Up @@ -298,6 +303,8 @@ tag_invoke(
{
io.map("doc", *I.javadoc);
}

io.map("attributes", dom::LazyArray(I.Attributes));
io.map("loc", dynamic_cast<SourceInfo const&>(I));
}

Expand Down
14 changes: 0 additions & 14 deletions include/mrdocs/Metadata/Info/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ struct FieldInfo final
/** The width of the bitfield */
ConstantExprInfo<std::uint64_t> BitfieldWidth;

// KRYSTIAN FIXME: nodiscard cannot be applied to fields; this should
// instead be IsMaybeUnused. we should also store the spelling
bool IsMaybeUnused = false;

bool IsDeprecated = false;

bool HasNoUniqueAddress = false;

std::vector<std::string> Attributes;

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

explicit FieldInfo(SymbolID ID) noexcept
Expand Down Expand Up @@ -86,17 +76,13 @@ tag_invoke(
{
io.map("default", I.Default.Written);
}
io.map("isMaybeUnused", I.IsMaybeUnused);
io.map("isDeprecated", I.IsDeprecated);
io.map("isVariant", I.IsVariant);
io.map("isMutable", I.IsMutable);
io.map("isBitfield", I.IsBitfield);
io.map("hasNoUniqueAddress", I.HasNoUniqueAddress);
if (I.IsBitfield)
{
io.map("bitfieldWidth", I.BitfieldWidth.Written);
}
io.map("attributes", dom::LazyArray(I.Attributes));
}

/** Map the FieldInfo to a @ref dom::Value object.
Expand Down
9 changes: 2 additions & 7 deletions include/mrdocs/Metadata/Info/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ struct FunctionInfo final
bool IsExplicitlyDefaulted = false;
bool IsDeleted = false;
bool IsDeletedAsWritten = false;
bool IsNoReturn = false;
bool HasOverrideAttr = false;
bool HasTrailingReturn = false;
bool IsNodiscard = false;
bool IsExplicitObjectMemberFunction = false;
ConstexprKind Constexpr = ConstexprKind::None;
OperatorKind OverloadedOperator = OperatorKind::None;
Expand All @@ -183,6 +180,7 @@ struct FunctionInfo final
bool IsConst = false;
bool IsVolatile = false;
bool IsFinal = false;
bool IsOverride = false;
ReferenceKind RefQualifier = ReferenceKind::None;
ExplicitInfo Explicit;

Expand Down Expand Up @@ -220,13 +218,11 @@ tag_invoke(
io.map("isExplicitlyDefaulted", I.IsExplicitlyDefaulted);
io.map("isDeleted", I.IsDeleted);
io.map("isDeletedAsWritten", I.IsDeletedAsWritten);
io.map("isNoReturn", I.IsNoReturn);
io.map("hasOverrideAttr", I.HasOverrideAttr);
io.map("hasTrailingReturn", I.HasTrailingReturn);
io.map("isConst", I.IsConst);
io.map("isVolatile", I.IsVolatile);
io.map("isFinal", I.IsFinal);
io.map("isNodiscard", I.IsNodiscard);
io.map("isOverride", I.IsOverride);
io.map("isExplicitObjectMemberFunction", I.IsExplicitObjectMemberFunction);
if (I.Constexpr != ConstexprKind::None)
{
Expand All @@ -251,7 +247,6 @@ tag_invoke(
{
io.map("requires", I.Requires.Written);
}
io.map("attributes", dom::LazyArray(I.Attributes));
}

/** Map the FunctionInfo to a @ref dom::Value object.
Expand Down
2 changes: 0 additions & 2 deletions include/mrdocs/Metadata/Info/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <mrdocs/Metadata/Template.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Type.hpp>
#include <mrdocs/Dom/LazyArray.hpp>
#include <mrdocs/ADT/Polymorphic.hpp>

namespace clang::mrdocs {
Expand Down Expand Up @@ -89,7 +88,6 @@ tag_invoke(
{
io.map("initializer", I.Initializer.Written);
}
io.map("attributes", dom::LazyArray(I.Attributes));
}

/** Map the VariableInfo to a @ref dom::Value object.
Expand Down
24 changes: 24 additions & 0 deletions include/mrdocs/Metadata/Specifiers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ enum class AccessKind
Private,
};

/** Attribute kinds.
*/
enum class AttributeKind
{
Deprecated,
MaybeUnused,
Nodiscard,
Noreturn,
NoUniqueAddress
};

/** `constexpr`/`consteval` specifier kinds

[dcl.spec.general] p2: At most one of the `constexpr`, `consteval`,
Expand Down Expand Up @@ -209,6 +220,7 @@ enum class StorageClassKind
};

MRDOCS_DECL dom::String toString(AccessKind kind) noexcept;
MRDOCS_DECL dom::String toString(AttributeKind kind) noexcept;
MRDOCS_DECL dom::String toString(ConstexprKind kind) noexcept;
MRDOCS_DECL dom::String toString(ExplicitKind kind) noexcept;
MRDOCS_DECL dom::String toString(NoexceptKind kind) noexcept;
Expand Down Expand Up @@ -278,6 +290,18 @@ tag_invoke(
v = toString(kind);
}

/** Return the AttributeKind as a @ref dom::Value string.
*/
inline
void
tag_invoke(
dom::ValueFromTag,
dom::Value& v,
AttributeKind kind)
{
v = toString(kind);
}

/** Return the ConstexprKind as a @ref dom::Value string.
*/
inline
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{!-- Renders the symbol attributes. --}}
{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{>template/head template}}

concept {{>symbol/name symbol}} = {{constraint}};
concept {{>symbol/name symbol}}{{#if attributes}} {{>symbol/attributes symbol}}{{/if}} = {{constraint}};
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
enum {{#if isScoped}}class {{/if}}{{>symbol/name .~}}
enum{{#if isScoped}} class{{/if}}{{#if attributes}} {{>symbol/attributes symbol}}{{/if}} {{>symbol/name .~}}
{{#if type}} : {{>type/declarator type}}{{/if}};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#if attributes}}{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
{{/if}}
{{#if attributes}}{{>symbol/attributes symbol}}
{{/if~}}
{{#if isMutable}}mutable
{{/if~}}
{{>type/declarator-prefix type}} {{>symbol/name symbol~}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{/if~}}
{{#if isFriend}}friend
{{/if~}}
{{#if attributes}}{{#unless isFriend}}{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
{{#if attributes}}{{#unless isFriend}}{{>symbol/attributes symbol}}
{{/unless}}{{/if~}}
{{#if constexprKind}}{{constexprKind}}
{{/if~}}
Expand All @@ -28,7 +28,7 @@
{{#if requires}}

requires {{requires}}{{/if~}}
{{#if hasOverrideAttr}} override{{/if~}}
{{#if isOverride}} override{{/if~}}
{{#if isFinal}} final{{/if~}}
{{#if isPure}} = 0{{/if~}}
{{#if isDeleted}} = delete{{/if~}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#if template}}{{>template/head template}}
{{/if~}}
{{#if isFriend}}friend {{/if}}{{tag}} {{>symbol/name symbol link=(select link link template.primary)~}}
{{#if isFriend}}friend {{/if}}{{tag}}{{#if attributes}} {{>symbol/attributes symbol}}{{/if}} {{>symbol/name symbol link=(select link link template.primary)~}}
{{#unless bases~}}
{{else if isFriend~}}
{{else}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{{#if isUsing~}}
{{#if template}}{{>template/head template}}
{{/if~}}
using {{name}} = {{>type/declarator type}}
using {{name}}{{#if attributes}} {{>symbol/attributes symbol}}{{/if}} = {{>type/declarator type}}
{{~else~}}
{{#if attributes}}{{>symbol/attributes symbol}}
{{/if~}}
typedef {{>type/declarator type decl-name=name}}
{{~/if}};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{#if template}}{{>template/head template}}
{{/if~}}
{{#if attributes}}{{>symbol/attributes symbol}}
{{/if~}}
{{#if isInline}}inline {{/if~}}
{{#if isConstexpr}}constexpr {{/if~}}
{{#if storageClass}}{{storageClass}}
Expand Down
Loading
Loading