Skip to content

Commit f3d43cb

Browse files
committed
refactor: split base and derived classes
Split base and derived classes into their own headers to remove circular dependencies in the code.
1 parent f48bbd2 commit f3d43cb

File tree

269 files changed

+7391
-4919
lines changed

Some content is hidden

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

269 files changed

+7391
-4919
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ target_include_directories(mrdocs-core
321321
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
322322
PRIVATE
323323
"${PROJECT_SOURCE_DIR}/src"
324-
"${PROJECT_BINARY_DIR}/src")
324+
"${PROJECT_BINARY_DIR}/src"
325+
"${PROJECT_SOURCE_DIR}/third-party/lua/src"
326+
)
325327
target_compile_definitions(
326328
mrdocs-core
327329
PUBLIC

docs/modules/ROOT/pages/contribute.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ Thus, after the command line and configuration file options are parsed, they are
4646

4747
As a last step, `DoGenerateAction` converts the public `Config` settings into a `ConfigImpl` object, which is used by the rest of the program with the parsed options.
4848

49+
[#representing_symbols]
50+
== Representing Symbols
51+
52+
MrDocs has many categories of objects, where we utilize polymorphism with a fixed set of valid derived types, including Symbols (functions, classes, and enums), Javadoc blocks, template parameters, template arguments, and data types. For each such family, we follow a consistent file layout. Most of these families are defined in the `mrdocs/Metadata` directory.
53+
54+
Each base class is defined in its own header and, when necessary, implementation file. Each derived class also has its own header and implementation file. Finally, there is a single aggregator header file that includes all the derived headers. This file centralizes logic that requires knowledge of the full set of variants, such as visitors, comparison operators, and other operations that depend on the discriminator.
55+
56+
This pattern keeps the individual derived types self-contained while making cross-variant operations explicit and localized. When adding a new derived type, contributors should create its header and source file alongside the existing ones and update the corresponding aggregator file to register the new variant. This keeps the codebase predictable, avoids scattering logic, and ensures that operations over polymorphic families remain easy to find and maintain.
57+
4958
[#extract_symbols]
5059
=== Extracting Symbols
5160

@@ -201,6 +210,8 @@ This directory contains build scripts and configuration files for third-party li
201210
** `third-party/duktape/`—CMake scripts for Duktape
202211
** `third-party/lua/`—A bundled Lua interpreter
203212

213+
== Polymorphism
214+
204215
== Coding Standards
205216

206217
=== Paths

include/mrdocs/ADT/Nullable.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
#define MRDOCS_API_ADT_NULLABLE_HPP
1414

1515
#include <mrdocs/Platform.hpp>
16-
16+
#include <cmath>
17+
#include <concepts>
18+
#include <memory>
1719
#include <type_traits>
1820
#include <utility>
19-
#include <memory>
20-
#include <concepts>
21-
#include <cmath>
2221

2322
namespace clang::mrdocs {
2423

@@ -315,4 +314,4 @@ null_of() noexcept(noexcept(nullable_traits<T>::null()))
315314

316315
} // clang::mrdocs
317316

318-
#endif
317+
#endif // MRDOCS_API_ADT_NULLABLE_HPP

include/mrdocs/ADT/Polymorphic.hpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#ifndef MRDOCS_API_ADT_POLYMORPHIC_HPP
1313
#define MRDOCS_API_ADT_POLYMORPHIC_HPP
1414

15-
#include <concepts>
16-
#include <mrdocs/Support/Assert.hpp>
1715
#include <mrdocs/ADT/Nullable.hpp>
16+
#include <mrdocs/Support/Assert.hpp>
17+
#include <concepts>
1818
#include <utility>
1919

2020
namespace clang::mrdocs {
@@ -26,9 +26,7 @@ namespace clang::mrdocs {
2626
2727
It implements a tweaked version of std::polymorphic, based on the
2828
reference implementation for P3019R14. Differences are:
29-
* It supports nullability, which was originally supported in P3019 through
30-
std::optional specializations, but was later removed from the paper.
31-
* It implements comparison operators with a very project specific design.
29+
* It implements comparison operators with a very project-specific design.
3230
* Fixed allocator, not parametrizable.
3331
* No initializer_list constructor.
3432
@@ -37,13 +35,14 @@ namespace clang::mrdocs {
3735
To copy polymorphic objects, the class uses the
3836
copy constructor of the owned derived-type
3937
object when copying to another value.
40-
Similarly, to allow correct destruction of
38+
Similarly, to allow the correct destruction of
4139
derived objects, it uses the destructor of
4240
the owned derived-type object in the
4341
destructor.
4442
*/
4543
template <class T>
4644
class Polymorphic {
45+
// Base class for type-erasure.
4746
struct WrapperBase {
4847
virtual constexpr ~WrapperBase() = default;
4948
virtual T& getValue() = 0;
@@ -61,7 +60,8 @@ class Polymorphic {
6160
constexpr WrapperBase* clone() override { return new Wrapper(Value); }
6261
};
6362

64-
WrapperBase* WB; // nullptr only when constructed/reset by nullable_traits
63+
// nullptr only when constructed/reset by nullable_traits
64+
WrapperBase* WB = nullptr;
6565

6666
// Private null token and constructor: only the friend traits can call this.
6767
struct _null_t { explicit constexpr _null_t(int) {} };
@@ -70,15 +70,15 @@ class Polymorphic {
7070
// Allow the traits specialization to access private members/ctors.
7171
friend struct nullable_traits<Polymorphic<T>>;
7272

73-
// std::polymorphic has a default constructor that
74-
// default-constructs the base type T if it's default-constructible.
75-
// We disable this constructor because this is always an error
76-
// in MrDocs.
77-
// constexpr explicit Polymorphic()
78-
// requires std::is_default_constructible_v<T>
79-
// && std::is_copy_constructible_v<T>
80-
// : WB(new Wrapper<T>())
81-
// {}
73+
// std::polymorphic has a default constructor that
74+
// default-constructs the base type T if it's default-constructible.
75+
// We disable this constructor because this is always an error
76+
// in MrDocs.
77+
// constexpr explicit Polymorphic()
78+
// requires std::is_default_constructible_v<T>
79+
// && std::is_copy_constructible_v<T>
80+
// : WB(new Wrapper<T>())
81+
// {}
8282

8383
public:
8484
using value_type = T;
@@ -96,7 +96,10 @@ class Polymorphic {
9696
std::derived_from<std::remove_cvref_t<U>, T>
9797
: WB(new Wrapper<std::remove_cvref_t<U>>(std::forward<U>(u))) {}
9898

99-
/** In-place constructor for a specific derived U. */
99+
/** In-place constructor for a specific derived U.
100+
101+
@param ts Arguments to forward to U's constructor.
102+
*/
100103
template <class U, class... Ts>
101104
explicit constexpr Polymorphic(std::in_place_type_t<U>, Ts&&... ts)
102105
requires std::same_as<std::remove_cvref_t<U>, U> &&
@@ -288,4 +291,4 @@ struct nullable_traits<Polymorphic<T>>
288291

289292
} // namespace clang::mrdocs
290293

291-
#endif
294+
#endif // MRDOCS_API_ADT_POLYMORPHIC_HPP

include/mrdocs/ADT/UnorderedStringMap.hpp

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

15-
#include <unordered_map>
1615
#include <string>
16+
#include <unordered_map>
1717

1818
namespace clang::mrdocs {
1919

@@ -34,4 +34,4 @@ using UnorderedStringMultiMap = std::unordered_multimap<std::string, T, StringHa
3434

3535
} // clang::mrdocs
3636

37-
#endif
37+
#endif // MRDOCS_API_ADT_UNORDEREDSTRINGMAP_HPP

include/mrdocs/Config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#define MRDOCS_API_CONFIG_HPP
1414

1515
#include <mrdocs/Platform.hpp>
16-
#include <mrdocs/Support/Error.hpp>
1716
#include <mrdocs/Dom/Object.hpp>
1817
#include <mrdocs/PublicSettings.hpp>
18+
#include <mrdocs/Support/Error.hpp>
1919
#include <functional>
2020
#include <memory>
2121
#include <string>
@@ -225,4 +225,4 @@ class MRDOCS_DECL
225225
} // mrdocs
226226
} // clang
227227

228-
#endif
228+
#endif // MRDOCS_API_CONFIG_HPP

include/mrdocs/Config/ReferenceDirectories.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// Official repository: https://github.com/cppalliance/mrdocs
1010
//
1111

12-
#ifndef MRDOCS_API_CONFIG_REFERENCE_DIRECTORIES_HPP
13-
#define MRDOCS_API_CONFIG_REFERENCE_DIRECTORIES_HPP
12+
#ifndef MRDOCS_API_CONFIG_REFERENCEDIRECTORIES_HPP
13+
#define MRDOCS_API_CONFIG_REFERENCEDIRECTORIES_HPP
1414

1515
#include <string>
1616

@@ -34,4 +34,4 @@ struct ReferenceDirectories
3434
} // mrdocs
3535
} // clang
3636

37-
#endif
37+
#endif // MRDOCS_API_CONFIG_REFERENCEDIRECTORIES_HPP

include/mrdocs/Corpus.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
#include <mrdocs/Platform.hpp>
1818
#include <mrdocs/Config.hpp>
1919
#include <mrdocs/Metadata.hpp>
20+
#include <algorithm>
2021
#include <string>
2122
#include <type_traits>
2223
#include <utility>
2324
#include <vector>
24-
#include <algorithm>
2525

2626
namespace clang::mrdocs {
2727

@@ -500,4 +500,4 @@ getParents(Corpus const& C, Info const& I);
500500

501501
} // clang::mrdocs
502502

503-
#endif
503+
#endif // MRDOCS_API_CORPUS_HPP

include/mrdocs/Dom.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313

1414
#include <mrdocs/Dom/Value.hpp>
1515

16-
#endif
16+
#endif // MRDOCS_API_DOM_HPP

include/mrdocs/Dom/LazyArray.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// Official repository: https://github.com/cppalliance/mrdocs
99
//
1010

11-
#ifndef MRDOCS_LIB_DOM_LAZY_ARRAY_HPP
12-
#define MRDOCS_LIB_DOM_LAZY_ARRAY_HPP
11+
#ifndef MRDOCS_API_DOM_LAZYARRAY_HPP
12+
#define MRDOCS_API_DOM_LAZYARRAY_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 <ranges>
1818
#include <string_view>
@@ -195,4 +195,4 @@ TransformArray(T const& arr, F const& f)
195195
} // mrdocs
196196
} // clang
197197

198-
#endif
198+
#endif // MRDOCS_API_DOM_LAZYARRAY_HPP

0 commit comments

Comments
 (0)