diff options
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-expr.h | 79 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 44 |
2 files changed, 123 insertions, 0 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index a8048bb..df836fc 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.h +++ b/gcc/rust/hir/rust-ast-lower-expr.h @@ -728,6 +728,85 @@ public: expr.get_outer_attrs (), expr.get_locus ()); } + void visit (AST::RangeFromToExpr &expr) override + { + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Expr *range_from + = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); + HIR::Expr *range_to + = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); + + translated + = new HIR::RangeFromToExpr (mapping, + std::unique_ptr<HIR::Expr> (range_from), + std::unique_ptr<HIR::Expr> (range_to), + expr.get_locus ()); + } + + void visit (AST::RangeFromExpr &expr) override + { + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Expr *range_from + = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); + + translated + = new HIR::RangeFromExpr (mapping, + std::unique_ptr<HIR::Expr> (range_from), + expr.get_locus ()); + } + + void visit (AST::RangeToExpr &expr) override + { + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Expr *range_to + = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); + + translated + = new HIR::RangeToExpr (mapping, std::unique_ptr<HIR::Expr> (range_to), + expr.get_locus ()); + } + + void visit (AST::RangeFullExpr &expr) override + { + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated = new HIR::RangeFullExpr (mapping, expr.get_locus ()); + } + + void visit (AST::RangeFromToInclExpr &expr) override + { + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Expr *range_from + = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); + HIR::Expr *range_to + = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); + + translated + = new HIR::RangeFromToInclExpr (mapping, + std::unique_ptr<HIR::Expr> (range_from), + std::unique_ptr<HIR::Expr> (range_to), + expr.get_locus ()); + } + private: ASTLoweringExpr () : ASTLoweringBase (), translated (nullptr), diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index b8d3354..b77545a 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -2430,6 +2430,9 @@ public: void accept_vis (HIRFullVisitor &vis) override; + std::unique_ptr<Expr> &get_from_expr () { return from; } + std::unique_ptr<Expr> &get_to_expr () { return to; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -2480,6 +2483,8 @@ public: void accept_vis (HIRFullVisitor &vis) override; + std::unique_ptr<Expr> &get_from_expr () { return from; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -2531,6 +2536,8 @@ public: void accept_vis (HIRFullVisitor &vis) override; + std::unique_ptr<Expr> &get_to_expr () { return to; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -2617,6 +2624,9 @@ public: void accept_vis (HIRFullVisitor &vis) override; + std::unique_ptr<Expr> &get_from_expr () { return from; } + std::unique_ptr<Expr> &get_to_expr () { return to; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -4019,6 +4029,40 @@ 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 ()) + {} + + OperatorExprMeta (HIR::ArrayIndexExpr &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 |