diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-02-24 16:22:29 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-02-24 16:39:12 +0000 |
commit | d8351d9168f92c997858fdb25942c05dc832f330 (patch) | |
tree | c5937fb363281a91eb7230141f308b932528fc09 /gcc/rust | |
parent | 5d5396d52277be5e2c82249f889a78d909f29084 (diff) | |
download | gcc-d8351d9168f92c997858fdb25942c05dc832f330.zip gcc-d8351d9168f92c997858fdb25942c05dc832f330.tar.gz gcc-d8351d9168f92c997858fdb25942c05dc832f330.tar.bz2 |
Decouple the HIR::OperatorExpr from resolving operator overloads
This means we can reuse the same code for operations that are not
HIR::OperatorExpr's such as ArrayIndexExpr which can resolve to
core::ops::index lang items.
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 2 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 2 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 30 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.cc | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 2 |
5 files changed, 34 insertions, 4 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 6849471..dfe5231 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -790,7 +790,7 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref, tree CompileExpr::resolve_operator_overload ( - Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExpr &expr, + Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExprMeta expr, tree lhs, tree rhs, HIR::Expr *lhs_expr, HIR::Expr *rhs_expr) { TyTy::FnType *fntype; diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 7fd708c..f2b4df8 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -799,7 +799,7 @@ protected: tree resolve_operator_overload (Analysis::RustLangItem::ItemType lang_item_type, - HIR::OperatorExpr &expr, tree lhs, tree rhs, + HIR::OperatorExprMeta expr, tree lhs, tree rhs, HIR::Expr *lhs_expr, HIR::Expr *rhs_expr); tree compile_bool_literal (const HIR::LiteralExpr &expr, diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 8b98881..6ec8d52 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -4029,6 +4029,36 @@ protected: return new AsyncBlockExpr (*this); } }; + +// this is a utility helper class for type-checking and code-generation +class OperatorExprMeta +{ +public: + OperatorExprMeta (HIR::CompoundAssignmentExpr &expr) + : node_mappings (expr.get_mappings ()), locus (expr.get_locus ()) + {} + + OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr) + : node_mappings (expr.get_mappings ()), locus (expr.get_locus ()) + {} + + OperatorExprMeta (HIR::NegationExpr &expr) + : node_mappings (expr.get_mappings ()), locus (expr.get_locus ()) + {} + + OperatorExprMeta (HIR::DereferenceExpr &expr) + : node_mappings (expr.get_mappings ()), locus (expr.get_locus ()) + {} + + const Analysis::NodeMapping &get_mappings () const { return node_mappings; } + + Location get_locus () const { return locus; } + +private: + const Analysis::NodeMapping node_mappings; + Location locus; +}; + } // namespace HIR } // namespace Rust diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 2703d91..7ae2b57 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -288,7 +288,7 @@ TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr) bool TypeCheckExpr::resolve_operator_overload ( - Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExpr &expr, + Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExprMeta expr, TyTy::BaseType *lhs, TyTy::BaseType *rhs) { // look up lang item for arithmetic type diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index e222528..93aa868 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -1239,7 +1239,7 @@ public: protected: bool resolve_operator_overload (Analysis::RustLangItem::ItemType lang_item_type, - HIR::OperatorExpr &expr, TyTy::BaseType *lhs, + HIR::OperatorExprMeta expr, TyTy::BaseType *lhs, TyTy::BaseType *rhs); private: |