Merge pull request #1 from bkryza/refactor-to-cppast
Refactor to cppast
This commit is contained in:
@@ -9,3 +9,4 @@ PointerBindsToType: false
|
|||||||
Standard: Cpp11
|
Standard: Cpp11
|
||||||
BreakBeforeBinaryOperators: false
|
BreakBeforeBinaryOperators: false
|
||||||
BreakBeforeBraces: Stroustrup
|
BreakBeforeBraces: Stroustrup
|
||||||
|
IndentCaseLabels: false
|
||||||
|
|||||||
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@@ -6,7 +6,10 @@ jobs:
|
|||||||
build-ubuntu:
|
build-ubuntu:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: sudo apt-get install ccache cmake libyaml-cpp-dev libspdlog-dev clang-11 libclang-11-dev libclang-cpp11-dev
|
run: sudo apt-get install ccache cmake libyaml-cpp-dev libspdlog-dev clang-11 libclang-11-dev libclang-cpp11-dev
|
||||||
- name: Build and unit test
|
- name: Build and unit test
|
||||||
|
|||||||
4
.gitmodules
vendored
Normal file
4
.gitmodules
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[submodule "thirdparty/cppast"]
|
||||||
|
path = thirdparty/cppast
|
||||||
|
url = https://github.com/bkryza/cppast
|
||||||
|
branch = handle-exposed-template-arguments
|
||||||
@@ -15,6 +15,8 @@ set(CLANG_UML_INSTALL_BIN_DIR ${PROJECT_SOURCE_DIR}/bin)
|
|||||||
|
|
||||||
set(UML_HEADERS_DIR ${PROJECT_SOURCE_DIR}/src/uml)
|
set(UML_HEADERS_DIR ${PROJECT_SOURCE_DIR}/src/uml)
|
||||||
|
|
||||||
|
set(LLVM_PREFERRED_VERSION 11.0.0)
|
||||||
|
|
||||||
message(STATUS "Checking for spdlog...")
|
message(STATUS "Checking for spdlog...")
|
||||||
find_package(spdlog REQUIRED)
|
find_package(spdlog REQUIRED)
|
||||||
|
|
||||||
@@ -28,6 +30,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 ${LIBCLANG_CXXFLAGS}")
|
|||||||
|
|
||||||
# Thirdparty sources
|
# Thirdparty sources
|
||||||
set(THIRDPARTY_HEADERS_DIR ${PROJECT_SOURCE_DIR}/thirdparty/)
|
set(THIRDPARTY_HEADERS_DIR ${PROJECT_SOURCE_DIR}/thirdparty/)
|
||||||
|
add_subdirectory(thirdparty/cppast)
|
||||||
|
|
||||||
find_package(LLVM REQUIRED CONFIG)
|
find_package(LLVM REQUIRED CONFIG)
|
||||||
set(CLANG_INCLUDE_DIRS "llvm/clang/include")
|
set(CLANG_INCLUDE_DIRS "llvm/clang/include")
|
||||||
@@ -37,6 +40,9 @@ include_directories(${CLANG_UML_INSTALL_INCLUDE_DIR})
|
|||||||
include_directories(${YAML_CPP_INCLUDE_DIR})
|
include_directories(${YAML_CPP_INCLUDE_DIR})
|
||||||
include_directories(${UML_HEADERS_DIR})
|
include_directories(${UML_HEADERS_DIR})
|
||||||
include_directories(${THIRDPARTY_HEADERS_DIR})
|
include_directories(${THIRDPARTY_HEADERS_DIR})
|
||||||
|
include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/include)
|
||||||
|
include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/external/type_safe/include)
|
||||||
|
include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/external/type_safe/external/debug_assert)
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/src/)
|
include_directories(${PROJECT_SOURCE_DIR}/src/)
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCES src/*.cc include/*.h)
|
file(GLOB_RECURSE SOURCES src/*.cc include/*.h)
|
||||||
@@ -47,7 +53,7 @@ add_library(clang-umllib OBJECT ${SOURCES})
|
|||||||
|
|
||||||
add_executable(clang-uml ${MAIN_SOURCE_FILE})
|
add_executable(clang-uml ${MAIN_SOURCE_FILE})
|
||||||
install(TARGETS clang-uml DESTINATION ${CLANG_UML_INSTALL_BIN_DIR})
|
install(TARGETS clang-uml DESTINATION ${CLANG_UML_INSTALL_BIN_DIR})
|
||||||
target_link_libraries(clang-uml ${LIBCLANG_LIBRARIES} ${YAML_CPP_LIBRARIES} spdlog::spdlog clang-umllib)
|
target_link_libraries(clang-uml ${LIBCLANG_LIBRARIES} ${YAML_CPP_LIBRARIES} spdlog::spdlog cppast clang-umllib)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -21,7 +21,7 @@
|
|||||||
# Specify preferred LLVM version for CMake
|
# Specify preferred LLVM version for CMake
|
||||||
LLVM_VERSION ?= 11
|
LLVM_VERSION ?= 11
|
||||||
|
|
||||||
.DEFAULT_GOAL := test
|
.DEFAULT_GOAL := debug
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -211,6 +211,11 @@ public:
|
|||||||
return clang_getCXXAccessSpecifier(m_cursor);
|
return clang_getCXXAccessSpecifier(m_cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cx::type underlying_type() const
|
||||||
|
{
|
||||||
|
return clang_getTypedefDeclUnderlyingType(m_cursor);
|
||||||
|
}
|
||||||
|
|
||||||
int template_argument_count() const
|
int template_argument_count() const
|
||||||
{
|
{
|
||||||
return clang_Cursor_getNumTemplateArguments(m_cursor);
|
return clang_Cursor_getNumTemplateArguments(m_cursor);
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#include "cx/util.h"
|
#include "cx/util.h"
|
||||||
|
|
||||||
|
#include <cppast/cpp_class.hpp>
|
||||||
|
#include <cppast/cpp_entity_kind.hpp>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
namespace clanguml {
|
namespace clanguml {
|
||||||
@@ -30,6 +32,77 @@ std::string to_string(CXString &&cxs)
|
|||||||
clang_disposeString(cxs);
|
clang_disposeString(cxs);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string full_name(const cppast::cpp_entity &e)
|
||||||
|
{
|
||||||
|
if (e.name().empty())
|
||||||
|
return "";
|
||||||
|
else if (cppast::is_parameter(e.kind()))
|
||||||
|
// parameters don't have a full name
|
||||||
|
return e.name();
|
||||||
|
|
||||||
|
std::string scopes;
|
||||||
|
|
||||||
|
for (auto cur = e.parent(); cur; cur = cur.value().parent())
|
||||||
|
// prepend each scope, if there is any
|
||||||
|
if (cur.value().kind() == cppast::cpp_entity_kind::namespace_t)
|
||||||
|
type_safe::with(cur.value().scope_name(),
|
||||||
|
[&](const cppast::cpp_scope_name &cur_scope) {
|
||||||
|
scopes = cur_scope.name() + "::" + scopes;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (e.kind() == cppast::cpp_entity_kind::class_t) {
|
||||||
|
auto &c = static_cast<const cppast::cpp_class &>(e);
|
||||||
|
return scopes /*+ c.semantic_scope()*/ + c.name();
|
||||||
|
}
|
||||||
|
else if (e.kind() == cppast::cpp_entity_kind::class_template_t) {
|
||||||
|
return scopes;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return scopes + e.name();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ns(const cppast::cpp_entity &e)
|
||||||
|
{
|
||||||
|
std::vector<std::string> res{};
|
||||||
|
|
||||||
|
auto it = e.parent();
|
||||||
|
while (it) {
|
||||||
|
if (it.value().kind() == cppast::cpp_entity_kind::namespace_t) {
|
||||||
|
res.push_back(it.value().name());
|
||||||
|
}
|
||||||
|
it = it.value().parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt::format("{}", fmt::join(res.rbegin(), res.rend(), "::"));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string fully_prefixed(const cppast::cpp_entity &e)
|
||||||
|
{
|
||||||
|
std::vector<std::string> res{e.name()};
|
||||||
|
|
||||||
|
auto it = e.parent();
|
||||||
|
while (it) {
|
||||||
|
if (it.value().kind() == cppast::cpp_entity_kind::namespace_t) {
|
||||||
|
res.push_back(it.value().name());
|
||||||
|
}
|
||||||
|
it = it.value().parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt::format("{}", fmt::join(res.rbegin(), res.rend(), "::"));
|
||||||
|
}
|
||||||
|
|
||||||
|
const cppast::cpp_type &unreferenced(const cppast::cpp_type &t)
|
||||||
|
{
|
||||||
|
if (t.kind() == cppast::cpp_type_kind::pointer_t)
|
||||||
|
return unreferenced(
|
||||||
|
static_cast<const cppast::cpp_pointer_type &>(t).pointee());
|
||||||
|
else if (t.kind() == cppast::cpp_type_kind::reference_t)
|
||||||
|
return unreferenced(
|
||||||
|
static_cast<const cppast::cpp_reference_type &>(t).referee());
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
} // namespace util
|
} // namespace util
|
||||||
} // namespace cx
|
} // namespace cx
|
||||||
} // namespace clanguml
|
} // namespace clanguml
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include <clang-c/CXCompilationDatabase.h>
|
#include <clang-c/CXCompilationDatabase.h>
|
||||||
#include <clang-c/Index.h>
|
#include <clang-c/Index.h>
|
||||||
|
#include <cppast/cpp_entity.hpp>
|
||||||
|
#include <cppast/cpp_type.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -38,6 +40,12 @@ namespace util {
|
|||||||
*/
|
*/
|
||||||
std::string to_string(CXString &&cxs);
|
std::string to_string(CXString &&cxs);
|
||||||
|
|
||||||
|
std::string full_name(const cppast::cpp_entity &e);
|
||||||
|
|
||||||
|
std::string fully_prefixed(const cppast::cpp_entity &e);
|
||||||
|
|
||||||
|
const cppast::cpp_type &unreferenced(const cppast::cpp_type &t);
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
} // namespace cx
|
} // namespace cx
|
||||||
} // namespace clanguml
|
} // namespace clanguml
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "uml/sequence_diagram_visitor.h"
|
#include "uml/sequence_diagram_visitor.h"
|
||||||
|
|
||||||
#include <cli11/CLI11.hpp>
|
#include <cli11/CLI11.hpp>
|
||||||
|
#include <cppast/libclang_parser.hpp>
|
||||||
#include <glob/glob.hpp>
|
#include <glob/glob.hpp>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
@@ -73,6 +74,8 @@ int main(int argc, const char *argv[])
|
|||||||
auto db =
|
auto db =
|
||||||
compilation_database::from_directory(config.compilation_database_dir);
|
compilation_database::from_directory(config.compilation_database_dir);
|
||||||
|
|
||||||
|
cppast::libclang_compilation_database db2(config.compilation_database_dir);
|
||||||
|
|
||||||
for (const auto &[name, diagram] : config.diagrams) {
|
for (const auto &[name, diagram] : config.diagrams) {
|
||||||
using clanguml::config::class_diagram;
|
using clanguml::config::class_diagram;
|
||||||
using clanguml::config::sequence_diagram;
|
using clanguml::config::sequence_diagram;
|
||||||
@@ -83,7 +86,7 @@ int main(int argc, const char *argv[])
|
|||||||
|
|
||||||
if (std::dynamic_pointer_cast<class_diagram>(diagram)) {
|
if (std::dynamic_pointer_cast<class_diagram>(diagram)) {
|
||||||
auto model = generators::class_diagram::generate(
|
auto model = generators::class_diagram::generate(
|
||||||
db, name, dynamic_cast<class_diagram &>(*diagram));
|
db2, name, dynamic_cast<class_diagram &>(*diagram));
|
||||||
|
|
||||||
ofs << clanguml::generators::class_diagram::puml::generator(
|
ofs << clanguml::generators::class_diagram::puml::generator(
|
||||||
dynamic_cast<clanguml::config::class_diagram &>(*diagram),
|
dynamic_cast<clanguml::config::class_diagram &>(*diagram),
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
#include "uml/class_diagram_visitor.h"
|
#include "uml/class_diagram_visitor.h"
|
||||||
#include "util/util.h"
|
#include "util/util.h"
|
||||||
|
|
||||||
|
#include <cppast/cpp_entity_index.hpp>
|
||||||
|
#include <cppast/libclang_parser.hpp>
|
||||||
#include <glob/glob.hpp>
|
#include <glob/glob.hpp>
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
@@ -85,7 +87,7 @@ public:
|
|||||||
case relationship_t::kAggregation:
|
case relationship_t::kAggregation:
|
||||||
return "o--";
|
return "o--";
|
||||||
case relationship_t::kContainment:
|
case relationship_t::kContainment:
|
||||||
return "+--";
|
return "--+";
|
||||||
case relationship_t::kAssociation:
|
case relationship_t::kAssociation:
|
||||||
return "-->";
|
return "-->";
|
||||||
case relationship_t::kInstantiation:
|
case relationship_t::kInstantiation:
|
||||||
@@ -222,6 +224,33 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ostr << "}" << std::endl;
|
ostr << "}" << std::endl;
|
||||||
|
|
||||||
|
for (const auto &r : e.relationships) {
|
||||||
|
std::string destination;
|
||||||
|
if (r.destination.find("#") != std::string::npos ||
|
||||||
|
r.destination.find("@") != std::string::npos) {
|
||||||
|
destination = m_model.usr_to_name(
|
||||||
|
m_config.using_namespace, r.destination);
|
||||||
|
if (destination.empty()) {
|
||||||
|
ostr << "' ";
|
||||||
|
destination = r.destination;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
destination = r.destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
ostr << m_model.to_alias(m_config.using_namespace,
|
||||||
|
ns_relative(m_config.using_namespace, e.name))
|
||||||
|
<< " " << to_string(r.type) << " "
|
||||||
|
<< m_model.to_alias(m_config.using_namespace,
|
||||||
|
ns_relative(m_config.using_namespace, destination));
|
||||||
|
|
||||||
|
if (!r.label.empty())
|
||||||
|
ostr << " : " << r.label;
|
||||||
|
|
||||||
|
ostr << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate(std::ostream &ostr) const
|
void generate(std::ostream &ostr) const
|
||||||
@@ -267,7 +296,7 @@ std::ostream &operator<<(std::ostream &os, const generator &g)
|
|||||||
}
|
}
|
||||||
|
|
||||||
clanguml::model::class_diagram::diagram generate(
|
clanguml::model::class_diagram::diagram generate(
|
||||||
clanguml::cx::compilation_database &db, const std::string &name,
|
cppast::libclang_compilation_database &db, const std::string &name,
|
||||||
clanguml::config::class_diagram &diagram)
|
clanguml::config::class_diagram &diagram)
|
||||||
{
|
{
|
||||||
spdlog::info("Generating diagram {}.puml", name);
|
spdlog::info("Generating diagram {}.puml", name);
|
||||||
@@ -276,7 +305,7 @@ clanguml::model::class_diagram::diagram generate(
|
|||||||
|
|
||||||
// Get all translation units matching the glob from diagram
|
// Get all translation units matching the glob from diagram
|
||||||
// configuration
|
// configuration
|
||||||
std::vector<std::filesystem::path> translation_units{};
|
std::vector<std::string> translation_units{};
|
||||||
for (const auto &g : diagram.glob) {
|
for (const auto &g : diagram.glob) {
|
||||||
spdlog::debug("Processing glob: {}", g);
|
spdlog::debug("Processing glob: {}", g);
|
||||||
const auto matches = glob::glob(g);
|
const auto matches = glob::glob(g);
|
||||||
@@ -284,13 +313,21 @@ clanguml::model::class_diagram::diagram generate(
|
|||||||
std::back_inserter(translation_units));
|
std::back_inserter(translation_units));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cppast::cpp_entity_index idx;
|
||||||
|
cppast::simple_file_parser<cppast::libclang_parser> parser{
|
||||||
|
type_safe::ref(idx)};
|
||||||
|
|
||||||
// Process all matching translation units
|
// Process all matching translation units
|
||||||
|
clanguml::visitor::class_diagram::tu_visitor ctx(idx, d, diagram);
|
||||||
|
cppast::parse_files(parser, translation_units, db);
|
||||||
|
for (auto &file : parser.files())
|
||||||
|
ctx(file);
|
||||||
|
|
||||||
|
/*
|
||||||
for (const auto &tu_path : translation_units) {
|
for (const auto &tu_path : translation_units) {
|
||||||
spdlog::debug("Processing translation unit: {}",
|
spdlog::debug("Processing translation unit: {}",
|
||||||
std::filesystem::canonical(tu_path).c_str());
|
std::filesystem::canonical(tu_path).c_str());
|
||||||
|
|
||||||
auto tu = db.parse_translation_unit(tu_path);
|
|
||||||
|
|
||||||
auto cursor = clang_getTranslationUnitCursor(tu);
|
auto cursor = clang_getTranslationUnitCursor(tu);
|
||||||
|
|
||||||
if (clang_Cursor_isNull(cursor)) {
|
if (clang_Cursor_isNull(cursor)) {
|
||||||
@@ -309,6 +346,7 @@ clanguml::model::class_diagram::diagram generate(
|
|||||||
|
|
||||||
clang_suspendTranslationUnit(tu);
|
clang_suspendTranslationUnit(tu);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,34 @@ namespace clanguml {
|
|||||||
namespace model {
|
namespace model {
|
||||||
namespace class_diagram {
|
namespace class_diagram {
|
||||||
std::atomic_uint64_t element::m_nextId = 1;
|
std::atomic_uint64_t element::m_nextId = 1;
|
||||||
|
|
||||||
|
std::string to_string(relationship_t r)
|
||||||
|
{
|
||||||
|
switch (r) {
|
||||||
|
case relationship_t::kNone:
|
||||||
|
return "none";
|
||||||
|
case relationship_t::kExtension:
|
||||||
|
return "extension";
|
||||||
|
case relationship_t::kComposition:
|
||||||
|
return "composition";
|
||||||
|
case relationship_t::kAggregation:
|
||||||
|
return "aggregation";
|
||||||
|
case relationship_t::kContainment:
|
||||||
|
return "containment";
|
||||||
|
case relationship_t::kOwnership:
|
||||||
|
return "ownership";
|
||||||
|
case relationship_t::kAssociation:
|
||||||
|
return "association";
|
||||||
|
case relationship_t::kInstantiation:
|
||||||
|
return "instantiation";
|
||||||
|
case relationship_t::kFriendship:
|
||||||
|
return "frendship";
|
||||||
|
case relationship_t::kDependency:
|
||||||
|
return "dependency";
|
||||||
|
default:
|
||||||
|
return "invalid";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ enum class relationship_t {
|
|||||||
kDependency
|
kDependency
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string to_string(relationship_t r);
|
||||||
|
|
||||||
class element {
|
class element {
|
||||||
public:
|
public:
|
||||||
element()
|
element()
|
||||||
@@ -211,6 +213,7 @@ public:
|
|||||||
|
|
||||||
struct enum_ : public element {
|
struct enum_ : public element {
|
||||||
std::vector<std::string> constants;
|
std::vector<std::string> constants;
|
||||||
|
std::vector<class_relationship> relationships;
|
||||||
|
|
||||||
friend bool operator==(const enum_ &l, const enum_ &r)
|
friend bool operator==(const enum_ &l, const enum_ &r)
|
||||||
{
|
{
|
||||||
@@ -225,17 +228,22 @@ struct diagram {
|
|||||||
|
|
||||||
void add_class(class_ &&c)
|
void add_class(class_ &&c)
|
||||||
{
|
{
|
||||||
spdlog::debug("ADDING CLASS: {}, {}", c.name, c.usr);
|
spdlog::debug("Adding class: {}, {}", c.name, c.usr);
|
||||||
auto it = std::find(classes.begin(), classes.end(), c);
|
auto it = std::find(classes.begin(), classes.end(), c);
|
||||||
if (it == classes.end())
|
if (it == classes.end())
|
||||||
classes.emplace_back(std::move(c));
|
classes.emplace_back(std::move(c));
|
||||||
|
else
|
||||||
|
spdlog::debug("Class {} already in the model", c.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_enum(enum_ &&e)
|
void add_enum(enum_ &&e)
|
||||||
{
|
{
|
||||||
|
spdlog::debug("Adding enum: {}", e.name);
|
||||||
auto it = std::find(enums.begin(), enums.end(), e);
|
auto it = std::find(enums.begin(), enums.end(), e);
|
||||||
if (it == enums.end())
|
if (it == enums.end())
|
||||||
enums.emplace_back(std::move(e));
|
enums.emplace_back(std::move(e));
|
||||||
|
else
|
||||||
|
spdlog::debug("Enum {} already in the model", e.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_alias(const std::vector<std::string> &using_namespaces,
|
std::string to_alias(const std::vector<std::string> &using_namespaces,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,13 @@
|
|||||||
|
|
||||||
#include <clang-c/CXCompilationDatabase.h>
|
#include <clang-c/CXCompilationDatabase.h>
|
||||||
#include <clang-c/Index.h>
|
#include <clang-c/Index.h>
|
||||||
|
#include <cppast/cpp_friend.hpp>
|
||||||
|
#include <cppast/cpp_function_template.hpp>
|
||||||
|
#include <cppast/cpp_member_function.hpp>
|
||||||
|
#include <cppast/cpp_member_variable.hpp>
|
||||||
|
#include <cppast/cpp_template_parameter.hpp>
|
||||||
|
#include <cppast/cpp_type.hpp>
|
||||||
|
#include <cppast/visitor.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -33,14 +40,17 @@ namespace visitor {
|
|||||||
namespace class_diagram {
|
namespace class_diagram {
|
||||||
|
|
||||||
struct tu_context {
|
struct tu_context {
|
||||||
tu_context(clanguml::model::class_diagram::diagram &d_,
|
tu_context(cppast::cpp_entity_index &idx,
|
||||||
|
clanguml::model::class_diagram::diagram &d_,
|
||||||
const clanguml::config::class_diagram &config_)
|
const clanguml::config::class_diagram &config_)
|
||||||
: d{d_}
|
: entity_index{idx}
|
||||||
|
, d{d_}
|
||||||
, config{config_}
|
, config{config_}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> namespace_;
|
std::vector<std::string> namespace_;
|
||||||
|
cppast::cpp_entity_index &entity_index;
|
||||||
clanguml::model::class_diagram::diagram &d;
|
clanguml::model::class_diagram::diagram &d;
|
||||||
const clanguml::config::class_diagram &config;
|
const clanguml::config::class_diagram &config;
|
||||||
};
|
};
|
||||||
@@ -58,69 +68,81 @@ template <typename T> struct element_visitor_context {
|
|||||||
clanguml::model::class_diagram::diagram &d;
|
clanguml::model::class_diagram::diagram &d;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Visitors
|
class tu_visitor {
|
||||||
|
public:
|
||||||
|
tu_visitor(cppast::cpp_entity_index &idx_,
|
||||||
|
clanguml::model::class_diagram::diagram &d_,
|
||||||
|
const clanguml::config::class_diagram &config_)
|
||||||
|
: ctx{idx_, d_, config_}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
enum CXChildVisitResult visit_if_cursor_valid(
|
void operator()(const cppast::cpp_entity &file);
|
||||||
cx::cursor cursor, std::function<enum CXChildVisitResult(cx::cursor)> f);
|
|
||||||
|
|
||||||
enum CXChildVisitResult enum_visitor(
|
void process_class_declaration(const cppast::cpp_class &cls);
|
||||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data);
|
|
||||||
|
|
||||||
enum CXChildVisitResult method_parameter_visitor(
|
void process_enum_declaration(const cppast::cpp_enum &enm);
|
||||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data);
|
|
||||||
|
|
||||||
enum CXChildVisitResult friend_class_visitor(
|
void process_field(const cppast::cpp_member_variable &mv,
|
||||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data);
|
clanguml::model::class_diagram::class_ &c,
|
||||||
|
cppast::cpp_access_specifier_kind as);
|
||||||
|
|
||||||
enum CXChildVisitResult class_visitor(
|
void process_static_field(const cppast::cpp_variable &mv,
|
||||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data);
|
clanguml::model::class_diagram::class_ &c,
|
||||||
|
cppast::cpp_access_specifier_kind as);
|
||||||
|
|
||||||
enum CXChildVisitResult translation_unit_visitor(
|
void process_method(const cppast::cpp_member_function &mf,
|
||||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data);
|
clanguml::model::class_diagram::class_ &c,
|
||||||
|
cppast::cpp_access_specifier_kind as);
|
||||||
|
|
||||||
// Entity processors
|
void process_template_method(const cppast::cpp_function_template &mf,
|
||||||
|
clanguml::model::class_diagram::class_ &c,
|
||||||
|
cppast::cpp_access_specifier_kind as);
|
||||||
|
|
||||||
enum CXChildVisitResult process_class_base_specifier(cx::cursor cursor,
|
void process_static_method(const cppast::cpp_function &mf,
|
||||||
clanguml::model::class_diagram::class_ *parent, struct tu_context *ctx);
|
clanguml::model::class_diagram::class_ &c,
|
||||||
|
cppast::cpp_access_specifier_kind as);
|
||||||
|
|
||||||
enum CXChildVisitResult process_template_type_parameter(cx::cursor cursor,
|
void process_constructor(const cppast::cpp_constructor &mf,
|
||||||
clanguml::model::class_diagram::class_ *parent, struct tu_context *ctx);
|
clanguml::model::class_diagram::class_ &c,
|
||||||
|
cppast::cpp_access_specifier_kind as);
|
||||||
|
|
||||||
enum CXChildVisitResult process_template_nontype_parameter(cx::cursor cursor,
|
void process_destructor(const cppast::cpp_destructor &mf,
|
||||||
clanguml::model::class_diagram::class_ *parent, struct tu_context *ctx);
|
clanguml::model::class_diagram::class_ &c,
|
||||||
|
cppast::cpp_access_specifier_kind as);
|
||||||
|
|
||||||
enum CXChildVisitResult process_template_template_parameter(cx::cursor cursor,
|
void process_function_parameter(const cppast::cpp_function_parameter ¶m,
|
||||||
clanguml::model::class_diagram::class_ *parent, struct tu_context *ctx);
|
clanguml::model::class_diagram::class_method &m,
|
||||||
|
clanguml::model::class_diagram::class_ &c);
|
||||||
|
|
||||||
enum CXChildVisitResult process_method(cx::cursor cursor,
|
void find_relationships(const cppast::cpp_type &t,
|
||||||
clanguml::model::class_diagram::class_ *parent, struct tu_context *ctx);
|
std::vector<std::pair<std::string,
|
||||||
|
|
||||||
enum CXChildVisitResult process_class_declaration(cx::cursor cursor,
|
|
||||||
bool is_struct, clanguml::model::class_diagram::class_ *parent,
|
|
||||||
struct tu_context *ctx);
|
|
||||||
|
|
||||||
enum CXChildVisitResult process_enum_declaration(cx::cursor cursor,
|
|
||||||
clanguml::model::class_diagram::class_ *parent, struct tu_context *ctx);
|
|
||||||
|
|
||||||
bool process_template_specialization_class_field(cx::cursor cursor, cx::type t,
|
|
||||||
clanguml::model::class_diagram::class_ *parent, struct tu_context *ctx);
|
|
||||||
|
|
||||||
enum CXChildVisitResult process_field(cx::cursor cursor,
|
|
||||||
clanguml::model::class_diagram::class_ *parent, struct tu_context *ctx);
|
|
||||||
|
|
||||||
// Utils
|
|
||||||
|
|
||||||
clanguml::model::class_diagram::class_ build_template_instantiation(
|
|
||||||
cx::cursor cursor, cx::type t);
|
|
||||||
|
|
||||||
clanguml::model::class_diagram::scope_t cx_access_specifier_to_scope(
|
|
||||||
CX_CXXAccessSpecifier as);
|
|
||||||
|
|
||||||
void find_relationships(cx::type t,
|
|
||||||
std::vector<std::pair<cx::type,
|
|
||||||
clanguml::model::class_diagram::relationship_t>> &relationships,
|
clanguml::model::class_diagram::relationship_t>> &relationships,
|
||||||
clanguml::model::class_diagram::relationship_t relationship_hint =
|
clanguml::model::class_diagram::relationship_t relationship_hint =
|
||||||
clanguml::model::class_diagram::relationship_t::kNone);
|
clanguml::model::class_diagram::relationship_t::kNone);
|
||||||
|
|
||||||
|
void process_template_type_parameter(
|
||||||
|
const cppast::cpp_template_type_parameter &t,
|
||||||
|
clanguml::model::class_diagram::class_ &parent);
|
||||||
|
|
||||||
|
void process_template_nontype_parameter(
|
||||||
|
const cppast::cpp_non_type_template_parameter &t,
|
||||||
|
clanguml::model::class_diagram::class_ &parent);
|
||||||
|
|
||||||
|
void process_template_template_parameter(
|
||||||
|
const cppast::cpp_template_template_parameter &t,
|
||||||
|
clanguml::model::class_diagram::class_ &parent);
|
||||||
|
|
||||||
|
void process_friend(const cppast::cpp_friend &t,
|
||||||
|
clanguml::model::class_diagram::class_ &parent);
|
||||||
|
|
||||||
|
private:
|
||||||
|
clanguml::model::class_diagram::class_ build_template_instantiation(
|
||||||
|
const cppast::cpp_entity &e,
|
||||||
|
const cppast::cpp_template_instantiation_type &t);
|
||||||
|
|
||||||
|
tu_context ctx;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,8 +85,7 @@ static enum CXChildVisitResult translation_unit_visitor(
|
|||||||
unsigned int line{};
|
unsigned int line{};
|
||||||
unsigned int column{};
|
unsigned int column{};
|
||||||
unsigned int offset{};
|
unsigned int offset{};
|
||||||
clang_getFileLocation(
|
clang_getFileLocation(cursor.location(), &f, &line, &column, &offset);
|
||||||
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->d;
|
||||||
@@ -103,27 +102,25 @@ static enum CXChildVisitResult translation_unit_visitor(
|
|||||||
"::" + ctx->current_method.spelling() + "()";
|
"::" + ctx->current_method.spelling() + "()";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
caller = ctx->current_method.semantic_parent()
|
caller =
|
||||||
.fully_qualified();
|
ctx->current_method.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 =
|
auto callee = referenced.semantic_parent().fully_qualified();
|
||||||
referenced.semantic_parent().fully_qualified();
|
|
||||||
auto callee_usr = referenced.semantic_parent().usr();
|
auto callee_usr = referenced.semantic_parent().usr();
|
||||||
|
|
||||||
// Get called method
|
// Get called method
|
||||||
auto called_message = cursor.spelling();
|
auto called_message = cursor.spelling();
|
||||||
|
|
||||||
// Found method call: CXCursorKind () const
|
// Found method call: CXCursorKind () const
|
||||||
spdlog::debug(
|
spdlog::debug("Adding method call at line {}:{} to diagram {}"
|
||||||
"Adding method call at line {}:{} to diagram {}"
|
|
||||||
"\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(),
|
file, line, d.name, ctx->current_method.spelling(), caller,
|
||||||
caller, callee, called_message, caller_usr, callee_usr,
|
callee, called_message, caller_usr, callee_usr,
|
||||||
referenced.type().result_type().spelling());
|
referenced.type().result_type().spelling());
|
||||||
|
|
||||||
message m;
|
message m;
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ std::string ns_relative(
|
|||||||
std::string unqualify(const std::string &s)
|
std::string unqualify(const std::string &s)
|
||||||
{
|
{
|
||||||
auto toks = clanguml::util::split(s, " ");
|
auto toks = clanguml::util::split(s, " ");
|
||||||
const std::vector<std::string> qualifiers = {
|
const std::vector<std::string> qualifiers = {"static", "const", "volatile",
|
||||||
"static", "const", "volatile", "register", "mutable", "struct", "enum"};
|
"register", "constexpr", "mutable", "struct", "enum"};
|
||||||
|
|
||||||
toks.erase(toks.begin(),
|
toks.erase(toks.begin(),
|
||||||
std::find_if(toks.begin(), toks.end(), [&qualifiers](const auto &t) {
|
std::find_if(toks.begin(), toks.end(), [&qualifiers](const auto &t) {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ target_link_libraries(test_util
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
${LIBCLANG_LIBRARIES}
|
${LIBCLANG_LIBRARIES}
|
||||||
${YAML_CPP_LIBRARIES}
|
${YAML_CPP_LIBRARIES}
|
||||||
spdlog::spdlog clang-umllib)
|
spdlog::spdlog clang-umllib cppast)
|
||||||
|
|
||||||
|
|
||||||
add_executable(test_cases
|
add_executable(test_cases
|
||||||
@@ -42,7 +42,7 @@ target_link_libraries(test_cases
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
${LIBCLANG_LIBRARIES}
|
${LIBCLANG_LIBRARIES}
|
||||||
${YAML_CPP_LIBRARIES}
|
${YAML_CPP_LIBRARIES}
|
||||||
spdlog::spdlog clang-umllib)
|
spdlog::spdlog clang-umllib cppast)
|
||||||
|
|
||||||
foreach(TEST_CASE_CONFIG ${TEST_CASE_CONFIGS})
|
foreach(TEST_CASE_CONFIG ${TEST_CASE_CONFIGS})
|
||||||
file(RELATIVE_PATH
|
file(RELATIVE_PATH
|
||||||
|
|||||||
@@ -11449,11 +11449,10 @@ public:
|
|||||||
case Colour::BrightRed:
|
case Colour::BrightRed:
|
||||||
return setTextAttribute(FOREGROUND_INTENSITY | FOREGROUND_RED);
|
return setTextAttribute(FOREGROUND_INTENSITY | FOREGROUND_RED);
|
||||||
case Colour::BrightGreen:
|
case Colour::BrightGreen:
|
||||||
return setTextAttribute(
|
return setTextAttribute(FOREGROUND_INTENSITY | FOREGROUND_GREEN);
|
||||||
FOREGROUND_INTENSITY | FOREGROUND_GREEN);
|
|
||||||
case Colour::BrightWhite:
|
case Colour::BrightWhite:
|
||||||
return setTextAttribute(FOREGROUND_INTENSITY |
|
return setTextAttribute(FOREGROUND_INTENSITY | FOREGROUND_GREEN |
|
||||||
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE);
|
FOREGROUND_RED | FOREGROUND_BLUE);
|
||||||
case Colour::BrightYellow:
|
case Colour::BrightYellow:
|
||||||
return setTextAttribute(
|
return setTextAttribute(
|
||||||
FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
|
FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
|
||||||
@@ -12966,8 +12965,8 @@ bool WithinUlpsMatcher::match(double const &matchee) const
|
|||||||
{
|
{
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case FloatingPointKind::Float:
|
case FloatingPointKind::Float:
|
||||||
return almostEqualUlps<float>(static_cast<float>(matchee),
|
return almostEqualUlps<float>(
|
||||||
static_cast<float>(m_target), m_ulps);
|
static_cast<float>(matchee), static_cast<float>(m_target), m_ulps);
|
||||||
case FloatingPointKind::Double:
|
case FloatingPointKind::Double:
|
||||||
return almostEqualUlps<double>(matchee, m_target, m_ulps);
|
return almostEqualUlps<double>(matchee, m_target, m_ulps);
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ TEST_CASE("t00003", "[test-case][class]")
|
|||||||
REQUIRE_THAT(puml, IsField(Public("int public_member")));
|
REQUIRE_THAT(puml, IsField(Public("int public_member")));
|
||||||
REQUIRE_THAT(puml, IsField(Protected("int protected_member")));
|
REQUIRE_THAT(puml, IsField(Protected("int protected_member")));
|
||||||
REQUIRE_THAT(puml, IsField(Private("int private_member")));
|
REQUIRE_THAT(puml, IsField(Private("int private_member")));
|
||||||
REQUIRE_THAT(puml, IsField(Static(Public("unsigned long auto_member"))));
|
REQUIRE_THAT(
|
||||||
|
puml, IsField(Static(Public("unsigned long const auto_member"))));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, IsField(Private("int a")));
|
REQUIRE_THAT(puml, IsField(Private("int a")));
|
||||||
REQUIRE_THAT(puml, IsField(Private("int b")));
|
REQUIRE_THAT(puml, IsField(Private("int b")));
|
||||||
|
|||||||
@@ -17,9 +17,18 @@ public:
|
|||||||
CMP comparator;
|
CMP comparator;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, template <typename> typename C> class B {
|
template <typename T> struct Vector {
|
||||||
public:
|
std::vector<T> values;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, template <typename> typename C> struct B {
|
||||||
C<T> template_template;
|
C<T> template_template;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct D {
|
||||||
|
B<int, Vector> ints;
|
||||||
|
|
||||||
|
void add(int i) { ints.template_template.values.push_back(i); }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,18 +42,20 @@ TEST_CASE("t00008", "[test-case][class]")
|
|||||||
|
|
||||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
REQUIRE_THAT(puml, IsClassTemplate("A", "T, P, bool (*)(int, int), int N"));
|
// TODO: add option to resolve using declared types
|
||||||
|
// REQUIRE_THAT(puml, IsClassTemplate("A", "T, P, bool (*)(int, int), int
|
||||||
|
// N"));
|
||||||
|
REQUIRE_THAT(puml, IsClassTemplate("A", "T, P, CMP, int N"));
|
||||||
|
REQUIRE_THAT(puml, IsClassTemplate("B", "T, C<>"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, IsField(Public("T value")));
|
REQUIRE_THAT(puml, IsField(Public("T value")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("T* pointer")));
|
REQUIRE_THAT(puml, IsField(Public("T* pointer")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("T& reference")));
|
REQUIRE_THAT(puml, IsField(Public("T& reference")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("std::vector<P> values")));
|
REQUIRE_THAT(puml, IsField(Public("std::vector<P> values")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("std::array<int,N> ints")));
|
REQUIRE_THAT(puml, IsField(Public("std::array<int,N> ints")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("bool (*)(int, int) comparator")));
|
// TODO: add option to resolve using declared types
|
||||||
|
// REQUIRE_THAT(puml, IsField(Public("bool (*)(int, int) comparator")));
|
||||||
REQUIRE_THAT(puml, IsClassTemplate("B", "T, C<>"));
|
REQUIRE_THAT(puml, IsField(Public("CMP comparator")));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, IsField(Public("C<T> template_template")));
|
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ TEST_CASE("t00009", "[test-case][class]")
|
|||||||
REQUIRE_THAT(puml, IsField(Public("T value")));
|
REQUIRE_THAT(puml, IsField(Public("T value")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("A<int> aint")));
|
REQUIRE_THAT(puml, IsField(Public("A<int> aint")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("A<std::string>* astring")));
|
REQUIRE_THAT(puml, IsField(Public("A<std::string>* astring")));
|
||||||
REQUIRE_THAT(
|
REQUIRE_THAT(puml, IsField(Public("A<std::vector<std::string>>& avector")));
|
||||||
puml, IsField(Public("A<std::vector<std::string>> & avector")));
|
|
||||||
|
|
||||||
REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<int>")));
|
REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<int>")));
|
||||||
REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<std::string>")));
|
REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<std::string>")));
|
||||||
|
|||||||
@@ -17,8 +17,11 @@ private:
|
|||||||
void foo() {}
|
void foo() {}
|
||||||
friend class B;
|
friend class B;
|
||||||
friend class external::C;
|
friend class external::C;
|
||||||
|
// TODO
|
||||||
template <typename T> friend class D;
|
template <typename T> friend class D;
|
||||||
// TODO: Add friend for a template specialization
|
// TODO
|
||||||
|
friend class D<int>;
|
||||||
|
friend class D<A>;
|
||||||
};
|
};
|
||||||
|
|
||||||
class B {
|
class B {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ TEST_CASE("t00011", "[test-case][class]")
|
|||||||
REQUIRE_THAT(puml, IsClass(_A("D<T>")));
|
REQUIRE_THAT(puml, IsClass(_A("D<T>")));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, IsFriend(_A("A"), _A("B")));
|
REQUIRE_THAT(puml, IsFriend(_A("A"), _A("B")));
|
||||||
REQUIRE_THAT(puml, IsFriend(_A("A"), _A("D<T>")));
|
// REQUIRE_THAT(puml, IsFriend(_A("A"), _A("D<T>")));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace clanguml {
|
namespace clanguml {
|
||||||
namespace t00012 {
|
namespace t00012 {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
|
||||||
|
|
||||||
namespace ABCD {
|
namespace ABCD {
|
||||||
template <typename T> struct F {
|
template <typename T> struct F {
|
||||||
@@ -40,17 +39,18 @@ class R {
|
|||||||
public:
|
public:
|
||||||
int get_a(A *a) { return a->a; }
|
int get_a(A *a) { return a->a; }
|
||||||
int get_b(B &b) { return b.b; }
|
int get_b(B &b) { return b.b; }
|
||||||
// TODO: int get_const_b(const B &b) { return b.b; }
|
int get_const_b(const B &b) { return b.b; }
|
||||||
int get_c(C c) { return c.c; }
|
int get_c(C c) { return c.c; }
|
||||||
int get_d(D &&d) { return d.d; }
|
int get_d(D &&d) { return d.d; }
|
||||||
// Dependency relationship should be rendered only once
|
// Dependency relationship should be rendered only once
|
||||||
int get_d2(D &&d) { return d.d; }
|
int get_d2(D &&d) { return d.d; }
|
||||||
|
|
||||||
template <typename T> T get_e(E<T> &e) { return e.e; }
|
template <typename T> T get_e(E<T> e) { return e.e; }
|
||||||
int get_int_e(const E<int> &e) { return e.e; }
|
int get_int_e(const E<int> &e) { return e.e; }
|
||||||
int get_int_e2(E<int> &e) { return e.e; }
|
int get_int_e2(E<int> &e) { return e.e; }
|
||||||
|
|
||||||
template <typename T> T get_f(const F<T> &f) { return f.f; }
|
template <typename T> T get_f(const F<T> &f) { return f.f; }
|
||||||
|
int get_int_f(const F<int> &f) { return f.f; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable E<std::string> estring;
|
mutable E<std::string> estring;
|
||||||
|
|||||||
@@ -51,13 +51,15 @@ TEST_CASE("t00013", "[test-case][class]")
|
|||||||
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("B")));
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("B")));
|
||||||
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("C")));
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("C")));
|
||||||
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("D")));
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("D")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("D"), _A("R")));
|
||||||
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E<T>")));
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E<T>")));
|
||||||
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E<int>")));
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E<int>")));
|
||||||
REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<int>")));
|
REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<int>")));
|
||||||
REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<std::string>")));
|
REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<std::string>")));
|
||||||
REQUIRE_THAT(puml, IsComposition(_A("R"), _A("E<std::string>"), "estring"));
|
REQUIRE_THAT(puml, IsComposition(_A("R"), _A("E<std::string>"), "estring"));
|
||||||
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<T>")));
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<T>")));
|
||||||
REQUIRE_THAT(puml, IsDependency(_A("D"), _A("R")));
|
REQUIRE_THAT(puml, IsInstantiation(_A("ABCD::F<T>"), _A("ABCD::F<int>")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<int>")));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||||
|
|||||||
12
tests/t00014/.clanguml
Normal file
12
tests/t00014/.clanguml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
compilation_database_dir: ..
|
||||||
|
output_directory: puml
|
||||||
|
diagrams:
|
||||||
|
t00014_class:
|
||||||
|
type: class
|
||||||
|
glob:
|
||||||
|
- ../../tests/t00014/t00014.cc
|
||||||
|
using_namespace:
|
||||||
|
- clanguml::t00014
|
||||||
|
include:
|
||||||
|
namespaces:
|
||||||
|
- clanguml::t00014
|
||||||
29
tests/t00014/t00014.cc
Normal file
29
tests/t00014/t00014.cc
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <ios>
|
||||||
|
#include <map>
|
||||||
|
#include <numeric>
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
namespace clanguml {
|
||||||
|
namespace t00014 {
|
||||||
|
|
||||||
|
template <typename T, typename P> struct A {
|
||||||
|
T t;
|
||||||
|
P p;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T> using AString = A<T, std::string>;
|
||||||
|
|
||||||
|
using AIntString = AString<int>;
|
||||||
|
using AStringString = AString<std::string>;
|
||||||
|
|
||||||
|
class R {
|
||||||
|
A<bool, std::string> boolstring;
|
||||||
|
AString<float> floatstring;
|
||||||
|
AIntString intstring;
|
||||||
|
AStringString stringstring;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
66
tests/t00014/test_case.h
Normal file
66
tests/t00014/test_case.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* tests/t00014/test_case.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
TEST_CASE("t00014", "[test-case][class]")
|
||||||
|
{
|
||||||
|
auto [config, db] = load_config("t00014");
|
||||||
|
|
||||||
|
auto diagram = config.diagrams["t00014_class"];
|
||||||
|
|
||||||
|
REQUIRE(diagram->name == "t00014_class");
|
||||||
|
|
||||||
|
REQUIRE_THAT(diagram->include.namespaces,
|
||||||
|
VectorContains(std::string{"clanguml::t00014"}));
|
||||||
|
|
||||||
|
REQUIRE(diagram->exclude.namespaces.size() == 0);
|
||||||
|
|
||||||
|
REQUIRE(diagram->should_include("clanguml::t00014::S"));
|
||||||
|
|
||||||
|
auto model = generate_class_diagram(db, diagram);
|
||||||
|
|
||||||
|
REQUIRE(model.name == "t00014_class");
|
||||||
|
|
||||||
|
auto puml = generate_class_puml(diagram, model);
|
||||||
|
AliasMatcher _A(puml);
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
|
REQUIRE_THAT(puml, IsClassTemplate("A", "T, P"));
|
||||||
|
/*
|
||||||
|
REQUIRE_THAT(puml, IsClass(_A("B")));
|
||||||
|
REQUIRE_THAT(puml, IsClass(_A("C")));
|
||||||
|
REQUIRE_THAT(puml, IsClass(_A("D")));
|
||||||
|
REQUIRE_THAT(puml, !IsDependency(_A("R"), _A("R")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("A")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("B")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("C")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("D")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("D"), _A("R")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E<T>")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E<int>")));
|
||||||
|
REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<int>")));
|
||||||
|
REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<std::string>")));
|
||||||
|
REQUIRE_THAT(puml, IsComposition(_A("R"), _A("E<std::string>"), "estring"));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<T>")));
|
||||||
|
REQUIRE_THAT(puml, IsInstantiation(_A("ABCD::F<T>"), _A("ABCD::F<int>")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<int>")));
|
||||||
|
*/
|
||||||
|
|
||||||
|
save_puml(
|
||||||
|
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
TEST_CASE("t20001", "[test-case][sequence]")
|
TEST_CASE("t20001", "[test-case][sequence]")
|
||||||
{
|
{
|
||||||
auto [config, db] = load_config("t20001");
|
auto [config, db] = load_config2("t20001");
|
||||||
|
|
||||||
auto diagram = config.diagrams["t20001_sequence"];
|
auto diagram = config.diagrams["t20001_sequence"];
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,17 @@
|
|||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
std::pair<clanguml::config::config, compilation_database> load_config(
|
std::pair<clanguml::config::config, cppast::libclang_compilation_database>
|
||||||
|
load_config(const std::string &test_name)
|
||||||
|
{
|
||||||
|
auto config = clanguml::config::load(test_name + "/.clanguml");
|
||||||
|
|
||||||
|
cppast::libclang_compilation_database db(config.compilation_database_dir);
|
||||||
|
|
||||||
|
return std::make_pair(std::move(config), std::move(db));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<clanguml::config::config, compilation_database> load_config2(
|
||||||
const std::string &test_name)
|
const std::string &test_name)
|
||||||
{
|
{
|
||||||
auto config = clanguml::config::load(test_name + "/.clanguml");
|
auto config = clanguml::config::load(test_name + "/.clanguml");
|
||||||
@@ -42,7 +52,7 @@ clanguml::model::sequence_diagram::diagram generate_sequence_diagram(
|
|||||||
}
|
}
|
||||||
|
|
||||||
clanguml::model::class_diagram::diagram generate_class_diagram(
|
clanguml::model::class_diagram::diagram generate_class_diagram(
|
||||||
compilation_database &db,
|
cppast::libclang_compilation_database &db,
|
||||||
std::shared_ptr<clanguml::config::diagram> diagram)
|
std::shared_ptr<clanguml::config::diagram> diagram)
|
||||||
{
|
{
|
||||||
auto diagram_model =
|
auto diagram_model =
|
||||||
@@ -129,6 +139,7 @@ using clanguml::test::matchers::Static;
|
|||||||
#include "t00011/test_case.h"
|
#include "t00011/test_case.h"
|
||||||
#include "t00012/test_case.h"
|
#include "t00012/test_case.h"
|
||||||
#include "t00013/test_case.h"
|
#include "t00013/test_case.h"
|
||||||
|
#include "t00014/test_case.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// Sequence diagram tests
|
// Sequence diagram tests
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ using Catch::Matchers::VectorContains;
|
|||||||
using clanguml::cx::compilation_database;
|
using clanguml::cx::compilation_database;
|
||||||
using namespace clanguml::util;
|
using namespace clanguml::util;
|
||||||
|
|
||||||
std::pair<clanguml::config::config, compilation_database> load_config(
|
std::pair<clanguml::config::config, cppast::libclang_compilation_database>
|
||||||
|
load_config(const std::string &test_name);
|
||||||
|
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::model::sequence_diagram::diagram generate_sequence_diagram(
|
||||||
@@ -263,7 +265,7 @@ ContainsMatcher IsInnerClass(std::string const &parent,
|
|||||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||||
{
|
{
|
||||||
return ContainsMatcher(
|
return ContainsMatcher(
|
||||||
CasedString(parent + " +-- " + inner, caseSensitivity));
|
CasedString(inner + " --+ " + parent, caseSensitivity));
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainsMatcher IsAssociation(std::string const &from, std::string const &to,
|
ContainsMatcher IsAssociation(std::string const &from, std::string const &to,
|
||||||
|
|||||||
1
thirdparty/cppast
vendored
Submodule
1
thirdparty/cppast
vendored
Submodule
Submodule thirdparty/cppast added at dd8d9e668a
Reference in New Issue
Block a user