From 9798204cc11b1d405d051d71abd5e69919b2d18b Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Thu, 29 Jun 2023 13:27:08 -0400 Subject: [PATCH] feat: add IsMutable for FieldInfo closes #177 --- include/mrdox/Metadata/Field.hpp | 3 ++ source/-XML/XMLWriter.cpp | 5 +++ source/AST/ASTVisitor.cpp | 2 ++ source/AST/AnyBlock.hpp | 4 +-- source/AST/BitcodeIDs.hpp | 2 +- source/AST/BitcodeWriter.cpp | 6 ++-- source/Metadata/Reduce.cpp | 1 + test-files/old-tests/record-data.cpp | 12 +++++++ test-files/old-tests/record-data.xml | 49 +++++++++++++++++++++++----- 9 files changed, 70 insertions(+), 14 deletions(-) diff --git a/include/mrdox/Metadata/Field.hpp b/include/mrdox/Metadata/Field.hpp index d9277b977..e8bc3d5e4 100644 --- a/include/mrdox/Metadata/Field.hpp +++ b/include/mrdox/Metadata/Field.hpp @@ -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 diff --git a/source/-XML/XMLWriter.cpp b/source/-XML/XMLWriter.cpp index 415fefa00..af1b2242c 100644 --- a/source/-XML/XMLWriter.cpp +++ b/source/-XML/XMLWriter.cpp @@ -386,6 +386,11 @@ writeField( writeSourceInfo(I); + if(I.IsMutable) + tags_.write(attributeTagName, {}, { + {"id", "is-mutable"} + }); + write(I.specs, tags_); writeType(I.Type, tags_); diff --git a/source/AST/ASTVisitor.cpp b/source/AST/ASTVisitor.cpp index 8ba8ab03f..1d80ec52d 100644 --- a/source/AST/ASTVisitor.cpp +++ b/source/AST/ASTVisitor.cpp @@ -1275,6 +1275,8 @@ buildField( I.Type = buildTypeInfoForType(D->getType()); #endif + I.IsMutable = D->isMutable(); + I.specs.hasNoUniqueAddress = D->hasAttr(); I.specs.isDeprecated = D->hasAttr(); I.specs.isMaybeUnused = D->hasAttr(); diff --git a/source/AST/AnyBlock.hpp b/source/AST/AnyBlock.hpp index abe1ec424..0991afa89 100644 --- a/source/AST/AnyBlock.hpp +++ b/source/AST/AnyBlock.hpp @@ -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); } diff --git a/source/AST/BitcodeIDs.hpp b/source/AST/BitcodeIDs.hpp index b60bd9ddc..87103f99e 100644 --- a/source/AST/BitcodeIDs.hpp +++ b/source/AST/BitcodeIDs.hpp @@ -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, diff --git a/source/AST/BitcodeWriter.cpp b/source/AST/BitcodeWriter.cpp index 23b4dfdd6..ee1986ead 100644 --- a/source/AST/BitcodeWriter.cpp +++ b/source/AST/BitcodeWriter.cpp @@ -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}}, @@ -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}}, @@ -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 diff --git a/source/Metadata/Reduce.cpp b/source/Metadata/Reduce.cpp index f80c4f568..1289cbde6 100644 --- a/source/Metadata/Reduce.cpp +++ b/source/Metadata/Reduce.cpp @@ -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); } diff --git a/test-files/old-tests/record-data.cpp b/test-files/old-tests/record-data.cpp index e19bd5503..eb1e6aa0a 100644 --- a/test-files/old-tests/record-data.cpp +++ b/test-files/old-tests/record-data.cpp @@ -4,6 +4,7 @@ struct T { int i; double j; + mutable int k; }; struct U @@ -24,3 +25,14 @@ struct W { char buf[64]; }; + +template +struct X +{ + using Q = P; + + int x0 = 0; + P x1; + const P x2[32]; + Q x3; +}; diff --git a/test-files/old-tests/record-data.xml b/test-files/old-tests/record-data.xml index 3795456d2..e1f544de3 100644 --- a/test-files/old-tests/record-data.xml +++ b/test-files/old-tests/record-data.xml @@ -12,37 +12,70 @@ + + + + + - + - + - + - + - + - + - + - + +