20
20
#include < llvm/Support/Error.h>
21
21
#include < functional>
22
22
#include < memory>
23
- #include < string>
23
+ #include < string_view>
24
+ #include < system_error>
25
+ #include < utility>
26
+ #include < vector>
24
27
25
28
namespace clang {
26
29
namespace mrdox {
@@ -42,15 +45,7 @@ class MRDOX_VISIBLE
42
45
Config& operator =(Config const &) = delete ;
43
46
44
47
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 ;
54
49
55
50
public:
56
51
class Options ; // private, but for clang-15 bug
@@ -63,74 +58,19 @@ class MRDOX_VISIBLE
63
58
*/
64
59
MRDOX_DECL
65
60
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 ;
67
67
68
68
//
69
69
// VFALCO these naked data members are temporary...
70
70
//
71
71
tooling::ArgumentsAdjuster ArgAdjuster;
72
72
bool IgnoreMappingFailures = false ;
73
73
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
-
134
74
/* * Call a function for each element of a range.
135
75
136
76
The function is invoked with a reference
@@ -148,94 +88,39 @@ class MRDOX_VISIBLE
148
88
149
89
// --------------------------------------------
150
90
//
151
- // Modifiers
91
+ // Observers
152
92
//
153
93
// --------------------------------------------
154
94
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;
163
98
164
- void
165
- setSinglePage (
166
- bool singlePage) noexcept
167
- {
168
- singlePage_ = singlePage;
169
- }
99
+ /* * Return the YAML strings which produced this config.
170
100
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.
179
104
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.
189
109
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 .
193
113
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.
197
118
198
- @param dirPath The directory .
119
+ @return The pair of valid YAML strings .
199
120
*/
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 ;
239
124
};
240
125
241
126
// ------------------------------------------------
@@ -306,8 +191,6 @@ class MRDOX_VISIBLE
306
191
std::unique_ptr<Base> impl_;
307
192
};
308
193
309
- // ------------------------------------------------
310
-
311
194
template <class Range , class UnaryFunction >
312
195
void
313
196
Config::
@@ -324,6 +207,100 @@ parallelForEach(
324
207
wg.wait ();
325
208
}
326
209
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
+
327
304
} // mrdox
328
305
} // clang
329
306
0 commit comments