Removed cppast dependency

This commit is contained in:
Bartek Kryza 2022-08-03 22:12:08 +02:00
parent 5917d341e2
commit 487e5d435b
46 changed files with 167 additions and 1230 deletions

View File

@ -8,8 +8,6 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Update package database
run: sudo apt -y update
- name: Install deps

4
.gitmodules vendored
View File

@ -1,4 +0,0 @@
[submodule "thirdparty/cppast"]
path = thirdparty/cppast
url = https://github.com/bkryza/cppast
branch = handle-exposed-template-arguments

View File

@ -44,7 +44,6 @@ message(STATUS "Using CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
# Thirdparty sources
set(THIRDPARTY_HEADERS_DIR ${PROJECT_SOURCE_DIR}/thirdparty/)
add_subdirectory(thirdparty/cppast)
find_package(LLVM REQUIRED CONFIG)
set(CLANG_INCLUDE_DIRS "llvm/clang/include")
@ -76,9 +75,6 @@ include_directories(${CLANG_UML_INSTALL_INCLUDE_DIR})
include_directories(${YAML_CPP_INCLUDE_DIR})
include_directories(${UML_HEADERS_DIR})
include_directories(${THIRDPARTY_HEADERS_DIR})
include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/include)
include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/external/type_safe/include)
include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/external/type_safe/external/debug_assert)
include_directories(${PROJECT_SOURCE_DIR}/src/)
include_directories(${PROJECT_BINARY_DIR}/src/version)
@ -122,7 +118,6 @@ target_link_libraries(clang-uml
${LIBCLANG_LIBRARIES}
${YAML_CPP_LIBRARIES}
${LIBTOOLING_LIBS}
cppast
clang-umllib
Threads::Threads)

View File

@ -70,7 +70,6 @@ Then proceed with building the sources:
```bash
git clone https://github.com/bkryza/clang-uml
cd clang-uml
make submodules
# Please note that top level Makefile is just a convenience wrapper for CMake
make release
release/clang-uml --help
@ -466,8 +465,7 @@ The build-in test cases used for unit testing of the `clang-uml`, can be browsed
## Acknowledgements
This project relies on the following great tools:
* [libclang](https://clang.llvm.org/) - a C/C++ frontend for LLVM
* [cppast](https://github.com/foonathan/cppast) - high-level C++ API for libclang
* [clang](https://clang.llvm.org/) - a C/C++ frontend for LLVM
* [PlantUML](https://plantuml.com/) - language and diagram for generating UML diagrams
* [Catch2](https://github.com/catchorg/Catch2) - C++ unit test framework
* [glob](https://github.com/p-ranav/glob) - Unix style path expansion for C++

View File

@ -25,29 +25,23 @@
namespace clanguml::class_diagram::model {
const std::vector<std::reference_wrapper<class_>> &diagram::classes() const
const common::reference_vector<class_> &diagram::classes() const
{
return classes_;
}
const std::vector<std::reference_wrapper<enum_>> &diagram::enums() const
{
return enums_;
}
const common::reference_vector<enum_> &diagram::enums() const { return enums_; }
common::model::diagram_t diagram::type() const
{
return common::model::diagram_t::kClass;
}
std::optional<std::reference_wrapper<clanguml::common::model::diagram_element>>
diagram::get(const std::string &full_name) const
common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
const std::string &full_name) const
{
std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
res;
res = get_class(full_name);
common::optional_ref<clanguml::common::model::diagram_element> res =
get_class(full_name);
if (res.has_value())
return res;
@ -57,12 +51,10 @@ diagram::get(const std::string &full_name) const
return res;
}
std::optional<std::reference_wrapper<clanguml::common::model::diagram_element>>
diagram::get(const clanguml::common::model::diagram_element::id_t id) const
common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
const clanguml::common::model::diagram_element::id_t id) const
{
std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
res;
common::optional_ref<clanguml::common::model::diagram_element> res;
res = get_class(id);
@ -86,8 +78,7 @@ bool diagram::has_enum(const enum_ &e) const
[&e](const auto &ee) { return ee.get().full_name() == e.full_name(); });
}
std::optional<std::reference_wrapper<class_>> diagram::get_class(
const std::string &name) const
common::optional_ref<class_> diagram::get_class(const std::string &name) const
{
for (const auto &c : classes_) {
const auto full_name = c.get().full_name(false);
@ -100,7 +91,7 @@ std::optional<std::reference_wrapper<class_>> diagram::get_class(
return {};
}
std::optional<std::reference_wrapper<class_>> diagram::get_class(
common::optional_ref<class_> diagram::get_class(
clanguml::common::model::diagram_element::id_t id) const
{
for (const auto &c : classes_) {
@ -112,8 +103,7 @@ std::optional<std::reference_wrapper<class_>> diagram::get_class(
return {};
}
std::optional<std::reference_wrapper<enum_>> diagram::get_enum(
const std::string &name) const
common::optional_ref<enum_> diagram::get_enum(const std::string &name) const
{
for (const auto &e : enums_) {
if (e.get().full_name(false) == name) {
@ -124,7 +114,7 @@ std::optional<std::reference_wrapper<enum_>> diagram::get_enum(
return {};
}
std::optional<std::reference_wrapper<enum_>> diagram::get_enum(
common::optional_ref<enum_> diagram::get_enum(
clanguml::common::model::diagram_element::id_t id) const
{
for (const auto &e : enums_) {
@ -176,11 +166,9 @@ bool diagram::add_class(std::unique_ptr<class_> &&c)
auto name_and_ns = ns | name;
auto &cc = *c;
auto cc_ref = std::ref(cc);
if (!has_class(cc)) {
if (add_element(ns, std::move(c)))
classes_.push_back(std::move(cc_ref));
classes_.push_back(std::ref(cc));
const auto &el = get_element<class_>(name_and_ns).value();

View File

@ -45,32 +45,28 @@ public:
common::model::diagram_t type() const override;
std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
get(const std::string &full_name) const override;
common::optional_ref<common::model::diagram_element> get(
const std::string &full_name) const override;
std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
get(const clanguml::common::model::diagram_element::id_t id) const override;
common::optional_ref<common::model::diagram_element> get(
const clanguml::common::model::diagram_element::id_t id) const override;
const std::vector<std::reference_wrapper<class_>> &classes() const;
const common::reference_vector<class_> &classes() const;
const std::vector<std::reference_wrapper<enum_>> &enums() const;
const common::reference_vector<enum_> &enums() const;
bool has_class(const class_ &c) const;
bool has_enum(const enum_ &e) const;
std::optional<std::reference_wrapper<class_>> get_class(
const std::string &name) const;
common::optional_ref<class_> get_class(const std::string &name) const;
std::optional<std::reference_wrapper<class_>> get_class(
common::optional_ref<class_> get_class(
clanguml::common::model::diagram_element::id_t id) const;
std::optional<std::reference_wrapper<enum_>> get_enum(
const std::string &name) const;
common::optional_ref<enum_> get_enum(const std::string &name) const;
std::optional<std::reference_wrapper<enum_>> get_enum(
common::optional_ref<enum_> get_enum(
clanguml::common::model::diagram_element::id_t id) const;
void add_type_alias(std::unique_ptr<type_alias> &&ta);
@ -92,9 +88,9 @@ public:
const clanguml::common::model::diagram_element::id_t id) const override;
private:
std::vector<std::reference_wrapper<class_>> classes_;
common::reference_vector<class_> classes_;
std::vector<std::reference_wrapper<enum_>> enums_;
common::reference_vector<enum_> enums_;
std::map<std::string, std::unique_ptr<type_alias>> type_aliases_;
};

View File

@ -1,57 +0,0 @@
/**
* src/class_diagram/model/visitor/element_visitor_context.cc
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "element_visitor_context.h"
#include "translation_unit_context.h"
namespace clanguml::class_diagram::visitor {
template <typename T>
element_visitor_context<T>::element_visitor_context(
clanguml::class_diagram::model::diagram &diagram, T &element)
: element_{element}
, diagram_{diagram}
{
}
template <typename T>
void element_visitor_context<T>::set_parent_class(
clanguml::class_diagram::model::class_ *parent_class)
{
parent_class_ = parent_class;
}
template <typename T>
clanguml::class_diagram::model::class_ *
element_visitor_context<T>::parent_class()
{
return parent_class_;
}
template <typename T> T &element_visitor_context<T>::element()
{
return element_;
}
template <typename T>
clanguml::class_diagram::model::diagram &element_visitor_context<T>::diagram()
{
return diagram_;
}
}

View File

@ -1,48 +0,0 @@
/**
* src/class_diagram/model/visitor/element_visitor_context.h
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "class_diagram/model/class.h"
#include "class_diagram/model/diagram.h"
namespace clanguml::class_diagram::visitor {
class translation_unit_context;
template <typename T> class element_visitor_context {
public:
element_visitor_context(
clanguml::class_diagram::model::diagram &diagram, T &element);
void set_parent_class(clanguml::class_diagram::model::class_ *parent_class);
clanguml::class_diagram::model::class_ *parent_class();
T &element();
clanguml::class_diagram::model::diagram &diagram();
private:
translation_unit_context *ctx_;
T &element_;
clanguml::class_diagram::model::class_ *parent_class_{};
clanguml::class_diagram::model::diagram &diagram_;
};
}

View File

@ -1,273 +0,0 @@
/**
* src/class_diagram/visitor/translation_unit_context.cc
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "translation_unit_context.h"
#include "cx/util.h"
namespace clanguml::class_diagram::visitor {
translation_unit_context::translation_unit_context(
cppast::cpp_entity_index &idx,
clanguml::class_diagram::model::diagram &diagram,
const clanguml::config::class_diagram &config)
: entity_index_{idx}
, diagram_{diagram}
, config_{config}
{
}
bool translation_unit_context::has_namespace_alias(
const std::string &full_name) const
{
bool res =
namespace_alias_index_.find(full_name) != namespace_alias_index_.end();
LOG_DBG("Alias {} {} found in index", full_name, res ? "" : "not");
return res;
}
void translation_unit_context::add_namespace_alias(const std::string &full_name,
type_safe::object_ref<const cppast::cpp_namespace> ref)
{
if (!has_namespace_alias(full_name)) {
LOG_DBG(
"Stored namespace alias: {} -> {} ", full_name, ref.get().name());
namespace_alias_index_.emplace(full_name, std::move(ref));
}
}
type_safe::object_ref<const cppast::cpp_namespace>
translation_unit_context::get_namespace_alias(
const std::string &full_name) const
{
assert(has_namespace_alias(full_name));
return namespace_alias_index_.at(full_name);
}
type_safe::object_ref<const cppast::cpp_namespace>
translation_unit_context::get_namespace_alias_final(
const cppast::cpp_namespace &ns) const
{
auto ns_full_name = cx::util::full_name({}, ns);
ns_full_name = cx::util::ns(ns) + "::" + ns_full_name;
if (has_namespace_alias(ns_full_name)) {
return get_namespace_alias_final(
namespace_alias_index_.at(ns_full_name).get());
}
return type_safe::ref(ns);
}
bool translation_unit_context::has_type_alias(
const std::string &full_name) const
{
bool res = alias_index_.find(full_name) != alias_index_.end();
LOG_DBG("Alias {} {} found in index", full_name, res ? "" : "not");
return res;
}
void translation_unit_context::add_type_alias(const std::string &full_name,
type_safe::object_ref<const cppast::cpp_type> &&ref)
{
if (!has_type_alias(full_name)) {
LOG_DBG("Stored type alias: {} -> {} ", full_name,
cppast::to_string(ref.get()));
alias_index_.emplace(full_name, std::move(ref));
}
}
type_safe::object_ref<const cppast::cpp_type>
translation_unit_context::get_type_alias(const std::string &full_name) const
{
assert(has_type_alias(full_name));
return alias_index_.at(full_name);
}
type_safe::object_ref<const cppast::cpp_type>
translation_unit_context::get_type_alias_final(const cppast::cpp_type &t) const
{
const auto type_full_name =
cx::util::full_name(cppast::remove_cv(t), entity_index_, false);
if (has_type_alias(type_full_name)) {
const auto &alias_type = alias_index_.at(type_full_name).get();
// Prevent infinite recursion
if (type_full_name !=
cx::util::full_name(
cppast::remove_cv(alias_type), entity_index_, false))
return get_type_alias_final(alias_type);
}
return type_safe::ref(t);
}
bool translation_unit_context::has_type_alias_template(
const std::string &full_name) const
{
bool res =
alias_template_index_.find(full_name) != alias_template_index_.end();
LOG_DBG("Alias template {} {} found in index", full_name, res ? "" : "not");
return res;
}
void translation_unit_context::add_type_alias_template(
const std::string &full_name,
type_safe::object_ref<const cppast::cpp_type> &&ref)
{
if (!has_type_alias_template(full_name)) {
LOG_DBG("Stored type alias template for: {} ", full_name);
alias_template_index_.emplace(full_name, std::move(ref));
}
}
type_safe::object_ref<const cppast::cpp_type>
translation_unit_context::get_type_alias_template(
const std::string &full_name) const
{
assert(has_type_alias_template(full_name));
return alias_template_index_.at(full_name);
}
void translation_unit_context::push_namespace(const std::string &ns)
{
ns_ |= ns;
}
void translation_unit_context::pop_namespace() { ns_.pop_back(); }
const common::model::namespace_ &translation_unit_context::get_namespace() const
{
return ns_;
}
const cppast::cpp_entity_index &translation_unit_context::entity_index() const
{
return entity_index_;
}
const clanguml::config::class_diagram &translation_unit_context::config() const
{
return config_;
}
clanguml::class_diagram::model::diagram &translation_unit_context::diagram()
{
return diagram_;
}
clanguml::class_diagram::model::diagram &
translation_unit_context::diagram() const
{
return diagram_;
}
void translation_unit_context::set_current_package(
type_safe::optional_ref<common::model::package> p)
{
current_package_ = p;
}
type_safe::optional_ref<common::model::package>
translation_unit_context::get_current_package() const
{
return current_package_;
}
void translation_unit_context::add_using_namespace_directive(
common::model::namespace_ ns)
{
using_ns_declarations_[ns_.to_string()].insert(std::move(ns));
}
const std::set<common::model::namespace_> &
translation_unit_context::using_namespace_directive(
const common::model::namespace_ &ns) const
{
return using_ns_declarations_.at(ns.to_string());
}
type_safe::optional<common::model::namespace_>
translation_unit_context::get_name_with_namespace(const std::string &name) const
{
using common::model::namespace_;
std::set<namespace_> possible_matches;
possible_matches.emplace(name);
possible_matches.emplace(get_namespace() | namespace_{name});
auto parent = get_namespace().parent();
while (parent.has_value()) {
possible_matches.emplace(parent.value() | namespace_{name});
parent = parent.value().parent();
}
if (using_ns_declarations_.find(get_namespace().to_string()) !=
using_ns_declarations_.end()) {
for (const auto &ns :
using_ns_declarations_.at(get_namespace().to_string())) {
possible_matches.emplace(ns | namespace_{name});
auto parent = ns.parent();
while (parent.has_value()) {
possible_matches.emplace(parent.value() | namespace_{name});
parent = parent.value().parent();
}
}
}
// Search classes
for (const auto &c : diagram_.classes()) {
auto c_ns = namespace_{c->name_and_ns()};
for (const auto &possible_match : possible_matches) {
if (c_ns == possible_match) {
return possible_match;
}
}
}
// Search enums
for (const auto &e : diagram_.enums()) {
auto e_ns = namespace_{e->name_and_ns()};
for (const auto &possible_match : possible_matches) {
if (e_ns == possible_match) {
return possible_match;
}
// Try to also match possible references to enum values
else if (possible_match.starts_with(e_ns)) {
return possible_match;
}
}
}
return {};
}
}

View File

@ -1,127 +0,0 @@
/**
* src/class_diagram/visitor/translation_unit_context.h
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "config/config.h"
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_namespace.hpp>
#include <cppast/cpp_type.hpp>
#include <type_safe/reference.hpp>
namespace clanguml::class_diagram::visitor {
class translation_unit_context {
public:
translation_unit_context(cppast::cpp_entity_index &idx,
clanguml::class_diagram::model::diagram &diagram,
const clanguml::config::class_diagram &config);
bool has_namespace_alias(const std::string &full_name) const;
void add_namespace_alias(const std::string &full_name,
type_safe::object_ref<const cppast::cpp_namespace> ref);
type_safe::object_ref<const cppast::cpp_namespace> get_namespace_alias(
const std::string &full_name) const;
type_safe::object_ref<const cppast::cpp_namespace>
get_namespace_alias_final(const cppast::cpp_namespace &t) const;
bool has_type_alias(const std::string &full_name) const;
void add_type_alias(const std::string &full_name,
type_safe::object_ref<const cppast::cpp_type> &&ref);
type_safe::object_ref<const cppast::cpp_type> get_type_alias(
const std::string &full_name) const;
type_safe::object_ref<const cppast::cpp_type> get_type_alias_final(
const cppast::cpp_type &t) const;
bool has_type_alias_template(const std::string &full_name) const;
void add_type_alias_template(const std::string &full_name,
type_safe::object_ref<const cppast::cpp_type> &&ref);
type_safe::object_ref<const cppast::cpp_type> get_type_alias_template(
const std::string &full_name) const;
void push_namespace(const std::string &ns);
void pop_namespace();
const common::model::namespace_ &get_namespace() const;
const cppast::cpp_entity_index &entity_index() const;
const clanguml::config::class_diagram &config() const;
clanguml::class_diagram::model::diagram &diagram();
clanguml::class_diagram::model::diagram &diagram() const;
void set_current_package(type_safe::optional_ref<common::model::package> p);
type_safe::optional_ref<common::model::package> get_current_package() const;
void add_using_namespace_directive(common::model::namespace_ ns);
const std::set<common::model::namespace_> &using_namespace_directive(
const common::model::namespace_ &ns) const;
type_safe::optional<common::model::namespace_> get_name_with_namespace(
const std::string &name) const;
private:
// Current visitor namespace
common::model::namespace_ ns_;
// A map of 'using namespace' declared within a given namespace scope
// This is necessary to properly establish the namespace of a given entity
// for instance in unexposed template parameters
// - key - namespace
// - value - set of namespaces 'imported' within this namespace scope
std::map<std::string, std::set<common::model::namespace_>>
using_ns_declarations_;
// Reference to the cppast entity index
cppast::cpp_entity_index &entity_index_;
// Reference to the output diagram model
clanguml::class_diagram::model::diagram &diagram_;
// Reference to class diagram config
const clanguml::config::class_diagram &config_;
// Map of discovered aliases (declared with 'namespace' keyword)
std::map<std::string, type_safe::object_ref<const cppast::cpp_namespace>>
namespace_alias_index_;
// Map of discovered aliases (declared with 'using' keyword)
std::map<std::string, type_safe::object_ref<const cppast::cpp_type>>
alias_index_;
// Map of discovered template aliases (declared with 'using' keyword)
std::map<std::string, type_safe::object_ref<const cppast::cpp_type>>
alias_template_index_;
type_safe::optional_ref<common::model::package> current_package_;
};
}

View File

@ -1193,7 +1193,7 @@ bool translation_unit_visitor::find_relationships_in_unexposed_template_params(
auto element_opt = diagram().get(type_with_namespace.value().to_string());
if (element_opt) {
relationships.emplace_back(
element_opt.value().get().id(), relationship_t::kDependency);
element_opt.value().id(), relationship_t::kDependency);
found = true;
}

View File

@ -163,9 +163,9 @@ void generator<C, D>::generate_config_layout_hints(std::ostream &ostr) const
if (!element_opt || !hint_element_opt)
continue;
hint_str << element_opt.value().get().alias() << " -[hidden]"
hint_str << element_opt.value().alias() << " -[hidden]"
<< clanguml::config::to_string(hint.hint) << "- "
<< hint_element_opt.value().get().alias() << '\n';
<< hint_element_opt.value().alias() << '\n';
ostr << hint_str.str();
}
catch (clanguml::error::uml_alias_missing &e) {
@ -196,8 +196,7 @@ void generator<C, D>::generate_plantuml_directives(
if (element_opt)
directive.replace(std::get<1>(alias_match),
std::get<2>(alias_match),
element_opt.value().get().alias());
std::get<2>(alias_match), element_opt.value().alias());
else {
LOG_ERROR(
"CANNOT FIND ALIAS TO ELEMENT {}", full_name.to_string());
@ -426,7 +425,7 @@ template <typename C, typename D> void generator<C, D>::init_env()
m_config.using_namespace() | args[0]->get<std::string>();
auto element_opt = m_model.get(alias_match.to_string());
return element_opt.value().get().alias();
return element_opt.value().alias();
});
m_env.add_callback("comment", 1, [this](inja::Arguments &args) {
@ -441,7 +440,7 @@ template <typename C, typename D> void generator<C, D>::init_env()
}
if (element.has_value()) {
auto comment = element.value().get().comment();
auto comment = element.value().comment();
if (comment.has_value())
res = comment.value();

View File

@ -39,13 +39,11 @@ public:
virtual diagram_t type() const = 0;
virtual std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
get(const std::string &full_name) const = 0;
virtual common::optional_ref<clanguml::common::model::diagram_element> get(
const std::string &full_name) const = 0;
virtual std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
get(const diagram_element::id_t id) const = 0;
virtual common::optional_ref<clanguml::common::model::diagram_element> get(
const diagram_element::id_t id) const = 0;
diagram(const diagram &) = delete;
diagram(diagram &&);

View File

@ -295,25 +295,25 @@ tvl::value_t context_filter::match(const diagram &d, const element &e) const
if (context_root.has_value()) {
// This is a direct match to the context root
if (context_root.value().get().id() == e.id())
if (context_root.value().id() == e.id())
return true;
// Return a positive match if the element e is in a direct
// relationship with any of the context_root's
for (const relationship &rel :
context_root.value().get().relationships()) {
context_root.value().relationships()) {
if (rel.destination() == e.id())
return true;
}
for (const relationship &rel : e.relationships()) {
if (rel.destination() == context_root.value().get().id())
if (rel.destination() == context_root.value().id())
return true;
}
// Return a positive match if the context_root is a parent
// of the element
for (const class_diagram::model::class_parent &p :
context_root.value().get().parents()) {
context_root.value().parents()) {
if (p.name() == e.full_name(false))
return true;
}
@ -322,8 +322,7 @@ tvl::value_t context_filter::match(const diagram &d, const element &e) const
for (const class_diagram::model::class_parent &p :
static_cast<const class_diagram::model::class_ &>(e)
.parents()) {
if (p.name() ==
context_root.value().get().full_name(false))
if (p.name() == context_root.value().full_name(false))
return true;
}
}

View File

@ -221,7 +221,7 @@ private:
while (parent.has_value()) {
parents.emplace(std::ref(parent.value()));
parent = detail::get<ElementT, DiagramT>(
cd, parent.value().get().path().to_string());
cd, parent.value().path().to_string());
}
});

View File

@ -19,8 +19,8 @@
#include "path.h"
#include <optional>
#include <string>
#include <type_safe/optional.hpp>
#include <vector>
namespace clanguml::common::model {

View File

@ -19,9 +19,8 @@
#include "util/util.h"
#include <type_safe/optional_ref.hpp>
#include <iostream>
#include <optional>
#include <string>
#include <vector>
@ -84,7 +83,7 @@ public:
if (path.is_empty() || !has_element(path[0])) {
LOG_DBG("Nested element {} not found in element", path.to_string());
return type_safe::optional_ref<V>{};
return optional_ref<V>{};
}
if (path.size() == 1) {
@ -94,13 +93,13 @@ public:
auto p = get_element<T>(path[0]);
if (!p)
return type_safe::optional_ref<V>{};
return optional_ref<V>{};
if (dynamic_cast<nested_trait<T, Path> *>(&p.value()))
return dynamic_cast<nested_trait<T, Path> &>(p.value())
.get_element<V>(Path{path.begin() + 1, path.end()});
return type_safe::optional_ref<V>{};
return optional_ref<V>{};
}
template <typename V = T> auto get_element_parent(const T &element) const
@ -109,10 +108,10 @@ public:
auto parent = get_element(path);
if (parent.has_value())
return type_safe::optional_ref<V>{
type_safe::ref<V>(dynamic_cast<V &>(parent.value()))};
return optional_ref<V>{
std::ref<V>(dynamic_cast<V &>(parent.value()))};
return type_safe::optional_ref<V>{};
return optional_ref<V>{};
}
template <typename V = T> auto get_element(const std::string &name) const
@ -123,15 +122,14 @@ public:
[&](const auto &p) { return name == p->name(); });
if (it == elements_.end())
return type_safe::optional_ref<V>{type_safe::nullopt};
return optional_ref<V>{};
assert(it->get() != nullptr);
if (dynamic_cast<V *>(it->get()))
return type_safe::optional_ref<V>{
type_safe::ref<V>(dynamic_cast<V &>(*it->get()))};
return optional_ref<V>{std::ref<V>(dynamic_cast<V &>(*it->get()))};
return type_safe::optional_ref<V>{type_safe::nullopt};
return optional_ref<V>{};
}
bool has_element(const std::string &name) const

View File

@ -24,7 +24,6 @@
#include "util/util.h"
#include <spdlog/spdlog.h>
#include <type_safe/optional_ref.hpp>
#include <set>
#include <string>

View File

@ -19,8 +19,8 @@
#include "util/util.h"
#include <optional>
#include <string>
#include <type_safe/optional.hpp>
#include <vector>
namespace clanguml::common::model {
@ -130,7 +130,7 @@ public:
void pop_back() { path_.pop_back(); }
type_safe::optional<path> parent() const
std::optional<path> parent() const
{
if (size() <= 1) {
return {};

View File

@ -27,7 +27,6 @@
#include "util/util.h"
#include <spdlog/spdlog.h>
#include <type_safe/optional_ref.hpp>
#include <set>
#include <string>

View File

@ -17,6 +17,7 @@
*/
#pragma once
#include <cassert>
#include <cstdint>
#include <optional>
#include <unordered_set>
@ -26,8 +27,89 @@ namespace clanguml::common {
using id_t = int64_t;
template <typename T>
using optional_ref = std::optional<std::reference_wrapper<T>>;
template <typename T> class optional_ref {
public:
using optional_type = T;
optional_ref()
: value_{nullptr}
{
}
optional_ref(T &value) { value_ = &value; }
optional_ref(const T &value) { value_ = &value; }
optional_ref(optional_ref &right) { value_ = right.get(); }
template <typename V,
typename = std::enable_if<
std::is_base_of_v<optional_type, typename V::optional_type> ||
std::is_same_v<optional_type, typename V::optional_type>>>
optional_ref(const V &t)
{
value_ = t.get();
}
template <typename V,
typename = std::enable_if<
std::is_base_of_v<optional_type, typename V::optional_type> ||
std::is_same_v<optional_type, typename V::optional_type>>>
optional_ref(V &&t)
{
value_ = t.get();
t.reset();
}
template <typename V,
typename = std::enable_if<std::is_base_of_v<optional_type, V>>>
optional_ref(const std::reference_wrapper<V> &t)
{
value_ = &t.get();
}
optional_ref &operator=(const optional_ref &right)
{
if (this == &right)
return *this;
value_ = right.value_;
return *this;
}
optional_ref &operator=(optional_ref &&right) noexcept
{
if (this == &right)
return *this;
value_ = right.value_;
right.reset();
return *this;
}
bool has_value() const noexcept { return value_ != nullptr; }
operator bool() const noexcept { return has_value(); }
const T &value() const
{
assert(value_ != nullptr);
return *value_;
}
T &value()
{
assert(value_ != nullptr);
return *value_;
}
void reset() { value_ = nullptr; }
T *get() const { return value_; }
private:
T *value_;
};
template <typename T>
using reference_vector = std::vector<std::reference_wrapper<T>>;

View File

@ -19,112 +19,12 @@
#include "cx/util.h"
#include "util/util.h"
#include <cppast/cpp_class.hpp>
#include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_namespace.hpp>
#include <cppast/cpp_template.hpp>
#include <spdlog/spdlog.h>
#include <class_diagram/model/template_parameter.h>
#include <list>
namespace clanguml {
namespace cx {
namespace util {
std::string full_name(
const common::model::namespace_ &current_ns, const cppast::cpp_entity &e)
{
if (e.name().empty())
return "";
else if (cppast::is_parameter(e.kind()))
// parameters don't have a full name
return e.name();
std::vector<std::string> fn;
for (const auto &ns : current_ns) {
if (!ns.empty())
fn.push_back(ns);
}
fn.push_back(e.name());
return fmt::format("{}", fmt::join(fn, "::"));
}
std::string full_name(const cppast::cpp_type &t,
const cppast::cpp_entity_index &idx, bool inside_class)
{
std::string t_ns;
if (!inside_class) {
t_ns = ns(cppast::remove_cv(unreferenced(t)), idx);
}
auto t_name = cppast::to_string(t);
if (t_ns.size() > 0 &&
t_name.substr(0, t_name.find("<")).find("::") == std::string::npos)
return t_ns + "::" + t_name;
return cppast::to_string(t);
}
std::string ns(const cppast::cpp_entity &e)
{
std::vector<std::string> res{};
auto it = e.parent();
while (it) {
if (it.value().kind() == cppast::cpp_entity_kind::namespace_t) {
const auto &ns =
static_cast<const cppast::cpp_namespace &>(it.value());
if (!ns.name().empty() && !ns.is_inline())
res.push_back(it.value().name());
}
it = it.value().parent();
}
if (res.empty())
return "";
std::reverse(res.begin(), res.end());
return fmt::format("{}", fmt::join(res, "::"));
}
type_safe::optional_ref<const cppast::cpp_namespace> entity_ns(
const cppast::cpp_entity &e)
{
std::vector<std::string> res{};
if (e.kind() == cppast::cpp_entity_kind::namespace_t)
return type_safe::optional_ref<const cppast::cpp_namespace>(
static_cast<const cppast::cpp_namespace &>(e));
auto it = e.parent();
while (it) {
if (it.value().kind() == cppast::cpp_entity_kind::namespace_t) {
return type_safe::optional_ref<const cppast::cpp_namespace>(
static_cast<const cppast::cpp_namespace &>(it.value()));
}
it = it.value().parent();
}
return {};
}
bool is_inside_class(const cppast::cpp_entity &e)
{
auto it = e.parent();
while (it) {
if (it.value().kind() == cppast::cpp_entity_kind::class_t) {
return true;
}
it = it.value().parent();
}
return false;
}
namespace clanguml::cx::util {
std::pair<common::model::namespace_, std::string> split_ns(
const std::string &full_name)
@ -139,123 +39,6 @@ std::pair<common::model::namespace_, std::string> split_ns(
return {ns, name};
}
std::string ns(const cppast::cpp_type &t, const cppast::cpp_entity_index &idx)
{
if (t.kind() == cppast::cpp_type_kind::user_defined_t &&
(static_cast<const cppast::cpp_user_defined_type &>(t)
.entity()
.get(idx)
.size() > 0)) {
// If this is a user defined type - return the namespace of the
// entity
return ns(static_cast<const cppast::cpp_user_defined_type &>(t)
.entity()
.get(idx)[0]
.get());
}
else if (t.kind() == cppast::cpp_type_kind::template_instantiation_t) {
if (static_cast<const cppast::cpp_template_instantiation_type &>(t)
.primary_template()
.get(idx)
.size() > 0) {
return ns(
static_cast<const cppast::cpp_template_instantiation_type &>(t)
.primary_template()
.get(idx)[0]
.get());
}
else {
return {};
}
}
else {
auto canon = cppast::to_string(t.canonical());
auto full_name = canon.substr(0, canon.find("<"));
if (full_name.empty()) {
return "";
}
else if (canon.find("type-parameter-") == std::string::npos) {
// This is an easy case, canonical representation contains full
// namespace
auto ns_toks = clanguml::util::split(full_name, "::");
if (ns_toks.size() > 0)
ns_toks.pop_back();
return fmt::format(
"{}", fmt::join(ns_toks.begin(), ns_toks.end(), "::"));
}
else if (canon.find("type-parameter-") == 0) {
return "";
}
else {
// This is a bug/feature in libclang, where canonical representation
// of a template type with incomplete specialization doesn't have a
// full namespace. We have to extract it from the primary template
const auto &primary_template =
static_cast<const cppast::cpp_template_instantiation_type &>(t)
.primary_template();
if (!primary_template.is_overloaded()) {
LOG_DBG(
"Cannot establish namespace for ", cppast::to_string(t));
return "";
}
return ns(primary_template.get(idx)[0].get());
}
}
}
std::string fully_prefixed(
const common::model::namespace_ &current_ns, const cppast::cpp_entity &e)
{
if (e.name().find("::") != std::string::npos) {
// the name already contains namespace, but it could be not
// absolute, i.e. relative to some supernamespace of current
// namespace context
std::list<std::string> res;
for (const auto &n : clanguml::util::split(e.name(), "::"))
res.push_back(n);
std::list<std::string> prefix_ns;
for (const auto &n : current_ns) {
if (!n.empty() && n != res.front())
prefix_ns.push_back(n);
else
break;
}
prefix_ns.reverse();
for (const auto &n : prefix_ns)
res.push_front(n);
return fmt::format("{}", fmt::join(res, "::"));
}
std::vector<std::string> res{e.name()};
auto it = e.parent();
while (it) {
if (it.value().kind() == cppast::cpp_entity_kind::namespace_t) {
if (!it.value().name().empty())
res.push_back(it.value().name());
}
it = it.value().parent();
}
return fmt::format("{}", fmt::join(res.rbegin(), res.rend(), "::"));
}
const cppast::cpp_type &unreferenced(const cppast::cpp_type &t)
{
if (t.kind() == cppast::cpp_type_kind::pointer_t)
return unreferenced(
static_cast<const cppast::cpp_pointer_type &>(t).pointee());
else if (t.kind() == cppast::cpp_type_kind::reference_t)
return unreferenced(
static_cast<const cppast::cpp_reference_type &>(t).referee());
return t;
}
std::vector<class_diagram::model::template_parameter>
parse_unexposed_template_params(const std::string &params,
std::function<std::string(const std::string &)> ns_resolve)
@ -334,6 +117,4 @@ parse_unexposed_template_params(const std::string &params,
return res;
}
} // namespace util
} // namespace cx
} // namespace clanguml
} // namespace clanguml::cx::util

View File

@ -21,43 +21,17 @@
#include <clang-c/CXCompilationDatabase.h>
#include <clang-c/Index.h>
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_type.hpp>
#include <class_diagram/model/template_parameter.h>
#include <string>
namespace clanguml {
namespace cx {
namespace util {
std::string full_name(
const common::model::namespace_ &current_ns, const cppast::cpp_entity &e);
std::string full_name(const cppast::cpp_type &t,
const cppast::cpp_entity_index &idx, bool inside_class);
std::string fully_prefixed(
const common::model::namespace_ &current_ns, const cppast::cpp_entity &e);
const cppast::cpp_type &unreferenced(const cppast::cpp_type &t);
std::string ns(const cppast::cpp_entity &e);
type_safe::optional_ref<const cppast::cpp_namespace> entity_ns(
const cppast::cpp_entity &e);
std::string ns(const cppast::cpp_type &t, const cppast::cpp_entity_index &idx);
namespace clanguml::cx::util {
std::pair<common::model::namespace_, std::string> split_ns(
const std::string &full_name);
bool is_inside_class(const cppast::cpp_entity &e);
std::vector<class_diagram::model::template_parameter>
parse_unexposed_template_params(const std::string &params,
std::function<std::string(const std::string &)> ns_resolve);
} // namespace util
} // namespace cx
} // namespace clanguml
} // namespace clanguml::cx::util

View File

@ -49,13 +49,12 @@ void generator::generate_relationships(
[this](const auto &r) {
return m_model.should_include(r.type()) &&
util::contains(m_generated_aliases,
m_model.get(r.destination()).value().get().alias());
m_model.get(r.destination()).value().alias());
},
[&f, &ostr, this](const auto &r) {
ostr << f.alias() << " "
<< plantuml_common::to_plantuml(r.type(), r.style()) << " "
<< m_model.get(r.destination()).value().get().alias()
<< '\n';
<< m_model.get(r.destination()).value().alias() << '\n';
});
}
}

View File

@ -26,9 +26,6 @@
#include "include_diagram/visitor/translation_unit_visitor.h"
#include "util/util.h"
#include <cppast/cpp_entity_index.hpp>
#include <cppast/libclang_parser.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>

View File

@ -1,42 +0,0 @@
/**
* src/include_diagram/model/visitor/element_visitor_context.h
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "include_diagram/model/diagram.h"
namespace clanguml::include_diagram::visitor {
class translation_unit_context;
template <typename T> class element_visitor_context {
public:
element_visitor_context(
clanguml::include_diagram::model::diagram &diagram, T &element);
T &element();
clanguml::include_diagram::model::diagram &diagram();
private:
translation_unit_context *ctx_;
T &element_;
clanguml::include_diagram::model::diagram &diagram_;
};
}

View File

@ -1,62 +0,0 @@
/**
* src/include_diagram/visitor/translation_unit_context.h
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "common/model/package.h"
#include "config/config.h"
#include "include_diagram/model/diagram.h"
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_namespace.hpp>
#include <cppast/cpp_type.hpp>
#include <type_safe/reference.hpp>
namespace clanguml::include_diagram::visitor {
class translation_unit_context {
public:
translation_unit_context(cppast::cpp_entity_index &idx,
clanguml::include_diagram::model::diagram &diagram,
const clanguml::config::include_diagram &config);
const cppast::cpp_entity_index &entity_index() const;
const clanguml::config::include_diagram &config() const;
clanguml::include_diagram::model::diagram &diagram();
void set_current_file(
type_safe::optional_ref<common::model::source_file> p);
type_safe::optional_ref<common::model::source_file>
get_current_file() const;
private:
// Reference to the cppast entity index
cppast::cpp_entity_index &entity_index_;
// Reference to the output diagram model
clanguml::include_diagram::model::diagram &diagram_;
// Reference to class diagram config
const clanguml::config::include_diagram &config_;
type_safe::optional_ref<common::model::source_file> current_file_;
};
}

View File

@ -132,7 +132,6 @@ translation_unit_visitor::include_visitor::process_internal_header(
diagram()
.get(current_file_id)
.value()
.get()
.add_relationship(common::model::relationship{
relationship_type, include_file.id()});
}
@ -161,7 +160,6 @@ translation_unit_visitor::include_visitor::process_external_system_header(
diagram()
.get(current_file_id)
.value()
.get()
.add_relationship(common::model::relationship{
common::model::relationship_t::kDependency, f_id});
}

View File

@ -21,7 +21,6 @@
#include "common/model/package.h"
#include "config/config.h"
#include "include_diagram/model/diagram.h"
#include "include_diagram/visitor/translation_unit_context.h"
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Basic/SourceManager.h>

View File

@ -25,7 +25,6 @@
#include "version.h"
#include <cli11/CLI11.hpp>
#include <cppast/libclang_parser.hpp>
#include <spdlog/spdlog.h>
#include <filesystem>

View File

@ -25,9 +25,6 @@
#include "package_diagram/visitor/translation_unit_visitor.h"
#include "util/util.h"
#include <cppast/cpp_entity_index.hpp>
#include <cppast/libclang_parser.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>

View File

@ -28,7 +28,7 @@ common::model::diagram_t diagram::type() const
return common::model::diagram_t::kPackage;
}
const std::vector<std::reference_wrapper<clanguml::common::model::package>> &
const common::reference_vector<clanguml::common::model::package> &
diagram::packages() const
{
return packages_;
@ -45,8 +45,8 @@ void diagram::add_package(std::unique_ptr<common::model::package> &&p)
add_element(ns, std::move(p));
}
std::optional<std::reference_wrapper<common::model::package>>
diagram::get_package(const std::string &name) const
common::optional_ref<common::model::package> diagram::get_package(
const std::string &name) const
{
for (const auto &p : packages_) {
auto p_full_name = p.get().full_name(false);
@ -58,8 +58,7 @@ diagram::get_package(const std::string &name) const
return {};
}
std::optional<std::reference_wrapper<common::model::package>>
diagram::get_package(
common::optional_ref<common::model::package> diagram::get_package(
const clanguml::common::model::diagram_element::id_t id) const
{
for (const auto &p : packages_) {
@ -71,14 +70,14 @@ diagram::get_package(
return {};
}
std::optional<std::reference_wrapper<clanguml::common::model::diagram_element>>
diagram::get(const std::string &full_name) const
common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
const std::string &full_name) const
{
return get_package(full_name);
}
std::optional<std::reference_wrapper<clanguml::common::model::diagram_element>>
diagram::get(const clanguml::common::model::diagram_element::id_t id) const
common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
const clanguml::common::model::diagram_element::id_t id) const
{
return get_package(id);
}

View File

@ -39,31 +39,28 @@ public:
common::model::diagram_t type() const override;
const std::vector<std::reference_wrapper<clanguml::common::model::package>>
&packages() const;
const common::reference_vector<clanguml::common::model::package> &
packages() const;
std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
get(const std::string &full_name) const override;
common::optional_ref<clanguml::common::model::diagram_element> get(
const std::string &full_name) const override;
std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
get(const clanguml::common::model::diagram_element::id_t id) const override;
common::optional_ref<clanguml::common::model::diagram_element> get(
const clanguml::common::model::diagram_element::id_t id) const override;
void add_package(std::unique_ptr<common::model::package> &&p);
std::optional<std::reference_wrapper<clanguml::common::model::package>>
get_package(const std::string &name) const;
common::optional_ref<clanguml::common::model::package> get_package(
const std::string &name) const;
std::optional<std::reference_wrapper<common::model::package>> get_package(
common::optional_ref<common::model::package> get_package(
const clanguml::common::model::diagram_element::id_t id) const;
std::string to_alias(
const clanguml::common::model::diagram_element::id_t) const;
private:
std::vector<std::reference_wrapper<clanguml::common::model::package>>
packages_;
common::reference_vector<clanguml::common::model::package> packages_;
};
}

View File

@ -1,42 +0,0 @@
/**
* src/package_diagram/model/visitor/element_visitor_context.h
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "package_diagram/model/diagram.h"
namespace clanguml::package_diagram::visitor {
class translation_unit_context;
template <typename T> class element_visitor_context {
public:
element_visitor_context(
clanguml::package_diagram::model::diagram &diagram, T &element);
T &element();
clanguml::package_diagram::model::diagram &diagram();
private:
translation_unit_context *ctx_;
T &element_;
clanguml::package_diagram::model::diagram &diagram_;
};
}

View File

@ -1,111 +0,0 @@
/**
* src/package_diagram/visitor/translation_unit_context.h
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "common/model/package.h"
#include "config/config.h"
#include "package_diagram/model/diagram.h"
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_namespace.hpp>
#include <cppast/cpp_type.hpp>
#include <type_safe/reference.hpp>
namespace clanguml::package_diagram::visitor {
class translation_unit_context {
public:
translation_unit_context(cppast::cpp_entity_index &idx,
clanguml::package_diagram::model::diagram &diagram,
const clanguml::config::package_diagram &config);
bool has_namespace_alias(const std::string &full_name) const;
void add_namespace_alias(const std::string &full_name,
type_safe::object_ref<const cppast::cpp_namespace> ref);
type_safe::object_ref<const cppast::cpp_namespace> get_namespace_alias(
const std::string &full_name) const;
type_safe::object_ref<const cppast::cpp_namespace>
get_namespace_alias_final(const cppast::cpp_namespace &t) const;
bool has_type_alias(const std::string &full_name) const;
void add_type_alias(const std::string &full_name,
type_safe::object_ref<const cppast::cpp_type> &&ref);
type_safe::object_ref<const cppast::cpp_type> get_type_alias(
const std::string &full_name) const;
type_safe::object_ref<const cppast::cpp_type> get_type_alias_final(
const cppast::cpp_type &t) const;
bool has_type_alias_template(const std::string &full_name) const;
void add_type_alias_template(const std::string &full_name,
type_safe::object_ref<const cppast::cpp_type> &&ref);
type_safe::object_ref<const cppast::cpp_type> get_type_alias_template(
const std::string &full_name) const;
void push_namespace(const std::string &ns);
void pop_namespace();
const common::model::namespace_ &get_namespace() const;
const cppast::cpp_entity_index &entity_index() const;
const clanguml::config::package_diagram &config() const;
clanguml::package_diagram::model::diagram &diagram();
void set_current_package(type_safe::optional_ref<common::model::package> p);
type_safe::optional_ref<common::model::package> get_current_package() const;
private:
// Current visitor namespace
common::model::namespace_ namespace_;
// Reference to the cppast entity index
cppast::cpp_entity_index &entity_index_;
// Reference to the output diagram model
clanguml::package_diagram::model::diagram &diagram_;
// Reference to class diagram config
const clanguml::config::package_diagram &config_;
// Map of discovered aliases (declared with 'namespace' keyword)
std::map<std::string, type_safe::object_ref<const cppast::cpp_namespace>>
namespace_alias_index_;
// Map of discovered type aliases (declared with 'using' keyword)
std::map<std::string, type_safe::object_ref<const cppast::cpp_type>>
alias_index_;
// Map of discovered template aliases (declared with 'using' keyword)
std::map<std::string, type_safe::object_ref<const cppast::cpp_type>>
alias_template_index_;
type_safe::optional_ref<common::model::package> current_package_;
};
}

View File

@ -164,7 +164,7 @@ void translation_unit_visitor::add_relationships(
const auto destination_id = std::get<0>(dependency);
relationship r{relationship_t::kDependency, destination_id};
if (destination_id != current_package_id)
current_package.value().get().add_relationship(std::move(r));
current_package.value().add_relationship(std::move(r));
}
}
}

View File

@ -19,7 +19,6 @@
#include "config/config.h"
#include "package_diagram/model/diagram.h"
#include "package_diagram/visitor/translation_unit_context.h"
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Basic/SourceManager.h>

View File

@ -18,18 +18,12 @@
#include "sequence_diagram_generator.h"
#include "sequence_diagram/visitor/translation_unit_context.h"
#include <cppast/libclang_parser.hpp>
#include <cppast/parser.hpp>
namespace clanguml::sequence_diagram::generators::plantuml {
using clanguml::common::model::message_t;
using clanguml::config::source_location;
using clanguml::sequence_diagram::model::activity;
using clanguml::sequence_diagram::model::message;
using clanguml::sequence_diagram::visitor::translation_unit_context;
using namespace clanguml::util;
//

View File

@ -23,7 +23,6 @@
#include "sequence_diagram/visitor/translation_unit_visitor.h"
#include "util/util.h"
#include <cppast/libclang_parser.hpp>
#include <glob/glob.hpp>
#include <filesystem>

View File

@ -1,58 +0,0 @@
/**
* src/sequence_diagram/visitor/translation_unit_context.h
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "config/config.h"
#include "sequence_diagram/model/diagram.h"
#include <cppast/cpp_entity_index.hpp>
#include <functional>
#include <memory>
#include <string>
namespace clanguml::sequence_diagram::visitor {
class translation_unit_context {
public:
translation_unit_context(cppast::cpp_entity_index &idx,
clanguml::sequence_diagram::model::diagram &diagram,
const clanguml::config::sequence_diagram &config);
void push_namespace(const std::string &ns);
void pop_namespace();
const std::vector<std::string> &get_namespace() const;
const cppast::cpp_entity_index &entity_index() const;
const clanguml::config::sequence_diagram &config() const;
clanguml::sequence_diagram::model::diagram &diagram();
private:
// Reference to the cppast entity index
cppast::cpp_entity_index &entity_index_;
clanguml::sequence_diagram::model::diagram &diagram_;
const clanguml::config::sequence_diagram &config_;
std::vector<std::string> namespace_;
};
}

View File

@ -20,7 +20,6 @@
#include "common/model/namespace.h"
#include "cx/util.h"
#include "translation_unit_context.h"
namespace clanguml::sequence_diagram::visitor {
@ -36,16 +35,6 @@ translation_unit_visitor::translation_unit_visitor(clang::SourceManager &sm,
/*
void translation_unit_visitor::process_activities(const cppast::cpp_function &e)
{
using clanguml::common::model::message_t;
using clanguml::sequence_diagram::model::activity;
using clanguml::sequence_diagram::model::diagram;
using clanguml::sequence_diagram::model::message;
using cppast::cpp_entity;
using cppast::cpp_entity_kind;
using cppast::cpp_function;
using cppast::cpp_member_function;
using cppast::cpp_member_function_call;
using cppast::visitor_info;
for (const auto &function_call_ptr : e.function_calls()) {
const auto &function_call =
@ -129,12 +118,6 @@ void translation_unit_visitor::process_activities(const cppast::cpp_function &e)
void translation_unit_visitor::operator()(const cppast::cpp_entity &file)
{
using cppast::cpp_entity;
using cppast::cpp_entity_kind;
using cppast::cpp_function;
using cppast::cpp_member_function;
using cppast::cpp_member_function_call;
using cppast::visitor_info;
cppast::visit(file, [&, this](const cpp_entity &e, visitor_info) {
if (e.kind() == cpp_entity_kind::function_t) {

View File

@ -19,7 +19,6 @@
#include "config/config.h"
#include "sequence_diagram/model/diagram.h"
#include "sequence_diagram/visitor/translation_unit_context.h"
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Basic/SourceManager.h>

View File

@ -14,7 +14,6 @@ file(GLOB_RECURSE TEST_CONFIG_YMLS test_config_data/*.yml)
set(CLANG_UML_TEST_LIBRARIES
clang-umllib
cppast
${YAML_CPP_LIBRARIES}
${LIBTOOLING_LIBS}
${LIBCLANG_LIBRARIES}

View File

@ -2,7 +2,7 @@
#include "lib1/lib1.h"
#include <cppast/cpp_preprocessor.hpp>
#include <clang/Lex/Lexer.h>
#include <string>

View File

@ -41,7 +41,7 @@ TEST_CASE("t40001", "[test-case][package]")
REQUIRE_THAT(puml, IsFile("t40001_include1.h"));
REQUIRE_THAT(puml, IsFile("string"));
REQUIRE_THAT(puml, IsFile("cppast/cpp_preprocessor.hpp"));
REQUIRE_THAT(puml, IsFile("clang/Lex/Lexer.h"));
REQUIRE_THAT(puml, IsAssociation(_A("t40001.cc"), _A("t40001_include1.h")));
REQUIRE_THAT(puml, IsAssociation(_A("t40001_include1.h"), _A("lib1.h")));

1
thirdparty/cppast vendored

@ -1 +0,0 @@
Subproject commit 79b8d56391b8e40a7b51bd1d567df300ba39a77a