Added note decorator handling in class declarations

This commit is contained in:
Bartek Kryza
2021-07-29 18:43:35 +02:00
parent 0c82da9160
commit 75cb5765f8
5 changed files with 57 additions and 33 deletions

View File

@@ -19,6 +19,7 @@
#include "util/error.h"
#include "util/util.h"
#include "decorators.h"
#include <clang-c/CXCompilationDatabase.h>
#include <clang-c/Index.h>
@@ -61,6 +62,7 @@ public:
}
std::string name;
std::vector<std::string> namespace_;
std::vector<std::shared_ptr<decorators::decorator>> decorators;
std::string alias() const { return fmt::format("C_{:010}", m_id); }

View File

@@ -229,6 +229,10 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls,
cppast::cpp_access_specifier_kind last_access_specifier =
cppast::cpp_access_specifier_kind::cpp_private;
// Process class documentation comment
if(cls.comment().has_value())
c.decorators = decorators::parse(cls.comment().value());
// Process class child entities
if (c.is_struct)
last_access_specifier = cppast::cpp_access_specifier_kind::cpp_public;

View File

@@ -36,12 +36,12 @@ std::shared_ptr<decorator> decorator::from_string(std::string_view c)
if (c.find(note::label) == 0) {
return note::from_string(c);
}
else if (c.find(skip::label) == 0) {
return skip::from_string(c);
}
else if (c.find(skip_relationship::label) == 0) {
return skip_relationship::from_string(c);
}
else if (c.find(skip::label) == 0) {
return skip::from_string(c);
}
else if (c.find(style::label) == 0) {
return style::from_string(c);
}
@@ -58,17 +58,25 @@ std::shared_ptr<decorator> note::from_string(std::string_view c)
auto it = c.begin();
std::advance(it, note::label.size());
if (*it != '[')
return {};
if (*it == '[') {
std::advance(it, 1);
std::advance(it, 1);
auto pos = std::distance(c.begin(), it);
auto note_position = c.substr(pos, c.find("]", pos) - pos);
if (!note_position.empty())
res->position = note_position;
std::advance(it, note_position.size() + 1);
}
else if (*it == ' ') {
std::advance(it, 1);
}
else {
LOG_WARN("Invalid note decorator: {}", c);
return {};
}
auto pos = std::distance(c.begin(), it);
res->position = c.substr(pos, c.find("]", pos) - pos);
std::advance(it, res->position.size() + 1);
pos = std::distance(c.begin(), it);
res->text = c.substr(pos, c.find("}", pos) - pos);
res->position = util::trim(res->position);

View File

@@ -17,7 +17,6 @@
*/
#pragma once
#include "config/config.h"
#include <functional>
#include <map>
#include <memory>
@@ -34,7 +33,7 @@ struct decorator {
struct note : public decorator {
static const std::string label;
std::string position;
std::string position{"left"};
std::string text;
static std::shared_ptr<decorator> from_string(std::string_view c);