Skip to content

Commit 71b3bc4

Browse files
committed
feat: add IsMutable for FieldInfo
closes cppalliance#177
1 parent 33d5505 commit 71b3bc4

File tree

7 files changed

+18
-6
lines changed

7 files changed

+18
-6
lines changed

include/mrdox/Metadata/Field.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ struct FieldInfo
5252
// attributes (maybe_unused, no_unique_address, deprecated)
5353
FieldFlags specs;
5454

55+
/** Whether the field is declared mutable */
56+
bool IsMutable = false;
57+
5558
//--------------------------------------------
5659

5760
explicit

source/-XML/XMLWriter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,12 @@ writeField(
438438

439439
writeSourceInfo(I);
440440

441+
if(I.IsMutable)
442+
tags_.write(attributeTagName, {}, {
443+
{"name", "is-mutable"},
444+
{"value", "1"}
445+
});
446+
441447
write(I.specs, tags_);
442448

443449
writeType(I.Type, tags_);

source/AST/ASTVisitor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,8 @@ buildField(
12751275
I.Type = buildTypeInfoForType(D->getType());
12761276
#endif
12771277

1278+
I.IsMutable = D->isMutable();
1279+
12781280
I.specs.hasNoUniqueAddress = D->hasAttr<NoUniqueAddressAttr>();
12791281
I.specs.isDeprecated = D->hasAttr<DeprecatedAttr>();
12801282
I.specs.isMaybeUnused = D->hasAttr<UnusedAttr>();

source/AST/AnyBlock.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,12 +1247,12 @@ class FieldBlock
12471247
{
12481248
switch(ID)
12491249
{
1250-
case FIELD_NAME:
1251-
return decodeRecord(R, I->Name, Blob);
12521250
case FIELD_DEFAULT:
12531251
return decodeRecord(R, I->Default, Blob);
12541252
case FIELD_ATTRIBUTES:
12551253
return decodeRecord(R, {&I->specs.raw}, Blob);
1254+
case FIELD_IS_MUTABLE:
1255+
return decodeRecord(R, I->IsMutable, Blob);
12561256
default:
12571257
return TopLevelBlock::parseRecord(R, ID, Blob);
12581258
}

source/AST/BitcodeIDs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ enum RecordID
104104
BASE_IS_VIRTUAL,
105105
FIELD_ATTRIBUTES,
106106
FIELD_DEFAULT,
107-
FIELD_NAME,
107+
FIELD_IS_MUTABLE,
108108
FUNCTION_BITS,
109109
FUNCTION_PARAM_NAME,
110110
FUNCTION_PARAM_DEFAULT,

source/AST/BitcodeWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ RecordIDNameMap = []()
242242
{ENUM_VALUE_NAME, {"Name", &StringAbbrev}},
243243
{ENUM_VALUE_VALUE, {"Value", &StringAbbrev}},
244244
{ENUM_VALUE_EXPR, {"Expr", &StringAbbrev}},
245-
{FIELD_NAME, {"Name", &StringAbbrev}},
246245
{FIELD_DEFAULT, {"DefaultValue", &StringAbbrev}},
247246
{FIELD_ATTRIBUTES, {"FieldAttributes", &Integer32ArrayAbbrev}},
247+
{FIELD_IS_MUTABLE, {"FieldIsMutable", &BoolAbbrev}},
248248
{FUNCTION_BITS, {"Bits", &Integer32ArrayAbbrev}},
249249
{FUNCTION_PARAM_NAME, {"Name", &StringAbbrev}},
250250
{FUNCTION_PARAM_DEFAULT, {"Default", &StringAbbrev}},
@@ -322,7 +322,7 @@ RecordsByBlock{
322322
{ENUM_VALUE_NAME, ENUM_VALUE_VALUE, ENUM_VALUE_EXPR}},
323323
// FieldInfo
324324
{BI_FIELD_BLOCK_ID,
325-
{FIELD_NAME, FIELD_DEFAULT, FIELD_ATTRIBUTES}},
325+
{FIELD_DEFAULT, FIELD_ATTRIBUTES, FIELD_IS_MUTABLE}},
326326
// FunctionInfo
327327
{BI_FUNCTION_BLOCK_ID,
328328
{FUNCTION_BITS}},
@@ -790,9 +790,9 @@ emitBlock(
790790
emitInfoPart(F);
791791
emitSourceInfo(F, F);
792792
emitBlock(F.Type);
793-
emitRecord(F.Name, FIELD_NAME);
794793
emitRecord(F.Default, FIELD_DEFAULT);
795794
emitRecord({F.specs.raw}, FIELD_ATTRIBUTES);
795+
emitRecord(F.IsMutable, FIELD_IS_MUTABLE);
796796
}
797797

798798
void

source/Metadata/Reduce.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ void merge(FieldInfo& I, FieldInfo&& Other)
218218
mergeSourceInfo(I, std::move(Other));
219219
mergeInfo(I, std::move(Other));
220220
I.specs.raw.value |= Other.specs.raw.value;
221+
I.IsMutable |= Other.IsMutable;
221222
if(I.Default.empty())
222223
I.Default = std::move(Other.Default);
223224
}

0 commit comments

Comments
 (0)