Skip to content

Commit ac00578

Browse files
committed
merge mutually exclusive field and variable symbol types
#improvement
1 parent b055f05 commit ac00578

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+310
-480
lines changed

include/mrdocs/Metadata.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,10 @@
1414

1515
#include <mrdocs/Platform.hpp>
1616

17-
// All headers related to
18-
// metadata extracted from AST
19-
20-
#include <mrdocs/Metadata/Info/Using.hpp>
21-
#include <mrdocs/Metadata/Expression.hpp>
2217
#include <mrdocs/Metadata/Info.hpp>
2318
#include <mrdocs/Metadata/Info/Concept.hpp>
2419
#include <mrdocs/Metadata/Info/Enum.hpp>
2520
#include <mrdocs/Metadata/Info/EnumConstant.hpp>
26-
#include <mrdocs/Metadata/Info/Field.hpp>
2721
#include <mrdocs/Metadata/Info/Friend.hpp>
2822
#include <mrdocs/Metadata/Info/Function.hpp>
2923
#include <mrdocs/Metadata/Info/Guide.hpp>
@@ -33,6 +27,9 @@
3327
#include <mrdocs/Metadata/Info/Record.hpp>
3428
#include <mrdocs/Metadata/Info/Typedef.hpp>
3529
#include <mrdocs/Metadata/Info/Variable.hpp>
30+
#include <mrdocs/Metadata/Info/Using.hpp>
31+
32+
#include <mrdocs/Metadata/Expression.hpp>
3633
#include <mrdocs/Metadata/Javadoc.hpp>
3734
#include <mrdocs/Metadata/Name.hpp>
3835
#include <mrdocs/Metadata/Source.hpp>

include/mrdocs/Metadata/Info/Field.hpp

Lines changed: 0 additions & 117 deletions
This file was deleted.

include/mrdocs/Metadata/Info/Variable.hpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace clang::mrdocs {
2525
/** A variable.
2626
2727
This includes variables at namespace
28-
scope, and static variables at class scope.
28+
or record scope.
2929
*/
3030
struct VariableInfo final
3131
: InfoCommonBase<InfoKind::Variable>
@@ -35,6 +35,8 @@ struct VariableInfo final
3535

3636
std::optional<TemplateInfo> Template;
3737

38+
/** The default member initializer, if any.
39+
*/
3840
ExprInfo Initializer;
3941

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

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

54+
bool IsMaybeUnused = false;
55+
56+
bool IsDeprecated = false;
57+
58+
bool HasNoUniqueAddress = false;
59+
60+
//--------------------------------------------
61+
// Record fields
62+
bool IsRecordField = false;
63+
64+
/** Whether the field is declared mutable */
65+
bool IsMutable = false;
66+
67+
/** Whether the field is a variant member */
68+
bool IsVariant = false;
69+
70+
/** Whether the field is a bitfield */
71+
bool IsBitfield = false;
72+
73+
/** The width of the bitfield */
74+
ConstantExprInfo<std::uint64_t> BitfieldWidth;
75+
5276
//--------------------------------------------
5377

5478
explicit VariableInfo(SymbolID const &ID) noexcept
@@ -90,6 +114,18 @@ tag_invoke(
90114
io.map("initializer", I.Initializer.Written);
91115
}
92116
io.map("attributes", dom::LazyArray(I.Attributes));
117+
io.map("isRecordField", I.IsRecordField);
118+
io.map("isMaybeUnused", I.IsMaybeUnused);
119+
io.map("isDeprecated", I.IsDeprecated);
120+
io.map("isVariant", I.IsVariant);
121+
io.map("isMutable", I.IsMutable);
122+
io.map("isBitfield", I.IsBitfield);
123+
if (I.IsBitfield)
124+
{
125+
io.map("bitfieldWidth", I.BitfieldWidth.Written);
126+
}
127+
io.map("hasNoUniqueAddress", I.HasNoUniqueAddress);
128+
io.map("attributes", dom::LazyArray(I.Attributes));
93129
}
94130

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

mrdocs.rnc

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,30 +166,14 @@ grammar
166166

167167
#---------------------------------------------
168168

169-
Field =
170-
element (field|bitfield)
171-
{
172-
Name,
173-
Access ?,
174-
ID,
175-
attribute width { text } ?,
176-
attribute default { text } ?,
177-
Location,
178-
(
179-
Attr * &
180-
TypeInfo &
181-
Javadoc ?
182-
)
183-
}
184-
185-
#---------------------------------------------
186-
187169
Variable =
188170
element variable
189171
{
190172
Name,
191173
Access ?,
192174
ID,
175+
attribute width { text } ?,
176+
attribute default { text } ?,
193177
Location *,
194178
(
195179
Attr * &
@@ -367,7 +351,6 @@ grammar
367351
Function |
368352
Typedef |
369353
Enum |
370-
Field |
371354
Variable |
372355
Guide |
373356
Template |

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

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
{{#if attributes}}{{ str "[[" }}{{join ", " attributes}}{{ str "]]" }}
2+
{{/if}}
13
{{#if template}}{{>template/head template}}
24
{{/if~}}
5+
{{#if isMutable}}mutable
6+
{{/if~}}
37
{{#if isInline}}inline {{/if~}}
48
{{#if isConstexpr}}constexpr {{/if~}}
59
{{#if storageClass}}{{storageClass}}
610
{{/if~}}
711
{{#if isThreadLocal}}thread_local
812
{{/if~}}
913
{{>type/declarator-prefix type}} {{>symbol/name symbol link=(select link link template.primary)~}}
14+
{{#if isBitfield}} : {{bitfieldWidth}}{{/if~}}
15+
{{#if default}} = {{default}}{{/if~}}
1016
{{>type/declarator-suffix type~}}
1117
{{#if initializer}} = {{initializer}}{{/if}};

share/mrdocs/addons/generator/common/partials/symbol/special-function-suffix.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{{~#if isDeleted~}}
2727
{{str ' '}}{{#>markup/span class="small"}}[deleted]{{/markup/span}}
2828
{{~/if~}}
29-
{{else if (eq kind "field")~}}
29+
{{else if (eq kind "variable")~}}
3030
{{~#if isVariant~}}
3131
{{#>markup/span class="small"}}[variant member]{{/markup/span}}
3232
{{~/if~}}

src/lib/AST/ASTVisitor.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,16 +1085,17 @@ populate(VariableInfo& I, VarTemplatePartialSpecializationDecl const* D)
10851085
void
10861086
ASTVisitor::
10871087
populate(
1088-
FieldInfo& I,
1088+
VariableInfo& I,
10891089
FieldDecl const* D)
10901090
{
1091+
I.IsRecordField = true;
10911092
I.Type = toTypeInfo(D->getType());
1092-
I.IsVariant = D->getParent()->isUnion();
1093-
I.IsMutable = D->isMutable();
10941093
if (Expr const* E = D->getInClassInitializer())
10951094
{
1096-
populate(I.Default, E);
1095+
populate(I.Initializer, E);
10971096
}
1097+
I.IsVariant = D->getParent()->isUnion();
1098+
I.IsMutable = D->isMutable();
10981099
if(D->isBitField())
10991100
{
11001101
I.IsBitfield = true;
@@ -1756,14 +1757,16 @@ addMember(RecordTranche& T, Info const& Member)
17561757
}
17571758
return;
17581759
}
1759-
if (auto const* U = Member.asFieldPtr())
1760-
{
1761-
addMember(T.Variables, *U);
1762-
return;
1763-
}
17641760
if (auto const* U = Member.asVariablePtr())
17651761
{
1766-
addMember(T.StaticVariables, *U);
1762+
if (U->StorageClass != StorageClassKind::Static)
1763+
{
1764+
addMember(T.Variables, *U);
1765+
}
1766+
else
1767+
{
1768+
addMember(T.StaticVariables, *U);
1769+
}
17671770
return;
17681771
}
17691772
if (auto const* U = Member.asConceptPtr())

src/lib/AST/ASTVisitor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class ASTVisitor
573573
populate(VariableInfo& I, VarTemplatePartialSpecializationDecl const* D);
574574

575575
void
576-
populate(FieldInfo& I, FieldDecl const* D);
576+
populate(VariableInfo& I, FieldDecl const* D);
577577

578578
void
579579
populate(FriendInfo& I, FriendDecl const* D);

src/lib/AST/ClangHelpers.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,9 @@ template <>
165165
struct InfoTypeFor<VarTemplateDecl>
166166
: std::type_identity<VariableInfo> {};
167167

168-
// Extract FieldInfo from FieldDecl
169168
template <>
170169
struct InfoTypeFor<FieldDecl>
171-
: std::type_identity<FieldInfo> {};
170+
: std::type_identity<VariableInfo> {};
172171

173172
// Extract FriendInfo from FriendDecl
174173
template <>

0 commit comments

Comments
 (0)