Refactored top level directory structure
This commit is contained in:
23
src/sequence_diagram/model/activity.cc
Normal file
23
src/sequence_diagram/model/activity.cc
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* src/uml/sequence_diagram/model/activity.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 "activity.h"
|
||||
|
||||
namespace clanguml::sequence_diagram::model {
|
||||
|
||||
}
|
||||
33
src/sequence_diagram/model/activity.h
Normal file
33
src/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/sequence_diagram/model/diagram.cc
Normal file
32
src/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/sequence_diagram/model/diagram.h
Normal file
34
src/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/sequence_diagram/model/enums.h
Normal file
24
src/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/sequence_diagram/model/message.cc
Normal file
23
src/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 {
|
||||
|
||||
}
|
||||
38
src/sequence_diagram/model/message.h
Normal file
38
src/sequence_diagram/model/message.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* src/uml/sequence_diagram/model/message.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 "enums.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace clanguml::sequence_diagram::model {
|
||||
|
||||
struct message {
|
||||
message_t type;
|
||||
std::string from;
|
||||
std::string from_usr;
|
||||
std::string to;
|
||||
std::string to_usr;
|
||||
std::string message;
|
||||
std::string return_type;
|
||||
unsigned int line;
|
||||
};
|
||||
|
||||
}
|
||||
68
src/sequence_diagram/visitor/translation_unit_context.cc
Normal file
68
src/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/sequence_diagram/visitor/translation_unit_context.h
Normal file
59
src/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 "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_;
|
||||
};
|
||||
|
||||
}
|
||||
143
src/sequence_diagram/visitor/translation_unit_visitor.cc
Normal file
143
src/sequence_diagram/visitor/translation_unit_visitor.cc
Normal file
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* src/uml/sequence_diagram/visitor/translation_unit_visitor.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_visitor.h"
|
||||
|
||||
#include "translation_unit_context.h"
|
||||
|
||||
namespace clanguml::sequence_diagram::visitor {
|
||||
|
||||
enum CXChildVisitResult translation_unit_visitor(
|
||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data)
|
||||
{
|
||||
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;
|
||||
|
||||
auto *ctx = (struct translation_unit_context *)client_data;
|
||||
|
||||
enum CXChildVisitResult ret = CXChildVisit_Break;
|
||||
|
||||
cx::cursor cursor{std::move(cx_cursor)};
|
||||
cx::cursor parent{std::move(cx_parent)};
|
||||
|
||||
if (cursor.spelling().empty()) {
|
||||
return CXChildVisit_Recurse;
|
||||
}
|
||||
|
||||
switch (cursor.kind()) {
|
||||
case CXCursor_FunctionTemplate:
|
||||
case CXCursor_CXXMethod:
|
||||
case CXCursor_FunctionDecl:
|
||||
ctx->set_current_method(cursor);
|
||||
ret = CXChildVisit_Recurse;
|
||||
break;
|
||||
case CXCursor_CallExpr: {
|
||||
auto referenced = cursor.referenced();
|
||||
auto referenced_type = referenced.type();
|
||||
auto referenced_cursor_name = referenced.display_name();
|
||||
|
||||
auto semantic_parent = referenced.semantic_parent();
|
||||
auto sp_name = semantic_parent.fully_qualified();
|
||||
auto lexical_parent = cursor.lexical_parent();
|
||||
auto lp_name = lexical_parent.spelling();
|
||||
|
||||
CXFile f;
|
||||
unsigned int line{};
|
||||
unsigned int column{};
|
||||
unsigned int offset{};
|
||||
clang_getFileLocation(cursor.location(), &f, &line, &column, &offset);
|
||||
std::string file{clang_getCString(clang_getFileName(f))};
|
||||
|
||||
auto &d = ctx->diagram();
|
||||
auto &config = ctx->config();
|
||||
if (referenced.kind() == CXCursor_CXXMethod) {
|
||||
if (config.should_include(sp_name)) {
|
||||
// Get calling object
|
||||
std::string caller{};
|
||||
if (ctx->current_method()
|
||||
.semantic_parent()
|
||||
.is_translation_unit() ||
|
||||
ctx->current_method().semantic_parent().is_namespace()) {
|
||||
caller = ctx->current_method()
|
||||
.semantic_parent()
|
||||
.fully_qualified() +
|
||||
"::" + ctx->current_method().spelling() + "()";
|
||||
}
|
||||
else {
|
||||
caller = ctx->current_method()
|
||||
.semantic_parent()
|
||||
.fully_qualified();
|
||||
}
|
||||
|
||||
auto caller_usr = ctx->current_method().usr();
|
||||
// Get called object
|
||||
auto callee = referenced.semantic_parent().fully_qualified();
|
||||
auto callee_usr = referenced.semantic_parent().usr();
|
||||
|
||||
// Get called method
|
||||
auto called_message = cursor.spelling();
|
||||
|
||||
// Found method call: CXCursorKind () const
|
||||
spdlog::debug("Adding method call at line {}:{} to diagram {}"
|
||||
"\n\tCURRENT_METHOD: {}\n\tFROM: '{}'\n\tTO: "
|
||||
"{}\n\tMESSAGE: {}\n\tFROM_USR: {}\n\tTO_USR: "
|
||||
"{}\n\tRETURN_TYPE: {}",
|
||||
file, line, d.name, ctx->current_method().spelling(),
|
||||
caller, callee, called_message, caller_usr, callee_usr,
|
||||
referenced.type().result_type().spelling());
|
||||
|
||||
message m;
|
||||
m.type = message_t::kCall;
|
||||
m.from = caller;
|
||||
m.from_usr = caller_usr;
|
||||
m.line = line;
|
||||
m.to = callee;
|
||||
m.to_usr = referenced.usr();
|
||||
m.message = called_message;
|
||||
m.return_type = referenced.type().result_type().spelling();
|
||||
|
||||
if (d.sequences.find(caller_usr) == d.sequences.end()) {
|
||||
activity a;
|
||||
a.usr = caller_usr;
|
||||
a.from = caller;
|
||||
d.sequences.insert({caller_usr, std::move(a)});
|
||||
}
|
||||
|
||||
d.sequences[caller_usr].messages.emplace_back(std::move(m));
|
||||
}
|
||||
}
|
||||
else if (referenced.kind() == CXCursor_FunctionDecl) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
ret = CXChildVisit_Recurse;
|
||||
break;
|
||||
}
|
||||
case CXCursor_Namespace: {
|
||||
ret = CXChildVisit_Recurse;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = CXChildVisit_Recurse;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
29
src/sequence_diagram/visitor/translation_unit_visitor.h
Normal file
29
src/sequence_diagram/visitor/translation_unit_visitor.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* src/uml/sequence_diagram/visitor/translation_unit_visitor.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 "sequence_diagram/model/diagram.h"
|
||||
|
||||
namespace clanguml::sequence_diagram::visitor {
|
||||
|
||||
enum CXChildVisitResult translation_unit_visitor(
|
||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user