@@ -247,6 +247,22 @@ sortUsrToInfo(llvm::StringMap<std::unique_ptr<doc::Info>> &USRToInfo) {
247247 }
248248}
249249
250+ llvm::Error runMappingPhase (tooling::ToolExecutor *Executor,
251+ clang::doc::ClangDocContext &CDCtx, tooling::ArgumentsAdjuster &ArgAdjuster, bool IgnoreMappingFailures ) {
252+ auto Err =
253+ Executor->execute (doc::newMapperActionFactory (CDCtx), ArgAdjuster);
254+ if (Err) {
255+ if (IgnoreMappingFailures) {
256+ llvm::errs () << " Error mapping decls in files. Clang-doc will ignore "
257+ " these files and continue:\n "
258+ << toString (std::move (Err)) << " \n " ;
259+ return llvm::Error::success ();
260+ }
261+ return Err;
262+ }
263+ return llvm::Error::success ();
264+ }
265+
250266int main (int argc, const char **argv) {
251267 llvm::sys::PrintStackTraceOnErrorSignal (argv[0 ]);
252268 std::error_code OK;
@@ -265,13 +281,10 @@ Example usage for a project using a compile commands database:
265281 $ clang-doc --executor=all-TUs compile_commands.json
266282)" ;
267283
268- auto Executor = clang::tooling::createExecutorFromCommandLineArgs (
269- argc, argv, ClangDocCategory, Overview);
284+ auto Executor = ExitOnErr (clang::tooling::createExecutorFromCommandLineArgs (
285+ argc, argv, ClangDocCategory, Overview));
286+
270287
271- if (!Executor) {
272- llvm::errs () << toString (Executor.takeError ()) << " \n " ;
273- return 1 ;
274- }
275288
276289 // Fail early if an invalid format was provided.
277290 std::string Format = getFormatString ();
@@ -286,7 +299,7 @@ Example usage for a project using a compile commands database:
286299 ArgAdjuster);
287300
288301 clang::doc::ClangDocContext CDCtx = {
289- Executor->get ()-> getExecutionContext (),
302+ Executor->getExecutionContext (),
290303 ProjectName,
291304 PublicOnly,
292305 OutDirectory,
@@ -306,24 +319,14 @@ Example usage for a project using a compile commands database:
306319
307320 // Mapping phase
308321 llvm::outs () << " Mapping decls...\n " ;
309- auto Err =
310- Executor->get ()->execute (doc::newMapperActionFactory (CDCtx), ArgAdjuster);
311- if (Err) {
312- if (IgnoreMappingFailures)
313- llvm::errs () << " Error mapping decls in files. Clang-doc will ignore "
314- " these files and continue:\n "
315- << toString (std::move (Err)) << " \n " ;
316- else {
317- ExitOnErr (std::move (Err));
318- }
319- }
322+ ExitOnErr (runMappingPhase (Executor.get (), CDCtx, ArgAdjuster, IgnoreMappingFailures));
320323
321324 // Collect values into output by key.
322325 // In ToolResults, the Key is the hashed USR and the value is the
323326 // bitcode-encoded representation of the Info object.
324327 llvm::outs () << " Collecting infos...\n " ;
325328 llvm::StringMap<std::vector<StringRef>> USRToBitcode;
326- Executor->get ()-> getToolResults ()->forEachResult (
329+ Executor->getToolResults ()->forEachResult (
327330 [&](StringRef Key, StringRef Value) {
328331 USRToBitcode[Key].emplace_back (Value);
329332 });
0 commit comments