From 1347d23e09845b854ce50f8f857c062e04a89b60 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 14 Jul 2022 14:08:26 +0100 Subject: Implement AST dump for ArithmeticOrLogicalExpr to fix unreachable --- gcc/rust/ast/rust-ast-dump.cc | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 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..f4bff44 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -173,8 +173,40 @@ Dump::visit (ArithmeticOrLogicalExpr &expr) stream << "+"; break; - default: - gcc_unreachable (); + case ArithmeticOrLogicalOperator::SUBTRACT: + stream << "-"; + break; + + case ArithmeticOrLogicalOperator::MULTIPLY: + stream << "*"; + break; + + case ArithmeticOrLogicalOperator::DIVIDE: + stream << "/"; + break; + + case ArithmeticOrLogicalOperator::MODULUS: + stream << "%"; + break; + + case ArithmeticOrLogicalOperator::BITWISE_AND: + stream << "&"; + break; + + case ArithmeticOrLogicalOperator::BITWISE_OR: + stream << "|"; + break; + + case ArithmeticOrLogicalOperator::BITWISE_XOR: + stream << "^"; + break; + + case ArithmeticOrLogicalOperator::LEFT_SHIFT: + stream << "<<"; + break; + + case ArithmeticOrLogicalOperator::RIGHT_SHIFT: + stream << ">>"; break; } -- cgit v1.1 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