Merge pull request #228 from bkryza/add-coroutine-testcase

Add coroutine testcase
This commit is contained in:
Bartek Kryza
2024-01-11 17:10:25 +01:00
committed by GitHub
730 changed files with 20748 additions and 7689 deletions

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/clang_utils.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -887,4 +887,10 @@ clang::RawComment *get_expression_raw_comment(const clang::SourceManager &sm,
return {};
}
bool is_coroutine(const clang::FunctionDecl &decl)
{
const auto *body = decl.getBody();
return clang::isa_and_nonnull<clang::CoroutineBodyStmt>(body);
}
} // namespace clanguml::common

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/clang_utils.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -295,4 +295,12 @@ consume_type_context(clang::QualType type);
clang::RawComment *get_expression_raw_comment(const clang::SourceManager &sm,
const clang::ASTContext &context, const clang::Stmt *stmt);
/**
* Check if function or method declaration is a C++20 coroutine.
*
* @param decl Function declaration
* @return True, if the function is a C++20 coroutine.
*/
bool is_coroutine(const clang::FunctionDecl &decl);
} // namespace clanguml::common

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/compilation_database.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/compilation_database.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/generator.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/generators.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -127,7 +127,7 @@ void generate_diagram_impl(const std::string &name,
auto from_values = model->list_from_values();
for (const auto &from : from_values) {
std::cout << from << std::endl;
std::cout << from << '\n';
}
return;
@@ -136,7 +136,7 @@ void generate_diagram_impl(const std::string &name,
auto to_values = model->list_to_values();
for (const auto &to : to_values) {
std::cout << "|" << to << "|" << std::endl;
std::cout << "|" << to << "|" << '\n';
}
return;

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/generators.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/json/generator.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -42,7 +42,7 @@ void to_json(nlohmann::json &j, const element &c)
j = json{{"id", std::to_string(c.id())},
{"name", detail::render_name(c.name())},
{"namespace", c.get_namespace().to_string()}, {"type", c.type_name()},
{"display_name", detail::render_name(c.full_name(false))}};
{"display_name", detail::render_name(c.full_name(true))}};
if (const auto &comment = c.comment(); comment)
j["comment"] = comment.value();

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/json/generator.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -35,13 +35,13 @@
namespace clanguml::common::model {
using nlohmann::json;
void to_json(nlohmann::json &j, const source_location &sl);
void to_json(json &j, const source_location &sl);
void to_json(nlohmann::json &j, const element &c);
void to_json(json &j, const element &c);
void to_json(nlohmann::json &j, const template_parameter &c);
void to_json(json &j, const template_parameter &c);
void to_json(nlohmann::json &j, const relationship &c);
void to_json(json &j, const relationship &c);
} // namespace clanguml::common::model
namespace clanguml::common::generators::json {

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/mermaid/generator.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/mermaid/generator.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/nested_element_stack.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/plantuml/generator.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/plantuml/generator.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/progress_indicator.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/generators/progress_indicator.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/decorated_element.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/decorated_element.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/diagram.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/diagram.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -65,7 +65,7 @@ public:
* @return Optional reference to a diagram element.
*/
virtual common::optional_ref<clanguml::common::model::diagram_element> get(
diagram_element::id_t id) const = 0;
common::id_t id) const = 0;
/**
* Return optional reference to a diagram_element by name and namespace.
@@ -152,10 +152,7 @@ public:
// Disallow std::string overload
bool should_include(const std::string &s) const = delete;
virtual bool has_element(const diagram_element::id_t /*id*/) const
{
return false;
}
virtual bool has_element(const common::id_t /*id*/) const { return false; }
virtual bool should_include(
const namespace_ &ns, const std::string &name) const;

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/diagram_element.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -26,16 +26,16 @@ namespace clanguml::common::model {
diagram_element::diagram_element() = default;
diagram_element::id_t diagram_element::id() const { return id_; }
common::id_t diagram_element::id() const { return id_; }
void diagram_element::set_id(diagram_element::id_t id) { id_ = id; }
void diagram_element::set_id(common::id_t id) { id_ = id; }
std::optional<id_t> diagram_element::parent_element_id() const
{
return parent_element_id_;
}
void diagram_element::set_parent_element_id(diagram_element::id_t id)
void diagram_element::set_parent_element_id(common::id_t id)
{
parent_element_id_ = id;
}

View File

@@ -1,7 +1,7 @@
/**
* src/common/model/diagram_element.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -39,8 +39,6 @@ namespace clanguml::common::model {
*/
class diagram_element : public decorated_element, public source_location {
public:
using id_t = int64_t;
diagram_element();
~diagram_element() override = default;
@@ -55,14 +53,14 @@ public:
*
* @return Elements id.
*/
id_t id() const;
common::id_t id() const;
/**
* Set elements id.
*
* @param id Elements id.
*/
void set_id(id_t id);
void set_id(common::id_t id);
/**
* Get elements parent package id.
@@ -76,7 +74,7 @@ public:
*
* @param id Id of parent package.
*/
void set_parent_element_id(diagram_element::id_t id);
void set_parent_element_id(id_t id);
/**
* @brief Return elements' diagram alias.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/diagram_filter.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -285,6 +285,47 @@ tvl::value_t namespace_filter::match(const diagram &d, const element &e) const
return result;
}
modules_filter::modules_filter(
filter_t type, std::vector<common::string_or_regex> modules)
: filter_visitor{type}
, modules_{std::move(modules)}
{
}
tvl::value_t modules_filter::match(
const diagram & /*d*/, const element &e) const
{
if (modules_.empty())
return {};
if (!e.module().has_value())
return {false};
auto module_toks =
path::split(e.module().value(), path_type::kModule); // NOLINT
if (dynamic_cast<const package *>(&e) != nullptr &&
e.get_namespace().type() == path_type::kModule) {
module_toks.push_back(e.name());
}
auto result = tvl::any_of(modules_.begin(), modules_.end(),
[&e, &module_toks](const auto &modit) {
if (std::holds_alternative<std::string>(modit.value())) {
const auto &modit_str = std::get<std::string>(modit.value());
const auto modit_toks =
path::split(modit_str, path_type::kModule);
return e.module() == modit_str ||
util::starts_with(module_toks, modit_toks);
}
return std::get<common::regex>(modit.value()) %= e.module().value();
});
return result;
}
element_filter::element_filter(
filter_t type, std::vector<common::string_or_regex> elements)
: filter_visitor{type}
@@ -534,6 +575,31 @@ tvl::value_t access_filter::match(
[&a](const auto &access) { return a == access; });
}
module_access_filter::module_access_filter(
filter_t type, std::vector<module_access_t> access)
: filter_visitor{type}
, access_{std::move(access)}
{
}
tvl::value_t module_access_filter::match(
const diagram & /*d*/, const element &e) const
{
if (!e.module().has_value())
return {};
if (access_.empty())
return {};
return tvl::any_of(
access_.begin(), access_.end(), [&e](const auto &access) {
if (access == module_access_t::kPublic)
return !e.module_private();
return e.module_private();
});
}
context_filter::context_filter(
filter_t type, std::vector<config::context_config> context)
: filter_visitor{type}
@@ -887,6 +953,12 @@ void diagram_filter::init_filters(const config::diagram &c)
add_inclusive_filter(std::make_unique<namespace_filter>(
filter_t::kInclusive, c.include().namespaces));
add_inclusive_filter(std::make_unique<modules_filter>(
filter_t::kInclusive, c.include().modules));
add_inclusive_filter(std::make_unique<module_access_filter>(
filter_t::kInclusive, c.include().module_access));
add_inclusive_filter(std::make_unique<relationship_filter>(
filter_t::kInclusive, c.include().relationships));
@@ -997,6 +1069,12 @@ void diagram_filter::init_filters(const config::diagram &c)
add_exclusive_filter(std::make_unique<namespace_filter>(
filter_t::kExclusive, c.exclude().namespaces));
add_exclusive_filter(std::make_unique<modules_filter>(
filter_t::kExclusive, c.exclude().modules));
add_exclusive_filter(std::make_unique<module_access_filter>(
filter_t::kExclusive, c.exclude().module_access));
add_exclusive_filter(std::make_unique<paths_filter>(
filter_t::kExclusive, c.root_directory(), c.exclude().paths));

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/diagram_filter.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -154,6 +154,21 @@ private:
std::vector<common::namespace_or_regex> namespaces_;
};
/**
* Match diagram elements to a set of specified modules or
* module regex patterns.
*/
struct modules_filter : public filter_visitor {
modules_filter(filter_t type, std::vector<common::string_or_regex> modules);
~modules_filter() override = default;
tvl::value_t match(const diagram &d, const element &e) const override;
private:
std::vector<common::string_or_regex> modules_;
};
/**
* Match element's name to a set of names or regex patterns.
*/
@@ -442,6 +457,20 @@ private:
std::vector<access_t> access_;
};
/**
* Match diagram elements based on module access (public or private).
*/
struct module_access_filter : public filter_visitor {
module_access_filter(filter_t type, std::vector<module_access_t> access);
~module_access_filter() override = default;
tvl::value_t match(const diagram &d, const element &a) const override;
private:
std::vector<module_access_t> access_;
};
/**
* Match diagram elements which are in within a 'radius' distance relationship
* to any of the elements specified in context.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/element.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -25,8 +25,9 @@
namespace clanguml::common::model {
element::element(namespace_ using_namespace)
: using_namespace_{std::move(using_namespace)}
element::element(namespace_ using_namespace, path_type pt)
: ns_{pt}
, using_namespace_{std::move(using_namespace)}
{
}

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/element.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -37,7 +37,7 @@ namespace clanguml::common::model {
*/
class element : public diagram_element {
public:
element(namespace_ using_namespace);
element(namespace_ using_namespace, path_type pt = path_type::kNamespace);
~element() override = default;
@@ -87,13 +87,47 @@ public:
*/
const namespace_ &path() const { return ns_; }
/**
* Set elements owning module.
*
* @param module C++20 module.
*/
void set_module(const std::string &module) { module_ = module; }
/**
* Return elements owning module, if any.
*
* @return C++20 module.
*/
std::optional<std::string> module() const { return module_; }
/**
* Set whether the element is in a private module
*
* @param module C++20 module.
*/
void set_module_private(const bool module_private)
{
module_private_ = module_private;
}
/**
* Check whether the element is in a private module.
*
* @return C++20 module.
*/
bool module_private() const { return module_private_; }
/**
* Return elements full name.
*
* @return Fully qualified elements name.
*/
std::string full_name(bool /*relative*/) const override
std::string full_name(bool relative) const override
{
if (relative)
return name();
return name_and_ns();
}
@@ -120,5 +154,7 @@ public:
private:
namespace_ ns_;
namespace_ using_namespace_;
std::optional<std::string> module_;
bool module_private_{false};
};
} // namespace clanguml::common::model

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/element_view.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -58,8 +58,7 @@ public:
*
* @return
*/
common::optional_ref<T> get(
clanguml::common::model::diagram_element::id_t id) const
common::optional_ref<T> get(clanguml::common::id_t id) const
{
for (const auto &e : elements_) {
if (e.get().id() == id) {

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/enums.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -70,6 +70,19 @@ std::string to_string(access_t a)
}
}
std::string to_string(module_access_t a)
{
switch (a) {
case module_access_t::kPublic:
return "public";
case module_access_t::kPrivate:
return "private";
default:
assert(false);
return "";
}
}
std::string to_string(message_t r)
{
switch (r) {

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/enums.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -23,6 +23,7 @@ namespace clanguml::common::model {
enum class diagram_t { kClass, kSequence, kPackage, kInclude };
enum class module_access_t { kPublic, kPrivate };
enum class access_t { kPublic, kProtected, kPrivate, kNone };
enum class relationship_t {
@@ -77,6 +78,8 @@ std::string to_string(relationship_t r);
std::string to_string(access_t r);
std::string to_string(module_access_t r);
std::string to_string(message_t m);
std::string to_string(diagram_t r);

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/namespace.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/namespace.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/nested_trait.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/package.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -21,8 +21,8 @@
#include <sstream>
namespace clanguml::common::model {
package::package(const common::model::namespace_ &using_namespace)
: element{using_namespace}
package::package(const common::model::namespace_ &using_namespace, path_type pt)
: element{using_namespace, pt}
{
}

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/package.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -41,7 +41,8 @@ class package : public element,
public stylable_element,
public nested_trait<element, path> {
public:
package(const common::model::path &using_namespace);
package(const common::model::path &using_namespace,
path_type pt = path_type::kNamespace);
package(const package &) = delete;
package(package &&) = default;

38
src/common/model/path.cc Normal file
View File

@@ -0,0 +1,38 @@
/**
* @file src/common/model/path.cc
*
* Copyright (c) 2021-2024 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 "path.h"
namespace clanguml::common::model {
std::string to_string(const path_type pt)
{
switch (pt) {
case path_type::kModule:
return "module";
case path_type::kNamespace:
return "namespace";
case path_type::kFilesystem:
return "directory";
default:
assert(false);
return "";
}
}
} // namespace clanguml::common::model

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/path.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -32,10 +32,13 @@ namespace clanguml::common::model {
* a nested set of namespaces or nested set of directories.
*/
enum class path_type {
kNamespace, /*!< Namespace path */
kFilesystem /*!< Filesystem path */
kNamespace, /*!< Namespace path */
kFilesystem, /*!< Filesystem path */
kModule /*!< Module path */
};
std::string to_string(path_type pt);
/**
* @brief Diagram path
*
@@ -49,11 +52,13 @@ class path {
*
* @return Path separator
*/
const char *separator() const
static const char *separator(path_type pt)
{
switch (path_type_) {
switch (pt) {
case path_type::kNamespace:
return "::";
case path_type::kModule:
return ".";
case path_type::kFilesystem:
#ifdef _WIN32
return "\\";
@@ -65,9 +70,38 @@ class path {
return "::";
}
/**
* Returns the path separator based on the type of the instance path.
*
* @return Path separator
*/
const char *separator() const { return separator(path_type_); }
public:
using container_type = std::vector<std::string>;
static container_type split(
const std::string &ns, path_type pt = path_type::kNamespace)
{
container_type result;
if (pt == path_type::kModule) {
auto path_toks = util::split(ns, separator(pt));
for (const auto &pt : path_toks) {
const auto subtoks = util::split(pt, ":");
if (subtoks.size() == 2) {
result.push_back(subtoks.at(0));
result.push_back(fmt::format(":{}", subtoks.at(1)));
}
else
result.push_back(subtoks.at(0));
}
}
else
result = util::split(ns, separator(pt));
return result;
}
path(path_type pt = path_type::kNamespace)
: path_type_{pt}
{
@@ -79,7 +113,7 @@ public:
if (ns.empty())
return;
path_ = util::split(ns, separator());
path_ = split(ns, pt);
}
virtual ~path() = default;
@@ -103,7 +137,8 @@ public:
return *this;
if (path_type_ != right.path_type_)
throw std::runtime_error("");
throw std::runtime_error(
"Cannot assign a path to a path with another path type.");
path_type_ = right.path_type_;
path_ = right.path_;
@@ -160,7 +195,14 @@ public:
*/
std::string to_string() const
{
return fmt::format("{}", fmt::join(path_, std::string{separator()}));
auto result =
fmt::format("{}", fmt::join(path_, std::string{separator()}));
if (path_type_ == path_type::kModule) {
util::replace_all(result, ".:", ":");
}
return result;
}
/**
@@ -186,6 +228,7 @@ public:
path operator|(const path &right) const
{
path res{*this};
res.path_type_ = right.path_type_;
res.append(right);
return res;
}
@@ -383,6 +426,8 @@ public:
*/
path_type type() const { return path_type_; }
const container_type &tokens() const { return path_; }
private:
path_type path_type_;
container_type path_;

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/relationship.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/relationship.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/source_file.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/source_file.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -117,6 +117,20 @@ public:
*/
source_file_t type() const { return type_; }
/**
* Set whether the file is a system header
*
* @param is_system Whether the file is a system header
*/
void set_system_header(bool is_system) { is_system_header_ = is_system; }
/**
* Is the file a system header?
*
* @return True, if the source file is a system header
*/
bool is_system_header() const { return is_system_header_; }
/**
* Get the source file's parent path.
*
@@ -185,6 +199,7 @@ private:
filesystem_path path_{path_type::kFilesystem};
source_file_t type_{source_file_t::kDirectory};
bool is_absolute_{false};
bool is_system_header_{false};
};
} // namespace clanguml::common::model

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/source_location.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/source_location.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/stylable_element.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/stylable_element.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/template_parameter.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/template_parameter.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/template_trait.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/template_trait.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/model/tvl.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/types.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/types.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/ast_id_mapper.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/ast_id_mapper.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -40,7 +40,7 @@ namespace clanguml::common::visitor {
*/
class ast_id_mapper {
public:
using id_t = common::model::diagram_element::id_t;
using id_t = common::id_t;
ast_id_mapper() = default;

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/comment/clang_visitor.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/comment/clang_visitor.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/comment/comment_visitor.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/comment/comment_visitor.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/comment/plain_visitor.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/comment/plain_visitor.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/translation_unit_visitor.cc
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -20,6 +20,10 @@
#include "comment/clang_visitor.h"
#include "comment/plain_visitor.h"
#include "common/clang_utils.h"
#include <clang/AST/Expr.h>
#include <clang/Basic/Module.h>
namespace clanguml::common::visitor {
@@ -161,4 +165,25 @@ void translation_unit_visitor::set_source_location(
element.set_location_id(location.getHashValue());
}
void translation_unit_visitor::set_owning_module(
const clang::Decl &decl, clanguml::common::model::element &element)
{
if (const clang::Module *module = decl.getOwningModule();
module != nullptr) {
std::string module_name = module->Name;
bool is_private{false};
#if LLVM_VERSION_MAJOR < 15
is_private =
module->Kind == clang::Module::ModuleKind::PrivateModuleFragment;
#else
is_private = module->isPrivateModule();
#endif
if (is_private) {
// Clang just maps private modules names to "<private>"
module_name = module->getTopLevelModule()->Name;
}
element.set_module(module_name);
element.set_module_private(is_private);
}
}
} // namespace clanguml::common::visitor

View File

@@ -1,7 +1,7 @@
/**
* @file src/common/visitor/translation_unit_visitor.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
* Copyright (c) 2021-2024 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.
@@ -18,9 +18,12 @@
#pragma once
#include "comment/comment_visitor.h"
#include "common/model/element.h"
#include "common/model/source_location.h"
#include "config/config.h"
#include <clang/AST/Comment.h>
#include <clang/AST/RawCommentList.h>
#include <clang/Basic/SourceManager.h>
#include <deque>
@@ -31,9 +34,8 @@
namespace clanguml::common::visitor {
using found_relationships_t =
std::vector<std::pair<clanguml::common::model::diagram_element::id_t,
common::model::relationship_t>>;
using found_relationships_t = std::vector<
std::pair<clanguml::common::id_t, common::model::relationship_t>>;
/**
* @brief Diagram translation unit visitor base class
@@ -100,6 +102,9 @@ public:
void set_source_location(const clang::SourceLocation &location,
clanguml::common::model::source_location &element);
void set_owning_module(
const clang::Decl &decl, clanguml::common::model::element &element);
protected:
/**
* @brief Process comment directives in comment attached to a declaration