Skip to content

Commit b4fec4f

Browse files
committed
sort-members option
#feat
1 parent f1cdecc commit b4fec4f

File tree

147 files changed

+11380
-7066
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+11380
-7066
lines changed

docs/mrdocs.schema.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,66 @@
297297
"title": "Detect and reduce SFINAE expressions",
298298
"type": "boolean"
299299
},
300+
"sort-members": {
301+
"default": true,
302+
"description": "When set to `true`, sort the members of a record or namespace by name and parameters. When set to `false`, the members are included in the declaration order they are extracted.",
303+
"enum": [
304+
true,
305+
false
306+
],
307+
"title": "Sort the members of a record or namespace",
308+
"type": "boolean"
309+
},
310+
"sort-members-assignment-1st": {
311+
"default": true,
312+
"description": "When set to `true`, assignment operators are sorted first in the list of members of a record.",
313+
"enum": [
314+
true,
315+
false
316+
],
317+
"title": "Sort assignment operators first",
318+
"type": "boolean"
319+
},
320+
"sort-members-conversion-last": {
321+
"default": true,
322+
"description": "When set to `true`, conversion operators are sorted last in the list of members of a record or namespace.",
323+
"enum": [
324+
true,
325+
false
326+
],
327+
"title": "Sort conversion operators last",
328+
"type": "boolean"
329+
},
330+
"sort-members-ctors-1st": {
331+
"default": true,
332+
"description": "When set to `true`, constructors are sorted first in the list of members of a record.",
333+
"enum": [
334+
true,
335+
false
336+
],
337+
"title": "Sort constructors first",
338+
"type": "boolean"
339+
},
340+
"sort-members-dtors-1st": {
341+
"default": true,
342+
"description": "When set to `true`, destructors are sorted first in the list of members of a record.",
343+
"enum": [
344+
true,
345+
false
346+
],
347+
"title": "Sort destructors first",
348+
"type": "boolean"
349+
},
350+
"sort-members-relational-last": {
351+
"default": true,
352+
"description": "When set to `true`, relational operators are sorted last in the list of members of a record or namespace.",
353+
"enum": [
354+
true,
355+
false
356+
],
357+
"title": "Sort relational operators last",
358+
"type": "boolean"
359+
},
300360
"source-root": {
301361
"default": "<config-dir>",
302362
"description": "Path to the root directory of the source code. This path is used as a default for input files and a base for relative paths formed from absolute paths. This should typically be the root directory of the git project, as relative paths formed from it can be used to create links to these source files in the repository. Templates use the `base-url` option to create links to the source code.",

include/mrdocs/ADT/Polymorphic.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,41 @@ CompareDerived(
876876
: std::strong_ordering::greater;
877877
}
878878

879+
/// @copydoc CompareDerived
880+
template <class Base>
881+
requires
882+
(!IsPolymorphic_v<Base>) &&
883+
detail::CanVisitCompare<Base>
884+
auto
885+
CompareDerived(Base const& lhs, Base const& rhs)
886+
{
887+
if (lhs.Kind == rhs.Kind)
888+
{
889+
return visit(lhs, detail::VisitCompareFn<Base>(rhs));
890+
}
891+
return lhs.Kind <=> rhs.Kind;
892+
}
893+
894+
template <class Base>
895+
requires detail::CanVisitCompare<Base>
896+
auto
897+
operator<=>(
898+
Polymorphic<Base> const& lhs,
899+
Polymorphic<Base> const& rhs)
900+
{
901+
return CompareDerived(lhs, rhs);
902+
}
903+
904+
template <class Base>
905+
requires detail::CanVisitCompare<Base>
906+
bool
907+
operator==(
908+
Polymorphic<Base> const& lhs,
909+
Polymorphic<Base> const& rhs)
910+
{
911+
return lhs <=> rhs == std::strong_ordering::equal;
912+
}
913+
879914
} // clang::mrdocs
880915

881916
#endif

include/mrdocs/Corpus.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class MRDOCS_VISIBLE
150150
*/
151151
template <range_of<SymbolID> R, class F, class... Args>
152152
void
153-
traverseIDs(R&& range, F&& f, Args&&... args) const
153+
visitIDs(R&& range, F&& f, Args&&... args) const
154154
{
155155
for (SymbolID const& id : range)
156156
{
@@ -200,7 +200,7 @@ class MRDOCS_VISIBLE
200200
if (!opts.skipInherited)
201201
{
202202
auto MS = allMembers(I);
203-
traverseIDs(MS,
203+
visitIDs(MS,
204204
std::forward<F>(f),
205205
std::forward<Args>(args)...);
206206
for (SymbolID const& id : MS)
@@ -210,7 +210,7 @@ class MRDOCS_VISIBLE
210210
traverse(opts, *MI, std::forward<F>(f), std::forward<Args>(args)...);
211211
}
212212
}
213-
else
213+
else /* skipInherited */
214214
{
215215
auto nonInherited =
216216
allMembers(I) |
@@ -219,7 +219,7 @@ class MRDOCS_VISIBLE
219219
MRDOCS_CHECK_OR(MI, false);
220220
return MI->Parent == I.id;
221221
});
222-
traverseIDs(nonInherited,
222+
visitIDs(nonInherited,
223223
std::forward<F>(f),
224224
std::forward<Args>(args)...);
225225
if (opts.recursive)
@@ -233,23 +233,28 @@ class MRDOCS_VISIBLE
233233
}
234234
}
235235
}
236-
else
236+
else /* ordered */
237237
{
238238
auto members0 = allMembers(I);
239239
static_assert(range_of<decltype(members0), SymbolID>);
240240
std::vector<SymbolID> members;
241241
members.reserve(std::ranges::distance(members0));
242242
std::ranges::copy(members0, std::back_inserter(members));
243-
std::stable_sort(members.begin(), members.end(),
243+
std::ranges::sort(members,
244244
[this](SymbolID const& lhs, SymbolID const& rhs)
245245
{
246246
auto const& lhsInfo = get(lhs);
247247
auto const& rhsInfo = get(rhs);
248-
return lhsInfo < rhsInfo;
248+
if (auto const cmp = lhsInfo.Name <=> rhsInfo.Name;
249+
!std::is_eq(cmp))
250+
{
251+
return std::is_lt(cmp);
252+
}
253+
return std::is_lt(CompareDerived(lhsInfo, rhsInfo));
249254
});
250255
if (!opts.skipInherited)
251256
{
252-
traverseIDs(members,
257+
visitIDs(members,
253258
std::forward<F>(f),
254259
std::forward<Args>(args)...);
255260
if (opts.recursive)
@@ -262,7 +267,7 @@ class MRDOCS_VISIBLE
262267
}
263268
}
264269
}
265-
else
270+
else /* skipInherited */
266271
{
267272
auto nonInherited =
268273
members |
@@ -271,7 +276,7 @@ class MRDOCS_VISIBLE
271276
MRDOCS_CHECK_OR(MI, false);
272277
return MI->Parent == I.id;
273278
});
274-
traverseIDs(nonInherited,
279+
visitIDs(nonInherited,
275280
std::forward<F>(f),
276281
std::forward<Args>(args)...);
277282
if (opts.recursive)

include/mrdocs/Dom/LazyArray.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class LazyArrayImpl : public ArrayImpl
7575

7676
const_iterator_t begin_;
7777
const_sentinel_t end_;
78-
[[no_unique_address]] size_type size_;
79-
[[no_unique_address]] Context context_;
78+
MRDOCS_NO_UNIQUE_ADDRESS size_type size_;
79+
MRDOCS_NO_UNIQUE_ADDRESS Context context_;
8080

8181
public:
8282
explicit

include/mrdocs/Dom/LazyObject.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#ifndef MRDOCS_LIB_DOM_LAZY_OBJECT_HPP
1212
#define MRDOCS_LIB_DOM_LAZY_OBJECT_HPP
1313

14-
#include <mrdocs/Dom.hpp>
1514
#include <mrdocs/Platform.hpp>
15+
#include <mrdocs/Dom.hpp>
1616
#include <mrdocs/Support/Error.hpp>
1717
#include <string_view>
1818

@@ -164,7 +164,7 @@ class LazyObjectImpl : public ObjectImpl
164164
{
165165
T const* underlying_;
166166
Object overlay_;
167-
[[no_unique_address]] Context context_{};
167+
MRDOCS_NO_UNIQUE_ADDRESS Context context_{};
168168

169169
public:
170170
explicit

include/mrdocs/Metadata/Info.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ struct MRDOCS_VISIBLE Info
138138

139139
#define INFO(Type) constexpr bool is##Type() const noexcept { return Kind == InfoKind::Type; }
140140
#include <mrdocs/Metadata/InfoNodesPascal.inc>
141+
142+
auto operator<=>(const Info&) const = default;
141143
};
142144

143145
//------------------------------------------------
@@ -162,6 +164,8 @@ struct InfoCommonBase : Info
162164
static constexpr bool is##Kind() noexcept { return K == InfoKind::Kind; }
163165
#include <mrdocs/Metadata/InfoNodesPascal.inc>
164166

167+
auto operator<=>(const InfoCommonBase&) const = default;
168+
165169
protected:
166170
constexpr explicit InfoCommonBase(SymbolID const& ID)
167171
: Info(K, ID)
@@ -351,14 +355,6 @@ tag_invoke(
351355
});
352356
}
353357

354-
/** Compare two Info objects
355-
*/
356-
MRDOCS_DECL
357-
bool
358-
operator<(
359-
Info const& lhs,
360-
Info const& rhs) noexcept;
361-
362358
} // clang::mrdocs
363359

364360
#endif

include/mrdocs/Metadata/Info/Concept.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <mrdocs/Metadata/Expression.hpp>
1616
#include <mrdocs/Metadata/Source.hpp>
1717
#include <mrdocs/Metadata/Template.hpp>
18+
#include <mrdocs/ADT/Polymorphic.hpp>
1819

1920
namespace clang::mrdocs {
2021

@@ -37,6 +38,9 @@ struct ConceptInfo final
3738
: InfoCommonBase(ID)
3839
{
3940
}
41+
42+
std::strong_ordering
43+
operator<=>(ConceptInfo const& other) const;
4044
};
4145

4246
MRDOCS_DECL

include/mrdocs/Metadata/Info/Function.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <mrdocs/Metadata/Template.hpp>
2323
#include <mrdocs/Dom/LazyArray.hpp>
2424
#include <mrdocs/ADT/Polymorphic.hpp>
25-
#include <memory>
2625
#include <string>
2726
#include <vector>
2827

@@ -175,6 +174,9 @@ struct FunctionInfo final
175174
: InfoCommonBase(ID)
176175
{
177176
}
177+
178+
std::strong_ordering
179+
operator<=>(const FunctionInfo& other) const;
178180
};
179181

180182
MRDOCS_DECL

include/mrdocs/Metadata/Info/Guide.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <mrdocs/Metadata/Template.hpp>
1818
#include <mrdocs/Metadata/Info/Function.hpp>
1919
#include <mrdocs/Metadata/Type.hpp>
20+
#include <mrdocs/ADT/Polymorphic.hpp>
2021
#include <vector>
2122

2223
namespace clang::mrdocs {
@@ -49,6 +50,9 @@ struct GuideInfo final
4950
explicit GuideInfo(SymbolID ID) noexcept
5051
: InfoCommonBase(ID)
5152
{}
53+
54+
std::strong_ordering
55+
operator<=>(GuideInfo const& other) const;
5256
};
5357

5458
MRDOCS_DECL

include/mrdocs/Metadata/Info/Namespace.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct NamespaceTranche {
3232
std::vector<SymbolID> Concepts;
3333
std::vector<SymbolID> Guides;
3434
std::vector<SymbolID> Usings;
35+
36+
auto operator<=>(NamespaceTranche const&) const = default;
3537
};
3638

3739
MRDOCS_DECL
@@ -118,6 +120,8 @@ struct NamespaceInfo final
118120
: InfoCommonBase(ID)
119121
{
120122
}
123+
124+
auto operator<=>(NamespaceInfo const&) const = default;
121125
};
122126

123127
MRDOCS_DECL

0 commit comments

Comments
 (0)