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 (sym
->objfile (), 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 value
*evaluate_funcall (struct type
*expect_type
,
1001 struct expression
*exp
,
1003 const std::vector
<operation_up
> &args
) override
;
1005 /* Try to complete this operation in the context of EXP. TRACKER is
1006 the completion tracker to update. Return true if completion was
1007 possible, false otherwise. */
1008 virtual bool complete (struct expression
*exp
, completion_tracker
&tracker
)
1010 return complete (exp
, tracker
, "");
1015 /* Do the work of the public 'complete' method. PREFIX is prepended
1017 bool complete (struct expression
*exp
, completion_tracker
&tracker
,
1018 const char *prefix
);
1020 using tuple_holding_operation::tuple_holding_operation
;
1023 class structop_operation
1024 : public structop_base_operation
1028 using structop_base_operation::structop_base_operation
;
1030 value
*evaluate (struct type
*expect_type
,
1031 struct expression
*exp
,
1032 enum noside noside
) override
1034 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1035 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
1036 std::get
<1> (m_storage
).c_str ());
1039 enum exp_opcode
opcode () const override
1040 { return STRUCTOP_STRUCT
; }
1044 void do_generate_ax (struct expression
*exp
,
1045 struct agent_expr
*ax
,
1046 struct axs_value
*value
,
1047 struct type
*cast_type
)
1050 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
1051 std::get
<0> (this->m_storage
).get (),
1052 std::get
<1> (this->m_storage
).c_str (),
1057 class structop_ptr_operation
1058 : public structop_base_operation
1062 using structop_base_operation::structop_base_operation
;
1064 value
*evaluate (struct type
*expect_type
,
1065 struct expression
*exp
,
1066 enum noside noside
) override
1068 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1069 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
1070 std::get
<1> (m_storage
).c_str ());
1073 enum exp_opcode
opcode () const override
1074 { return STRUCTOP_PTR
; }
1078 void do_generate_ax (struct expression
*exp
,
1079 struct agent_expr
*ax
,
1080 struct axs_value
*value
,
1081 struct type
*cast_type
)
1084 gen_expr_structop (exp
, STRUCTOP_PTR
,
1085 std::get
<0> (this->m_storage
).get (),
1086 std::get
<1> (this->m_storage
).c_str (),
1091 class structop_member_base
1092 : public tuple_holding_operation
<operation_up
, operation_up
>
1096 using tuple_holding_operation::tuple_holding_operation
;
1098 value
*evaluate_funcall (struct type
*expect_type
,
1099 struct expression
*exp
,
1101 const std::vector
<operation_up
> &args
) override
;
1104 class structop_member_operation
1105 : public structop_member_base
1109 using structop_member_base::structop_member_base
;
1111 value
*evaluate (struct type
*expect_type
,
1112 struct expression
*exp
,
1113 enum noside noside
) override
1116 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1118 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1119 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1122 enum exp_opcode
opcode () const override
1123 { return STRUCTOP_MEMBER
; }
1126 class structop_mptr_operation
1127 : public structop_member_base
1131 using structop_member_base::structop_member_base
;
1133 value
*evaluate (struct type
*expect_type
,
1134 struct expression
*exp
,
1135 enum noside noside
) override
1138 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1140 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1141 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1144 enum exp_opcode
opcode () const override
1145 { return STRUCTOP_MPTR
; }
1148 class concat_operation
1149 : public maybe_constant_operation
<operation_up
, operation_up
>
1153 using maybe_constant_operation::maybe_constant_operation
;
1155 value
*evaluate (struct type
*expect_type
,
1156 struct expression
*exp
,
1157 enum noside noside
) override
1160 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1162 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1163 return value_concat (lhs
, rhs
);
1166 enum exp_opcode
opcode () const override
1167 { return BINOP_CONCAT
; }
1171 : public maybe_constant_operation
<operation_up
, operation_up
>
1175 using maybe_constant_operation::maybe_constant_operation
;
1177 value
*evaluate (struct type
*expect_type
,
1178 struct expression
*exp
,
1179 enum noside noside
) override
1182 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1184 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1185 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1188 enum exp_opcode
opcode () const override
1189 { return BINOP_ADD
; }
1193 void do_generate_ax (struct expression
*exp
,
1194 struct agent_expr
*ax
,
1195 struct axs_value
*value
,
1196 struct type
*cast_type
)
1199 gen_expr_binop (exp
, BINOP_ADD
,
1200 std::get
<0> (this->m_storage
).get (),
1201 std::get
<1> (this->m_storage
).get (),
1207 : public maybe_constant_operation
<operation_up
, operation_up
>
1211 using maybe_constant_operation::maybe_constant_operation
;
1213 value
*evaluate (struct type
*expect_type
,
1214 struct expression
*exp
,
1215 enum noside noside
) override
1218 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1220 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1221 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1224 enum exp_opcode
opcode () const override
1225 { return BINOP_SUB
; }
1229 void do_generate_ax (struct expression
*exp
,
1230 struct agent_expr
*ax
,
1231 struct axs_value
*value
,
1232 struct type
*cast_type
)
1235 gen_expr_binop (exp
, BINOP_SUB
,
1236 std::get
<0> (this->m_storage
).get (),
1237 std::get
<1> (this->m_storage
).get (),
1242 typedef struct value
*binary_ftype (struct type
*expect_type
,
1243 struct expression
*exp
,
1244 enum noside noside
, enum exp_opcode op
,
1245 struct value
*arg1
, struct value
*arg2
);
1247 template<enum exp_opcode OP
, binary_ftype FUNC
>
1248 class binop_operation
1249 : public maybe_constant_operation
<operation_up
, operation_up
>
1253 using maybe_constant_operation::maybe_constant_operation
;
1255 value
*evaluate (struct type
*expect_type
,
1256 struct expression
*exp
,
1257 enum noside noside
) override
1260 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1262 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1263 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1266 enum exp_opcode
opcode () const override
1270 template<enum exp_opcode OP
, binary_ftype FUNC
>
1271 class usual_ax_binop_operation
1272 : public binop_operation
<OP
, FUNC
>
1276 using binop_operation
<OP
, FUNC
>::binop_operation
;
1280 void do_generate_ax (struct expression
*exp
,
1281 struct agent_expr
*ax
,
1282 struct axs_value
*value
,
1283 struct type
*cast_type
)
1286 gen_expr_binop (exp
, OP
,
1287 std::get
<0> (this->m_storage
).get (),
1288 std::get
<1> (this->m_storage
).get (),
1293 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1294 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1295 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1297 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1298 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1299 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1300 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1301 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1302 using bitwise_and_operation
1303 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1304 using bitwise_ior_operation
1305 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1306 using bitwise_xor_operation
1307 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1309 class subscript_operation
1310 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1313 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1314 eval_op_subscript
>::usual_ax_binop_operation
;
1316 value
*evaluate_for_sizeof (struct expression
*exp
,
1317 enum noside noside
) override
;
1320 /* Implementation of comparison operations. */
1321 template<enum exp_opcode OP
, binary_ftype FUNC
>
1322 class comparison_operation
1323 : public usual_ax_binop_operation
<OP
, FUNC
>
1327 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1329 value
*evaluate (struct type
*expect_type
,
1330 struct expression
*exp
,
1331 enum noside noside
) override
1334 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1336 = std::get
<1> (this->m_storage
)->evaluate (value_type (lhs
), exp
,
1338 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1342 class equal_operation
1343 : public comparison_operation
<BINOP_EQUAL
, eval_op_equal
>
1347 using comparison_operation::comparison_operation
;
1349 operation
*get_lhs () const
1351 return std::get
<0> (m_storage
).get ();
1354 operation
*get_rhs () const
1356 return std::get
<1> (m_storage
).get ();
1360 using notequal_operation
1361 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1362 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1363 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1364 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1365 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1367 /* Implement the GDB '@' repeat operator. */
1368 class repeat_operation
1369 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1371 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1375 void do_generate_ax (struct expression
*exp
,
1376 struct agent_expr
*ax
,
1377 struct axs_value
*value
,
1378 struct type
*cast_type
)
1382 /* C-style comma operator. */
1383 class comma_operation
1384 : public maybe_constant_operation
<operation_up
, operation_up
>
1388 using maybe_constant_operation::maybe_constant_operation
;
1390 value
*evaluate (struct type
*expect_type
,
1391 struct expression
*exp
,
1392 enum noside noside
) override
1394 /* The left-hand-side is only evaluated for side effects, so don't
1395 bother in other modes. */
1396 if (noside
== EVAL_NORMAL
)
1397 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1398 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1401 enum exp_opcode
opcode () const override
1402 { return BINOP_COMMA
; }
1406 void do_generate_ax (struct expression
*exp
,
1407 struct agent_expr
*ax
,
1408 struct axs_value
*value
,
1409 struct type
*cast_type
)
1413 typedef struct value
*unary_ftype (struct type
*expect_type
,
1414 struct expression
*exp
,
1415 enum noside noside
, enum exp_opcode op
,
1416 struct value
*arg1
);
1418 /* Base class for unary operations. */
1419 template<enum exp_opcode OP
, unary_ftype FUNC
>
1420 class unop_operation
1421 : public maybe_constant_operation
<operation_up
>
1425 using maybe_constant_operation::maybe_constant_operation
;
1427 value
*evaluate (struct type
*expect_type
,
1428 struct expression
*exp
,
1429 enum noside noside
) override
1431 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1432 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1435 enum exp_opcode
opcode () const override
1439 /* Unary operations that can also be turned into agent expressions in
1441 template<enum exp_opcode OP
, unary_ftype FUNC
>
1442 class usual_ax_unop_operation
1443 : public unop_operation
<OP
, FUNC
>
1445 using unop_operation
<OP
, FUNC
>::unop_operation
;
1449 void do_generate_ax (struct expression
*exp
,
1450 struct agent_expr
*ax
,
1451 struct axs_value
*value
,
1452 struct type
*cast_type
)
1455 gen_expr_unop (exp
, OP
,
1456 std::get
<0> (this->m_storage
).get (),
1461 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1462 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1463 using unary_complement_operation
1464 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1465 using unary_logical_not_operation
1466 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1468 /* Handle pre- and post- increment and -decrement. */
1469 template<enum exp_opcode OP
, unary_ftype FUNC
>
1470 class unop_incr_operation
1471 : public tuple_holding_operation
<operation_up
>
1475 using tuple_holding_operation::tuple_holding_operation
;
1477 value
*evaluate (struct type
*expect_type
,
1478 struct expression
*exp
,
1479 enum noside noside
) override
1481 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1482 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1485 enum exp_opcode
opcode () const override
1489 using preinc_operation
1490 = unop_incr_operation
<UNOP_PREINCREMENT
, eval_op_preinc
>;
1491 using predec_operation
1492 = unop_incr_operation
<UNOP_PREDECREMENT
, eval_op_predec
>;
1493 using postinc_operation
1494 = unop_incr_operation
<UNOP_POSTINCREMENT
, eval_op_postinc
>;
1495 using postdec_operation
1496 = unop_incr_operation
<UNOP_POSTDECREMENT
, eval_op_postdec
>;
1498 /* Base class for implementations of UNOP_IND. */
1499 class unop_ind_base_operation
1500 : public tuple_holding_operation
<operation_up
>
1504 using tuple_holding_operation::tuple_holding_operation
;
1506 value
*evaluate (struct type
*expect_type
,
1507 struct expression
*exp
,
1508 enum noside noside
) override
1510 if (expect_type
!= nullptr && expect_type
->code () == TYPE_CODE_PTR
)
1511 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1512 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1513 return eval_op_ind (expect_type
, exp
, noside
, val
);
1516 value
*evaluate_for_address (struct expression
*exp
,
1517 enum noside noside
) override
;
1519 value
*evaluate_for_sizeof (struct expression
*exp
,
1520 enum noside noside
) override
;
1522 enum exp_opcode
opcode () const override
1523 { return UNOP_IND
; }
1526 /* Ordinary UNOP_IND implementation. */
1527 class unop_ind_operation
1528 : public unop_ind_base_operation
1532 using unop_ind_base_operation::unop_ind_base_operation
;
1536 void do_generate_ax (struct expression
*exp
,
1537 struct agent_expr
*ax
,
1538 struct axs_value
*value
,
1539 struct type
*cast_type
)
1542 gen_expr_unop (exp
, UNOP_IND
,
1543 std::get
<0> (this->m_storage
).get (),
1548 /* Implement OP_TYPE. */
1549 class type_operation
1550 : public tuple_holding_operation
<struct type
*>
1554 using tuple_holding_operation::tuple_holding_operation
;
1556 value
*evaluate (struct type
*expect_type
,
1557 struct expression
*exp
,
1558 enum noside noside
) override
1560 return eval_op_type (expect_type
, exp
, noside
, std::get
<0> (m_storage
));
1563 enum exp_opcode
opcode () const override
1566 bool constant_p () const override
1570 /* Implement the "typeof" operation. */
1571 class typeof_operation
1572 : public maybe_constant_operation
<operation_up
>
1576 using maybe_constant_operation::maybe_constant_operation
;
1578 value
*evaluate (struct type
*expect_type
,
1579 struct expression
*exp
,
1580 enum noside noside
) override
1582 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1583 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1584 EVAL_AVOID_SIDE_EFFECTS
);
1586 error (_("Attempt to use a type as an expression"));
1589 enum exp_opcode
opcode () const override
1590 { return OP_TYPEOF
; }
1593 /* Implement 'decltype'. */
1594 class decltype_operation
1595 : public maybe_constant_operation
<operation_up
>
1599 using maybe_constant_operation::maybe_constant_operation
;
1601 value
*evaluate (struct type
*expect_type
,
1602 struct expression
*exp
,
1603 enum noside noside
) override
1605 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1608 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1609 EVAL_AVOID_SIDE_EFFECTS
);
1610 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1611 if (sub_op
== BINOP_SUBSCRIPT
1612 || sub_op
== STRUCTOP_MEMBER
1613 || sub_op
== STRUCTOP_MPTR
1614 || sub_op
== UNOP_IND
1615 || sub_op
== STRUCTOP_STRUCT
1616 || sub_op
== STRUCTOP_PTR
1617 || sub_op
== OP_SCOPE
)
1619 struct type
*type
= value_type (result
);
1621 if (!TYPE_IS_REFERENCE (type
))
1623 type
= lookup_lvalue_reference_type (type
);
1624 result
= allocate_value (type
);
1631 error (_("Attempt to use a type as an expression"));
1634 enum exp_opcode
opcode () const override
1635 { return OP_DECLTYPE
; }
1638 /* Implement 'typeid'. */
1639 class typeid_operation
1640 : public tuple_holding_operation
<operation_up
>
1644 using tuple_holding_operation::tuple_holding_operation
;
1646 value
*evaluate (struct type
*expect_type
,
1647 struct expression
*exp
,
1648 enum noside noside
) override
1650 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1651 enum noside sub_noside
1652 = ((sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
1653 ? EVAL_AVOID_SIDE_EFFECTS
1656 value
*result
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1658 if (noside
!= EVAL_NORMAL
)
1659 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
1660 return cplus_typeid (result
);
1663 enum exp_opcode
opcode () const override
1664 { return OP_TYPEID
; }
1667 /* Implement the address-of operation. */
1668 class unop_addr_operation
1669 : public maybe_constant_operation
<operation_up
>
1673 using maybe_constant_operation::maybe_constant_operation
;
1675 value
*evaluate (struct type
*expect_type
,
1676 struct expression
*exp
,
1677 enum noside noside
) override
1679 /* C++: check for and handle pointer to members. */
1680 return std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1683 enum exp_opcode
opcode () const override
1684 { return UNOP_ADDR
; }
1686 /* Return the subexpression. */
1687 const operation_up
&get_expression () const
1689 return std::get
<0> (m_storage
);
1694 void do_generate_ax (struct expression
*exp
,
1695 struct agent_expr
*ax
,
1696 struct axs_value
*value
,
1697 struct type
*cast_type
)
1700 gen_expr_unop (exp
, UNOP_ADDR
,
1701 std::get
<0> (this->m_storage
).get (),
1706 /* Implement 'sizeof'. */
1707 class unop_sizeof_operation
1708 : public maybe_constant_operation
<operation_up
>
1712 using maybe_constant_operation::maybe_constant_operation
;
1714 value
*evaluate (struct type
*expect_type
,
1715 struct expression
*exp
,
1716 enum noside noside
) override
1718 return std::get
<0> (m_storage
)->evaluate_for_sizeof (exp
, noside
);
1721 enum exp_opcode
opcode () const override
1722 { return UNOP_SIZEOF
; }
1726 void do_generate_ax (struct expression
*exp
,
1727 struct agent_expr
*ax
,
1728 struct axs_value
*value
,
1729 struct type
*cast_type
)
1733 /* Implement 'alignof'. */
1734 class unop_alignof_operation
1735 : public maybe_constant_operation
<operation_up
>
1739 using maybe_constant_operation::maybe_constant_operation
;
1741 value
*evaluate (struct type
*expect_type
,
1742 struct expression
*exp
,
1743 enum noside noside
) override
1745 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1746 EVAL_AVOID_SIDE_EFFECTS
);
1747 return eval_op_alignof (expect_type
, exp
, noside
, val
);
1750 enum exp_opcode
opcode () const override
1751 { return UNOP_ALIGNOF
; }
1754 /* Implement UNOP_MEMVAL. */
1755 class unop_memval_operation
1756 : public tuple_holding_operation
<operation_up
, struct type
*>
1760 using tuple_holding_operation::tuple_holding_operation
;
1762 value
*evaluate (struct type
*expect_type
,
1763 struct expression
*exp
,
1764 enum noside noside
) override
1766 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1767 return eval_op_memval (expect_type
, exp
, noside
, val
,
1768 std::get
<1> (m_storage
));
1771 value
*evaluate_for_sizeof (struct expression
*exp
,
1772 enum noside noside
) override
;
1774 value
*evaluate_for_address (struct expression
*exp
,
1775 enum noside noside
) override
;
1777 enum exp_opcode
opcode () const override
1778 { return UNOP_MEMVAL
; }
1780 /* Return the type referenced by this object. */
1781 struct type
*get_type () const
1783 return std::get
<1> (m_storage
);
1788 void do_generate_ax (struct expression
*exp
,
1789 struct agent_expr
*ax
,
1790 struct axs_value
*value
,
1791 struct type
*cast_type
)
1795 /* Implement UNOP_MEMVAL_TYPE. */
1796 class unop_memval_type_operation
1797 : public tuple_holding_operation
<operation_up
, operation_up
>
1801 using tuple_holding_operation::tuple_holding_operation
;
1803 value
*evaluate (struct type
*expect_type
,
1804 struct expression
*exp
,
1805 enum noside noside
) override
1808 = std::get
<0> (m_storage
)->evaluate (expect_type
, exp
,
1809 EVAL_AVOID_SIDE_EFFECTS
);
1810 struct type
*type
= value_type (typeval
);
1811 value
*val
= std::get
<1> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1812 return eval_op_memval (expect_type
, exp
, noside
, val
, type
);
1815 value
*evaluate_for_sizeof (struct expression
*exp
,
1816 enum noside noside
) override
;
1818 value
*evaluate_for_address (struct expression
*exp
,
1819 enum noside noside
) override
;
1821 enum exp_opcode
opcode () const override
1822 { return UNOP_MEMVAL_TYPE
; }
1826 void do_generate_ax (struct expression
*exp
,
1827 struct agent_expr
*ax
,
1828 struct axs_value
*value
,
1829 struct type
*cast_type
)
1833 /* Implement the 'this' expression. */
1834 class op_this_operation
1835 : public tuple_holding_operation
<>
1839 using tuple_holding_operation::tuple_holding_operation
;
1841 value
*evaluate (struct type
*expect_type
,
1842 struct expression
*exp
,
1843 enum noside noside
) override
1845 return value_of_this (exp
->language_defn
);
1848 enum exp_opcode
opcode () const override
1853 void do_generate_ax (struct expression
*exp
,
1854 struct agent_expr
*ax
,
1855 struct axs_value
*value
,
1856 struct type
*cast_type
)
1860 /* Implement the "type instance" operation. */
1861 class type_instance_operation
1862 : public tuple_holding_operation
<type_instance_flags
, std::vector
<type
*>,
1867 using tuple_holding_operation::tuple_holding_operation
;
1869 value
*evaluate (struct type
*expect_type
,
1870 struct expression
*exp
,
1871 enum noside noside
) override
;
1873 enum exp_opcode
opcode () const override
1874 { return TYPE_INSTANCE
; }
1877 /* The assignment operator. */
1878 class assign_operation
1879 : public tuple_holding_operation
<operation_up
, operation_up
>
1883 using tuple_holding_operation::tuple_holding_operation
;
1885 value
*evaluate (struct type
*expect_type
,
1886 struct expression
*exp
,
1887 enum noside noside
) override
1889 value
*lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1890 /* Special-case assignments where the left-hand-side is a
1891 convenience variable -- in these, don't bother setting an
1892 expected type. This avoids a weird case where re-assigning a
1893 string or array to an internal variable could error with "Too
1894 many array elements". */
1895 struct type
*xtype
= (VALUE_LVAL (lhs
) == lval_internalvar
1897 : value_type (lhs
));
1898 value
*rhs
= std::get
<1> (m_storage
)->evaluate (xtype
, exp
, noside
);
1900 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1902 if (binop_user_defined_p (BINOP_ASSIGN
, lhs
, rhs
))
1903 return value_x_binop (lhs
, rhs
, BINOP_ASSIGN
, OP_NULL
, noside
);
1905 return value_assign (lhs
, rhs
);
1908 enum exp_opcode
opcode () const override
1909 { return BINOP_ASSIGN
; }
1911 /* Return the left-hand-side of the assignment. */
1912 operation
*get_lhs () const
1914 return std::get
<0> (m_storage
).get ();
1919 void do_generate_ax (struct expression
*exp
,
1920 struct agent_expr
*ax
,
1921 struct axs_value
*value
,
1922 struct type
*cast_type
)
1926 /* Assignment with modification, like "+=". */
1927 class assign_modify_operation
1928 : public tuple_holding_operation
<exp_opcode
, operation_up
, operation_up
>
1932 using tuple_holding_operation::tuple_holding_operation
;
1934 value
*evaluate (struct type
*expect_type
,
1935 struct expression
*exp
,
1936 enum noside noside
) override
1938 value
*lhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1939 value
*rhs
= std::get
<2> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1940 return eval_binop_assign_modify (expect_type
, exp
, noside
,
1941 std::get
<0> (m_storage
), lhs
, rhs
);
1944 enum exp_opcode
opcode () const override
1945 { return BINOP_ASSIGN_MODIFY
; }
1949 void do_generate_ax (struct expression
*exp
,
1950 struct agent_expr
*ax
,
1951 struct axs_value
*value
,
1952 struct type
*cast_type
)
1956 /* Not a cast! Extract a value of a given type from the contents of a
1957 value. The new value is extracted from the least significant bytes
1958 of the old value. The new value's type must be no bigger than the
1960 class unop_extract_operation
1961 : public maybe_constant_operation
<operation_up
, struct type
*>
1965 using maybe_constant_operation::maybe_constant_operation
;
1967 value
*evaluate (struct type
*expect_type
, struct expression
*exp
,
1968 enum noside noside
) override
;
1970 enum exp_opcode
opcode () const override
1971 { return UNOP_EXTRACT
; }
1973 /* Return the type referenced by this object. */
1974 struct type
*get_type () const
1976 return std::get
<1> (m_storage
);
1981 void do_generate_ax (struct expression
*exp
,
1982 struct agent_expr
*ax
,
1983 struct axs_value
*value
,
1984 struct type
*cast_type
) override
;
1988 class unop_cast_operation
1989 : public maybe_constant_operation
<operation_up
, struct type
*>
1993 using maybe_constant_operation::maybe_constant_operation
;
1995 value
*evaluate (struct type
*expect_type
,
1996 struct expression
*exp
,
1997 enum noside noside
) override
1999 return std::get
<0> (m_storage
)->evaluate_for_cast (std::get
<1> (m_storage
),
2003 enum exp_opcode
opcode () const override
2004 { return UNOP_CAST
; }
2006 /* Return the type referenced by this object. */
2007 struct type
*get_type () const
2009 return std::get
<1> (m_storage
);
2014 void do_generate_ax (struct expression
*exp
,
2015 struct agent_expr
*ax
,
2016 struct axs_value
*value
,
2017 struct type
*cast_type
)
2021 /* A cast, but the type comes from an expression, not a "struct
2023 class unop_cast_type_operation
2024 : public maybe_constant_operation
<operation_up
, operation_up
>
2028 using maybe_constant_operation::maybe_constant_operation
;
2030 value
*evaluate (struct type
*expect_type
,
2031 struct expression
*exp
,
2032 enum noside noside
) override
2034 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2035 EVAL_AVOID_SIDE_EFFECTS
);
2036 return std::get
<1> (m_storage
)->evaluate_for_cast (value_type (val
),
2040 enum exp_opcode
opcode () const override
2041 { return UNOP_CAST_TYPE
; }
2045 void do_generate_ax (struct expression
*exp
,
2046 struct agent_expr
*ax
,
2047 struct axs_value
*value
,
2048 struct type
*cast_type
)
2052 typedef value
*cxx_cast_ftype (struct type
*, value
*);
2054 /* This implements dynamic_cast and reinterpret_cast. static_cast and
2055 const_cast are handled by the ordinary case operations. */
2056 template<exp_opcode OP
, cxx_cast_ftype FUNC
>
2057 class cxx_cast_operation
2058 : public maybe_constant_operation
<operation_up
, operation_up
>
2062 using maybe_constant_operation::maybe_constant_operation
;
2064 value
*evaluate (struct type
*expect_type
,
2065 struct expression
*exp
,
2066 enum noside noside
) override
2068 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2069 EVAL_AVOID_SIDE_EFFECTS
);
2070 struct type
*type
= value_type (val
);
2071 value
*rhs
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
2072 return FUNC (type
, rhs
);
2075 enum exp_opcode
opcode () const override
2079 using dynamic_cast_operation
= cxx_cast_operation
<UNOP_DYNAMIC_CAST
,
2080 value_dynamic_cast
>;
2081 using reinterpret_cast_operation
= cxx_cast_operation
<UNOP_REINTERPRET_CAST
,
2082 value_reinterpret_cast
>;
2084 /* Multi-dimensional subscripting. */
2085 class multi_subscript_operation
2086 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2090 using tuple_holding_operation::tuple_holding_operation
;
2092 value
*evaluate (struct type
*expect_type
,
2093 struct expression
*exp
,
2094 enum noside noside
) override
;
2096 enum exp_opcode
opcode () const override
2097 { return MULTI_SUBSCRIPT
; }
2100 /* The "&&" operator. */
2101 class logical_and_operation
2102 : public maybe_constant_operation
<operation_up
, operation_up
>
2106 using maybe_constant_operation::maybe_constant_operation
;
2108 value
*evaluate (struct type
*expect_type
,
2109 struct expression
*exp
,
2110 enum noside noside
) override
;
2112 enum exp_opcode
opcode () const override
2113 { return BINOP_LOGICAL_AND
; }
2117 void do_generate_ax (struct expression
*exp
,
2118 struct agent_expr
*ax
,
2119 struct axs_value
*value
,
2120 struct type
*cast_type
)
2124 /* The "||" operator. */
2125 class logical_or_operation
2126 : public maybe_constant_operation
<operation_up
, operation_up
>
2130 using maybe_constant_operation::maybe_constant_operation
;
2132 value
*evaluate (struct type
*expect_type
,
2133 struct expression
*exp
,
2134 enum noside noside
) override
;
2136 enum exp_opcode
opcode () const override
2137 { return BINOP_LOGICAL_OR
; }
2141 void do_generate_ax (struct expression
*exp
,
2142 struct agent_expr
*ax
,
2143 struct axs_value
*value
,
2144 struct type
*cast_type
)
2148 /* This class implements ADL (aka Koenig) function calls for C++. It
2149 holds the name of the function to call, the block in which the
2150 lookup should be done, and a vector of arguments. */
2151 class adl_func_operation
2152 : public tuple_holding_operation
<std::string
, const block
*,
2153 std::vector
<operation_up
>>
2157 using tuple_holding_operation::tuple_holding_operation
;
2159 value
*evaluate (struct type
*expect_type
,
2160 struct expression
*exp
,
2161 enum noside noside
) override
;
2163 enum exp_opcode
opcode () const override
2164 { return OP_ADL_FUNC
; }
2167 /* The OP_ARRAY operation. */
2168 class array_operation
2169 : public tuple_holding_operation
<int, int, std::vector
<operation_up
>>
2173 using tuple_holding_operation::tuple_holding_operation
;
2175 value
*evaluate (struct type
*expect_type
,
2176 struct expression
*exp
,
2177 enum noside noside
) override
;
2179 enum exp_opcode
opcode () const override
2180 { return OP_ARRAY
; }
2184 struct value
*evaluate_struct_tuple (struct value
*struct_val
,
2185 struct expression
*exp
,
2186 enum noside noside
, int nargs
);
2189 /* A function call. This holds the callee operation and the
2191 class funcall_operation
2192 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2196 using tuple_holding_operation::tuple_holding_operation
;
2198 value
*evaluate (struct type
*expect_type
,
2199 struct expression
*exp
,
2200 enum noside noside
) override
2202 return std::get
<0> (m_storage
)->evaluate_funcall (expect_type
, exp
, noside
,
2203 std::get
<1> (m_storage
));
2206 enum exp_opcode
opcode () const override
2207 { return OP_FUNCALL
; }
2210 } /* namespace expr */
2212 #endif /* EXPOP_H */