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
,
212 /* The check_objfile overloads are used to check whether a particular
213 component of some operation references an objfile. The passed-in
214 objfile will never be a debug objfile. */
216 /* See if EXP_OBJFILE matches OBJFILE. */
218 check_objfile (struct objfile
*exp_objfile
, struct objfile
*objfile
)
220 if (exp_objfile
->separate_debug_objfile_backlink
)
221 exp_objfile
= exp_objfile
->separate_debug_objfile_backlink
;
222 return exp_objfile
== objfile
;
226 check_objfile (struct type
*type
, struct objfile
*objfile
)
228 struct objfile
*ty_objfile
= type
->objfile_owner ();
229 if (ty_objfile
!= nullptr)
230 return check_objfile (ty_objfile
, objfile
);
235 check_objfile (struct symbol
*sym
, struct objfile
*objfile
)
237 return check_objfile (symbol_objfile (sym
), objfile
);
241 check_objfile (const struct block
*block
, struct objfile
*objfile
)
243 return check_objfile (block_objfile (block
), objfile
);
247 check_objfile (minimal_symbol
*minsym
, struct objfile
*objfile
)
249 /* This may seem strange but minsyms are only used with an objfile
255 check_objfile (internalvar
*ivar
, struct objfile
*objfile
)
261 check_objfile (const std::string
&str
, struct objfile
*objfile
)
267 check_objfile (const operation_up
&op
, struct objfile
*objfile
)
269 return op
->uses_objfile (objfile
);
273 check_objfile (enum exp_opcode val
, struct objfile
*objfile
)
279 check_objfile (ULONGEST val
, struct objfile
*objfile
)
286 check_objfile (enum_flags
<T
> val
, struct objfile
*objfile
)
293 check_objfile (const std::vector
<T
> &collection
, struct objfile
*objfile
)
295 for (const auto &item
: collection
)
297 if (check_objfile (item
, objfile
))
303 template<typename S
, typename T
>
305 check_objfile (const std::pair
<S
, T
> &item
, struct objfile
*objfile
)
307 return (check_objfile (item
.first
, objfile
)
308 || check_objfile (item
.second
, objfile
));
311 extern bool check_objfile (const std::unique_ptr
<ada_component
> &comp
,
312 struct objfile
*objfile
);
315 dump_for_expression (struct ui_file
*stream
, int depth
,
316 const operation_up
&op
)
318 op
->dump (stream
, depth
);
321 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
323 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
324 const std::string
&str
);
325 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
327 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
329 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
331 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
333 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
334 minimal_symbol
*msym
);
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 type_instance_flags flags
);
339 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
340 enum c_string_type_values flags
);
341 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
342 enum range_flag flags
);
343 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
345 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
346 const std::unique_ptr
<ada_component
> &comp
);
350 dump_for_expression (struct ui_file
*stream
, int depth
,
351 const std::vector
<T
> &vals
)
353 fprintf_filtered (stream
, _("%*sVector:\n"), depth
, "");
354 for (auto &item
: vals
)
355 dump_for_expression (stream
, depth
+ 1, item
);
358 template<typename X
, typename Y
>
360 dump_for_expression (struct ui_file
*stream
, int depth
,
361 const std::pair
<X
, Y
> &vals
)
363 dump_for_expression (stream
, depth
, vals
.first
);
364 dump_for_expression (stream
, depth
, vals
.second
);
367 /* Base class for most concrete operations. This class holds data,
368 specified via template parameters, and supplies generic
369 implementations of the 'dump' and 'uses_objfile' methods. */
370 template<typename
... Arg
>
371 class tuple_holding_operation
: public operation
375 explicit tuple_holding_operation (Arg
... args
)
376 : m_storage (std::forward
<Arg
> (args
)...)
380 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation
);
382 bool uses_objfile (struct objfile
*objfile
) const override
384 return do_check_objfile
<0, Arg
...> (objfile
, m_storage
);
387 void dump (struct ui_file
*stream
, int depth
) const override
389 dump_for_expression (stream
, depth
, opcode ());
390 do_dump
<0, Arg
...> (stream
, depth
+ 1, m_storage
);
395 /* Storage for the data. */
396 std::tuple
<Arg
...> m_storage
;
400 /* do_dump does the work of dumping the data. */
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
)
408 template<int I
, typename
... T
>
409 typename
std::enable_if
<I
< sizeof... (T
), void>::type
410 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
413 dump_for_expression (stream
, depth
, std::get
<I
> (value
));
414 do_dump
<I
+ 1, T
...> (stream
, depth
, value
);
417 /* do_check_objfile does the work of checking whether this object
418 refers to OBJFILE. */
419 template<int I
, typename
... T
>
420 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
421 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
427 template<int I
, typename
... T
>
428 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
429 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
432 if (check_objfile (std::get
<I
> (value
), objfile
))
434 return do_check_objfile
<I
+ 1, T
...> (objfile
, value
);
438 /* The check_constant overloads are used to decide whether a given
439 concrete operation is a constant. This is done by checking the
443 check_constant (const operation_up
&item
)
445 return item
->constant_p ();
449 check_constant (struct minimal_symbol
*msym
)
455 check_constant (struct type
*type
)
461 check_constant (const struct block
*block
)
467 check_constant (const std::string
&str
)
473 check_constant (struct objfile
*objfile
)
479 check_constant (ULONGEST cst
)
485 check_constant (struct symbol
*sym
)
487 enum address_class sc
= SYMBOL_CLASS (sym
);
488 return (sc
== LOC_BLOCK
490 || sc
== LOC_CONST_BYTES
496 check_constant (const std::vector
<T
> &collection
)
498 for (const auto &item
: collection
)
499 if (!check_constant (item
))
504 template<typename S
, typename T
>
506 check_constant (const std::pair
<S
, T
> &item
)
508 return check_constant (item
.first
) && check_constant (item
.second
);
511 /* Base class for concrete operations. This class supplies an
512 implementation of 'constant_p' that works by checking the
514 template<typename
... Arg
>
515 class maybe_constant_operation
516 : public tuple_holding_operation
<Arg
...>
520 using tuple_holding_operation
<Arg
...>::tuple_holding_operation
;
522 bool constant_p () const override
524 return do_check_constant
<0, Arg
...> (this->m_storage
);
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
536 template<int I
, typename
... T
>
537 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
538 do_check_constant (const std::tuple
<T
...> &value
) const
540 if (!check_constant (std::get
<I
> (value
)))
542 return do_check_constant
<I
+ 1, T
...> (value
);
546 /* A floating-point constant. The constant is encoded in the target
549 typedef std::array
<gdb_byte
, 16> float_data
;
551 /* An operation that holds a floating-point constant of a given
554 This does not need the facilities provided by
555 tuple_holding_operation, so it does not use it. */
556 class float_const_operation
561 float_const_operation (struct type
*type
, float_data data
)
567 value
*evaluate (struct type
*expect_type
,
568 struct expression
*exp
,
569 enum noside noside
) override
571 return value_from_contents (m_type
, m_data
.data ());
574 enum exp_opcode
opcode () const override
577 bool constant_p () const override
580 void dump (struct ui_file
*stream
, int depth
) const override
;
588 class scope_operation
589 : public maybe_constant_operation
<struct type
*, std::string
>
593 using maybe_constant_operation::maybe_constant_operation
;
595 value
*evaluate (struct type
*expect_type
,
596 struct expression
*exp
,
597 enum noside noside
) override
599 return eval_op_scope (expect_type
, exp
, noside
,
600 std::get
<0> (m_storage
),
601 std::get
<1> (m_storage
).c_str ());
604 value
*evaluate_for_address (struct expression
*exp
,
605 enum noside noside
) override
;
607 value
*evaluate_funcall (struct type
*expect_type
,
608 struct expression
*exp
,
610 const std::vector
<operation_up
> &args
) override
;
612 enum exp_opcode
opcode () const override
617 void do_generate_ax (struct expression
*exp
,
618 struct agent_expr
*ax
,
619 struct axs_value
*value
,
620 struct type
*cast_type
)
624 /* Compute the value of a variable. */
625 class var_value_operation
626 : public maybe_constant_operation
<symbol
*, const block
*>
630 using maybe_constant_operation::maybe_constant_operation
;
632 value
*evaluate (struct type
*expect_type
,
633 struct expression
*exp
,
634 enum noside noside
) override
;
636 value
*evaluate_with_coercion (struct expression
*exp
,
637 enum noside noside
) override
;
639 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
642 value
*evaluate_for_cast (struct type
*expect_type
,
643 struct expression
*exp
,
644 enum noside noside
) override
;
646 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
649 value
*evaluate_funcall (struct type
*expect_type
,
650 struct expression
*exp
,
652 const std::vector
<operation_up
> &args
) override
;
654 enum exp_opcode
opcode () const override
655 { return OP_VAR_VALUE
; }
657 /* Return the symbol referenced by this object. */
658 symbol
*get_symbol () const
660 return std::get
<0> (m_storage
);
665 void do_generate_ax (struct expression
*exp
,
666 struct agent_expr
*ax
,
667 struct axs_value
*value
,
668 struct type
*cast_type
)
672 class long_const_operation
673 : public tuple_holding_operation
<struct type
*, LONGEST
>
677 using tuple_holding_operation::tuple_holding_operation
;
679 value
*evaluate (struct type
*expect_type
,
680 struct expression
*exp
,
681 enum noside noside
) override
683 return value_from_longest (std::get
<0> (m_storage
),
684 std::get
<1> (m_storage
));
687 enum exp_opcode
opcode () const override
690 bool constant_p () const override
695 void do_generate_ax (struct expression
*exp
,
696 struct agent_expr
*ax
,
697 struct axs_value
*value
,
698 struct type
*cast_type
)
702 class var_msym_value_operation
703 : public maybe_constant_operation
<minimal_symbol
*, struct objfile
*>
707 using maybe_constant_operation::maybe_constant_operation
;
709 value
*evaluate (struct type
*expect_type
,
710 struct expression
*exp
,
711 enum noside noside
) override
713 return eval_op_var_msym_value (expect_type
, exp
, noside
, m_outermost
,
714 std::get
<0> (m_storage
),
715 std::get
<1> (m_storage
));
718 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
721 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
724 value
*evaluate_for_cast (struct type
*expect_type
,
725 struct expression
*exp
,
726 enum noside noside
) override
;
728 value
*evaluate_funcall (struct type
*expect_type
,
729 struct expression
*exp
,
731 const std::vector
<operation_up
> &args
) override
733 const char *name
= std::get
<0> (m_storage
)->print_name ();
734 return operation::evaluate_funcall (expect_type
, exp
, noside
, name
, args
);
737 enum exp_opcode
opcode () const override
738 { return OP_VAR_MSYM_VALUE
; }
740 void set_outermost () override
747 /* True if this is the outermost operation in the expression. */
748 bool m_outermost
= false;
750 void do_generate_ax (struct expression
*exp
,
751 struct agent_expr
*ax
,
752 struct axs_value
*value
,
753 struct type
*cast_type
)
757 class var_entry_value_operation
758 : public tuple_holding_operation
<symbol
*>
762 using tuple_holding_operation::tuple_holding_operation
;
764 value
*evaluate (struct type
*expect_type
,
765 struct expression
*exp
,
766 enum noside noside
) override
768 return eval_op_var_entry_value (expect_type
, exp
, noside
,
769 std::get
<0> (m_storage
));
772 enum exp_opcode
opcode () const override
773 { return OP_VAR_ENTRY_VALUE
; }
776 class func_static_var_operation
777 : public maybe_constant_operation
<operation_up
, std::string
>
781 using maybe_constant_operation::maybe_constant_operation
;
783 value
*evaluate (struct type
*expect_type
,
784 struct expression
*exp
,
785 enum noside noside
) override
787 value
*func
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
788 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
789 std::get
<1> (m_storage
).c_str ());
792 enum exp_opcode
opcode () const override
793 { return OP_FUNC_STATIC_VAR
; }
797 : public tuple_holding_operation
<int>
801 using tuple_holding_operation::tuple_holding_operation
;
803 value
*evaluate (struct type
*expect_type
,
804 struct expression
*exp
,
805 enum noside noside
) override
807 return access_value_history (std::get
<0> (m_storage
));
810 enum exp_opcode
opcode () const override
814 class register_operation
815 : public tuple_holding_operation
<std::string
>
819 using tuple_holding_operation::tuple_holding_operation
;
821 value
*evaluate (struct type
*expect_type
,
822 struct expression
*exp
,
823 enum noside noside
) override
825 return eval_op_register (expect_type
, exp
, noside
,
826 std::get
<0> (m_storage
).c_str ());
829 enum exp_opcode
opcode () const override
830 { return OP_REGISTER
; }
832 /* Return the name of the register. */
833 const char *get_name () const
835 return std::get
<0> (m_storage
).c_str ();
840 void do_generate_ax (struct expression
*exp
,
841 struct agent_expr
*ax
,
842 struct axs_value
*value
,
843 struct type
*cast_type
)
848 : public tuple_holding_operation
<bool>
852 using tuple_holding_operation::tuple_holding_operation
;
854 value
*evaluate (struct type
*expect_type
,
855 struct expression
*exp
,
856 enum noside noside
) override
858 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
859 return value_from_longest (type
, std::get
<0> (m_storage
));
862 enum exp_opcode
opcode () const override
865 bool constant_p () const override
869 class internalvar_operation
870 : public tuple_holding_operation
<internalvar
*>
874 using tuple_holding_operation::tuple_holding_operation
;
876 value
*evaluate (struct type
*expect_type
,
877 struct expression
*exp
,
878 enum noside noside
) override
880 return value_of_internalvar (exp
->gdbarch
,
881 std::get
<0> (m_storage
));
884 internalvar
*get_internalvar () const
886 return std::get
<0> (m_storage
);
889 enum exp_opcode
opcode () const override
890 { return OP_INTERNALVAR
; }
894 void do_generate_ax (struct expression
*exp
,
895 struct agent_expr
*ax
,
896 struct axs_value
*value
,
897 struct type
*cast_type
)
901 class string_operation
902 : public tuple_holding_operation
<std::string
>
906 using tuple_holding_operation::tuple_holding_operation
;
908 value
*evaluate (struct type
*expect_type
,
909 struct expression
*exp
,
910 enum noside noside
) override
912 const std::string
&str
= std::get
<0> (m_storage
);
913 return eval_op_string (expect_type
, exp
, noside
,
914 str
.size (), str
.c_str ());
917 enum exp_opcode
opcode () const override
918 { return OP_STRING
; }
921 class ternop_slice_operation
922 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
926 using maybe_constant_operation::maybe_constant_operation
;
928 value
*evaluate (struct type
*expect_type
,
929 struct expression
*exp
,
930 enum noside noside
) override
933 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
935 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
937 = std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
938 return eval_op_ternop (expect_type
, exp
, noside
, array
, low
, upper
);
941 enum exp_opcode
opcode () const override
942 { return TERNOP_SLICE
; }
945 class ternop_cond_operation
946 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
950 using maybe_constant_operation::maybe_constant_operation
;
952 value
*evaluate (struct type
*expect_type
,
953 struct expression
*exp
,
954 enum noside noside
) override
957 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
959 if (value_logical_not (val
))
960 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
961 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
964 enum exp_opcode
opcode () const override
965 { return TERNOP_COND
; }
969 void do_generate_ax (struct expression
*exp
,
970 struct agent_expr
*ax
,
971 struct axs_value
*value
,
972 struct type
*cast_type
)
976 class complex_operation
977 : public maybe_constant_operation
<operation_up
, operation_up
, struct type
*>
981 using maybe_constant_operation::maybe_constant_operation
;
983 value
*evaluate (struct type
*expect_type
,
984 struct expression
*exp
,
985 enum noside noside
) override
987 value
*real
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
988 value
*imag
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
989 return value_literal_complex (real
, imag
,
990 std::get
<2> (m_storage
));
993 enum exp_opcode
opcode () const override
994 { return OP_COMPLEX
; }
997 class structop_base_operation
998 : public tuple_holding_operation
<operation_up
, std::string
>
1002 /* Used for completion. Return the field name. */
1003 const std::string
&get_string () const
1005 return std::get
<1> (m_storage
);
1008 /* Used for completion. Evaluate the LHS for type. */
1009 value
*evaluate_lhs (struct expression
*exp
)
1011 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1012 EVAL_AVOID_SIDE_EFFECTS
);
1015 value
*evaluate_funcall (struct type
*expect_type
,
1016 struct expression
*exp
,
1018 const std::vector
<operation_up
> &args
) override
;
1022 using tuple_holding_operation::tuple_holding_operation
;
1025 class structop_operation
1026 : public structop_base_operation
1030 using structop_base_operation::structop_base_operation
;
1032 value
*evaluate (struct type
*expect_type
,
1033 struct expression
*exp
,
1034 enum noside noside
) override
1036 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1037 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
1038 std::get
<1> (m_storage
).c_str ());
1041 enum exp_opcode
opcode () const override
1042 { return STRUCTOP_STRUCT
; }
1046 void do_generate_ax (struct expression
*exp
,
1047 struct agent_expr
*ax
,
1048 struct axs_value
*value
,
1049 struct type
*cast_type
)
1052 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
1053 std::get
<0> (this->m_storage
).get (),
1054 std::get
<1> (this->m_storage
).c_str (),
1059 class structop_ptr_operation
1060 : public structop_base_operation
1064 using structop_base_operation::structop_base_operation
;
1066 value
*evaluate (struct type
*expect_type
,
1067 struct expression
*exp
,
1068 enum noside noside
) override
1070 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1071 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
1072 std::get
<1> (m_storage
).c_str ());
1075 enum exp_opcode
opcode () const override
1076 { return STRUCTOP_PTR
; }
1080 void do_generate_ax (struct expression
*exp
,
1081 struct agent_expr
*ax
,
1082 struct axs_value
*value
,
1083 struct type
*cast_type
)
1086 gen_expr_structop (exp
, STRUCTOP_PTR
,
1087 std::get
<0> (this->m_storage
).get (),
1088 std::get
<1> (this->m_storage
).c_str (),
1093 class structop_member_base
1094 : public tuple_holding_operation
<operation_up
, operation_up
>
1098 using tuple_holding_operation::tuple_holding_operation
;
1100 value
*evaluate_funcall (struct type
*expect_type
,
1101 struct expression
*exp
,
1103 const std::vector
<operation_up
> &args
) override
;
1106 class structop_member_operation
1107 : public structop_member_base
1111 using structop_member_base::structop_member_base
;
1113 value
*evaluate (struct type
*expect_type
,
1114 struct expression
*exp
,
1115 enum noside noside
) override
1118 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1120 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1121 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1124 enum exp_opcode
opcode () const override
1125 { return STRUCTOP_MEMBER
; }
1128 class structop_mptr_operation
1129 : public structop_member_base
1133 using structop_member_base::structop_member_base
;
1135 value
*evaluate (struct type
*expect_type
,
1136 struct expression
*exp
,
1137 enum noside noside
) override
1140 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1142 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1143 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1146 enum exp_opcode
opcode () const override
1147 { return STRUCTOP_MPTR
; }
1150 class concat_operation
1151 : public maybe_constant_operation
<operation_up
, operation_up
>
1155 using maybe_constant_operation::maybe_constant_operation
;
1157 value
*evaluate (struct type
*expect_type
,
1158 struct expression
*exp
,
1159 enum noside noside
) override
1162 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1164 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1165 return eval_op_concat (expect_type
, exp
, noside
, lhs
, rhs
);
1168 enum exp_opcode
opcode () const override
1169 { return BINOP_CONCAT
; }
1173 : public maybe_constant_operation
<operation_up
, operation_up
>
1177 using maybe_constant_operation::maybe_constant_operation
;
1179 value
*evaluate (struct type
*expect_type
,
1180 struct expression
*exp
,
1181 enum noside noside
) override
1184 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1186 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1187 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1190 enum exp_opcode
opcode () const override
1191 { return BINOP_ADD
; }
1195 void do_generate_ax (struct expression
*exp
,
1196 struct agent_expr
*ax
,
1197 struct axs_value
*value
,
1198 struct type
*cast_type
)
1201 gen_expr_binop (exp
, BINOP_ADD
,
1202 std::get
<0> (this->m_storage
).get (),
1203 std::get
<1> (this->m_storage
).get (),
1209 : public maybe_constant_operation
<operation_up
, operation_up
>
1213 using maybe_constant_operation::maybe_constant_operation
;
1215 value
*evaluate (struct type
*expect_type
,
1216 struct expression
*exp
,
1217 enum noside noside
) override
1220 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1222 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1223 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1226 enum exp_opcode
opcode () const override
1227 { return BINOP_SUB
; }
1231 void do_generate_ax (struct expression
*exp
,
1232 struct agent_expr
*ax
,
1233 struct axs_value
*value
,
1234 struct type
*cast_type
)
1237 gen_expr_binop (exp
, BINOP_SUB
,
1238 std::get
<0> (this->m_storage
).get (),
1239 std::get
<1> (this->m_storage
).get (),
1244 typedef struct value
*binary_ftype (struct type
*expect_type
,
1245 struct expression
*exp
,
1246 enum noside noside
, enum exp_opcode op
,
1247 struct value
*arg1
, struct value
*arg2
);
1249 template<enum exp_opcode OP
, binary_ftype FUNC
>
1250 class binop_operation
1251 : public maybe_constant_operation
<operation_up
, operation_up
>
1255 using maybe_constant_operation::maybe_constant_operation
;
1257 value
*evaluate (struct type
*expect_type
,
1258 struct expression
*exp
,
1259 enum noside noside
) override
1262 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1264 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1265 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1268 enum exp_opcode
opcode () const override
1272 template<enum exp_opcode OP
, binary_ftype FUNC
>
1273 class usual_ax_binop_operation
1274 : public binop_operation
<OP
, FUNC
>
1278 using binop_operation
<OP
, FUNC
>::binop_operation
;
1282 void do_generate_ax (struct expression
*exp
,
1283 struct agent_expr
*ax
,
1284 struct axs_value
*value
,
1285 struct type
*cast_type
)
1288 gen_expr_binop (exp
, OP
,
1289 std::get
<0> (this->m_storage
).get (),
1290 std::get
<1> (this->m_storage
).get (),
1295 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1296 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1297 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1299 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1300 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1301 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1302 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1303 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1304 using bitwise_and_operation
1305 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1306 using bitwise_ior_operation
1307 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1308 using bitwise_xor_operation
1309 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1311 class subscript_operation
1312 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1315 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1316 eval_op_subscript
>::usual_ax_binop_operation
;
1318 value
*evaluate_for_sizeof (struct expression
*exp
,
1319 enum noside noside
) override
;
1322 /* Implementation of comparison operations. */
1323 template<enum exp_opcode OP
, binary_ftype FUNC
>
1324 class comparison_operation
1325 : public usual_ax_binop_operation
<OP
, FUNC
>
1329 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1331 value
*evaluate (struct type
*expect_type
,
1332 struct expression
*exp
,
1333 enum noside noside
) override
1336 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1338 = std::get
<1> (this->m_storage
)->evaluate (value_type (lhs
), exp
,
1340 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1344 class equal_operation
1345 : public comparison_operation
<BINOP_EQUAL
, eval_op_equal
>
1349 using comparison_operation::comparison_operation
;
1351 operation
*get_lhs () const
1353 return std::get
<0> (m_storage
).get ();
1356 operation
*get_rhs () const
1358 return std::get
<1> (m_storage
).get ();
1362 using notequal_operation
1363 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1364 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1365 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1366 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1367 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1369 /* Implement the GDB '@' repeat operator. */
1370 class repeat_operation
1371 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1373 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1377 void do_generate_ax (struct expression
*exp
,
1378 struct agent_expr
*ax
,
1379 struct axs_value
*value
,
1380 struct type
*cast_type
)
1384 /* C-style comma operator. */
1385 class comma_operation
1386 : public maybe_constant_operation
<operation_up
, operation_up
>
1390 using maybe_constant_operation::maybe_constant_operation
;
1392 value
*evaluate (struct type
*expect_type
,
1393 struct expression
*exp
,
1394 enum noside noside
) override
1396 /* The left-hand-side is only evaluated for side effects, so don't
1397 bother in other modes. */
1398 if (noside
== EVAL_NORMAL
)
1399 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1400 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1403 enum exp_opcode
opcode () const override
1404 { return BINOP_COMMA
; }
1408 void do_generate_ax (struct expression
*exp
,
1409 struct agent_expr
*ax
,
1410 struct axs_value
*value
,
1411 struct type
*cast_type
)
1415 typedef struct value
*unary_ftype (struct type
*expect_type
,
1416 struct expression
*exp
,
1417 enum noside noside
, enum exp_opcode op
,
1418 struct value
*arg1
);
1420 /* Base class for unary operations. */
1421 template<enum exp_opcode OP
, unary_ftype FUNC
>
1422 class unop_operation
1423 : public maybe_constant_operation
<operation_up
>
1427 using maybe_constant_operation::maybe_constant_operation
;
1429 value
*evaluate (struct type
*expect_type
,
1430 struct expression
*exp
,
1431 enum noside noside
) override
1433 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1434 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1437 enum exp_opcode
opcode () const override
1441 /* Unary operations that can also be turned into agent expressions in
1443 template<enum exp_opcode OP
, unary_ftype FUNC
>
1444 class usual_ax_unop_operation
1445 : public unop_operation
<OP
, FUNC
>
1447 using unop_operation
<OP
, FUNC
>::unop_operation
;
1451 void do_generate_ax (struct expression
*exp
,
1452 struct agent_expr
*ax
,
1453 struct axs_value
*value
,
1454 struct type
*cast_type
)
1457 gen_expr_unop (exp
, OP
,
1458 std::get
<0> (this->m_storage
).get (),
1463 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1464 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1465 using unary_complement_operation
1466 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1467 using unary_logical_not_operation
1468 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1470 /* Handle pre- and post- increment and -decrement. */
1471 template<enum exp_opcode OP
, unary_ftype FUNC
>
1472 class unop_incr_operation
1473 : public tuple_holding_operation
<operation_up
>
1477 using tuple_holding_operation::tuple_holding_operation
;
1479 value
*evaluate (struct type
*expect_type
,
1480 struct expression
*exp
,
1481 enum noside noside
) override
1483 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1484 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1487 enum exp_opcode
opcode () const override
1491 using preinc_operation
1492 = unop_incr_operation
<UNOP_PREINCREMENT
, eval_op_preinc
>;
1493 using predec_operation
1494 = unop_incr_operation
<UNOP_PREDECREMENT
, eval_op_predec
>;
1495 using postinc_operation
1496 = unop_incr_operation
<UNOP_POSTINCREMENT
, eval_op_postinc
>;
1497 using postdec_operation
1498 = unop_incr_operation
<UNOP_POSTDECREMENT
, eval_op_postdec
>;
1500 /* Base class for implementations of UNOP_IND. */
1501 class unop_ind_base_operation
1502 : public tuple_holding_operation
<operation_up
>
1506 using tuple_holding_operation::tuple_holding_operation
;
1508 value
*evaluate (struct type
*expect_type
,
1509 struct expression
*exp
,
1510 enum noside noside
) override
1512 if (expect_type
!= nullptr && expect_type
->code () == TYPE_CODE_PTR
)
1513 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1514 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1515 return eval_op_ind (expect_type
, exp
, noside
, val
);
1518 value
*evaluate_for_address (struct expression
*exp
,
1519 enum noside noside
) override
;
1521 value
*evaluate_for_sizeof (struct expression
*exp
,
1522 enum noside noside
) override
;
1524 enum exp_opcode
opcode () const override
1525 { return UNOP_IND
; }
1528 /* Ordinary UNOP_IND implementation. */
1529 class unop_ind_operation
1530 : public unop_ind_base_operation
1534 using unop_ind_base_operation::unop_ind_base_operation
;
1538 void do_generate_ax (struct expression
*exp
,
1539 struct agent_expr
*ax
,
1540 struct axs_value
*value
,
1541 struct type
*cast_type
)
1544 gen_expr_unop (exp
, UNOP_IND
,
1545 std::get
<0> (this->m_storage
).get (),
1550 /* Implement OP_TYPE. */
1551 class type_operation
1552 : public tuple_holding_operation
<struct type
*>
1556 using tuple_holding_operation::tuple_holding_operation
;
1558 value
*evaluate (struct type
*expect_type
,
1559 struct expression
*exp
,
1560 enum noside noside
) override
1562 return eval_op_type (expect_type
, exp
, noside
, std::get
<0> (m_storage
));
1565 enum exp_opcode
opcode () const override
1568 bool constant_p () const override
1572 /* Implement the "typeof" operation. */
1573 class typeof_operation
1574 : public maybe_constant_operation
<operation_up
>
1578 using maybe_constant_operation::maybe_constant_operation
;
1580 value
*evaluate (struct type
*expect_type
,
1581 struct expression
*exp
,
1582 enum noside noside
) override
1584 if (noside
== EVAL_SKIP
)
1585 return eval_skip_value (exp
);
1586 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1587 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1588 EVAL_AVOID_SIDE_EFFECTS
);
1590 error (_("Attempt to use a type as an expression"));
1593 enum exp_opcode
opcode () const override
1594 { return OP_TYPEOF
; }
1597 /* Implement 'decltype'. */
1598 class decltype_operation
1599 : public maybe_constant_operation
<operation_up
>
1603 using maybe_constant_operation::maybe_constant_operation
;
1605 value
*evaluate (struct type
*expect_type
,
1606 struct expression
*exp
,
1607 enum noside noside
) override
1609 if (noside
== EVAL_SKIP
)
1610 return eval_skip_value (exp
);
1611 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1614 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1615 EVAL_AVOID_SIDE_EFFECTS
);
1616 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1617 if (sub_op
== BINOP_SUBSCRIPT
1618 || sub_op
== STRUCTOP_MEMBER
1619 || sub_op
== STRUCTOP_MPTR
1620 || sub_op
== UNOP_IND
1621 || sub_op
== STRUCTOP_STRUCT
1622 || sub_op
== STRUCTOP_PTR
1623 || sub_op
== OP_SCOPE
)
1625 struct type
*type
= value_type (result
);
1627 if (!TYPE_IS_REFERENCE (type
))
1629 type
= lookup_lvalue_reference_type (type
);
1630 result
= allocate_value (type
);
1637 error (_("Attempt to use a type as an expression"));
1640 enum exp_opcode
opcode () const override
1641 { return OP_DECLTYPE
; }
1644 /* Implement 'typeid'. */
1645 class typeid_operation
1646 : public tuple_holding_operation
<operation_up
>
1650 using tuple_holding_operation::tuple_holding_operation
;
1652 value
*evaluate (struct type
*expect_type
,
1653 struct expression
*exp
,
1654 enum noside noside
) override
1656 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1657 enum noside sub_noside
1658 = ((sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
1659 ? EVAL_AVOID_SIDE_EFFECTS
1662 value
*result
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1664 if (noside
!= EVAL_NORMAL
)
1665 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
1666 return cplus_typeid (result
);
1669 enum exp_opcode
opcode () const override
1670 { return OP_TYPEID
; }
1673 /* Implement the address-of operation. */
1674 class unop_addr_operation
1675 : public maybe_constant_operation
<operation_up
>
1679 using maybe_constant_operation::maybe_constant_operation
;
1681 value
*evaluate (struct type
*expect_type
,
1682 struct expression
*exp
,
1683 enum noside noside
) override
1685 /* C++: check for and handle pointer to members. */
1686 if (noside
== EVAL_SKIP
)
1687 return eval_skip_value (exp
);
1689 return std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1692 enum exp_opcode
opcode () const override
1693 { return UNOP_ADDR
; }
1695 /* Return the subexpression. */
1696 const operation_up
&get_expression () const
1698 return std::get
<0> (m_storage
);
1703 void do_generate_ax (struct expression
*exp
,
1704 struct agent_expr
*ax
,
1705 struct axs_value
*value
,
1706 struct type
*cast_type
)
1709 gen_expr_unop (exp
, UNOP_ADDR
,
1710 std::get
<0> (this->m_storage
).get (),
1715 /* Implement 'sizeof'. */
1716 class unop_sizeof_operation
1717 : public maybe_constant_operation
<operation_up
>
1721 using maybe_constant_operation::maybe_constant_operation
;
1723 value
*evaluate (struct type
*expect_type
,
1724 struct expression
*exp
,
1725 enum noside noside
) override
1727 if (noside
== EVAL_SKIP
)
1728 return eval_skip_value (exp
);
1729 return std::get
<0> (m_storage
)->evaluate_for_sizeof (exp
, noside
);
1732 enum exp_opcode
opcode () const override
1733 { return UNOP_SIZEOF
; }
1737 void do_generate_ax (struct expression
*exp
,
1738 struct agent_expr
*ax
,
1739 struct axs_value
*value
,
1740 struct type
*cast_type
)
1744 /* Implement 'alignof'. */
1745 class unop_alignof_operation
1746 : public maybe_constant_operation
<operation_up
>
1750 using maybe_constant_operation::maybe_constant_operation
;
1752 value
*evaluate (struct type
*expect_type
,
1753 struct expression
*exp
,
1754 enum noside noside
) override
1756 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1757 EVAL_AVOID_SIDE_EFFECTS
);
1758 return eval_op_alignof (expect_type
, exp
, noside
, val
);
1761 enum exp_opcode
opcode () const override
1762 { return UNOP_ALIGNOF
; }
1765 /* Implement UNOP_MEMVAL. */
1766 class unop_memval_operation
1767 : public tuple_holding_operation
<operation_up
, struct type
*>
1771 using tuple_holding_operation::tuple_holding_operation
;
1773 value
*evaluate (struct type
*expect_type
,
1774 struct expression
*exp
,
1775 enum noside noside
) override
1777 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1778 return eval_op_memval (expect_type
, exp
, noside
, val
,
1779 std::get
<1> (m_storage
));
1782 value
*evaluate_for_sizeof (struct expression
*exp
,
1783 enum noside noside
) override
;
1785 value
*evaluate_for_address (struct expression
*exp
,
1786 enum noside noside
) override
;
1788 enum exp_opcode
opcode () const override
1789 { return UNOP_MEMVAL
; }
1791 /* Return the type referenced by this object. */
1792 struct type
*get_type () const
1794 return std::get
<1> (m_storage
);
1799 void do_generate_ax (struct expression
*exp
,
1800 struct agent_expr
*ax
,
1801 struct axs_value
*value
,
1802 struct type
*cast_type
)
1806 /* Implement UNOP_MEMVAL_TYPE. */
1807 class unop_memval_type_operation
1808 : public tuple_holding_operation
<operation_up
, operation_up
>
1812 using tuple_holding_operation::tuple_holding_operation
;
1814 value
*evaluate (struct type
*expect_type
,
1815 struct expression
*exp
,
1816 enum noside noside
) override
1819 = std::get
<0> (m_storage
)->evaluate (expect_type
, exp
,
1820 EVAL_AVOID_SIDE_EFFECTS
);
1821 struct type
*type
= value_type (typeval
);
1822 value
*val
= std::get
<1> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1823 return eval_op_memval (expect_type
, exp
, noside
, val
, type
);
1826 value
*evaluate_for_sizeof (struct expression
*exp
,
1827 enum noside noside
) override
;
1829 value
*evaluate_for_address (struct expression
*exp
,
1830 enum noside noside
) override
;
1832 enum exp_opcode
opcode () const override
1833 { return UNOP_MEMVAL_TYPE
; }
1837 void do_generate_ax (struct expression
*exp
,
1838 struct agent_expr
*ax
,
1839 struct axs_value
*value
,
1840 struct type
*cast_type
)
1844 /* Implement the 'this' expression. */
1845 class op_this_operation
1846 : public tuple_holding_operation
<>
1850 using tuple_holding_operation::tuple_holding_operation
;
1852 value
*evaluate (struct type
*expect_type
,
1853 struct expression
*exp
,
1854 enum noside noside
) override
1856 return value_of_this (exp
->language_defn
);
1859 enum exp_opcode
opcode () const override
1864 void do_generate_ax (struct expression
*exp
,
1865 struct agent_expr
*ax
,
1866 struct axs_value
*value
,
1867 struct type
*cast_type
)
1871 /* Implement the "type instance" operation. */
1872 class type_instance_operation
1873 : public tuple_holding_operation
<type_instance_flags
, std::vector
<type
*>,
1878 using tuple_holding_operation::tuple_holding_operation
;
1880 value
*evaluate (struct type
*expect_type
,
1881 struct expression
*exp
,
1882 enum noside noside
) override
;
1884 enum exp_opcode
opcode () const override
1885 { return TYPE_INSTANCE
; }
1888 /* The assignment operator. */
1889 class assign_operation
1890 : public tuple_holding_operation
<operation_up
, operation_up
>
1894 using tuple_holding_operation::tuple_holding_operation
;
1896 value
*evaluate (struct type
*expect_type
,
1897 struct expression
*exp
,
1898 enum noside noside
) override
1900 value
*lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1901 /* Special-case assignments where the left-hand-side is a
1902 convenience variable -- in these, don't bother setting an
1903 expected type. This avoids a weird case where re-assigning a
1904 string or array to an internal variable could error with "Too
1905 many array elements". */
1906 struct type
*xtype
= (VALUE_LVAL (lhs
) == lval_internalvar
1908 : value_type (lhs
));
1909 value
*rhs
= std::get
<1> (m_storage
)->evaluate (xtype
, exp
, noside
);
1911 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1913 if (binop_user_defined_p (BINOP_ASSIGN
, lhs
, rhs
))
1914 return value_x_binop (lhs
, rhs
, BINOP_ASSIGN
, OP_NULL
, noside
);
1916 return value_assign (lhs
, rhs
);
1919 enum exp_opcode
opcode () const override
1920 { return BINOP_ASSIGN
; }
1922 /* Return the left-hand-side of the assignment. */
1923 operation
*get_lhs () const
1925 return std::get
<0> (m_storage
).get ();
1930 void do_generate_ax (struct expression
*exp
,
1931 struct agent_expr
*ax
,
1932 struct axs_value
*value
,
1933 struct type
*cast_type
)
1937 /* Assignment with modification, like "+=". */
1938 class assign_modify_operation
1939 : public tuple_holding_operation
<exp_opcode
, operation_up
, operation_up
>
1943 using tuple_holding_operation::tuple_holding_operation
;
1945 value
*evaluate (struct type
*expect_type
,
1946 struct expression
*exp
,
1947 enum noside noside
) override
1949 value
*lhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1950 value
*rhs
= std::get
<2> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1951 return eval_binop_assign_modify (expect_type
, exp
, noside
,
1952 std::get
<0> (m_storage
), lhs
, rhs
);
1955 enum exp_opcode
opcode () const override
1956 { return BINOP_ASSIGN_MODIFY
; }
1960 void do_generate_ax (struct expression
*exp
,
1961 struct agent_expr
*ax
,
1962 struct axs_value
*value
,
1963 struct type
*cast_type
)
1968 class unop_cast_operation
1969 : public maybe_constant_operation
<operation_up
, struct type
*>
1973 using maybe_constant_operation::maybe_constant_operation
;
1975 value
*evaluate (struct type
*expect_type
,
1976 struct expression
*exp
,
1977 enum noside noside
) override
1979 return std::get
<0> (m_storage
)->evaluate_for_cast (std::get
<1> (m_storage
),
1983 enum exp_opcode
opcode () const override
1984 { return UNOP_CAST
; }
1986 /* Return the type referenced by this object. */
1987 struct type
*get_type () const
1989 return std::get
<1> (m_storage
);
1994 void do_generate_ax (struct expression
*exp
,
1995 struct agent_expr
*ax
,
1996 struct axs_value
*value
,
1997 struct type
*cast_type
)
2001 /* A cast, but the type comes from an expression, not a "struct
2003 class unop_cast_type_operation
2004 : public maybe_constant_operation
<operation_up
, operation_up
>
2008 using maybe_constant_operation::maybe_constant_operation
;
2010 value
*evaluate (struct type
*expect_type
,
2011 struct expression
*exp
,
2012 enum noside noside
) override
2014 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2015 EVAL_AVOID_SIDE_EFFECTS
);
2016 return std::get
<1> (m_storage
)->evaluate_for_cast (value_type (val
),
2020 enum exp_opcode
opcode () const override
2021 { return UNOP_CAST_TYPE
; }
2025 void do_generate_ax (struct expression
*exp
,
2026 struct agent_expr
*ax
,
2027 struct axs_value
*value
,
2028 struct type
*cast_type
)
2032 typedef value
*cxx_cast_ftype (struct type
*, value
*);
2034 /* This implements dynamic_cast and reinterpret_cast. static_cast and
2035 const_cast are handled by the ordinary case operations. */
2036 template<exp_opcode OP
, cxx_cast_ftype FUNC
>
2037 class cxx_cast_operation
2038 : public maybe_constant_operation
<operation_up
, operation_up
>
2042 using maybe_constant_operation::maybe_constant_operation
;
2044 value
*evaluate (struct type
*expect_type
,
2045 struct expression
*exp
,
2046 enum noside noside
) override
2048 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2049 EVAL_AVOID_SIDE_EFFECTS
);
2050 struct type
*type
= value_type (val
);
2051 value
*rhs
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
2052 if (noside
== EVAL_SKIP
)
2053 return eval_skip_value (exp
);
2054 return FUNC (type
, rhs
);
2057 enum exp_opcode
opcode () const override
2061 using dynamic_cast_operation
= cxx_cast_operation
<UNOP_DYNAMIC_CAST
,
2062 value_dynamic_cast
>;
2063 using reinterpret_cast_operation
= cxx_cast_operation
<UNOP_REINTERPRET_CAST
,
2064 value_reinterpret_cast
>;
2066 /* Multi-dimensional subscripting. */
2067 class multi_subscript_operation
2068 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2072 using tuple_holding_operation::tuple_holding_operation
;
2074 value
*evaluate (struct type
*expect_type
,
2075 struct expression
*exp
,
2076 enum noside noside
) override
;
2078 enum exp_opcode
opcode () const override
2079 { return MULTI_SUBSCRIPT
; }
2082 /* The "&&" operator. */
2083 class logical_and_operation
2084 : public maybe_constant_operation
<operation_up
, operation_up
>
2088 using maybe_constant_operation::maybe_constant_operation
;
2090 value
*evaluate (struct type
*expect_type
,
2091 struct expression
*exp
,
2092 enum noside noside
) override
;
2094 enum exp_opcode
opcode () const override
2095 { return BINOP_LOGICAL_AND
; }
2099 void do_generate_ax (struct expression
*exp
,
2100 struct agent_expr
*ax
,
2101 struct axs_value
*value
,
2102 struct type
*cast_type
)
2106 /* The "||" operator. */
2107 class logical_or_operation
2108 : public maybe_constant_operation
<operation_up
, operation_up
>
2112 using maybe_constant_operation::maybe_constant_operation
;
2114 value
*evaluate (struct type
*expect_type
,
2115 struct expression
*exp
,
2116 enum noside noside
) override
;
2118 enum exp_opcode
opcode () const override
2119 { return BINOP_LOGICAL_OR
; }
2123 void do_generate_ax (struct expression
*exp
,
2124 struct agent_expr
*ax
,
2125 struct axs_value
*value
,
2126 struct type
*cast_type
)
2130 /* This class implements ADL (aka Koenig) function calls for C++. It
2131 holds the name of the function to call, the block in which the
2132 lookup should be done, and a vector of arguments. */
2133 class adl_func_operation
2134 : public tuple_holding_operation
<std::string
, const block
*,
2135 std::vector
<operation_up
>>
2139 using tuple_holding_operation::tuple_holding_operation
;
2141 value
*evaluate (struct type
*expect_type
,
2142 struct expression
*exp
,
2143 enum noside noside
) override
;
2145 enum exp_opcode
opcode () const override
2146 { return OP_ADL_FUNC
; }
2149 /* The OP_ARRAY operation. */
2150 class array_operation
2151 : public tuple_holding_operation
<int, int, std::vector
<operation_up
>>
2155 using tuple_holding_operation::tuple_holding_operation
;
2157 value
*evaluate (struct type
*expect_type
,
2158 struct expression
*exp
,
2159 enum noside noside
) override
;
2161 enum exp_opcode
opcode () const override
2162 { return OP_ARRAY
; }
2166 struct value
*evaluate_struct_tuple (struct value
*struct_val
,
2167 struct expression
*exp
,
2168 enum noside noside
, int nargs
);
2171 /* A function call. This holds the callee operation and the
2173 class funcall_operation
2174 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2178 using tuple_holding_operation::tuple_holding_operation
;
2180 value
*evaluate (struct type
*expect_type
,
2181 struct expression
*exp
,
2182 enum noside noside
) override
2184 return std::get
<0> (m_storage
)->evaluate_funcall (expect_type
, exp
, noside
,
2185 std::get
<1> (m_storage
));
2188 enum exp_opcode
opcode () const override
2189 { return OP_FUNCALL
; }
2192 } /* namespace expr */
2194 #endif /* EXPOP_H */