Fixed include diagram test cases
This commit is contained in:
@@ -31,4 +31,10 @@ template <> id_t to_id(const clang::TemplateSpecializationType &t)
|
||||
{
|
||||
return t.getTemplateName().getAsTemplateDecl()->getID();
|
||||
}
|
||||
|
||||
template <> id_t to_id(const std::filesystem::path &file)
|
||||
{
|
||||
return std::hash<std::string>{}(file.lexically_normal()) >> 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <clang/AST/RecursiveASTVisitor.h>
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
namespace clang {
|
||||
class NamespaceDecl;
|
||||
@@ -49,4 +50,5 @@ template <> id_t to_id(const clang::EnumType &type);
|
||||
|
||||
template <> id_t to_id(const clang::TemplateSpecializationType &type);
|
||||
|
||||
template <> id_t to_id(const std::filesystem::path &type);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "util/error.h"
|
||||
#include "util/util.h"
|
||||
|
||||
//#include <cppast/libclang_parser.hpp>
|
||||
#include <clang/Frontend/CompilerInstance.h>
|
||||
#include <clang/Tooling/CompilationDatabase.h>
|
||||
#include <clang/Tooling/Tooling.h>
|
||||
@@ -262,8 +261,6 @@ public:
|
||||
|
||||
virtual void HandleTranslationUnit(clang::ASTContext &ast_context)
|
||||
{
|
||||
// const auto* tud = ast_context.getTranslationUnitDecl();
|
||||
//// tud->dump();
|
||||
visitor_.TraverseDecl(ast_context.getTranslationUnitDecl());
|
||||
visitor_.finalize();
|
||||
}
|
||||
@@ -280,14 +277,31 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
|
||||
clang::CompilerInstance &CI, clang::StringRef file)
|
||||
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
|
||||
clang::CompilerInstance &CI, clang::StringRef file) override
|
||||
{
|
||||
return std::make_unique<
|
||||
diagram_ast_consumer<DiagramModel, DiagramConfig, DiagramVisitor>>(
|
||||
CI, diagram_, config_);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool BeginSourceFileAction(clang::CompilerInstance &ci) override
|
||||
{
|
||||
if constexpr (std::is_same_v<DiagramModel,
|
||||
clanguml::include_diagram::model::diagram>) {
|
||||
auto find_includes_callback =
|
||||
std::make_unique<typename DiagramVisitor::include_visitor>(
|
||||
ci.getSourceManager(), diagram_, config_);
|
||||
|
||||
clang::Preprocessor &pp = ci.getPreprocessor();
|
||||
|
||||
pp.addPPCallbacks(std::move(find_includes_callback));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
DiagramModel &diagram_;
|
||||
const DiagramConfig &config_;
|
||||
@@ -338,28 +352,12 @@ std::unique_ptr<DiagramModel> generate(
|
||||
std::back_inserter(translation_units));
|
||||
}
|
||||
|
||||
// DiagramVisitor visitor(db, *diagram, config);
|
||||
|
||||
clang::tooling::ClangTool clang_tool(db, translation_units);
|
||||
auto action_factory =
|
||||
std::make_unique<diagram_action_visitor_factory<DiagramModel,
|
||||
DiagramConfig, DiagramVisitor>>(*diagram, config);
|
||||
clang_tool.run(action_factory.get());
|
||||
|
||||
/*
|
||||
cppast::cpp_entity_index idx;
|
||||
auto logger =
|
||||
verbose ? cppast::default_logger() : cppast::default_quiet_logger();
|
||||
cppast::simple_file_parser<cppast::libclang_parser> parser{
|
||||
type_safe::ref(idx), std::move(logger)};
|
||||
|
||||
// Process all matching translation units
|
||||
DiagramVisitor ctx(idx, *diagram, config);
|
||||
cppast::parse_files(parser, translation_units, db);
|
||||
for (auto &file : parser.files())
|
||||
ctx(file);
|
||||
*/
|
||||
|
||||
diagram->set_complete(true);
|
||||
|
||||
return diagram;
|
||||
|
||||
@@ -357,6 +357,10 @@ tvl::value_t paths_filter::match(
|
||||
return {};
|
||||
}
|
||||
|
||||
// Matching source paths doesn't make sens if they are not absolute
|
||||
if(!p.is_absolute())
|
||||
return {};
|
||||
|
||||
auto pp = p.fs_path(root_);
|
||||
for (const auto &path : paths_) {
|
||||
if (util::starts_with(pp, path))
|
||||
|
||||
@@ -238,8 +238,9 @@ private:
|
||||
// of matching elements
|
||||
for (const auto &template_root : roots_) {
|
||||
auto template_ref = detail::get<ElementT>(cd, template_root);
|
||||
if (template_ref.has_value())
|
||||
if (template_ref.has_value()) {
|
||||
matching_elements_.emplace(template_ref.value());
|
||||
}
|
||||
}
|
||||
|
||||
assert(roots_.empty() == matching_elements_.empty());
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "common/clang_utils.h"
|
||||
#include "common/model/diagram_element.h"
|
||||
#include "common/model/nested_trait.h"
|
||||
#include "common/model/path.h"
|
||||
@@ -51,17 +52,20 @@ class source_file
|
||||
public:
|
||||
source_file() = default;
|
||||
|
||||
source_file(const std::filesystem::path &p)
|
||||
explicit source_file(const std::filesystem::path &p)
|
||||
{
|
||||
set_path({p.parent_path().string()});
|
||||
set_name(p.filename());
|
||||
is_absolute_ = p.is_absolute();
|
||||
set_id(common::to_id(p));
|
||||
}
|
||||
|
||||
void set_path(const filesystem_path &p) { path_ = p; }
|
||||
|
||||
void set_absolute() { is_absolute_ = true; }
|
||||
|
||||
bool is_absolute() const { return is_absolute_; }
|
||||
|
||||
void set_type(source_file_t type) { type_ = type; }
|
||||
|
||||
source_file_t type() const { return type_; }
|
||||
@@ -71,6 +75,12 @@ public:
|
||||
source_file &operator=(const source_file &) = delete;
|
||||
source_file &operator=(source_file &&) = delete;
|
||||
|
||||
bool operator==(const source_file &right) const
|
||||
{
|
||||
return (path_ == right.path_) && (name() == right.name()) &&
|
||||
(type_ == right.type_);
|
||||
}
|
||||
|
||||
const filesystem_path &path() const { return path_; }
|
||||
|
||||
std::string full_name(bool /*relative*/) const override
|
||||
|
||||
Reference in New Issue
Block a user