Skip to content

Commit fd1bc63

Browse files
committed
sort-members option
#feat
1 parent 83458af commit fd1bc63

File tree

133 files changed

+11140
-6945
lines changed

Some content is hidden

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

133 files changed

+11140
-6945
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,19 @@ CompareDerived(
876876
: std::strong_ordering::greater;
877877
}
878878

879+
/// @copydoc CompareDerived
880+
template <class Base>
881+
requires detail::CanVisitCompare<Base>
882+
auto
883+
CompareDerived(Base const& lhs, Base const& rhs)
884+
{
885+
if (lhs.Kind == rhs.Kind)
886+
{
887+
return visit(lhs, detail::VisitCompareFn<Base>(rhs));
888+
}
889+
return lhs.Kind <=> rhs.Kind;
890+
}
891+
879892
} // clang::mrdocs
880893

881894
#endif

include/mrdocs/Corpus.hpp

Lines changed: 14 additions & 9 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,7 +233,7 @@ 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>);
@@ -245,11 +245,16 @@ class MRDOCS_VISIBLE
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/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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ struct ConceptInfo final
3737
: InfoCommonBase(ID)
3838
{
3939
}
40+
41+
std::strong_ordering
42+
operator<=>(ConceptInfo const& other) const;
4043
};
4144

4245
MRDOCS_DECL

include/mrdocs/Metadata/Info/Function.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ struct FunctionInfo final
175175
: InfoCommonBase(ID)
176176
{
177177
}
178+
179+
std::strong_ordering
180+
operator<=>(const FunctionInfo& other) const;
178181
};
179182

180183
MRDOCS_DECL

include/mrdocs/Metadata/Info/Guide.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ struct GuideInfo final
4949
explicit GuideInfo(SymbolID ID) noexcept
5050
: InfoCommonBase(ID)
5151
{}
52+
53+
std::strong_ordering
54+
operator<=>(GuideInfo const& other) const;
5255
};
5356

5457
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

include/mrdocs/Metadata/Info/Record.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ struct RecordInfo final
300300
: InfoCommonBase(ID)
301301
{
302302
}
303+
304+
std::strong_ordering
305+
operator<=>(const RecordInfo& other) const;
303306
};
304307

305308
constexpr

include/mrdocs/Metadata/Info/Typedef.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ struct TypedefInfo final
4747
: InfoCommonBase(ID)
4848
{
4949
}
50+
51+
std::strong_ordering
52+
operator<=>(TypedefInfo const& other) const;
53+
5054
};
5155

5256
MRDOCS_DECL

0 commit comments

Comments
 (0)