Skip to content
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

Support ast dump of generic parameters on functions #1382

Merged
merged 1 commit into from Jul 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions gcc/rust/ast/rust-ast-dump.cc
Expand Up @@ -48,7 +48,11 @@ void
Dump::go (AST::Crate &crate)
{
for (auto &item : crate.items)
item->accept_vis (*this);
{
stream << indentation;
item->accept_vis (*this);
stream << "\n";
}
}

void
Expand Down Expand Up @@ -401,8 +405,12 @@ Dump::visit (AsyncBlockExpr &expr)
void
Dump::visit (TypeParam &param)
{
// Is it possible to have a null type here?
param.get_type ()->accept_vis (*this);
stream << param.get_type_representation ();
if (param.has_type ())
{
stream << ": ";
param.get_type ()->accept_vis (*this);
}
}

void
Expand Down Expand Up @@ -473,8 +481,24 @@ Dump::visit (UseDeclaration &use_decl)
void
Dump::visit (Function &function)
{
stream << indentation << "fn " << function.get_function_name () << '(';
stream << "fn " << function.get_function_name ();

if (function.has_generics ())
{
stream << "<";
for (size_t i = 0; i < function.get_generic_params ().size (); i++)
{
auto &param = function.get_generic_params ().at (i);
param->accept_vis (*this);

bool has_next = (i + 1) < function.get_generic_params ().size ();
if (has_next)
stream << ", ";
}
stream << ">";
}

stream << '(';
auto &params = function.get_function_params ();
if (params.size () >= 1)
{
Expand Down