diff options
author | Philip Herron <herron.philip@googlemail.com> | 2020-05-30 19:01:06 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2020-11-28 21:13:15 +0000 |
commit | de6bc4da463e949ed63a636c3d8fdac0859d1c4f (patch) | |
tree | 5afac641d21af3db1399d0394fb6ee7546dc86f2 /gcc | |
parent | f230adf6179df01a709bacc8e7e83a160d04aeb2 (diff) | |
download | gcc-de6bc4da463e949ed63a636c3d8fdac0859d1c4f.zip gcc-de6bc4da463e949ed63a636c3d8fdac0859d1c4f.tar.gz gcc-de6bc4da463e949ed63a636c3d8fdac0859d1c4f.tar.bz2 |
Lower NegationExprs
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 3 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 29 |
2 files changed, 30 insertions, 2 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index ea66884..9531cf2 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -501,7 +501,6 @@ public: NOT }; -private: // Note: overload negation via std::ops::Neg and not via std::ops::Not // Negation only works for signed integer and floating-point types, NOT only // works for boolean and integer types (via bitwise NOT) @@ -531,6 +530,8 @@ public: virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + Expr *get_expr () { return main_or_left_expr.get (); } + protected: // Use covariance to implement clone function as returning this object rather // than base 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) |