Ported template instantiation handling to cppast
This commit is contained in:
@@ -50,8 +50,6 @@ std::string to_string(relationship_t r)
|
|||||||
return "invalid";
|
return "invalid";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ void tu_visitor::operator()(const cppast::cpp_entity &file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e.kind() == cppast::cpp_entity_kind::class_t) {
|
if (e.kind() == cppast::cpp_entity_kind::class_t) {
|
||||||
spdlog::debug("'{}' - {}", cx::util::full_name(e),
|
spdlog::debug("========== Visiting '{}' - {}",
|
||||||
cppast::to_string(e.kind()));
|
cx::util::full_name(e), cppast::to_string(e.kind()));
|
||||||
|
|
||||||
auto &cls = static_cast<const cppast::cpp_class &>(e);
|
auto &cls = static_cast<const cppast::cpp_class &>(e);
|
||||||
|
|
||||||
@@ -86,8 +86,8 @@ void tu_visitor::operator()(const cppast::cpp_entity &file)
|
|||||||
process_class_declaration(cls);
|
process_class_declaration(cls);
|
||||||
}
|
}
|
||||||
else if (e.kind() == cppast::cpp_entity_kind::enum_t) {
|
else if (e.kind() == cppast::cpp_entity_kind::enum_t) {
|
||||||
spdlog::debug("'{}' - {}", cx::util::full_name(e),
|
spdlog::debug("========== Visiting '{}' - {}",
|
||||||
cppast::to_string(e.kind()));
|
cx::util::full_name(e), cppast::to_string(e.kind()));
|
||||||
|
|
||||||
auto &enm = static_cast<const cppast::cpp_enum &>(e);
|
auto &enm = static_cast<const cppast::cpp_enum &>(e);
|
||||||
|
|
||||||
@@ -146,6 +146,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls)
|
|||||||
}
|
}
|
||||||
else if (child.kind() == cppast::cpp_entity_kind::member_variable_t) {
|
else if (child.kind() == cppast::cpp_entity_kind::member_variable_t) {
|
||||||
auto &mv = static_cast<const cppast::cpp_member_variable &>(child);
|
auto &mv = static_cast<const cppast::cpp_member_variable &>(child);
|
||||||
|
spdlog::debug("Found member variable {}", mv.name());
|
||||||
process_field(mv, c, last_access_specifier);
|
process_field(mv, c, last_access_specifier);
|
||||||
}
|
}
|
||||||
else if (child.kind() == cppast::cpp_entity_kind::variable_t) {
|
else if (child.kind() == cppast::cpp_entity_kind::variable_t) {
|
||||||
@@ -171,8 +172,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls)
|
|||||||
else if (child.kind() == cppast::cpp_entity_kind::friend_t) {
|
else if (child.kind() == cppast::cpp_entity_kind::friend_t) {
|
||||||
auto &fr = static_cast<const cppast::cpp_friend &>(child);
|
auto &fr = static_cast<const cppast::cpp_friend &>(child);
|
||||||
|
|
||||||
spdlog::debug("Found friend declaration: {}, {}",
|
spdlog::debug("Found friend declaration: {}, {}", child.name(),
|
||||||
child.name(),
|
|
||||||
child.scope_name() ? child.scope_name().value().name()
|
child.scope_name() ? child.scope_name().value().name()
|
||||||
: "<no-scope>");
|
: "<no-scope>");
|
||||||
|
|
||||||
@@ -187,8 +187,8 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls)
|
|||||||
process_friend(fr, c);
|
process_friend(fr, c);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
spdlog::debug("Found some other class child: {} ({})",
|
spdlog::debug("Found some other class child: {} ({})", child.name(),
|
||||||
child.name(), cppast::to_string(child.kind()));
|
cppast::to_string(child.kind()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,10 +217,13 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls)
|
|||||||
|
|
||||||
// Process class template arguments
|
// Process class template arguments
|
||||||
if (cppast::is_templated(cls)) {
|
if (cppast::is_templated(cls)) {
|
||||||
|
spdlog::debug("Processing class template parameters...");
|
||||||
auto scope = cppast::cpp_scope_name(type_safe::ref(cls));
|
auto scope = cppast::cpp_scope_name(type_safe::ref(cls));
|
||||||
for (const auto &tp : scope.template_parameters()) {
|
for (const auto &tp : scope.template_parameters()) {
|
||||||
if (tp.kind() ==
|
if (tp.kind() ==
|
||||||
cppast::cpp_entity_kind::template_type_parameter_t) {
|
cppast::cpp_entity_kind::template_type_parameter_t) {
|
||||||
|
spdlog::debug(
|
||||||
|
"Processing template type parameter {}", tp.name());
|
||||||
process_template_type_parameter(
|
process_template_type_parameter(
|
||||||
static_cast<const cppast::cpp_template_type_parameter &>(
|
static_cast<const cppast::cpp_template_type_parameter &>(
|
||||||
tp),
|
tp),
|
||||||
@@ -228,6 +231,8 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls)
|
|||||||
}
|
}
|
||||||
else if (tp.kind() ==
|
else if (tp.kind() ==
|
||||||
cppast::cpp_entity_kind::non_type_template_parameter_t) {
|
cppast::cpp_entity_kind::non_type_template_parameter_t) {
|
||||||
|
spdlog::debug(
|
||||||
|
"Processing template nontype parameter {}", tp.name());
|
||||||
process_template_nontype_parameter(
|
process_template_nontype_parameter(
|
||||||
static_cast<
|
static_cast<
|
||||||
const cppast::cpp_non_type_template_parameter &>(tp),
|
const cppast::cpp_non_type_template_parameter &>(tp),
|
||||||
@@ -235,6 +240,8 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls)
|
|||||||
}
|
}
|
||||||
else if (tp.kind() ==
|
else if (tp.kind() ==
|
||||||
cppast::cpp_entity_kind::template_template_parameter_t) {
|
cppast::cpp_entity_kind::template_template_parameter_t) {
|
||||||
|
spdlog::debug(
|
||||||
|
"Processing template template parameter {}", tp.name());
|
||||||
process_template_template_parameter(
|
process_template_template_parameter(
|
||||||
static_cast<
|
static_cast<
|
||||||
const cppast::cpp_template_template_parameter &>(tp),
|
const cppast::cpp_template_template_parameter &>(tp),
|
||||||
@@ -281,7 +288,14 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c,
|
|||||||
m.is_static = false;
|
m.is_static = false;
|
||||||
|
|
||||||
const auto &tr = cx::util::unreferenced(mv.type());
|
const auto &tr = cx::util::unreferenced(mv.type());
|
||||||
|
|
||||||
|
spdlog::debug(
|
||||||
|
"Processing field with unreferenced type of kind {}", tr.kind());
|
||||||
|
|
||||||
if (tr.kind() == cppast::cpp_type_kind::template_instantiation_t) {
|
if (tr.kind() == cppast::cpp_type_kind::template_instantiation_t) {
|
||||||
|
spdlog::debug("Processing field with template instatiation type {}",
|
||||||
|
cppast::to_string(tr));
|
||||||
|
|
||||||
const auto &template_instantiation_type =
|
const auto &template_instantiation_type =
|
||||||
static_cast<const cppast::cpp_template_instantiation_type &>(tr);
|
static_cast<const cppast::cpp_template_instantiation_type &>(tr);
|
||||||
if (template_instantiation_type.primary_template()
|
if (template_instantiation_type.primary_template()
|
||||||
@@ -325,6 +339,11 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (tr.kind() == cppast::cpp_type_kind::unexposed_t) {
|
||||||
|
spdlog::debug(
|
||||||
|
"Processing field with unexposed type {}", cppast::to_string(tr));
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
if (mv.type().kind() != cppast::cpp_type_kind::builtin_t) {
|
if (mv.type().kind() != cppast::cpp_type_kind::builtin_t) {
|
||||||
std::vector<std::pair<std::string, relationship_t>> relationships;
|
std::vector<std::pair<std::string, relationship_t>> relationships;
|
||||||
@@ -614,6 +633,7 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (const auto &arg : args) {
|
for (const auto &arg : args) {
|
||||||
|
if (arg.type())
|
||||||
find_relationships(
|
find_relationships(
|
||||||
arg.type().value(), relationships, relationship_type);
|
arg.type().value(), relationships, relationship_type);
|
||||||
}
|
}
|
||||||
@@ -675,6 +695,11 @@ class_ tu_visitor::build_template_instantiation(const cppast::cpp_entity &e,
|
|||||||
ct.type =
|
ct.type =
|
||||||
static_cast<const cppast::cpp_literal_expression &>(exp)
|
static_cast<const cppast::cpp_literal_expression &>(exp)
|
||||||
.value();
|
.value();
|
||||||
|
else if (exp.kind() == cppast::cpp_expression_kind::unexposed_t)
|
||||||
|
ct.type =
|
||||||
|
static_cast<const cppast::cpp_unexposed_expression &>(exp)
|
||||||
|
.expression()
|
||||||
|
.as_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
spdlog::debug("Adding template argument '{}'", ct.type);
|
spdlog::debug("Adding template argument '{}'", ct.type);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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 const 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")));
|
||||||
|
|||||||
@@ -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>")));
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user