@@ -92,6 +92,31 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
92
92
ctx->add_statement (assignment);
93
93
}
94
94
95
+ void
96
+ CompileExpr::visit (HIR::NegationExpr &expr)
97
+ {
98
+ auto op = expr.get_expr_type ();
99
+ auto negated_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
100
+ auto location = expr.get_locus ();
101
+
102
+ // this might be an operator overload situation lets check
103
+ TyTy::FnType *fntype;
104
+ bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
105
+ expr.get_mappings ().get_hirid (), &fntype);
106
+ if (is_op_overload)
107
+ {
108
+ auto lang_item_type
109
+ = Analysis::RustLangItem::NegationOperatorToLangItem (op);
110
+ translated
111
+ = resolve_operator_overload (lang_item_type, expr, negated_expr,
112
+ nullptr , expr.get_expr ().get (), nullptr );
113
+ return ;
114
+ }
115
+
116
+ translated
117
+ = ctx->get_backend ()->negation_expression (op, negated_expr, location);
118
+ }
119
+
95
120
Bexpression *
96
121
CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
97
122
TyTy::BaseType *receiver,
@@ -311,7 +336,8 @@ CompileExpr::resolve_operator_overload (
311
336
= static_cast <const TyTy::DynamicObjectType *> (receiver->get_root ());
312
337
313
338
std::vector<HIR::Expr *> arguments;
314
- arguments.push_back (rhs_expr);
339
+ if (rhs_expr != nullptr ) // can be null for negation_expr (unary ones)
340
+ arguments.push_back (rhs_expr);
315
341
316
342
return compile_dyn_dispatch_call (dyn, receiver, fntype, lhs, arguments,
317
343
expr.get_locus ());
@@ -356,7 +382,8 @@ CompileExpr::resolve_operator_overload (
356
382
357
383
std::vector<Bexpression *> args;
358
384
args.push_back (self); // adjusted self
359
- args.push_back (rhs);
385
+ if (rhs != nullptr ) // can be null for negation_expr (unary ones)
386
+ args.push_back (rhs);
360
387
361
388
auto fncontext = ctx->peek_fn ();
362
389
return ctx->get_backend ()->call_expression (fncontext.fndecl , fn_expr, args,
0 commit comments