diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-11-16 15:18:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 15:18:49 +0000 |
commit | 5514d9cec51d5ec7cc30dd6cdbfadfdddbe0aab3 (patch) | |
tree | 55051cad7f474f411d79ca1e86cc23d63138716d /gcc/rust/backend/rust-compile-expr.h | |
parent | dcd758595f646a480947265ccc9833fdd3976b75 (diff) | |
parent | 6d1333ef46cba6ed9e1ace817f9cc649b7f7a1df (diff) | |
download | gcc-5514d9cec51d5ec7cc30dd6cdbfadfdddbe0aab3.zip gcc-5514d9cec51d5ec7cc30dd6cdbfadfdddbe0aab3.tar.gz gcc-5514d9cec51d5ec7cc30dd6cdbfadfdddbe0aab3.tar.bz2 |
Merge #801
801: operator overloading r=philberty a=philberty
This change adds operator overloading by following how the C++ front-end
does it. We are relying on GCC to inline the operator overloads which does
occur once optimizations are enabled. It also brings back the desurgared
compound assignment expression (e2b761b13e6ccd3a7af4100183bb13e32b5b0da0)
for lang_items such as add_assign. You can find more information on how the algorithm works in:
- c47d5cbdee9b701fb7753b44530fcb51f80b20fa
- a7fb60bb626f7b936bf117636db777a5f0df30c9
These were refactored in: 0f74fe23c6d602c257ba94b2522bd9d6a594609e
Fixes #249
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index f43db50..b4079f7 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -388,6 +388,8 @@ public: ctx->add_statement (assignment); } + void visit (HIR::CompoundAssignmentExpr &expr) override; + void visit (HIR::ArrayIndexExpr &expr) override { Bexpression *array = CompileExpr::Compile (expr.get_array_expr (), ctx); @@ -448,17 +450,7 @@ public: constructor.push_back (translated_expr); } - void visit (HIR::ArithmeticOrLogicalExpr &expr) override - { - auto op = expr.get_expr_type (); - auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx); - auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx); - auto location = expr.get_locus (); - - translated - = ctx->get_backend ()->arithmetic_or_logical_expression (op, lhs, rhs, - location); - } + void visit (HIR::ArithmeticOrLogicalExpr &expr) override; void visit (HIR::ComparisonExpr &expr) override { @@ -482,15 +474,7 @@ public: = ctx->get_backend ()->lazy_boolean_expression (op, lhs, rhs, location); } - void visit (HIR::NegationExpr &expr) override - { - auto op = expr.get_expr_type (); - auto negated_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx); - auto location = expr.get_locus (); - - translated - = ctx->get_backend ()->negation_expression (op, negated_expr, location); - } + void visit (HIR::NegationExpr &expr) override; void visit (HIR::TypeCastExpr &expr) override { @@ -999,6 +983,26 @@ public: expr.get_locus ()); } +protected: + Bexpression *compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn, + TyTy::BaseType *receiver, + TyTy::FnType *fntype, + Bexpression *receiver_ref, + std::vector<HIR::Expr *> &arguments, + Location expr_locus); + + Bexpression *resolve_method_address (TyTy::FnType *fntype, HirId ref, + TyTy::BaseType *receiver, + HIR::PathIdentSegment &segment, + Analysis::NodeMapping expr_mappings, + Location expr_locus); + + Bexpression * + resolve_operator_overload (Analysis::RustLangItem::ItemType lang_item_type, + HIR::OperatorExpr &expr, Bexpression *lhs, + Bexpression *rhs, HIR::Expr *lhs_expr, + HIR::Expr *rhs_expr); + private: CompileExpr (Context *ctx) : HIRCompileBase (ctx), translated (nullptr), capacity_expr (nullptr) |