Skip to content
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
16 changes: 12 additions & 4 deletions docs/modules/ROOT/pages/generators.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,18 @@ When the symbol kind is `variable`, the symbol object has the following addition
| `<<template-info-fields,Template Info Object>>`
| The template information of the variable.

| `constexprKind`
| `string`
| The constexpr kind of the variable (e.g., `consteval`, `constexpr`).

| `storageClass`
| `string`
| The storage class of the variable (e.g., `static`, `extern`).

| `isInline`
| `bool`
| Whether the variable is `inline`.

| `isConstexpr`
| `bool`
| Whether the variable is `constexpr`.

| `isConstinit`
| `bool`
| Whether the variable is `constinit`.
Expand All @@ -457,6 +461,10 @@ 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 Down
6 changes: 5 additions & 1 deletion include/mrdocs/Metadata/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ struct VariableInfo

StorageClassKind StorageClass = StorageClassKind::None;

ConstexprKind Constexpr = ConstexprKind::None;
bool IsInline = false;

bool IsConstexpr = false;

bool IsConstinit = false;

bool IsThreadLocal = false;

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

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

explicit VariableInfo(SymbolID ID) noexcept
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#if template}}{{>template/head template}}
{{/if~}}
{{#if constexprKind}}{{constexprKind}}
{{/if~}}
{{#if isInline}}inline {{/if~}}
{{#if isConstexpr}}constexpr {{/if~}}
{{#if storageClass}}{{storageClass}}
{{/if~}}
{{#if isThreadLocal}}thread_local
Expand Down
61 changes: 37 additions & 24 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,9 +1089,11 @@ populate(
default_arg)
{
param.Default = getSourceCode(default_arg->getSourceRange());
param.Default = trim(param.Default);
if (param.Default.starts_with("= "))
{
param.Default.erase(0, 2);
param.Default = ltrim(param.Default);
}
}
}
Expand All @@ -1110,17 +1112,7 @@ populate(
populate(I.Requires, TRC);
}

if (D->hasAttrs())
{
for (AttrVec& attrs = D->getAttrs();
Attr const* attr: attrs)
{
if (IdentifierInfo const* II = attr->getAttrName())
{
I.Attributes.emplace_back(II->getName());
}
}
}
populateAttributes(I, D);
}

void
Expand Down Expand Up @@ -1200,15 +1192,20 @@ populate(
// it is possible to declare a static data member
// as both constexpr and constinit in separate declarations..
I.IsConstinit |= D->hasAttr<ConstInitAttr>();
if (D->isConstexpr())
{
I.Constexpr = ConstexprKind::Constexpr;
}
I.IsConstexpr |= D->isConstexpr();
I.IsInline |= D->isInline();
if (Expr const* E = D->getInit())
{
populate(I.Initializer, E);
}
I.Type = toTypeInfo(D->getType());
auto QT = D->getType();
if (D->isConstexpr()) {
// when D->isConstexpr() is true, QT contains a redundant
// `const` qualifier which we need to remove
QT.removeLocalConst();
}
I.Type = toTypeInfo(QT);
populateAttributes(I, D);
}

void
Expand All @@ -1232,14 +1229,7 @@ populate(
I.HasNoUniqueAddress = D->hasAttr<NoUniqueAddressAttr>();
I.IsDeprecated = D->hasAttr<DeprecatedAttr>();
I.IsMaybeUnused = D->hasAttr<UnusedAttr>();
if (D->hasAttrs())
{
for (AttrVec& attrs = D->getAttrs();
Attr const* attr: attrs)
{
I.Attributes.emplace_back(attr->getAttrName()->getName());
}
}
populateAttributes(I, D);
}

void
Expand Down Expand Up @@ -1671,6 +1661,29 @@ populate(
}));
}

template <std::derived_from<Info> InfoTy>
void
ASTVisitor::
populateAttributes(InfoTy& I, const Decl* D)
{
if constexpr (requires { I.Attributes; })
{
MRDOCS_CHECK_OR(D->hasAttrs());
for (Attr const* attr: D->getAttrs())
{
IdentifierInfo const* II = attr->getAttrName();
if (!II)
{
continue;
}
if (std::ranges::find(I.Attributes, II->getName()) == I.Attributes.end())
{
I.Attributes.emplace_back(II->getName());
}
}
}
}

std::string
ASTVisitor::
extractName(NamedDecl const* D)
Expand Down
5 changes: 5 additions & 0 deletions src/lib/AST/ASTVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ class ASTVisitor
std::vector<std::unique_ptr<TArg>>& result,
const ASTTemplateArgumentListInfo* args);

template <std::derived_from<Info> InfoTy>
static
void
populateAttributes(InfoTy& I, const Decl* D);

// =================================================
// Populate function helpers
// =================================================
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Gen/xml/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ writeVariable(
writeSourceInfo(I);

writeAttr(I.StorageClass, "storage-class", tags_);
writeAttr(I.Constexpr, "constexpr-kind", tags_);
writeAttr(I.IsInline, "is-inline", tags_);
writeAttr(I.IsConstexpr, "is-constexpr", tags_);
writeAttr(I.IsConstinit, "is-constinit", tags_);
writeAttr(I.IsThreadLocal, "is-thread-local", tags_);

Expand Down
24 changes: 12 additions & 12 deletions src/lib/Metadata/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,22 @@ tag_invoke(
}
if constexpr (T::isVariable())
{
io.map("type", I.Type);
io.map("template", I.Template);
if (I.Constexpr != ConstexprKind::None)
{
io.map("constexprKind", I.Constexpr);
}
if (I.StorageClass != StorageClassKind::None)
auto const& U = static_cast<VariableInfo const&>(I);
io.map("type", U.Type);
io.map("template", U.Template);
if (U.StorageClass != StorageClassKind::None)
{
io.map("storageClass", I.StorageClass);
io.map("storageClass", U.StorageClass);
}
io.map("isConstinit", I.IsConstinit);
io.map("isThreadLocal", I.IsThreadLocal);
if (!I.Initializer.Written.empty())
io.map("isInline", U.IsInline);
io.map("isConstexpr", U.IsConstexpr);
io.map("isConstinit", U.IsConstinit);
io.map("isThreadLocal", U.IsThreadLocal);
if (!U.Initializer.Written.empty())
{
io.map("initializer", I.Initializer.Written);
io.map("initializer", U.Initializer.Written);
}
io.map("attributes", dom::LazyArray(U.Attributes));
}
if constexpr (T::isField())
{
Expand Down
16 changes: 12 additions & 4 deletions src/lib/Metadata/Reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,19 @@ void merge(VariableInfo& I, VariableInfo&& Other)

I.IsConstinit |= Other.IsConstinit;
I.IsThreadLocal |= Other.IsThreadLocal;

if(I.Constexpr == ConstexprKind::None)
I.Constexpr = Other.Constexpr;
if(I.StorageClass == StorageClassKind::None)
I.IsConstexpr |= Other.IsConstexpr;
I.IsInline |= Other.IsInline;
if (I.StorageClass == StorageClassKind::None)
{
I.StorageClass = Other.StorageClass;
}
for (auto& otherAttr: Other.Attributes)
{
if (std::ranges::find(I.Attributes, otherAttr) == I.Attributes.end())
{
I.Attributes.push_back(otherAttr);
}
}
}

void merge(SpecializationInfo& I, SpecializationInfo&& Other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ Declared in `&lt;impl&hyphen;defined&hyphen;member&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
&sol;&ast; implementation-defined &ast;&sol; const absolute&lowbar;uri&lowbar;rule = &lcub;&rcub;;
constexpr &sol;&ast; implementation-defined &ast;&sol; absolute&lowbar;uri&lowbar;rule = &lcub;&rcub;;
----

[#regular_absolute_uri_rule]
Expand All @@ -79,8 +78,7 @@ Declared in `&lt;impl&hyphen;defined&hyphen;member&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
<<regular,regular>>::<<regular-absolute_uri_rule_t,absolute&lowbar;uri&lowbar;rule&lowbar;t>> const regular&lowbar;absolute&lowbar;uri&lowbar;rule = &lcub;&rcub;;
constexpr <<regular,regular>>::<<regular-absolute_uri_rule_t,absolute&lowbar;uri&lowbar;rule&lowbar;t>> regular&lowbar;absolute&lowbar;uri&lowbar;rule = &lcub;&rcub;;
----


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ <h3>Synopsis</h3>
Declared in <code>&lt;impl-defined-member.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
constexpr
/* implementation-defined */ const absolute_uri_rule = {};
constexpr /* implementation-defined */ absolute_uri_rule = {};
</code>
</pre>
</div>
Expand All @@ -95,8 +94,7 @@ <h3>Synopsis</h3>
Declared in <code>&lt;impl-defined-member.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
constexpr
<a href="#regular">regular</a>::<a href="#regular-absolute_uri_rule_t">absolute_uri_rule_t</a> const regular_absolute_uri_rule = {};
constexpr <a href="#regular">regular</a>::<a href="#regular-absolute_uri_rule_t">absolute_uri_rule_t</a> regular_absolute_uri_rule = {};
</code>
</pre>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
</namespace>
<variable name="absolute_uri_rule" id="/ePshzEghZYl/D7bJ6X3M2XbKEg=">
<file path="impl-defined-member.cpp" line="9" class="def"/>
<attr id="constexpr-kind" name="constexpr" value="1"/>
<type id="vOKKVGAcuI3CBaMkdZstuFgnnuQ=" name="detail::absolute_uri_rule_t" cv-qualifiers="const"/>
<attr id="is-constexpr"/>
<type id="vOKKVGAcuI3CBaMkdZstuFgnnuQ=" name="detail::absolute_uri_rule_t"/>
</variable>
<variable name="regular_absolute_uri_rule" id="ixmivDXFAcQVJd4G7XOqINAR858=">
<file path="impl-defined-member.cpp" line="11" class="def"/>
<attr id="constexpr-kind" name="constexpr" value="1"/>
<type id="fA+/UQOR2lG0f1+BZ+GeGlfo5sY=" name="regular::absolute_uri_rule_t" cv-qualifiers="const"/>
<attr id="is-constexpr"/>
<type id="fA+/UQOR2lG0f1+BZ+GeGlfo5sY=" name="regular::absolute_uri_rule_t"/>
</variable>
</namespace>
</mrdocs>
13 changes: 5 additions & 8 deletions test-files/golden-tests/metadata/ns-variables.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ Declared in `&lt;ns&hyphen;variables&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
int const i = 0;
constexpr int i = 0;
----

[#j]
Expand Down Expand Up @@ -87,9 +86,8 @@ Declared in `&lt;ns&hyphen;variables&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
extern
int const k = 1;
constexpr extern
int k = 1;
----

[#l]
Expand Down Expand Up @@ -178,10 +176,9 @@ Declared in `&lt;ns&hyphen;variables&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
static
constexpr static
thread_local
int const x2 = 0;
int x2 = 0;
----


Expand Down
13 changes: 5 additions & 8 deletions test-files/golden-tests/metadata/ns-variables.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ <h3>Synopsis</h3>
Declared in <code>&lt;ns-variables.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
constexpr
int const i = 0;
constexpr int i = 0;
</code>
</pre>
</div>
Expand Down Expand Up @@ -100,9 +99,8 @@ <h3>Synopsis</h3>
Declared in <code>&lt;ns-variables.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
constexpr
extern
int const k = 1;
constexpr extern
int k = 1;
</code>
</pre>
</div>
Expand Down Expand Up @@ -197,10 +195,9 @@ <h3>Synopsis</h3>
Declared in <code>&lt;ns-variables.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
constexpr
static
constexpr static
thread_local
int const x2 = 0;
int x2 = 0;
</code>
</pre>
</div>
Expand Down
Loading