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 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_string (struct type
*expect_type
,
68 struct expression
*exp
,
69 enum noside noside
, int len
,
71 extern struct value
*eval_op_ternop (struct type
*expect_type
,
72 struct expression
*exp
,
74 struct value
*array
, struct value
*low
,
76 extern struct value
*eval_op_structop_struct (struct type
*expect_type
,
77 struct expression
*exp
,
81 extern struct value
*eval_op_structop_ptr (struct type
*expect_type
,
82 struct expression
*exp
,
86 extern struct value
*eval_op_member (struct type
*expect_type
,
87 struct expression
*exp
,
89 struct value
*arg1
, struct value
*arg2
);
90 extern struct value
*eval_op_concat (struct type
*expect_type
,
91 struct expression
*exp
,
93 struct value
*arg1
, struct value
*arg2
);
94 extern struct value
*eval_op_add (struct type
*expect_type
,
95 struct expression
*exp
,
97 struct value
*arg1
, struct value
*arg2
);
98 extern struct value
*eval_op_sub (struct type
*expect_type
,
99 struct expression
*exp
,
101 struct value
*arg1
, struct value
*arg2
);
102 extern struct value
*eval_op_binary (struct type
*expect_type
,
103 struct expression
*exp
,
104 enum noside noside
, enum exp_opcode op
,
105 struct value
*arg1
, struct value
*arg2
);
106 extern struct value
*eval_op_subscript (struct type
*expect_type
,
107 struct expression
*exp
,
108 enum noside noside
, enum exp_opcode op
,
111 extern struct value
*eval_op_equal (struct type
*expect_type
,
112 struct expression
*exp
,
113 enum noside noside
, enum exp_opcode op
,
116 extern struct value
*eval_op_notequal (struct type
*expect_type
,
117 struct expression
*exp
,
118 enum noside noside
, enum exp_opcode op
,
121 extern struct value
*eval_op_less (struct type
*expect_type
,
122 struct expression
*exp
,
123 enum noside noside
, enum exp_opcode op
,
126 extern struct value
*eval_op_gtr (struct type
*expect_type
,
127 struct expression
*exp
,
128 enum noside noside
, enum exp_opcode op
,
131 extern struct value
*eval_op_geq (struct type
*expect_type
,
132 struct expression
*exp
,
133 enum noside noside
, enum exp_opcode op
,
136 extern struct value
*eval_op_leq (struct type
*expect_type
,
137 struct expression
*exp
,
138 enum noside noside
, enum exp_opcode op
,
141 extern struct value
*eval_op_repeat (struct type
*expect_type
,
142 struct expression
*exp
,
143 enum noside noside
, enum exp_opcode op
,
146 extern struct value
*eval_op_plus (struct type
*expect_type
,
147 struct expression
*exp
,
148 enum noside noside
, enum exp_opcode op
,
150 extern struct value
*eval_op_neg (struct type
*expect_type
,
151 struct expression
*exp
,
152 enum noside noside
, enum exp_opcode op
,
154 extern struct value
*eval_op_complement (struct type
*expect_type
,
155 struct expression
*exp
,
159 extern struct value
*eval_op_lognot (struct type
*expect_type
,
160 struct expression
*exp
,
164 extern struct value
*eval_op_preinc (struct type
*expect_type
,
165 struct expression
*exp
,
169 extern struct value
*eval_op_predec (struct type
*expect_type
,
170 struct expression
*exp
,
174 extern struct value
*eval_op_postinc (struct type
*expect_type
,
175 struct expression
*exp
,
179 extern struct value
*eval_op_postdec (struct type
*expect_type
,
180 struct expression
*exp
,
184 extern struct value
*eval_op_ind (struct type
*expect_type
,
185 struct expression
*exp
,
188 extern struct value
*eval_op_type (struct type
*expect_type
,
189 struct expression
*exp
,
190 enum noside noside
, struct type
*type
);
191 extern struct value
*eval_op_alignof (struct type
*expect_type
,
192 struct expression
*exp
,
195 extern struct value
*eval_op_memval (struct type
*expect_type
,
196 struct expression
*exp
,
198 struct value
*arg1
, struct type
*type
);
199 extern struct value
*eval_binop_assign_modify (struct type
*expect_type
,
200 struct expression
*exp
,
211 /* The check_objfile overloads are used to check whether a particular
212 component of some operation references an objfile. The passed-in
213 objfile will never be a debug objfile. */
215 /* See if EXP_OBJFILE matches OBJFILE. */
217 check_objfile (struct objfile
*exp_objfile
, struct objfile
*objfile
)
219 if (exp_objfile
->separate_debug_objfile_backlink
)
220 exp_objfile
= exp_objfile
->separate_debug_objfile_backlink
;
221 return exp_objfile
== objfile
;
225 check_objfile (struct type
*type
, struct objfile
*objfile
)
227 struct objfile
*ty_objfile
= type
->objfile_owner ();
228 if (ty_objfile
!= nullptr)
229 return check_objfile (ty_objfile
, objfile
);
234 check_objfile (struct symbol
*sym
, struct objfile
*objfile
)
236 return check_objfile (symbol_objfile (sym
), objfile
);
240 check_objfile (const struct block
*block
, struct objfile
*objfile
)
242 return check_objfile (block_objfile (block
), objfile
);
246 check_objfile (const block_symbol
&sym
, struct objfile
*objfile
)
248 return (check_objfile (sym
.symbol
, objfile
)
249 || check_objfile (sym
.block
, objfile
));
253 check_objfile (bound_minimal_symbol minsym
, struct objfile
*objfile
)
255 return check_objfile (minsym
.objfile
, objfile
);
259 check_objfile (internalvar
*ivar
, struct objfile
*objfile
)
265 check_objfile (const std::string
&str
, struct objfile
*objfile
)
271 check_objfile (const operation_up
&op
, struct objfile
*objfile
)
273 return op
->uses_objfile (objfile
);
277 check_objfile (enum exp_opcode val
, struct objfile
*objfile
)
283 check_objfile (ULONGEST val
, struct objfile
*objfile
)
290 check_objfile (enum_flags
<T
> val
, struct objfile
*objfile
)
297 check_objfile (const std::vector
<T
> &collection
, struct objfile
*objfile
)
299 for (const auto &item
: collection
)
301 if (check_objfile (item
, objfile
))
307 template<typename S
, typename T
>
309 check_objfile (const std::pair
<S
, T
> &item
, struct objfile
*objfile
)
311 return (check_objfile (item
.first
, objfile
)
312 || check_objfile (item
.second
, objfile
));
315 extern bool check_objfile (const std::unique_ptr
<ada_component
> &comp
,
316 struct objfile
*objfile
);
319 dump_for_expression (struct ui_file
*stream
, int depth
,
320 const operation_up
&op
)
322 op
->dump (stream
, 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
,
328 const std::string
&str
);
329 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
331 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
333 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
335 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
337 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
338 const block_symbol
&sym
);
339 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
340 bound_minimal_symbol msym
);
341 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
343 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
344 type_instance_flags flags
);
345 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
346 enum c_string_type_values flags
);
347 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
348 enum range_flag flags
);
349 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
350 const std::unique_ptr
<ada_component
> &comp
);
354 dump_for_expression (struct ui_file
*stream
, int depth
,
355 const std::vector
<T
> &vals
)
357 fprintf_filtered (stream
, _("%*sVector:\n"), depth
, "");
358 for (auto &item
: vals
)
359 dump_for_expression (stream
, depth
+ 1, item
);
362 template<typename X
, typename Y
>
364 dump_for_expression (struct ui_file
*stream
, int depth
,
365 const std::pair
<X
, Y
> &vals
)
367 dump_for_expression (stream
, depth
, vals
.first
);
368 dump_for_expression (stream
, depth
, vals
.second
);
371 /* Base class for most concrete operations. This class holds data,
372 specified via template parameters, and supplies generic
373 implementations of the 'dump' and 'uses_objfile' methods. */
374 template<typename
... Arg
>
375 class tuple_holding_operation
: public operation
379 explicit tuple_holding_operation (Arg
... args
)
380 : m_storage (std::forward
<Arg
> (args
)...)
384 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation
);
386 bool uses_objfile (struct objfile
*objfile
) const override
388 return do_check_objfile
<0, Arg
...> (objfile
, m_storage
);
391 void dump (struct ui_file
*stream
, int depth
) const override
393 dump_for_expression (stream
, depth
, opcode ());
394 do_dump
<0, Arg
...> (stream
, depth
+ 1, m_storage
);
399 /* Storage for the data. */
400 std::tuple
<Arg
...> m_storage
;
404 /* do_dump does the work of dumping the data. */
405 template<int I
, typename
... T
>
406 typename
std::enable_if
<I
== sizeof... (T
), void>::type
407 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
412 template<int I
, typename
... T
>
413 typename
std::enable_if
<I
< sizeof... (T
), void>::type
414 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
417 dump_for_expression (stream
, depth
, std::get
<I
> (value
));
418 do_dump
<I
+ 1, T
...> (stream
, depth
, value
);
421 /* do_check_objfile does the work of checking whether this object
422 refers to OBJFILE. */
423 template<int I
, typename
... T
>
424 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
425 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
431 template<int I
, typename
... T
>
432 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
433 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
436 if (check_objfile (std::get
<I
> (value
), objfile
))
438 return do_check_objfile
<I
+ 1, T
...> (objfile
, value
);
442 /* The check_constant overloads are used to decide whether a given
443 concrete operation is a constant. This is done by checking the
447 check_constant (const operation_up
&item
)
449 return item
->constant_p ();
453 check_constant (bound_minimal_symbol msym
)
459 check_constant (struct type
*type
)
465 check_constant (const struct block
*block
)
471 check_constant (const std::string
&str
)
477 check_constant (ULONGEST cst
)
483 check_constant (struct symbol
*sym
)
485 enum address_class sc
= SYMBOL_CLASS (sym
);
486 return (sc
== LOC_BLOCK
488 || sc
== LOC_CONST_BYTES
493 check_constant (const block_symbol
&sym
)
495 /* We know the block is constant, so we only need to check the
497 return check_constant (sym
.symbol
);
502 check_constant (const std::vector
<T
> &collection
)
504 for (const auto &item
: collection
)
505 if (!check_constant (item
))
510 template<typename S
, typename T
>
512 check_constant (const std::pair
<S
, T
> &item
)
514 return check_constant (item
.first
) && check_constant (item
.second
);
517 /* Base class for concrete operations. This class supplies an
518 implementation of 'constant_p' that works by checking the
520 template<typename
... Arg
>
521 class maybe_constant_operation
522 : public tuple_holding_operation
<Arg
...>
526 using tuple_holding_operation
<Arg
...>::tuple_holding_operation
;
528 bool constant_p () const override
530 return do_check_constant
<0, Arg
...> (this->m_storage
);
535 template<int I
, typename
... T
>
536 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
537 do_check_constant (const std::tuple
<T
...> &value
) const
542 template<int I
, typename
... T
>
543 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
544 do_check_constant (const std::tuple
<T
...> &value
) const
546 if (!check_constant (std::get
<I
> (value
)))
548 return do_check_constant
<I
+ 1, T
...> (value
);
552 /* A floating-point constant. The constant is encoded in the target
555 typedef std::array
<gdb_byte
, 16> float_data
;
557 /* An operation that holds a floating-point constant of a given
560 This does not need the facilities provided by
561 tuple_holding_operation, so it does not use it. */
562 class float_const_operation
567 float_const_operation (struct type
*type
, float_data data
)
573 value
*evaluate (struct type
*expect_type
,
574 struct expression
*exp
,
575 enum noside noside
) override
577 return value_from_contents (m_type
, m_data
.data ());
580 enum exp_opcode
opcode () const override
583 bool constant_p () const override
586 void dump (struct ui_file
*stream
, int depth
) const override
;
594 class scope_operation
595 : public maybe_constant_operation
<struct type
*, std::string
>
599 using maybe_constant_operation::maybe_constant_operation
;
601 value
*evaluate (struct type
*expect_type
,
602 struct expression
*exp
,
603 enum noside noside
) override
605 return eval_op_scope (expect_type
, exp
, noside
,
606 std::get
<0> (m_storage
),
607 std::get
<1> (m_storage
).c_str ());
610 value
*evaluate_for_address (struct expression
*exp
,
611 enum noside noside
) override
;
613 value
*evaluate_funcall (struct type
*expect_type
,
614 struct expression
*exp
,
616 const std::vector
<operation_up
> &args
) override
;
618 enum exp_opcode
opcode () const override
623 void do_generate_ax (struct expression
*exp
,
624 struct agent_expr
*ax
,
625 struct axs_value
*value
,
626 struct type
*cast_type
)
630 /* Compute the value of a variable. */
631 class var_value_operation
632 : public maybe_constant_operation
<block_symbol
>
636 using maybe_constant_operation::maybe_constant_operation
;
638 value
*evaluate (struct type
*expect_type
,
639 struct expression
*exp
,
640 enum noside noside
) override
;
642 value
*evaluate_with_coercion (struct expression
*exp
,
643 enum noside noside
) override
;
645 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
648 value
*evaluate_for_cast (struct type
*expect_type
,
649 struct expression
*exp
,
650 enum noside noside
) override
;
652 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
655 value
*evaluate_funcall (struct type
*expect_type
,
656 struct expression
*exp
,
658 const std::vector
<operation_up
> &args
) override
;
660 enum exp_opcode
opcode () const override
661 { return OP_VAR_VALUE
; }
663 /* Return the symbol referenced by this object. */
664 symbol
*get_symbol () const
666 return std::get
<0> (m_storage
).symbol
;
671 void do_generate_ax (struct expression
*exp
,
672 struct agent_expr
*ax
,
673 struct axs_value
*value
,
674 struct type
*cast_type
)
678 class long_const_operation
679 : public tuple_holding_operation
<struct type
*, LONGEST
>
683 using tuple_holding_operation::tuple_holding_operation
;
685 value
*evaluate (struct type
*expect_type
,
686 struct expression
*exp
,
687 enum noside noside
) override
689 return value_from_longest (std::get
<0> (m_storage
),
690 std::get
<1> (m_storage
));
693 enum exp_opcode
opcode () const override
696 bool constant_p () const override
701 void do_generate_ax (struct expression
*exp
,
702 struct agent_expr
*ax
,
703 struct axs_value
*value
,
704 struct type
*cast_type
)
708 class var_msym_value_operation
709 : public maybe_constant_operation
<bound_minimal_symbol
>
713 using maybe_constant_operation::maybe_constant_operation
;
715 value
*evaluate (struct type
*expect_type
,
716 struct expression
*exp
,
717 enum noside noside
) override
719 return eval_op_var_msym_value (expect_type
, exp
, noside
, m_outermost
,
720 std::get
<0> (m_storage
));
723 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
726 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
729 value
*evaluate_for_cast (struct type
*expect_type
,
730 struct expression
*exp
,
731 enum noside noside
) override
;
733 value
*evaluate_funcall (struct type
*expect_type
,
734 struct expression
*exp
,
736 const std::vector
<operation_up
> &args
) override
738 const char *name
= std::get
<0> (m_storage
).minsym
->print_name ();
739 return operation::evaluate_funcall (expect_type
, exp
, noside
, name
, args
);
742 enum exp_opcode
opcode () const override
743 { return OP_VAR_MSYM_VALUE
; }
745 void set_outermost () override
752 /* True if this is the outermost operation in the expression. */
753 bool m_outermost
= false;
755 void do_generate_ax (struct expression
*exp
,
756 struct agent_expr
*ax
,
757 struct axs_value
*value
,
758 struct type
*cast_type
)
762 class var_entry_value_operation
763 : public tuple_holding_operation
<symbol
*>
767 using tuple_holding_operation::tuple_holding_operation
;
769 value
*evaluate (struct type
*expect_type
,
770 struct expression
*exp
,
771 enum noside noside
) override
773 return eval_op_var_entry_value (expect_type
, exp
, noside
,
774 std::get
<0> (m_storage
));
777 enum exp_opcode
opcode () const override
778 { return OP_VAR_ENTRY_VALUE
; }
781 class func_static_var_operation
782 : public maybe_constant_operation
<operation_up
, std::string
>
786 using maybe_constant_operation::maybe_constant_operation
;
788 value
*evaluate (struct type
*expect_type
,
789 struct expression
*exp
,
790 enum noside noside
) override
792 value
*func
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
793 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
794 std::get
<1> (m_storage
).c_str ());
797 enum exp_opcode
opcode () const override
798 { return OP_FUNC_STATIC_VAR
; }
802 : public tuple_holding_operation
<int>
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 access_value_history (std::get
<0> (m_storage
));
815 enum exp_opcode
opcode () const override
819 class register_operation
820 : public tuple_holding_operation
<std::string
>
824 using tuple_holding_operation::tuple_holding_operation
;
826 value
*evaluate (struct type
*expect_type
,
827 struct expression
*exp
,
828 enum noside noside
) override
830 return eval_op_register (expect_type
, exp
, noside
,
831 std::get
<0> (m_storage
).c_str ());
834 enum exp_opcode
opcode () const override
835 { return OP_REGISTER
; }
837 /* Return the name of the register. */
838 const char *get_name () const
840 return std::get
<0> (m_storage
).c_str ();
845 void do_generate_ax (struct expression
*exp
,
846 struct agent_expr
*ax
,
847 struct axs_value
*value
,
848 struct type
*cast_type
)
853 : public tuple_holding_operation
<bool>
857 using tuple_holding_operation::tuple_holding_operation
;
859 value
*evaluate (struct type
*expect_type
,
860 struct expression
*exp
,
861 enum noside noside
) override
863 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
864 return value_from_longest (type
, std::get
<0> (m_storage
));
867 enum exp_opcode
opcode () const override
870 bool constant_p () const override
874 class internalvar_operation
875 : public tuple_holding_operation
<internalvar
*>
879 using tuple_holding_operation::tuple_holding_operation
;
881 value
*evaluate (struct type
*expect_type
,
882 struct expression
*exp
,
883 enum noside noside
) override
885 return value_of_internalvar (exp
->gdbarch
,
886 std::get
<0> (m_storage
));
889 internalvar
*get_internalvar () const
891 return std::get
<0> (m_storage
);
894 enum exp_opcode
opcode () const override
895 { return OP_INTERNALVAR
; }
899 void do_generate_ax (struct expression
*exp
,
900 struct agent_expr
*ax
,
901 struct axs_value
*value
,
902 struct type
*cast_type
)
906 class string_operation
907 : public tuple_holding_operation
<std::string
>
911 using tuple_holding_operation::tuple_holding_operation
;
913 value
*evaluate (struct type
*expect_type
,
914 struct expression
*exp
,
915 enum noside noside
) override
917 const std::string
&str
= std::get
<0> (m_storage
);
918 return eval_op_string (expect_type
, exp
, noside
,
919 str
.size (), str
.c_str ());
922 enum exp_opcode
opcode () const override
923 { return OP_STRING
; }
926 class ternop_slice_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 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
942 = std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
943 return eval_op_ternop (expect_type
, exp
, noside
, array
, low
, upper
);
946 enum exp_opcode
opcode () const override
947 { return TERNOP_SLICE
; }
950 class ternop_cond_operation
951 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
955 using maybe_constant_operation::maybe_constant_operation
;
957 value
*evaluate (struct type
*expect_type
,
958 struct expression
*exp
,
959 enum noside noside
) override
962 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
964 if (value_logical_not (val
))
965 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
966 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
969 enum exp_opcode
opcode () const override
970 { return TERNOP_COND
; }
974 void do_generate_ax (struct expression
*exp
,
975 struct agent_expr
*ax
,
976 struct axs_value
*value
,
977 struct type
*cast_type
)
981 class complex_operation
982 : public maybe_constant_operation
<operation_up
, operation_up
, struct type
*>
986 using maybe_constant_operation::maybe_constant_operation
;
988 value
*evaluate (struct type
*expect_type
,
989 struct expression
*exp
,
990 enum noside noside
) override
992 value
*real
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
993 value
*imag
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
994 return value_literal_complex (real
, imag
,
995 std::get
<2> (m_storage
));
998 enum exp_opcode
opcode () const override
999 { return OP_COMPLEX
; }
1002 class structop_base_operation
1003 : public tuple_holding_operation
<operation_up
, std::string
>
1007 /* Used for completion. Return the field name. */
1008 const std::string
&get_string () const
1010 return std::get
<1> (m_storage
);
1013 /* Used for completion. Evaluate the LHS for type. */
1014 value
*evaluate_lhs (struct expression
*exp
)
1016 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1017 EVAL_AVOID_SIDE_EFFECTS
);
1020 value
*evaluate_funcall (struct type
*expect_type
,
1021 struct expression
*exp
,
1023 const std::vector
<operation_up
> &args
) override
;
1027 using tuple_holding_operation::tuple_holding_operation
;
1030 class structop_operation
1031 : public structop_base_operation
1035 using structop_base_operation::structop_base_operation
;
1037 value
*evaluate (struct type
*expect_type
,
1038 struct expression
*exp
,
1039 enum noside noside
) override
1041 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1042 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
1043 std::get
<1> (m_storage
).c_str ());
1046 enum exp_opcode
opcode () const override
1047 { return STRUCTOP_STRUCT
; }
1051 void do_generate_ax (struct expression
*exp
,
1052 struct agent_expr
*ax
,
1053 struct axs_value
*value
,
1054 struct type
*cast_type
)
1057 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
1058 std::get
<0> (this->m_storage
).get (),
1059 std::get
<1> (this->m_storage
).c_str (),
1064 class structop_ptr_operation
1065 : public structop_base_operation
1069 using structop_base_operation::structop_base_operation
;
1071 value
*evaluate (struct type
*expect_type
,
1072 struct expression
*exp
,
1073 enum noside noside
) override
1075 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1076 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
1077 std::get
<1> (m_storage
).c_str ());
1080 enum exp_opcode
opcode () const override
1081 { return STRUCTOP_PTR
; }
1085 void do_generate_ax (struct expression
*exp
,
1086 struct agent_expr
*ax
,
1087 struct axs_value
*value
,
1088 struct type
*cast_type
)
1091 gen_expr_structop (exp
, STRUCTOP_PTR
,
1092 std::get
<0> (this->m_storage
).get (),
1093 std::get
<1> (this->m_storage
).c_str (),
1098 class structop_member_base
1099 : public tuple_holding_operation
<operation_up
, operation_up
>
1103 using tuple_holding_operation::tuple_holding_operation
;
1105 value
*evaluate_funcall (struct type
*expect_type
,
1106 struct expression
*exp
,
1108 const std::vector
<operation_up
> &args
) override
;
1111 class structop_member_operation
1112 : public structop_member_base
1116 using structop_member_base::structop_member_base
;
1118 value
*evaluate (struct type
*expect_type
,
1119 struct expression
*exp
,
1120 enum noside noside
) override
1123 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1125 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1126 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1129 enum exp_opcode
opcode () const override
1130 { return STRUCTOP_MEMBER
; }
1133 class structop_mptr_operation
1134 : public structop_member_base
1138 using structop_member_base::structop_member_base
;
1140 value
*evaluate (struct type
*expect_type
,
1141 struct expression
*exp
,
1142 enum noside noside
) override
1145 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1147 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1148 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1151 enum exp_opcode
opcode () const override
1152 { return STRUCTOP_MPTR
; }
1155 class concat_operation
1156 : public maybe_constant_operation
<operation_up
, operation_up
>
1160 using maybe_constant_operation::maybe_constant_operation
;
1162 value
*evaluate (struct type
*expect_type
,
1163 struct expression
*exp
,
1164 enum noside noside
) override
1167 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1169 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1170 return eval_op_concat (expect_type
, exp
, noside
, lhs
, rhs
);
1173 enum exp_opcode
opcode () const override
1174 { return BINOP_CONCAT
; }
1178 : public maybe_constant_operation
<operation_up
, operation_up
>
1182 using maybe_constant_operation::maybe_constant_operation
;
1184 value
*evaluate (struct type
*expect_type
,
1185 struct expression
*exp
,
1186 enum noside noside
) override
1189 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1191 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1192 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1195 enum exp_opcode
opcode () const override
1196 { return BINOP_ADD
; }
1200 void do_generate_ax (struct expression
*exp
,
1201 struct agent_expr
*ax
,
1202 struct axs_value
*value
,
1203 struct type
*cast_type
)
1206 gen_expr_binop (exp
, BINOP_ADD
,
1207 std::get
<0> (this->m_storage
).get (),
1208 std::get
<1> (this->m_storage
).get (),
1214 : public maybe_constant_operation
<operation_up
, operation_up
>
1218 using maybe_constant_operation::maybe_constant_operation
;
1220 value
*evaluate (struct type
*expect_type
,
1221 struct expression
*exp
,
1222 enum noside noside
) override
1225 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1227 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1228 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1231 enum exp_opcode
opcode () const override
1232 { return BINOP_SUB
; }
1236 void do_generate_ax (struct expression
*exp
,
1237 struct agent_expr
*ax
,
1238 struct axs_value
*value
,
1239 struct type
*cast_type
)
1242 gen_expr_binop (exp
, BINOP_SUB
,
1243 std::get
<0> (this->m_storage
).get (),
1244 std::get
<1> (this->m_storage
).get (),
1249 typedef struct value
*binary_ftype (struct type
*expect_type
,
1250 struct expression
*exp
,
1251 enum noside noside
, enum exp_opcode op
,
1252 struct value
*arg1
, struct value
*arg2
);
1254 template<enum exp_opcode OP
, binary_ftype FUNC
>
1255 class binop_operation
1256 : public maybe_constant_operation
<operation_up
, operation_up
>
1260 using maybe_constant_operation::maybe_constant_operation
;
1262 value
*evaluate (struct type
*expect_type
,
1263 struct expression
*exp
,
1264 enum noside noside
) override
1267 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1269 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1270 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1273 enum exp_opcode
opcode () const override
1277 template<enum exp_opcode OP
, binary_ftype FUNC
>
1278 class usual_ax_binop_operation
1279 : public binop_operation
<OP
, FUNC
>
1283 using binop_operation
<OP
, FUNC
>::binop_operation
;
1287 void do_generate_ax (struct expression
*exp
,
1288 struct agent_expr
*ax
,
1289 struct axs_value
*value
,
1290 struct type
*cast_type
)
1293 gen_expr_binop (exp
, OP
,
1294 std::get
<0> (this->m_storage
).get (),
1295 std::get
<1> (this->m_storage
).get (),
1300 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1301 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1302 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1304 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1305 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1306 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1307 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1308 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1309 using bitwise_and_operation
1310 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1311 using bitwise_ior_operation
1312 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1313 using bitwise_xor_operation
1314 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1316 class subscript_operation
1317 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1320 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1321 eval_op_subscript
>::usual_ax_binop_operation
;
1323 value
*evaluate_for_sizeof (struct expression
*exp
,
1324 enum noside noside
) override
;
1327 /* Implementation of comparison operations. */
1328 template<enum exp_opcode OP
, binary_ftype FUNC
>
1329 class comparison_operation
1330 : public usual_ax_binop_operation
<OP
, FUNC
>
1334 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1336 value
*evaluate (struct type
*expect_type
,
1337 struct expression
*exp
,
1338 enum noside noside
) override
1341 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1343 = std::get
<1> (this->m_storage
)->evaluate (value_type (lhs
), exp
,
1345 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1349 class equal_operation
1350 : public comparison_operation
<BINOP_EQUAL
, eval_op_equal
>
1354 using comparison_operation::comparison_operation
;
1356 operation
*get_lhs () const
1358 return std::get
<0> (m_storage
).get ();
1361 operation
*get_rhs () const
1363 return std::get
<1> (m_storage
).get ();
1367 using notequal_operation
1368 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1369 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1370 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1371 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1372 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1374 /* Implement the GDB '@' repeat operator. */
1375 class repeat_operation
1376 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1378 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1382 void do_generate_ax (struct expression
*exp
,
1383 struct agent_expr
*ax
,
1384 struct axs_value
*value
,
1385 struct type
*cast_type
)
1389 /* C-style comma operator. */
1390 class comma_operation
1391 : public maybe_constant_operation
<operation_up
, operation_up
>
1395 using maybe_constant_operation::maybe_constant_operation
;
1397 value
*evaluate (struct type
*expect_type
,
1398 struct expression
*exp
,
1399 enum noside noside
) override
1401 /* The left-hand-side is only evaluated for side effects, so don't
1402 bother in other modes. */
1403 if (noside
== EVAL_NORMAL
)
1404 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1405 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1408 enum exp_opcode
opcode () const override
1409 { return BINOP_COMMA
; }
1413 void do_generate_ax (struct expression
*exp
,
1414 struct agent_expr
*ax
,
1415 struct axs_value
*value
,
1416 struct type
*cast_type
)
1420 typedef struct value
*unary_ftype (struct type
*expect_type
,
1421 struct expression
*exp
,
1422 enum noside noside
, enum exp_opcode op
,
1423 struct value
*arg1
);
1425 /* Base class for unary operations. */
1426 template<enum exp_opcode OP
, unary_ftype FUNC
>
1427 class unop_operation
1428 : public maybe_constant_operation
<operation_up
>
1432 using maybe_constant_operation::maybe_constant_operation
;
1434 value
*evaluate (struct type
*expect_type
,
1435 struct expression
*exp
,
1436 enum noside noside
) override
1438 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1439 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1442 enum exp_opcode
opcode () const override
1446 /* Unary operations that can also be turned into agent expressions in
1448 template<enum exp_opcode OP
, unary_ftype FUNC
>
1449 class usual_ax_unop_operation
1450 : public unop_operation
<OP
, FUNC
>
1452 using unop_operation
<OP
, FUNC
>::unop_operation
;
1456 void do_generate_ax (struct expression
*exp
,
1457 struct agent_expr
*ax
,
1458 struct axs_value
*value
,
1459 struct type
*cast_type
)
1462 gen_expr_unop (exp
, OP
,
1463 std::get
<0> (this->m_storage
).get (),
1468 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1469 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1470 using unary_complement_operation
1471 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1472 using unary_logical_not_operation
1473 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1475 /* Handle pre- and post- increment and -decrement. */
1476 template<enum exp_opcode OP
, unary_ftype FUNC
>
1477 class unop_incr_operation
1478 : public tuple_holding_operation
<operation_up
>
1482 using tuple_holding_operation::tuple_holding_operation
;
1484 value
*evaluate (struct type
*expect_type
,
1485 struct expression
*exp
,
1486 enum noside noside
) override
1488 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1489 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1492 enum exp_opcode
opcode () const override
1496 using preinc_operation
1497 = unop_incr_operation
<UNOP_PREINCREMENT
, eval_op_preinc
>;
1498 using predec_operation
1499 = unop_incr_operation
<UNOP_PREDECREMENT
, eval_op_predec
>;
1500 using postinc_operation
1501 = unop_incr_operation
<UNOP_POSTINCREMENT
, eval_op_postinc
>;
1502 using postdec_operation
1503 = unop_incr_operation
<UNOP_POSTDECREMENT
, eval_op_postdec
>;
1505 /* Base class for implementations of UNOP_IND. */
1506 class unop_ind_base_operation
1507 : public tuple_holding_operation
<operation_up
>
1511 using tuple_holding_operation::tuple_holding_operation
;
1513 value
*evaluate (struct type
*expect_type
,
1514 struct expression
*exp
,
1515 enum noside noside
) override
1517 if (expect_type
!= nullptr && expect_type
->code () == TYPE_CODE_PTR
)
1518 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1519 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1520 return eval_op_ind (expect_type
, exp
, noside
, val
);
1523 value
*evaluate_for_address (struct expression
*exp
,
1524 enum noside noside
) override
;
1526 value
*evaluate_for_sizeof (struct expression
*exp
,
1527 enum noside noside
) override
;
1529 enum exp_opcode
opcode () const override
1530 { return UNOP_IND
; }
1533 /* Ordinary UNOP_IND implementation. */
1534 class unop_ind_operation
1535 : public unop_ind_base_operation
1539 using unop_ind_base_operation::unop_ind_base_operation
;
1543 void do_generate_ax (struct expression
*exp
,
1544 struct agent_expr
*ax
,
1545 struct axs_value
*value
,
1546 struct type
*cast_type
)
1549 gen_expr_unop (exp
, UNOP_IND
,
1550 std::get
<0> (this->m_storage
).get (),
1555 /* Implement OP_TYPE. */
1556 class type_operation
1557 : public tuple_holding_operation
<struct type
*>
1561 using tuple_holding_operation::tuple_holding_operation
;
1563 value
*evaluate (struct type
*expect_type
,
1564 struct expression
*exp
,
1565 enum noside noside
) override
1567 return eval_op_type (expect_type
, exp
, noside
, std::get
<0> (m_storage
));
1570 enum exp_opcode
opcode () const override
1573 bool constant_p () const override
1577 /* Implement the "typeof" operation. */
1578 class typeof_operation
1579 : public maybe_constant_operation
<operation_up
>
1583 using maybe_constant_operation::maybe_constant_operation
;
1585 value
*evaluate (struct type
*expect_type
,
1586 struct expression
*exp
,
1587 enum noside noside
) override
1589 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1590 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1591 EVAL_AVOID_SIDE_EFFECTS
);
1593 error (_("Attempt to use a type as an expression"));
1596 enum exp_opcode
opcode () const override
1597 { return OP_TYPEOF
; }
1600 /* Implement 'decltype'. */
1601 class decltype_operation
1602 : public maybe_constant_operation
<operation_up
>
1606 using maybe_constant_operation::maybe_constant_operation
;
1608 value
*evaluate (struct type
*expect_type
,
1609 struct expression
*exp
,
1610 enum noside noside
) override
1612 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1615 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1616 EVAL_AVOID_SIDE_EFFECTS
);
1617 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1618 if (sub_op
== BINOP_SUBSCRIPT
1619 || sub_op
== STRUCTOP_MEMBER
1620 || sub_op
== STRUCTOP_MPTR
1621 || sub_op
== UNOP_IND
1622 || sub_op
== STRUCTOP_STRUCT
1623 || sub_op
== STRUCTOP_PTR
1624 || sub_op
== OP_SCOPE
)
1626 struct type
*type
= value_type (result
);
1628 if (!TYPE_IS_REFERENCE (type
))
1630 type
= lookup_lvalue_reference_type (type
);
1631 result
= allocate_value (type
);
1638 error (_("Attempt to use a type as an expression"));
1641 enum exp_opcode
opcode () const override
1642 { return OP_DECLTYPE
; }
1645 /* Implement 'typeid'. */
1646 class typeid_operation
1647 : public tuple_holding_operation
<operation_up
>
1651 using tuple_holding_operation::tuple_holding_operation
;
1653 value
*evaluate (struct type
*expect_type
,
1654 struct expression
*exp
,
1655 enum noside noside
) override
1657 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1658 enum noside sub_noside
1659 = ((sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
1660 ? EVAL_AVOID_SIDE_EFFECTS
1663 value
*result
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1665 if (noside
!= EVAL_NORMAL
)
1666 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
1667 return cplus_typeid (result
);
1670 enum exp_opcode
opcode () const override
1671 { return OP_TYPEID
; }
1674 /* Implement the address-of operation. */
1675 class unop_addr_operation
1676 : public maybe_constant_operation
<operation_up
>
1680 using maybe_constant_operation::maybe_constant_operation
;
1682 value
*evaluate (struct type
*expect_type
,
1683 struct expression
*exp
,
1684 enum noside noside
) override
1686 /* C++: check for and handle pointer to members. */
1687 return std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1690 enum exp_opcode
opcode () const override
1691 { return UNOP_ADDR
; }
1693 /* Return the subexpression. */
1694 const operation_up
&get_expression () const
1696 return std::get
<0> (m_storage
);
1701 void do_generate_ax (struct expression
*exp
,
1702 struct agent_expr
*ax
,
1703 struct axs_value
*value
,
1704 struct type
*cast_type
)
1707 gen_expr_unop (exp
, UNOP_ADDR
,
1708 std::get
<0> (this->m_storage
).get (),
1713 /* Implement 'sizeof'. */
1714 class unop_sizeof_operation
1715 : public maybe_constant_operation
<operation_up
>
1719 using maybe_constant_operation::maybe_constant_operation
;
1721 value
*evaluate (struct type
*expect_type
,
1722 struct expression
*exp
,
1723 enum noside noside
) override
1725 return std::get
<0> (m_storage
)->evaluate_for_sizeof (exp
, noside
);
1728 enum exp_opcode
opcode () const override
1729 { return UNOP_SIZEOF
; }
1733 void do_generate_ax (struct expression
*exp
,
1734 struct agent_expr
*ax
,
1735 struct axs_value
*value
,
1736 struct type
*cast_type
)
1740 /* Implement 'alignof'. */
1741 class unop_alignof_operation
1742 : public maybe_constant_operation
<operation_up
>
1746 using maybe_constant_operation::maybe_constant_operation
;
1748 value
*evaluate (struct type
*expect_type
,
1749 struct expression
*exp
,
1750 enum noside noside
) override
1752 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1753 EVAL_AVOID_SIDE_EFFECTS
);
1754 return eval_op_alignof (expect_type
, exp
, noside
, val
);
1757 enum exp_opcode
opcode () const override
1758 { return UNOP_ALIGNOF
; }
1761 /* Implement UNOP_MEMVAL. */
1762 class unop_memval_operation
1763 : public tuple_holding_operation
<operation_up
, struct type
*>
1767 using tuple_holding_operation::tuple_holding_operation
;
1769 value
*evaluate (struct type
*expect_type
,
1770 struct expression
*exp
,
1771 enum noside noside
) override
1773 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1774 return eval_op_memval (expect_type
, exp
, noside
, val
,
1775 std::get
<1> (m_storage
));
1778 value
*evaluate_for_sizeof (struct expression
*exp
,
1779 enum noside noside
) override
;
1781 value
*evaluate_for_address (struct expression
*exp
,
1782 enum noside noside
) override
;
1784 enum exp_opcode
opcode () const override
1785 { return UNOP_MEMVAL
; }
1787 /* Return the type referenced by this object. */
1788 struct type
*get_type () const
1790 return std::get
<1> (m_storage
);
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 UNOP_MEMVAL_TYPE. */
1803 class unop_memval_type_operation
1804 : public tuple_holding_operation
<operation_up
, operation_up
>
1808 using tuple_holding_operation::tuple_holding_operation
;
1810 value
*evaluate (struct type
*expect_type
,
1811 struct expression
*exp
,
1812 enum noside noside
) override
1815 = std::get
<0> (m_storage
)->evaluate (expect_type
, exp
,
1816 EVAL_AVOID_SIDE_EFFECTS
);
1817 struct type
*type
= value_type (typeval
);
1818 value
*val
= std::get
<1> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1819 return eval_op_memval (expect_type
, exp
, noside
, val
, type
);
1822 value
*evaluate_for_sizeof (struct expression
*exp
,
1823 enum noside noside
) override
;
1825 value
*evaluate_for_address (struct expression
*exp
,
1826 enum noside noside
) override
;
1828 enum exp_opcode
opcode () const override
1829 { return UNOP_MEMVAL_TYPE
; }
1833 void do_generate_ax (struct expression
*exp
,
1834 struct agent_expr
*ax
,
1835 struct axs_value
*value
,
1836 struct type
*cast_type
)
1840 /* Implement the 'this' expression. */
1841 class op_this_operation
1842 : public tuple_holding_operation
<>
1846 using tuple_holding_operation::tuple_holding_operation
;
1848 value
*evaluate (struct type
*expect_type
,
1849 struct expression
*exp
,
1850 enum noside noside
) override
1852 return value_of_this (exp
->language_defn
);
1855 enum exp_opcode
opcode () const override
1860 void do_generate_ax (struct expression
*exp
,
1861 struct agent_expr
*ax
,
1862 struct axs_value
*value
,
1863 struct type
*cast_type
)
1867 /* Implement the "type instance" operation. */
1868 class type_instance_operation
1869 : public tuple_holding_operation
<type_instance_flags
, std::vector
<type
*>,
1874 using tuple_holding_operation::tuple_holding_operation
;
1876 value
*evaluate (struct type
*expect_type
,
1877 struct expression
*exp
,
1878 enum noside noside
) override
;
1880 enum exp_opcode
opcode () const override
1881 { return TYPE_INSTANCE
; }
1884 /* The assignment operator. */
1885 class assign_operation
1886 : public tuple_holding_operation
<operation_up
, operation_up
>
1890 using tuple_holding_operation::tuple_holding_operation
;
1892 value
*evaluate (struct type
*expect_type
,
1893 struct expression
*exp
,
1894 enum noside noside
) override
1896 value
*lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1897 /* Special-case assignments where the left-hand-side is a
1898 convenience variable -- in these, don't bother setting an
1899 expected type. This avoids a weird case where re-assigning a
1900 string or array to an internal variable could error with "Too
1901 many array elements". */
1902 struct type
*xtype
= (VALUE_LVAL (lhs
) == lval_internalvar
1904 : value_type (lhs
));
1905 value
*rhs
= std::get
<1> (m_storage
)->evaluate (xtype
, exp
, noside
);
1907 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1909 if (binop_user_defined_p (BINOP_ASSIGN
, lhs
, rhs
))
1910 return value_x_binop (lhs
, rhs
, BINOP_ASSIGN
, OP_NULL
, noside
);
1912 return value_assign (lhs
, rhs
);
1915 enum exp_opcode
opcode () const override
1916 { return BINOP_ASSIGN
; }
1918 /* Return the left-hand-side of the assignment. */
1919 operation
*get_lhs () const
1921 return std::get
<0> (m_storage
).get ();
1926 void do_generate_ax (struct expression
*exp
,
1927 struct agent_expr
*ax
,
1928 struct axs_value
*value
,
1929 struct type
*cast_type
)
1933 /* Assignment with modification, like "+=". */
1934 class assign_modify_operation
1935 : public tuple_holding_operation
<exp_opcode
, operation_up
, operation_up
>
1939 using tuple_holding_operation::tuple_holding_operation
;
1941 value
*evaluate (struct type
*expect_type
,
1942 struct expression
*exp
,
1943 enum noside noside
) override
1945 value
*lhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1946 value
*rhs
= std::get
<2> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1947 return eval_binop_assign_modify (expect_type
, exp
, noside
,
1948 std::get
<0> (m_storage
), lhs
, rhs
);
1951 enum exp_opcode
opcode () const override
1952 { return BINOP_ASSIGN_MODIFY
; }
1956 void do_generate_ax (struct expression
*exp
,
1957 struct agent_expr
*ax
,
1958 struct axs_value
*value
,
1959 struct type
*cast_type
)
1964 class unop_cast_operation
1965 : public maybe_constant_operation
<operation_up
, struct type
*>
1969 using maybe_constant_operation::maybe_constant_operation
;
1971 value
*evaluate (struct type
*expect_type
,
1972 struct expression
*exp
,
1973 enum noside noside
) override
1975 return std::get
<0> (m_storage
)->evaluate_for_cast (std::get
<1> (m_storage
),
1979 enum exp_opcode
opcode () const override
1980 { return UNOP_CAST
; }
1982 /* Return the type referenced by this object. */
1983 struct type
*get_type () const
1985 return std::get
<1> (m_storage
);
1990 void do_generate_ax (struct expression
*exp
,
1991 struct agent_expr
*ax
,
1992 struct axs_value
*value
,
1993 struct type
*cast_type
)
1997 /* A cast, but the type comes from an expression, not a "struct
1999 class unop_cast_type_operation
2000 : public maybe_constant_operation
<operation_up
, operation_up
>
2004 using maybe_constant_operation::maybe_constant_operation
;
2006 value
*evaluate (struct type
*expect_type
,
2007 struct expression
*exp
,
2008 enum noside noside
) override
2010 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2011 EVAL_AVOID_SIDE_EFFECTS
);
2012 return std::get
<1> (m_storage
)->evaluate_for_cast (value_type (val
),
2016 enum exp_opcode
opcode () const override
2017 { return UNOP_CAST_TYPE
; }
2021 void do_generate_ax (struct expression
*exp
,
2022 struct agent_expr
*ax
,
2023 struct axs_value
*value
,
2024 struct type
*cast_type
)
2028 typedef value
*cxx_cast_ftype (struct type
*, value
*);
2030 /* This implements dynamic_cast and reinterpret_cast. static_cast and
2031 const_cast are handled by the ordinary case operations. */
2032 template<exp_opcode OP
, cxx_cast_ftype FUNC
>
2033 class cxx_cast_operation
2034 : public maybe_constant_operation
<operation_up
, operation_up
>
2038 using maybe_constant_operation::maybe_constant_operation
;
2040 value
*evaluate (struct type
*expect_type
,
2041 struct expression
*exp
,
2042 enum noside noside
) override
2044 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2045 EVAL_AVOID_SIDE_EFFECTS
);
2046 struct type
*type
= value_type (val
);
2047 value
*rhs
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
2048 return FUNC (type
, rhs
);
2051 enum exp_opcode
opcode () const override
2055 using dynamic_cast_operation
= cxx_cast_operation
<UNOP_DYNAMIC_CAST
,
2056 value_dynamic_cast
>;
2057 using reinterpret_cast_operation
= cxx_cast_operation
<UNOP_REINTERPRET_CAST
,
2058 value_reinterpret_cast
>;
2060 /* Multi-dimensional subscripting. */
2061 class multi_subscript_operation
2062 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2066 using tuple_holding_operation::tuple_holding_operation
;
2068 value
*evaluate (struct type
*expect_type
,
2069 struct expression
*exp
,
2070 enum noside noside
) override
;
2072 enum exp_opcode
opcode () const override
2073 { return MULTI_SUBSCRIPT
; }
2076 /* The "&&" operator. */
2077 class logical_and_operation
2078 : public maybe_constant_operation
<operation_up
, operation_up
>
2082 using maybe_constant_operation::maybe_constant_operation
;
2084 value
*evaluate (struct type
*expect_type
,
2085 struct expression
*exp
,
2086 enum noside noside
) override
;
2088 enum exp_opcode
opcode () const override
2089 { return BINOP_LOGICAL_AND
; }
2093 void do_generate_ax (struct expression
*exp
,
2094 struct agent_expr
*ax
,
2095 struct axs_value
*value
,
2096 struct type
*cast_type
)
2100 /* The "||" operator. */
2101 class logical_or_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_OR
; }
2117 void do_generate_ax (struct expression
*exp
,
2118 struct agent_expr
*ax
,
2119 struct axs_value
*value
,
2120 struct type
*cast_type
)
2124 /* This class implements ADL (aka Koenig) function calls for C++. It
2125 holds the name of the function to call, the block in which the
2126 lookup should be done, and a vector of arguments. */
2127 class adl_func_operation
2128 : public tuple_holding_operation
<std::string
, const block
*,
2129 std::vector
<operation_up
>>
2133 using tuple_holding_operation::tuple_holding_operation
;
2135 value
*evaluate (struct type
*expect_type
,
2136 struct expression
*exp
,
2137 enum noside noside
) override
;
2139 enum exp_opcode
opcode () const override
2140 { return OP_ADL_FUNC
; }
2143 /* The OP_ARRAY operation. */
2144 class array_operation
2145 : public tuple_holding_operation
<int, int, std::vector
<operation_up
>>
2149 using tuple_holding_operation::tuple_holding_operation
;
2151 value
*evaluate (struct type
*expect_type
,
2152 struct expression
*exp
,
2153 enum noside noside
) override
;
2155 enum exp_opcode
opcode () const override
2156 { return OP_ARRAY
; }
2160 struct value
*evaluate_struct_tuple (struct value
*struct_val
,
2161 struct expression
*exp
,
2162 enum noside noside
, int nargs
);
2165 /* A function call. This holds the callee operation and the
2167 class funcall_operation
2168 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2172 using tuple_holding_operation::tuple_holding_operation
;
2174 value
*evaluate (struct type
*expect_type
,
2175 struct expression
*exp
,
2176 enum noside noside
) override
2178 return std::get
<0> (m_storage
)->evaluate_funcall (expect_type
, exp
, noside
,
2179 std::get
<1> (m_storage
));
2182 enum exp_opcode
opcode () const override
2183 { return OP_FUNCALL
; }
2186 } /* namespace expr */
2188 #endif /* EXPOP_H */