First passing test cases using libtooling visitor
This commit is contained in:
@@ -26,8 +26,6 @@
|
||||
#include "config/config.h"
|
||||
#include "util/util.h"
|
||||
|
||||
#include <cppast/cpp_entity_index.hpp>
|
||||
#include <cppast/libclang_parser.hpp>
|
||||
#include <glob/glob.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,26 +18,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "class_diagram/model/diagram.h"
|
||||
#include "class_diagram/visitor/translation_unit_context.h"
|
||||
//#include "class_diagram/visitor/translation_unit_context.h"
|
||||
#include "common/model/enums.h"
|
||||
#include "config/config.h"
|
||||
|
||||
#include <clang-c/CXCompilationDatabase.h>
|
||||
#include <clang-c/Index.h>
|
||||
#include <cppast/cpp_friend.hpp>
|
||||
#include <cppast/cpp_function_template.hpp>
|
||||
#include <cppast/cpp_member_function.hpp>
|
||||
#include <cppast/cpp_member_variable.hpp>
|
||||
#include <cppast/cpp_template.hpp>
|
||||
#include <cppast/cpp_template_parameter.hpp>
|
||||
#include <cppast/cpp_type.hpp>
|
||||
#include <cppast/visitor.hpp>
|
||||
#include <type_safe/reference.hpp>
|
||||
|
||||
//#include <clang-c/CXCompilationDatabase.h>
|
||||
//#include <clang-c/Index.h>
|
||||
//#include <cppast/cpp_friend.hpp>
|
||||
//#include <cppast/cpp_function_template.hpp>
|
||||
//#include <cppast/cpp_member_function.hpp>
|
||||
//#include <cppast/cpp_member_variable.hpp>
|
||||
//#include <cppast/cpp_template.hpp>
|
||||
//#include <cppast/cpp_template_parameter.hpp>
|
||||
//#include <cppast/cpp_type.hpp>
|
||||
//#include <cppast/visitor.hpp>
|
||||
#include <clang/AST/RecursiveASTVisitor.h>
|
||||
#include <clang/Basic/SourceManager.h>
|
||||
#include <class_diagram/model/class.h>
|
||||
#include <common/model/enums.h>
|
||||
#include <cppast/cpp_alias_template.hpp>
|
||||
#include <cppast/cpp_type_alias.hpp>
|
||||
#include <type_safe/reference.hpp>
|
||||
//#include <cppast/cpp_alias_template.hpp>
|
||||
//#include <cppast/cpp_type_alias.hpp>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
@@ -47,13 +48,88 @@
|
||||
namespace clanguml::class_diagram::visitor {
|
||||
|
||||
using found_relationships_t =
|
||||
std::vector<std::pair<std::string, common::model::relationship_t>>;
|
||||
std::vector<std::pair<clanguml::common::model::element::id_t,
|
||||
common::model::relationship_t>>;
|
||||
|
||||
// class nested_template_relationships {
|
||||
//
|
||||
// std::vector<std::unique_ptr<nested_template_relationships>> children;
|
||||
//};
|
||||
class translation_unit_visitor
|
||||
: public clang::RecursiveASTVisitor<translation_unit_visitor> {
|
||||
public:
|
||||
explicit translation_unit_visitor(clang::SourceManager &sm,
|
||||
clanguml::class_diagram::model::diagram &diagram,
|
||||
const clanguml::config::class_diagram &config);
|
||||
|
||||
virtual bool VisitCXXRecordDecl(clang::CXXRecordDecl *d);
|
||||
|
||||
virtual bool VisitEnumDecl(clang::EnumDecl *e);
|
||||
|
||||
// virtual bool VisitVarDecl(clang::VarDecl *variable_declaration);
|
||||
clanguml::class_diagram::model::diagram &diagram() { return diagram_; }
|
||||
// void operator()();
|
||||
|
||||
private:
|
||||
void process_class_bases(const clang::CXXRecordDecl *cls,
|
||||
clanguml::class_diagram::model::class_ &c) const;
|
||||
|
||||
void process_class_children(const clang::CXXRecordDecl *cls,
|
||||
clanguml::class_diagram::model::class_ &c);
|
||||
|
||||
void process_record_containment(const clang::TagDecl &record,
|
||||
clanguml::common::model::element &c) const;
|
||||
|
||||
void process_method(const clang::CXXMethodDecl &mf,
|
||||
clanguml::class_diagram::model::class_ &c);
|
||||
|
||||
void process_static_field(const clang::VarDecl &field_declaration,
|
||||
clanguml::class_diagram::model::class_ &c);
|
||||
|
||||
void process_field(const clang::FieldDecl &field_declaration,
|
||||
clanguml::class_diagram::model::class_ &c);
|
||||
|
||||
void process_function_parameter(const clang::ParmVarDecl ¶m,
|
||||
clanguml::class_diagram::model::class_method &method,
|
||||
clanguml::class_diagram::model::class_ &c,
|
||||
const std::set<std::string> &template_parameter_names = {});
|
||||
|
||||
bool find_relationships(const clang::QualType &type, &,
|
||||
clanguml::common::model::relationship_t relationship_hint);
|
||||
|
||||
void add_relationships(clanguml::class_diagram::model::class_ &c,
|
||||
const found_relationships_t &relationships,
|
||||
clanguml::common::model::access_t access,
|
||||
std::optional<std::string> label);
|
||||
|
||||
void set_source_location(const clang::Decl &decl,
|
||||
clanguml::common::model::source_location &element);
|
||||
|
||||
template <typename ClangDecl>
|
||||
void process_comment(
|
||||
const ClangDecl &decl, clanguml::common::model::decorated_element &e)
|
||||
{
|
||||
const auto *comment =
|
||||
decl.getASTContext().getRawCommentForDeclNoCache(&decl);
|
||||
|
||||
if (comment != nullptr) {
|
||||
e.set_comment(comment->getBriefText(decl.getASTContext()));
|
||||
|
||||
// if (mf.location().has_value()) {
|
||||
// e.set_file(mf.location().value().file);
|
||||
// e.set_line(mf.location().value().line);
|
||||
// }
|
||||
|
||||
e.add_decorators(decorators::parse(e.comment().value()));
|
||||
}
|
||||
}
|
||||
|
||||
clang::SourceManager &source_manager_;
|
||||
|
||||
// Reference to the output diagram model
|
||||
clanguml::class_diagram::model::diagram &diagram_;
|
||||
|
||||
// Reference to class diagram config
|
||||
const clanguml::config::class_diagram &config_;
|
||||
};
|
||||
|
||||
/*
|
||||
class translation_unit_visitor {
|
||||
public:
|
||||
translation_unit_visitor(cppast::cpp_entity_index &idx,
|
||||
@@ -106,8 +182,8 @@ public:
|
||||
clanguml::class_diagram::model::class_ &c,
|
||||
cppast::cpp_access_specifier_kind as);
|
||||
|
||||
void process_function_parameter(const cppast::cpp_function_parameter ¶m,
|
||||
clanguml::class_diagram::model::class_method &m,
|
||||
void process_function_parameter(const cppast::cpp_function_parameter
|
||||
¶m, clanguml::class_diagram::model::class_method &m,
|
||||
clanguml::class_diagram::model::class_ &c,
|
||||
const std::set<std::string> &template_parameter_names = {});
|
||||
|
||||
@@ -139,28 +215,27 @@ public:
|
||||
|
||||
void process_type_alias_template(const cppast::cpp_alias_template &at);
|
||||
|
||||
void process_class_children(const cppast::cpp_class &cls, model::class_ &c);
|
||||
void process_class_children(const cppast::cpp_class &cls, model::class_
|
||||
&c);
|
||||
|
||||
void process_class_bases(
|
||||
const cppast::cpp_class &cls, model::class_ &c) const;
|
||||
|
||||
void process_unexposed_template_specialization_parameters(
|
||||
const type_safe::optional_ref<const cppast::cpp_template_specialization>
|
||||
&tspec,
|
||||
model::class_ &c) const;
|
||||
const type_safe::optional_ref<const
|
||||
cppast::cpp_template_specialization> &tspec, model::class_ &c) const;
|
||||
|
||||
void process_exposed_template_specialization_parameters(
|
||||
const type_safe::optional_ref<const cppast::cpp_template_specialization>
|
||||
&tspec,
|
||||
model::class_ &c);
|
||||
const type_safe::optional_ref<const
|
||||
cppast::cpp_template_specialization> &tspec, model::class_ &c);
|
||||
|
||||
void process_scope_template_parameters(
|
||||
model::class_ &c, const cppast::cpp_scope_name &scope);
|
||||
|
||||
bool process_template_parameters(const cppast::cpp_class &cls,
|
||||
model::class_ &c,
|
||||
const type_safe::optional_ref<const cppast::cpp_template_specialization>
|
||||
&tspec);
|
||||
const type_safe::optional_ref<const
|
||||
cppast::cpp_template_specialization> &tspec);
|
||||
|
||||
void process_class_containment(
|
||||
const cppast::cpp_class &cls, model::class_ &c) const;
|
||||
@@ -169,19 +244,17 @@ private:
|
||||
std::unique_ptr<clanguml::class_diagram::model::class_>
|
||||
build_template_instantiation(
|
||||
const cppast::cpp_template_instantiation_type &t,
|
||||
std::optional<clanguml::class_diagram::model::class_ *> parent = {});
|
||||
std::optional<clanguml::class_diagram::model::class_ *> parent =
|
||||
{});
|
||||
|
||||
/**
|
||||
* Try to resolve a type instance into a type referenced through an alias.
|
||||
* If t does not represent an alias, returns t.
|
||||
*/
|
||||
const cppast::cpp_type &resolve_alias(const cppast::cpp_type &t);
|
||||
|
||||
const cppast::cpp_type &resolve_alias_template(
|
||||
const cppast::cpp_type &type);
|
||||
|
||||
bool find_relationships_in_array(
|
||||
found_relationships_t &relationships, const cppast::cpp_type &t) const;
|
||||
found_relationships_t &relationships, const cppast::cpp_type &t)
|
||||
const;
|
||||
|
||||
bool find_relationships_in_pointer(const cppast::cpp_type &t_,
|
||||
found_relationships_t &relationships,
|
||||
@@ -196,8 +269,8 @@ private:
|
||||
common::model::relationship_t &relationship_type,
|
||||
const cppast::cpp_type &t) const;
|
||||
|
||||
bool find_relationships_in_template_instantiation(const cppast::cpp_type &t,
|
||||
const std::string &fn, found_relationships_t &relationships,
|
||||
bool find_relationships_in_template_instantiation(const cppast::cpp_type
|
||||
&t, const std::string &fn, found_relationships_t &relationships,
|
||||
common::model::relationship_t relationship_type) const;
|
||||
|
||||
bool find_relationships_in_unexposed_template_params(
|
||||
@@ -207,13 +280,13 @@ private:
|
||||
void build_template_instantiation_primary_template(
|
||||
const cppast::cpp_template_instantiation_type &t,
|
||||
clanguml::class_diagram::model::class_ &tinst,
|
||||
std::deque<std::tuple<std::string, int, bool>> &template_base_params,
|
||||
std::optional<clanguml::class_diagram::model::class_ *> &parent,
|
||||
std::string &full_template_name) const;
|
||||
std::deque<std::tuple<std::string, int, bool>>
|
||||
&template_base_params, std::optional<clanguml::class_diagram::model::class_
|
||||
*> &parent, std::string &full_template_name) const;
|
||||
|
||||
void build_template_instantiation_process_type_argument(
|
||||
const std::optional<clanguml::class_diagram::model::class_ *> &parent,
|
||||
model::class_ &tinst, const cppast::cpp_type &targ_type,
|
||||
const std::optional<clanguml::class_diagram::model::class_ *>
|
||||
&parent, model::class_ &tinst, const cppast::cpp_type &targ_type,
|
||||
class_diagram::model::template_parameter &ct);
|
||||
|
||||
void build_template_instantiation_process_expression_argument(
|
||||
@@ -221,18 +294,19 @@ private:
|
||||
model::template_parameter &ct) const;
|
||||
|
||||
bool build_template_instantiation_add_base_classes(model::class_ &tinst,
|
||||
std::deque<std::tuple<std::string, int, bool>> &template_base_params,
|
||||
int arg_index, bool variadic_params,
|
||||
const model::template_parameter &ct) const;
|
||||
std::deque<std::tuple<std::string, int, bool>>
|
||||
&template_base_params, int arg_index, bool variadic_params, const
|
||||
model::template_parameter &ct) const;
|
||||
|
||||
void process_function_parameter_find_relationships_in_template(
|
||||
model::class_ &c, const std::set<std::string> &template_parameter_names,
|
||||
const cppast::cpp_type &t);
|
||||
model::class_ &c, const std::set<std::string>
|
||||
&template_parameter_names, const cppast::cpp_type &t);
|
||||
|
||||
// ctx allows to track current visitor context, e.g. current namespace
|
||||
translation_unit_context ctx;
|
||||
bool simplify_system_template(
|
||||
model::template_parameter ¶meter, const std::string &basicString);
|
||||
model::template_parameter ¶meter, const std::string
|
||||
&basicString);
|
||||
|
||||
bool add_nested_template_relationships(
|
||||
const cppast::cpp_member_variable &mv, model::class_ &c,
|
||||
@@ -242,4 +316,5 @@ private:
|
||||
common::model::relationship_t &decorator_rtype,
|
||||
std::string &decorator_rmult);
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user