1 /* Definitions for Rust expressions
3 Copyright (C) 2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 extern struct value
*eval_op_rust_complement (struct type
*expect_type
,
26 struct expression
*exp
,
28 enum exp_opcode opcode
,
30 extern struct value
*eval_op_rust_array (struct type
*expect_type
,
31 struct expression
*exp
,
33 enum exp_opcode opcode
,
34 struct value
*ncopies
,
36 extern struct value
*eval_op_rust_ind (struct type
*expect_type
,
37 struct expression
*exp
,
39 enum exp_opcode opcode
,
41 extern struct value
*rust_subscript (struct type
*expect_type
,
42 struct expression
*exp
,
43 enum noside noside
, bool for_addr
,
44 struct value
*lhs
, struct value
*rhs
);
49 using rust_unop_compl_operation
= unop_operation
<UNOP_COMPLEMENT
,
50 eval_op_rust_complement
>;
51 using rust_array_operation
= binop_operation
<OP_RUST_ARRAY
,
54 /* The Rust indirection operation. */
55 class rust_unop_ind_operation
56 : public unop_ind_operation
60 using unop_ind_operation::unop_ind_operation
;
62 value
*evaluate (struct type
*expect_type
,
63 struct expression
*exp
,
64 enum noside noside
) override
66 if (noside
!= EVAL_NORMAL
)
67 return unop_ind_operation::evaluate (expect_type
, exp
, noside
);
69 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
70 return eval_op_rust_ind (expect_type
, exp
, noside
, UNOP_IND
, arg1
);
74 /* Subscript operator for Rust. */
75 class rust_subscript_operation
76 : public tuple_holding_operation
<operation_up
, operation_up
>
80 using tuple_holding_operation::tuple_holding_operation
;
82 value
*evaluate (struct type
*expect_type
,
83 struct expression
*exp
,
84 enum noside noside
) override
86 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
87 value
*arg2
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
88 return rust_subscript (expect_type
, exp
, noside
, false, arg1
, arg2
);
91 value
*slice (struct type
*expect_type
,
92 struct expression
*exp
,
95 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
96 value
*arg2
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
97 return rust_subscript (expect_type
, exp
, noside
, true, arg1
, arg2
);
100 enum exp_opcode
opcode () const override
101 { return BINOP_SUBSCRIPT
; }
104 class rust_unop_addr_operation
105 : public tuple_holding_operation
<operation_up
>
109 using tuple_holding_operation::tuple_holding_operation
;
111 value
*evaluate (struct type
*expect_type
,
112 struct expression
*exp
,
113 enum noside noside
) override
115 operation
*oper
= std::get
<0> (m_storage
).get ();
116 rust_subscript_operation
*sub_op
117 = dynamic_cast<rust_subscript_operation
*> (oper
);
118 if (sub_op
!= nullptr)
119 return sub_op
->slice (expect_type
, exp
, noside
);
120 return oper
->evaluate_for_address (exp
, noside
);
123 enum exp_opcode
opcode () const override
124 { return UNOP_ADDR
; }
127 } /* namespace expr */
129 #endif /* RUST_EXP_H */