Refactored sequence diagram generator
This commit is contained in:
@@ -56,4 +56,16 @@ std::string to_plantuml(scope_t scope)
|
||||
}
|
||||
}
|
||||
|
||||
std::string to_plantuml(message_t r)
|
||||
{
|
||||
switch (r) {
|
||||
case message_t::kCall:
|
||||
return "->";
|
||||
case message_t::kReturn:
|
||||
return "-->";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config/config.h"
|
||||
#include "generator.h"
|
||||
#include "util/error.h"
|
||||
#include "util/util.h"
|
||||
|
||||
@@ -26,12 +25,13 @@
|
||||
|
||||
namespace clanguml::common::generators::plantuml {
|
||||
|
||||
using clanguml::common::model::message_t;
|
||||
using clanguml::common::model::relationship_t;
|
||||
using clanguml::common::model::scope_t;
|
||||
|
||||
std::string to_plantuml(relationship_t r, std::string style);
|
||||
|
||||
std::string to_plantuml(scope_t scope);
|
||||
std::string to_plantuml(message_t r);
|
||||
|
||||
template <typename ConfigType, typename DiagramType> class generator {
|
||||
public:
|
||||
|
||||
@@ -78,4 +78,16 @@ std::string to_string(access_t a)
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
std::string to_string(message_t r)
|
||||
{
|
||||
switch (r) {
|
||||
case message_t::kCall:
|
||||
return "call";
|
||||
case message_t::kReturn:
|
||||
return "return";
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +38,14 @@ enum class relationship_t {
|
||||
kDependency
|
||||
};
|
||||
|
||||
enum class message_t { kCall, kReturn };
|
||||
|
||||
std::string to_string(relationship_t r);
|
||||
|
||||
std::string to_string(scope_t r);
|
||||
|
||||
std::string to_string(access_t r);
|
||||
|
||||
std::string to_string(message_t r);
|
||||
|
||||
}
|
||||
|
||||
@@ -25,12 +25,10 @@
|
||||
|
||||
namespace clanguml::sequence_diagram::generators::plantuml {
|
||||
|
||||
using diagram_model = clanguml::sequence_diagram::model::diagram;
|
||||
using diagram_config = clanguml::config::sequence_diagram::diagram;
|
||||
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::model::message_t;
|
||||
using clanguml::sequence_diagram::visitor::translation_unit_context;
|
||||
using namespace clanguml::util;
|
||||
|
||||
@@ -40,31 +38,18 @@ using namespace clanguml::util;
|
||||
|
||||
generator::generator(
|
||||
clanguml::config::sequence_diagram &config, diagram_model &model)
|
||||
: m_config(config)
|
||||
, m_model(model)
|
||||
: common_generator<diagram_config, diagram_model>{config, model}
|
||||
{
|
||||
}
|
||||
|
||||
std::string generator::to_string(message_t r) const
|
||||
{
|
||||
switch (r) {
|
||||
case message_t::kCall:
|
||||
return "->";
|
||||
case message_t::kReturn:
|
||||
return "<--";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void generator::generate_call(const message &m, std::ostream &ostr) const
|
||||
{
|
||||
const auto from = ns_relative(m_config.using_namespace(), m.from);
|
||||
const auto to = ns_relative(m_config.using_namespace(), m.to);
|
||||
|
||||
ostr << '"' << from << "\" "
|
||||
<< "->"
|
||||
<< " \"" << to << "\" : " << m.message << "()" << std::endl;
|
||||
<< common::generators::plantuml::to_plantuml(message_t::kCall) << " \""
|
||||
<< to << "\" : " << m.message << "()" << std::endl;
|
||||
}
|
||||
|
||||
void generator::generate_return(const message &m, std::ostream &ostr) const
|
||||
@@ -76,7 +61,7 @@ void generator::generate_return(const message &m, std::ostream &ostr) const
|
||||
const auto to = ns_relative(m_config.using_namespace(), m.to);
|
||||
|
||||
ostr << '"' << to << "\" "
|
||||
<< "-->"
|
||||
<< common::generators::plantuml::to_plantuml(message_t::kReturn)
|
||||
<< " \"" << from << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -98,8 +83,7 @@ void generator::generate(std::ostream &ostr) const
|
||||
{
|
||||
ostr << "@startuml" << std::endl;
|
||||
|
||||
for (const auto &b : m_config.puml().before)
|
||||
ostr << b << std::endl;
|
||||
generate_plantuml_directives(ostr, m_config.puml().before);
|
||||
|
||||
for (const auto &sf : m_config.start_from()) {
|
||||
if (sf.location_type == source_location::location_t::function) {
|
||||
@@ -117,18 +101,12 @@ void generator::generate(std::ostream &ostr) const
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (const auto &a : m_config.puml().after)
|
||||
ostr << a << std::endl;
|
||||
|
||||
generate_plantuml_directives(ostr, m_config.puml().after);
|
||||
|
||||
ostr << "@enduml" << std::endl;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const generator &g)
|
||||
{
|
||||
g.generate(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
clanguml::sequence_diagram::model::diagram generate(
|
||||
cppast::libclang_compilation_database &db, const std::string &name,
|
||||
clanguml::config::sequence_diagram &diagram)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "common/generators/plantuml/generator.h"
|
||||
#include "config/config.h"
|
||||
#include "cx/compilation_database.h"
|
||||
#include "sequence_diagram/model/diagram.h"
|
||||
@@ -36,13 +37,16 @@ namespace sequence_diagram {
|
||||
namespace generators {
|
||||
namespace plantuml {
|
||||
|
||||
using diagram_config = clanguml::config::sequence_diagram;
|
||||
using diagram_model = clanguml::sequence_diagram::model::diagram;
|
||||
|
||||
class generator {
|
||||
public:
|
||||
generator(clanguml::config::sequence_diagram &config, diagram_model &model);
|
||||
template <typename C, typename D>
|
||||
using common_generator =
|
||||
clanguml::common::generators::plantuml::generator<C, D>;
|
||||
|
||||
std::string to_string(clanguml::sequence_diagram::model::message_t r) const;
|
||||
class generator : public common_generator<diagram_config, diagram_model> {
|
||||
public:
|
||||
generator(diagram_config &config, diagram_model &model);
|
||||
|
||||
void generate_call(const clanguml::sequence_diagram::model::message &m,
|
||||
std::ostream &ostr) const;
|
||||
@@ -54,12 +58,6 @@ public:
|
||||
std::ostream &ostr) const;
|
||||
|
||||
void generate(std::ostream &ostr) const;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, const generator &g);
|
||||
|
||||
private:
|
||||
clanguml::config::sequence_diagram &m_config;
|
||||
clanguml::sequence_diagram::model::diagram &m_model;
|
||||
};
|
||||
|
||||
clanguml::sequence_diagram::model::diagram generate(
|
||||
|
||||
@@ -29,4 +29,9 @@
|
||||
|
||||
namespace clanguml::sequence_diagram::model {
|
||||
|
||||
std::string diagram::to_alias(const std::string &full_name) const
|
||||
{
|
||||
return full_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
namespace clanguml::sequence_diagram::model {
|
||||
|
||||
struct diagram {
|
||||
std::string to_alias(const std::string &full_name) const;
|
||||
|
||||
bool started{false};
|
||||
std::string name;
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/**
|
||||
* src/sequence_diagram/model/enums.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
|
||||
|
||||
namespace clanguml::sequence_diagram::model {
|
||||
|
||||
enum class message_t { kCall, kReturn };
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "enums.h"
|
||||
#include "common/model/enums.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace clanguml::sequence_diagram::model {
|
||||
|
||||
struct message {
|
||||
message_t type;
|
||||
common::model::message_t type;
|
||||
std::string from;
|
||||
std::uint_least64_t from_usr;
|
||||
std::string to;
|
||||
|
||||
@@ -36,10 +36,10 @@ translation_unit_visitor::translation_unit_visitor(
|
||||
|
||||
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 clanguml::sequence_diagram::model::message_t;
|
||||
using cppast::cpp_entity;
|
||||
using cppast::cpp_entity_kind;
|
||||
using cppast::cpp_function;
|
||||
|
||||
Reference in New Issue
Block a user