1 /* Definitions for expressions in GDB
3 Copyright (C) 2020-2023 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 #include "expression.h"
28 #include "gdbsupport/traits.h"
29 #include "gdbsupport/enum-flags.h"
34 extern void gen_expr_binop (struct expression
*exp
,
36 expr::operation
*lhs
, expr::operation
*rhs
,
37 struct agent_expr
*ax
, struct axs_value
*value
);
38 extern void gen_expr_structop (struct expression
*exp
,
42 struct agent_expr
*ax
, struct axs_value
*value
);
43 extern void gen_expr_unop (struct expression
*exp
,
46 struct agent_expr
*ax
, struct axs_value
*value
);
48 extern struct value
*eval_op_scope (struct type
*expect_type
,
49 struct expression
*exp
,
51 struct type
*type
, const char *string
);
52 extern struct value
*eval_op_var_msym_value (struct type
*expect_type
,
53 struct expression
*exp
,
56 bound_minimal_symbol msymbol
);
57 extern struct value
*eval_op_var_entry_value (struct type
*expect_type
,
58 struct expression
*exp
,
59 enum noside noside
, symbol
*sym
);
60 extern struct value
*eval_op_func_static_var (struct type
*expect_type
,
61 struct expression
*exp
,
63 value
*func
, const char *var
);
64 extern struct value
*eval_op_register (struct type
*expect_type
,
65 struct expression
*exp
,
66 enum noside noside
, const char *name
);
67 extern struct value
*eval_op_ternop (struct type
*expect_type
,
68 struct expression
*exp
,
70 struct value
*array
, struct value
*low
,
72 extern struct value
*eval_op_structop_struct (struct type
*expect_type
,
73 struct expression
*exp
,
77 extern struct value
*eval_op_structop_ptr (struct type
*expect_type
,
78 struct expression
*exp
,
82 extern struct value
*eval_op_member (struct type
*expect_type
,
83 struct expression
*exp
,
85 struct value
*arg1
, struct value
*arg2
);
86 extern struct value
*eval_op_add (struct type
*expect_type
,
87 struct expression
*exp
,
89 struct value
*arg1
, struct value
*arg2
);
90 extern struct value
*eval_op_sub (struct type
*expect_type
,
91 struct expression
*exp
,
93 struct value
*arg1
, struct value
*arg2
);
94 extern struct value
*eval_op_binary (struct type
*expect_type
,
95 struct expression
*exp
,
96 enum noside noside
, enum exp_opcode op
,
97 struct value
*arg1
, struct value
*arg2
);
98 extern struct value
*eval_op_subscript (struct type
*expect_type
,
99 struct expression
*exp
,
100 enum noside noside
, enum exp_opcode op
,
103 extern struct value
*eval_op_equal (struct type
*expect_type
,
104 struct expression
*exp
,
105 enum noside noside
, enum exp_opcode op
,
108 extern struct value
*eval_op_notequal (struct type
*expect_type
,
109 struct expression
*exp
,
110 enum noside noside
, enum exp_opcode op
,
113 extern struct value
*eval_op_less (struct type
*expect_type
,
114 struct expression
*exp
,
115 enum noside noside
, enum exp_opcode op
,
118 extern struct value
*eval_op_gtr (struct type
*expect_type
,
119 struct expression
*exp
,
120 enum noside noside
, enum exp_opcode op
,
123 extern struct value
*eval_op_geq (struct type
*expect_type
,
124 struct expression
*exp
,
125 enum noside noside
, enum exp_opcode op
,
128 extern struct value
*eval_op_leq (struct type
*expect_type
,
129 struct expression
*exp
,
130 enum noside noside
, enum exp_opcode op
,
133 extern struct value
*eval_op_repeat (struct type
*expect_type
,
134 struct expression
*exp
,
135 enum noside noside
, enum exp_opcode op
,
138 extern struct value
*eval_op_plus (struct type
*expect_type
,
139 struct expression
*exp
,
140 enum noside noside
, enum exp_opcode op
,
142 extern struct value
*eval_op_neg (struct type
*expect_type
,
143 struct expression
*exp
,
144 enum noside noside
, enum exp_opcode op
,
146 extern struct value
*eval_op_complement (struct type
*expect_type
,
147 struct expression
*exp
,
151 extern struct value
*eval_op_lognot (struct type
*expect_type
,
152 struct expression
*exp
,
156 extern struct value
*eval_op_preinc (struct type
*expect_type
,
157 struct expression
*exp
,
161 extern struct value
*eval_op_predec (struct type
*expect_type
,
162 struct expression
*exp
,
166 extern struct value
*eval_op_postinc (struct type
*expect_type
,
167 struct expression
*exp
,
171 extern struct value
*eval_op_postdec (struct type
*expect_type
,
172 struct expression
*exp
,
176 extern struct value
*eval_op_ind (struct type
*expect_type
,
177 struct expression
*exp
,
180 extern struct value
*eval_op_type (struct type
*expect_type
,
181 struct expression
*exp
,
182 enum noside noside
, struct type
*type
);
183 extern struct value
*eval_op_alignof (struct type
*expect_type
,
184 struct expression
*exp
,
187 extern struct value
*eval_op_memval (struct type
*expect_type
,
188 struct expression
*exp
,
190 struct value
*arg1
, struct type
*type
);
191 extern struct value
*eval_binop_assign_modify (struct type
*expect_type
,
192 struct expression
*exp
,
203 /* The check_objfile overloads are used to check whether a particular
204 component of some operation references an objfile. The passed-in
205 objfile will never be a debug objfile. */
207 /* See if EXP_OBJFILE matches OBJFILE. */
209 check_objfile (struct objfile
*exp_objfile
, struct objfile
*objfile
)
211 if (exp_objfile
->separate_debug_objfile_backlink
)
212 exp_objfile
= exp_objfile
->separate_debug_objfile_backlink
;
213 return exp_objfile
== objfile
;
217 check_objfile (struct type
*type
, struct objfile
*objfile
)
219 struct objfile
*ty_objfile
= type
->objfile_owner ();
220 if (ty_objfile
!= nullptr)
221 return check_objfile (ty_objfile
, objfile
);
226 check_objfile (struct symbol
*sym
, struct objfile
*objfile
)
228 return check_objfile (sym
->objfile (), objfile
);
231 extern bool check_objfile (const struct block
*block
,
232 struct objfile
*objfile
);
235 check_objfile (const block_symbol
&sym
, struct objfile
*objfile
)
237 return (check_objfile (sym
.symbol
, objfile
)
238 || check_objfile (sym
.block
, objfile
));
242 check_objfile (bound_minimal_symbol minsym
, struct objfile
*objfile
)
244 return check_objfile (minsym
.objfile
, objfile
);
248 check_objfile (internalvar
*ivar
, struct objfile
*objfile
)
254 check_objfile (const std::string
&str
, struct objfile
*objfile
)
260 check_objfile (const operation_up
&op
, struct objfile
*objfile
)
262 return op
->uses_objfile (objfile
);
266 check_objfile (enum exp_opcode val
, struct objfile
*objfile
)
272 check_objfile (ULONGEST val
, struct objfile
*objfile
)
278 check_objfile (const gdb_mpz
&val
, struct objfile
*objfile
)
285 check_objfile (enum_flags
<T
> val
, struct objfile
*objfile
)
292 check_objfile (const std::vector
<T
> &collection
, struct objfile
*objfile
)
294 for (const auto &item
: collection
)
296 if (check_objfile (item
, objfile
))
302 template<typename S
, typename T
>
304 check_objfile (const std::pair
<S
, T
> &item
, struct objfile
*objfile
)
306 return (check_objfile (item
.first
, objfile
)
307 || check_objfile (item
.second
, objfile
));
310 extern bool check_objfile (const std::unique_ptr
<ada_component
> &comp
,
311 struct objfile
*objfile
);
314 dump_for_expression (struct ui_file
*stream
, int depth
,
315 const operation_up
&op
)
318 gdb_printf (stream
, _("%*snullptr\n"), depth
, "");
320 op
->dump (stream
, depth
);
323 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
325 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
326 const std::string
&str
);
327 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
329 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
331 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
332 const gdb_mpz
&addr
);
333 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
335 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
337 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
338 const block_symbol
&sym
);
339 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
340 bound_minimal_symbol msym
);
341 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
343 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
344 type_instance_flags flags
);
345 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
346 enum c_string_type_values flags
);
347 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
348 enum range_flag flags
);
349 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
350 const std::unique_ptr
<ada_component
> &comp
);
354 dump_for_expression (struct ui_file
*stream
, int depth
,
355 const std::vector
<T
> &vals
)
357 gdb_printf (stream
, _("%*sVector:\n"), depth
, "");
358 for (auto &item
: vals
)
359 dump_for_expression (stream
, depth
+ 1, item
);
362 template<typename X
, typename Y
>
364 dump_for_expression (struct ui_file
*stream
, int depth
,
365 const std::pair
<X
, Y
> &vals
)
367 dump_for_expression (stream
, depth
, vals
.first
);
368 dump_for_expression (stream
, depth
, vals
.second
);
371 /* Base class for most concrete operations. This class holds data,
372 specified via template parameters, and supplies generic
373 implementations of the 'dump' and 'uses_objfile' methods. */
374 template<typename
... Arg
>
375 class tuple_holding_operation
: public operation
379 explicit tuple_holding_operation (Arg
... args
)
380 : m_storage (std::forward
<Arg
> (args
)...)
384 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation
);
386 bool uses_objfile (struct objfile
*objfile
) const override
388 return do_check_objfile
<0, Arg
...> (objfile
, m_storage
);
391 void dump (struct ui_file
*stream
, int depth
) const override
393 dump_for_expression (stream
, depth
, opcode ());
394 do_dump
<0, Arg
...> (stream
, depth
+ 1, m_storage
);
399 /* Storage for the data. */
400 std::tuple
<Arg
...> m_storage
;
404 /* do_dump does the work of dumping the data. */
405 template<int I
, typename
... T
>
406 typename
std::enable_if
<I
== sizeof... (T
), void>::type
407 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
412 template<int I
, typename
... T
>
413 typename
std::enable_if
<I
< sizeof... (T
), void>::type
414 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
417 dump_for_expression (stream
, depth
, std::get
<I
> (value
));
418 do_dump
<I
+ 1, T
...> (stream
, depth
, value
);
421 /* do_check_objfile does the work of checking whether this object
422 refers to OBJFILE. */
423 template<int I
, typename
... T
>
424 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
425 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
431 template<int I
, typename
... T
>
432 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
433 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
436 if (check_objfile (std::get
<I
> (value
), objfile
))
438 return do_check_objfile
<I
+ 1, T
...> (objfile
, value
);
442 /* The check_constant overloads are used to decide whether a given
443 concrete operation is a constant. This is done by checking the
447 check_constant (const operation_up
&item
)
449 return item
->constant_p ();
453 check_constant (bound_minimal_symbol msym
)
459 check_constant (struct type
*type
)
465 check_constant (const struct block
*block
)
471 check_constant (const std::string
&str
)
477 check_constant (ULONGEST cst
)
483 check_constant (const gdb_mpz
&cst
)
489 check_constant (struct symbol
*sym
)
491 enum address_class sc
= sym
->aclass ();
492 return (sc
== LOC_BLOCK
494 || sc
== LOC_CONST_BYTES
499 check_constant (const block_symbol
&sym
)
501 /* We know the block is constant, so we only need to check the
503 return check_constant (sym
.symbol
);
508 check_constant (const std::vector
<T
> &collection
)
510 for (const auto &item
: collection
)
511 if (!check_constant (item
))
516 template<typename S
, typename T
>
518 check_constant (const std::pair
<S
, T
> &item
)
520 return check_constant (item
.first
) && check_constant (item
.second
);
523 /* Base class for concrete operations. This class supplies an
524 implementation of 'constant_p' that works by checking the
526 template<typename
... Arg
>
527 class maybe_constant_operation
528 : public tuple_holding_operation
<Arg
...>
532 using tuple_holding_operation
<Arg
...>::tuple_holding_operation
;
534 bool constant_p () const override
536 return do_check_constant
<0, Arg
...> (this->m_storage
);
541 template<int I
, typename
... T
>
542 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
543 do_check_constant (const std::tuple
<T
...> &value
) const
548 template<int I
, typename
... T
>
549 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
550 do_check_constant (const std::tuple
<T
...> &value
) const
552 if (!check_constant (std::get
<I
> (value
)))
554 return do_check_constant
<I
+ 1, T
...> (value
);
558 /* A floating-point constant. The constant is encoded in the target
561 typedef std::array
<gdb_byte
, 16> float_data
;
563 /* An operation that holds a floating-point constant of a given
566 This does not need the facilities provided by
567 tuple_holding_operation, so it does not use it. */
568 class float_const_operation
573 float_const_operation (struct type
*type
, float_data data
)
579 value
*evaluate (struct type
*expect_type
,
580 struct expression
*exp
,
581 enum noside noside
) override
583 return value_from_contents (m_type
, m_data
.data ());
586 enum exp_opcode
opcode () const override
589 bool constant_p () const override
592 void dump (struct ui_file
*stream
, int depth
) const override
;
600 class scope_operation
601 : public maybe_constant_operation
<struct type
*, std::string
>
605 using maybe_constant_operation::maybe_constant_operation
;
607 value
*evaluate (struct type
*expect_type
,
608 struct expression
*exp
,
609 enum noside noside
) override
611 return eval_op_scope (expect_type
, exp
, noside
,
612 std::get
<0> (m_storage
),
613 std::get
<1> (m_storage
).c_str ());
616 value
*evaluate_for_address (struct expression
*exp
,
617 enum noside noside
) override
;
619 value
*evaluate_funcall (struct type
*expect_type
,
620 struct expression
*exp
,
622 const std::vector
<operation_up
> &args
) override
;
624 enum exp_opcode
opcode () const override
629 void do_generate_ax (struct expression
*exp
,
630 struct agent_expr
*ax
,
631 struct axs_value
*value
,
632 struct type
*cast_type
)
636 /* Compute the value of a variable. */
637 class var_value_operation
638 : public maybe_constant_operation
<block_symbol
>
642 using maybe_constant_operation::maybe_constant_operation
;
644 value
*evaluate (struct type
*expect_type
,
645 struct expression
*exp
,
646 enum noside noside
) override
;
648 value
*evaluate_with_coercion (struct expression
*exp
,
649 enum noside noside
) override
;
651 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
654 value
*evaluate_for_cast (struct type
*expect_type
,
655 struct expression
*exp
,
656 enum noside noside
) override
;
658 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
661 value
*evaluate_funcall (struct type
*expect_type
,
662 struct expression
*exp
,
664 const std::vector
<operation_up
> &args
) override
;
666 enum exp_opcode
opcode () const override
667 { return OP_VAR_VALUE
; }
669 /* Return the symbol referenced by this object. */
670 symbol
*get_symbol () const
672 return std::get
<0> (m_storage
).symbol
;
677 void do_generate_ax (struct expression
*exp
,
678 struct agent_expr
*ax
,
679 struct axs_value
*value
,
680 struct type
*cast_type
)
684 class long_const_operation
685 : public tuple_holding_operation
<struct type
*, gdb_mpz
>
689 using tuple_holding_operation::tuple_holding_operation
;
691 long_const_operation (struct type
*type
, LONGEST val
)
692 : long_const_operation (type
, gdb_mpz (val
))
695 value
*evaluate (struct type
*expect_type
,
696 struct expression
*exp
,
697 enum noside noside
) override
699 return value_from_mpz (std::get
<0> (m_storage
), std::get
<1> (m_storage
));
702 enum exp_opcode
opcode () const override
705 bool constant_p () const override
710 LONGEST
as_longest () const
711 { return std::get
<1> (m_storage
).as_integer_truncate
<LONGEST
> (); }
713 void do_generate_ax (struct expression
*exp
,
714 struct agent_expr
*ax
,
715 struct axs_value
*value
,
716 struct type
*cast_type
)
720 class var_msym_value_operation
721 : public maybe_constant_operation
<bound_minimal_symbol
>
725 using maybe_constant_operation::maybe_constant_operation
;
727 value
*evaluate (struct type
*expect_type
,
728 struct expression
*exp
,
729 enum noside noside
) override
731 return eval_op_var_msym_value (expect_type
, exp
, noside
, m_outermost
,
732 std::get
<0> (m_storage
));
735 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
738 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
741 value
*evaluate_for_cast (struct type
*expect_type
,
742 struct expression
*exp
,
743 enum noside noside
) override
;
745 value
*evaluate_funcall (struct type
*expect_type
,
746 struct expression
*exp
,
748 const std::vector
<operation_up
> &args
) override
750 const char *name
= std::get
<0> (m_storage
).minsym
->print_name ();
751 return operation::evaluate_funcall (expect_type
, exp
, noside
, name
, args
);
754 enum exp_opcode
opcode () const override
755 { return OP_VAR_MSYM_VALUE
; }
757 void set_outermost () override
764 /* True if this is the outermost operation in the expression. */
765 bool m_outermost
= false;
767 void do_generate_ax (struct expression
*exp
,
768 struct agent_expr
*ax
,
769 struct axs_value
*value
,
770 struct type
*cast_type
)
774 class var_entry_value_operation
775 : public tuple_holding_operation
<symbol
*>
779 using tuple_holding_operation::tuple_holding_operation
;
781 value
*evaluate (struct type
*expect_type
,
782 struct expression
*exp
,
783 enum noside noside
) override
785 return eval_op_var_entry_value (expect_type
, exp
, noside
,
786 std::get
<0> (m_storage
));
789 enum exp_opcode
opcode () const override
790 { return OP_VAR_ENTRY_VALUE
; }
793 class func_static_var_operation
794 : public maybe_constant_operation
<operation_up
, std::string
>
798 using maybe_constant_operation::maybe_constant_operation
;
800 value
*evaluate (struct type
*expect_type
,
801 struct expression
*exp
,
802 enum noside noside
) override
804 value
*func
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
805 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
806 std::get
<1> (m_storage
).c_str ());
809 enum exp_opcode
opcode () const override
810 { return OP_FUNC_STATIC_VAR
; }
814 : public tuple_holding_operation
<int>
818 using tuple_holding_operation::tuple_holding_operation
;
820 value
*evaluate (struct type
*expect_type
,
821 struct expression
*exp
,
822 enum noside noside
) override
824 return access_value_history (std::get
<0> (m_storage
));
827 enum exp_opcode
opcode () const override
831 class register_operation
832 : public tuple_holding_operation
<std::string
>
836 using tuple_holding_operation::tuple_holding_operation
;
838 value
*evaluate (struct type
*expect_type
,
839 struct expression
*exp
,
840 enum noside noside
) override
842 return eval_op_register (expect_type
, exp
, noside
,
843 std::get
<0> (m_storage
).c_str ());
846 enum exp_opcode
opcode () const override
847 { return OP_REGISTER
; }
849 /* Return the name of the register. */
850 const char *get_name () const
852 return std::get
<0> (m_storage
).c_str ();
857 void do_generate_ax (struct expression
*exp
,
858 struct agent_expr
*ax
,
859 struct axs_value
*value
,
860 struct type
*cast_type
)
865 : public tuple_holding_operation
<bool>
869 using tuple_holding_operation::tuple_holding_operation
;
871 value
*evaluate (struct type
*expect_type
,
872 struct expression
*exp
,
873 enum noside noside
) override
875 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
876 return value_from_longest (type
, std::get
<0> (m_storage
));
879 enum exp_opcode
opcode () const override
882 bool constant_p () const override
886 class internalvar_operation
887 : public tuple_holding_operation
<internalvar
*>
891 using tuple_holding_operation::tuple_holding_operation
;
893 value
*evaluate (struct type
*expect_type
,
894 struct expression
*exp
,
895 enum noside noside
) override
897 return value_of_internalvar (exp
->gdbarch
,
898 std::get
<0> (m_storage
));
901 internalvar
*get_internalvar () const
903 return std::get
<0> (m_storage
);
906 enum exp_opcode
opcode () const override
907 { return OP_INTERNALVAR
; }
911 void do_generate_ax (struct expression
*exp
,
912 struct agent_expr
*ax
,
913 struct axs_value
*value
,
914 struct type
*cast_type
)
918 class string_operation
919 : public tuple_holding_operation
<std::string
>
923 using tuple_holding_operation::tuple_holding_operation
;
925 value
*evaluate (struct type
*expect_type
,
926 struct expression
*exp
,
927 enum noside noside
) override
;
929 enum exp_opcode
opcode () const override
930 { return OP_STRING
; }
933 class ternop_slice_operation
934 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
938 using maybe_constant_operation::maybe_constant_operation
;
940 value
*evaluate (struct type
*expect_type
,
941 struct expression
*exp
,
942 enum noside noside
) override
945 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
947 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
949 = std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
950 return eval_op_ternop (expect_type
, exp
, noside
, array
, low
, upper
);
953 enum exp_opcode
opcode () const override
954 { return TERNOP_SLICE
; }
957 class ternop_cond_operation
958 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
962 using maybe_constant_operation::maybe_constant_operation
;
964 value
*evaluate (struct type
*expect_type
,
965 struct expression
*exp
,
966 enum noside noside
) override
969 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
971 if (value_logical_not (val
))
972 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
973 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
976 enum exp_opcode
opcode () const override
977 { return TERNOP_COND
; }
981 void do_generate_ax (struct expression
*exp
,
982 struct agent_expr
*ax
,
983 struct axs_value
*value
,
984 struct type
*cast_type
)
988 class complex_operation
989 : public maybe_constant_operation
<operation_up
, operation_up
, struct type
*>
993 using maybe_constant_operation::maybe_constant_operation
;
995 value
*evaluate (struct type
*expect_type
,
996 struct expression
*exp
,
997 enum noside noside
) override
999 value
*real
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1000 value
*imag
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1001 return value_literal_complex (real
, imag
,
1002 std::get
<2> (m_storage
));
1005 enum exp_opcode
opcode () const override
1006 { return OP_COMPLEX
; }
1009 class structop_base_operation
1010 : public tuple_holding_operation
<operation_up
, std::string
>
1014 /* Used for completion. Return the field name. */
1015 const std::string
&get_string () const
1017 return std::get
<1> (m_storage
);
1020 value
*evaluate_funcall (struct type
*expect_type
,
1021 struct expression
*exp
,
1023 const std::vector
<operation_up
> &args
) override
;
1025 /* Try to complete this operation in the context of EXP. TRACKER is
1026 the completion tracker to update. Return true if completion was
1027 possible, false otherwise. */
1028 virtual bool complete (struct expression
*exp
, completion_tracker
&tracker
)
1030 return complete (exp
, tracker
, "");
1035 /* Do the work of the public 'complete' method. PREFIX is prepended
1037 bool complete (struct expression
*exp
, completion_tracker
&tracker
,
1038 const char *prefix
);
1040 using tuple_holding_operation::tuple_holding_operation
;
1043 class structop_operation
1044 : public structop_base_operation
1048 using structop_base_operation::structop_base_operation
;
1050 value
*evaluate (struct type
*expect_type
,
1051 struct expression
*exp
,
1052 enum noside noside
) override
1054 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1055 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
1056 std::get
<1> (m_storage
).c_str ());
1059 enum exp_opcode
opcode () const override
1060 { return STRUCTOP_STRUCT
; }
1064 void do_generate_ax (struct expression
*exp
,
1065 struct agent_expr
*ax
,
1066 struct axs_value
*value
,
1067 struct type
*cast_type
)
1070 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
1071 std::get
<0> (this->m_storage
).get (),
1072 std::get
<1> (this->m_storage
).c_str (),
1077 class structop_ptr_operation
1078 : public structop_base_operation
1082 using structop_base_operation::structop_base_operation
;
1084 value
*evaluate (struct type
*expect_type
,
1085 struct expression
*exp
,
1086 enum noside noside
) override
1088 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1089 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
1090 std::get
<1> (m_storage
).c_str ());
1093 enum exp_opcode
opcode () const override
1094 { return STRUCTOP_PTR
; }
1098 void do_generate_ax (struct expression
*exp
,
1099 struct agent_expr
*ax
,
1100 struct axs_value
*value
,
1101 struct type
*cast_type
)
1104 gen_expr_structop (exp
, STRUCTOP_PTR
,
1105 std::get
<0> (this->m_storage
).get (),
1106 std::get
<1> (this->m_storage
).c_str (),
1111 class structop_member_base
1112 : public tuple_holding_operation
<operation_up
, operation_up
>
1116 using tuple_holding_operation::tuple_holding_operation
;
1118 value
*evaluate_funcall (struct type
*expect_type
,
1119 struct expression
*exp
,
1121 const std::vector
<operation_up
> &args
) override
;
1124 class structop_member_operation
1125 : public structop_member_base
1129 using structop_member_base::structop_member_base
;
1131 value
*evaluate (struct type
*expect_type
,
1132 struct expression
*exp
,
1133 enum noside noside
) override
1136 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1138 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1139 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1142 enum exp_opcode
opcode () const override
1143 { return STRUCTOP_MEMBER
; }
1146 class structop_mptr_operation
1147 : public structop_member_base
1151 using structop_member_base::structop_member_base
;
1153 value
*evaluate (struct type
*expect_type
,
1154 struct expression
*exp
,
1155 enum noside noside
) override
1158 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1160 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1161 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1164 enum exp_opcode
opcode () const override
1165 { return STRUCTOP_MPTR
; }
1168 class concat_operation
1169 : public maybe_constant_operation
<operation_up
, operation_up
>
1173 using maybe_constant_operation::maybe_constant_operation
;
1175 value
*evaluate (struct type
*expect_type
,
1176 struct expression
*exp
,
1177 enum noside noside
) override
1180 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1182 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1183 return value_concat (lhs
, rhs
);
1186 enum exp_opcode
opcode () const override
1187 { return BINOP_CONCAT
; }
1191 : public maybe_constant_operation
<operation_up
, operation_up
>
1195 using maybe_constant_operation::maybe_constant_operation
;
1197 value
*evaluate (struct type
*expect_type
,
1198 struct expression
*exp
,
1199 enum noside noside
) override
1202 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1204 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1205 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1208 enum exp_opcode
opcode () const override
1209 { return BINOP_ADD
; }
1213 void do_generate_ax (struct expression
*exp
,
1214 struct agent_expr
*ax
,
1215 struct axs_value
*value
,
1216 struct type
*cast_type
)
1219 gen_expr_binop (exp
, BINOP_ADD
,
1220 std::get
<0> (this->m_storage
).get (),
1221 std::get
<1> (this->m_storage
).get (),
1227 : public maybe_constant_operation
<operation_up
, operation_up
>
1231 using maybe_constant_operation::maybe_constant_operation
;
1233 value
*evaluate (struct type
*expect_type
,
1234 struct expression
*exp
,
1235 enum noside noside
) override
1238 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1240 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1241 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1244 enum exp_opcode
opcode () const override
1245 { return BINOP_SUB
; }
1249 void do_generate_ax (struct expression
*exp
,
1250 struct agent_expr
*ax
,
1251 struct axs_value
*value
,
1252 struct type
*cast_type
)
1255 gen_expr_binop (exp
, BINOP_SUB
,
1256 std::get
<0> (this->m_storage
).get (),
1257 std::get
<1> (this->m_storage
).get (),
1262 typedef struct value
*binary_ftype (struct type
*expect_type
,
1263 struct expression
*exp
,
1264 enum noside noside
, enum exp_opcode op
,
1265 struct value
*arg1
, struct value
*arg2
);
1267 template<enum exp_opcode OP
, binary_ftype FUNC
>
1268 class binop_operation
1269 : public maybe_constant_operation
<operation_up
, operation_up
>
1273 using maybe_constant_operation::maybe_constant_operation
;
1275 value
*evaluate (struct type
*expect_type
,
1276 struct expression
*exp
,
1277 enum noside noside
) override
1280 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1282 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1283 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1286 enum exp_opcode
opcode () const override
1290 template<enum exp_opcode OP
, binary_ftype FUNC
>
1291 class usual_ax_binop_operation
1292 : public binop_operation
<OP
, FUNC
>
1296 using binop_operation
<OP
, FUNC
>::binop_operation
;
1300 void do_generate_ax (struct expression
*exp
,
1301 struct agent_expr
*ax
,
1302 struct axs_value
*value
,
1303 struct type
*cast_type
)
1306 gen_expr_binop (exp
, OP
,
1307 std::get
<0> (this->m_storage
).get (),
1308 std::get
<1> (this->m_storage
).get (),
1313 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1314 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1315 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1317 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1318 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1319 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1320 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1321 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1322 using bitwise_and_operation
1323 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1324 using bitwise_ior_operation
1325 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1326 using bitwise_xor_operation
1327 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1329 class subscript_operation
1330 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1333 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1334 eval_op_subscript
>::usual_ax_binop_operation
;
1336 value
*evaluate_for_sizeof (struct expression
*exp
,
1337 enum noside noside
) override
;
1340 /* Implementation of comparison operations. */
1341 template<enum exp_opcode OP
, binary_ftype FUNC
>
1342 class comparison_operation
1343 : public usual_ax_binop_operation
<OP
, FUNC
>
1347 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1349 value
*evaluate (struct type
*expect_type
,
1350 struct expression
*exp
,
1351 enum noside noside
) override
1354 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1356 = std::get
<1> (this->m_storage
)->evaluate (lhs
->type (), exp
,
1358 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1362 class equal_operation
1363 : public comparison_operation
<BINOP_EQUAL
, eval_op_equal
>
1367 using comparison_operation::comparison_operation
;
1369 operation
*get_lhs () const
1371 return std::get
<0> (m_storage
).get ();
1374 operation
*get_rhs () const
1376 return std::get
<1> (m_storage
).get ();
1380 using notequal_operation
1381 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1382 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1383 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1384 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1385 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1387 /* Implement the GDB '@' repeat operator. */
1388 class repeat_operation
1389 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1391 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1395 void do_generate_ax (struct expression
*exp
,
1396 struct agent_expr
*ax
,
1397 struct axs_value
*value
,
1398 struct type
*cast_type
)
1402 /* C-style comma operator. */
1403 class comma_operation
1404 : public maybe_constant_operation
<operation_up
, operation_up
>
1408 using maybe_constant_operation::maybe_constant_operation
;
1410 value
*evaluate (struct type
*expect_type
,
1411 struct expression
*exp
,
1412 enum noside noside
) override
1414 /* The left-hand-side is only evaluated for side effects, so don't
1415 bother in other modes. */
1416 if (noside
== EVAL_NORMAL
)
1417 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1418 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1421 enum exp_opcode
opcode () const override
1422 { return BINOP_COMMA
; }
1426 void do_generate_ax (struct expression
*exp
,
1427 struct agent_expr
*ax
,
1428 struct axs_value
*value
,
1429 struct type
*cast_type
)
1433 typedef struct value
*unary_ftype (struct type
*expect_type
,
1434 struct expression
*exp
,
1435 enum noside noside
, enum exp_opcode op
,
1436 struct value
*arg1
);
1438 /* Base class for unary operations. */
1439 template<enum exp_opcode OP
, unary_ftype FUNC
>
1440 class unop_operation
1441 : public maybe_constant_operation
<operation_up
>
1445 using maybe_constant_operation::maybe_constant_operation
;
1447 value
*evaluate (struct type
*expect_type
,
1448 struct expression
*exp
,
1449 enum noside noside
) override
1451 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1452 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1455 enum exp_opcode
opcode () const override
1459 /* Unary operations that can also be turned into agent expressions in
1461 template<enum exp_opcode OP
, unary_ftype FUNC
>
1462 class usual_ax_unop_operation
1463 : public unop_operation
<OP
, FUNC
>
1465 using unop_operation
<OP
, FUNC
>::unop_operation
;
1469 void do_generate_ax (struct expression
*exp
,
1470 struct agent_expr
*ax
,
1471 struct axs_value
*value
,
1472 struct type
*cast_type
)
1475 gen_expr_unop (exp
, OP
,
1476 std::get
<0> (this->m_storage
).get (),
1481 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1482 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1483 using unary_complement_operation
1484 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1485 using unary_logical_not_operation
1486 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1488 /* Handle pre- and post- increment and -decrement. */
1489 template<enum exp_opcode OP
, unary_ftype FUNC
>
1490 class unop_incr_operation
1491 : public tuple_holding_operation
<operation_up
>
1495 using tuple_holding_operation::tuple_holding_operation
;
1497 value
*evaluate (struct type
*expect_type
,
1498 struct expression
*exp
,
1499 enum noside noside
) override
1501 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1502 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1505 enum exp_opcode
opcode () const override
1509 using preinc_operation
1510 = unop_incr_operation
<UNOP_PREINCREMENT
, eval_op_preinc
>;
1511 using predec_operation
1512 = unop_incr_operation
<UNOP_PREDECREMENT
, eval_op_predec
>;
1513 using postinc_operation
1514 = unop_incr_operation
<UNOP_POSTINCREMENT
, eval_op_postinc
>;
1515 using postdec_operation
1516 = unop_incr_operation
<UNOP_POSTDECREMENT
, eval_op_postdec
>;
1518 /* Base class for implementations of UNOP_IND. */
1519 class unop_ind_base_operation
1520 : public tuple_holding_operation
<operation_up
>
1524 using tuple_holding_operation::tuple_holding_operation
;
1526 value
*evaluate (struct type
*expect_type
,
1527 struct expression
*exp
,
1528 enum noside noside
) override
1530 if (expect_type
!= nullptr && expect_type
->code () == TYPE_CODE_PTR
)
1531 expect_type
= check_typedef (expect_type
)->target_type ();
1532 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1533 return eval_op_ind (expect_type
, exp
, noside
, val
);
1536 value
*evaluate_for_address (struct expression
*exp
,
1537 enum noside noside
) override
;
1539 value
*evaluate_for_sizeof (struct expression
*exp
,
1540 enum noside noside
) override
;
1542 enum exp_opcode
opcode () const override
1543 { return UNOP_IND
; }
1546 /* Ordinary UNOP_IND implementation. */
1547 class unop_ind_operation
1548 : public unop_ind_base_operation
1552 using unop_ind_base_operation::unop_ind_base_operation
;
1556 void do_generate_ax (struct expression
*exp
,
1557 struct agent_expr
*ax
,
1558 struct axs_value
*value
,
1559 struct type
*cast_type
)
1562 gen_expr_unop (exp
, UNOP_IND
,
1563 std::get
<0> (this->m_storage
).get (),
1568 /* Implement OP_TYPE. */
1569 class type_operation
1570 : public tuple_holding_operation
<struct type
*>
1574 using tuple_holding_operation::tuple_holding_operation
;
1576 value
*evaluate (struct type
*expect_type
,
1577 struct expression
*exp
,
1578 enum noside noside
) override
1580 return eval_op_type (expect_type
, exp
, noside
, std::get
<0> (m_storage
));
1583 enum exp_opcode
opcode () const override
1586 bool constant_p () const override
1590 /* Implement the "typeof" operation. */
1591 class typeof_operation
1592 : public maybe_constant_operation
<operation_up
>
1596 using maybe_constant_operation::maybe_constant_operation
;
1598 value
*evaluate (struct type
*expect_type
,
1599 struct expression
*exp
,
1600 enum noside noside
) override
1602 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1603 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1604 EVAL_AVOID_SIDE_EFFECTS
);
1606 error (_("Attempt to use a type as an expression"));
1609 enum exp_opcode
opcode () const override
1610 { return OP_TYPEOF
; }
1613 /* Implement 'decltype'. */
1614 class decltype_operation
1615 : public maybe_constant_operation
<operation_up
>
1619 using maybe_constant_operation::maybe_constant_operation
;
1621 value
*evaluate (struct type
*expect_type
,
1622 struct expression
*exp
,
1623 enum noside noside
) override
1625 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1628 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1629 EVAL_AVOID_SIDE_EFFECTS
);
1630 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1631 if (sub_op
== BINOP_SUBSCRIPT
1632 || sub_op
== STRUCTOP_MEMBER
1633 || sub_op
== STRUCTOP_MPTR
1634 || sub_op
== UNOP_IND
1635 || sub_op
== STRUCTOP_STRUCT
1636 || sub_op
== STRUCTOP_PTR
1637 || sub_op
== OP_SCOPE
)
1639 struct type
*type
= result
->type ();
1641 if (!TYPE_IS_REFERENCE (type
))
1643 type
= lookup_lvalue_reference_type (type
);
1644 result
= value::allocate (type
);
1651 error (_("Attempt to use a type as an expression"));
1654 enum exp_opcode
opcode () const override
1655 { return OP_DECLTYPE
; }
1658 /* Implement 'typeid'. */
1659 class typeid_operation
1660 : public tuple_holding_operation
<operation_up
>
1664 using tuple_holding_operation::tuple_holding_operation
;
1666 value
*evaluate (struct type
*expect_type
,
1667 struct expression
*exp
,
1668 enum noside noside
) override
1670 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1671 enum noside sub_noside
1672 = ((sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
1673 ? EVAL_AVOID_SIDE_EFFECTS
1676 value
*result
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1678 if (noside
!= EVAL_NORMAL
)
1679 return value::allocate (cplus_typeid_type (exp
->gdbarch
));
1680 return cplus_typeid (result
);
1683 enum exp_opcode
opcode () const override
1684 { return OP_TYPEID
; }
1687 /* Implement the address-of operation. */
1688 class unop_addr_operation
1689 : public maybe_constant_operation
<operation_up
>
1693 using maybe_constant_operation::maybe_constant_operation
;
1695 value
*evaluate (struct type
*expect_type
,
1696 struct expression
*exp
,
1697 enum noside noside
) override
1699 /* C++: check for and handle pointer to members. */
1700 return std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1703 enum exp_opcode
opcode () const override
1704 { return UNOP_ADDR
; }
1706 /* Return the subexpression. */
1707 const operation_up
&get_expression () const
1709 return std::get
<0> (m_storage
);
1714 void do_generate_ax (struct expression
*exp
,
1715 struct agent_expr
*ax
,
1716 struct axs_value
*value
,
1717 struct type
*cast_type
)
1720 gen_expr_unop (exp
, UNOP_ADDR
,
1721 std::get
<0> (this->m_storage
).get (),
1726 /* Implement 'sizeof'. */
1727 class unop_sizeof_operation
1728 : public maybe_constant_operation
<operation_up
>
1732 using maybe_constant_operation::maybe_constant_operation
;
1734 value
*evaluate (struct type
*expect_type
,
1735 struct expression
*exp
,
1736 enum noside noside
) override
1738 return std::get
<0> (m_storage
)->evaluate_for_sizeof (exp
, noside
);
1741 enum exp_opcode
opcode () const override
1742 { return UNOP_SIZEOF
; }
1746 void do_generate_ax (struct expression
*exp
,
1747 struct agent_expr
*ax
,
1748 struct axs_value
*value
,
1749 struct type
*cast_type
)
1753 /* Implement 'alignof'. */
1754 class unop_alignof_operation
1755 : public maybe_constant_operation
<operation_up
>
1759 using maybe_constant_operation::maybe_constant_operation
;
1761 value
*evaluate (struct type
*expect_type
,
1762 struct expression
*exp
,
1763 enum noside noside
) override
1765 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1766 EVAL_AVOID_SIDE_EFFECTS
);
1767 return eval_op_alignof (expect_type
, exp
, noside
, val
);
1770 enum exp_opcode
opcode () const override
1771 { return UNOP_ALIGNOF
; }
1774 /* Implement UNOP_MEMVAL. */
1775 class unop_memval_operation
1776 : public tuple_holding_operation
<operation_up
, struct type
*>
1780 using tuple_holding_operation::tuple_holding_operation
;
1782 value
*evaluate (struct type
*expect_type
,
1783 struct expression
*exp
,
1784 enum noside noside
) override
1786 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1787 return eval_op_memval (expect_type
, exp
, noside
, val
,
1788 std::get
<1> (m_storage
));
1791 value
*evaluate_for_sizeof (struct expression
*exp
,
1792 enum noside noside
) override
;
1794 value
*evaluate_for_address (struct expression
*exp
,
1795 enum noside noside
) override
;
1797 enum exp_opcode
opcode () const override
1798 { return UNOP_MEMVAL
; }
1800 /* Return the type referenced by this object. */
1801 struct type
*get_type () const
1803 return std::get
<1> (m_storage
);
1808 void do_generate_ax (struct expression
*exp
,
1809 struct agent_expr
*ax
,
1810 struct axs_value
*value
,
1811 struct type
*cast_type
)
1815 /* Implement UNOP_MEMVAL_TYPE. */
1816 class unop_memval_type_operation
1817 : public tuple_holding_operation
<operation_up
, operation_up
>
1821 using tuple_holding_operation::tuple_holding_operation
;
1823 value
*evaluate (struct type
*expect_type
,
1824 struct expression
*exp
,
1825 enum noside noside
) override
1828 = std::get
<0> (m_storage
)->evaluate (expect_type
, exp
,
1829 EVAL_AVOID_SIDE_EFFECTS
);
1830 struct type
*type
= typeval
->type ();
1831 value
*val
= std::get
<1> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1832 return eval_op_memval (expect_type
, exp
, noside
, val
, type
);
1835 value
*evaluate_for_sizeof (struct expression
*exp
,
1836 enum noside noside
) override
;
1838 value
*evaluate_for_address (struct expression
*exp
,
1839 enum noside noside
) override
;
1841 enum exp_opcode
opcode () const override
1842 { return UNOP_MEMVAL_TYPE
; }
1846 void do_generate_ax (struct expression
*exp
,
1847 struct agent_expr
*ax
,
1848 struct axs_value
*value
,
1849 struct type
*cast_type
)
1853 /* Implement the 'this' expression. */
1854 class op_this_operation
1855 : public tuple_holding_operation
<>
1859 using tuple_holding_operation::tuple_holding_operation
;
1861 value
*evaluate (struct type
*expect_type
,
1862 struct expression
*exp
,
1863 enum noside noside
) override
1865 return value_of_this (exp
->language_defn
);
1868 enum exp_opcode
opcode () const override
1873 void do_generate_ax (struct expression
*exp
,
1874 struct agent_expr
*ax
,
1875 struct axs_value
*value
,
1876 struct type
*cast_type
)
1880 /* Implement the "type instance" operation. */
1881 class type_instance_operation
1882 : public tuple_holding_operation
<type_instance_flags
, std::vector
<type
*>,
1887 using tuple_holding_operation::tuple_holding_operation
;
1889 value
*evaluate (struct type
*expect_type
,
1890 struct expression
*exp
,
1891 enum noside noside
) override
;
1893 enum exp_opcode
opcode () const override
1894 { return TYPE_INSTANCE
; }
1897 /* The assignment operator. */
1898 class assign_operation
1899 : public tuple_holding_operation
<operation_up
, operation_up
>
1903 using tuple_holding_operation::tuple_holding_operation
;
1905 value
*evaluate (struct type
*expect_type
,
1906 struct expression
*exp
,
1907 enum noside noside
) override
1909 value
*lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1910 /* Special-case assignments where the left-hand-side is a
1911 convenience variable -- in these, don't bother setting an
1912 expected type. This avoids a weird case where re-assigning a
1913 string or array to an internal variable could error with "Too
1914 many array elements". */
1915 struct type
*xtype
= (lhs
->lval () == lval_internalvar
1918 value
*rhs
= std::get
<1> (m_storage
)->evaluate (xtype
, exp
, noside
);
1920 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1922 if (binop_user_defined_p (BINOP_ASSIGN
, lhs
, rhs
))
1923 return value_x_binop (lhs
, rhs
, BINOP_ASSIGN
, OP_NULL
, noside
);
1925 return value_assign (lhs
, rhs
);
1928 enum exp_opcode
opcode () const override
1929 { return BINOP_ASSIGN
; }
1931 /* Return the left-hand-side of the assignment. */
1932 operation
*get_lhs () const
1934 return std::get
<0> (m_storage
).get ();
1939 void do_generate_ax (struct expression
*exp
,
1940 struct agent_expr
*ax
,
1941 struct axs_value
*value
,
1942 struct type
*cast_type
)
1946 /* Assignment with modification, like "+=". */
1947 class assign_modify_operation
1948 : public tuple_holding_operation
<exp_opcode
, operation_up
, operation_up
>
1952 using tuple_holding_operation::tuple_holding_operation
;
1954 value
*evaluate (struct type
*expect_type
,
1955 struct expression
*exp
,
1956 enum noside noside
) override
1958 value
*lhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1959 value
*rhs
= std::get
<2> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1960 return eval_binop_assign_modify (expect_type
, exp
, noside
,
1961 std::get
<0> (m_storage
), lhs
, rhs
);
1964 enum exp_opcode
opcode () const override
1965 { return BINOP_ASSIGN_MODIFY
; }
1969 void do_generate_ax (struct expression
*exp
,
1970 struct agent_expr
*ax
,
1971 struct axs_value
*value
,
1972 struct type
*cast_type
)
1976 /* Not a cast! Extract a value of a given type from the contents of a
1977 value. The new value is extracted from the least significant bytes
1978 of the old value. The new value's type must be no bigger than the
1980 class unop_extract_operation
1981 : public maybe_constant_operation
<operation_up
, struct type
*>
1985 using maybe_constant_operation::maybe_constant_operation
;
1987 value
*evaluate (struct type
*expect_type
, struct expression
*exp
,
1988 enum noside noside
) override
;
1990 enum exp_opcode
opcode () const override
1991 { return UNOP_EXTRACT
; }
1993 /* Return the type referenced by this object. */
1994 struct type
*get_type () const
1996 return std::get
<1> (m_storage
);
2001 void do_generate_ax (struct expression
*exp
,
2002 struct agent_expr
*ax
,
2003 struct axs_value
*value
,
2004 struct type
*cast_type
) override
;
2008 class unop_cast_operation
2009 : public maybe_constant_operation
<operation_up
, struct type
*>
2013 using maybe_constant_operation::maybe_constant_operation
;
2015 value
*evaluate (struct type
*expect_type
,
2016 struct expression
*exp
,
2017 enum noside noside
) override
2019 return std::get
<0> (m_storage
)->evaluate_for_cast (std::get
<1> (m_storage
),
2023 enum exp_opcode
opcode () const override
2024 { return UNOP_CAST
; }
2026 /* Return the type referenced by this object. */
2027 struct type
*get_type () const
2029 return std::get
<1> (m_storage
);
2034 void do_generate_ax (struct expression
*exp
,
2035 struct agent_expr
*ax
,
2036 struct axs_value
*value
,
2037 struct type
*cast_type
)
2041 /* A cast, but the type comes from an expression, not a "struct
2043 class unop_cast_type_operation
2044 : public maybe_constant_operation
<operation_up
, operation_up
>
2048 using maybe_constant_operation::maybe_constant_operation
;
2050 value
*evaluate (struct type
*expect_type
,
2051 struct expression
*exp
,
2052 enum noside noside
) override
2054 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2055 EVAL_AVOID_SIDE_EFFECTS
);
2056 return std::get
<1> (m_storage
)->evaluate_for_cast (val
->type (),
2060 enum exp_opcode
opcode () const override
2061 { return UNOP_CAST_TYPE
; }
2065 void do_generate_ax (struct expression
*exp
,
2066 struct agent_expr
*ax
,
2067 struct axs_value
*value
,
2068 struct type
*cast_type
)
2072 typedef value
*cxx_cast_ftype (struct type
*, value
*);
2074 /* This implements dynamic_cast and reinterpret_cast. static_cast and
2075 const_cast are handled by the ordinary case operations. */
2076 template<exp_opcode OP
, cxx_cast_ftype FUNC
>
2077 class cxx_cast_operation
2078 : public maybe_constant_operation
<operation_up
, operation_up
>
2082 using maybe_constant_operation::maybe_constant_operation
;
2084 value
*evaluate (struct type
*expect_type
,
2085 struct expression
*exp
,
2086 enum noside noside
) override
2088 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2089 EVAL_AVOID_SIDE_EFFECTS
);
2090 struct type
*type
= val
->type ();
2091 value
*rhs
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
2092 return FUNC (type
, rhs
);
2095 enum exp_opcode
opcode () const override
2099 using dynamic_cast_operation
= cxx_cast_operation
<UNOP_DYNAMIC_CAST
,
2100 value_dynamic_cast
>;
2101 using reinterpret_cast_operation
= cxx_cast_operation
<UNOP_REINTERPRET_CAST
,
2102 value_reinterpret_cast
>;
2104 /* Multi-dimensional subscripting. */
2105 class multi_subscript_operation
2106 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2110 using tuple_holding_operation::tuple_holding_operation
;
2112 value
*evaluate (struct type
*expect_type
,
2113 struct expression
*exp
,
2114 enum noside noside
) override
;
2116 enum exp_opcode
opcode () const override
2117 { return MULTI_SUBSCRIPT
; }
2120 /* The "&&" operator. */
2121 class logical_and_operation
2122 : public maybe_constant_operation
<operation_up
, operation_up
>
2126 using maybe_constant_operation::maybe_constant_operation
;
2128 value
*evaluate (struct type
*expect_type
,
2129 struct expression
*exp
,
2130 enum noside noside
) override
;
2132 enum exp_opcode
opcode () const override
2133 { return BINOP_LOGICAL_AND
; }
2137 void do_generate_ax (struct expression
*exp
,
2138 struct agent_expr
*ax
,
2139 struct axs_value
*value
,
2140 struct type
*cast_type
)
2144 /* The "||" operator. */
2145 class logical_or_operation
2146 : public maybe_constant_operation
<operation_up
, operation_up
>
2150 using maybe_constant_operation::maybe_constant_operation
;
2152 value
*evaluate (struct type
*expect_type
,
2153 struct expression
*exp
,
2154 enum noside noside
) override
;
2156 enum exp_opcode
opcode () const override
2157 { return BINOP_LOGICAL_OR
; }
2161 void do_generate_ax (struct expression
*exp
,
2162 struct agent_expr
*ax
,
2163 struct axs_value
*value
,
2164 struct type
*cast_type
)
2168 /* This class implements ADL (aka Koenig) function calls for C++. It
2169 holds the name of the function to call, the block in which the
2170 lookup should be done, and a vector of arguments. */
2171 class adl_func_operation
2172 : public tuple_holding_operation
<std::string
, const block
*,
2173 std::vector
<operation_up
>>
2177 using tuple_holding_operation::tuple_holding_operation
;
2179 value
*evaluate (struct type
*expect_type
,
2180 struct expression
*exp
,
2181 enum noside noside
) override
;
2183 enum exp_opcode
opcode () const override
2184 { return OP_ADL_FUNC
; }
2187 /* The OP_ARRAY operation. */
2188 class array_operation
2189 : public tuple_holding_operation
<int, int, std::vector
<operation_up
>>
2193 using tuple_holding_operation::tuple_holding_operation
;
2195 value
*evaluate (struct type
*expect_type
,
2196 struct expression
*exp
,
2197 enum noside noside
) override
;
2199 enum exp_opcode
opcode () const override
2200 { return OP_ARRAY
; }
2204 struct value
*evaluate_struct_tuple (struct value
*struct_val
,
2205 struct expression
*exp
,
2206 enum noside noside
, int nargs
);
2209 /* A function call. This holds the callee operation and the
2211 class funcall_operation
2212 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2216 using tuple_holding_operation::tuple_holding_operation
;
2218 value
*evaluate (struct type
*expect_type
,
2219 struct expression
*exp
,
2220 enum noside noside
) override
2222 return std::get
<0> (m_storage
)->evaluate_funcall (expect_type
, exp
, noside
,
2223 std::get
<1> (m_storage
));
2226 enum exp_opcode
opcode () const override
2227 { return OP_FUNCALL
; }
2230 } /* namespace expr */
2232 #endif /* EXPOP_H */