Changed scope_t to access_t and fixed friend access specifier handling

This commit is contained in:
Bartek Kryza
2022-03-30 23:27:46 +02:00
parent a216a81e19
commit a8b57e4eb1
30 changed files with 134 additions and 137 deletions

View File

@@ -110,7 +110,7 @@ void generator::generate(
// Process methods
//
for (const auto &m : c.methods()) {
if (!m_model.should_include(m.scope()))
if (!m_model.should_include(m.access()))
continue;
if (m.is_pure_virtual())
@@ -121,7 +121,7 @@ void generator::generate(
std::string type{m.type()};
ostr << plantuml_common::to_plantuml(m.scope()) << m.name();
ostr << plantuml_common::to_plantuml(m.access()) << m.name();
ostr << "(";
if (m_config.generate_method_arguments() !=
@@ -195,7 +195,7 @@ void generator::generate(
<< m_model.to_alias(uns.relative(destination));
if (!r.label().empty()) {
relstr << " : " << plantuml_common::to_plantuml(r.scope())
relstr << " : " << plantuml_common::to_plantuml(r.access())
<< r.label();
rendered_relations.emplace(r.label());
}
@@ -222,7 +222,7 @@ void generator::generate(
// Process members
//
for (const auto &m : c.members()) {
if (!m_model.should_include(m.scope()))
if (!m_model.should_include(m.access()))
continue;
if (!m_config.include_relations_also_as_members() &&
@@ -232,7 +232,7 @@ void generator::generate(
if (m.is_static())
ostr << "{static} ";
ostr << plantuml_common::to_plantuml(m.scope()) << m.name() << " : "
ostr << plantuml_common::to_plantuml(m.access()) << m.name() << " : "
<< uns.relative(m.type());
if (m_config.generate_links) {

View File

@@ -49,9 +49,9 @@ using common_generator =
using clanguml::class_diagram::model::class_;
using clanguml::class_diagram::model::enum_;
using clanguml::common::model::access_t;
using clanguml::common::model::package;
using clanguml::common::model::relationship_t;
using clanguml::common::model::scope_t;
using namespace clanguml::util;

View File

@@ -20,15 +20,15 @@
namespace clanguml::class_diagram::model {
class_element::class_element(common::model::scope_t scope,
class_element::class_element(common::model::access_t access,
const std::string &name, const std::string &type)
: scope_{scope}
: access_{access}
, name_{name}
, type_{type}
{
}
common::model::scope_t class_element::scope() const { return scope_; }
common::model::access_t class_element::access() const { return access_; }
std::string class_element::name() const { return name_; }
@@ -39,7 +39,7 @@ inja::json class_element::context() const
inja::json ctx;
ctx["name"] = name();
ctx["type"] = type();
ctx["scope"] = to_string(scope());
ctx["access"] = to_string(access());
return ctx;
}
}

View File

@@ -29,17 +29,17 @@ namespace clanguml::class_diagram::model {
class class_element : public common::model::decorated_element,
public common::model::source_location {
public:
class_element(common::model::scope_t scope, const std::string &name,
class_element(common::model::access_t scope, const std::string &name,
const std::string &type);
common::model::scope_t scope() const;
common::model::access_t access() const;
std::string name() const;
std::string type() const;
virtual inja::json context() const;
private:
common::model::scope_t scope_;
common::model::access_t access_;
std::string name_;
std::string type_;
};

View File

@@ -20,9 +20,9 @@
namespace clanguml::class_diagram::model {
class_member::class_member(common::model::scope_t scope,
class_member::class_member(common::model::access_t access,
const std::string &name, const std::string &type)
: class_element{scope, name, type}
: class_element{access, name, type}
{
}

View File

@@ -25,7 +25,7 @@ namespace clanguml::class_diagram::model {
class class_member : public class_element {
public:
class_member(common::model::scope_t scope, const std::string &name,
class_member(common::model::access_t access, const std::string &name,
const std::string &type);
bool is_relationship() const;

View File

@@ -20,9 +20,9 @@
namespace clanguml::class_diagram::model {
class_method::class_method(common::model::scope_t scope,
class_method::class_method(common::model::access_t access,
const std::string &name, const std::string &type)
: class_element{scope, name, type}
: class_element{access, name, type}
{
}

View File

@@ -27,7 +27,7 @@ namespace clanguml::class_diagram::model {
class class_method : public class_element {
public:
class_method(common::model::scope_t scope, const std::string &name,
class_method(common::model::access_t access, const std::string &name,
const std::string &type);
bool is_pure_virtual() const;

View File

@@ -46,28 +46,27 @@ using clanguml::class_diagram::model::type_alias;
using clanguml::common::model::access_t;
using clanguml::common::model::relationship;
using clanguml::common::model::relationship_t;
using clanguml::common::model::scope_t;
namespace detail {
scope_t cpp_access_specifier_to_scope(
access_t cpp_access_specifier_to_access(
cppast::cpp_access_specifier_kind access_specifier)
{
scope_t scope = scope_t::kPublic;
auto access = access_t::kPublic;
switch (access_specifier) {
case cppast::cpp_access_specifier_kind::cpp_public:
scope = scope_t::kPublic;
access = access_t::kPublic;
break;
case cppast::cpp_access_specifier_kind::cpp_private:
scope = scope_t::kPrivate;
access = access_t::kPrivate;
break;
case cppast::cpp_access_specifier_kind::cpp_protected:
scope = scope_t::kProtected;
access = access_t::kProtected;
break;
default:
break;
}
return scope;
return access;
}
}
@@ -662,7 +661,7 @@ void translation_unit_visitor::process_class_children(
child.scope_name() ? child.scope_name().value().name()
: "<no-scope>");
process_friend(fr, c);
process_friend(fr, c, last_access_specifier);
}
else if (cppast::is_friended(child)) {
auto &fr =
@@ -670,7 +669,7 @@ void translation_unit_visitor::process_class_children(
LOG_DBG("Found friend template: {}", child.name());
process_friend(fr, c);
process_friend(fr, c, last_access_specifier);
}
else {
LOG_DBG("Found some other class child: {} ({})", child.name(),
@@ -717,7 +716,7 @@ bool translation_unit_visitor::process_field_with_template_instantiation(
relationship_type = relationship_t::kAggregation;
relationship rr{relationship_type, tinst.full_name(),
detail::cpp_access_specifier_to_scope(as), mv.name()};
detail::cpp_access_specifier_to_access(as), mv.name()};
rr.set_style(m.style_spec());
// Process field decorators
@@ -765,7 +764,7 @@ void translation_unit_visitor::process_field(
type_name = "<<anonymous>>";
class_member m{
detail::cpp_access_specifier_to_scope(as), mv.name(), type_name};
detail::cpp_access_specifier_to_access(as), mv.name(), type_name};
if (mv.location().has_value()) {
m.set_file(mv.location().value().file);
@@ -816,7 +815,7 @@ void translation_unit_visitor::process_field(
for (const auto &[type, relationship_type] : relationships) {
if (relationship_type != relationship_t::kNone) {
relationship r{relationship_type, type, m.scope(), m.name()};
relationship r{relationship_type, type, m.access(), m.name()};
r.set_style(m.style_spec());
auto [decorator_rtype, decorator_rmult] = m.get_relationship();
@@ -848,7 +847,7 @@ void translation_unit_visitor::process_anonymous_enum(
for (const auto &ev : en) {
if (ev.kind() == cppast::cpp_entity_kind::enum_value_t) {
class_member m{
detail::cpp_access_specifier_to_scope(as), ev.name(), "enum"};
detail::cpp_access_specifier_to_access(as), ev.name(), "enum"};
c.add_member(std::move(m));
}
}
@@ -858,7 +857,7 @@ void translation_unit_visitor::process_static_field(
const cppast::cpp_variable &mv, class_ &c,
cppast::cpp_access_specifier_kind as)
{
class_member m{detail::cpp_access_specifier_to_scope(as), mv.name(),
class_member m{detail::cpp_access_specifier_to_access(as), mv.name(),
cppast::to_string(mv.type())};
if (mv.location().has_value()) {
@@ -881,7 +880,7 @@ void translation_unit_visitor::process_method(
const cppast::cpp_member_function &mf, class_ &c,
cppast::cpp_access_specifier_kind as)
{
class_method m{detail::cpp_access_specifier_to_scope(as),
class_method m{detail::cpp_access_specifier_to_access(as),
util::trim(mf.name()), cppast::to_string(mf.return_type())};
m.is_pure_virtual(cppast::is_pure(mf.virtual_info()));
m.is_virtual(cppast::is_virtual(mf.virtual_info()));
@@ -923,8 +922,8 @@ void translation_unit_visitor::process_template_method(
static_cast<const cppast::cpp_member_function &>(mf.function())
.return_type());
class_method m{
detail::cpp_access_specifier_to_scope(as), util::trim(mf.name()), type};
class_method m{detail::cpp_access_specifier_to_access(as),
util::trim(mf.name()), type};
m.is_pure_virtual(false);
m.is_virtual(false);
m.is_const(cppast::is_const(
@@ -964,7 +963,7 @@ void translation_unit_visitor::process_static_method(
const cppast::cpp_function &mf, class_ &c,
cppast::cpp_access_specifier_kind as)
{
class_method m{detail::cpp_access_specifier_to_scope(as),
class_method m{detail::cpp_access_specifier_to_access(as),
util::trim(mf.name()), cppast::to_string(mf.return_type())};
m.is_pure_virtual(false);
m.is_virtual(false);
@@ -998,7 +997,7 @@ void translation_unit_visitor::process_constructor(
const cppast::cpp_constructor &mf, class_ &c,
cppast::cpp_access_specifier_kind as)
{
class_method m{detail::cpp_access_specifier_to_scope(as),
class_method m{detail::cpp_access_specifier_to_access(as),
util::trim(mf.name()), "void"};
m.is_pure_virtual(false);
m.is_virtual(false);
@@ -1030,7 +1029,7 @@ void translation_unit_visitor::process_destructor(
const cppast::cpp_destructor &mf, class_ &c,
cppast::cpp_access_specifier_kind as)
{
class_method m{detail::cpp_access_specifier_to_scope(as),
class_method m{detail::cpp_access_specifier_to_access(as),
util::trim(mf.name()), "void"};
m.is_pure_virtual(false);
m.is_virtual(cppast::is_virtual(mf.virtual_info()));
@@ -1230,8 +1229,8 @@ void translation_unit_visitor::process_template_template_parameter(
parent.add_template({"", t.name() + "<>"});
}
void translation_unit_visitor::process_friend(
const cppast::cpp_friend &f, class_ &parent)
void translation_unit_visitor::process_friend(const cppast::cpp_friend &f,
class_ &parent, cppast::cpp_access_specifier_kind as)
{
// Only process friends to other classes or class templates
if (!f.entity() ||
@@ -1240,8 +1239,8 @@ void translation_unit_visitor::process_friend(
cppast::cpp_entity_kind::class_template_t))
return;
relationship r{
relationship_t::kFriendship, "", scope_t::kNone, "<<friend>>"};
relationship r{relationship_t::kFriendship, "",
detail::cpp_access_specifier_to_access(as), "<<friend>>"};
if (f.comment().has_value())
r.add_decorators(decorators::parse(f.comment().value()));

View File

@@ -124,7 +124,8 @@ public:
clanguml::class_diagram::model::class_ &parent);
void process_friend(const cppast::cpp_friend &t,
clanguml::class_diagram::model::class_ &parent);
clanguml::class_diagram::model::class_ &parent,
cppast::cpp_access_specifier_kind as);
void process_namespace(const cppast::cpp_entity &e,
const cppast::cpp_namespace &ns_declaration);