From 2ff776d36416adbade8161eeda4ee478a288af87 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 14 Jul 2022 15:06:22 +0100 Subject: Support ast dump of generic parameters on functions --- gcc/rust/ast/rust-ast-dump.cc | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index a06dd72..9af8fa8 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -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 @@ -401,8 +405,12 @@ Dump::visit (AsyncBlockExpr &expr) void Dump::visit (TypeParam ¶m) { - // 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 @@ -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 ¶m = 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 ¶ms = function.get_function_params (); if (params.size () >= 1) { -- cgit v1.1