[committed,006/103] gccrs: ast: dump assignment and compound assignment expr

Message ID 20230221120230.596966-7-arthur.cohen@embecosm.com
State Unresolved
Headers
Series [committed,001/103] gccrs: Fix missing dead code analysis ICE on local enum definition |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Arthur Cohen Feb. 21, 2023, noon UTC
  From: David Faust <david.faust@oracle.com>

gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Dump assignment and compound
	assignment expressions.
---
 gcc/rust/ast/rust-ast-dump.cc | 56 +++++++++++++++++++++++++++++++++--
 1 file changed, 54 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 3d1b42d70e3..f3d0e2d9974 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -306,11 +306,63 @@  Dump::visit (TypeCastExpr &expr)
 
 void
 Dump::visit (AssignmentExpr &expr)
-{}
+{
+  expr.visit_lhs (*this);
+  stream << " = ";
+  expr.visit_rhs (*this);
+}
 
 void
 Dump::visit (CompoundAssignmentExpr &expr)
-{}
+{
+  auto op = "";
+  switch (expr.get_expr_type ())
+    {
+    case CompoundAssignmentOperator::ADD:
+      op = "+";
+      break;
+
+    case CompoundAssignmentOperator::SUBTRACT:
+      op = "-";
+      break;
+
+    case CompoundAssignmentOperator::MULTIPLY:
+      op = "*";
+      break;
+
+    case CompoundAssignmentOperator::DIVIDE:
+      op = "/";
+      break;
+
+    case CompoundAssignmentOperator::MODULUS:
+      op = "%";
+      break;
+
+    case CompoundAssignmentOperator::BITWISE_AND:
+      op = "&";
+      break;
+
+    case CompoundAssignmentOperator::BITWISE_OR:
+      op = "|";
+      break;
+
+    case CompoundAssignmentOperator::BITWISE_XOR:
+      op = "^";
+      break;
+
+    case CompoundAssignmentOperator::LEFT_SHIFT:
+      op = "<<";
+      break;
+
+    case CompoundAssignmentOperator::RIGHT_SHIFT:
+      op = ">>";
+      break;
+    }
+
+  expr.get_left_expr ()->accept_vis (*this);
+  stream << " " << op << "= ";
+  expr.get_right_expr ()->accept_vis (*this);
+}
 
 void
 Dump::visit (GroupedExpr &expr)