Skip to content

Commit

Permalink
feat: add IsMutable for FieldInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Jun 29, 2023
1 parent 33d5505 commit 71b3bc4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 6 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
6 changes: 6 additions & 0 deletions source/-XML/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ writeField(

writeSourceInfo(I);

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

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

0 comments on commit 71b3bc4

Please sign in to comment.