Skip to content

Commit afa558a

Browse files
committed
refactor(Corpus): enforce non-optional polymorphic types
Ensure optional polymorphic types are only used for members that are really optional in terms of application logic. Otherwise, we only make them polymorphic objects that cannot be empty and give them reasonable defaults among the derived types in that type family.
1 parent c3d8145 commit afa558a

File tree

85 files changed

+717
-684
lines changed

Some content is hidden

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

85 files changed

+717
-684
lines changed

include/mrdocs/Metadata/Info/Concept.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#define MRDOCS_API_METADATA_INFO_CONCEPT_HPP
1313

1414
#include <mrdocs/Platform.hpp>
15-
#include <mrdocs/ADT/Polymorphic.hpp>
1615
#include <mrdocs/ADT/Optional.hpp>
16+
#include <mrdocs/ADT/Polymorphic.hpp>
1717
#include <mrdocs/Metadata/Expression.hpp>
1818
#include <mrdocs/Metadata/Info.hpp>
1919
#include <mrdocs/Metadata/Info/Source.hpp>

include/mrdocs/Metadata/Info/Enum.hpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,32 @@ namespace clang::mrdocs {
2424
struct EnumInfo final
2525
: InfoCommonBase<InfoKind::Enum>
2626
{
27-
// Indicates whether this enum is scoped (e.g. enum class).
27+
/** Indicates whether this enum is scoped (e.g. enum class).
28+
29+
If true, the enumerators are accessed with the scope resolution
30+
operator (e.g. EnumName::Enumerator).
31+
32+
If false, the enumerators are accessed directly (e.g. Enumerator)
33+
in the parent context.
34+
*/
2835
bool Scoped = false;
2936

30-
// Set too nonempty to the type when this is an explicitly typed enum. For
31-
// enum Foo : short { ... };
32-
// this will be "short".
37+
/** The underlying type of this enum, if explicitly specified.
38+
39+
If not specified, the underlying type is an implementation-defined
40+
integral type that can represent all the enumerator values defined in
41+
the enumeration.
42+
43+
For `enum Foo : short { ... };` this will be represent `short`.
44+
*/
3345
Optional<Polymorphic<TypeInfo>> UnderlyingType = std::nullopt;
3446

3547
/** The members of this scope.
3648
37-
All members are enum constants;
49+
All members are enum constants.
50+
51+
Enum constants are independent symbol types that
52+
can be documented separately.
3853
*/
3954
std::vector<SymbolID> Constants;
4055

include/mrdocs/Metadata/Info/Friend.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ namespace clang::mrdocs {
2121
2222
- Friendship is not transitive
2323
- Friendship is not inherited
24-
- Access specifiers have no effect on the meaning of friend declarations
24+
- Access specifiers do not affect the meaning of friend declarations
25+
26+
The friends of a record are stored directly in the record's metadata.
27+
28+
If the friend declaration is documented, the documentation is
29+
stored in the befriended symbol's metadata rather than in the
30+
relationship.
2531
*/
2632
struct FriendInfo final
2733
{
@@ -30,6 +36,8 @@ struct FriendInfo final
3036
SymbolID id = SymbolID::invalid;
3137

3238
/** Befriended type.
39+
40+
This member is nullable and only used when befriending a type.
3341
*/
3442
Optional<Polymorphic<TypeInfo>> Type = std::nullopt;
3543
};

include/mrdocs/Metadata/Info/Function.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ namespace clang::mrdocs {
3030
struct FunctionInfo final
3131
: InfoCommonBase<InfoKind::Function>
3232
{
33-
/// Info about the return type of this function.
34-
Optional<Polymorphic<TypeInfo>> ReturnType = std::nullopt;
33+
/** Info about the return type of this function.
34+
35+
If the function has a deduced return type, this contains
36+
`auto` to indicate that.
37+
38+
By default, we also use `auto` in the member to indicate
39+
an unknown return type.
40+
*/
41+
Polymorphic<TypeInfo> ReturnType = Polymorphic<TypeInfo>(AutoTypeInfo{});
3542

3643
/// List of parameters.
3744
std::vector<Param> Params;

include/mrdocs/Metadata/Info/Guide.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#define MRDOCS_API_METADATA_INFO_GUIDE_HPP
1313

1414
#include <mrdocs/Platform.hpp>
15-
#include <mrdocs/ADT/Polymorphic.hpp>
1615
#include <mrdocs/ADT/Optional.hpp>
16+
#include <mrdocs/ADT/Polymorphic.hpp>
1717
#include <mrdocs/Metadata/Info.hpp>
1818
#include <mrdocs/Metadata/Info/Function.hpp>
1919
#include <mrdocs/Metadata/Info/Source.hpp>
@@ -32,7 +32,7 @@ struct GuideInfo final
3232
3333
This is always a SpecializationTypeInfo.
3434
*/
35-
Optional<Polymorphic<TypeInfo>> Deduced = std::nullopt;
35+
Polymorphic<TypeInfo> Deduced = Polymorphic<TypeInfo>(AutoTypeInfo{});
3636

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

include/mrdocs/Metadata/Info/NamespaceAlias.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct NamespaceAliasInfo final
2828
This is another namespace that might or might
2929
not be in the same project.
3030
*/
31-
Optional<Polymorphic<NameInfo>> AliasedSymbol;
31+
IdentifierNameInfo AliasedSymbol;
3232

3333
//--------------------------------------------
3434

include/mrdocs/Metadata/Info/Overloads.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ struct OverloadsInfo final
3131
/// The members of the overload set.
3232
std::vector<SymbolID> Members;
3333

34-
/// Info about the return type of this function.
35-
Optional<Polymorphic<TypeInfo>> ReturnType = std::nullopt;
34+
/** Info about the return type of these function overloads.
35+
36+
If all overloads have the same return type, this contains
37+
that type. Otherwise, it contains `auto` to indicate that
38+
the return type varies according to the parameters.
39+
*/
40+
Polymorphic<TypeInfo> ReturnType = Polymorphic<TypeInfo>(AutoTypeInfo{});
3641

3742
//--------------------------------------------
3843

include/mrdocs/Metadata/Info/Param.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct Param final
2727
{
2828
/** The type of this parameter
2929
*/
30-
Optional<Polymorphic<TypeInfo>> Type = std::nullopt;
30+
Polymorphic<TypeInfo> Type = Polymorphic<TypeInfo>(AutoTypeInfo{});
3131

3232
/** The parameter name.
3333
*/

include/mrdocs/Metadata/Info/RecordBase.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,23 @@ namespace clang::mrdocs {
2222
*/
2323
struct BaseInfo
2424
{
25-
Optional<Polymorphic<TypeInfo>> Type;
25+
/** The base type.
26+
27+
This is typically a `NamedTypeInfo` that refers to a
28+
`RecordInfo`, but it could also be a more complex type
29+
such as a `decltype`.
30+
*/
31+
Polymorphic<TypeInfo> Type;
32+
33+
/** The access specifier for the base.
34+
*/
2635
AccessKind Access = AccessKind::Public;
36+
37+
/** Whether the base is virtual.
38+
*/
2739
bool IsVirtual = false;
2840

29-
BaseInfo() = default;
41+
BaseInfo() = delete;
3042

3143
BaseInfo(
3244
Polymorphic<TypeInfo>&& type,

include/mrdocs/Metadata/Info/Source.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#define MRDOCS_API_METADATA_INFO_SOURCE_HPP
1515

1616
#include <mrdocs/Platform.hpp>
17-
#include <mrdocs/Metadata/Info/Location.hpp>
1817
#include <mrdocs/ADT/Optional.hpp>
1918
#include <mrdocs/Dom.hpp>
19+
#include <mrdocs/Metadata/Info/Location.hpp>
2020
#include <string>
2121

2222
namespace clang::mrdocs {

0 commit comments

Comments
 (0)