Skip to content

fix(cpp1): emit parents' *template-head*s of alias #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

87 changes: 29 additions & 58 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4904,6 +4904,30 @@ class cppfront
)
-> void
{
// Helper for declarations with parent *template-head*s.
auto const emit_parent_template_parameters = [&]() {
auto parent_template_parameters = std::string{};
auto parent = n.parent_declaration;
while (
parent
&& parent->is_type()
)
{
if (parent->requires_clause_expression) {
parent_template_parameters =
"requires( " + print_to_string(*parent->requires_clause_expression) + " )\n"
+ parent_template_parameters;
}
if (parent->template_parameters) {
parent_template_parameters =
"template " + print_to_string( *parent->template_parameters, false, true )
+ " " + parent_template_parameters;
}
parent = parent->parent_declaration;
}
printer.print_cpp2(parent_template_parameters, n.position());
};

// Helper for declarations that can have requires-clauses
auto const emit_requires_clause = [&]() {
if (
Expand Down Expand Up @@ -5097,46 +5121,12 @@ class cppfront
return;
}

auto parent_template_params = std::string{};
auto parent_template_args = std::string{};
auto parent_qualifier = std::string{};

auto parent = n.parent_declaration;
while (parent && parent->is_type())
{
if (!parent_qualifier.empty()) {
parent_qualifier.insert(0, "::");
}
parent_qualifier.insert(0, parent->name()->to_string());

if (parent->template_parameters) {
parent_template_params.insert(0, "template" + print_to_string(*parent->template_parameters));
for (auto const& param : parent->template_parameters->parameters) {
assert(param->name());
if (parent_template_args.empty()) {
parent_template_args = "<>";
}
else {
parent_template_args.insert(parent_template_args.size()-1, ",");
}
parent_template_args.insert(parent_template_args.size()-1, param->name()->as_string_view());
}
}

parent = parent->parent_declaration;
}

if (!parent_template_params.empty()) {
parent_template_params += " ";
}

emit_parent_template_parameters();
printer.print_cpp2(
parent_template_params
+ "inline CPP2_CONSTEXPR "
"inline CPP2_CONSTEXPR "
+ type
+ parent_template_args
+ " " + parent_qualifier
+ parent_template_args + "::"
+ " "
+ type_qualification_if_any_for(n)
+ print_to_string(*n.identifier)
+ " = "
+ print_to_string( *std::get<alias_node::an_object>(a->initializer) )
Expand Down Expand Up @@ -5304,26 +5294,7 @@ class cppfront
&& n.initializer // only if the function has a definition (is not abstract)
)
{
auto parent_template_parameters = std::string{};
auto parent = n.parent_declaration;
while (
parent
&& parent->is_type()
)
{
if (parent->requires_clause_expression) {
parent_template_parameters =
"requires( " + print_to_string(*parent->requires_clause_expression) + " )\n"
+ parent_template_parameters;
}
if (parent->template_parameters) {
parent_template_parameters =
"template " + print_to_string( *parent->template_parameters, false, true )
+ " " + parent_template_parameters;
}
parent = parent->parent_declaration;
}
printer.print_cpp2(parent_template_parameters, n.position());
emit_parent_template_parameters();
}

// Now, emit our own template parameters
Expand Down