Added basic method parameter handling
This commit is contained in:
@@ -130,7 +130,17 @@ public:
|
||||
if (m.type != "void")
|
||||
type = m.type + " ";
|
||||
|
||||
ostr << to_string(m.scope) << type << m.name + "()";
|
||||
ostr << to_string(m.scope) << type << m.name;
|
||||
|
||||
ostr << "(";
|
||||
if (true) { // TODO: add option to disable parameter generation
|
||||
std::vector<std::string> params;
|
||||
std::transform(m.parameters.begin(), m.parameters.end(),
|
||||
std::back_inserter(params),
|
||||
[](const auto &mp) { return mp.to_string(); });
|
||||
ostr << fmt::format("{}", fmt::join(params, ", "));
|
||||
}
|
||||
ostr << ")";
|
||||
|
||||
if (m.is_const)
|
||||
ostr << " const";
|
||||
|
||||
@@ -77,13 +77,22 @@ struct class_member : public class_element {
|
||||
bool is_static{false};
|
||||
};
|
||||
|
||||
struct method_argument {
|
||||
struct method_parameter {
|
||||
std::string type;
|
||||
std::string name;
|
||||
std::string default_value;
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
if (default_value.empty())
|
||||
return fmt::format("{} {}", type, name);
|
||||
|
||||
return fmt::format("{} {} = {}", type, name, default_value);
|
||||
}
|
||||
};
|
||||
|
||||
struct class_method : public class_element {
|
||||
std::vector<method_argument> arguments;
|
||||
std::vector<method_parameter> parameters;
|
||||
bool is_pure_virtual{false};
|
||||
bool is_virtual{false};
|
||||
bool is_const{false};
|
||||
|
||||
@@ -40,6 +40,7 @@ using clanguml::model::class_diagram::class_relationship;
|
||||
using clanguml::model::class_diagram::class_template;
|
||||
using clanguml::model::class_diagram::diagram;
|
||||
using clanguml::model::class_diagram::enum_;
|
||||
using clanguml::model::class_diagram::method_parameter;
|
||||
using clanguml::model::class_diagram::relationship_t;
|
||||
using clanguml::model::class_diagram::scope_t;
|
||||
|
||||
@@ -201,6 +202,54 @@ static enum CXChildVisitResult enum_visitor(
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum CXChildVisitResult method_parameter_visitor(
|
||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data)
|
||||
{
|
||||
auto ctx = (element_visitor_context<class_method> *)client_data;
|
||||
|
||||
cx::cursor cursor{std::move(cx_cursor)};
|
||||
cx::cursor parent{std::move(cx_parent)};
|
||||
|
||||
spdlog::debug("Visiting method declaration {}: {} - {}:{}",
|
||||
ctx->element.name, cursor.spelling(), cursor.kind(),
|
||||
cursor.referenced());
|
||||
|
||||
enum CXChildVisitResult ret = CXChildVisit_Break;
|
||||
switch (cursor.kind()) {
|
||||
case CXCursor_ParmDecl: {
|
||||
spdlog::debug(
|
||||
"Analyzing method parameter: {}, {}", cursor, cursor.type());
|
||||
|
||||
method_parameter mp;
|
||||
mp.name = cursor.spelling();
|
||||
mp.type = cursor.type().spelling();
|
||||
|
||||
ctx->element.parameters.emplace_back(std::move(mp));
|
||||
|
||||
/* TODO: handle dependency relationships based
|
||||
* on method arguments
|
||||
*
|
||||
if (ctx->ctx->config.should_include(
|
||||
cursor.type().referenced().fully_qualified())) {
|
||||
|
||||
class_relationship r;
|
||||
r.type = relationship_t::kDependency;
|
||||
r.destination = cursor.type().referenced().usr();
|
||||
|
||||
ctx->element.relationships.emplace_back(std::move(r));
|
||||
}
|
||||
*/
|
||||
|
||||
ret = CXChildVisit_Continue;
|
||||
} break;
|
||||
default:
|
||||
ret = CXChildVisit_Continue;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum CXChildVisitResult friend_class_visitor(
|
||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data)
|
||||
{
|
||||
@@ -395,6 +444,13 @@ static enum CXChildVisitResult class_visitor(
|
||||
m.scope =
|
||||
cx_access_specifier_to_scope(cursor.cxxaccess_specifier());
|
||||
|
||||
auto method_ctx =
|
||||
element_visitor_context<class_method>(ctx->d, m);
|
||||
method_ctx.ctx = ctx->ctx;
|
||||
|
||||
clang_visitChildren(
|
||||
cursor.get(), method_parameter_visitor, &method_ctx);
|
||||
|
||||
spdlog::debug("Adding method {} {}::{}()", m.type,
|
||||
ctx->element.name, cursor.spelling());
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ public:
|
||||
void const_method() const {}
|
||||
auto auto_method() { return 1; }
|
||||
|
||||
auto double_int(const int i) { return 2 * i; }
|
||||
auto sum(const double a, const double b) { return a + b; }
|
||||
|
||||
int public_member;
|
||||
static int static_int;
|
||||
static const int static_const_int = 1;
|
||||
|
||||
Reference in New Issue
Block a user