Skip to content

Commit aa9b4c2

Browse files
attributes on data members are supported.
1 parent 49dda57 commit aa9b4c2

File tree

12 files changed

+111
-26
lines changed

12 files changed

+111
-26
lines changed

include/mrdox/Metadata/FieldType.hpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@
1414

1515
#include <mrdox/Platform.hpp>
1616
#include <mrdox/Metadata/Type.hpp>
17+
#include <mrdox/Metadata/BitField.hpp>
1718
#include <llvm/ADT/SmallString.h>
1819
#include <utility>
1920

2021
namespace clang {
2122
namespace mrdox {
2223

24+
union FieldFlags
25+
{
26+
BitFieldFullValue raw{.value=0u};
27+
28+
BitFlag<0> isNodiscard;
29+
BitFlag<1> isDeprecated;
30+
BitFlag<2> hasNoUniqueAddress;
31+
};
32+
2333
// Info for field types.
2434
struct FieldTypeInfo
2535
: public TypeInfo
@@ -31,31 +41,23 @@ struct FieldTypeInfo
3141
// or the variable initializer if any.
3242
llvm::SmallString<16> DefaultValue;
3343

44+
// attributes (nodiscard, no_unique_address, deprecated)
45+
FieldFlags Flags;
3446
//--------------------------------------------
3547

3648
FieldTypeInfo() = default;
3749

3850
FieldTypeInfo(
39-
TypeInfo const& TI,
40-
llvm::StringRef Name = llvm::StringRef(),
41-
llvm::StringRef DefaultValue = llvm::StringRef())
51+
TypeInfo const& TI,
52+
llvm::StringRef Name = llvm::StringRef(),
53+
llvm::StringRef DefaultValue = llvm::StringRef(),
54+
FieldFlags Flags = {})
4255
: TypeInfo(TI)
4356
, Name(Name)
4457
, DefaultValue(DefaultValue)
58+
, Flags(Flags)
4559
{
4660
}
47-
48-
#if 0
49-
// VFALCO What was this for?
50-
bool
51-
operator==(
52-
FieldTypeInfo const& Other) const
53-
{
54-
return
55-
std::tie(Type, Name, DefaultValue) ==
56-
std::tie(Other.Type, Other.Name, Other.DefaultValue);
57-
}
58-
#endif
5961
};
6062

6163
} // mrdox

mrdox.rnc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ grammar
7373
attribute type { text },
7474
attribute value { text } ?,
7575
Access,
76-
ID ?
76+
ID ?,
77+
Attr *
7778
}
7879

7980
#---------------------------------------------

mrdox.rng

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
<optional>
9797
<ref name="ID"/>
9898
</optional>
99+
<zeroOrMore>
100+
<ref name="Attr"/>
101+
</zeroOrMore>
99102
</element>
100103
</define>
101104
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

source/api/AST/ASTVisitor.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,27 @@ getMemberTypeInfo(
334334
{
335335
Assert(D && "Expect non-null FieldDecl in getMemberTypeInfo");
336336
parseJavadoc(I.javadoc, D);
337+
338+
for (auto attr : D->attrs())
339+
{
340+
switch (attr->getKind())
341+
{
342+
case clang::attr::Kind::NoUniqueAddress:
343+
I.Flags.hasNoUniqueAddress = true;
344+
break;
345+
case clang::attr::Kind::Deprecated:
346+
I.Flags.isDeprecated = true;
347+
break;
348+
case clang::attr::Kind::Unused:
349+
I.Flags.isNodiscard = true;
350+
break;
351+
default:
352+
break;
353+
}
354+
}
337355
}
338356

357+
339358
//------------------------------------------------
340359

341360
template<class Parent, class Child>

source/api/AST/AnyBlock.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ class FieldTypeBlock
464464
return decodeRecord(R, I_.Name, Blob);
465465
case FIELD_DEFAULT_VALUE:
466466
return decodeRecord(R, I_.DefaultValue, Blob);
467+
case FIELD_ATTRIBUTES:
468+
return decodeRecord(R, {&I_.Flags.raw}, Blob);
467469
default:
468470
return AnyBlock::parseRecord(R, ID, Blob);
469471
}
@@ -538,6 +540,11 @@ class MemberTypeBlock
538540
I_.Type = std::move(B.I);
539541
return llvm::Error::success();
540542
}
543+
case BI_FIELD_TYPE_BLOCK_ID:
544+
{
545+
FieldTypeBlock B(I_, br_);
546+
return br_.readBlock(B, ID);
547+
}
541548
case BI_JAVADOC_BLOCK_ID:
542549
{
543550
JavadocBlock B(I_.javadoc, br_);

source/api/AST/BitcodeIDs.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ enum RecordId
9999
JAVADOC_NODE_ADMONISH,
100100
FIELD_TYPE_NAME,
101101
FIELD_DEFAULT_VALUE,
102+
FIELD_ATTRIBUTES,
102103
MEMBER_TYPE_NAME,
103104
MEMBER_TYPE_ACCESS,
104105
ENUM_SCOPED,

source/api/AST/BitcodeWriter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ RecordIdNameMap = []()
247247
{JAVADOC_NODE_ADMONISH, {"JavadocNodeAdmonish", &Integer32Abbrev}},
248248
{FIELD_TYPE_NAME, {"Name", &StringAbbrev}},
249249
{FIELD_DEFAULT_VALUE, {"DefaultValue", &StringAbbrev}},
250+
{FIELD_ATTRIBUTES, {"FieldAttributes", &Integer32ArrayAbbrev}},
250251
{MEMBER_TYPE_NAME, {"Name", &StringAbbrev}},
251252
{MEMBER_TYPE_ACCESS, {"Access", &Integer32Abbrev}},
252253
{ENUM_SCOPED, {"Scoped", &BoolAbbrev}},
@@ -302,7 +303,7 @@ RecordsByBlock{
302303
{BI_ENUM_VALUE_BLOCK_ID,
303304
{ENUM_VALUE_NAME, ENUM_VALUE_VALUE, ENUM_VALUE_EXPR}},
304305
// FieldTypeInfo
305-
{BI_FIELD_TYPE_BLOCK_ID, {FIELD_TYPE_NAME, FIELD_DEFAULT_VALUE}},
306+
{BI_FIELD_TYPE_BLOCK_ID, {FIELD_TYPE_NAME, FIELD_DEFAULT_VALUE, FIELD_ATTRIBUTES}},
306307
// FunctionInfo
307308
{BI_FUNCTION_BLOCK_ID,
308309
{FUNCTION_ACCESS, FUNCTION_IS_METHOD, FUNCTION_BITS}},
@@ -760,6 +761,7 @@ emitBlock(
760761
emitBlock(T.Type, FieldId::F_type);
761762
emitRecord(T.Name, FIELD_TYPE_NAME);
762763
emitRecord(T.DefaultValue, FIELD_DEFAULT_VALUE);
764+
emitRecord({T.Flags.raw}, FIELD_ATTRIBUTES);
763765
}
764766

765767
void
@@ -871,7 +873,8 @@ emitBlock(
871873
MemberTypeInfo const& T)
872874
{
873875
StreamSubBlockGuard Block(Stream, BI_MEMBER_TYPE_BLOCK_ID);
874-
emitBlock(T.Type, FieldId::F_type);
876+
// emitBlock(T.Type, FieldId::F_type);
877+
emitBlock(static_cast<const FieldTypeInfo &>(T));
875878
emitRecord(T.Name, MEMBER_TYPE_NAME);
876879
emitRecord(T.Access, MEMBER_TYPE_ACCESS);
877880
if(T.javadoc)

source/api/_XML/CXXTags.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ inline void write(FnFlags1 const& bits, XMLTags& tags)
214214
fw.write(&FnFlags1::isExplicit, "is-explicit");
215215
}
216216

217+
218+
inline void write(FieldFlags const& bits, XMLTags& tags)
219+
{
220+
BitFieldWriter<FieldFlags> fw(bits, tags);
221+
222+
fw.write(&FieldFlags::isNodiscard, "nodiscard");
223+
fw.write(&FieldFlags::isDeprecated, "deprecated");
224+
fw.write(&FieldFlags::hasNoUniqueAddress, "no-unique-address");
225+
}
226+
227+
217228
inline void write(VarFlags0 const& bits, XMLTags& tags)
218229
{
219230
BitFieldWriter<VarFlags0> fw(bits, tags);

source/api/_XML/XMLWriter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,15 @@ XMLWriter::
434434
writeMemberType(
435435
MemberTypeInfo const& I)
436436
{
437-
tags_.write(dataMemberTagName, {}, {
437+
tags_.open(dataMemberTagName, {
438438
{ "name", I.Name },
439439
{ "type", I.Type.Name },
440440
{ "value", I.DefaultValue, ! I.DefaultValue.empty() },
441441
{ I.Access },
442442
{ I.Type.id } });
443+
444+
write(I.Flags, tags_);
445+
tags_.close("data");
443446
}
444447

445448
//------------------------------------------------
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// data members
2+
3+
struct Empty {};
4+
5+
struct T
6+
{
7+
int i;
8+
[[/*no_unique_address, */deprecated, maybe_unused]] Empty e = Empty{};
9+
};
10+
// https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/

0 commit comments

Comments
 (0)