Refactored sequence diagram
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
#include "puml/sequence_diagram_generator.h"
|
#include "puml/sequence_diagram_generator.h"
|
||||||
#include "uml/class_diagram/model/diagram.h"
|
#include "uml/class_diagram/model/diagram.h"
|
||||||
#include "uml/class_diagram/visitor/translation_unit_visitor.h"
|
#include "uml/class_diagram/visitor/translation_unit_visitor.h"
|
||||||
#include "uml/sequence_diagram_visitor.h"
|
#include "uml/sequence_diagram/visitor/translation_unit_context.h"
|
||||||
#include "util/util.h"
|
#include "util/util.h"
|
||||||
|
|
||||||
#include <cli11/CLI11.hpp>
|
#include <cli11/CLI11.hpp>
|
||||||
|
|||||||
@@ -18,15 +18,18 @@
|
|||||||
|
|
||||||
#include "puml/sequence_diagram_generator.h"
|
#include "puml/sequence_diagram_generator.h"
|
||||||
|
|
||||||
|
#include "uml/sequence_diagram/visitor/translation_unit_context.h"
|
||||||
|
|
||||||
namespace clanguml::generators::sequence_diagram {
|
namespace clanguml::generators::sequence_diagram {
|
||||||
namespace puml {
|
namespace puml {
|
||||||
using diagram_model = clanguml::model::sequence_diagram::diagram;
|
|
||||||
|
using diagram_model = clanguml::sequence_diagram::model::diagram;
|
||||||
using diagram_config = clanguml::config::sequence_diagram::diagram;
|
using diagram_config = clanguml::config::sequence_diagram::diagram;
|
||||||
using clanguml::config::source_location;
|
using clanguml::config::source_location;
|
||||||
using clanguml::model::sequence_diagram::activity;
|
using clanguml::sequence_diagram::model::activity;
|
||||||
using clanguml::model::sequence_diagram::message;
|
using clanguml::sequence_diagram::model::message;
|
||||||
using clanguml::model::sequence_diagram::message_t;
|
using clanguml::sequence_diagram::model::message_t;
|
||||||
using clanguml::visitor::sequence_diagram::tu_context;
|
using clanguml::sequence_diagram::visitor::translation_unit_context;
|
||||||
using namespace clanguml::util;
|
using namespace clanguml::util;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -118,12 +121,12 @@ std::ostream &operator<<(std::ostream &os, const generator &g)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clanguml::model::sequence_diagram::diagram generate(
|
clanguml::sequence_diagram::model::diagram generate(
|
||||||
clanguml::cx::compilation_database &db, const std::string &name,
|
clanguml::cx::compilation_database &db, const std::string &name,
|
||||||
clanguml::config::sequence_diagram &diagram)
|
clanguml::config::sequence_diagram &diagram)
|
||||||
{
|
{
|
||||||
spdlog::info("Generating diagram {}.puml", name);
|
spdlog::info("Generating diagram {}.puml", name);
|
||||||
clanguml::model::sequence_diagram::diagram d;
|
clanguml::sequence_diagram::model::diagram d;
|
||||||
d.name = name;
|
d.name = name;
|
||||||
|
|
||||||
// Get all translation units matching the glob from diagram
|
// Get all translation units matching the glob from diagram
|
||||||
@@ -154,9 +157,10 @@ clanguml::model::sequence_diagram::diagram generate(
|
|||||||
spdlog::debug("Cursor name: {}",
|
spdlog::debug("Cursor name: {}",
|
||||||
clang_getCString(clang_getCursorDisplayName(cursor)));
|
clang_getCString(clang_getCursorDisplayName(cursor)));
|
||||||
|
|
||||||
clanguml::visitor::sequence_diagram::tu_context ctx(d, diagram);
|
clanguml::sequence_diagram::visitor::translation_unit_context ctx(
|
||||||
|
d, diagram);
|
||||||
auto res = clang_visitChildren(cursor,
|
auto res = clang_visitChildren(cursor,
|
||||||
clanguml::visitor::sequence_diagram::translation_unit_visitor,
|
clanguml::sequence_diagram::visitor::translation_unit_visitor,
|
||||||
&ctx);
|
&ctx);
|
||||||
|
|
||||||
spdlog::debug("Processing result: {}", res);
|
spdlog::debug("Processing result: {}", res);
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "cx/compilation_database.h"
|
#include "cx/compilation_database.h"
|
||||||
#include "uml/sequence_diagram_model.h"
|
#include "uml/sequence_diagram/model/diagram.h"
|
||||||
#include "uml/sequence_diagram_visitor.h"
|
#include "uml/sequence_diagram/visitor/translation_unit_visitor.h"
|
||||||
#include "util/util.h"
|
#include "util/util.h"
|
||||||
|
|
||||||
#include <glob/glob.hpp>
|
#include <glob/glob.hpp>
|
||||||
@@ -35,21 +35,21 @@ namespace generators {
|
|||||||
namespace sequence_diagram {
|
namespace sequence_diagram {
|
||||||
namespace puml {
|
namespace puml {
|
||||||
|
|
||||||
using diagram_model = clanguml::model::sequence_diagram::diagram;
|
using diagram_model = clanguml::sequence_diagram::model::diagram;
|
||||||
|
|
||||||
class generator {
|
class generator {
|
||||||
public:
|
public:
|
||||||
generator(clanguml::config::sequence_diagram &config, diagram_model &model);
|
generator(clanguml::config::sequence_diagram &config, diagram_model &model);
|
||||||
|
|
||||||
std::string to_string(clanguml::model::sequence_diagram::message_t r) const;
|
std::string to_string(clanguml::sequence_diagram::model::message_t r) const;
|
||||||
|
|
||||||
void generate_call(const clanguml::model::sequence_diagram::message &m,
|
void generate_call(const clanguml::sequence_diagram::model::message &m,
|
||||||
std::ostream &ostr) const;
|
std::ostream &ostr) const;
|
||||||
|
|
||||||
void generate_return(const clanguml::model::sequence_diagram::message &m,
|
void generate_return(const clanguml::sequence_diagram::model::message &m,
|
||||||
std::ostream &ostr) const;
|
std::ostream &ostr) const;
|
||||||
|
|
||||||
void generate_activity(const clanguml::model::sequence_diagram::activity &a,
|
void generate_activity(const clanguml::sequence_diagram::model::activity &a,
|
||||||
std::ostream &ostr) const;
|
std::ostream &ostr) const;
|
||||||
|
|
||||||
void generate(std::ostream &ostr) const;
|
void generate(std::ostream &ostr) const;
|
||||||
@@ -58,12 +58,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
clanguml::config::sequence_diagram &m_config;
|
clanguml::config::sequence_diagram &m_config;
|
||||||
clanguml::model::sequence_diagram::diagram &m_model;
|
clanguml::sequence_diagram::model::diagram &m_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clanguml::model::sequence_diagram::diagram generate(
|
clanguml::sequence_diagram::model::diagram generate(
|
||||||
clanguml::cx::compilation_database &db, const std::string &name,
|
clanguml::cx::compilation_database &db, const std::string &name,
|
||||||
clanguml::config::sequence_diagram &diagram);
|
clanguml::config::sequence_diagram &diagram);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* src/uml/sequence_diagram_model.cc
|
* src/uml/sequence_diagram/model/activity.cc
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021 Bartek Kryza <bkryza@gmail.com>
|
* Copyright (c) 2021 Bartek Kryza <bkryza@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sequence_diagram_visitor.h"
|
#include "activity.h"
|
||||||
|
|
||||||
namespace clanguml::model::sequence_diagram {
|
namespace clanguml::sequence_diagram::model {
|
||||||
|
|
||||||
}
|
}
|
||||||
33
src/uml/sequence_diagram/model/activity.h
Normal file
33
src/uml/sequence_diagram/model/activity.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* src/uml/sequence_diagram/model/activity.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 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 "message.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace clanguml::sequence_diagram::model {
|
||||||
|
|
||||||
|
struct activity {
|
||||||
|
std::string usr;
|
||||||
|
std::string from;
|
||||||
|
std::vector<message> messages;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
32
src/uml/sequence_diagram/model/diagram.cc
Normal file
32
src/uml/sequence_diagram/model/diagram.cc
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* src/uml/sequence_diagram/model/diagram.cc
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 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 "diagram.h"
|
||||||
|
|
||||||
|
#include <clang-c/CXCompilationDatabase.h>
|
||||||
|
#include <clang-c/Index.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace clanguml::sequence_diagram::model {
|
||||||
|
|
||||||
|
}
|
||||||
34
src/uml/sequence_diagram/model/diagram.h
Normal file
34
src/uml/sequence_diagram/model/diagram.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* src/uml/sequence_diagram/model/diagram.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 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 "activity.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace clanguml::sequence_diagram::model {
|
||||||
|
|
||||||
|
struct diagram {
|
||||||
|
bool started{false};
|
||||||
|
std::string name;
|
||||||
|
|
||||||
|
std::map<std::string, activity> sequences;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
24
src/uml/sequence_diagram/model/enums.h
Normal file
24
src/uml/sequence_diagram/model/enums.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* src/uml/sequence_diagram/model/enums.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 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 };
|
||||||
|
|
||||||
|
}
|
||||||
23
src/uml/sequence_diagram/model/message.cc
Normal file
23
src/uml/sequence_diagram/model/message.cc
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* src/uml/sequence_diagram/model/message.cc
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 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 "message.h"
|
||||||
|
|
||||||
|
namespace clanguml::sequence_diagram::model {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* src/uml/sequence_diagram_model.h
|
* src/uml/sequence_diagram/model/message.h
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021 Bartek Kryza <bkryza@gmail.com>
|
* Copyright (c) 2021 Bartek Kryza <bkryza@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -17,20 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <clang-c/CXCompilationDatabase.h>
|
#include "enums.h"
|
||||||
#include <clang-c/Index.h>
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace clanguml {
|
namespace clanguml::sequence_diagram::model {
|
||||||
namespace model {
|
|
||||||
namespace sequence_diagram {
|
|
||||||
|
|
||||||
enum class message_t { kCall, kReturn };
|
|
||||||
|
|
||||||
struct message {
|
struct message {
|
||||||
message_t type;
|
message_t type;
|
||||||
@@ -43,18 +35,4 @@ struct message {
|
|||||||
unsigned int line;
|
unsigned int line;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct activity {
|
|
||||||
std::string usr;
|
|
||||||
std::string from;
|
|
||||||
std::vector<message> messages;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct diagram {
|
|
||||||
bool started{false};
|
|
||||||
std::string name;
|
|
||||||
|
|
||||||
std::map<std::string, activity> sequences;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
68
src/uml/sequence_diagram/visitor/translation_unit_context.cc
Normal file
68
src/uml/sequence_diagram/visitor/translation_unit_context.cc
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* src/uml/sequence_diagram/visitor/translation_unit_context.cc
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 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 <clang-c/CXCompilationDatabase.h>
|
||||||
|
#include <clang-c/Index.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
namespace clanguml::sequence_diagram::visitor {
|
||||||
|
|
||||||
|
translation_unit_context::translation_unit_context(
|
||||||
|
clanguml::sequence_diagram::model::diagram &diagram,
|
||||||
|
const clanguml::config::sequence_diagram &config)
|
||||||
|
: diagram_{diagram}
|
||||||
|
, config_{config}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void translation_unit_context::push_namespace(const std::string &ns)
|
||||||
|
{
|
||||||
|
namespace_.push_back(ns);
|
||||||
|
}
|
||||||
|
|
||||||
|
void translation_unit_context::pop_namespace() { namespace_.pop_back(); }
|
||||||
|
|
||||||
|
const std::vector<std::string> &translation_unit_context::get_namespace() const
|
||||||
|
{
|
||||||
|
return namespace_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const clanguml::config::sequence_diagram &
|
||||||
|
translation_unit_context::config() const
|
||||||
|
{
|
||||||
|
return config_;
|
||||||
|
}
|
||||||
|
|
||||||
|
clanguml::sequence_diagram::model::diagram &translation_unit_context::diagram()
|
||||||
|
{
|
||||||
|
return diagram_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void translation_unit_context::set_current_method(cx::cursor method)
|
||||||
|
{
|
||||||
|
current_method_ = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
cx::cursor &translation_unit_context::current_method()
|
||||||
|
{
|
||||||
|
return current_method_;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
59
src/uml/sequence_diagram/visitor/translation_unit_context.h
Normal file
59
src/uml/sequence_diagram/visitor/translation_unit_context.h
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* src/uml/sequence_diagram/visitor/translation_unit_context.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 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 "cx/cursor.h"
|
||||||
|
#include "uml/sequence_diagram/model/diagram.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace clanguml::sequence_diagram::visitor {
|
||||||
|
|
||||||
|
class translation_unit_context {
|
||||||
|
public:
|
||||||
|
translation_unit_context(
|
||||||
|
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();
|
||||||
|
|
||||||
|
void set_current_method(cx::cursor method);
|
||||||
|
|
||||||
|
cx::cursor ¤t_method();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::string> namespace_;
|
||||||
|
cx::cursor current_method_;
|
||||||
|
clanguml::sequence_diagram::model::diagram &diagram_;
|
||||||
|
const clanguml::config::sequence_diagram &config_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* src/uml/sequence_diagram_visitor.cc
|
* src/uml/sequence_diagram/visitor/translation_unit_visitor.cc
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021 Bartek Kryza <bkryza@gmail.com>
|
* Copyright (c) 2021 Bartek Kryza <bkryza@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -16,30 +16,21 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sequence_diagram_visitor.h"
|
#include "translation_unit_visitor.h"
|
||||||
|
|
||||||
namespace clanguml::visitor::sequence_diagram {
|
#include "translation_unit_context.h"
|
||||||
|
|
||||||
//
|
namespace clanguml::sequence_diagram::visitor {
|
||||||
// tu_context
|
|
||||||
//
|
|
||||||
|
|
||||||
tu_context::tu_context(clanguml::model::sequence_diagram::diagram &d_,
|
|
||||||
const clanguml::config::sequence_diagram &config_)
|
|
||||||
: d{d_}
|
|
||||||
, config{config_}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CXChildVisitResult translation_unit_visitor(
|
enum CXChildVisitResult translation_unit_visitor(
|
||||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data)
|
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data)
|
||||||
{
|
{
|
||||||
using clanguml::model::sequence_diagram::activity;
|
using clanguml::sequence_diagram::model::activity;
|
||||||
using clanguml::model::sequence_diagram::diagram;
|
using clanguml::sequence_diagram::model::diagram;
|
||||||
using clanguml::model::sequence_diagram::message;
|
using clanguml::sequence_diagram::model::message;
|
||||||
using clanguml::model::sequence_diagram::message_t;
|
using clanguml::sequence_diagram::model::message_t;
|
||||||
|
|
||||||
struct tu_context *ctx = (struct tu_context *)client_data;
|
auto *ctx = (struct translation_unit_context *)client_data;
|
||||||
|
|
||||||
enum CXChildVisitResult ret = CXChildVisit_Break;
|
enum CXChildVisitResult ret = CXChildVisit_Break;
|
||||||
|
|
||||||
@@ -54,7 +45,7 @@ enum CXChildVisitResult translation_unit_visitor(
|
|||||||
case CXCursor_FunctionTemplate:
|
case CXCursor_FunctionTemplate:
|
||||||
case CXCursor_CXXMethod:
|
case CXCursor_CXXMethod:
|
||||||
case CXCursor_FunctionDecl:
|
case CXCursor_FunctionDecl:
|
||||||
ctx->current_method = cursor;
|
ctx->set_current_method(cursor);
|
||||||
ret = CXChildVisit_Recurse;
|
ret = CXChildVisit_Recurse;
|
||||||
break;
|
break;
|
||||||
case CXCursor_CallExpr: {
|
case CXCursor_CallExpr: {
|
||||||
@@ -74,25 +65,28 @@ enum CXChildVisitResult translation_unit_visitor(
|
|||||||
clang_getFileLocation(cursor.location(), &f, &line, &column, &offset);
|
clang_getFileLocation(cursor.location(), &f, &line, &column, &offset);
|
||||||
std::string file{clang_getCString(clang_getFileName(f))};
|
std::string file{clang_getCString(clang_getFileName(f))};
|
||||||
|
|
||||||
auto &d = ctx->d;
|
auto &d = ctx->diagram();
|
||||||
auto &config = ctx->config;
|
auto &config = ctx->config();
|
||||||
if (referenced.kind() == CXCursor_CXXMethod) {
|
if (referenced.kind() == CXCursor_CXXMethod) {
|
||||||
if (config.should_include(sp_name)) {
|
if (config.should_include(sp_name)) {
|
||||||
// Get calling object
|
// Get calling object
|
||||||
std::string caller{};
|
std::string caller{};
|
||||||
if (ctx->current_method.semantic_parent()
|
if (ctx->current_method()
|
||||||
|
.semantic_parent()
|
||||||
.is_translation_unit() ||
|
.is_translation_unit() ||
|
||||||
ctx->current_method.semantic_parent().is_namespace()) {
|
ctx->current_method().semantic_parent().is_namespace()) {
|
||||||
caller = ctx->current_method.semantic_parent()
|
caller = ctx->current_method()
|
||||||
|
.semantic_parent()
|
||||||
.fully_qualified() +
|
.fully_qualified() +
|
||||||
"::" + ctx->current_method.spelling() + "()";
|
"::" + ctx->current_method().spelling() + "()";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
caller =
|
caller = ctx->current_method()
|
||||||
ctx->current_method.semantic_parent().fully_qualified();
|
.semantic_parent()
|
||||||
|
.fully_qualified();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto caller_usr = ctx->current_method.usr();
|
auto caller_usr = ctx->current_method().usr();
|
||||||
// Get called object
|
// Get called object
|
||||||
auto callee = referenced.semantic_parent().fully_qualified();
|
auto callee = referenced.semantic_parent().fully_qualified();
|
||||||
auto callee_usr = referenced.semantic_parent().usr();
|
auto callee_usr = referenced.semantic_parent().usr();
|
||||||
@@ -105,8 +99,8 @@ enum CXChildVisitResult translation_unit_visitor(
|
|||||||
"\n\tCURRENT_METHOD: {}\n\tFROM: '{}'\n\tTO: "
|
"\n\tCURRENT_METHOD: {}\n\tFROM: '{}'\n\tTO: "
|
||||||
"{}\n\tMESSAGE: {}\n\tFROM_USR: {}\n\tTO_USR: "
|
"{}\n\tMESSAGE: {}\n\tFROM_USR: {}\n\tTO_USR: "
|
||||||
"{}\n\tRETURN_TYPE: {}",
|
"{}\n\tRETURN_TYPE: {}",
|
||||||
file, line, d.name, ctx->current_method.spelling(), caller,
|
file, line, d.name, ctx->current_method().spelling(),
|
||||||
callee, called_message, caller_usr, callee_usr,
|
caller, callee, called_message, caller_usr, callee_usr,
|
||||||
referenced.type().result_type().spelling());
|
referenced.type().result_type().spelling());
|
||||||
|
|
||||||
message m;
|
message m;
|
||||||
@@ -146,5 +140,4 @@ enum CXChildVisitResult translation_unit_visitor(
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* src/uml/sequence_diagram_visitor.h
|
* src/uml/sequence_diagram/visitor/translation_unit_visitor.h
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021 Bartek Kryza <bkryza@gmail.com>
|
* Copyright (c) 2021 Bartek Kryza <bkryza@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -19,33 +19,11 @@
|
|||||||
|
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "cx/cursor.h"
|
#include "cx/cursor.h"
|
||||||
#include "sequence_diagram_model.h"
|
#include "uml/sequence_diagram/model/diagram.h"
|
||||||
|
|
||||||
#include <clang-c/CXCompilationDatabase.h>
|
namespace clanguml::sequence_diagram::visitor {
|
||||||
#include <clang-c/Index.h>
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace clanguml {
|
|
||||||
namespace visitor {
|
|
||||||
namespace sequence_diagram {
|
|
||||||
|
|
||||||
struct tu_context {
|
|
||||||
tu_context(clanguml::model::sequence_diagram::diagram &d_,
|
|
||||||
const clanguml::config::sequence_diagram &config_);
|
|
||||||
|
|
||||||
std::vector<std::string> namespace_;
|
|
||||||
cx::cursor current_method;
|
|
||||||
clanguml::model::sequence_diagram::diagram &d;
|
|
||||||
const clanguml::config::sequence_diagram &config;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum CXChildVisitResult translation_unit_visitor(
|
enum CXChildVisitResult translation_unit_visitor(
|
||||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data);
|
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -40,7 +40,7 @@ std::pair<clanguml::config::config, compilation_database> load_config2(
|
|||||||
return std::make_pair(std::move(config), std::move(db));
|
return std::make_pair(std::move(config), std::move(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
clanguml::model::sequence_diagram::diagram generate_sequence_diagram(
|
clanguml::sequence_diagram::model::diagram generate_sequence_diagram(
|
||||||
compilation_database &db,
|
compilation_database &db,
|
||||||
std::shared_ptr<clanguml::config::diagram> diagram)
|
std::shared_ptr<clanguml::config::diagram> diagram)
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ clanguml::class_diagram::model::diagram generate_class_diagram(
|
|||||||
|
|
||||||
std::string generate_sequence_puml(
|
std::string generate_sequence_puml(
|
||||||
std::shared_ptr<clanguml::config::diagram> config,
|
std::shared_ptr<clanguml::config::diagram> config,
|
||||||
clanguml::model::sequence_diagram::diagram &model)
|
clanguml::sequence_diagram::model::diagram &model)
|
||||||
{
|
{
|
||||||
using namespace clanguml::generators::sequence_diagram::puml;
|
using namespace clanguml::generators::sequence_diagram::puml;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
#include "puml/sequence_diagram_generator.h"
|
#include "puml/sequence_diagram_generator.h"
|
||||||
#include "uml/class_diagram/model/diagram.h"
|
#include "uml/class_diagram/model/diagram.h"
|
||||||
#include "uml/class_diagram/visitor/translation_unit_visitor.h"
|
#include "uml/class_diagram/visitor/translation_unit_visitor.h"
|
||||||
#include "uml/sequence_diagram_visitor.h"
|
#include "uml/sequence_diagram/visitor/translation_unit_visitor.h"
|
||||||
#include "util/util.h"
|
#include "util/util.h"
|
||||||
|
|
||||||
#define CATCH_CONFIG_RUNNER
|
#define CATCH_CONFIG_RUNNER
|
||||||
@@ -48,7 +48,7 @@ load_config(const std::string &test_name);
|
|||||||
std::pair<clanguml::config::config, compilation_database> load_config2(
|
std::pair<clanguml::config::config, compilation_database> load_config2(
|
||||||
const std::string &test_name);
|
const std::string &test_name);
|
||||||
|
|
||||||
clanguml::model::sequence_diagram::diagram generate_sequence_diagram(
|
clanguml::sequence_diagram::model::diagram generate_sequence_diagram(
|
||||||
compilation_database &db,
|
compilation_database &db,
|
||||||
std::shared_ptr<clanguml::config::diagram> diagram);
|
std::shared_ptr<clanguml::config::diagram> diagram);
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ clanguml::class_diagram::model::diagram generate_class_diagram(
|
|||||||
|
|
||||||
std::string generate_sequence_puml(
|
std::string generate_sequence_puml(
|
||||||
std::shared_ptr<clanguml::config::diagram> config,
|
std::shared_ptr<clanguml::config::diagram> config,
|
||||||
clanguml::model::sequence_diagram::diagram &model);
|
clanguml::sequence_diagram::model::diagram &model);
|
||||||
|
|
||||||
std::string generate_class_puml(
|
std::string generate_class_puml(
|
||||||
std::shared_ptr<clanguml::config::diagram> config,
|
std::shared_ptr<clanguml::config::diagram> config,
|
||||||
|
|||||||
Reference in New Issue
Block a user