1 /* Definitions for expressions in GDB
3 Copyright (C) 2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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 minimal_symbol
*msymbol
,
57 struct objfile
*objfile
);
58 extern struct value
*eval_op_var_entry_value (struct type
*expect_type
,
59 struct expression
*exp
,
60 enum noside noside
, symbol
*sym
);
61 extern struct value
*eval_op_func_static_var (struct type
*expect_type
,
62 struct expression
*exp
,
64 value
*func
, const char *var
);
65 extern struct value
*eval_op_register (struct type
*expect_type
,
66 struct expression
*exp
,
67 enum noside noside
, const char *name
);
68 extern struct value
*eval_op_string (struct type
*expect_type
,
69 struct expression
*exp
,
70 enum noside noside
, int len
,
72 extern struct value
*eval_op_ternop (struct type
*expect_type
,
73 struct expression
*exp
,
75 struct value
*array
, struct value
*low
,
77 extern struct value
*eval_op_structop_struct (struct type
*expect_type
,
78 struct expression
*exp
,
82 extern struct value
*eval_op_structop_ptr (struct type
*expect_type
,
83 struct expression
*exp
,
87 extern struct value
*eval_op_member (struct type
*expect_type
,
88 struct expression
*exp
,
90 struct value
*arg1
, struct value
*arg2
);
91 extern struct value
*eval_op_concat (struct type
*expect_type
,
92 struct expression
*exp
,
94 struct value
*arg1
, struct value
*arg2
);
95 extern struct value
*eval_op_add (struct type
*expect_type
,
96 struct expression
*exp
,
98 struct value
*arg1
, struct value
*arg2
);
99 extern struct value
*eval_op_sub (struct type
*expect_type
,
100 struct expression
*exp
,
102 struct value
*arg1
, struct value
*arg2
);
103 extern struct value
*eval_op_binary (struct type
*expect_type
,
104 struct expression
*exp
,
105 enum noside noside
, enum exp_opcode op
,
106 struct value
*arg1
, struct value
*arg2
);
107 extern struct value
*eval_op_subscript (struct type
*expect_type
,
108 struct expression
*exp
,
109 enum noside noside
, enum exp_opcode op
,
112 extern struct value
*eval_op_equal (struct type
*expect_type
,
113 struct expression
*exp
,
114 enum noside noside
, enum exp_opcode op
,
117 extern struct value
*eval_op_notequal (struct type
*expect_type
,
118 struct expression
*exp
,
119 enum noside noside
, enum exp_opcode op
,
122 extern struct value
*eval_op_less (struct type
*expect_type
,
123 struct expression
*exp
,
124 enum noside noside
, enum exp_opcode op
,
127 extern struct value
*eval_op_gtr (struct type
*expect_type
,
128 struct expression
*exp
,
129 enum noside noside
, enum exp_opcode op
,
132 extern struct value
*eval_op_geq (struct type
*expect_type
,
133 struct expression
*exp
,
134 enum noside noside
, enum exp_opcode op
,
137 extern struct value
*eval_op_leq (struct type
*expect_type
,
138 struct expression
*exp
,
139 enum noside noside
, enum exp_opcode op
,
142 extern struct value
*eval_op_repeat (struct type
*expect_type
,
143 struct expression
*exp
,
144 enum noside noside
, enum exp_opcode op
,
147 extern struct value
*eval_op_plus (struct type
*expect_type
,
148 struct expression
*exp
,
149 enum noside noside
, enum exp_opcode op
,
151 extern struct value
*eval_op_neg (struct type
*expect_type
,
152 struct expression
*exp
,
153 enum noside noside
, enum exp_opcode op
,
155 extern struct value
*eval_op_complement (struct type
*expect_type
,
156 struct expression
*exp
,
160 extern struct value
*eval_op_lognot (struct type
*expect_type
,
161 struct expression
*exp
,
165 extern struct value
*eval_op_preinc (struct type
*expect_type
,
166 struct expression
*exp
,
170 extern struct value
*eval_op_predec (struct type
*expect_type
,
171 struct expression
*exp
,
175 extern struct value
*eval_op_postinc (struct type
*expect_type
,
176 struct expression
*exp
,
180 extern struct value
*eval_op_postdec (struct type
*expect_type
,
181 struct expression
*exp
,
185 extern struct value
*eval_op_ind (struct type
*expect_type
,
186 struct expression
*exp
,
189 extern struct value
*eval_op_type (struct type
*expect_type
,
190 struct expression
*exp
,
191 enum noside noside
, struct type
*type
);
192 extern struct value
*eval_op_alignof (struct type
*expect_type
,
193 struct expression
*exp
,
196 extern struct value
*eval_op_memval (struct type
*expect_type
,
197 struct expression
*exp
,
199 struct value
*arg1
, struct type
*type
);
200 extern struct value
*eval_binop_assign_modify (struct type
*expect_type
,
201 struct expression
*exp
,
210 /* The check_objfile overloads are used to check whether a particular
211 component of some operation references an objfile. The passed-in
212 objfile will never be a debug objfile. */
214 /* See if EXP_OBJFILE matches OBJFILE. */
216 check_objfile (struct objfile
*exp_objfile
, struct objfile
*objfile
)
218 if (exp_objfile
->separate_debug_objfile_backlink
)
219 exp_objfile
= exp_objfile
->separate_debug_objfile_backlink
;
220 return exp_objfile
== objfile
;
224 check_objfile (struct type
*type
, struct objfile
*objfile
)
226 struct objfile
*ty_objfile
= type
->objfile_owner ();
227 if (ty_objfile
!= nullptr)
228 return check_objfile (ty_objfile
, objfile
);
233 check_objfile (struct symbol
*sym
, struct objfile
*objfile
)
235 return check_objfile (symbol_objfile (sym
), objfile
);
239 check_objfile (const struct block
*block
, struct objfile
*objfile
)
241 return check_objfile (block_objfile (block
), objfile
);
245 check_objfile (minimal_symbol
*minsym
, struct objfile
*objfile
)
247 /* This may seem strange but minsyms are only used with an objfile
253 check_objfile (internalvar
*ivar
, struct objfile
*objfile
)
259 check_objfile (const std::string
&str
, struct objfile
*objfile
)
265 check_objfile (const operation_up
&op
, struct objfile
*objfile
)
267 return op
->uses_objfile (objfile
);
271 check_objfile (enum exp_opcode val
, struct objfile
*objfile
)
277 check_objfile (ULONGEST val
, struct objfile
*objfile
)
284 check_objfile (enum_flags
<T
> val
, struct objfile
*objfile
)
291 check_objfile (const std::vector
<T
> &collection
, struct objfile
*objfile
)
293 for (const auto &item
: collection
)
295 if (check_objfile (item
, objfile
))
301 template<typename S
, typename T
>
303 check_objfile (const std::pair
<S
, T
> &item
, struct objfile
*objfile
)
305 return (check_objfile (item
.first
, objfile
)
306 || check_objfile (item
.second
, objfile
));
310 dump_for_expression (struct ui_file
*stream
, int depth
,
311 const operation_up
&op
)
313 op
->dump (stream
, depth
);
316 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
318 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
319 const std::string
&str
);
320 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
322 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
324 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
326 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
328 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
329 minimal_symbol
*msym
);
330 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
332 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
333 type_instance_flags flags
);
334 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
335 enum c_string_type_values flags
);
336 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
337 enum range_flag flags
);
338 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
343 dump_for_expression (struct ui_file
*stream
, int depth
,
344 const std::vector
<T
> &vals
)
346 fprintf_filtered (stream
, _("%*sVector:\n"), depth
, "");
347 for (auto &item
: vals
)
348 dump_for_expression (stream
, depth
+ 1, item
);
351 template<typename X
, typename Y
>
353 dump_for_expression (struct ui_file
*stream
, int depth
,
354 const std::pair
<X
, Y
> &vals
)
356 dump_for_expression (stream
, depth
, vals
.first
);
357 dump_for_expression (stream
, depth
, vals
.second
);
360 /* Base class for most concrete operations. This class holds data,
361 specified via template parameters, and supplies generic
362 implementations of the 'dump' and 'uses_objfile' methods. */
363 template<typename
... Arg
>
364 class tuple_holding_operation
: public operation
368 explicit tuple_holding_operation (Arg
... args
)
369 : m_storage (std::forward
<Arg
> (args
)...)
373 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation
);
375 bool uses_objfile (struct objfile
*objfile
) const override
377 return do_check_objfile
<0, Arg
...> (objfile
, m_storage
);
380 void dump (struct ui_file
*stream
, int depth
) const override
382 dump_for_expression (stream
, depth
, opcode ());
383 do_dump
<0, Arg
...> (stream
, depth
+ 1, m_storage
);
388 /* Storage for the data. */
389 std::tuple
<Arg
...> m_storage
;
393 /* do_dump does the work of dumping the data. */
394 template<int I
, typename
... T
>
395 typename
std::enable_if
<I
== sizeof... (T
), void>::type
396 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
401 template<int I
, typename
... T
>
402 typename
std::enable_if
<I
< sizeof... (T
), void>::type
403 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
406 dump_for_expression (stream
, depth
, std::get
<I
> (value
));
407 do_dump
<I
+ 1, T
...> (stream
, depth
, value
);
410 /* do_check_objfile does the work of checking whether this object
411 refers to OBJFILE. */
412 template<int I
, typename
... T
>
413 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
414 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
420 template<int I
, typename
... T
>
421 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
422 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
425 if (check_objfile (std::get
<I
> (value
), objfile
))
427 return do_check_objfile
<I
+ 1, T
...> (objfile
, value
);
431 /* The check_constant overloads are used to decide whether a given
432 concrete operation is a constant. This is done by checking the
436 check_constant (const operation_up
&item
)
438 return item
->constant_p ();
442 check_constant (struct minimal_symbol
*msym
)
448 check_constant (struct type
*type
)
454 check_constant (const struct block
*block
)
460 check_constant (const std::string
&str
)
466 check_constant (struct objfile
*objfile
)
472 check_constant (ULONGEST cst
)
478 check_constant (struct symbol
*sym
)
480 enum address_class sc
= SYMBOL_CLASS (sym
);
481 return (sc
== LOC_BLOCK
483 || sc
== LOC_CONST_BYTES
489 check_constant (const std::vector
<T
> &collection
)
491 for (const auto &item
: collection
)
492 if (!check_constant (item
))
497 template<typename S
, typename T
>
499 check_constant (const std::pair
<S
, T
> &item
)
501 return check_constant (item
.first
) && check_constant (item
.second
);
504 /* Base class for concrete operations. This class supplies an
505 implementation of 'constant_p' that works by checking the
507 template<typename
... Arg
>
508 class maybe_constant_operation
509 : public tuple_holding_operation
<Arg
...>
513 using tuple_holding_operation
<Arg
...>::tuple_holding_operation
;
515 bool constant_p () const override
517 return do_check_constant
<0, Arg
...> (this->m_storage
);
522 template<int I
, typename
... T
>
523 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
524 do_check_constant (const std::tuple
<T
...> &value
) const
529 template<int I
, typename
... T
>
530 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
531 do_check_constant (const std::tuple
<T
...> &value
) const
533 if (!check_constant (std::get
<I
> (value
)))
535 return do_check_constant
<I
+ 1, T
...> (value
);
539 /* A floating-point constant. The constant is encoded in the target
542 typedef std::array
<gdb_byte
, 16> float_data
;
544 /* An operation that holds a floating-point constant of a given
547 This does not need the facilities provided by
548 tuple_holding_operation, so it does not use it. */
549 class float_const_operation
554 float_const_operation (struct type
*type
, float_data data
)
560 value
*evaluate (struct type
*expect_type
,
561 struct expression
*exp
,
562 enum noside noside
) override
564 return value_from_contents (m_type
, m_data
.data ());
567 enum exp_opcode
opcode () const override
570 bool constant_p () const override
573 void dump (struct ui_file
*stream
, int depth
) const override
;
581 class scope_operation
582 : public maybe_constant_operation
<struct type
*, std::string
>
586 using maybe_constant_operation::maybe_constant_operation
;
588 value
*evaluate (struct type
*expect_type
,
589 struct expression
*exp
,
590 enum noside noside
) override
592 return eval_op_scope (expect_type
, exp
, noside
,
593 std::get
<0> (m_storage
),
594 std::get
<1> (m_storage
).c_str ());
597 value
*evaluate_for_address (struct expression
*exp
,
598 enum noside noside
) override
;
600 value
*evaluate_funcall (struct type
*expect_type
,
601 struct expression
*exp
,
603 const std::vector
<operation_up
> &args
) override
;
605 enum exp_opcode
opcode () const override
610 void do_generate_ax (struct expression
*exp
,
611 struct agent_expr
*ax
,
612 struct axs_value
*value
,
613 struct type
*cast_type
)
617 /* Compute the value of a variable. */
618 class var_value_operation
619 : public maybe_constant_operation
<symbol
*, const block
*>
623 using maybe_constant_operation::maybe_constant_operation
;
625 value
*evaluate (struct type
*expect_type
,
626 struct expression
*exp
,
627 enum noside noside
) override
;
629 value
*evaluate_with_coercion (struct expression
*exp
,
630 enum noside noside
) override
;
632 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
635 value
*evaluate_for_cast (struct type
*expect_type
,
636 struct expression
*exp
,
637 enum noside noside
) override
;
639 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
642 value
*evaluate_funcall (struct type
*expect_type
,
643 struct expression
*exp
,
645 const std::vector
<operation_up
> &args
) override
;
647 enum exp_opcode
opcode () const override
648 { return OP_VAR_VALUE
; }
652 void do_generate_ax (struct expression
*exp
,
653 struct agent_expr
*ax
,
654 struct axs_value
*value
,
655 struct type
*cast_type
)
659 class long_const_operation
660 : public tuple_holding_operation
<struct type
*, LONGEST
>
664 using tuple_holding_operation::tuple_holding_operation
;
666 value
*evaluate (struct type
*expect_type
,
667 struct expression
*exp
,
668 enum noside noside
) override
670 return value_from_longest (std::get
<0> (m_storage
),
671 std::get
<1> (m_storage
));
674 enum exp_opcode
opcode () const override
677 bool constant_p () const override
682 void do_generate_ax (struct expression
*exp
,
683 struct agent_expr
*ax
,
684 struct axs_value
*value
,
685 struct type
*cast_type
)
689 class var_msym_value_operation
690 : public maybe_constant_operation
<minimal_symbol
*, struct objfile
*>
694 using maybe_constant_operation::maybe_constant_operation
;
696 value
*evaluate (struct type
*expect_type
,
697 struct expression
*exp
,
698 enum noside noside
) override
700 return eval_op_var_msym_value (expect_type
, exp
, noside
, m_outermost
,
701 std::get
<0> (m_storage
),
702 std::get
<1> (m_storage
));
705 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
708 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
711 value
*evaluate_for_cast (struct type
*expect_type
,
712 struct expression
*exp
,
713 enum noside noside
) override
;
715 value
*evaluate_funcall (struct type
*expect_type
,
716 struct expression
*exp
,
718 const std::vector
<operation_up
> &args
) override
720 const char *name
= std::get
<0> (m_storage
)->print_name ();
721 return operation::evaluate_funcall (expect_type
, exp
, noside
, name
, args
);
724 enum exp_opcode
opcode () const override
725 { return OP_VAR_MSYM_VALUE
; }
727 void set_outermost () override
734 /* True if this is the outermost operation in the expression. */
735 bool m_outermost
= false;
737 void do_generate_ax (struct expression
*exp
,
738 struct agent_expr
*ax
,
739 struct axs_value
*value
,
740 struct type
*cast_type
)
744 class var_entry_value_operation
745 : public tuple_holding_operation
<symbol
*>
749 using tuple_holding_operation::tuple_holding_operation
;
751 value
*evaluate (struct type
*expect_type
,
752 struct expression
*exp
,
753 enum noside noside
) override
755 return eval_op_var_entry_value (expect_type
, exp
, noside
,
756 std::get
<0> (m_storage
));
759 enum exp_opcode
opcode () const override
760 { return OP_VAR_ENTRY_VALUE
; }
763 class func_static_var_operation
764 : public maybe_constant_operation
<operation_up
, std::string
>
768 using maybe_constant_operation::maybe_constant_operation
;
770 value
*evaluate (struct type
*expect_type
,
771 struct expression
*exp
,
772 enum noside noside
) override
774 value
*func
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
775 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
776 std::get
<1> (m_storage
).c_str ());
779 enum exp_opcode
opcode () const override
780 { return OP_FUNC_STATIC_VAR
; }
784 : public tuple_holding_operation
<int>
788 using tuple_holding_operation::tuple_holding_operation
;
790 value
*evaluate (struct type
*expect_type
,
791 struct expression
*exp
,
792 enum noside noside
) override
794 return access_value_history (std::get
<0> (m_storage
));
797 enum exp_opcode
opcode () const override
801 class register_operation
802 : public tuple_holding_operation
<std::string
>
806 using tuple_holding_operation::tuple_holding_operation
;
808 value
*evaluate (struct type
*expect_type
,
809 struct expression
*exp
,
810 enum noside noside
) override
812 return eval_op_register (expect_type
, exp
, noside
,
813 std::get
<0> (m_storage
).c_str ());
816 enum exp_opcode
opcode () const override
817 { return OP_REGISTER
; }
821 void do_generate_ax (struct expression
*exp
,
822 struct agent_expr
*ax
,
823 struct axs_value
*value
,
824 struct type
*cast_type
)
829 : public tuple_holding_operation
<bool>
833 using tuple_holding_operation::tuple_holding_operation
;
835 value
*evaluate (struct type
*expect_type
,
836 struct expression
*exp
,
837 enum noside noside
) override
839 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
840 return value_from_longest (type
, std::get
<0> (m_storage
));
843 enum exp_opcode
opcode () const override
846 bool constant_p () const override
850 class internalvar_operation
851 : public tuple_holding_operation
<internalvar
*>
855 using tuple_holding_operation::tuple_holding_operation
;
857 value
*evaluate (struct type
*expect_type
,
858 struct expression
*exp
,
859 enum noside noside
) override
861 return value_of_internalvar (exp
->gdbarch
,
862 std::get
<0> (m_storage
));
865 internalvar
*get_internalvar () const
867 return std::get
<0> (m_storage
);
870 enum exp_opcode
opcode () const override
871 { return OP_INTERNALVAR
; }
875 void do_generate_ax (struct expression
*exp
,
876 struct agent_expr
*ax
,
877 struct axs_value
*value
,
878 struct type
*cast_type
)
882 class string_operation
883 : public tuple_holding_operation
<std::string
>
887 using tuple_holding_operation::tuple_holding_operation
;
889 value
*evaluate (struct type
*expect_type
,
890 struct expression
*exp
,
891 enum noside noside
) override
893 const std::string
&str
= std::get
<0> (m_storage
);
894 return eval_op_string (expect_type
, exp
, noside
,
895 str
.size (), str
.c_str ());
898 enum exp_opcode
opcode () const override
899 { return OP_STRING
; }
902 class ternop_slice_operation
903 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
907 using maybe_constant_operation::maybe_constant_operation
;
909 value
*evaluate (struct type
*expect_type
,
910 struct expression
*exp
,
911 enum noside noside
) override
914 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
916 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
918 = std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
919 return eval_op_ternop (expect_type
, exp
, noside
, array
, low
, upper
);
922 enum exp_opcode
opcode () const override
923 { return TERNOP_SLICE
; }
926 class ternop_cond_operation
927 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
931 using maybe_constant_operation::maybe_constant_operation
;
933 value
*evaluate (struct type
*expect_type
,
934 struct expression
*exp
,
935 enum noside noside
) override
938 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
940 if (value_logical_not (val
))
941 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
942 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
945 enum exp_opcode
opcode () const override
946 { return TERNOP_COND
; }
950 void do_generate_ax (struct expression
*exp
,
951 struct agent_expr
*ax
,
952 struct axs_value
*value
,
953 struct type
*cast_type
)
957 class complex_operation
958 : public maybe_constant_operation
<operation_up
, operation_up
, struct type
*>
962 using maybe_constant_operation::maybe_constant_operation
;
964 value
*evaluate (struct type
*expect_type
,
965 struct expression
*exp
,
966 enum noside noside
) override
968 value
*real
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
969 value
*imag
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
970 return value_literal_complex (real
, imag
,
971 std::get
<2> (m_storage
));
974 enum exp_opcode
opcode () const override
975 { return OP_COMPLEX
; }
978 class structop_base_operation
979 : public tuple_holding_operation
<operation_up
, std::string
>
983 /* Used for completion. Return the field name. */
984 const std::string
&get_string () const
986 return std::get
<1> (m_storage
);
989 /* Used for completion. Evaluate the LHS for type. */
990 value
*evaluate_lhs (struct expression
*exp
)
992 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
993 EVAL_AVOID_SIDE_EFFECTS
);
996 value
*evaluate_funcall (struct type
*expect_type
,
997 struct expression
*exp
,
999 const std::vector
<operation_up
> &args
) override
;
1003 using tuple_holding_operation::tuple_holding_operation
;
1006 class structop_operation
1007 : public structop_base_operation
1011 using structop_base_operation::structop_base_operation
;
1013 value
*evaluate (struct type
*expect_type
,
1014 struct expression
*exp
,
1015 enum noside noside
) override
1017 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1018 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
1019 std::get
<1> (m_storage
).c_str ());
1022 enum exp_opcode
opcode () const override
1023 { return STRUCTOP_STRUCT
; }
1027 void do_generate_ax (struct expression
*exp
,
1028 struct agent_expr
*ax
,
1029 struct axs_value
*value
,
1030 struct type
*cast_type
)
1033 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
1034 std::get
<0> (this->m_storage
).get (),
1035 std::get
<1> (this->m_storage
).c_str (),
1040 class structop_ptr_operation
1041 : public structop_base_operation
1045 using structop_base_operation::structop_base_operation
;
1047 value
*evaluate (struct type
*expect_type
,
1048 struct expression
*exp
,
1049 enum noside noside
) override
1051 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1052 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
1053 std::get
<1> (m_storage
).c_str ());
1056 enum exp_opcode
opcode () const override
1057 { return STRUCTOP_PTR
; }
1061 void do_generate_ax (struct expression
*exp
,
1062 struct agent_expr
*ax
,
1063 struct axs_value
*value
,
1064 struct type
*cast_type
)
1067 gen_expr_structop (exp
, STRUCTOP_PTR
,
1068 std::get
<0> (this->m_storage
).get (),
1069 std::get
<1> (this->m_storage
).c_str (),
1074 class structop_member_base
1075 : public tuple_holding_operation
<operation_up
, operation_up
>
1079 using tuple_holding_operation::tuple_holding_operation
;
1081 value
*evaluate_funcall (struct type
*expect_type
,
1082 struct expression
*exp
,
1084 const std::vector
<operation_up
> &args
) override
;
1087 class structop_member_operation
1088 : public structop_member_base
1092 using structop_member_base::structop_member_base
;
1094 value
*evaluate (struct type
*expect_type
,
1095 struct expression
*exp
,
1096 enum noside noside
) override
1099 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1101 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1102 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1105 enum exp_opcode
opcode () const override
1106 { return STRUCTOP_MEMBER
; }
1109 class structop_mptr_operation
1110 : public structop_member_base
1114 using structop_member_base::structop_member_base
;
1116 value
*evaluate (struct type
*expect_type
,
1117 struct expression
*exp
,
1118 enum noside noside
) override
1121 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1123 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1124 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1127 enum exp_opcode
opcode () const override
1128 { return STRUCTOP_MPTR
; }
1131 class concat_operation
1132 : public maybe_constant_operation
<operation_up
, operation_up
>
1136 using maybe_constant_operation::maybe_constant_operation
;
1138 value
*evaluate (struct type
*expect_type
,
1139 struct expression
*exp
,
1140 enum noside noside
) override
1143 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1145 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1146 return eval_op_concat (expect_type
, exp
, noside
, lhs
, rhs
);
1149 enum exp_opcode
opcode () const override
1150 { return BINOP_CONCAT
; }
1154 : public maybe_constant_operation
<operation_up
, operation_up
>
1158 using maybe_constant_operation::maybe_constant_operation
;
1160 value
*evaluate (struct type
*expect_type
,
1161 struct expression
*exp
,
1162 enum noside noside
) override
1165 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1167 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1168 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1171 enum exp_opcode
opcode () const override
1172 { return BINOP_ADD
; }
1176 void do_generate_ax (struct expression
*exp
,
1177 struct agent_expr
*ax
,
1178 struct axs_value
*value
,
1179 struct type
*cast_type
)
1182 gen_expr_binop (exp
, BINOP_ADD
,
1183 std::get
<0> (this->m_storage
).get (),
1184 std::get
<1> (this->m_storage
).get (),
1190 : public maybe_constant_operation
<operation_up
, operation_up
>
1194 using maybe_constant_operation::maybe_constant_operation
;
1196 value
*evaluate (struct type
*expect_type
,
1197 struct expression
*exp
,
1198 enum noside noside
) override
1201 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1203 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1204 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1207 enum exp_opcode
opcode () const override
1208 { return BINOP_SUB
; }
1212 void do_generate_ax (struct expression
*exp
,
1213 struct agent_expr
*ax
,
1214 struct axs_value
*value
,
1215 struct type
*cast_type
)
1218 gen_expr_binop (exp
, BINOP_SUB
,
1219 std::get
<0> (this->m_storage
).get (),
1220 std::get
<1> (this->m_storage
).get (),
1225 typedef struct value
*binary_ftype (struct type
*expect_type
,
1226 struct expression
*exp
,
1227 enum noside noside
, enum exp_opcode op
,
1228 struct value
*arg1
, struct value
*arg2
);
1230 template<enum exp_opcode OP
, binary_ftype FUNC
>
1231 class binop_operation
1232 : public maybe_constant_operation
<operation_up
, operation_up
>
1236 using maybe_constant_operation::maybe_constant_operation
;
1238 value
*evaluate (struct type
*expect_type
,
1239 struct expression
*exp
,
1240 enum noside noside
) override
1243 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1245 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1246 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1249 enum exp_opcode
opcode () const override
1253 template<enum exp_opcode OP
, binary_ftype FUNC
>
1254 class usual_ax_binop_operation
1255 : public binop_operation
<OP
, FUNC
>
1259 using binop_operation
<OP
, FUNC
>::binop_operation
;
1263 void do_generate_ax (struct expression
*exp
,
1264 struct agent_expr
*ax
,
1265 struct axs_value
*value
,
1266 struct type
*cast_type
)
1269 gen_expr_binop (exp
, OP
,
1270 std::get
<0> (this->m_storage
).get (),
1271 std::get
<1> (this->m_storage
).get (),
1276 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1277 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1278 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1280 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1281 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1282 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1283 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1284 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1285 using bitwise_and_operation
1286 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1287 using bitwise_ior_operation
1288 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1289 using bitwise_xor_operation
1290 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1292 class subscript_operation
1293 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1296 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1297 eval_op_subscript
>::usual_ax_binop_operation
;
1299 value
*evaluate_for_sizeof (struct expression
*exp
,
1300 enum noside noside
) override
;
1303 /* Implementation of comparison operations. */
1304 template<enum exp_opcode OP
, binary_ftype FUNC
>
1305 class comparison_operation
1306 : public usual_ax_binop_operation
<OP
, FUNC
>
1310 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1312 value
*evaluate (struct type
*expect_type
,
1313 struct expression
*exp
,
1314 enum noside noside
) override
1317 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1319 = std::get
<1> (this->m_storage
)->evaluate (value_type (lhs
), exp
,
1321 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1325 using equal_operation
= comparison_operation
<BINOP_EQUAL
, eval_op_equal
>;
1326 using notequal_operation
1327 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1328 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1329 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1330 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1331 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1333 /* Implement the GDB '@' repeat operator. */
1334 class repeat_operation
1335 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1337 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1341 void do_generate_ax (struct expression
*exp
,
1342 struct agent_expr
*ax
,
1343 struct axs_value
*value
,
1344 struct type
*cast_type
)
1348 /* C-style comma operator. */
1349 class comma_operation
1350 : public maybe_constant_operation
<operation_up
, operation_up
>
1354 using maybe_constant_operation::maybe_constant_operation
;
1356 value
*evaluate (struct type
*expect_type
,
1357 struct expression
*exp
,
1358 enum noside noside
) override
1360 /* The left-hand-side is only evaluated for side effects, so don't
1361 bother in other modes. */
1362 if (noside
== EVAL_NORMAL
)
1363 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1364 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1367 enum exp_opcode
opcode () const override
1368 { return BINOP_COMMA
; }
1372 void do_generate_ax (struct expression
*exp
,
1373 struct agent_expr
*ax
,
1374 struct axs_value
*value
,
1375 struct type
*cast_type
)
1379 typedef struct value
*unary_ftype (struct type
*expect_type
,
1380 struct expression
*exp
,
1381 enum noside noside
, enum exp_opcode op
,
1382 struct value
*arg1
);
1384 /* Base class for unary operations. */
1385 template<enum exp_opcode OP
, unary_ftype FUNC
>
1386 class unop_operation
1387 : public maybe_constant_operation
<operation_up
>
1391 using maybe_constant_operation::maybe_constant_operation
;
1393 value
*evaluate (struct type
*expect_type
,
1394 struct expression
*exp
,
1395 enum noside noside
) override
1397 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1398 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1401 enum exp_opcode
opcode () const override
1405 /* Unary operations that can also be turned into agent expressions in
1407 template<enum exp_opcode OP
, unary_ftype FUNC
>
1408 class usual_ax_unop_operation
1409 : public unop_operation
<OP
, FUNC
>
1411 using unop_operation
<OP
, FUNC
>::unop_operation
;
1415 void do_generate_ax (struct expression
*exp
,
1416 struct agent_expr
*ax
,
1417 struct axs_value
*value
,
1418 struct type
*cast_type
)
1421 gen_expr_unop (exp
, OP
,
1422 std::get
<0> (this->m_storage
).get (),
1427 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1428 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1429 using unary_complement_operation
1430 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1431 using unary_logical_not_operation
1432 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1434 /* Handle pre- and post- increment and -decrement. */
1435 template<enum exp_opcode OP
, unary_ftype FUNC
>
1436 class unop_incr_operation
1437 : public tuple_holding_operation
<operation_up
>
1441 using tuple_holding_operation::tuple_holding_operation
;
1443 value
*evaluate (struct type
*expect_type
,
1444 struct expression
*exp
,
1445 enum noside noside
) override
1447 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1448 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1451 enum exp_opcode
opcode () const override
1455 using preinc_operation
1456 = unop_incr_operation
<UNOP_PREINCREMENT
, eval_op_preinc
>;
1457 using predec_operation
1458 = unop_incr_operation
<UNOP_PREDECREMENT
, eval_op_predec
>;
1459 using postinc_operation
1460 = unop_incr_operation
<UNOP_POSTINCREMENT
, eval_op_postinc
>;
1461 using postdec_operation
1462 = unop_incr_operation
<UNOP_POSTDECREMENT
, eval_op_postdec
>;
1464 /* Base class for implementations of UNOP_IND. */
1465 class unop_ind_base_operation
1466 : public tuple_holding_operation
<operation_up
>
1470 using tuple_holding_operation::tuple_holding_operation
;
1472 value
*evaluate (struct type
*expect_type
,
1473 struct expression
*exp
,
1474 enum noside noside
) override
1476 if (expect_type
!= nullptr && expect_type
->code () == TYPE_CODE_PTR
)
1477 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1478 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1479 return eval_op_ind (expect_type
, exp
, noside
, val
);
1482 value
*evaluate_for_address (struct expression
*exp
,
1483 enum noside noside
) override
;
1485 value
*evaluate_for_sizeof (struct expression
*exp
,
1486 enum noside noside
) override
;
1488 enum exp_opcode
opcode () const override
1489 { return UNOP_IND
; }
1492 /* Ordinary UNOP_IND implementation. */
1493 class unop_ind_operation
1494 : public unop_ind_base_operation
1498 using unop_ind_base_operation::unop_ind_base_operation
;
1502 void do_generate_ax (struct expression
*exp
,
1503 struct agent_expr
*ax
,
1504 struct axs_value
*value
,
1505 struct type
*cast_type
)
1508 gen_expr_unop (exp
, UNOP_IND
,
1509 std::get
<0> (this->m_storage
).get (),
1514 /* Implement OP_TYPE. */
1515 class type_operation
1516 : public tuple_holding_operation
<struct type
*>
1520 using tuple_holding_operation::tuple_holding_operation
;
1522 value
*evaluate (struct type
*expect_type
,
1523 struct expression
*exp
,
1524 enum noside noside
) override
1526 return eval_op_type (expect_type
, exp
, noside
, std::get
<0> (m_storage
));
1529 enum exp_opcode
opcode () const override
1532 bool constant_p () const override
1536 /* Implement the "typeof" operation. */
1537 class typeof_operation
1538 : public maybe_constant_operation
<operation_up
>
1542 using maybe_constant_operation::maybe_constant_operation
;
1544 value
*evaluate (struct type
*expect_type
,
1545 struct expression
*exp
,
1546 enum noside noside
) override
1548 if (noside
== EVAL_SKIP
)
1549 return eval_skip_value (exp
);
1550 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1551 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1552 EVAL_AVOID_SIDE_EFFECTS
);
1554 error (_("Attempt to use a type as an expression"));
1557 enum exp_opcode
opcode () const override
1558 { return OP_TYPEOF
; }
1561 /* Implement 'decltype'. */
1562 class decltype_operation
1563 : public maybe_constant_operation
<operation_up
>
1567 using maybe_constant_operation::maybe_constant_operation
;
1569 value
*evaluate (struct type
*expect_type
,
1570 struct expression
*exp
,
1571 enum noside noside
) override
1573 if (noside
== EVAL_SKIP
)
1574 return eval_skip_value (exp
);
1575 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1578 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1579 EVAL_AVOID_SIDE_EFFECTS
);
1580 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1581 if (sub_op
== BINOP_SUBSCRIPT
1582 || sub_op
== STRUCTOP_MEMBER
1583 || sub_op
== STRUCTOP_MPTR
1584 || sub_op
== UNOP_IND
1585 || sub_op
== STRUCTOP_STRUCT
1586 || sub_op
== STRUCTOP_PTR
1587 || sub_op
== OP_SCOPE
)
1589 struct type
*type
= value_type (result
);
1591 if (!TYPE_IS_REFERENCE (type
))
1593 type
= lookup_lvalue_reference_type (type
);
1594 result
= allocate_value (type
);
1601 error (_("Attempt to use a type as an expression"));
1604 enum exp_opcode
opcode () const override
1605 { return OP_DECLTYPE
; }
1608 /* Implement 'typeid'. */
1609 class typeid_operation
1610 : public tuple_holding_operation
<operation_up
>
1614 using tuple_holding_operation::tuple_holding_operation
;
1616 value
*evaluate (struct type
*expect_type
,
1617 struct expression
*exp
,
1618 enum noside noside
) override
1620 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1621 enum noside sub_noside
1622 = ((sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
1623 ? EVAL_AVOID_SIDE_EFFECTS
1626 value
*result
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1628 if (noside
!= EVAL_NORMAL
)
1629 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
1630 return cplus_typeid (result
);
1633 enum exp_opcode
opcode () const override
1634 { return OP_TYPEID
; }
1637 /* Implement the address-of operation. */
1638 class unop_addr_operation
1639 : public maybe_constant_operation
<operation_up
>
1643 using maybe_constant_operation::maybe_constant_operation
;
1645 value
*evaluate (struct type
*expect_type
,
1646 struct expression
*exp
,
1647 enum noside noside
) override
1649 /* C++: check for and handle pointer to members. */
1650 if (noside
== EVAL_SKIP
)
1651 return eval_skip_value (exp
);
1653 return std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1656 enum exp_opcode
opcode () const override
1657 { return UNOP_ADDR
; }
1659 /* Return the subexpression. */
1660 const operation_up
&get_expression () const
1662 return std::get
<0> (m_storage
);
1667 void do_generate_ax (struct expression
*exp
,
1668 struct agent_expr
*ax
,
1669 struct axs_value
*value
,
1670 struct type
*cast_type
)
1673 gen_expr_unop (exp
, UNOP_ADDR
,
1674 std::get
<0> (this->m_storage
).get (),
1679 /* Implement 'sizeof'. */
1680 class unop_sizeof_operation
1681 : public maybe_constant_operation
<operation_up
>
1685 using maybe_constant_operation::maybe_constant_operation
;
1687 value
*evaluate (struct type
*expect_type
,
1688 struct expression
*exp
,
1689 enum noside noside
) override
1691 if (noside
== EVAL_SKIP
)
1692 return eval_skip_value (exp
);
1693 return std::get
<0> (m_storage
)->evaluate_for_sizeof (exp
, noside
);
1696 enum exp_opcode
opcode () const override
1697 { return UNOP_SIZEOF
; }
1701 void do_generate_ax (struct expression
*exp
,
1702 struct agent_expr
*ax
,
1703 struct axs_value
*value
,
1704 struct type
*cast_type
)
1708 /* Implement 'alignof'. */
1709 class unop_alignof_operation
1710 : public maybe_constant_operation
<operation_up
>
1714 using maybe_constant_operation::maybe_constant_operation
;
1716 value
*evaluate (struct type
*expect_type
,
1717 struct expression
*exp
,
1718 enum noside noside
) override
1720 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1721 EVAL_AVOID_SIDE_EFFECTS
);
1722 return eval_op_alignof (expect_type
, exp
, noside
, val
);
1725 enum exp_opcode
opcode () const override
1726 { return UNOP_ALIGNOF
; }
1729 /* Implement UNOP_MEMVAL. */
1730 class unop_memval_operation
1731 : public tuple_holding_operation
<operation_up
, struct type
*>
1735 using tuple_holding_operation::tuple_holding_operation
;
1737 value
*evaluate (struct type
*expect_type
,
1738 struct expression
*exp
,
1739 enum noside noside
) override
1741 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1742 return eval_op_memval (expect_type
, exp
, noside
, val
,
1743 std::get
<1> (m_storage
));
1746 value
*evaluate_for_sizeof (struct expression
*exp
,
1747 enum noside noside
) override
;
1749 value
*evaluate_for_address (struct expression
*exp
,
1750 enum noside noside
) override
;
1752 enum exp_opcode
opcode () const override
1753 { return UNOP_MEMVAL
; }
1757 void do_generate_ax (struct expression
*exp
,
1758 struct agent_expr
*ax
,
1759 struct axs_value
*value
,
1760 struct type
*cast_type
)
1764 /* Implement UNOP_MEMVAL_TYPE. */
1765 class unop_memval_type_operation
1766 : public tuple_holding_operation
<operation_up
, operation_up
>
1770 using tuple_holding_operation::tuple_holding_operation
;
1772 value
*evaluate (struct type
*expect_type
,
1773 struct expression
*exp
,
1774 enum noside noside
) override
1777 = std::get
<0> (m_storage
)->evaluate (expect_type
, exp
,
1778 EVAL_AVOID_SIDE_EFFECTS
);
1779 struct type
*type
= value_type (typeval
);
1780 value
*val
= std::get
<1> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1781 return eval_op_memval (expect_type
, exp
, noside
, val
, type
);
1784 value
*evaluate_for_sizeof (struct expression
*exp
,
1785 enum noside noside
) override
;
1787 value
*evaluate_for_address (struct expression
*exp
,
1788 enum noside noside
) override
;
1790 enum exp_opcode
opcode () const override
1791 { return UNOP_MEMVAL_TYPE
; }
1795 void do_generate_ax (struct expression
*exp
,
1796 struct agent_expr
*ax
,
1797 struct axs_value
*value
,
1798 struct type
*cast_type
)
1802 /* Implement the 'this' expression. */
1803 class op_this_operation
1804 : public tuple_holding_operation
<>
1808 using tuple_holding_operation::tuple_holding_operation
;
1810 value
*evaluate (struct type
*expect_type
,
1811 struct expression
*exp
,
1812 enum noside noside
) override
1814 return value_of_this (exp
->language_defn
);
1817 enum exp_opcode
opcode () const override
1822 void do_generate_ax (struct expression
*exp
,
1823 struct agent_expr
*ax
,
1824 struct axs_value
*value
,
1825 struct type
*cast_type
)
1829 /* Implement the "type instance" operation. */
1830 class type_instance_operation
1831 : public tuple_holding_operation
<type_instance_flags
, std::vector
<type
*>,
1836 using tuple_holding_operation::tuple_holding_operation
;
1838 value
*evaluate (struct type
*expect_type
,
1839 struct expression
*exp
,
1840 enum noside noside
) override
;
1842 enum exp_opcode
opcode () const override
1843 { return TYPE_INSTANCE
; }
1846 /* The assignment operator. */
1847 class assign_operation
1848 : public tuple_holding_operation
<operation_up
, operation_up
>
1852 using tuple_holding_operation::tuple_holding_operation
;
1854 value
*evaluate (struct type
*expect_type
,
1855 struct expression
*exp
,
1856 enum noside noside
) override
1858 value
*lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1859 /* Special-case assignments where the left-hand-side is a
1860 convenience variable -- in these, don't bother setting an
1861 expected type. This avoids a weird case where re-assigning a
1862 string or array to an internal variable could error with "Too
1863 many array elements". */
1864 struct type
*xtype
= (VALUE_LVAL (lhs
) == lval_internalvar
1866 : value_type (lhs
));
1867 value
*rhs
= std::get
<1> (m_storage
)->evaluate (xtype
, exp
, noside
);
1869 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1871 if (binop_user_defined_p (BINOP_ASSIGN
, lhs
, rhs
))
1872 return value_x_binop (lhs
, rhs
, BINOP_ASSIGN
, OP_NULL
, noside
);
1874 return value_assign (lhs
, rhs
);
1877 enum exp_opcode
opcode () const override
1878 { return BINOP_ASSIGN
; }
1882 void do_generate_ax (struct expression
*exp
,
1883 struct agent_expr
*ax
,
1884 struct axs_value
*value
,
1885 struct type
*cast_type
)
1889 /* Assignment with modification, like "+=". */
1890 class assign_modify_operation
1891 : public tuple_holding_operation
<exp_opcode
, operation_up
, operation_up
>
1895 using tuple_holding_operation::tuple_holding_operation
;
1897 value
*evaluate (struct type
*expect_type
,
1898 struct expression
*exp
,
1899 enum noside noside
) override
1901 value
*lhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1902 value
*rhs
= std::get
<2> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1903 return eval_binop_assign_modify (expect_type
, exp
, noside
,
1904 std::get
<0> (m_storage
), lhs
, rhs
);
1907 enum exp_opcode
opcode () const override
1908 { return BINOP_ASSIGN_MODIFY
; }
1912 void do_generate_ax (struct expression
*exp
,
1913 struct agent_expr
*ax
,
1914 struct axs_value
*value
,
1915 struct type
*cast_type
)
1920 class unop_cast_operation
1921 : public maybe_constant_operation
<operation_up
, struct type
*>
1925 using maybe_constant_operation::maybe_constant_operation
;
1927 value
*evaluate (struct type
*expect_type
,
1928 struct expression
*exp
,
1929 enum noside noside
) override
1931 return std::get
<0> (m_storage
)->evaluate_for_cast (std::get
<1> (m_storage
),
1935 enum exp_opcode
opcode () const override
1936 { return UNOP_CAST
; }
1940 void do_generate_ax (struct expression
*exp
,
1941 struct agent_expr
*ax
,
1942 struct axs_value
*value
,
1943 struct type
*cast_type
)
1947 /* A cast, but the type comes from an expression, not a "struct
1949 class unop_cast_type_operation
1950 : public maybe_constant_operation
<operation_up
, operation_up
>
1954 using maybe_constant_operation::maybe_constant_operation
;
1956 value
*evaluate (struct type
*expect_type
,
1957 struct expression
*exp
,
1958 enum noside noside
) override
1960 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1961 EVAL_AVOID_SIDE_EFFECTS
);
1962 return std::get
<1> (m_storage
)->evaluate_for_cast (value_type (val
),
1966 enum exp_opcode
opcode () const override
1967 { return UNOP_CAST_TYPE
; }
1971 void do_generate_ax (struct expression
*exp
,
1972 struct agent_expr
*ax
,
1973 struct axs_value
*value
,
1974 struct type
*cast_type
)
1978 typedef value
*cxx_cast_ftype (struct type
*, value
*);
1980 /* This implements dynamic_cast and reinterpret_cast. static_cast and
1981 const_cast are handled by the ordinary case operations. */
1982 template<exp_opcode OP
, cxx_cast_ftype FUNC
>
1983 class cxx_cast_operation
1984 : public maybe_constant_operation
<operation_up
, operation_up
>
1988 using maybe_constant_operation::maybe_constant_operation
;
1990 value
*evaluate (struct type
*expect_type
,
1991 struct expression
*exp
,
1992 enum noside noside
) override
1994 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1995 EVAL_AVOID_SIDE_EFFECTS
);
1996 struct type
*type
= value_type (val
);
1997 value
*rhs
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
1998 if (noside
== EVAL_SKIP
)
1999 return eval_skip_value (exp
);
2000 return FUNC (type
, rhs
);
2003 enum exp_opcode
opcode () const override
2007 using dynamic_cast_operation
= cxx_cast_operation
<UNOP_DYNAMIC_CAST
,
2008 value_dynamic_cast
>;
2009 using reinterpret_cast_operation
= cxx_cast_operation
<UNOP_REINTERPRET_CAST
,
2010 value_reinterpret_cast
>;
2012 /* Multi-dimensional subscripting. */
2013 class multi_subscript_operation
2014 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2018 using tuple_holding_operation::tuple_holding_operation
;
2020 value
*evaluate (struct type
*expect_type
,
2021 struct expression
*exp
,
2022 enum noside noside
) override
;
2024 enum exp_opcode
opcode () const override
2025 { return MULTI_SUBSCRIPT
; }
2028 /* The "&&" operator. */
2029 class logical_and_operation
2030 : public maybe_constant_operation
<operation_up
, operation_up
>
2034 using maybe_constant_operation::maybe_constant_operation
;
2036 value
*evaluate (struct type
*expect_type
,
2037 struct expression
*exp
,
2038 enum noside noside
) override
;
2040 enum exp_opcode
opcode () const override
2041 { return BINOP_LOGICAL_AND
; }
2045 void do_generate_ax (struct expression
*exp
,
2046 struct agent_expr
*ax
,
2047 struct axs_value
*value
,
2048 struct type
*cast_type
)
2052 /* The "||" operator. */
2053 class logical_or_operation
2054 : public maybe_constant_operation
<operation_up
, operation_up
>
2058 using maybe_constant_operation::maybe_constant_operation
;
2060 value
*evaluate (struct type
*expect_type
,
2061 struct expression
*exp
,
2062 enum noside noside
) override
;
2064 enum exp_opcode
opcode () const override
2065 { return BINOP_LOGICAL_OR
; }
2069 void do_generate_ax (struct expression
*exp
,
2070 struct agent_expr
*ax
,
2071 struct axs_value
*value
,
2072 struct type
*cast_type
)
2076 /* This class implements ADL (aka Koenig) function calls for C++. It
2077 holds the name of the function to call, the block in which the
2078 lookup should be done, and a vector of arguments. */
2079 class adl_func_operation
2080 : public tuple_holding_operation
<std::string
, const block
*,
2081 std::vector
<operation_up
>>
2085 using tuple_holding_operation::tuple_holding_operation
;
2087 value
*evaluate (struct type
*expect_type
,
2088 struct expression
*exp
,
2089 enum noside noside
) override
;
2091 enum exp_opcode
opcode () const override
2092 { return OP_ADL_FUNC
; }
2095 /* The OP_ARRAY operation. */
2096 class array_operation
2097 : public tuple_holding_operation
<int, int, std::vector
<operation_up
>>
2101 using tuple_holding_operation::tuple_holding_operation
;
2103 value
*evaluate (struct type
*expect_type
,
2104 struct expression
*exp
,
2105 enum noside noside
) override
;
2107 enum exp_opcode
opcode () const override
2108 { return OP_ARRAY
; }
2112 struct value
*evaluate_struct_tuple (struct value
*struct_val
,
2113 struct expression
*exp
,
2114 enum noside noside
, int nargs
);
2117 /* A function call. This holds the callee operation and the
2119 class funcall_operation
2120 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2124 using tuple_holding_operation::tuple_holding_operation
;
2126 value
*evaluate (struct type
*expect_type
,
2127 struct expression
*exp
,
2128 enum noside noside
) override
2130 return std::get
<0> (m_storage
)->evaluate_funcall (expect_type
, exp
, noside
,
2131 std::get
<1> (m_storage
));
2134 enum exp_opcode
opcode () const override
2135 { return OP_FUNCALL
; }
2138 } /* namespace expr */
2140 #endif /* EXPOP_H */