aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-11-16 13:54:43 +0000
committerPhilip Herron <philip.herron@embecosm.com>2021-11-16 14:09:23 +0000
commitc47d5cbdee9b701fb7753b44530fcb51f80b20fa (patch)
tree2cd74fceb2f9cc92ae47988507fdf424fb3d3682 /gcc/rust/backend/rust-compile-expr.h
parent89e02f52d86c7120046236e654e49749c4b4ecb3 (diff)
downloadgcc-c47d5cbdee9b701fb7753b44530fcb51f80b20fa.zip
gcc-c47d5cbdee9b701fb7753b44530fcb51f80b20fa.tar.gz
gcc-c47d5cbdee9b701fb7753b44530fcb51f80b20fa.tar.bz2
Initial support operator overloading on [lang = "add"]
This change incorporates a few changes. 1. Create new gcc/rust/backend/rust-compile-expr.cc to split out implementation code 2. Create new type check context api calls: - TypeCheckContext::lookup_operator_overload - TypeCheckContext::insert_operator_overload 3. Update type checking for ArithmeticOrLogicalExpr to look for any operator overloading When we are looking for operator overloads we must look up the associated lang item type for this paticular operation, to resolve the operation to any known lang_items by looking up the specified lang_item to DefId. Then we must probe for the lang_item candidate for this paticular lang_item DefID to see if we can resolve it to a method call. Then based on the autoderef rules in a MethodCallExpr we must verify that we don't end up in a recursive operator overload by checking that the current context is not the same as the actual operator overload for this type. Finally we mark this expression as operator overload and setup everything as a resolved MethodCallExpr. Fixes #249
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h26
1 files changed, 15 insertions, 11 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index f43db50..c9d3c30 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -448,17 +448,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
{
@@ -999,6 +989,20 @@ 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);
+
private:
CompileExpr (Context *ctx)
: HIRCompileBase (ctx), translated (nullptr), capacity_expr (nullptr)