Fixed handling of template function specialization arguments
This commit is contained in:
@@ -250,6 +250,19 @@ 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)
|
||||
{
|
||||
assert(type_parameter.find("type-parameter-") == 0);
|
||||
|
||||
auto toks =
|
||||
util::split(type_parameter.substr(strlen("type-parameter-")), "-");
|
||||
|
||||
assert(toks.size() == 2);
|
||||
|
||||
return {std::stoi(toks.at(0)), std::stoi(toks.at(1))};
|
||||
}
|
||||
|
||||
bool is_subexpr_of(const clang::Stmt *parent_stmt, const clang::Stmt *sub_stmt)
|
||||
{
|
||||
if (parent_stmt == nullptr || sub_stmt == nullptr)
|
||||
|
||||
@@ -95,6 +95,9 @@ 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);
|
||||
|
||||
/**
|
||||
* @brief Check if an expression is contained in another expression
|
||||
*
|
||||
|
||||
@@ -111,6 +111,11 @@ bool template_parameter::is_variadic() const noexcept { return is_variadic_; }
|
||||
bool template_parameter::is_specialization_of(
|
||||
const template_parameter &ct) const
|
||||
{
|
||||
if(is_function_template() && ct.is_function_template()) {
|
||||
bool res{true};
|
||||
|
||||
}
|
||||
|
||||
return (ct.is_template_parameter() ||
|
||||
ct.is_template_template_parameter()) &&
|
||||
!is_template_parameter();
|
||||
@@ -139,6 +144,9 @@ bool operator==(const template_parameter &l, const template_parameter &r)
|
||||
if (l.is_template_parameter() != r.is_template_parameter())
|
||||
return res;
|
||||
|
||||
if (l.is_function_template() != r.is_function_template())
|
||||
return res;
|
||||
|
||||
if (l.is_template_parameter()) {
|
||||
// If this is a template parameter (e.g. 'typename T' or 'typename U'
|
||||
// we don't actually care what it is called
|
||||
@@ -165,6 +173,19 @@ std::string template_parameter::to_string(
|
||||
|
||||
assert(!(type().has_value() && concept_constraint().has_value()));
|
||||
|
||||
if (is_function_template()) {
|
||||
auto it = template_params_.begin();
|
||||
auto return_type = it->to_string(using_namespace, relative);
|
||||
std::advance(it, 1);
|
||||
|
||||
std::vector<std::string> function_args;
|
||||
for (; it != template_params_.end(); it++)
|
||||
function_args.push_back(it->to_string(using_namespace, relative));
|
||||
|
||||
return fmt::format(
|
||||
"{}({})", return_type, fmt::join(function_args, ","));
|
||||
}
|
||||
|
||||
std::string res;
|
||||
const auto maybe_type = type();
|
||||
if (maybe_type) {
|
||||
|
||||
@@ -176,6 +176,10 @@ public:
|
||||
|
||||
void set_unexposed(bool unexposed) { is_unexposed_ = unexposed; }
|
||||
|
||||
void set_function_template(bool ft) { is_function_template_ = ft; }
|
||||
|
||||
bool is_function_template() const { return is_function_template_; }
|
||||
|
||||
private:
|
||||
template_parameter() = default;
|
||||
|
||||
@@ -202,11 +206,14 @@ private:
|
||||
/// Whether the template parameter is variadic
|
||||
bool is_variadic_{false};
|
||||
|
||||
bool is_function_template_{false};
|
||||
|
||||
/// Stores optional fully qualified name of constraint for this template
|
||||
/// parameter
|
||||
std::optional<std::string> concept_constraint_;
|
||||
|
||||
// Nested template parameters
|
||||
// If this is a function template, the first element is the return type
|
||||
std::vector<template_parameter> template_params_;
|
||||
|
||||
std::optional<int64_t> id_;
|
||||
|
||||
Reference in New Issue
Block a user