Skip to content

Commit cca6494

Browse files
committed
add Generators
1 parent 82f80a9 commit cca6494

17 files changed

+338
-72
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ target_include_directories(mrdox-api
9494
)
9595
target_compile_definitions(
9696
mrdox-api
97+
PUBLIC
98+
-DMRDOX_STATIC_LINK
9799
PRIVATE
98100
-DMRDOX_LIB
99101
)

include/mrdox/Config.hpp

+22-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ namespace mrdox {
4242
particular directory from which absolute paths
4343
are calculated from relative paths.
4444
*/
45-
class Config : public std::enable_shared_from_this<Config>
45+
class MRDOX_VISIBLE
46+
Config
47+
: public std::enable_shared_from_this<Config>
4648
{
4749
template<class T>
4850
friend struct llvm::yaml::MappingTraits;
@@ -63,21 +65,23 @@ class Config : public std::enable_shared_from_this<Config>
6365
explicit Config(llvm::StringRef configDir);
6466

6567
public:
66-
virtual ~Config() = default;
68+
MRDOX_DECL virtual ~Config() = default;
6769

6870
/** Return a defaulted Config using an existing directory.
6971
7072
@param dirPath The path to the directory.
7173
If this is relative, an absolute path will
7274
be calculated from the current directory.
7375
*/
76+
MRDOX_DECL
7477
static
7578
llvm::Expected<std::shared_ptr<Config>>
7679
createAtDirectory(
7780
llvm::StringRef dirPath);
7881

7982
/** Return a Config loaded from the specified YAML file.
8083
*/
84+
MRDOX_DECL
8185
static
8286
llvm::Expected<std::shared_ptr<Config>>
8387
loadFromFile(
@@ -230,12 +234,14 @@ class Config : public std::enable_shared_from_this<Config>
230234
231235
@param dirPath The directory.
232236
*/
237+
MRDOX_DECL
233238
void
234239
setSourceRoot(
235240
llvm::StringRef dirPath);
236241

237242
/** Set the filter for including translation units.
238243
*/
244+
MRDOX_DECL
239245
void
240246
setInputFileIncludes(
241247
std::vector<std::string> const& list);
@@ -258,7 +264,7 @@ class Config::WorkGroup
258264
concurrency level. Calls to post and wait
259265
are blocking.
260266
*/
261-
WorkGroup() noexcept = default;
267+
MRDOX_DECL WorkGroup() noexcept;
262268

263269
/** Constructor.
264270
*/
@@ -268,27 +274,35 @@ class Config::WorkGroup
268274

269275
/** Constructor.
270276
*/
271-
WorkGroup(WorkGroup const& other);
277+
MRDOX_DECL
278+
WorkGroup(
279+
WorkGroup const& other);
272280

273281
/** Assignment.
274282
*/
283+
MRDOX_DECL
275284
WorkGroup&
276-
operator=(WorkGroup const& other);
285+
operator=(
286+
WorkGroup const& other);
277287

278288
/** Post work to the work group.
279289
*/
280-
void post(std::function<void(void)>);
290+
MRDOX_DECL
291+
void
292+
post(std::function<void(void)>);
281293

282294
/** Wait for all posted work in the work group to complete.
283295
*/
284-
void wait();
296+
MRDOX_DECL
297+
void
298+
wait();
285299

286300
private:
287301
friend class Config::Impl;
288302

289303
struct Base
290304
{
291-
virtual ~Base() = default;
305+
MRDOX_DECL virtual ~Base() noexcept;
292306
};
293307

294308
class Impl;

include/mrdox/Corpus.hpp

+25-15
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ namespace mrdox {
3131

3232
/** The collection of declarations in extracted form.
3333
*/
34-
class Corpus
34+
class MRDOX_VISIBLE
35+
Corpus
3536
{
3637
public:
37-
virtual ~Corpus() = default;
38+
MRDOX_DECL
39+
virtual
40+
~Corpus() noexcept;
3841

3942
//--------------------------------------------
4043

@@ -46,20 +49,22 @@ class Corpus
4649

4750
/** Return the list of all uniquely identified symbols.
4851
*/
52+
MRDOX_DECL
4953
virtual
5054
std::vector<SymbolID> const&
5155
allSymbols() const noexcept = 0;
5256

5357
/** Return the metadata for the global namespace.
5458
*/
59+
MRDOX_DECL
5560
NamespaceInfo const&
5661
globalNamespace() const noexcept;
5762

5863
/** Return the Info with the matching ID, or nullptr.
5964
*/
6065
/** @{ */
61-
virtual Info* find(SymbolID const& id) noexcept = 0;
62-
virtual Info const* find(SymbolID const& id) const noexcept = 0;
66+
MRDOX_DECL virtual Info* find(SymbolID const& id) noexcept = 0;
67+
MRDOX_DECL virtual Info const* find(SymbolID const& id) const noexcept = 0;
6368
/** @} */
6469

6570
/** Return true if an Info with the specified symbol ID exists.
@@ -86,22 +91,26 @@ class Corpus
8691
*/
8792
struct Visitor
8893
{
89-
virtual ~Visitor() = default;
90-
virtual bool visit(NamespaceInfo const&);
91-
virtual bool visit(RecordInfo const&);
92-
virtual bool visit(Overloads const&);
93-
virtual bool visit(FunctionInfo const&);
94-
virtual bool visit(TypedefInfo const&);
95-
virtual bool visit(EnumInfo const&);
94+
MRDOX_DECL virtual ~Visitor() noexcept;
95+
MRDOX_DECL virtual bool visit(NamespaceInfo const&);
96+
MRDOX_DECL virtual bool visit(RecordInfo const&);
97+
MRDOX_DECL virtual bool visit(Overloads const&);
98+
MRDOX_DECL virtual bool visit(FunctionInfo const&);
99+
MRDOX_DECL virtual bool visit(TypedefInfo const&);
100+
MRDOX_DECL virtual bool visit(EnumInfo const&);
96101
};
97102

98103
/** Visit the specified symbol ID or node.
99104
*/
100105
/** @{ */
101-
[[nodiscard]] bool visit(SymbolID id, Visitor& f) const;
102-
[[nodiscard]] bool visit(Scope const& I, Visitor& f) const;
103-
[[nodiscard]] bool visitWithOverloads(Scope const& I, Visitor& f) const;
104-
[[nodiscard]] bool visit(Info const& I, Visitor& f) const;
106+
MRDOX_DECL [[nodiscard]] bool visit(
107+
SymbolID id, Visitor& f) const;
108+
MRDOX_DECL [[nodiscard]] bool visit(
109+
Scope const& I, Visitor& f) const;
110+
MRDOX_DECL [[nodiscard]] bool visitWithOverloads(
111+
Scope const& I, Visitor& f) const;
112+
MRDOX_DECL [[nodiscard]] bool visit(
113+
Info const& I, Visitor& f) const;
105114
/** @} */
106115

107116
//--------------------------------------------
@@ -113,6 +122,7 @@ class Corpus
113122
@param R The diagnostic reporting object to
114123
use for delivering errors and information.
115124
*/
125+
MRDOX_DECL
116126
[[nodiscard]]
117127
static
118128
llvm::Expected<std::unique_ptr<Corpus>>

include/mrdox/Debug.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ namespace mrdox {
2626
/** Return a stream which writes output to the debugger.
2727
*/
2828
/** @{ */
29-
llvm::raw_ostream& debug_outs();
30-
llvm::raw_ostream& debug_errs();
29+
MRDOX_DECL llvm::raw_ostream& debug_outs();
30+
MRDOX_DECL llvm::raw_ostream& debug_errs();
3131
/** @} */
3232

3333
/** Enable debug heap checking.
3434
*/
35-
void
36-
debugEnableHeapChecking();
35+
MRDOX_DECL void debugEnableHeapChecking();
3736

3837
#if defined(NDEBUG)
3938
#define Assert(expr) ((void)0)

include/mrdox/Error.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ auto nice(llvm::ErrorOr<T>&& e)
5858
return nice(e.getError());
5959
}
6060

61-
llvm::StringRef nice(std::source_location loc);
61+
MRDOX_DECL
62+
llvm::StringRef
63+
nice(std::source_location loc);
6264

6365
//------------------------------------------------
6466

@@ -68,6 +70,7 @@ llvm::StringRef nice(std::source_location loc);
6870
6971
@param loc The source location where the failure occurred.
7072
*/
73+
MRDOX_DECL
7174
[[nodiscard]]
7275
llvm::Error
7376
makeErrorString(

include/mrdox/Generator.hpp

+19-6
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,29 @@ namespace mrdox {
2626

2727
/** Base class for documentation generators.
2828
*/
29-
struct Generator
29+
struct MRDOX_VISIBLE
30+
Generator
3031
{
3132
/** Destructor.
3233
*/
33-
virtual ~Generator() = default;
34+
MRDOX_DECL
35+
virtual
36+
~Generator() noexcept;
3437

35-
/** Return the full name of the generator.
38+
/** Return the symbolic name of the generator.
3639
*/
40+
MRDOX_DECL
3741
virtual
3842
llvm::StringRef
3943
name() const noexcept = 0;
4044

45+
/** Return the display name of the generator.
46+
*/
47+
MRDOX_DECL
48+
virtual
49+
llvm::StringRef
50+
displayName() const noexcept = 0;
51+
4152
/** Return the extension or tag of the generator.
4253
4354
This should be in all lower case. Examples
@@ -49,6 +60,7 @@ struct Generator
4960
The returned string should not include
5061
a leading period.
5162
*/
63+
MRDOX_DECL
5264
virtual
5365
llvm::StringRef
5466
extension() const noexcept = 0;
@@ -73,6 +85,7 @@ struct Generator
7385
@param R The diagnostic reporting object to
7486
use for delivering errors and information.
7587
*/
88+
MRDOX_DECL
7689
virtual
7790
llvm::Error
7891
buildPages(
@@ -99,6 +112,7 @@ struct Generator
99112
fd_os->error() will be called periodically and
100113
the result returend if an error is indicated.
101114
*/
115+
MRDOX_DECL
102116
virtual
103117
llvm::Error
104118
buildSinglePage(
@@ -122,6 +136,7 @@ struct Generator
122136
123137
@param R The diagnostic reporting object to use.
124138
*/
139+
MRDOX_DECL
125140
llvm::Error
126141
buildSinglePageFile(
127142
llvm::StringRef filePath,
@@ -144,16 +159,14 @@ struct Generator
144159
145160
@param R The diagnostic reporting object to use.
146161
*/
162+
MRDOX_DECL
147163
llvm::Error
148164
buildSinglePageString(
149165
std::string& dest,
150166
Corpus const& corpus,
151167
Reporter& R) const;
152168
};
153169

154-
extern std::unique_ptr<Generator> makeXMLGenerator();
155-
extern std::unique_ptr<Generator> makeAsciidocGenerator();
156-
157170
} // mrdox
158171
} // clang
159172

include/mrdox/Generators.hpp

+54-3
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,73 @@
1212
#define MRDOX_GENERATORS_HPP
1313

1414
#include <mrdox/Platform.hpp>
15+
#include <mrdox/Generator.hpp>
16+
#include <llvm/ADT/StringRef.h>
17+
#include <cstdint>
1518

1619
namespace clang {
1720
namespace mrdox {
1821

1922
/** A dynamic list of Generator
2023
*/
21-
class Generators
24+
class MRDOX_VISIBLE
25+
Generators
2226
{
23-
Generators() noexcept;
27+
Generators(Generators const&) = delete;
28+
Generators& operator=(Generators const&) = delete;
29+
30+
protected:
31+
Generators() noexcept = default;
2432

2533
public:
34+
using value_type = Generator const*;
35+
using iterator = value_type const*;
36+
using const_iterator = iterator;
37+
using reference = value_type const&;
38+
using const_reference = value_type const&;
39+
using size_type = std::size_t;
40+
using difference_type = std::ptrdiff_t;
41+
2642
/** Destructor.
2743
*/
28-
virtual ~Generators() = default;
44+
MRDOX_DECL
45+
virtual
46+
~Generators() = default;
47+
48+
/** Return an iterator to the beginning.
49+
*/
50+
MRDOX_DECL
51+
virtual
52+
iterator
53+
begin() const noexcept = 0;
54+
55+
/** Return an iterator to the end.
56+
*/
57+
MRDOX_DECL
58+
virtual
59+
iterator
60+
end() const noexcept = 0;
61+
62+
/** Return a pointer to the matching generator.
63+
64+
@return A pointer to the generator, or `nullptr`.
65+
66+
@param name The name of the generator. The
67+
name must be an exact match, including case.
68+
*/
69+
MRDOX_DECL
70+
virtual
71+
Generator const*
72+
find(
73+
llvm::StringRef name) const noexcept = 0;
2974
};
3075

76+
/** Return a reference to the global Generators instance.
77+
*/
78+
MRDOX_DECL
79+
Generators const&
80+
getGenerators() noexcept;
81+
3182
} // mrdox
3283
} // clang
3384

0 commit comments

Comments
 (0)