Skip to content

Commit 75d9c37

Browse files
committed
refactor Config into impl
1 parent cca6494 commit 75d9c37

File tree

10 files changed

+289
-221
lines changed

10 files changed

+289
-221
lines changed

include/mrdox/Config.hpp

+57-87
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
#include <mrdox/Platform.hpp>
1616
#include <mrdox/Reporter.hpp>
1717
#include <clang/Tooling/ArgumentsAdjusters.h>
18-
#include <llvm/ADT/Optional.h>
19-
#include <llvm/ADT/SmallVector.h>
18+
#include <llvm/ADT/SmallString.h>
2019
#include <llvm/ADT/StringRef.h>
2120
#include <llvm/Support/Error.h>
22-
#include <llvm/Support/YAMLTraits.h>
2321
#include <functional>
2422
#include <memory>
2523
#include <string>
@@ -34,6 +32,8 @@ struct MappingTraits;
3432
namespace clang {
3533
namespace mrdox {
3634

35+
class ConfigImpl;
36+
3737
/** Configuration used to generate the Corpus and Docs
3838
3939
This contains all the settings applied from
@@ -44,75 +44,39 @@ namespace mrdox {
4444
*/
4545
class MRDOX_VISIBLE
4646
Config
47-
: public std::enable_shared_from_this<Config>
4847
{
49-
template<class T>
50-
friend struct llvm::yaml::MappingTraits;
51-
52-
class Impl;
53-
struct Options;
48+
Config(Config const&) = delete;
49+
Config& operator=(Config const&) = delete;
5450

55-
llvm::SmallString<0> configDir_;
51+
protected:
5652
std::string sourceRoot_;
57-
std::vector<llvm::SmallString<0>> inputFileIncludes_;
58-
bool verbose_ = true;
53+
llvm::SmallString<0> configDir_;
5954
bool includePrivate_ = false;
55+
bool verbose_ = true;
6056

61-
llvm::SmallString<0>
62-
normalizePath(llvm::StringRef pathName);
63-
64-
protected:
65-
explicit Config(llvm::StringRef configDir);
57+
explicit
58+
Config(llvm::StringRef configDir);
6659

6760
public:
68-
MRDOX_DECL virtual ~Config() = default;
69-
70-
/** Return a defaulted Config using an existing directory.
61+
class Options; // private, but for clang-15 bug
7162

72-
@param dirPath The path to the directory.
73-
If this is relative, an absolute path will
74-
be calculated from the current directory.
63+
/** A resource for running submitted work, possibly concurrent.
7564
*/
76-
MRDOX_DECL
77-
static
78-
llvm::Expected<std::shared_ptr<Config>>
79-
createAtDirectory(
80-
llvm::StringRef dirPath);
65+
class WorkGroup;
8166

82-
/** Return a Config loaded from the specified YAML file.
67+
/** Destructor.
8368
*/
8469
MRDOX_DECL
85-
static
86-
llvm::Expected<std::shared_ptr<Config>>
87-
loadFromFile(
88-
llvm::StringRef filePath);
70+
virtual
71+
~Config() noexcept;
8972

9073
//
9174
// VFALCO these naked data members are temporary...
9275
//
93-
94-
/** Adjustments to tool command line, applied during execute.
95-
*/
9676
tooling::ArgumentsAdjuster ArgAdjuster;
97-
98-
/** Name of project being documented.
99-
*/
100-
std::string ProjectName;
101-
102-
// Directory for outputting generated files.
10377
std::string OutDirectory;
104-
105-
// URL of repository that hosts code used
106-
// for links to definition locations.
107-
llvm::Optional<std::string> RepositoryUrl;
108-
10978
bool IgnoreMappingFailures = false;
11079

111-
public:
112-
/** A resource for running submitted work, possibly concurrent.
113-
*/
114-
class WorkGroup;
115-
11680
//--------------------------------------------
11781
//
11882
// Observers
@@ -157,32 +121,6 @@ class MRDOX_VISIBLE
157121
return includePrivate_;
158122
}
159123

160-
/** Returns true if the translation unit should be visited.
161-
162-
@param filePath The posix-style full path
163-
to the file being processed.
164-
*/
165-
bool
166-
shouldVisitTU(
167-
llvm::StringRef filePath) const noexcept;
168-
169-
/** Returns true if the file should be visited.
170-
171-
If the file is visited, then prefix is
172-
set to the portion of the file path which
173-
should be be removed for matching files.
174-
175-
@param filePath The posix-style full path
176-
to the file being processed.
177-
178-
@param prefix The prefix which should be
179-
removed from subsequent matches.
180-
*/
181-
bool
182-
shouldVisitFile(
183-
llvm::StringRef filePath,
184-
llvm::SmallVectorImpl<char>& prefix) const noexcept;
185-
186124
/** Call a function for each element of a range.
187125
188126
The function is invoked with a reference
@@ -235,42 +173,74 @@ class MRDOX_VISIBLE
235173
@param dirPath The directory.
236174
*/
237175
MRDOX_DECL
176+
virtual
238177
void
239178
setSourceRoot(
240-
llvm::StringRef dirPath);
179+
llvm::StringRef dirPath) = 0;
241180

242181
/** Set the filter for including translation units.
243182
*/
244183
MRDOX_DECL
184+
virtual
245185
void
246186
setInputFileIncludes(
247-
std::vector<std::string> const& list);
187+
std::vector<std::string> const& list) = 0;
188+
189+
//--------------------------------------------
190+
//
191+
// Creation
192+
//
193+
//--------------------------------------------
194+
195+
/** Return a defaulted Config using an existing directory.
196+
197+
@param dirPath The path to the directory.
198+
If this is relative, an absolute path will
199+
be calculated from the current directory.
200+
*/
201+
MRDOX_DECL
202+
static
203+
llvm::Expected<std::shared_ptr<Config>>
204+
createAtDirectory(
205+
llvm::StringRef dirPath);
206+
207+
/** Return a Config loaded from the specified YAML file.
208+
*/
209+
MRDOX_DECL
210+
static
211+
llvm::Expected<std::shared_ptr<Config>>
212+
loadFromFile(
213+
llvm::StringRef filePath);
248214
};
249215

250216
//------------------------------------------------
251217

252218
/** A group representing possibly concurrent related tasks.
253219
*/
254-
class Config::WorkGroup
220+
class MRDOX_VISIBLE
221+
Config::WorkGroup
255222
{
256223
public:
257224
/** Destructor.
258225
*/
259-
~WorkGroup();
226+
MRDOX_DECL
227+
~WorkGroup() noexcept;
260228

261229
/** Constructor.
262230
263231
Default constructed workgroups have no
264232
concurrency level. Calls to post and wait
265233
are blocking.
266234
*/
267-
MRDOX_DECL WorkGroup() noexcept;
235+
MRDOX_DECL
236+
WorkGroup() noexcept;
268237

269238
/** Constructor.
270239
*/
240+
MRDOX_DECL
271241
explicit
272242
WorkGroup(
273-
std::shared_ptr<Config const> config);
243+
Config const* config);
274244

275245
/** Constructor.
276246
*/
@@ -298,7 +268,7 @@ class Config::WorkGroup
298268
wait();
299269

300270
private:
301-
friend class Config::Impl;
271+
friend class ConfigImpl;
302272

303273
struct Base
304274
{
@@ -307,7 +277,7 @@ class Config::WorkGroup
307277

308278
class Impl;
309279

310-
std::shared_ptr<Config::Impl const> config_;
280+
std::shared_ptr<ConfigImpl const> config_;
311281
std::unique_ptr<Base> impl_;
312282
};
313283

@@ -320,7 +290,7 @@ parallelForEach(
320290
Range&& range,
321291
UnaryFunction const& f) const
322292
{
323-
WorkGroup wg(shared_from_this());
293+
WorkGroup wg(this);
324294
for(auto&& element : range)
325295
wg.post([&f, &element]
326296
{

include/mrdox/Metadata/MemberType.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <mrdox/Metadata/Javadoc.hpp>
1717
#include <mrdox/Metadata/FieldType.hpp>
1818
#include <mrdox/Metadata/Function.hpp>
19+
#include <llvm/ADT/Optional.h>
1920

2021
namespace clang {
2122
namespace mrdox {

source/lib/AST/ASTVisitor.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <mrdox/Debug.hpp>
1717
#include <clang/Index/USRGeneration.h>
1818
#include <clang/AST/RecursiveASTVisitor.h>
19+
#include <llvm/ADT/Optional.h>
1920
#include <llvm/ADT/StringExtras.h>
2021
#include <llvm/Support/Error.h>
2122
#include <llvm/Support/Path.h>

source/lib/AST/ASTVisitor.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define MRDOX_LIB_AST_ASTVISITOR_HPP
1414

1515
#include <mrdox/Platform.hpp>
16-
#include <mrdox/Config.hpp>
16+
#include "ConfigImpl.hpp"
1717
#include <mrdox/Reporter.hpp>
1818
#include <clang/AST/Mangle.h>
1919
#include <clang/AST/RecursiveASTVisitor.h>
@@ -46,7 +46,7 @@ class ASTVisitor
4646
};
4747

4848
tooling::ExecutionContext& ex_;
49-
Config const& config_;
49+
ConfigImpl const& config_;
5050
Reporter& R_;
5151
std::unordered_map<
5252
clang::SourceLocation::UIntTy,
@@ -59,7 +59,7 @@ class ASTVisitor
5959
Config const& config,
6060
Reporter& R) noexcept
6161
: ex_(ex)
62-
, config_(config)
62+
, config_(dynamic_cast<ConfigImpl const&>(config))
6363
, R_(R)
6464
{
6565
}

0 commit comments

Comments
 (0)