Skip to content

Commit

Permalink
feat: add IsMutable for FieldInfo
Browse files Browse the repository at this point in the history
closes #177
  • Loading branch information
sdkrystian committed Jun 30, 2023
1 parent db42b86 commit 9798204
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 14 deletions.
3 changes: 3 additions & 0 deletions include/mrdox/Metadata/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ struct FieldInfo
// attributes (maybe_unused, no_unique_address, deprecated)
FieldFlags specs;

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

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

explicit
Expand Down
5 changes: 5 additions & 0 deletions source/-XML/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ writeField(

writeSourceInfo(I);

if(I.IsMutable)
tags_.write(attributeTagName, {}, {
{"id", "is-mutable"}
});

write(I.specs, tags_);

writeType(I.Type, tags_);
Expand Down
2 changes: 2 additions & 0 deletions source/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,8 @@ buildField(
I.Type = buildTypeInfoForType(D->getType());
#endif

I.IsMutable = D->isMutable();

I.specs.hasNoUniqueAddress = D->hasAttr<NoUniqueAddressAttr>();
I.specs.isDeprecated = D->hasAttr<DeprecatedAttr>();
I.specs.isMaybeUnused = D->hasAttr<UnusedAttr>();
Expand Down
4 changes: 2 additions & 2 deletions source/AST/AnyBlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,12 +1247,12 @@ class FieldBlock
{
switch(ID)
{
case FIELD_NAME:
return decodeRecord(R, I->Name, Blob);
case FIELD_DEFAULT:
return decodeRecord(R, I->Default, Blob);
case FIELD_ATTRIBUTES:
return decodeRecord(R, {&I->specs.raw}, Blob);
case FIELD_IS_MUTABLE:
return decodeRecord(R, I->IsMutable, Blob);
default:
return TopLevelBlock::parseRecord(R, ID, Blob);
}
Expand Down
2 changes: 1 addition & 1 deletion source/AST/BitcodeIDs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ enum RecordID
BASE_IS_VIRTUAL,
FIELD_ATTRIBUTES,
FIELD_DEFAULT,
FIELD_NAME,
FIELD_IS_MUTABLE,
FUNCTION_BITS,
FUNCTION_PARAM_NAME,
FUNCTION_PARAM_DEFAULT,
Expand Down
6 changes: 3 additions & 3 deletions source/AST/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ RecordIDNameMap = []()
{ENUM_VALUE_NAME, {"Name", &StringAbbrev}},
{ENUM_VALUE_VALUE, {"Value", &StringAbbrev}},
{ENUM_VALUE_EXPR, {"Expr", &StringAbbrev}},
{FIELD_NAME, {"Name", &StringAbbrev}},
{FIELD_DEFAULT, {"DefaultValue", &StringAbbrev}},
{FIELD_ATTRIBUTES, {"FieldAttributes", &Integer32ArrayAbbrev}},
{FIELD_IS_MUTABLE, {"FieldIsMutable", &BoolAbbrev}},
{FUNCTION_BITS, {"Bits", &Integer32ArrayAbbrev}},
{FUNCTION_PARAM_NAME, {"Name", &StringAbbrev}},
{FUNCTION_PARAM_DEFAULT, {"Default", &StringAbbrev}},
Expand Down Expand Up @@ -322,7 +322,7 @@ RecordsByBlock{
{ENUM_VALUE_NAME, ENUM_VALUE_VALUE, ENUM_VALUE_EXPR}},
// FieldInfo
{BI_FIELD_BLOCK_ID,
{FIELD_NAME, FIELD_DEFAULT, FIELD_ATTRIBUTES}},
{FIELD_DEFAULT, FIELD_ATTRIBUTES, FIELD_IS_MUTABLE}},
// FunctionInfo
{BI_FUNCTION_BLOCK_ID,
{FUNCTION_BITS}},
Expand Down Expand Up @@ -790,9 +790,9 @@ emitBlock(
emitInfoPart(F);
emitSourceInfo(F, F);
emitBlock(F.Type);
emitRecord(F.Name, FIELD_NAME);
emitRecord(F.Default, FIELD_DEFAULT);
emitRecord({F.specs.raw}, FIELD_ATTRIBUTES);
emitRecord(F.IsMutable, FIELD_IS_MUTABLE);
}

void
Expand Down
1 change: 1 addition & 0 deletions source/Metadata/Reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ void merge(FieldInfo& I, FieldInfo&& Other)
mergeSourceInfo(I, std::move(Other));
mergeInfo(I, std::move(Other));
I.specs.raw.value |= Other.specs.raw.value;
I.IsMutable |= Other.IsMutable;
if(I.Default.empty())
I.Default = std::move(Other.Default);
}
Expand Down
12 changes: 12 additions & 0 deletions test-files/old-tests/record-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct T
{
int i;
double j;
mutable int k;
};

struct U
Expand All @@ -24,3 +25,14 @@ struct W
{
char buf[64];
};

template<typename P>
struct X
{
using Q = P;

int x0 = 0;
P x1;
const P x2[32];
Q x3;
};
49 changes: 41 additions & 8 deletions test-files/old-tests/record-data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,70 @@
<file path="record-data.cpp" line="6" class="def"/>
<type name="double"/>
</field>
<field name="k" id="DDn/yzxAAKSmBASeK+/IuU+FvzM=">
<file path="record-data.cpp" line="7" class="def"/>
<attr id="is-mutable"/>
<type name="int"/>
</field>
</struct>
<struct name="U" id="FLgkhM3m0U3Lo2o3XLPUizWPH00=">
<file path="record-data.cpp" line="9" class="def"/>
<file path="record-data.cpp" line="10" class="def"/>
<field name="t" id="LvEIBVXJYQQL4yraOaQv7ijMDng=">
<file path="record-data.cpp" line="11" class="def"/>
<file path="record-data.cpp" line="12" class="def"/>
<type class="tag" id="CgGNdHpW5mG/i5741WPYQDw28OQ=" name="T"/>
</field>
</struct>
<class name="V" id="9kzYwt0WPztMEDUaFxul1Jvqqs8=">
<file path="record-data.cpp" line="14" class="def"/>
<file path="record-data.cpp" line="15" class="def"/>
<field name="i" access="private" id="EWXCzRl9erjnMQFZ8VmHC5cVkLM=">
<file path="record-data.cpp" line="16" class="def"/>
<file path="record-data.cpp" line="17" class="def"/>
<type name="int"/>
</field>
<field name="j" access="protected" id="VKvx+Pci4bUmtjCsXJqKb7SNYqw=">
<file path="record-data.cpp" line="18" class="def"/>
<file path="record-data.cpp" line="19" class="def"/>
<type name="unsigned long"/>
</field>
<field name="k" access="private" id="iKr1oLycejUWY6AnSgoQnbmaCEE=">
<file path="record-data.cpp" line="20" class="def"/>
<file path="record-data.cpp" line="21" class="def"/>
<type name="double"/>
</field>
</class>
<struct name="W" id="6OhcFM3BV6KlrvmfpsljaMHxpdA=">
<file path="record-data.cpp" line="23" class="def"/>
<file path="record-data.cpp" line="24" class="def"/>
<field name="buf" id="2akJUSKKPN7IylZjqGMRlhXupds=">
<file path="record-data.cpp" line="25" class="def"/>
<file path="record-data.cpp" line="26" class="def"/>
<type class="array" bounds-value="64">
<element-type name="char"/>
</type>
</field>
</struct>
<template>
<tparam name="P" class="type"/>
<struct name="X" id="Zeeg2JUaOx6DlmptHhtEOTBqph8=">
<file path="record-data.cpp" line="30" class="def"/>
<alias name="Q" id="0ejZoZxNr1jbR7TmB6l+FL8J8sM=">
<file path="record-data.cpp" line="32" class="def"/>
<type name="P"/>
</alias>
<field name="x0" id="3/WSDyWN8Jo2uDqMI73W6O8PgZc=">
<file path="record-data.cpp" line="34" class="def"/>
<type name="int"/>
</field>
<field name="x1" id="rmZrg8Gl/RS4M9btLqQLTh2hIEY=">
<file path="record-data.cpp" line="35" class="def"/>
<type name="P"/>
</field>
<field name="x2" id="/8F/7HHyEkn08QLH9YBLyi9XC+g=">
<file path="record-data.cpp" line="36" class="def"/>
<type class="array" bounds-value="32">
<element-type name="P" cv-qualifiers="const"/>
</type>
</field>
<field name="x3" id="HbM0nu73RkZDGG6emSsnJEt+chI=">
<file path="record-data.cpp" line="37" class="def"/>
<type class="tag" id="0ejZoZxNr1jbR7TmB6l+FL8J8sM=" name="Q"/>
</field>
</struct>
</template>
</namespace>
</mrdox>

0 comments on commit 9798204

Please sign in to comment.