Added handling of static class fields

This commit is contained in:
Bartek Kryza
2021-02-25 20:43:13 +01:00
parent e3ffeba732
commit dfa39a0433
6 changed files with 24 additions and 9 deletions

View File

@@ -137,6 +137,11 @@ public:
return clang_CXXMethod_isVirtual(m_cursor);
}
bool is_static() const
{
return clang_Cursor_getStorageClass(m_cursor) == CX_SC_Static;
}
bool is_method_static() const { return clang_CXXMethod_isStatic(m_cursor); }
bool is_method_const() const { return clang_CXXMethod_isConst(m_cursor); }

View File

@@ -135,6 +135,9 @@ public:
// Process members
//
for (const auto &m : c.members) {
if (m.is_static)
ostr << "{static} ";
ostr << to_string(m.scope) << m.type << " " << m.name << std::endl;
}

View File

@@ -54,6 +54,7 @@ struct class_element {
struct class_member : public class_element {
bool is_relationship{false};
bool is_static{false};
};
struct method_argument {

View File

@@ -182,6 +182,7 @@ static enum CXChildVisitResult class_visitor(
ret = CXChildVisit_Continue;
break;
}
case CXCursor_VarDecl:
case CXCursor_FieldDecl: {
visit_if_cursor_valid(cursor, [c](cx::cursor cursor) {
auto t = cursor.type();
@@ -190,6 +191,7 @@ static enum CXChildVisitResult class_visitor(
m.type = cursor.type().spelling();
m.scope =
cx_access_specifier_to_scope(cursor.cxxaccess_specifier());
m.is_static = cursor.is_static();
spdlog::info("Adding member {} {}::{}", m.type, c->name,
cursor.spelling());
@@ -215,11 +217,7 @@ static enum CXChildVisitResult class_visitor(
t = t.pointee_type();
continue;
}
/*else if(t.kind == CXType_Elaborated) {
t = clang_Type_getNamedType(t);
continue;
}*/
else /*if (t.kind == CXType_Record) */ {
else {
spdlog::error("UNKNOWN CXTYPE: {}", t.kind());
class_relationship r;
auto template_argument_count =
@@ -259,9 +257,6 @@ static enum CXChildVisitResult class_visitor(
spdlog::debug(
"Adding relationship to: {}", r.destination);
}
// else {
// spdlog::error("UNKNOWN CXTYPE: {}", t.kind);
//}
break;
}
}

View File

@@ -1,3 +1,5 @@
#include <functional>
namespace clanguml {
namespace t00003 {
@@ -11,20 +13,28 @@ public:
void basic_method() {}
static int static_method() { return 0; }
void const_method() const {}
auto auto_method() { return 1; }
int public_member;
static int static_int;
static const int static_const_int = 1;
protected:
void protected_method() {}
int protected_member;
std::function<bool(const int)> compare = [this](const int v) {
return private_member > v;
};
private:
void private_method() {}
int private_member;
int a, b, c;
};
int A::static_int = 1;
}
}

View File

@@ -204,6 +204,7 @@ TEST_CASE("Test t00003", "[unit-test]")
REQUIRE_THAT(puml, Contains("-int a"));
REQUIRE_THAT(puml, Contains("-int b"));
REQUIRE_THAT(puml, Contains("-int c"));
REQUIRE_THAT(puml, Contains("{static} +int static_int"));
save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);