30#include "indicators/indicators.hpp"
40#include <clang/Frontend/CompilerInstance.h>
41#include <clang/Tooling/Tooling.h>
124template <
typename DiagramConfig,
typename GeneratorType>
205 const std::vector<std::string> &diagram_names,
207 const std::vector<std::string> &compilation_database_files,
208 std::map<std::string, std::vector<std::string>> &translation_units_map);
222template <
typename DiagramModel,
typename DiagramConfig,
223 typename TranslationUnitVisitor>
229 DiagramModel &diagram,
const DiagramConfig &config)
230 :
visitor_{ci.getSourceManager(), diagram, config}
238 visitor_.TraverseDecl(ast_context.getTranslationUnitDecl());
254template <
typename DiagramModel,
typename DiagramConfig,
255 typename DiagramVisitor>
259 const DiagramConfig &config, std::function<
void()> progress)
267 clang::CompilerInstance &CI, clang::StringRef )
override
269 auto ast_consumer = std::make_unique<
273 if constexpr (!std::is_same_v<DiagramModel,
275 ast_consumer->
visitor().set_tu_path(getCurrentFile().str());
284 LOG_DBG(
"Visiting source file: {}", getCurrentFile().str());
291 if constexpr (std::is_same_v<DiagramModel,
293 auto find_includes_callback =
294 std::make_unique<typename DiagramVisitor::include_visitor>(
297 clang::Preprocessor &pp = ci.getPreprocessor();
299 pp.addPPCallbacks(std::move(find_includes_callback));
322template <
typename DiagramModel,
typename DiagramConfig,
323 typename DiagramVisitor>
325 :
public clang::tooling::FrontendActionFactory {
328 const DiagramConfig &config, std::function<
void()> progress)
335 std::unique_ptr<clang::FrontendAction>
create()
override
360template <
typename DiagramModel,
typename DiagramConfig,
361 typename DiagramVisitor>
363 const std::string &name, DiagramConfig &config,
364 const std::vector<std::string> &translation_units,
bool =
false,
365 std::function<
void()> progress = {})
367 LOG_INFO(
"Generating diagram {}", name);
369 auto diagram = std::make_unique<DiagramModel>();
370 diagram->set_name(name);
374 LOG_DBG(
"Found translation units for diagram {}: {}", name,
375 fmt::join(translation_units,
", "));
377 clang::tooling::ClangTool clang_tool(db, translation_units);
378 auto action_factory =
379 std::make_unique<diagram_action_visitor_factory<DiagramModel,
380 DiagramConfig, DiagramVisitor>>(
381 *diagram, config, std::move(progress));
383 auto res = clang_tool.run(action_factory.get());
386 throw std::runtime_error(
"Diagram " + name +
" generation failed");
389 diagram->set_complete(
true);
408 std::shared_ptr<clanguml::config::diagram> diagram,
409 const common::compilation_database &db,
410 const std::vector<std::string> &translation_units,
411 const cli::runtime_config &runtime_config,
412 std::function<
void()> &&progress);
430 const cli::runtime_config &runtime_config,
431 const std::map<std::string, std::vector<std::string>>
432 &translation_units_map);