Added basic class access and type specifiers generation
This commit is contained in:
@@ -137,6 +137,8 @@ public:
|
||||
return clang_CXXMethod_isVirtual(m_cursor);
|
||||
}
|
||||
|
||||
bool is_method_static() const { return clang_CXXMethod_isStatic(m_cursor); }
|
||||
|
||||
bool is_method_const() const { return clang_CXXMethod_isConst(m_cursor); }
|
||||
|
||||
bool is_method_pure_virtual() const
|
||||
|
||||
@@ -101,18 +101,39 @@ public:
|
||||
|
||||
ostr << c.name << " {" << std::endl;
|
||||
|
||||
//
|
||||
// Process methods
|
||||
//
|
||||
for (const auto &m : c.methods) {
|
||||
if (m.is_pure_virtual)
|
||||
ostr << "{abstract} ";
|
||||
|
||||
ostr << to_string(m.scope) << m.type << " " << m.name + "()";
|
||||
if (m.is_static)
|
||||
ostr << "{static} ";
|
||||
|
||||
std::string type{};
|
||||
if (m.type != "void")
|
||||
type = m.type;
|
||||
|
||||
ostr << to_string(m.scope) << type << " " << m.name + "()";
|
||||
|
||||
if (m.is_const)
|
||||
ostr << " const";
|
||||
|
||||
assert(!(m.is_pure_virtual && m.is_defaulted));
|
||||
|
||||
if (m.is_pure_virtual)
|
||||
ostr << " = 0";
|
||||
|
||||
if (m.is_defaulted)
|
||||
ostr << " = default";
|
||||
|
||||
ostr << std::endl;
|
||||
}
|
||||
|
||||
//
|
||||
// Process members
|
||||
//
|
||||
for (const auto &m : c.members) {
|
||||
ostr << to_string(m.scope) << m.type << " " << m.name << std::endl;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ struct class_method : public class_element {
|
||||
bool is_virtual{false};
|
||||
bool is_const{false};
|
||||
bool is_defaulted{false};
|
||||
bool is_static{false};
|
||||
};
|
||||
|
||||
struct class_parent {
|
||||
|
||||
@@ -75,7 +75,7 @@ enum CXChildVisitResult visit_if_cursor_valid(
|
||||
cx::cursor cursor, std::function<void(cx::cursor)> f)
|
||||
{
|
||||
enum CXChildVisitResult ret = CXChildVisit_Break;
|
||||
if (cursor.is_definition()) {
|
||||
if (cursor.is_definition() || cursor.is_declaration()) {
|
||||
if (!cursor.spelling().empty()) {
|
||||
f(cursor);
|
||||
ret = CXChildVisit_Continue;
|
||||
@@ -84,21 +84,32 @@ enum CXChildVisitResult visit_if_cursor_valid(
|
||||
ret = CXChildVisit_Recurse;
|
||||
}
|
||||
}
|
||||
else if (cursor.is_declaration()) {
|
||||
if (cursor.is_method_pure_virtual()) {
|
||||
f(cursor);
|
||||
ret = CXChildVisit_Continue;
|
||||
}
|
||||
else {
|
||||
ret = CXChildVisit_Recurse;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ret = CXChildVisit_Continue;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
scope_t cx_access_specifier_to_scope(CX_CXXAccessSpecifier as)
|
||||
{
|
||||
scope_t res = scope_t::kPublic;
|
||||
switch (as) {
|
||||
case CX_CXXAccessSpecifier::CX_CXXPublic:
|
||||
res = scope_t::kPublic;
|
||||
break;
|
||||
case CX_CXXAccessSpecifier::CX_CXXPrivate:
|
||||
res = scope_t::kPrivate;
|
||||
break;
|
||||
case CX_CXXAccessSpecifier::CX_CXXProtected:
|
||||
res = scope_t::kProtected;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static enum CXChildVisitResult enum_visitor(
|
||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data)
|
||||
{
|
||||
@@ -144,6 +155,8 @@ static enum CXChildVisitResult class_visitor(
|
||||
c->name, cursor_name_str, cursor.kind());
|
||||
|
||||
enum CXChildVisitResult ret = CXChildVisit_Break;
|
||||
bool is_constructor{false};
|
||||
bool is_destructor{false};
|
||||
switch (cursor.kind()) {
|
||||
case CXCursor_CXXMethod:
|
||||
case CXCursor_Constructor:
|
||||
@@ -157,6 +170,9 @@ static enum CXChildVisitResult class_visitor(
|
||||
m.is_virtual = cursor.is_method_virtual();
|
||||
m.is_const = cursor.is_method_const();
|
||||
m.is_defaulted = cursor.is_method_defaulted();
|
||||
m.is_static = cursor.is_method_static();
|
||||
m.scope =
|
||||
cx_access_specifier_to_scope(cursor.cxxaccess_specifier());
|
||||
|
||||
spdlog::info("Adding method {} {}::{}()", m.type, c->name,
|
||||
cursor.spelling());
|
||||
@@ -172,6 +188,8 @@ static enum CXChildVisitResult class_visitor(
|
||||
class_member m;
|
||||
m.name = cursor.spelling();
|
||||
m.type = cursor.type().spelling();
|
||||
m.scope =
|
||||
cx_access_specifier_to_scope(cursor.cxxaccess_specifier());
|
||||
|
||||
spdlog::info("Adding member {} {}::{}", m.type, c->name,
|
||||
cursor.spelling());
|
||||
|
||||
Reference in New Issue
Block a user