1 /* Definitions for expressions in GDB
3 Copyright (C) 2020-2022 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/>. */
26 #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 (symbol_objfile (sym
), objfile
);
232 check_objfile (const struct block
*block
, struct objfile
*objfile
)
234 return check_objfile (block_objfile (block
), objfile
);
238 check_objfile (const block_symbol
&sym
, struct objfile
*objfile
)
240 return (check_objfile (sym
.symbol
, objfile
)
241 || check_objfile (sym
.block
, objfile
));
245 check_objfile (bound_minimal_symbol minsym
, struct objfile
*objfile
)
247 return check_objfile (minsym
.objfile
, objfile
);
251 check_objfile (internalvar
*ivar
, struct objfile
*objfile
)
257 check_objfile (const std::string
&str
, struct objfile
*objfile
)
263 check_objfile (const operation_up
&op
, struct objfile
*objfile
)
265 return op
->uses_objfile (objfile
);
269 check_objfile (enum exp_opcode val
, struct objfile
*objfile
)
275 check_objfile (ULONGEST val
, struct objfile
*objfile
)
282 check_objfile (enum_flags
<T
> val
, struct objfile
*objfile
)
289 check_objfile (const std::vector
<T
> &collection
, struct objfile
*objfile
)
291 for (const auto &item
: collection
)
293 if (check_objfile (item
, objfile
))
299 template<typename S
, typename T
>
301 check_objfile (const std::pair
<S
, T
> &item
, struct objfile
*objfile
)
303 return (check_objfile (item
.first
, objfile
)
304 || check_objfile (item
.second
, objfile
));
307 extern bool check_objfile (const std::unique_ptr
<ada_component
> &comp
,
308 struct objfile
*objfile
);
311 dump_for_expression (struct ui_file
*stream
, int depth
,
312 const operation_up
&op
)
314 op
->dump (stream
, depth
);
317 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
319 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
320 const std::string
&str
);
321 extern void dump_for_expression (struct ui_file
*stream
, int 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
,
327 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
329 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
330 const block_symbol
&sym
);
331 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
332 bound_minimal_symbol msym
);
333 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
335 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
336 type_instance_flags flags
);
337 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
338 enum c_string_type_values flags
);
339 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
340 enum range_flag flags
);
341 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
342 const std::unique_ptr
<ada_component
> &comp
);
346 dump_for_expression (struct ui_file
*stream
, int depth
,
347 const std::vector
<T
> &vals
)
349 gdb_printf (stream
, _("%*sVector:\n"), depth
, "");
350 for (auto &item
: vals
)
351 dump_for_expression (stream
, depth
+ 1, item
);
354 template<typename X
, typename Y
>
356 dump_for_expression (struct ui_file
*stream
, int depth
,
357 const std::pair
<X
, Y
> &vals
)
359 dump_for_expression (stream
, depth
, vals
.first
);
360 dump_for_expression (stream
, depth
, vals
.second
);
363 /* Base class for most concrete operations. This class holds data,
364 specified via template parameters, and supplies generic
365 implementations of the 'dump' and 'uses_objfile' methods. */
366 template<typename
... Arg
>
367 class tuple_holding_operation
: public operation
371 explicit tuple_holding_operation (Arg
... args
)
372 : m_storage (std::forward
<Arg
> (args
)...)
376 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation
);
378 bool uses_objfile (struct objfile
*objfile
) const override
380 return do_check_objfile
<0, Arg
...> (objfile
, m_storage
);
383 void dump (struct ui_file
*stream
, int depth
) const override
385 dump_for_expression (stream
, depth
, opcode ());
386 do_dump
<0, Arg
...> (stream
, depth
+ 1, m_storage
);
391 /* Storage for the data. */
392 std::tuple
<Arg
...> m_storage
;
396 /* do_dump does the work of dumping the data. */
397 template<int I
, typename
... T
>
398 typename
std::enable_if
<I
== sizeof... (T
), void>::type
399 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
404 template<int I
, typename
... T
>
405 typename
std::enable_if
<I
< sizeof... (T
), void>::type
406 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
409 dump_for_expression (stream
, depth
, std::get
<I
> (value
));
410 do_dump
<I
+ 1, T
...> (stream
, depth
, value
);
413 /* do_check_objfile does the work of checking whether this object
414 refers to OBJFILE. */
415 template<int I
, typename
... T
>
416 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
417 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
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
)
428 if (check_objfile (std::get
<I
> (value
), objfile
))
430 return do_check_objfile
<I
+ 1, T
...> (objfile
, value
);
434 /* The check_constant overloads are used to decide whether a given
435 concrete operation is a constant. This is done by checking the
439 check_constant (const operation_up
&item
)
441 return item
->constant_p ();
445 check_constant (bound_minimal_symbol msym
)
451 check_constant (struct type
*type
)
457 check_constant (const struct block
*block
)
463 check_constant (const std::string
&str
)
469 check_constant (ULONGEST cst
)
475 check_constant (struct symbol
*sym
)
477 enum address_class sc
= sym
->aclass ();
478 return (sc
== LOC_BLOCK
480 || sc
== LOC_CONST_BYTES
485 check_constant (const block_symbol
&sym
)
487 /* We know the block is constant, so we only need to check the
489 return check_constant (sym
.symbol
);
494 check_constant (const std::vector
<T
> &collection
)
496 for (const auto &item
: collection
)
497 if (!check_constant (item
))
502 template<typename S
, typename T
>
504 check_constant (const std::pair
<S
, T
> &item
)
506 return check_constant (item
.first
) && check_constant (item
.second
);
509 /* Base class for concrete operations. This class supplies an
510 implementation of 'constant_p' that works by checking the
512 template<typename
... Arg
>
513 class maybe_constant_operation
514 : public tuple_holding_operation
<Arg
...>
518 using tuple_holding_operation
<Arg
...>::tuple_holding_operation
;
520 bool constant_p () const override
522 return do_check_constant
<0, Arg
...> (this->m_storage
);
527 template<int I
, typename
... T
>
528 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
529 do_check_constant (const std::tuple
<T
...> &value
) const
534 template<int I
, typename
... T
>
535 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
536 do_check_constant (const std::tuple
<T
...> &value
) const
538 if (!check_constant (std::get
<I
> (value
)))
540 return do_check_constant
<I
+ 1, T
...> (value
);
544 /* A floating-point constant. The constant is encoded in the target
547 typedef std::array
<gdb_byte
, 16> float_data
;
549 /* An operation that holds a floating-point constant of a given
552 This does not need the facilities provided by
553 tuple_holding_operation, so it does not use it. */
554 class float_const_operation
559 float_const_operation (struct type
*type
, float_data data
)
565 value
*evaluate (struct type
*expect_type
,
566 struct expression
*exp
,
567 enum noside noside
) override
569 return value_from_contents (m_type
, m_data
.data ());
572 enum exp_opcode
opcode () const override
575 bool constant_p () const override
578 void dump (struct ui_file
*stream
, int depth
) const override
;
586 class scope_operation
587 : public maybe_constant_operation
<struct type
*, std::string
>
591 using maybe_constant_operation::maybe_constant_operation
;
593 value
*evaluate (struct type
*expect_type
,
594 struct expression
*exp
,
595 enum noside noside
) override
597 return eval_op_scope (expect_type
, exp
, noside
,
598 std::get
<0> (m_storage
),
599 std::get
<1> (m_storage
).c_str ());
602 value
*evaluate_for_address (struct expression
*exp
,
603 enum noside noside
) override
;
605 value
*evaluate_funcall (struct type
*expect_type
,
606 struct expression
*exp
,
608 const std::vector
<operation_up
> &args
) override
;
610 enum exp_opcode
opcode () const override
615 void do_generate_ax (struct expression
*exp
,
616 struct agent_expr
*ax
,
617 struct axs_value
*value
,
618 struct type
*cast_type
)
622 /* Compute the value of a variable. */
623 class var_value_operation
624 : public maybe_constant_operation
<block_symbol
>
628 using maybe_constant_operation::maybe_constant_operation
;
630 value
*evaluate (struct type
*expect_type
,
631 struct expression
*exp
,
632 enum noside noside
) override
;
634 value
*evaluate_with_coercion (struct expression
*exp
,
635 enum noside noside
) override
;
637 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
640 value
*evaluate_for_cast (struct type
*expect_type
,
641 struct expression
*exp
,
642 enum noside noside
) override
;
644 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
647 value
*evaluate_funcall (struct type
*expect_type
,
648 struct expression
*exp
,
650 const std::vector
<operation_up
> &args
) override
;
652 enum exp_opcode
opcode () const override
653 { return OP_VAR_VALUE
; }
655 /* Return the symbol referenced by this object. */
656 symbol
*get_symbol () const
658 return std::get
<0> (m_storage
).symbol
;
663 void do_generate_ax (struct expression
*exp
,
664 struct agent_expr
*ax
,
665 struct axs_value
*value
,
666 struct type
*cast_type
)
670 class long_const_operation
671 : public tuple_holding_operation
<struct type
*, LONGEST
>
675 using tuple_holding_operation::tuple_holding_operation
;
677 value
*evaluate (struct type
*expect_type
,
678 struct expression
*exp
,
679 enum noside noside
) override
681 return value_from_longest (std::get
<0> (m_storage
),
682 std::get
<1> (m_storage
));
685 enum exp_opcode
opcode () const override
688 bool constant_p () const override
693 void do_generate_ax (struct expression
*exp
,
694 struct agent_expr
*ax
,
695 struct axs_value
*value
,
696 struct type
*cast_type
)
700 class var_msym_value_operation
701 : public maybe_constant_operation
<bound_minimal_symbol
>
705 using maybe_constant_operation::maybe_constant_operation
;
707 value
*evaluate (struct type
*expect_type
,
708 struct expression
*exp
,
709 enum noside noside
) override
711 return eval_op_var_msym_value (expect_type
, exp
, noside
, m_outermost
,
712 std::get
<0> (m_storage
));
715 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
718 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
721 value
*evaluate_for_cast (struct type
*expect_type
,
722 struct expression
*exp
,
723 enum noside noside
) override
;
725 value
*evaluate_funcall (struct type
*expect_type
,
726 struct expression
*exp
,
728 const std::vector
<operation_up
> &args
) override
730 const char *name
= std::get
<0> (m_storage
).minsym
->print_name ();
731 return operation::evaluate_funcall (expect_type
, exp
, noside
, name
, args
);
734 enum exp_opcode
opcode () const override
735 { return OP_VAR_MSYM_VALUE
; }
737 void set_outermost () override
744 /* True if this is the outermost operation in the expression. */
745 bool m_outermost
= false;
747 void do_generate_ax (struct expression
*exp
,
748 struct agent_expr
*ax
,
749 struct axs_value
*value
,
750 struct type
*cast_type
)
754 class var_entry_value_operation
755 : public tuple_holding_operation
<symbol
*>
759 using tuple_holding_operation::tuple_holding_operation
;
761 value
*evaluate (struct type
*expect_type
,
762 struct expression
*exp
,
763 enum noside noside
) override
765 return eval_op_var_entry_value (expect_type
, exp
, noside
,
766 std::get
<0> (m_storage
));
769 enum exp_opcode
opcode () const override
770 { return OP_VAR_ENTRY_VALUE
; }
773 class func_static_var_operation
774 : public maybe_constant_operation
<operation_up
, std::string
>
778 using maybe_constant_operation::maybe_constant_operation
;
780 value
*evaluate (struct type
*expect_type
,
781 struct expression
*exp
,
782 enum noside noside
) override
784 value
*func
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
785 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
786 std::get
<1> (m_storage
).c_str ());
789 enum exp_opcode
opcode () const override
790 { return OP_FUNC_STATIC_VAR
; }
794 : public tuple_holding_operation
<int>
798 using tuple_holding_operation::tuple_holding_operation
;
800 value
*evaluate (struct type
*expect_type
,
801 struct expression
*exp
,
802 enum noside noside
) override
804 return access_value_history (std::get
<0> (m_storage
));
807 enum exp_opcode
opcode () const override
811 class register_operation
812 : public tuple_holding_operation
<std::string
>
816 using tuple_holding_operation::tuple_holding_operation
;
818 value
*evaluate (struct type
*expect_type
,
819 struct expression
*exp
,
820 enum noside noside
) override
822 return eval_op_register (expect_type
, exp
, noside
,
823 std::get
<0> (m_storage
).c_str ());
826 enum exp_opcode
opcode () const override
827 { return OP_REGISTER
; }
829 /* Return the name of the register. */
830 const char *get_name () const
832 return std::get
<0> (m_storage
).c_str ();
837 void do_generate_ax (struct expression
*exp
,
838 struct agent_expr
*ax
,
839 struct axs_value
*value
,
840 struct type
*cast_type
)
845 : public tuple_holding_operation
<bool>
849 using tuple_holding_operation::tuple_holding_operation
;
851 value
*evaluate (struct type
*expect_type
,
852 struct expression
*exp
,
853 enum noside noside
) override
855 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
856 return value_from_longest (type
, std::get
<0> (m_storage
));
859 enum exp_opcode
opcode () const override
862 bool constant_p () const override
866 class internalvar_operation
867 : public tuple_holding_operation
<internalvar
*>
871 using tuple_holding_operation::tuple_holding_operation
;
873 value
*evaluate (struct type
*expect_type
,
874 struct expression
*exp
,
875 enum noside noside
) override
877 return value_of_internalvar (exp
->gdbarch
,
878 std::get
<0> (m_storage
));
881 internalvar
*get_internalvar () const
883 return std::get
<0> (m_storage
);
886 enum exp_opcode
opcode () const override
887 { return OP_INTERNALVAR
; }
891 void do_generate_ax (struct expression
*exp
,
892 struct agent_expr
*ax
,
893 struct axs_value
*value
,
894 struct type
*cast_type
)
898 class string_operation
899 : public tuple_holding_operation
<std::string
>
903 using tuple_holding_operation::tuple_holding_operation
;
905 value
*evaluate (struct type
*expect_type
,
906 struct expression
*exp
,
907 enum noside noside
) override
;
909 enum exp_opcode
opcode () const override
910 { return OP_STRING
; }
913 class ternop_slice_operation
914 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
918 using maybe_constant_operation::maybe_constant_operation
;
920 value
*evaluate (struct type
*expect_type
,
921 struct expression
*exp
,
922 enum noside noside
) override
925 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
927 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
929 = std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
930 return eval_op_ternop (expect_type
, exp
, noside
, array
, low
, upper
);
933 enum exp_opcode
opcode () const override
934 { return TERNOP_SLICE
; }
937 class ternop_cond_operation
938 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
942 using maybe_constant_operation::maybe_constant_operation
;
944 value
*evaluate (struct type
*expect_type
,
945 struct expression
*exp
,
946 enum noside noside
) override
949 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
951 if (value_logical_not (val
))
952 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
953 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
956 enum exp_opcode
opcode () const override
957 { return TERNOP_COND
; }
961 void do_generate_ax (struct expression
*exp
,
962 struct agent_expr
*ax
,
963 struct axs_value
*value
,
964 struct type
*cast_type
)
968 class complex_operation
969 : public maybe_constant_operation
<operation_up
, operation_up
, struct type
*>
973 using maybe_constant_operation::maybe_constant_operation
;
975 value
*evaluate (struct type
*expect_type
,
976 struct expression
*exp
,
977 enum noside noside
) override
979 value
*real
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
980 value
*imag
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
981 return value_literal_complex (real
, imag
,
982 std::get
<2> (m_storage
));
985 enum exp_opcode
opcode () const override
986 { return OP_COMPLEX
; }
989 class structop_base_operation
990 : public tuple_holding_operation
<operation_up
, std::string
>
994 /* Used for completion. Return the field name. */
995 const std::string
&get_string () const
997 return std::get
<1> (m_storage
);
1000 /* Used for completion. Evaluate the LHS for type. */
1001 value
*evaluate_lhs (struct expression
*exp
)
1003 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1004 EVAL_AVOID_SIDE_EFFECTS
);
1007 value
*evaluate_funcall (struct type
*expect_type
,
1008 struct expression
*exp
,
1010 const std::vector
<operation_up
> &args
) override
;
1014 using tuple_holding_operation::tuple_holding_operation
;
1017 class structop_operation
1018 : public structop_base_operation
1022 using structop_base_operation::structop_base_operation
;
1024 value
*evaluate (struct type
*expect_type
,
1025 struct expression
*exp
,
1026 enum noside noside
) override
1028 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1029 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
1030 std::get
<1> (m_storage
).c_str ());
1033 enum exp_opcode
opcode () const override
1034 { return STRUCTOP_STRUCT
; }
1038 void do_generate_ax (struct expression
*exp
,
1039 struct agent_expr
*ax
,
1040 struct axs_value
*value
,
1041 struct type
*cast_type
)
1044 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
1045 std::get
<0> (this->m_storage
).get (),
1046 std::get
<1> (this->m_storage
).c_str (),
1051 class structop_ptr_operation
1052 : public structop_base_operation
1056 using structop_base_operation::structop_base_operation
;
1058 value
*evaluate (struct type
*expect_type
,
1059 struct expression
*exp
,
1060 enum noside noside
) override
1062 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1063 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
1064 std::get
<1> (m_storage
).c_str ());
1067 enum exp_opcode
opcode () const override
1068 { return STRUCTOP_PTR
; }
1072 void do_generate_ax (struct expression
*exp
,
1073 struct agent_expr
*ax
,
1074 struct axs_value
*value
,
1075 struct type
*cast_type
)
1078 gen_expr_structop (exp
, STRUCTOP_PTR
,
1079 std::get
<0> (this->m_storage
).get (),
1080 std::get
<1> (this->m_storage
).c_str (),
1085 class structop_member_base
1086 : public tuple_holding_operation
<operation_up
, operation_up
>
1090 using tuple_holding_operation::tuple_holding_operation
;
1092 value
*evaluate_funcall (struct type
*expect_type
,
1093 struct expression
*exp
,
1095 const std::vector
<operation_up
> &args
) override
;
1098 class structop_member_operation
1099 : public structop_member_base
1103 using structop_member_base::structop_member_base
;
1105 value
*evaluate (struct type
*expect_type
,
1106 struct expression
*exp
,
1107 enum noside noside
) override
1110 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1112 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1113 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1116 enum exp_opcode
opcode () const override
1117 { return STRUCTOP_MEMBER
; }
1120 class structop_mptr_operation
1121 : public structop_member_base
1125 using structop_member_base::structop_member_base
;
1127 value
*evaluate (struct type
*expect_type
,
1128 struct expression
*exp
,
1129 enum noside noside
) override
1132 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1134 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1135 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1138 enum exp_opcode
opcode () const override
1139 { return STRUCTOP_MPTR
; }
1142 class concat_operation
1143 : public maybe_constant_operation
<operation_up
, operation_up
>
1147 using maybe_constant_operation::maybe_constant_operation
;
1149 value
*evaluate (struct type
*expect_type
,
1150 struct expression
*exp
,
1151 enum noside noside
) override
1154 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1156 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1157 return value_concat (lhs
, rhs
);
1160 enum exp_opcode
opcode () const override
1161 { return BINOP_CONCAT
; }
1165 : public maybe_constant_operation
<operation_up
, operation_up
>
1169 using maybe_constant_operation::maybe_constant_operation
;
1171 value
*evaluate (struct type
*expect_type
,
1172 struct expression
*exp
,
1173 enum noside noside
) override
1176 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1178 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1179 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1182 enum exp_opcode
opcode () const override
1183 { return BINOP_ADD
; }
1187 void do_generate_ax (struct expression
*exp
,
1188 struct agent_expr
*ax
,
1189 struct axs_value
*value
,
1190 struct type
*cast_type
)
1193 gen_expr_binop (exp
, BINOP_ADD
,
1194 std::get
<0> (this->m_storage
).get (),
1195 std::get
<1> (this->m_storage
).get (),
1201 : public maybe_constant_operation
<operation_up
, operation_up
>
1205 using maybe_constant_operation::maybe_constant_operation
;
1207 value
*evaluate (struct type
*expect_type
,
1208 struct expression
*exp
,
1209 enum noside noside
) override
1212 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1214 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1215 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1218 enum exp_opcode
opcode () const override
1219 { return BINOP_SUB
; }
1223 void do_generate_ax (struct expression
*exp
,
1224 struct agent_expr
*ax
,
1225 struct axs_value
*value
,
1226 struct type
*cast_type
)
1229 gen_expr_binop (exp
, BINOP_SUB
,
1230 std::get
<0> (this->m_storage
).get (),
1231 std::get
<1> (this->m_storage
).get (),
1236 typedef struct value
*binary_ftype (struct type
*expect_type
,
1237 struct expression
*exp
,
1238 enum noside noside
, enum exp_opcode op
,
1239 struct value
*arg1
, struct value
*arg2
);
1241 template<enum exp_opcode OP
, binary_ftype FUNC
>
1242 class binop_operation
1243 : public maybe_constant_operation
<operation_up
, operation_up
>
1247 using maybe_constant_operation::maybe_constant_operation
;
1249 value
*evaluate (struct type
*expect_type
,
1250 struct expression
*exp
,
1251 enum noside noside
) override
1254 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1256 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1257 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1260 enum exp_opcode
opcode () const override
1264 template<enum exp_opcode OP
, binary_ftype FUNC
>
1265 class usual_ax_binop_operation
1266 : public binop_operation
<OP
, FUNC
>
1270 using binop_operation
<OP
, FUNC
>::binop_operation
;
1274 void do_generate_ax (struct expression
*exp
,
1275 struct agent_expr
*ax
,
1276 struct axs_value
*value
,
1277 struct type
*cast_type
)
1280 gen_expr_binop (exp
, OP
,
1281 std::get
<0> (this->m_storage
).get (),
1282 std::get
<1> (this->m_storage
).get (),
1287 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1288 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1289 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1291 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1292 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1293 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1294 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1295 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1296 using bitwise_and_operation
1297 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1298 using bitwise_ior_operation
1299 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1300 using bitwise_xor_operation
1301 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1303 class subscript_operation
1304 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1307 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1308 eval_op_subscript
>::usual_ax_binop_operation
;
1310 value
*evaluate_for_sizeof (struct expression
*exp
,
1311 enum noside noside
) override
;
1314 /* Implementation of comparison operations. */
1315 template<enum exp_opcode OP
, binary_ftype FUNC
>
1316 class comparison_operation
1317 : public usual_ax_binop_operation
<OP
, FUNC
>
1321 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1323 value
*evaluate (struct type
*expect_type
,
1324 struct expression
*exp
,
1325 enum noside noside
) override
1328 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1330 = std::get
<1> (this->m_storage
)->evaluate (value_type (lhs
), exp
,
1332 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1336 class equal_operation
1337 : public comparison_operation
<BINOP_EQUAL
, eval_op_equal
>
1341 using comparison_operation::comparison_operation
;
1343 operation
*get_lhs () const
1345 return std::get
<0> (m_storage
).get ();
1348 operation
*get_rhs () const
1350 return std::get
<1> (m_storage
).get ();
1354 using notequal_operation
1355 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1356 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1357 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1358 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1359 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1361 /* Implement the GDB '@' repeat operator. */
1362 class repeat_operation
1363 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1365 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1369 void do_generate_ax (struct expression
*exp
,
1370 struct agent_expr
*ax
,
1371 struct axs_value
*value
,
1372 struct type
*cast_type
)
1376 /* C-style comma operator. */
1377 class comma_operation
1378 : public maybe_constant_operation
<operation_up
, operation_up
>
1382 using maybe_constant_operation::maybe_constant_operation
;
1384 value
*evaluate (struct type
*expect_type
,
1385 struct expression
*exp
,
1386 enum noside noside
) override
1388 /* The left-hand-side is only evaluated for side effects, so don't
1389 bother in other modes. */
1390 if (noside
== EVAL_NORMAL
)
1391 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1392 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1395 enum exp_opcode
opcode () const override
1396 { return BINOP_COMMA
; }
1400 void do_generate_ax (struct expression
*exp
,
1401 struct agent_expr
*ax
,
1402 struct axs_value
*value
,
1403 struct type
*cast_type
)
1407 typedef struct value
*unary_ftype (struct type
*expect_type
,
1408 struct expression
*exp
,
1409 enum noside noside
, enum exp_opcode op
,
1410 struct value
*arg1
);
1412 /* Base class for unary operations. */
1413 template<enum exp_opcode OP
, unary_ftype FUNC
>
1414 class unop_operation
1415 : public maybe_constant_operation
<operation_up
>
1419 using maybe_constant_operation::maybe_constant_operation
;
1421 value
*evaluate (struct type
*expect_type
,
1422 struct expression
*exp
,
1423 enum noside noside
) override
1425 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1426 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1429 enum exp_opcode
opcode () const override
1433 /* Unary operations that can also be turned into agent expressions in
1435 template<enum exp_opcode OP
, unary_ftype FUNC
>
1436 class usual_ax_unop_operation
1437 : public unop_operation
<OP
, FUNC
>
1439 using unop_operation
<OP
, FUNC
>::unop_operation
;
1443 void do_generate_ax (struct expression
*exp
,
1444 struct agent_expr
*ax
,
1445 struct axs_value
*value
,
1446 struct type
*cast_type
)
1449 gen_expr_unop (exp
, OP
,
1450 std::get
<0> (this->m_storage
).get (),
1455 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1456 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1457 using unary_complement_operation
1458 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1459 using unary_logical_not_operation
1460 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1462 /* Handle pre- and post- increment and -decrement. */
1463 template<enum exp_opcode OP
, unary_ftype FUNC
>
1464 class unop_incr_operation
1465 : public tuple_holding_operation
<operation_up
>
1469 using tuple_holding_operation::tuple_holding_operation
;
1471 value
*evaluate (struct type
*expect_type
,
1472 struct expression
*exp
,
1473 enum noside noside
) override
1475 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1476 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1479 enum exp_opcode
opcode () const override
1483 using preinc_operation
1484 = unop_incr_operation
<UNOP_PREINCREMENT
, eval_op_preinc
>;
1485 using predec_operation
1486 = unop_incr_operation
<UNOP_PREDECREMENT
, eval_op_predec
>;
1487 using postinc_operation
1488 = unop_incr_operation
<UNOP_POSTINCREMENT
, eval_op_postinc
>;
1489 using postdec_operation
1490 = unop_incr_operation
<UNOP_POSTDECREMENT
, eval_op_postdec
>;
1492 /* Base class for implementations of UNOP_IND. */
1493 class unop_ind_base_operation
1494 : public tuple_holding_operation
<operation_up
>
1498 using tuple_holding_operation::tuple_holding_operation
;
1500 value
*evaluate (struct type
*expect_type
,
1501 struct expression
*exp
,
1502 enum noside noside
) override
1504 if (expect_type
!= nullptr && expect_type
->code () == TYPE_CODE_PTR
)
1505 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1506 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1507 return eval_op_ind (expect_type
, exp
, noside
, val
);
1510 value
*evaluate_for_address (struct expression
*exp
,
1511 enum noside noside
) override
;
1513 value
*evaluate_for_sizeof (struct expression
*exp
,
1514 enum noside noside
) override
;
1516 enum exp_opcode
opcode () const override
1517 { return UNOP_IND
; }
1520 /* Ordinary UNOP_IND implementation. */
1521 class unop_ind_operation
1522 : public unop_ind_base_operation
1526 using unop_ind_base_operation::unop_ind_base_operation
;
1530 void do_generate_ax (struct expression
*exp
,
1531 struct agent_expr
*ax
,
1532 struct axs_value
*value
,
1533 struct type
*cast_type
)
1536 gen_expr_unop (exp
, UNOP_IND
,
1537 std::get
<0> (this->m_storage
).get (),
1542 /* Implement OP_TYPE. */
1543 class type_operation
1544 : public tuple_holding_operation
<struct type
*>
1548 using tuple_holding_operation::tuple_holding_operation
;
1550 value
*evaluate (struct type
*expect_type
,
1551 struct expression
*exp
,
1552 enum noside noside
) override
1554 return eval_op_type (expect_type
, exp
, noside
, std::get
<0> (m_storage
));
1557 enum exp_opcode
opcode () const override
1560 bool constant_p () const override
1564 /* Implement the "typeof" operation. */
1565 class typeof_operation
1566 : public maybe_constant_operation
<operation_up
>
1570 using maybe_constant_operation::maybe_constant_operation
;
1572 value
*evaluate (struct type
*expect_type
,
1573 struct expression
*exp
,
1574 enum noside noside
) override
1576 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1577 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1578 EVAL_AVOID_SIDE_EFFECTS
);
1580 error (_("Attempt to use a type as an expression"));
1583 enum exp_opcode
opcode () const override
1584 { return OP_TYPEOF
; }
1587 /* Implement 'decltype'. */
1588 class decltype_operation
1589 : public maybe_constant_operation
<operation_up
>
1593 using maybe_constant_operation::maybe_constant_operation
;
1595 value
*evaluate (struct type
*expect_type
,
1596 struct expression
*exp
,
1597 enum noside noside
) override
1599 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1602 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1603 EVAL_AVOID_SIDE_EFFECTS
);
1604 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1605 if (sub_op
== BINOP_SUBSCRIPT
1606 || sub_op
== STRUCTOP_MEMBER
1607 || sub_op
== STRUCTOP_MPTR
1608 || sub_op
== UNOP_IND
1609 || sub_op
== STRUCTOP_STRUCT
1610 || sub_op
== STRUCTOP_PTR
1611 || sub_op
== OP_SCOPE
)
1613 struct type
*type
= value_type (result
);
1615 if (!TYPE_IS_REFERENCE (type
))
1617 type
= lookup_lvalue_reference_type (type
);
1618 result
= allocate_value (type
);
1625 error (_("Attempt to use a type as an expression"));
1628 enum exp_opcode
opcode () const override
1629 { return OP_DECLTYPE
; }
1632 /* Implement 'typeid'. */
1633 class typeid_operation
1634 : public tuple_holding_operation
<operation_up
>
1638 using tuple_holding_operation::tuple_holding_operation
;
1640 value
*evaluate (struct type
*expect_type
,
1641 struct expression
*exp
,
1642 enum noside noside
) override
1644 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1645 enum noside sub_noside
1646 = ((sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
1647 ? EVAL_AVOID_SIDE_EFFECTS
1650 value
*result
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1652 if (noside
!= EVAL_NORMAL
)
1653 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
1654 return cplus_typeid (result
);
1657 enum exp_opcode
opcode () const override
1658 { return OP_TYPEID
; }
1661 /* Implement the address-of operation. */
1662 class unop_addr_operation
1663 : public maybe_constant_operation
<operation_up
>
1667 using maybe_constant_operation::maybe_constant_operation
;
1669 value
*evaluate (struct type
*expect_type
,
1670 struct expression
*exp
,
1671 enum noside noside
) override
1673 /* C++: check for and handle pointer to members. */
1674 return std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1677 enum exp_opcode
opcode () const override
1678 { return UNOP_ADDR
; }
1680 /* Return the subexpression. */
1681 const operation_up
&get_expression () const
1683 return std::get
<0> (m_storage
);
1688 void do_generate_ax (struct expression
*exp
,
1689 struct agent_expr
*ax
,
1690 struct axs_value
*value
,
1691 struct type
*cast_type
)
1694 gen_expr_unop (exp
, UNOP_ADDR
,
1695 std::get
<0> (this->m_storage
).get (),
1700 /* Implement 'sizeof'. */
1701 class unop_sizeof_operation
1702 : public maybe_constant_operation
<operation_up
>
1706 using maybe_constant_operation::maybe_constant_operation
;
1708 value
*evaluate (struct type
*expect_type
,
1709 struct expression
*exp
,
1710 enum noside noside
) override
1712 return std::get
<0> (m_storage
)->evaluate_for_sizeof (exp
, noside
);
1715 enum exp_opcode
opcode () const override
1716 { return UNOP_SIZEOF
; }
1720 void do_generate_ax (struct expression
*exp
,
1721 struct agent_expr
*ax
,
1722 struct axs_value
*value
,
1723 struct type
*cast_type
)
1727 /* Implement 'alignof'. */
1728 class unop_alignof_operation
1729 : public maybe_constant_operation
<operation_up
>
1733 using maybe_constant_operation::maybe_constant_operation
;
1735 value
*evaluate (struct type
*expect_type
,
1736 struct expression
*exp
,
1737 enum noside noside
) override
1739 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1740 EVAL_AVOID_SIDE_EFFECTS
);
1741 return eval_op_alignof (expect_type
, exp
, noside
, val
);
1744 enum exp_opcode
opcode () const override
1745 { return UNOP_ALIGNOF
; }
1748 /* Implement UNOP_MEMVAL. */
1749 class unop_memval_operation
1750 : public tuple_holding_operation
<operation_up
, struct type
*>
1754 using tuple_holding_operation::tuple_holding_operation
;
1756 value
*evaluate (struct type
*expect_type
,
1757 struct expression
*exp
,
1758 enum noside noside
) override
1760 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1761 return eval_op_memval (expect_type
, exp
, noside
, val
,
1762 std::get
<1> (m_storage
));
1765 value
*evaluate_for_sizeof (struct expression
*exp
,
1766 enum noside noside
) override
;
1768 value
*evaluate_for_address (struct expression
*exp
,
1769 enum noside noside
) override
;
1771 enum exp_opcode
opcode () const override
1772 { return UNOP_MEMVAL
; }
1774 /* Return the type referenced by this object. */
1775 struct type
*get_type () const
1777 return std::get
<1> (m_storage
);
1782 void do_generate_ax (struct expression
*exp
,
1783 struct agent_expr
*ax
,
1784 struct axs_value
*value
,
1785 struct type
*cast_type
)
1789 /* Implement UNOP_MEMVAL_TYPE. */
1790 class unop_memval_type_operation
1791 : public tuple_holding_operation
<operation_up
, operation_up
>
1795 using tuple_holding_operation::tuple_holding_operation
;
1797 value
*evaluate (struct type
*expect_type
,
1798 struct expression
*exp
,
1799 enum noside noside
) override
1802 = std::get
<0> (m_storage
)->evaluate (expect_type
, exp
,
1803 EVAL_AVOID_SIDE_EFFECTS
);
1804 struct type
*type
= value_type (typeval
);
1805 value
*val
= std::get
<1> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1806 return eval_op_memval (expect_type
, exp
, noside
, val
, type
);
1809 value
*evaluate_for_sizeof (struct expression
*exp
,
1810 enum noside noside
) override
;
1812 value
*evaluate_for_address (struct expression
*exp
,
1813 enum noside noside
) override
;
1815 enum exp_opcode
opcode () const override
1816 { return UNOP_MEMVAL_TYPE
; }
1820 void do_generate_ax (struct expression
*exp
,
1821 struct agent_expr
*ax
,
1822 struct axs_value
*value
,
1823 struct type
*cast_type
)
1827 /* Implement the 'this' expression. */
1828 class op_this_operation
1829 : public tuple_holding_operation
<>
1833 using tuple_holding_operation::tuple_holding_operation
;
1835 value
*evaluate (struct type
*expect_type
,
1836 struct expression
*exp
,
1837 enum noside noside
) override
1839 return value_of_this (exp
->language_defn
);
1842 enum exp_opcode
opcode () const override
1847 void do_generate_ax (struct expression
*exp
,
1848 struct agent_expr
*ax
,
1849 struct axs_value
*value
,
1850 struct type
*cast_type
)
1854 /* Implement the "type instance" operation. */
1855 class type_instance_operation
1856 : public tuple_holding_operation
<type_instance_flags
, std::vector
<type
*>,
1861 using tuple_holding_operation::tuple_holding_operation
;
1863 value
*evaluate (struct type
*expect_type
,
1864 struct expression
*exp
,
1865 enum noside noside
) override
;
1867 enum exp_opcode
opcode () const override
1868 { return TYPE_INSTANCE
; }
1871 /* The assignment operator. */
1872 class assign_operation
1873 : public tuple_holding_operation
<operation_up
, operation_up
>
1877 using tuple_holding_operation::tuple_holding_operation
;
1879 value
*evaluate (struct type
*expect_type
,
1880 struct expression
*exp
,
1881 enum noside noside
) override
1883 value
*lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1884 /* Special-case assignments where the left-hand-side is a
1885 convenience variable -- in these, don't bother setting an
1886 expected type. This avoids a weird case where re-assigning a
1887 string or array to an internal variable could error with "Too
1888 many array elements". */
1889 struct type
*xtype
= (VALUE_LVAL (lhs
) == lval_internalvar
1891 : value_type (lhs
));
1892 value
*rhs
= std::get
<1> (m_storage
)->evaluate (xtype
, exp
, noside
);
1894 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1896 if (binop_user_defined_p (BINOP_ASSIGN
, lhs
, rhs
))
1897 return value_x_binop (lhs
, rhs
, BINOP_ASSIGN
, OP_NULL
, noside
);
1899 return value_assign (lhs
, rhs
);
1902 enum exp_opcode
opcode () const override
1903 { return BINOP_ASSIGN
; }
1905 /* Return the left-hand-side of the assignment. */
1906 operation
*get_lhs () const
1908 return std::get
<0> (m_storage
).get ();
1913 void do_generate_ax (struct expression
*exp
,
1914 struct agent_expr
*ax
,
1915 struct axs_value
*value
,
1916 struct type
*cast_type
)
1920 /* Assignment with modification, like "+=". */
1921 class assign_modify_operation
1922 : public tuple_holding_operation
<exp_opcode
, operation_up
, operation_up
>
1926 using tuple_holding_operation::tuple_holding_operation
;
1928 value
*evaluate (struct type
*expect_type
,
1929 struct expression
*exp
,
1930 enum noside noside
) override
1932 value
*lhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1933 value
*rhs
= std::get
<2> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1934 return eval_binop_assign_modify (expect_type
, exp
, noside
,
1935 std::get
<0> (m_storage
), lhs
, rhs
);
1938 enum exp_opcode
opcode () const override
1939 { return BINOP_ASSIGN_MODIFY
; }
1943 void do_generate_ax (struct expression
*exp
,
1944 struct agent_expr
*ax
,
1945 struct axs_value
*value
,
1946 struct type
*cast_type
)
1950 /* Not a cast! Extract a value of a given type from the contents of a
1951 value. The new value is extracted from the least significant bytes
1952 of the old value. The new value's type must be no bigger than the
1954 class unop_extract_operation
1955 : public maybe_constant_operation
<operation_up
, struct type
*>
1959 using maybe_constant_operation::maybe_constant_operation
;
1961 value
*evaluate (struct type
*expect_type
, struct expression
*exp
,
1962 enum noside noside
) override
;
1964 enum exp_opcode
opcode () const override
1965 { return UNOP_EXTRACT
; }
1967 /* Return the type referenced by this object. */
1968 struct type
*get_type () const
1970 return std::get
<1> (m_storage
);
1975 void do_generate_ax (struct expression
*exp
,
1976 struct agent_expr
*ax
,
1977 struct axs_value
*value
,
1978 struct type
*cast_type
) override
;
1982 class unop_cast_operation
1983 : public maybe_constant_operation
<operation_up
, struct type
*>
1987 using maybe_constant_operation::maybe_constant_operation
;
1989 value
*evaluate (struct type
*expect_type
,
1990 struct expression
*exp
,
1991 enum noside noside
) override
1993 return std::get
<0> (m_storage
)->evaluate_for_cast (std::get
<1> (m_storage
),
1997 enum exp_opcode
opcode () const override
1998 { return UNOP_CAST
; }
2000 /* Return the type referenced by this object. */
2001 struct type
*get_type () const
2003 return std::get
<1> (m_storage
);
2008 void do_generate_ax (struct expression
*exp
,
2009 struct agent_expr
*ax
,
2010 struct axs_value
*value
,
2011 struct type
*cast_type
)
2015 /* A cast, but the type comes from an expression, not a "struct
2017 class unop_cast_type_operation
2018 : public maybe_constant_operation
<operation_up
, operation_up
>
2022 using maybe_constant_operation::maybe_constant_operation
;
2024 value
*evaluate (struct type
*expect_type
,
2025 struct expression
*exp
,
2026 enum noside noside
) override
2028 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2029 EVAL_AVOID_SIDE_EFFECTS
);
2030 return std::get
<1> (m_storage
)->evaluate_for_cast (value_type (val
),
2034 enum exp_opcode
opcode () const override
2035 { return UNOP_CAST_TYPE
; }
2039 void do_generate_ax (struct expression
*exp
,
2040 struct agent_expr
*ax
,
2041 struct axs_value
*value
,
2042 struct type
*cast_type
)
2046 typedef value
*cxx_cast_ftype (struct type
*, value
*);
2048 /* This implements dynamic_cast and reinterpret_cast. static_cast and
2049 const_cast are handled by the ordinary case operations. */
2050 template<exp_opcode OP
, cxx_cast_ftype FUNC
>
2051 class cxx_cast_operation
2052 : public maybe_constant_operation
<operation_up
, operation_up
>
2056 using maybe_constant_operation::maybe_constant_operation
;
2058 value
*evaluate (struct type
*expect_type
,
2059 struct expression
*exp
,
2060 enum noside noside
) override
2062 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2063 EVAL_AVOID_SIDE_EFFECTS
);
2064 struct type
*type
= value_type (val
);
2065 value
*rhs
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
2066 return FUNC (type
, rhs
);
2069 enum exp_opcode
opcode () const override
2073 using dynamic_cast_operation
= cxx_cast_operation
<UNOP_DYNAMIC_CAST
,
2074 value_dynamic_cast
>;
2075 using reinterpret_cast_operation
= cxx_cast_operation
<UNOP_REINTERPRET_CAST
,
2076 value_reinterpret_cast
>;
2078 /* Multi-dimensional subscripting. */
2079 class multi_subscript_operation
2080 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2084 using tuple_holding_operation::tuple_holding_operation
;
2086 value
*evaluate (struct type
*expect_type
,
2087 struct expression
*exp
,
2088 enum noside noside
) override
;
2090 enum exp_opcode
opcode () const override
2091 { return MULTI_SUBSCRIPT
; }
2094 /* The "&&" operator. */
2095 class logical_and_operation
2096 : public maybe_constant_operation
<operation_up
, operation_up
>
2100 using maybe_constant_operation::maybe_constant_operation
;
2102 value
*evaluate (struct type
*expect_type
,
2103 struct expression
*exp
,
2104 enum noside noside
) override
;
2106 enum exp_opcode
opcode () const override
2107 { return BINOP_LOGICAL_AND
; }
2111 void do_generate_ax (struct expression
*exp
,
2112 struct agent_expr
*ax
,
2113 struct axs_value
*value
,
2114 struct type
*cast_type
)
2118 /* The "||" operator. */
2119 class logical_or_operation
2120 : public maybe_constant_operation
<operation_up
, operation_up
>
2124 using maybe_constant_operation::maybe_constant_operation
;
2126 value
*evaluate (struct type
*expect_type
,
2127 struct expression
*exp
,
2128 enum noside noside
) override
;
2130 enum exp_opcode
opcode () const override
2131 { return BINOP_LOGICAL_OR
; }
2135 void do_generate_ax (struct expression
*exp
,
2136 struct agent_expr
*ax
,
2137 struct axs_value
*value
,
2138 struct type
*cast_type
)
2142 /* This class implements ADL (aka Koenig) function calls for C++. It
2143 holds the name of the function to call, the block in which the
2144 lookup should be done, and a vector of arguments. */
2145 class adl_func_operation
2146 : public tuple_holding_operation
<std::string
, const block
*,
2147 std::vector
<operation_up
>>
2151 using tuple_holding_operation::tuple_holding_operation
;
2153 value
*evaluate (struct type
*expect_type
,
2154 struct expression
*exp
,
2155 enum noside noside
) override
;
2157 enum exp_opcode
opcode () const override
2158 { return OP_ADL_FUNC
; }
2161 /* The OP_ARRAY operation. */
2162 class array_operation
2163 : public tuple_holding_operation
<int, int, std::vector
<operation_up
>>
2167 using tuple_holding_operation::tuple_holding_operation
;
2169 value
*evaluate (struct type
*expect_type
,
2170 struct expression
*exp
,
2171 enum noside noside
) override
;
2173 enum exp_opcode
opcode () const override
2174 { return OP_ARRAY
; }
2178 struct value
*evaluate_struct_tuple (struct value
*struct_val
,
2179 struct expression
*exp
,
2180 enum noside noside
, int nargs
);
2183 /* A function call. This holds the callee operation and the
2185 class funcall_operation
2186 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2190 using tuple_holding_operation::tuple_holding_operation
;
2192 value
*evaluate (struct type
*expect_type
,
2193 struct expression
*exp
,
2194 enum noside noside
) override
2196 return std::get
<0> (m_storage
)->evaluate_funcall (expect_type
, exp
, noside
,
2197 std::get
<1> (m_storage
));
2200 enum exp_opcode
opcode () const override
2201 { return OP_FUNCALL
; }
2204 } /* namespace expr */
2206 #endif /* EXPOP_H */