30
30
#include < clang/ASTMatchers/ASTMatchersInternal.h>
31
31
#include < clang/Driver/Options.h>
32
32
#include < clang/Frontend/FrontendActions.h>
33
+ #include < clang/Tooling/AllTUsExecution.h>
33
34
#include < clang/Tooling/CommonOptionsParser.h>
35
+ #include < clang/Tooling/JSONCompilationDatabase.h>
34
36
#include < clang/Tooling/Execution.h>
35
37
#include < clang/Tooling/Tooling.h>
36
38
#include < llvm/ADT/APFloat.h>
41
43
#include < llvm/Support/Process.h>
42
44
#include < llvm/Support/Signals.h>
43
45
#include < llvm/Support/raw_ostream.h>
46
+ #include < memory>
44
47
#include < string>
45
48
46
49
// VFALCO GARBAGE
@@ -56,13 +59,10 @@ namespace {
56
59
const char * Overview =
57
60
R"( Generates documentation from source code and comments.
58
61
59
- Example usage for files without flags (default):
62
+ Examples
60
63
61
- $ mrdox File1.cpp File2.cpp ... FileN.cpp
62
-
63
- Example usage for a project using a compile commands database:
64
-
65
- $ mrdox --executor=all-TUs compile_commands.json
64
+ $ mrdox mrdox.yml
65
+ $ mrdox --output ./docs mrdox.yml
66
66
)" ;
67
67
68
68
static
@@ -74,13 +74,6 @@ static
74
74
llvm::cl::OptionCategory
75
75
ToolCategory (" mrdox options" );
76
76
77
- static
78
- llvm::cl::opt<std::string>
79
- ProjectName (
80
- " project-name" ,
81
- llvm::cl::desc (" Name of project." ),
82
- llvm::cl::cat(ToolCategory));
83
-
84
77
static
85
78
llvm::cl::opt<bool >
86
79
IgnoreMappingFailures (
@@ -94,32 +87,7 @@ llvm::cl::opt<std::string>
94
87
OutDirectory (
95
88
" output" ,
96
89
llvm::cl::desc (" Directory for outputting generated files." ),
97
- llvm::cl::init(" docs" ),
98
- llvm::cl::cat(ToolCategory));
99
-
100
- static
101
- llvm::cl::opt<bool >
102
- PublicOnly (
103
- " public" ,
104
- llvm::cl::desc (" Document only public declarations." ),
105
- llvm::cl::init(false ),
106
- llvm::cl::cat(ToolCategory));
107
-
108
- static
109
- llvm::cl::opt<std::string>
110
- SourceRoot (
111
- " source-root" , llvm::cl::desc(R"(
112
- Directory where processed files are stored.
113
- Links to definition locations will only be
114
- generated if the file is in this dir.)" ),
115
- llvm::cl::cat(ToolCategory));
116
-
117
- static
118
- llvm::cl::opt<std::string>
119
- RepositoryUrl (
120
- " repository" , llvm::cl::desc(R"(
121
- URL of repository that hosts code.
122
- Used for links to definition locations.)" ),
90
+ llvm::cl::init(" ." ),
123
91
llvm::cl::cat(ToolCategory));
124
92
125
93
enum OutputFormatTy
@@ -158,39 +126,27 @@ getFormatString()
158
126
159
127
// ------------------------------------------------
160
128
161
- bool
162
- setupConfig (
163
- Config& cfg,
164
- llvm::SmallVectorImpl<llvm::StringRef> const & args,
165
- Reporter& R)
129
+ int
130
+ toolMain (int argc, const char ** argv)
166
131
{
167
- llvm::SmallVector<char const *> argv;
168
- for (auto const & s : args)
169
- argv.push_back (s.data ());
170
- int argc = argv.size ();
132
+ // VFALCO GARBAGE
133
+ force_xml_generator_linkage ();
171
134
172
- // create executor
173
- {
174
- Result rv = clang::tooling::createExecutorFromCommandLineArgs (
175
- argc, argv.begin (), ToolCategory, Overview);
176
- if (! rv)
177
- {
178
- R.fail (" createExecutorFromCommandLineArgs" , rv);
179
- return false ;
180
- }
181
- cfg.Executor = std::move (*rv);
182
- }
135
+ Config cfg;
136
+ Corpus corpus;
137
+ Reporter R;
138
+ ErrorCode ec;
183
139
184
- // Fail early if an invalid format was provided.
185
- std::string Format = getFormatString ();
140
+ // parse command line options
186
141
{
187
- Result rv = findGeneratorByName (Format);
142
+ Result rv = tooling::CommonOptionsParser::create (
143
+ argc, argv, ToolCategory, llvm::cl::OneOrMore, Overview);
188
144
if (! rv)
189
145
{
190
- R.fail (" findGeneratorByName " , rv);
191
- return false ;
146
+ R.fail (" CommonOptionsParser::create " , rv);
147
+ return EXIT_FAILURE ;
192
148
}
193
- cfg.G = std::move (*rv);
149
+ cfg.options = std::make_unique<tooling::CommonOptionsParser>( std:: move (*rv) );
194
150
}
195
151
196
152
/*
@@ -202,54 +158,26 @@ setupConfig(
202
158
cfg.ArgAdjuster);
203
159
*/
204
160
205
- cfg.ProjectName = ProjectName;
206
- cfg.PublicOnly = PublicOnly;
161
+ cfg.PublicOnly = true ;
207
162
cfg.OutDirectory = OutDirectory;
208
- cfg.SourceRoot = SourceRoot;
209
- cfg.RepositoryUrl = RepositoryUrl;
210
163
cfg.IgnoreMappingFailures = IgnoreMappingFailures;
211
- cfg.OutDirectory = OutDirectory;
212
164
213
- return true ;
214
- }
215
-
216
- bool
217
- setupConfig (
218
- Config& cfg,
219
- int argc, const char ** argv,
220
- Reporter& R)
221
- {
222
- llvm::SmallVector<llvm::StringRef, 16 > args;
223
- for (int i = 0 ; i < argc; ++i)
224
- args.push_back (argv[i]);
225
- return setupConfig (cfg, args, R);
226
- }
227
-
228
- // ------------------------------------------------
229
-
230
- int
231
- toolMain (int argc, const char ** argv)
232
- {
233
- // VFALCO GARBAGE
234
- force_xml_generator_linkage ();
235
-
236
- Config cfg;
237
- Corpus corpus;
238
- Reporter R;
239
- ErrorCode ec;
165
+ // create the executor
166
+ cfg.Executor = std::make_unique<tooling::AllTUsToolExecutor>(
167
+ cfg.options ->getCompilations (), 0 );
240
168
169
+ // create the generator
170
+ std::unique_ptr<Generator> G;
241
171
{
242
- Result rv = tooling::CommonOptionsParser::create (
243
- argc, argv, ToolCategory, llvm::cl::OneOrMore, Overview );
172
+ std::string Format = getFormatString ();
173
+ Result rv = findGeneratorByName (Format );
244
174
if (! rv)
245
175
{
246
- R.fail (" CommonOptionsParser::create " , rv);
247
- return EXIT_FAILURE ;
176
+ R.fail (" findGeneratorByName " , rv);
177
+ return false ;
248
178
}
249
-
179
+ G = std::move (*rv);
250
180
}
251
- if (! setupConfig (cfg, argc, argv, R))
252
- return EXIT_FAILURE;
253
181
254
182
// Extract the AST first
255
183
if (llvm::Error err = doMapping (corpus, cfg))
@@ -281,7 +209,7 @@ toolMain(int argc, const char** argv)
281
209
282
210
// Run the generator.
283
211
llvm::outs () << " Generating docs...\n " ;
284
- if (auto Err = cfg. G ->generateDocs (
212
+ if (auto Err = G->generateDocs (
285
213
cfg.OutDirectory ,
286
214
corpus,
287
215
cfg))
@@ -295,7 +223,7 @@ toolMain(int argc, const char** argv)
295
223
//
296
224
{
297
225
llvm::outs () << " Generating assets for docs...\n " ;
298
- auto Err = cfg. G ->createResources (cfg, corpus);
226
+ auto Err = G->createResources (cfg, corpus);
299
227
if (Err) {
300
228
llvm::errs () << toString (std::move (Err)) << " \n " ;
301
229
return EXIT_FAILURE;
0 commit comments