Skip to content

Commit d308d29

Browse files
committed
non-static data members have SymbolIDs and are part of RecordScope
1 parent 55c1a94 commit d308d29

37 files changed

+427
-509
lines changed

include/mrdox/Corpus.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@ class MRDOX_VISIBLE
107107
MRDOX_DECL virtual bool visit(TypedefInfo const&);
108108
MRDOX_DECL virtual bool visit(EnumInfo const&);
109109
MRDOX_DECL virtual bool visit(VarInfo const&);
110+
// KRYSTIAN FIXME: is this correct? does it make sense to
111+
// visit a field as a non-member (a field *must* be class member)?
112+
MRDOX_DECL virtual bool visit(FieldInfo const&);
110113

111-
MRDOX_DECL virtual bool visit(DataMember const&, Access);
112114
MRDOX_DECL virtual bool visit(MemberEnum const&, Access);
113115
MRDOX_DECL virtual bool visit(MemberFunction const&, Access);
114116
MRDOX_DECL virtual bool visit(MemberRecord const&, Access);
115117
MRDOX_DECL virtual bool visit(MemberType const&, Access);
118+
MRDOX_DECL virtual bool visit(DataMember const&, Access);
116119
MRDOX_DECL virtual bool visit(StaticDataMember const&, Access);
117120
};
118121

@@ -169,6 +172,8 @@ get(
169172
assert(t->IT == InfoType::IT_enum);
170173
else if constexpr(std::is_same_v<T, VarInfo>)
171174
assert(t->IT == InfoType::IT_variable);
175+
else if constexpr(std::is_same_v<T, FieldInfo>)
176+
assert(t->IT == InfoType::IT_field);
172177
return *t;
173178
}
174179

include/mrdox/Metadata.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
// metadata extracted from AST
1919

2020
#include <mrdox/Metadata/Enum.hpp>
21-
#include <mrdox/Metadata/FieldType.hpp>
21+
#include <mrdox/Metadata/Field.hpp>
2222
#include <mrdox/Metadata/Function.hpp>
2323
#include <mrdox/Metadata/Info.hpp>
2424
#include <mrdox/Metadata/Interface.hpp>
2525
#include <mrdox/Metadata/Javadoc.hpp>
2626
#include <mrdox/Metadata/Location.hpp>
27-
#include <mrdox/Metadata/MemberType.hpp>
2827
#include <mrdox/Metadata/Namespace.hpp>
2928
#include <mrdox/Metadata/Overloads.hpp>
3029
#include <mrdox/Metadata/Record.hpp>

include/mrdox/Metadata/Access.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ enum class Access
3535
Private
3636
};
3737

38-
/** A reference to a symbol, and an access speciier.
38+
/** A reference to a symbol, and an access specifier.
3939
4040
This is used in records to refer to nested
4141
elements with access control.

include/mrdox/Metadata/Enum.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace clang {
2525
namespace mrdox {
2626

27+
// FIXME: this does not store javadocs...
2728
// Information for a single possible value of an enumeration.
2829
struct EnumValueInfo
2930
{
@@ -66,7 +67,8 @@ struct EnumValueInfo
6667

6768
// TODO: Expand to allow for documenting templating.
6869
// Info for types.
69-
struct EnumInfo : SymbolInfo
70+
struct EnumInfo
71+
: SymbolInfo
7072
{
7173
// Indicates whether this enum is scoped (e.g. enum class).
7274
bool Scoped = false;
@@ -82,15 +84,10 @@ struct EnumInfo : SymbolInfo
8284

8385
static constexpr InfoType type_id = InfoType::IT_enum;
8486

85-
EnumInfo()
86-
: SymbolInfo(InfoType::IT_enum)
87-
{
88-
}
89-
9087
explicit
9188
EnumInfo(
92-
SymbolID id_)
93-
: SymbolInfo(InfoType::IT_enum, id_)
89+
SymbolID id = SymbolID::zero)
90+
: SymbolInfo(InfoType::IT_enum, id)
9491
{
9592
}
9693
};

include/mrdox/Metadata/FieldType.hpp renamed to include/mrdox/Metadata/Field.hpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
// Copyright (c) 2023 Vinnie Falco ([email protected])
8+
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
89
//
910
// Official repository: https://github.com/cppalliance/mrdox
1011
//
1112

12-
#ifndef MRDOX_METADATA_FIELDTYPE_HPP
13-
#define MRDOX_METADATA_FIELDTYPE_HPP
13+
#ifndef MRDOX_METADATA_FIELD_HPP
14+
#define MRDOX_METADATA_FIELD_HPP
1415

1516
#include <mrdox/Platform.hpp>
17+
#include <mrdox/Metadata/Info.hpp>
18+
#include <mrdox/Metadata/Symbol.hpp>
1619
#include <mrdox/Metadata/Type.hpp>
1720
#include <mrdox/ADT/BitField.hpp>
1821
#include <llvm/ADT/SmallString.h>
@@ -25,37 +28,41 @@ union FieldFlags
2528
{
2629
BitFieldFullValue raw{.value=0u};
2730

31+
// KRYSTIAN FIXME: nodiscard cannot be applied to fields; this should
32+
// instead be isMaybeUnused. we should also store the spelling
2833
BitFlag<0> isNodiscard;
2934
BitFlag<1> isDeprecated;
3035
BitFlag<2> hasNoUniqueAddress;
3136
};
3237

33-
// Info for field types.
38+
/** Info for fields (i.e. non-static data members)
39+
40+
Non-static data members cannot be redeclared.
41+
*/
3442
struct FieldInfo
35-
: public TypeInfo
43+
: SymbolInfo
3644
{
37-
llvm::SmallString<16> Name; // Name associated with this info.
45+
/** Type of the field */
46+
TypeInfo Type;
47+
48+
// std::string Name; // Name associated with this info.
3849

3950
// When used for function parameters or variables,
4051
// contains the string representing the expression of the default value,
4152
// or the variable initializer if any.
42-
llvm::SmallString<16> DefaultValue;
53+
std::string Default;
4354

4455
// attributes (nodiscard, no_unique_address, deprecated)
45-
FieldFlags Flags;
56+
FieldFlags specs;
57+
4658
//--------------------------------------------
4759

48-
FieldInfo() = default;
60+
static constexpr InfoType type_id = InfoType::IT_field;
4961

5062
FieldInfo(
51-
TypeInfo const& TI,
52-
llvm::StringRef Name = llvm::StringRef(),
53-
llvm::StringRef DefaultValue = llvm::StringRef(),
54-
FieldFlags Flags = {})
55-
: TypeInfo(TI)
56-
, Name(Name)
57-
, DefaultValue(DefaultValue)
58-
, Flags(Flags)
63+
SymbolID ID = SymbolID::zero,
64+
llvm::StringRef Name = llvm::StringRef())
65+
: SymbolInfo(InfoType::IT_field, ID, Name)
5966
{
6067
}
6168
};

include/mrdox/Metadata/Function.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
// Copyright (c) 2023 Vinnie Falco ([email protected])
8+
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
89
//
910
// Official repository: https://github.com/cppalliance/mrdox
1011
//
@@ -14,7 +15,7 @@
1415

1516
#include <mrdox/Platform.hpp>
1617
#include <mrdox/ADT/BitField.hpp>
17-
#include <mrdox/Metadata/FieldType.hpp>
18+
#include <mrdox/Metadata/Field.hpp>
1819
#include <mrdox/Metadata/Function.hpp>
1920
#include <mrdox/Metadata/FunctionKind.hpp>
2021
#include <mrdox/Metadata/Symbol.hpp>
@@ -79,7 +80,10 @@ struct Param
7980
/** The type of this parameter */
8081
TypeInfo Type;
8182

82-
/** The name of this parameter, if any */
83+
/** The parameter name.
84+
85+
Unnamed parameters are represented by empty strings.
86+
*/
8387
std::string Name;
8488

8589
/** The default argument for this parameter, if any */
@@ -100,7 +104,8 @@ struct Param
100104

101105
// TODO: Expand to allow for documenting templating and default args.
102106
// Info for functions.
103-
struct FunctionInfo : SymbolInfo
107+
struct FunctionInfo
108+
: SymbolInfo
104109
{
105110
TypeInfo ReturnType; // Info about the return type of this function.
106111
std::vector<Param> Params; // List of parameters.
@@ -117,7 +122,7 @@ struct FunctionInfo : SymbolInfo
117122

118123
explicit
119124
FunctionInfo(
120-
SymbolID id_ = SymbolID())
125+
SymbolID id_ = SymbolID::zero)
121126
: SymbolInfo(InfoType::IT_function, id_)
122127
{
123128
}

include/mrdox/Metadata/Info.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct Info
3232
{
3333
/** The unique identifier for this symbol.
3434
*/
35-
SymbolID id = SymbolID();
35+
SymbolID id = SymbolID::zero;
3636

3737
/** Kind of declaration.
3838
*/
@@ -59,7 +59,7 @@ struct Info
5959
explicit
6060
Info(
6161
InfoType IT = InfoType::IT_default,
62-
SymbolID id_ = SymbolID(),
62+
SymbolID id_ = SymbolID::zero,
6363
llvm::StringRef Name = llvm::StringRef())
6464
: id(id_)
6565
, IT(IT)

include/mrdox/Metadata/MemberType.hpp

Lines changed: 0 additions & 64 deletions
This file was deleted.

include/mrdox/Metadata/Members.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
// Copyright (c) 2023 Vinnie Falco ([email protected])
8+
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
89
//
910
// Official repository: https://github.com/cppalliance/mrdox
1011
//
@@ -15,8 +16,8 @@
1516
#include <mrdox/Platform.hpp>
1617
#include <mrdox/Metadata/Access.hpp>
1718
#include <mrdox/Metadata/Enum.hpp>
19+
#include <mrdox/Metadata/Field.hpp>
1820
#include <mrdox/Metadata/Function.hpp>
19-
#include <mrdox/Metadata/MemberType.hpp>
2021
#include <mrdox/Metadata/Record.hpp>
2122
#include <mrdox/Metadata/Typedef.hpp>
2223
#include <mrdox/Metadata/Var.hpp>
@@ -26,8 +27,7 @@ namespace mrdox {
2627

2728
struct DataMember
2829
{
29-
// FieldInfo const* I;
30-
MemberTypeInfo const* I;
30+
FieldInfo const* I;
3131
RecordInfo const* From;
3232
};
3333

include/mrdox/Metadata/Record.hpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <mrdox/Platform.hpp>
1616
#include <mrdox/Metadata/Access.hpp>
1717
#include <mrdox/ADT/BitField.hpp>
18-
#include <mrdox/Metadata/MemberType.hpp>
18+
#include <mrdox/Metadata/Field.hpp>
1919
#include <mrdox/Metadata/Reference.hpp>
2020
#include <mrdox/Metadata/Scope.hpp>
2121
#include <mrdox/Metadata/Symbol.hpp>
@@ -63,20 +63,22 @@ struct BaseInfo
6363
}
6464
};
6565

66-
/** Children of a class, struct, or union.
66+
/** Members of a class, struct, or union.
6767
*/
6868
struct RecordScope
6969
{
7070
std::vector<MemberRef> Records;
7171
std::vector<MemberRef> Functions;
7272
std::vector<MemberRef> Enums;
7373
std::vector<MemberRef> Types;
74+
std::vector<MemberRef> Fields;
7475
std::vector<MemberRef> Vars;
7576
};
7677

7778
/** Metadata for struct, class, or union.
7879
*/
79-
struct RecordInfo : SymbolInfo
80+
struct RecordInfo
81+
: SymbolInfo
8082
{
8183
// VFALCO Use our own enumeration for this
8284
// Type of this record (struct, class, union, interface).
@@ -89,12 +91,11 @@ struct RecordInfo : SymbolInfo
8991
// structs in a typedef:
9092
// typedef struct { ... } foo_t;
9193
// are converted into records with the typedef as the Name + this flag set.
94+
// KRYSTIAN FIXME: this does not account for alias-declarations
9295
bool IsTypeDef = false;
9396

9497
RecFlags0 specs;
9598

96-
llvm::SmallVector<MemberTypeInfo, 4> Members; // List of info about record members.
97-
9899
/** List of immediate bases.
99100
*/
100101
std::vector<BaseInfo> Bases;
@@ -103,15 +104,17 @@ struct RecordInfo : SymbolInfo
103104
*/
104105
llvm::SmallVector<SymbolID, 4> Friends;
105106

106-
RecordScope Children_;
107+
/** Record members
108+
*/
109+
RecordScope Members;
107110

108111
//--------------------------------------------
109112

110113
static constexpr InfoType type_id = InfoType::IT_record;
111114

112115
explicit
113116
RecordInfo(
114-
SymbolID id = SymbolID(),
117+
SymbolID id = SymbolID::zero,
115118
llvm::StringRef Name = llvm::StringRef())
116119
: SymbolInfo(InfoType::IT_record, id, Name)
117120
{

0 commit comments

Comments
 (0)