Skip to content

Commit 617f4ee

Browse files
committed
refactor Config
fix #103
1 parent 0bd9adf commit 617f4ee

Some content is hidden

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

42 files changed

+733
-521
lines changed

include/mrdox/Config.hpp

Lines changed: 128 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#include <llvm/Support/Error.h>
2121
#include <functional>
2222
#include <memory>
23-
#include <string>
23+
#include <string_view>
24+
#include <system_error>
25+
#include <utility>
26+
#include <vector>
2427

2528
namespace clang {
2629
namespace mrdox {
@@ -42,15 +45,7 @@ class MRDOX_VISIBLE
4245
Config& operator=(Config const&) = delete;
4346

4447
protected:
45-
llvm::SmallString<0> configDir_;
46-
llvm::SmallString<0> outputPath_;
47-
std::string sourceRoot_;
48-
bool includePrivate_ = false;
49-
bool singlePage_ = false;
50-
bool verbose_ = true;
51-
52-
explicit
53-
Config(llvm::StringRef configDir);
48+
Config() noexcept;
5449

5550
public:
5651
class Options; // private, but for clang-15 bug
@@ -63,74 +58,19 @@ class MRDOX_VISIBLE
6358
*/
6459
MRDOX_DECL
6560
virtual
66-
~Config() noexcept;
61+
~Config() noexcept = 0;
62+
63+
/** Return true if tool output should be verbose.
64+
*/
65+
MRDOX_DECL virtual bool
66+
verbose() const noexcept = 0;
6767

6868
//
6969
// VFALCO these naked data members are temporary...
7070
//
7171
tooling::ArgumentsAdjuster ArgAdjuster;
7272
bool IgnoreMappingFailures = false;
7373

74-
//--------------------------------------------
75-
//
76-
// Observers
77-
//
78-
//--------------------------------------------
79-
80-
/** Return true if tools should show progress.
81-
*/
82-
bool
83-
verbose() const noexcept
84-
{
85-
return verbose_;
86-
}
87-
88-
/** Return the full path to the configuration directory.
89-
90-
The returned path will always be POSIX
91-
style and have a trailing separator.
92-
*/
93-
llvm::StringRef
94-
configDir() const noexcept
95-
{
96-
return configDir_;
97-
}
98-
99-
/** Return the full path to the source root directory.
100-
101-
The returned path will always be POSIX
102-
style and have a trailing separator.
103-
*/
104-
llvm::StringRef
105-
sourceRoot() const noexcept
106-
{
107-
return sourceRoot_;
108-
}
109-
110-
/** Return the output directory or filename.
111-
*/
112-
llvm::StringRef
113-
outputPath() const noexcept
114-
{
115-
return outputPath_;
116-
}
117-
118-
/** Return true if private members are documented.
119-
*/
120-
bool
121-
includePrivate() const noexcept
122-
{
123-
return includePrivate_;
124-
}
125-
126-
/** Return true if the output is single-page output.
127-
*/
128-
bool
129-
singlePage() const noexcept
130-
{
131-
return singlePage_;
132-
}
133-
13474
/** Call a function for each element of a range.
13575
13676
The function is invoked with a reference
@@ -148,94 +88,39 @@ class MRDOX_VISIBLE
14888

14989
//--------------------------------------------
15090
//
151-
// Modifiers
91+
// Observers
15292
//
15393
//--------------------------------------------
15494

155-
/** Set whether tools should show progress.
156-
*/
157-
void
158-
setVerbose(
159-
bool verbose) noexcept
160-
{
161-
verbose_ = verbose;
162-
}
95+
MRDOX_DECL virtual std::string_view outputPath() const noexcept = 0;
96+
MRDOX_DECL virtual std::string_view sourceRoot() const noexcept = 0;
97+
MRDOX_DECL virtual bool singlePage() const noexcept = 0;
16398

164-
void
165-
setSinglePage(
166-
bool singlePage) noexcept
167-
{
168-
singlePage_ = singlePage;
169-
}
99+
/** Return the YAML strings which produced this config.
170100
171-
/** Set whether or not to include private members.
172-
*/
173-
void
174-
setIncludePrivate(
175-
bool includePrivate) noexcept
176-
{
177-
includePrivate_ = includePrivate;
178-
}
101+
The first element of the pair is the entire
102+
contents of the YAML file or string used to
103+
apply the initial values to the configuration.
179104
180-
/** Set the output directory or file path.
181-
*/
182-
MRDOX_DECL
183-
virtual
184-
void
185-
setOutputPath(
186-
llvm::StringRef outputPath) = 0;
187-
188-
/** Set the directory where the input files are stored.
105+
The second element of the pair is either empty,
106+
or holds a complate additional YAML string which
107+
was applied to the values of the configuration,
108+
after the first string was applied.
189109
190-
Symbol documentation will not be emitted unless
191-
the corresponding source file is a child of this
192-
directory.
110+
Any keys in the second YAML which match keys
111+
found in the first YAML will effectively replace
112+
those entries in the configuration.
193113
194-
If the specified directory is relative, then
195-
the full path will be computed relative to
196-
@ref configDir().
114+
A @ref Generator that wishes to implement
115+
format-specific options, should parse and
116+
apply the first string, then parse and apply
117+
the second string to the same object.
197118
198-
@param dirPath The directory.
119+
@return The pair of valid YAML strings.
199120
*/
200-
MRDOX_DECL
201-
virtual
202-
void
203-
setSourceRoot(
204-
llvm::StringRef dirPath) = 0;
205-
206-
/** Set the filter for including translation units.
207-
*/
208-
MRDOX_DECL
209-
virtual
210-
void
211-
setInputFileIncludes(
212-
std::vector<std::string> const& list) = 0;
213-
214-
//--------------------------------------------
215-
//
216-
// Creation
217-
//
218-
//--------------------------------------------
219-
220-
/** Return a defaulted Config using an existing directory.
221-
222-
@param dirPath The path to the directory.
223-
If this is relative, an absolute path will
224-
be calculated from the current directory.
225-
*/
226-
MRDOX_DECL
227-
static
228-
llvm::Expected<std::shared_ptr<Config>>
229-
createAtDirectory(
230-
llvm::StringRef dirPath);
231-
232-
/** Return a Config loaded from the specified YAML file.
233-
*/
234-
MRDOX_DECL
235-
static
236-
llvm::Expected<std::shared_ptr<Config>>
237-
loadFromFile(
238-
llvm::StringRef filePath);
121+
MRDOX_DECL virtual auto
122+
configYaml() const noexcept ->
123+
std::pair<std::string_view, std::string_view> = 0;
239124
};
240125

241126
//------------------------------------------------
@@ -306,8 +191,6 @@ class MRDOX_VISIBLE
306191
std::unique_ptr<Base> impl_;
307192
};
308193

309-
//------------------------------------------------
310-
311194
template<class Range, class UnaryFunction>
312195
void
313196
Config::
@@ -324,6 +207,100 @@ parallelForEach(
324207
wg.wait();
325208
}
326209

210+
//------------------------------------------------
211+
212+
/** Create a configuration by loading a YAML file.
213+
214+
This function attemtps to load the given
215+
YAML file and apply the results to create
216+
a configuration. The working directory of
217+
the config object will be set to the
218+
directory containing the file.
219+
220+
If the `extraYaml` string is not empty, then
221+
after the YAML file is applied the string
222+
will be parsed as YAML and the results will
223+
be applied to the configuration. And keys
224+
and values in the extra YAML which are the
225+
same as elements from the file will replace
226+
existing settings.
227+
228+
@return A valid object upon success.
229+
230+
@param fileName A full or relative path to
231+
the configuration file, which may have any
232+
extension including no extension.
233+
234+
@param extraYaml An optional string containing
235+
additional valid YAML which will be parsed and
236+
applied to the existing configuration.
237+
238+
@param ec [out] Set to the error, if any occurred.
239+
*/
240+
MRDOX_DECL
241+
std::shared_ptr<Config const>
242+
loadConfigFile(
243+
std::string_view fileName,
244+
std::string_view extraYaml,
245+
std::error_code& ec);
246+
247+
/** Return a configuration by loading a YAML file.
248+
249+
This function attemtps to load the given
250+
YAML file and apply the settings to create
251+
a configuration. The working directory of
252+
the config object will be set to the
253+
directory containing the file.
254+
255+
@return A valid object upon success.
256+
257+
@param fileName A full or relative path to
258+
the configuration file, which may have any
259+
extension including no extension.
260+
261+
@param ec [out] Set to the error, if any occurred.
262+
*/
263+
inline
264+
std::shared_ptr<Config const>
265+
loadConfigFile(
266+
std::string_view fileName,
267+
std::error_code& ec)
268+
{
269+
return loadConfigFile(fileName, "", ec);
270+
}
271+
272+
/** Create a configuration by loading a YAML string.
273+
274+
This function attempts to parse the given
275+
YAML string and apply the results to create
276+
a configuration. The working directory of
277+
the config object will be set to the specified
278+
full path. If the specified path is empty,
279+
then the current working directory of the
280+
process will be used instead.
281+
282+
@return A valid object upon success.
283+
284+
@param workingDir The directory which
285+
should be considered the working directory
286+
for calculating filenames from relative
287+
paths.
288+
289+
@param configYaml A string containing valid
290+
YAML which will be parsed and applied to create
291+
the configuration.
292+
293+
@param ec [out] Set to the error, if any occurred.
294+
*/
295+
MRDOX_DECL
296+
std::shared_ptr<Config const>
297+
loadConfigString(
298+
std::string_view workingDir,
299+
std::string_view configYaml,
300+
std::error_code& ec);
301+
302+
//------------------------------------------------
303+
327304
} // mrdox
328305
} // clang
329306

include/mrdox/Corpus.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ class MRDOX_VISIBLE
4545

4646
/** Return the Config used to generate this corpus.
4747
*/
48+
MRDOX_DECL
4849
virtual
4950
std::shared_ptr<Config const> const&
5051
config() const noexcept = 0;
5152

52-
/** Return the list of all uniquely identified symbols.
53+
/** Return a sorted index of all
5354
*/
5455
MRDOX_DECL
5556
virtual
5657
std::vector<Info const*> const&
57-
allSymbols() const noexcept = 0;
58+
index() const noexcept = 0;
5859

5960
/** Return the metadata for the global namespace.
6061
*/

0 commit comments

Comments
 (0)