From b70d7266627a4b9379c25d8bbbc8f5ef4b7ce81f Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Mon, 15 Feb 2021 23:59:20 +0100 Subject: [PATCH] Restructured cx namespace --- src/{uml => cx}/compilation_database.cc | 0 src/{uml => cx}/compilation_database.h | 0 src/cx/cursor.h | 128 ++++++++++++++++++++++++ src/{uml/cx.h => cx/type.h} | 120 ---------------------- src/main.cc | 2 +- src/uml/class_diagram_visitor.h | 1 + src/uml/sequence_diagram_visitor.h | 2 +- 7 files changed, 131 insertions(+), 122 deletions(-) rename src/{uml => cx}/compilation_database.cc (100%) rename src/{uml => cx}/compilation_database.h (100%) create mode 100644 src/cx/cursor.h rename src/{uml/cx.h => cx/type.h} (53%) diff --git a/src/uml/compilation_database.cc b/src/cx/compilation_database.cc similarity index 100% rename from src/uml/compilation_database.cc rename to src/cx/compilation_database.cc diff --git a/src/uml/compilation_database.h b/src/cx/compilation_database.h similarity index 100% rename from src/uml/compilation_database.h rename to src/cx/compilation_database.h diff --git a/src/cx/cursor.h b/src/cx/cursor.h new file mode 100644 index 00000000..f6212912 --- /dev/null +++ b/src/cx/cursor.h @@ -0,0 +1,128 @@ +#pragma once + +#include "cx/type.h" + +namespace clanguml { +namespace cx { + +class cursor { +public: + cursor() + : m_cursor{clang_getNullCursor()} + { + } + + cursor(CXCursor &&c) + : m_cursor{std::move(c)} + { + } + + cursor(const CXCursor &c) + : m_cursor{c} + { + } + + cursor(const cursor &c) + : m_cursor{c.get()} + { + } + + ~cursor() = default; + + bool operator==(const cursor &b) const + { + return clang_equalCursors(m_cursor, b.get()); + } + + cx::type type() const { return {clang_getCursorType(m_cursor)}; } + + std::string display_name() const + { + return to_string(clang_getCursorDisplayName(m_cursor)); + } + + std::string spelling() const + { + return to_string(clang_getCursorSpelling(m_cursor)); + } + + std::string fully_qualified() const + { + std::list res; + cursor iterator{m_cursor}; + while (iterator.kind() != CXCursor_TranslationUnit) { + auto name = iterator.spelling(); + if (!name.empty()) + res.push_front(iterator.spelling()); + iterator = iterator.semantic_parent(); + } + + return fmt::format("{}", fmt::join(res, "::")); + } + + cursor referenced() const + { + return cx::cursor{clang_getCursorReferenced(m_cursor)}; + } + + cursor semantic_parent() const + { + return {clang_getCursorSemanticParent(m_cursor)}; + } + + cursor lexical_parent() const + { + return {clang_getCursorLexicalParent(m_cursor)}; + } + + CXCursorKind kind() const { return m_cursor.kind; } + + bool is_definition() const { return clang_isCursorDefinition(m_cursor); } + + bool is_declaration() const { return clang_isDeclaration(kind()); } + + bool is_invalid_declaration() const + { + return clang_isInvalidDeclaration(m_cursor); + } + + CXSourceLocation location() const + { + return clang_getCursorLocation(m_cursor); + } + + bool is_reference() const { return clang_isReference(kind()); } + + bool is_expression() const { return clang_isExpression(kind()); } + + bool is_statement() const { return clang_isStatement(kind()); } + + bool is_attribute() const { return clang_isAttribute(kind()); } + + bool has_attrs() const { return clang_Cursor_hasAttrs(m_cursor); } + + bool is_invalid() const { return clang_isInvalid(kind()); } + + bool is_translation_unit() const { return clang_isTranslationUnit(kind()); } + + bool is_preprocessing() const { return clang_isPreprocessing(kind()); } + + CXVisibilityKind visibitity() const + { + return clang_getCursorVisibility(m_cursor); + } + + CXAvailabilityKind availability() const + { + return clang_getCursorAvailability(m_cursor); + } + + std::string usr() const { return to_string(clang_getCursorUSR(m_cursor)); } + + const CXCursor &get() const { return m_cursor; } + +private: + CXCursor m_cursor; +}; +} +} diff --git a/src/uml/cx.h b/src/cx/type.h similarity index 53% rename from src/uml/cx.h rename to src/cx/type.h index e8fb33e7..9fc6bde2 100644 --- a/src/uml/cx.h +++ b/src/cx/type.h @@ -141,125 +141,5 @@ public: private: CXType m_type; }; - -class cursor { -public: - cursor() - : m_cursor{clang_getNullCursor()} - { - } - - cursor(CXCursor &&c) - : m_cursor{std::move(c)} - { - } - - cursor(const CXCursor &c) - : m_cursor{c} - { - } - - cursor(const cursor &c) - : m_cursor{c.get()} - { - } - - ~cursor() = default; - - bool operator==(const cursor &b) const - { - return clang_equalCursors(m_cursor, b.get()); - } - - cx::type type() const { return {clang_getCursorType(m_cursor)}; } - - std::string display_name() const - { - return to_string(clang_getCursorDisplayName(m_cursor)); - } - - std::string spelling() const - { - return to_string(clang_getCursorSpelling(m_cursor)); - } - - std::string fully_qualified() const - { - std::list res; - cursor iterator{m_cursor}; - while (iterator.kind() != CXCursor_TranslationUnit) { - auto name = iterator.spelling(); - if (!name.empty()) - res.push_front(iterator.spelling()); - iterator = iterator.semantic_parent(); - } - - return fmt::format("{}", fmt::join(res, "::")); - } - - cursor referenced() const - { - return cx::cursor{clang_getCursorReferenced(m_cursor)}; - } - - cursor semantic_parent() const - { - return {clang_getCursorSemanticParent(m_cursor)}; - } - - cursor lexical_parent() const - { - return {clang_getCursorLexicalParent(m_cursor)}; - } - - CXCursorKind kind() const { return m_cursor.kind; } - - bool is_definition() const { return clang_isCursorDefinition(m_cursor); } - - bool is_declaration() const { return clang_isDeclaration(kind()); } - - bool is_invalid_declaration() const - { - return clang_isInvalidDeclaration(m_cursor); - } - - CXSourceLocation location() const - { - return clang_getCursorLocation(m_cursor); - } - - bool is_reference() const { return clang_isReference(kind()); } - - bool is_expression() const { return clang_isExpression(kind()); } - - bool is_statement() const { return clang_isStatement(kind()); } - - bool is_attribute() const { return clang_isAttribute(kind()); } - - bool has_attrs() const { return clang_Cursor_hasAttrs(m_cursor); } - - bool is_invalid() const { return clang_isInvalid(kind()); } - - bool is_translation_unit() const { return clang_isTranslationUnit(kind()); } - - bool is_preprocessing() const { return clang_isPreprocessing(kind()); } - - CXVisibilityKind visibitity() const - { - return clang_getCursorVisibility(m_cursor); - } - - CXAvailabilityKind availability() const - { - return clang_getCursorAvailability(m_cursor); - } - - std::string usr() const { return to_string(clang_getCursorUSR(m_cursor)); } - - const CXCursor &get() const { return m_cursor; } - -private: - CXCursor m_cursor; -}; } } diff --git a/src/main.cc b/src/main.cc index 03612568..fb096937 100644 --- a/src/main.cc +++ b/src/main.cc @@ -3,7 +3,7 @@ #include "puml/sequence_diagram_generator.h" #include "uml/class_diagram_model.h" #include "uml/class_diagram_visitor.h" -#include "uml/compilation_database.h" +#include "cx/compilation_database.h" #include "uml/sequence_diagram_visitor.h" #include diff --git a/src/uml/class_diagram_visitor.h b/src/uml/class_diagram_visitor.h index 80909c38..2a6acc24 100644 --- a/src/uml/class_diagram_visitor.h +++ b/src/uml/class_diagram_visitor.h @@ -1,6 +1,7 @@ #pragma once #include "class_diagram_model.h" +#include "cx/cursor.h" #include #include diff --git a/src/uml/sequence_diagram_visitor.h b/src/uml/sequence_diagram_visitor.h index 2ea1f1ec..5b6e4207 100644 --- a/src/uml/sequence_diagram_visitor.h +++ b/src/uml/sequence_diagram_visitor.h @@ -1,6 +1,6 @@ #pragma once -#include "cx.h" +#include "cx/cursor.h" #include "sequence_diagram_model.h" #include