33#include "indicators/indicators.hpp"
43#include <clang/Frontend/CompilerInstance.h>
44#include <clang/Tooling/Tooling.h>
132template <
typename DiagramConfig,
typename GeneratorType>
218template <
typename GeneratorTag>
225 case diagram_t::kClass:
228 GeneratorTag>::type>;
229 case diagram_t::kSequence:
232 GeneratorTag>::type>;
233 case diagram_t::kPackage:
236 GeneratorTag>::type>;
237 case diagram_t::kInclude:
240 GeneratorTag>::type>;
262 const std::vector<std::string> &diagram_names,
264 const std::vector<std::string> &compilation_database_files,
265 std::map<std::string, std::vector<std::string>> &translation_units_map);
279template <
typename DiagramModel,
typename DiagramConfig,
280 typename TranslationUnitVisitor>
286 DiagramModel &diagram,
const DiagramConfig &config)
287 :
visitor_{ci.getSourceManager(), diagram, config}
295 visitor_.TraverseDecl(ast_context.getTranslationUnitDecl());
311template <
typename DiagramModel,
typename DiagramConfig,
312 typename DiagramVisitor>
316 const DiagramConfig &config, std::function<
void()> progress)
324 clang::CompilerInstance &CI, clang::StringRef )
override
326 auto ast_consumer = std::make_unique<
330 if constexpr (!std::is_same_v<DiagramModel,
332 ast_consumer->
visitor().set_tu_path(getCurrentFile().str());
341 LOG_DBG(
"Visiting source file: {}", getCurrentFile().str());
348 if constexpr (std::is_same_v<DiagramModel,
350 auto find_includes_callback =
351 std::make_unique<typename DiagramVisitor::include_visitor>(
354 clang::Preprocessor &pp = ci.getPreprocessor();
356 pp.addPPCallbacks(std::move(find_includes_callback));
379template <
typename DiagramModel,
typename DiagramConfig,
380 typename DiagramVisitor>
382 :
public clang::tooling::FrontendActionFactory {
385 const DiagramConfig &config, std::function<
void()> progress)
392 std::unique_ptr<clang::FrontendAction>
create()
override
417template <
typename DiagramModel,
typename DiagramConfig,
418 typename DiagramVisitor>
420 const std::string &name, DiagramConfig &config,
421 const std::vector<std::string> &translation_units,
bool =
false,
422 std::function<
void()> progress = {})
424 LOG_INFO(
"Generating diagram {}", name);
426 auto diagram = std::make_unique<DiagramModel>();
427 diagram->set_name(name);
431 LOG_DBG(
"Found translation units for diagram {}: {}", name,
432 fmt::join(translation_units,
", "));
434 const bool quiet_clang_tool = !!progress;
437 translation_units, config.get_relative_to()(), quiet_clang_tool);
439 auto action_factory =
440 std::make_unique<diagram_action_visitor_factory<DiagramModel,
441 DiagramConfig, DiagramVisitor>>(
442 *diagram, config, std::move(progress));
444 clang_tool.run(action_factory.get());
446 diagram->set_complete(
true);
465 std::shared_ptr<clanguml::config::diagram> diagram,
467 const std::vector<std::string> &translation_units,
469 std::function<
void()> &&progress);
490 const std::map<std::string, std::vector<std::string>>
491 &translation_units_map);