Skip to content

Commit 0df49fe

Browse files
committed
reimplement ADT/Polymorphic
This is a simpler design, with less differences in API wrt to std::polymorphic, though still with some differences, includinding nullability, and some unused features which are not important to us are left out. This avoids memory leaks facilitated by the previous design, and is a step towards making the project pass the LeakSanitizer.
1 parent f2ebf09 commit 0df49fe

31 files changed

+704
-1845
lines changed

include/mrdocs/ADT/Polymorphic.hpp

Lines changed: 132 additions & 809 deletions
Large diffs are not rendered by default.

include/mrdocs/ADT/detail/Polymorphic.hpp

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

include/mrdocs/Corpus.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ class MRDOCS_VISIBLE
259259
{
260260
return std::is_lt(cmp);
261261
}
262-
return std::is_lt(CompareDerived(lhsInfo, rhsInfo));
262+
return std::is_lt(
263+
CompareDerived(Polymorphic<Info>(lhsInfo),
264+
Polymorphic<Info>(rhsInfo)));
263265
});
264266
if (!opts.skipInherited)
265267
{

include/mrdocs/Metadata/Info/Enum.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct EnumInfo final
2929
// Set too nonempty to the type when this is an explicitly typed enum. For
3030
// enum Foo : short { ... };
3131
// this will be "short".
32-
Polymorphic<TypeInfo> UnderlyingType;
32+
Polymorphic<TypeInfo> UnderlyingType = std::nullopt;
3333

3434
/** The members of this scope.
3535

include/mrdocs/Metadata/Info/Friend.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct FriendInfo final
3131

3232
/** Befriended type.
3333
*/
34-
Polymorphic<TypeInfo> Type;
34+
Polymorphic<TypeInfo> Type = std::nullopt;
3535
};
3636

3737
MRDOCS_DECL

include/mrdocs/Metadata/Info/Function.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct Param final
109109
{
110110
/** The type of this parameter
111111
*/
112-
Polymorphic<TypeInfo> Type;
112+
Polymorphic<TypeInfo> Type = std::nullopt;
113113

114114
/** The parameter name.
115115
*/
@@ -154,7 +154,7 @@ struct FunctionInfo final
154154
: InfoCommonBase<InfoKind::Function>
155155
{
156156
/// Info about the return type of this function.
157-
Polymorphic<TypeInfo> ReturnType;
157+
Polymorphic<TypeInfo> ReturnType = std::nullopt;
158158

159159
/// List of parameters.
160160
std::vector<Param> Params;

include/mrdocs/Metadata/Info/Guide.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct GuideInfo final
3131
3232
This is always a SpecializationTypeInfo.
3333
*/
34-
Polymorphic<TypeInfo> Deduced;
34+
Polymorphic<TypeInfo> Deduced = std::nullopt;
3535

3636
/** Template head, if any.
3737
*/

include/mrdocs/Metadata/Info/Overloads.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct OverloadsInfo final
3232
std::vector<SymbolID> Members;
3333

3434
/// Info about the return type of this function.
35-
Polymorphic<TypeInfo> ReturnType;
35+
Polymorphic<TypeInfo> ReturnType = std::nullopt;
3636

3737
//--------------------------------------------
3838

include/mrdocs/Metadata/Info/Typedef.hpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,29 @@ namespace clang::mrdocs {
2525
struct TypedefInfo final
2626
: InfoCommonBase<InfoKind::Typedef>
2727
{
28-
Polymorphic<TypeInfo> Type;
28+
Polymorphic<TypeInfo> Type = std::nullopt;
2929

30-
/** Indicates if this is a new C++ "using"-style typedef
30+
/** Indicates if this is a new C++ "using"-style typedef
3131
32-
@code
33-
using MyVector = std::vector<int>
34-
@endcode
32+
@code
33+
using MyVector = std::vector<int>
34+
@endcode
3535
36-
False means it's a C-style typedef:
36+
False means it's a C-style typedef:
3737
38-
@code
39-
typedef std::vector<int> MyVector;
40-
@endcode
41-
*/
42-
bool IsUsing = false;
38+
@code
39+
typedef std::vector<int> MyVector;
40+
@endcode
41+
*/
42+
bool IsUsing = false;
4343

44-
std::optional<TemplateInfo> Template;
44+
std::optional<TemplateInfo> Template;
4545

46-
//--------------------------------------------
46+
//--------------------------------------------
4747

48-
explicit TypedefInfo(SymbolID ID) noexcept
49-
: InfoCommonBase(ID)
50-
{
51-
}
52-
53-
std::strong_ordering
54-
operator<=>(TypedefInfo const& other) const;
48+
explicit TypedefInfo(SymbolID ID) noexcept : InfoCommonBase(ID) {}
5549

50+
std::strong_ordering operator<=>(TypedefInfo const &other) const;
5651
};
5752

5853
MRDOCS_DECL

include/mrdocs/Metadata/Info/Variable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct VariableInfo final
3131
: InfoCommonBase<InfoKind::Variable>
3232
{
3333
/** The type of the variable */
34-
Polymorphic<TypeInfo> Type;
34+
Polymorphic<TypeInfo> Type = std::nullopt;
3535

3636
std::optional<TemplateInfo> Template;
3737

0 commit comments

Comments
 (0)