Added basic class relationship handling

This commit is contained in:
Bartek Kryza
2021-02-28 19:13:15 +01:00
parent e885149cf0
commit e4d77db5c0
11 changed files with 324 additions and 69 deletions

View File

@@ -21,6 +21,8 @@
#include <clang-c/Index.h>
#include <spdlog/spdlog.h>
#include "util/util.h"
namespace clanguml {
namespace cx {
@@ -93,6 +95,11 @@ public:
CXTypeKind kind() const { return m_type.kind; }
std::string kind_spelling()
{
return to_string(clang_getTypeKindSpelling(m_type.kind));
}
CXCallingConv calling_convention() const
{
return clang_getFunctionTypeCallingConv(m_type);
@@ -116,6 +123,39 @@ public:
bool is_pod() const { return clang_isPODType(m_type); }
bool is_pointer() const { return kind() == CXType_Pointer; }
bool is_record() const { return kind() == CXType_Record; }
/**
* @brief Return final referenced type.
*
* This method allows to extract a final type in case a type consists of a
* single or multiple pointers or references.
*
* @return Referenced type.
*/
type referenced() const
{
auto t = *this;
while (t.is_pointer() || t.is_reference()) {
t = t.pointee_type();
}
return t;
}
bool is_reference() const
{
return (kind() == CXType_LValueReference) ||
(kind() == CXType_RValueReference);
}
bool is_relationship() const
{
return is_pointer() || is_record() || is_reference() || !is_pod();
}
type element_type() const { return clang_getElementType(m_type); }
long long element_count() const { return clang_getNumElements(m_type); }
@@ -157,6 +197,20 @@ public:
return clang_Type_getCXXRefQualifier(m_type);
}
std::string unqualified() const
{
auto toks = clanguml::util::split(spelling(), " ");
const std::vector<std::string> qualifiers = {
"static", "const", "volatile", "register", "mutable"};
while (toks.size() > 0 &&
std::count(qualifiers.begin(), qualifiers.end(), toks.front())) {
toks.erase(toks.begin());
}
return fmt::format("{}", fmt::join(toks, " "));
}
private:
CXType m_type;
};