Skip to content

merge mutually exclusive fields and variables #892

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

Merged
merged 2 commits into from
Apr 1, 2025
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
9 changes: 3 additions & 6 deletions include/mrdocs/Metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@

#include <mrdocs/Platform.hpp>

// All headers related to
// metadata extracted from AST

#include <mrdocs/Metadata/Info/Using.hpp>
#include <mrdocs/Metadata/Expression.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Info/Concept.hpp>
#include <mrdocs/Metadata/Info/Enum.hpp>
#include <mrdocs/Metadata/Info/EnumConstant.hpp>
#include <mrdocs/Metadata/Info/Field.hpp>
#include <mrdocs/Metadata/Info/Friend.hpp>
#include <mrdocs/Metadata/Info/Function.hpp>
#include <mrdocs/Metadata/Info/Guide.hpp>
Expand All @@ -33,6 +27,9 @@
#include <mrdocs/Metadata/Info/Record.hpp>
#include <mrdocs/Metadata/Info/Typedef.hpp>
#include <mrdocs/Metadata/Info/Variable.hpp>
#include <mrdocs/Metadata/Info/Using.hpp>

#include <mrdocs/Metadata/Expression.hpp>
#include <mrdocs/Metadata/Javadoc.hpp>
#include <mrdocs/Metadata/Name.hpp>
#include <mrdocs/Metadata/Source.hpp>
Expand Down
117 changes: 0 additions & 117 deletions include/mrdocs/Metadata/Info/Field.hpp

This file was deleted.

38 changes: 37 additions & 1 deletion include/mrdocs/Metadata/Info/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace clang::mrdocs {
/** A variable.

This includes variables at namespace
scope, and static variables at class scope.
or record scope.
*/
struct VariableInfo final
: InfoCommonBase<InfoKind::Variable>
Expand All @@ -35,6 +35,8 @@ struct VariableInfo final

std::optional<TemplateInfo> Template;

/** The default member initializer, if any.
*/
ExprInfo Initializer;

StorageClassKind StorageClass = StorageClassKind::None;
Expand All @@ -49,6 +51,28 @@ struct VariableInfo final

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

bool IsMaybeUnused = false;

bool IsDeprecated = false;

bool HasNoUniqueAddress = false;

//--------------------------------------------
// Record fields
bool IsRecordField = false;

/** Whether the field is declared mutable */
bool IsMutable = false;

/** Whether the field is a variant member */
bool IsVariant = false;

/** Whether the field is a bitfield */
bool IsBitfield = false;

/** The width of the bitfield */
ConstantExprInfo<std::uint64_t> BitfieldWidth;

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

explicit VariableInfo(SymbolID const &ID) noexcept
Expand Down Expand Up @@ -90,6 +114,18 @@ tag_invoke(
io.map("initializer", I.Initializer.Written);
}
io.map("attributes", dom::LazyArray(I.Attributes));
io.map("isRecordField", I.IsRecordField);
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);
if (I.IsBitfield)
{
io.map("bitfieldWidth", I.BitfieldWidth.Written);
}
io.map("hasNoUniqueAddress", I.HasNoUniqueAddress);
io.map("attributes", dom::LazyArray(I.Attributes));
}

/** Map the VariableInfo to a @ref dom::Value object.
Expand Down
21 changes: 2 additions & 19 deletions mrdocs.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,14 @@ grammar

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

Field =
element (field|bitfield)
{
Name,
Access ?,
ID,
attribute width { text } ?,
attribute default { text } ?,
Location,
(
Attr * &
TypeInfo &
Javadoc ?
)
}

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

Variable =
element variable
{
Name,
Access ?,
ID,
attribute width { text } ?,
attribute default { text } ?,
Location *,
(
Attr * &
Expand Down Expand Up @@ -367,7 +351,6 @@ grammar
Function |
Typedef |
Enum |
Field |
Variable |
Guide |
Template |
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{{#if attributes}}{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
{{/if}}
{{#if template}}{{>template/head template}}
{{/if~}}
{{#if isMutable}}mutable
{{/if~}}
{{#if isInline}}inline {{/if~}}
{{#if isConstexpr}}constexpr {{/if~}}
{{#if storageClass}}{{storageClass}}
{{/if~}}
{{#if isThreadLocal}}thread_local
{{/if~}}
{{>type/declarator-prefix type}} {{>symbol/name symbol link=(select link link template.primary)~}}
{{#if isBitfield}} : {{bitfieldWidth}}{{/if~}}
{{#if default}} = {{default}}{{/if~}}
{{>type/declarator-suffix type~}}
{{#if initializer}} = {{initializer}}{{/if}};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{{~#if isDeleted~}}
{{str ' '}}{{#>markup/span class="small"}}[deleted]{{/markup/span}}
{{~/if~}}
{{else if (eq kind "field")~}}
{{else if (eq kind "variable")~}}
{{~#if isVariant~}}
{{#>markup/span class="small"}}[variant member]{{/markup/span}}
{{~/if~}}
Expand Down
23 changes: 13 additions & 10 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,16 +1085,17 @@ populate(VariableInfo& I, VarTemplatePartialSpecializationDecl const* D)
void
ASTVisitor::
populate(
FieldInfo& I,
VariableInfo& I,
FieldDecl const* D)
{
I.IsRecordField = true;
I.Type = toTypeInfo(D->getType());
I.IsVariant = D->getParent()->isUnion();
I.IsMutable = D->isMutable();
if (Expr const* E = D->getInClassInitializer())
{
populate(I.Default, E);
populate(I.Initializer, E);
}
I.IsVariant = D->getParent()->isUnion();
I.IsMutable = D->isMutable();
if(D->isBitField())
{
I.IsBitfield = true;
Expand Down Expand Up @@ -1756,14 +1757,16 @@ addMember(RecordTranche& T, Info const& Member)
}
return;
}
if (auto const* U = Member.asFieldPtr())
{
addMember(T.Variables, *U);
return;
}
if (auto const* U = Member.asVariablePtr())
{
addMember(T.StaticVariables, *U);
if (U->StorageClass != StorageClassKind::Static)
{
addMember(T.Variables, *U);
}
else
{
addMember(T.StaticVariables, *U);
}
return;
}
if (auto const* U = Member.asConceptPtr())
Expand Down
2 changes: 1 addition & 1 deletion src/lib/AST/ASTVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class ASTVisitor
populate(VariableInfo& I, VarTemplatePartialSpecializationDecl const* D);

void
populate(FieldInfo& I, FieldDecl const* D);
populate(VariableInfo& I, FieldDecl const* D);

void
populate(FriendInfo& I, FriendDecl const* D);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/AST/ClangHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ template <>
struct InfoTypeFor<VarTemplateDecl>
: std::type_identity<VariableInfo> {};

// Extract FieldInfo from FieldDecl
template <>
struct InfoTypeFor<FieldDecl>
: std::type_identity<FieldInfo> {};
: std::type_identity<VariableInfo> {};

// Extract FriendInfo from FriendDecl
template <>
Expand Down
Loading
Loading