Improved handling of method template deductions

This commit is contained in:
Bartek Kryza
2023-04-18 23:56:09 +02:00
parent 6323ce8a92
commit 7f9d698afc
7 changed files with 197 additions and 21 deletions

View File

@@ -269,17 +269,24 @@ std::string get_source_text(
return get_source_text_raw(printable_range, sm);
}
std::pair<unsigned int, unsigned int> extract_template_parameter_index(
const std::string &type_parameter)
std::tuple<unsigned int, unsigned int, std::string>
extract_template_parameter_index(const std::string &type_parameter)
{
assert(type_parameter.find("type-parameter-") == 0);
auto toks =
util::split(type_parameter.substr(strlen("type-parameter-")), "-");
auto type_parameter_and_suffix = util::split(type_parameter, " ");
assert(toks.size() == 2);
auto toks = util::split(
type_parameter_and_suffix.front().substr(strlen("type-parameter-")),
"-");
return {std::stoi(toks.at(0)), std::stoi(toks.at(1))};
std::string qualifier;
if (type_parameter_and_suffix.size() > 1) {
qualifier = type_parameter_and_suffix.at(1);
}
return {std::stoi(toks.at(0)), std::stoi(toks.at(1)), std::move(qualifier)};
}
bool is_subexpr_of(const clang::Stmt *parent_stmt, const clang::Stmt *sub_stmt)

View File

@@ -98,8 +98,8 @@ std::string get_source_text_raw(
std::string get_source_text(
clang::SourceRange range, const clang::SourceManager &sm);
std::pair<unsigned int, unsigned int> extract_template_parameter_index(
const std::string &type_parameter);
std::tuple<unsigned int, unsigned int, std::string>
extract_template_parameter_index(const std::string &type_parameter);
/**
* @brief Check if an expression is contained in another expression

View File

@@ -215,6 +215,13 @@ std::string template_parameter::to_string(
"{}({})", return_type, fmt::join(function_args, ","));
}
if (is_method_template()) {
assert(template_params().size() == 2);
return fmt::format("{} {}::*{}", template_params().at(0).name().value(),
template_params().at(1).name().value(), method_qualifier());
}
std::string res;
const auto maybe_type = type();
if (maybe_type) {

View File

@@ -182,6 +182,14 @@ public:
bool is_function_template() const { return is_function_template_; }
void set_method_template(bool mt) { is_method_template_ = mt; }
bool is_method_template() const { return is_method_template_; }
void set_method_qualifier(const std::string &q) { method_qualifier_ = q; }
const std::string &method_qualifier() const { return method_qualifier_; }
private:
template_parameter() = default;
@@ -210,6 +218,10 @@ private:
bool is_function_template_{false};
bool is_method_template_{false};
std::string method_qualifier_;
/// Stores optional fully qualified name of constraint for this template
/// parameter
std::optional<std::string> concept_constraint_;