aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile.cc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2020-05-30 19:01:06 +0100
committerPhilip Herron <philip.herron@embecosm.com>2020-11-28 21:13:15 +0000
commitde6bc4da463e949ed63a636c3d8fdac0859d1c4f (patch)
tree5afac641d21af3db1399d0394fb6ee7546dc86f2 /gcc/rust/backend/rust-compile.cc
parentf230adf6179df01a709bacc8e7e83a160d04aeb2 (diff)
downloadgcc-de6bc4da463e949ed63a636c3d8fdac0859d1c4f.zip
gcc-de6bc4da463e949ed63a636c3d8fdac0859d1c4f.tar.gz
gcc-de6bc4da463e949ed63a636c3d8fdac0859d1c4f.tar.bz2
Lower NegationExprs
Diffstat (limited to 'gcc/rust/backend/rust-compile.cc')
-rw-r--r--gcc/rust/backend/rust-compile.cc29
1 files changed, 28 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 69245dc..2630c0f 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -288,9 +288,36 @@ Compilation::visit (AST::DereferenceExpr &expr)
void
Compilation::visit (AST::ErrorPropagationExpr &expr)
{}
+
void
Compilation::visit (AST::NegationExpr &expr)
-{}
+{
+ Bexpression *root = NULL;
+ VISIT_POP (expr.get_expr ()->get_locus_slow (), expr.get_expr (), root,
+ exprs);
+ if (root == NULL)
+ {
+ rust_error_at (expr.get_expr ()->get_locus_slow (), "failed to compile");
+ return;
+ }
+
+ Operator op;
+ switch (expr.negation_type)
+ {
+ case AST::NegationExpr::NEGATE:
+ op = OPERATOR_MINUS;
+ break;
+ case AST::NegationExpr::NOT:
+ op = OPERATOR_NOT;
+ break;
+ default:
+ rust_fatal_error (expr.get_locus_slow (), "failed to compile operator");
+ return;
+ }
+
+ auto unary = backend->unary_expression (op, root, expr.get_locus_slow ());
+ exprs.push_back (unary);
+}
void
Compilation::visit (AST::ArithmeticOrLogicalExpr &expr)