Added parser util function for unexposed template params

This commit is contained in:
Bartek Kryza
2022-03-11 00:28:31 +01:00
parent 5ca55d51b1
commit 8ad4c4f5dc
4 changed files with 125 additions and 13 deletions

View File

@@ -25,6 +25,7 @@
#include <cppast/cpp_template.hpp>
#include <spdlog/spdlog.h>
#include <class_diagram/model/class_template.h>
#include <list>
namespace clanguml {
@@ -294,6 +295,81 @@ const cppast::cpp_type &unreferenced(const cppast::cpp_type &t)
return t;
}
std::vector<class_diagram::model::class_template>
parse_unexposed_template_params(const std::string &params)
{
using class_diagram::model::class_template;
std::vector<class_template> res;
int nested_template_level{0};
auto it = params.begin();
std::string type{};
std::vector<class_template> nested_params;
bool complete_class_template{false};
while (it != params.end()) {
if (*it == '<') {
int nested_level{0};
auto bracket_match_begin = it + 1;
auto bracket_match_end = bracket_match_begin;
while (bracket_match_end != params.end()) {
if (*bracket_match_end == '<') {
nested_level++;
}
else if (*bracket_match_end == '>') {
if (nested_level > 0)
nested_level--;
else
break;
}
else {
}
bracket_match_end++;
}
std::string nested_params_str(
bracket_match_begin, bracket_match_end);
nested_params = parse_unexposed_template_params(nested_params_str);
if (nested_params.empty())
nested_params.emplace_back(class_template{nested_params_str});
it = bracket_match_end - 1;
}
else if (*it == '>') {
complete_class_template = true;
}
else if (*it == ',') {
complete_class_template = true;
}
else {
type += *it;
}
if(complete_class_template) {
class_template t;
t.set_type(clanguml::util::trim(type));
type = "";
t.template_params_ = std::move(nested_params);
res.emplace_back(std::move(t));
complete_class_template = false;
}
it++;
}
if(!type.empty()) {
class_template t;
t.set_type(clanguml::util::trim(type));
type = "";
t.template_params_ = std::move(nested_params);
res.emplace_back(std::move(t));
complete_class_template = false;
}
return res;
}
} // namespace util
} // namespace cx
} // namespace clanguml