aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree
diff options
context:
space:
mode:
authorAntonio Gomes <antoniospg100@gmail.com>2024-07-14 01:45:24 -0300
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:53 +0100
commit57d12c683b3783e2b9460fe5607a4d91f6b67de9 (patch)
tree496aa805b4843141f55fc548ec687edf2b804825 /gcc/rust/hir/tree
parent8a83c569101b8b84056fb698c5cf67a7f6ae6d91 (diff)
downloadgcc-57d12c683b3783e2b9460fe5607a4d91f6b67de9.zip
gcc-57d12c683b3783e2b9460fe5607a4d91f6b67de9.tar.gz
gcc-57d12c683b3783e2b9460fe5607a4d91f6b67de9.tar.bz2
gccrs: Improve error messages for operator expressions
gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h: Add new get_operator_str method in ArithmeticOrLogicalExpr and CompoundAssignmentExpr * hir/tree/rust-hir.cc: Likewise * typecheck/rust-hir-type-check-expr.cc: Improve error message for operator expressions to display the correct operator symbol gcc/testsuite/ChangeLog: * rust/compile/shadow1.rs: Fix test for new error message Signed-off-by: Antonio Gomes <antoniospg100@gmail.com>
Diffstat (limited to 'gcc/rust/hir/tree')
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h4
-rw-r--r--gcc/rust/hir/tree/rust-hir.cc19
2 files changed, 20 insertions, 3 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index d8cfe68..ff9fcee 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -417,6 +417,8 @@ public:
std::unique_ptr<Expr> &get_lhs () { return main_or_left_expr; }
std::unique_ptr<Expr> &get_rhs () { return right_expr; }
+ std::string get_operator_str () const;
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -766,6 +768,8 @@ public:
void visit_lhs (HIRFullVisitor &vis) { main_or_left_expr->accept_vis (vis); }
void visit_rhs (HIRFullVisitor &vis) { right_expr->accept_vis (vis); }
+ std::string get_operator_str () const;
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index 8388d58..ac0a256 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -1299,7 +1299,7 @@ AssignmentExpr::as_string () const
}
std::string
-CompoundAssignmentExpr::as_string () const
+CompoundAssignmentExpr::get_operator_str () const
{
std::string operator_str;
operator_str.reserve (1);
@@ -1344,7 +1344,14 @@ CompoundAssignmentExpr::as_string () const
operator_str += "=";
+ return operator_str;
+}
+
+std::string
+CompoundAssignmentExpr::as_string () const
+{
std::string str ("CompoundAssignmentExpr: ");
+ std::string operator_str = get_operator_str ();
if (main_or_left_expr == nullptr || right_expr == nullptr)
{
str += "error. this is probably a parsing failure.";
@@ -1574,7 +1581,7 @@ ErrorPropagationExpr::as_string () const
}
std::string
-ArithmeticOrLogicalExpr::as_string () const
+ArithmeticOrLogicalExpr::get_operator_str () const
{
std::string operator_str;
operator_str.reserve (1);
@@ -1617,8 +1624,14 @@ ArithmeticOrLogicalExpr::as_string () const
break;
}
+ return operator_str;
+}
+
+std::string
+ArithmeticOrLogicalExpr::as_string () const
+{
std::string str = main_or_left_expr->as_string () + " ";
- str += operator_str + " ";
+ str += get_operator_str () + " ";
str += right_expr->as_string ();
return "( " + str + " (" + get_mappings ().as_string () + "))";