From bcd76dbcaabe6752657befcd8f4fec4d53126fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Mon, 3 Jul 2023 21:04:45 +0200 Subject: gccrs: rework the HIR dump pass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nearly complete rewrite of the HIR dump pass. fixes #693 gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (convert_param_kind_to_str): New. (convert_new_bind_type_to_str): New. (convert_mut_to_str): New. (Dump::go): New. (Dump::put): New. (Dump::begin): New. (Dump::end): New. (Dump::begin_field): New. (Dump::end_field): New. (Dump::put_field): New. (Dump::visit_field): New. (Dump::visit): Refactor. (Dump::visit_collection): New. (Dump::do_traititem): New. (Dump::do_vis_item): New. (Dump::do_functionparam): New. (Dump::do_pathpattern): New. (Dump::do_structexprstruct): New. (Dump::do_expr): New. (Dump::do_pathexpr): New. (Dump::do_typepathsegment): New. (Dump::do_typepathfunction): New. (Dump::do_qualifiedpathtype): New. (Dump::do_operatorexpr): New. (Dump::do_mappings): New. (Dump::do_inner_attrs): New. (Dump::do_outer_attrs): New. (Dump::do_baseloopexpr): New. (Dump::do_ifletexpr): New. (Dump::do_struct): New. (Dump::do_enumitem): New. (Dump::do_traitfunctiondecl): New. (Dump::do_externalitem): New. (Dump::do_namefunctionparam): New. (Dump::do_stmt): New. (Dump::do_type): New. (Dump::do_item): New. (Dump::do_tuplefield): New. (Dump::do_structfield): New. (Dump::do_genericargs): New. (Dump::do_maybenamedparam): New. * hir/rust-hir-dump.h: Refactor. * hir/tree/rust-hir-item.h (enum_to_str): New. * hir/tree/rust-hir-type.h (enum_to_str): New. * hir/tree/rust-hir.cc (enum_to_str): New. * util/rust-common.h (enum_to_str): New. Signed-off-by: Marc Poulhiès --- gcc/rust/hir/tree/rust-hir-item.h | 2 ++ gcc/rust/hir/tree/rust-hir-type.h | 2 ++ gcc/rust/hir/tree/rust-hir.cc | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) (limited to 'gcc/rust/hir/tree') diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 2d4cae5..cb0dc13 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -1009,6 +1009,8 @@ protected: } }; +std::string enum_to_str (UseTreeRebind::NewBindType); + // Rust use declaration (i.e. for modules) HIR node class UseDeclaration : public VisItem { diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h index 08a389e..37d108e 100644 --- a/gcc/rust/hir/tree/rust-hir-type.h +++ b/gcc/rust/hir/tree/rust-hir-type.h @@ -750,6 +750,8 @@ public: Identifier get_name () const { return name; } }; +std::string enum_to_str (MaybeNamedParam::ParamKind); + /* A function pointer type - can be created via coercion from function items and * non- capturing closures. */ class BareFunctionType : public TypeNoBounds diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc index 276c1a7..6e626c6 100644 --- a/gcc/rust/hir/tree/rust-hir.cc +++ b/gcc/rust/hir/tree/rust-hir.cc @@ -3670,6 +3670,36 @@ MaybeNamedParam::as_string () const return str; } +std::string +enum_to_str (MaybeNamedParam::ParamKind pk) +{ + switch (pk) + { + case MaybeNamedParam::ParamKind::UNNAMED: + return "UNNAMED"; + case MaybeNamedParam::ParamKind::IDENTIFIER: + return "IDENTIFIER"; + case MaybeNamedParam::ParamKind::WILDCARD: + return "WILDCARD"; + } + gcc_unreachable (); +} + +std::string +enum_to_str (UseTreeRebind::NewBindType nbt) +{ + switch (nbt) + { + case UseTreeRebind::NewBindType::NONE: + return "NONE"; + case UseTreeRebind::NewBindType::IDENTIFIER: + return "IDENTIFIER"; + case UseTreeRebind::NewBindType::WILDCARD: + return "WILDCARD"; + } + gcc_unreachable (); +} + /* Override that calls the function recursively on all items contained within * the module. */ void -- cgit v1.1