1 /* Definitions for expressions in GDB
3 Copyright (C) 2020-2024 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/>. */
25 #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_structop_struct (struct type
*expect_type
,
68 struct expression
*exp
,
72 extern struct value
*eval_op_structop_ptr (struct type
*expect_type
,
73 struct expression
*exp
,
77 extern struct value
*eval_op_member (struct type
*expect_type
,
78 struct expression
*exp
,
80 struct value
*arg1
, struct value
*arg2
);
81 extern struct value
*eval_op_add (struct type
*expect_type
,
82 struct expression
*exp
,
84 struct value
*arg1
, struct value
*arg2
);
85 extern struct value
*eval_op_sub (struct type
*expect_type
,
86 struct expression
*exp
,
88 struct value
*arg1
, struct value
*arg2
);
89 extern struct value
*eval_op_binary (struct type
*expect_type
,
90 struct expression
*exp
,
91 enum noside noside
, enum exp_opcode op
,
92 struct value
*arg1
, struct value
*arg2
);
93 extern struct value
*eval_op_subscript (struct type
*expect_type
,
94 struct expression
*exp
,
95 enum noside noside
, enum exp_opcode op
,
98 extern struct value
*eval_op_equal (struct type
*expect_type
,
99 struct expression
*exp
,
100 enum noside noside
, enum exp_opcode op
,
103 extern struct value
*eval_op_notequal (struct type
*expect_type
,
104 struct expression
*exp
,
105 enum noside noside
, enum exp_opcode op
,
108 extern struct value
*eval_op_less (struct type
*expect_type
,
109 struct expression
*exp
,
110 enum noside noside
, enum exp_opcode op
,
113 extern struct value
*eval_op_gtr (struct type
*expect_type
,
114 struct expression
*exp
,
115 enum noside noside
, enum exp_opcode op
,
118 extern struct value
*eval_op_geq (struct type
*expect_type
,
119 struct expression
*exp
,
120 enum noside noside
, enum exp_opcode op
,
123 extern struct value
*eval_op_leq (struct type
*expect_type
,
124 struct expression
*exp
,
125 enum noside noside
, enum exp_opcode op
,
128 extern struct value
*eval_op_repeat (struct type
*expect_type
,
129 struct expression
*exp
,
130 enum noside noside
, enum exp_opcode op
,
133 extern struct value
*eval_op_plus (struct type
*expect_type
,
134 struct expression
*exp
,
135 enum noside noside
, enum exp_opcode op
,
137 extern struct value
*eval_op_neg (struct type
*expect_type
,
138 struct expression
*exp
,
139 enum noside noside
, enum exp_opcode op
,
141 extern struct value
*eval_op_complement (struct type
*expect_type
,
142 struct expression
*exp
,
146 extern struct value
*eval_op_lognot (struct type
*expect_type
,
147 struct expression
*exp
,
151 extern struct value
*eval_op_preinc (struct type
*expect_type
,
152 struct expression
*exp
,
156 extern struct value
*eval_op_predec (struct type
*expect_type
,
157 struct expression
*exp
,
161 extern struct value
*eval_op_postinc (struct type
*expect_type
,
162 struct expression
*exp
,
166 extern struct value
*eval_op_postdec (struct type
*expect_type
,
167 struct expression
*exp
,
171 extern struct value
*eval_op_ind (struct type
*expect_type
,
172 struct expression
*exp
,
175 extern struct value
*eval_op_type (struct type
*expect_type
,
176 struct expression
*exp
,
177 enum noside noside
, struct type
*type
);
178 extern struct value
*eval_op_alignof (struct type
*expect_type
,
179 struct expression
*exp
,
182 extern struct value
*eval_op_memval (struct type
*expect_type
,
183 struct expression
*exp
,
185 struct value
*arg1
, struct type
*type
);
186 extern struct value
*eval_binop_assign_modify (struct type
*expect_type
,
187 struct expression
*exp
,
198 /* The check_objfile overloads are used to check whether a particular
199 component of some operation references an objfile. The passed-in
200 objfile will never be a debug objfile. */
202 /* See if EXP_OBJFILE matches OBJFILE. */
204 check_objfile (struct objfile
*exp_objfile
, struct objfile
*objfile
)
206 if (exp_objfile
->separate_debug_objfile_backlink
)
207 exp_objfile
= exp_objfile
->separate_debug_objfile_backlink
;
208 return exp_objfile
== objfile
;
212 check_objfile (struct type
*type
, struct objfile
*objfile
)
214 struct objfile
*ty_objfile
= type
->objfile_owner ();
215 if (ty_objfile
!= nullptr)
216 return check_objfile (ty_objfile
, objfile
);
221 check_objfile (struct symbol
*sym
, struct objfile
*objfile
)
223 return check_objfile (sym
->objfile (), objfile
);
226 extern bool check_objfile (const struct block
*block
,
227 struct objfile
*objfile
);
230 check_objfile (const block_symbol
&sym
, struct objfile
*objfile
)
232 return (check_objfile (sym
.symbol
, objfile
)
233 || check_objfile (sym
.block
, objfile
));
237 check_objfile (bound_minimal_symbol minsym
, struct objfile
*objfile
)
239 return check_objfile (minsym
.objfile
, objfile
);
243 check_objfile (internalvar
*ivar
, struct objfile
*objfile
)
249 check_objfile (const std::string
&str
, struct objfile
*objfile
)
255 check_objfile (const operation_up
&op
, struct objfile
*objfile
)
257 return op
->uses_objfile (objfile
);
261 check_objfile (enum exp_opcode val
, struct objfile
*objfile
)
267 check_objfile (ULONGEST val
, struct objfile
*objfile
)
273 check_objfile (const gdb_mpz
&val
, struct objfile
*objfile
)
280 check_objfile (enum_flags
<T
> val
, struct objfile
*objfile
)
287 check_objfile (const std::vector
<T
> &collection
, struct objfile
*objfile
)
289 for (const auto &item
: collection
)
291 if (check_objfile (item
, objfile
))
297 template<typename S
, typename T
>
299 check_objfile (const std::pair
<S
, T
> &item
, struct objfile
*objfile
)
301 return (check_objfile (item
.first
, objfile
)
302 || check_objfile (item
.second
, objfile
));
305 extern bool check_objfile (const std::unique_ptr
<ada_component
> &comp
,
306 struct objfile
*objfile
);
309 dump_for_expression (struct ui_file
*stream
, int depth
,
310 const operation_up
&op
)
313 gdb_printf (stream
, _("%*snullptr\n"), depth
, "");
315 op
->dump (stream
, depth
);
318 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
320 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
321 const std::string
&str
);
322 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
324 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
326 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
327 const gdb_mpz
&addr
);
328 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
330 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
332 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
333 const block_symbol
&sym
);
334 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
335 bound_minimal_symbol msym
);
336 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
338 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
339 type_instance_flags flags
);
340 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
341 enum c_string_type_values flags
);
342 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
343 enum range_flag flags
);
344 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
345 const std::unique_ptr
<ada_component
> &comp
);
349 dump_for_expression (struct ui_file
*stream
, int depth
,
350 const std::vector
<T
> &vals
)
352 gdb_printf (stream
, _("%*sVector:\n"), depth
, "");
353 for (auto &item
: vals
)
354 dump_for_expression (stream
, depth
+ 1, item
);
357 template<typename X
, typename Y
>
359 dump_for_expression (struct ui_file
*stream
, int depth
,
360 const std::pair
<X
, Y
> &vals
)
362 dump_for_expression (stream
, depth
, vals
.first
);
363 dump_for_expression (stream
, depth
, vals
.second
);
366 /* Base class for most concrete operations. This class holds data,
367 specified via template parameters, and supplies generic
368 implementations of the 'dump' and 'uses_objfile' methods. */
369 template<typename
... Arg
>
370 class tuple_holding_operation
: public operation
374 explicit tuple_holding_operation (Arg
... args
)
375 : m_storage (std::forward
<Arg
> (args
)...)
379 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation
);
381 bool uses_objfile (struct objfile
*objfile
) const override
383 return do_check_objfile
<0, Arg
...> (objfile
, m_storage
);
386 void dump (struct ui_file
*stream
, int depth
) const override
388 dump_for_expression (stream
, depth
, opcode ());
389 do_dump
<0, Arg
...> (stream
, depth
+ 1, m_storage
);
394 /* Storage for the data. */
395 std::tuple
<Arg
...> m_storage
;
399 /* do_dump does the work of dumping the data. */
400 template<int I
, typename
... T
>
401 typename
std::enable_if
<I
== sizeof... (T
), void>::type
402 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
407 template<int I
, typename
... T
>
408 typename
std::enable_if
<I
< sizeof... (T
), void>::type
409 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
412 dump_for_expression (stream
, depth
, std::get
<I
> (value
));
413 do_dump
<I
+ 1, T
...> (stream
, depth
, value
);
416 /* do_check_objfile does the work of checking whether this object
417 refers to OBJFILE. */
418 template<int I
, typename
... T
>
419 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
420 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
426 template<int I
, typename
... T
>
427 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
428 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
431 if (check_objfile (std::get
<I
> (value
), objfile
))
433 return do_check_objfile
<I
+ 1, T
...> (objfile
, value
);
437 /* The check_constant overloads are used to decide whether a given
438 concrete operation is a constant. This is done by checking the
442 check_constant (const operation_up
&item
)
444 return item
->constant_p ();
448 check_constant (bound_minimal_symbol msym
)
454 check_constant (struct type
*type
)
460 check_constant (const struct block
*block
)
466 check_constant (const std::string
&str
)
472 check_constant (ULONGEST cst
)
478 check_constant (const gdb_mpz
&cst
)
484 check_constant (struct symbol
*sym
)
486 enum address_class sc
= sym
->aclass ();
487 return (sc
== LOC_BLOCK
489 || sc
== LOC_CONST_BYTES
494 check_constant (const block_symbol
&sym
)
496 /* We know the block is constant, so we only need to check the
498 return check_constant (sym
.symbol
);
503 check_constant (const std::vector
<T
> &collection
)
505 for (const auto &item
: collection
)
506 if (!check_constant (item
))
511 template<typename S
, typename T
>
513 check_constant (const std::pair
<S
, T
> &item
)
515 return check_constant (item
.first
) && check_constant (item
.second
);
518 /* Base class for concrete operations. This class supplies an
519 implementation of 'constant_p' that works by checking the
521 template<typename
... Arg
>
522 class maybe_constant_operation
523 : public tuple_holding_operation
<Arg
...>
527 using tuple_holding_operation
<Arg
...>::tuple_holding_operation
;
529 bool constant_p () const override
531 return do_check_constant
<0, Arg
...> (this->m_storage
);
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
543 template<int I
, typename
... T
>
544 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
545 do_check_constant (const std::tuple
<T
...> &value
) const
547 if (!check_constant (std::get
<I
> (value
)))
549 return do_check_constant
<I
+ 1, T
...> (value
);
553 /* A floating-point constant. The constant is encoded in the target
556 typedef std::array
<gdb_byte
, 16> float_data
;
558 /* An operation that holds a floating-point constant of a given
561 This does not need the facilities provided by
562 tuple_holding_operation, so it does not use it. */
563 class float_const_operation
568 float_const_operation (struct type
*type
, float_data data
)
574 value
*evaluate (struct type
*expect_type
,
575 struct expression
*exp
,
576 enum noside noside
) override
578 return value_from_contents (m_type
, m_data
.data ());
581 enum exp_opcode
opcode () const override
584 bool constant_p () const override
587 void dump (struct ui_file
*stream
, int depth
) const override
;
595 class scope_operation
596 : public maybe_constant_operation
<struct type
*, std::string
>
600 using maybe_constant_operation::maybe_constant_operation
;
602 value
*evaluate (struct type
*expect_type
,
603 struct expression
*exp
,
604 enum noside noside
) override
606 return eval_op_scope (expect_type
, exp
, noside
,
607 std::get
<0> (m_storage
),
608 std::get
<1> (m_storage
).c_str ());
611 value
*evaluate_for_address (struct expression
*exp
,
612 enum noside noside
) override
;
614 value
*evaluate_funcall (struct type
*expect_type
,
615 struct expression
*exp
,
617 const std::vector
<operation_up
> &args
) override
;
619 enum exp_opcode
opcode () const override
624 void do_generate_ax (struct expression
*exp
,
625 struct agent_expr
*ax
,
626 struct axs_value
*value
,
627 struct type
*cast_type
)
631 /* Compute the value of a variable. */
632 class var_value_operation
633 : public maybe_constant_operation
<block_symbol
>
637 using maybe_constant_operation::maybe_constant_operation
;
639 value
*evaluate (struct type
*expect_type
,
640 struct expression
*exp
,
641 enum noside noside
) override
;
643 value
*evaluate_with_coercion (struct expression
*exp
,
644 enum noside noside
) override
;
646 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
649 value
*evaluate_for_cast (struct type
*expect_type
,
650 struct expression
*exp
,
651 enum noside noside
) override
;
653 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
656 value
*evaluate_funcall (struct type
*expect_type
,
657 struct expression
*exp
,
659 const std::vector
<operation_up
> &args
) override
;
661 enum exp_opcode
opcode () const override
662 { return OP_VAR_VALUE
; }
664 /* Return the symbol referenced by this object. */
665 symbol
*get_symbol () const
667 return std::get
<0> (m_storage
).symbol
;
672 void do_generate_ax (struct expression
*exp
,
673 struct agent_expr
*ax
,
674 struct axs_value
*value
,
675 struct type
*cast_type
)
679 class long_const_operation
680 : public tuple_holding_operation
<struct type
*, gdb_mpz
>
684 using tuple_holding_operation::tuple_holding_operation
;
686 long_const_operation (struct type
*type
, LONGEST val
)
687 : long_const_operation (type
, gdb_mpz (val
))
690 value
*evaluate (struct type
*expect_type
,
691 struct expression
*exp
,
692 enum noside noside
) override
694 return value_from_mpz (std::get
<0> (m_storage
), std::get
<1> (m_storage
));
697 enum exp_opcode
opcode () const override
700 bool constant_p () const override
705 LONGEST
as_longest () const
706 { return std::get
<1> (m_storage
).as_integer_truncate
<LONGEST
> (); }
708 void do_generate_ax (struct expression
*exp
,
709 struct agent_expr
*ax
,
710 struct axs_value
*value
,
711 struct type
*cast_type
)
715 class var_msym_value_operation
716 : public maybe_constant_operation
<bound_minimal_symbol
>
720 using maybe_constant_operation::maybe_constant_operation
;
722 value
*evaluate (struct type
*expect_type
,
723 struct expression
*exp
,
724 enum noside noside
) override
726 return eval_op_var_msym_value (expect_type
, exp
, noside
, m_outermost
,
727 std::get
<0> (m_storage
));
730 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
733 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
736 value
*evaluate_for_cast (struct type
*expect_type
,
737 struct expression
*exp
,
738 enum noside noside
) override
;
740 value
*evaluate_funcall (struct type
*expect_type
,
741 struct expression
*exp
,
743 const std::vector
<operation_up
> &args
) override
745 const char *name
= std::get
<0> (m_storage
).minsym
->print_name ();
746 return operation::evaluate_funcall (expect_type
, exp
, noside
, name
, args
);
749 enum exp_opcode
opcode () const override
750 { return OP_VAR_MSYM_VALUE
; }
752 void set_outermost () override
759 /* True if this is the outermost operation in the expression. */
760 bool m_outermost
= false;
762 void do_generate_ax (struct expression
*exp
,
763 struct agent_expr
*ax
,
764 struct axs_value
*value
,
765 struct type
*cast_type
)
769 class var_entry_value_operation
770 : public tuple_holding_operation
<symbol
*>
774 using tuple_holding_operation::tuple_holding_operation
;
776 value
*evaluate (struct type
*expect_type
,
777 struct expression
*exp
,
778 enum noside noside
) override
780 return eval_op_var_entry_value (expect_type
, exp
, noside
,
781 std::get
<0> (m_storage
));
784 enum exp_opcode
opcode () const override
785 { return OP_VAR_ENTRY_VALUE
; }
788 class func_static_var_operation
789 : public maybe_constant_operation
<operation_up
, std::string
>
793 using maybe_constant_operation::maybe_constant_operation
;
795 value
*evaluate (struct type
*expect_type
,
796 struct expression
*exp
,
797 enum noside noside
) override
799 value
*func
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
800 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
801 std::get
<1> (m_storage
).c_str ());
804 enum exp_opcode
opcode () const override
805 { return OP_FUNC_STATIC_VAR
; }
809 : public tuple_holding_operation
<int>
813 using tuple_holding_operation::tuple_holding_operation
;
815 value
*evaluate (struct type
*expect_type
,
816 struct expression
*exp
,
817 enum noside noside
) override
819 return access_value_history (std::get
<0> (m_storage
));
822 enum exp_opcode
opcode () const override
826 class register_operation
827 : public tuple_holding_operation
<std::string
>
831 using tuple_holding_operation::tuple_holding_operation
;
833 value
*evaluate (struct type
*expect_type
,
834 struct expression
*exp
,
835 enum noside noside
) override
837 return eval_op_register (expect_type
, exp
, noside
,
838 std::get
<0> (m_storage
).c_str ());
841 enum exp_opcode
opcode () const override
842 { return OP_REGISTER
; }
844 /* Return the name of the register. */
845 const char *get_name () const
847 return std::get
<0> (m_storage
).c_str ();
852 void do_generate_ax (struct expression
*exp
,
853 struct agent_expr
*ax
,
854 struct axs_value
*value
,
855 struct type
*cast_type
)
860 : public tuple_holding_operation
<bool>
864 using tuple_holding_operation::tuple_holding_operation
;
866 value
*evaluate (struct type
*expect_type
,
867 struct expression
*exp
,
868 enum noside noside
) override
870 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
871 return value_from_longest (type
, std::get
<0> (m_storage
));
874 enum exp_opcode
opcode () const override
877 bool constant_p () const override
881 class internalvar_operation
882 : public tuple_holding_operation
<internalvar
*>
886 using tuple_holding_operation::tuple_holding_operation
;
888 value
*evaluate (struct type
*expect_type
,
889 struct expression
*exp
,
890 enum noside noside
) override
892 return value_of_internalvar (exp
->gdbarch
,
893 std::get
<0> (m_storage
));
896 internalvar
*get_internalvar () const
898 return std::get
<0> (m_storage
);
901 enum exp_opcode
opcode () const override
902 { return OP_INTERNALVAR
; }
906 void do_generate_ax (struct expression
*exp
,
907 struct agent_expr
*ax
,
908 struct axs_value
*value
,
909 struct type
*cast_type
)
913 class string_operation
914 : public tuple_holding_operation
<std::string
>
918 using tuple_holding_operation::tuple_holding_operation
;
920 value
*evaluate (struct type
*expect_type
,
921 struct expression
*exp
,
922 enum noside noside
) override
;
924 enum exp_opcode
opcode () const override
925 { return OP_STRING
; }
928 class ternop_slice_operation
929 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
933 using maybe_constant_operation::maybe_constant_operation
;
935 value
*evaluate (struct type
*expect_type
,
936 struct expression
*exp
,
937 enum noside noside
) override
;
939 enum exp_opcode
opcode () const override
940 { return TERNOP_SLICE
; }
943 class ternop_cond_operation
944 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
948 using maybe_constant_operation::maybe_constant_operation
;
950 value
*evaluate (struct type
*expect_type
,
951 struct expression
*exp
,
952 enum noside noside
) override
955 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
957 if (value_logical_not (val
))
958 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
959 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
962 enum exp_opcode
opcode () const override
963 { return TERNOP_COND
; }
967 void do_generate_ax (struct expression
*exp
,
968 struct agent_expr
*ax
,
969 struct axs_value
*value
,
970 struct type
*cast_type
)
974 class complex_operation
975 : public maybe_constant_operation
<operation_up
, operation_up
, struct type
*>
979 using maybe_constant_operation::maybe_constant_operation
;
981 value
*evaluate (struct type
*expect_type
,
982 struct expression
*exp
,
983 enum noside noside
) override
985 value
*real
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
986 value
*imag
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
987 return value_literal_complex (real
, imag
,
988 std::get
<2> (m_storage
));
991 enum exp_opcode
opcode () const override
992 { return OP_COMPLEX
; }
995 class structop_base_operation
996 : public tuple_holding_operation
<operation_up
, std::string
>
1000 /* Used for completion. Return the field name. */
1001 const std::string
&get_string () const
1003 return std::get
<1> (m_storage
);
1006 value
*evaluate_funcall (struct type
*expect_type
,
1007 struct expression
*exp
,
1009 const std::vector
<operation_up
> &args
) override
;
1011 /* Try to complete this operation in the context of EXP. TRACKER is
1012 the completion tracker to update. Return true if completion was
1013 possible, false otherwise. */
1014 virtual bool complete (struct expression
*exp
, completion_tracker
&tracker
)
1016 return complete (exp
, tracker
, "");
1021 /* Do the work of the public 'complete' method. PREFIX is prepended
1023 bool complete (struct expression
*exp
, completion_tracker
&tracker
,
1024 const char *prefix
);
1026 using tuple_holding_operation::tuple_holding_operation
;
1029 class structop_operation
1030 : public structop_base_operation
1034 using structop_base_operation::structop_base_operation
;
1036 value
*evaluate (struct type
*expect_type
,
1037 struct expression
*exp
,
1038 enum noside noside
) override
1040 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1041 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
1042 std::get
<1> (m_storage
).c_str ());
1045 enum exp_opcode
opcode () const override
1046 { return STRUCTOP_STRUCT
; }
1050 void do_generate_ax (struct expression
*exp
,
1051 struct agent_expr
*ax
,
1052 struct axs_value
*value
,
1053 struct type
*cast_type
)
1056 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
1057 std::get
<0> (this->m_storage
).get (),
1058 std::get
<1> (this->m_storage
).c_str (),
1063 class structop_ptr_operation
1064 : public structop_base_operation
1068 using structop_base_operation::structop_base_operation
;
1070 value
*evaluate (struct type
*expect_type
,
1071 struct expression
*exp
,
1072 enum noside noside
) override
1074 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1075 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
1076 std::get
<1> (m_storage
).c_str ());
1079 enum exp_opcode
opcode () const override
1080 { return STRUCTOP_PTR
; }
1084 void do_generate_ax (struct expression
*exp
,
1085 struct agent_expr
*ax
,
1086 struct axs_value
*value
,
1087 struct type
*cast_type
)
1090 gen_expr_structop (exp
, STRUCTOP_PTR
,
1091 std::get
<0> (this->m_storage
).get (),
1092 std::get
<1> (this->m_storage
).c_str (),
1097 class structop_member_base
1098 : public tuple_holding_operation
<operation_up
, operation_up
>
1102 using tuple_holding_operation::tuple_holding_operation
;
1104 value
*evaluate_funcall (struct type
*expect_type
,
1105 struct expression
*exp
,
1107 const std::vector
<operation_up
> &args
) override
;
1110 class structop_member_operation
1111 : public structop_member_base
1115 using structop_member_base::structop_member_base
;
1117 value
*evaluate (struct type
*expect_type
,
1118 struct expression
*exp
,
1119 enum noside noside
) override
1122 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1124 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1125 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1128 enum exp_opcode
opcode () const override
1129 { return STRUCTOP_MEMBER
; }
1132 class structop_mptr_operation
1133 : public structop_member_base
1137 using structop_member_base::structop_member_base
;
1139 value
*evaluate (struct type
*expect_type
,
1140 struct expression
*exp
,
1141 enum noside noside
) override
1144 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1146 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1147 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1150 enum exp_opcode
opcode () const override
1151 { return STRUCTOP_MPTR
; }
1154 class concat_operation
1155 : public maybe_constant_operation
<operation_up
, operation_up
>
1159 using maybe_constant_operation::maybe_constant_operation
;
1161 value
*evaluate (struct type
*expect_type
,
1162 struct expression
*exp
,
1163 enum noside noside
) override
1166 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1168 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1169 return value_concat (lhs
, rhs
);
1172 enum exp_opcode
opcode () const override
1173 { return BINOP_CONCAT
; }
1177 : public maybe_constant_operation
<operation_up
, operation_up
>
1181 using maybe_constant_operation::maybe_constant_operation
;
1183 value
*evaluate (struct type
*expect_type
,
1184 struct expression
*exp
,
1185 enum noside noside
) override
1188 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1190 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1191 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1194 enum exp_opcode
opcode () const override
1195 { return BINOP_ADD
; }
1199 void do_generate_ax (struct expression
*exp
,
1200 struct agent_expr
*ax
,
1201 struct axs_value
*value
,
1202 struct type
*cast_type
)
1205 gen_expr_binop (exp
, BINOP_ADD
,
1206 std::get
<0> (this->m_storage
).get (),
1207 std::get
<1> (this->m_storage
).get (),
1213 : public maybe_constant_operation
<operation_up
, operation_up
>
1217 using maybe_constant_operation::maybe_constant_operation
;
1219 value
*evaluate (struct type
*expect_type
,
1220 struct expression
*exp
,
1221 enum noside noside
) override
1224 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1226 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1227 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1230 enum exp_opcode
opcode () const override
1231 { return BINOP_SUB
; }
1235 void do_generate_ax (struct expression
*exp
,
1236 struct agent_expr
*ax
,
1237 struct axs_value
*value
,
1238 struct type
*cast_type
)
1241 gen_expr_binop (exp
, BINOP_SUB
,
1242 std::get
<0> (this->m_storage
).get (),
1243 std::get
<1> (this->m_storage
).get (),
1248 typedef struct value
*binary_ftype (struct type
*expect_type
,
1249 struct expression
*exp
,
1250 enum noside noside
, enum exp_opcode op
,
1251 struct value
*arg1
, struct value
*arg2
);
1253 template<enum exp_opcode OP
, binary_ftype FUNC
>
1254 class binop_operation
1255 : public maybe_constant_operation
<operation_up
, operation_up
>
1259 using maybe_constant_operation::maybe_constant_operation
;
1261 value
*evaluate (struct type
*expect_type
,
1262 struct expression
*exp
,
1263 enum noside noside
) override
1266 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1268 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1269 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1272 enum exp_opcode
opcode () const override
1276 template<enum exp_opcode OP
, binary_ftype FUNC
>
1277 class usual_ax_binop_operation
1278 : public binop_operation
<OP
, FUNC
>
1282 using binop_operation
<OP
, FUNC
>::binop_operation
;
1286 void do_generate_ax (struct expression
*exp
,
1287 struct agent_expr
*ax
,
1288 struct axs_value
*value
,
1289 struct type
*cast_type
)
1292 gen_expr_binop (exp
, OP
,
1293 std::get
<0> (this->m_storage
).get (),
1294 std::get
<1> (this->m_storage
).get (),
1299 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1300 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1301 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1303 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1304 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1305 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1306 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1307 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1308 using bitwise_and_operation
1309 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1310 using bitwise_ior_operation
1311 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1312 using bitwise_xor_operation
1313 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1315 class subscript_operation
1316 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1319 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1320 eval_op_subscript
>::usual_ax_binop_operation
;
1322 value
*evaluate_for_sizeof (struct expression
*exp
,
1323 enum noside noside
) override
;
1326 /* Implementation of comparison operations. */
1327 template<enum exp_opcode OP
, binary_ftype FUNC
>
1328 class comparison_operation
1329 : public usual_ax_binop_operation
<OP
, FUNC
>
1333 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1335 value
*evaluate (struct type
*expect_type
,
1336 struct expression
*exp
,
1337 enum noside noside
) override
1340 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1342 = std::get
<1> (this->m_storage
)->evaluate (lhs
->type (), exp
,
1344 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1348 class equal_operation
1349 : public comparison_operation
<BINOP_EQUAL
, eval_op_equal
>
1353 using comparison_operation::comparison_operation
;
1355 operation
*get_lhs () const
1357 return std::get
<0> (m_storage
).get ();
1360 operation
*get_rhs () const
1362 return std::get
<1> (m_storage
).get ();
1366 using notequal_operation
1367 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1368 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1369 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1370 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1371 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1373 /* Implement the GDB '@' repeat operator. */
1374 class repeat_operation
1375 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1377 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1381 void do_generate_ax (struct expression
*exp
,
1382 struct agent_expr
*ax
,
1383 struct axs_value
*value
,
1384 struct type
*cast_type
)
1388 /* C-style comma operator. */
1389 class comma_operation
1390 : public maybe_constant_operation
<operation_up
, operation_up
>
1394 using maybe_constant_operation::maybe_constant_operation
;
1396 value
*evaluate (struct type
*expect_type
,
1397 struct expression
*exp
,
1398 enum noside noside
) override
1400 /* The left-hand-side is only evaluated for side effects, so don't
1401 bother in other modes. */
1402 if (noside
== EVAL_NORMAL
)
1403 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1404 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1407 enum exp_opcode
opcode () const override
1408 { return BINOP_COMMA
; }
1412 void do_generate_ax (struct expression
*exp
,
1413 struct agent_expr
*ax
,
1414 struct axs_value
*value
,
1415 struct type
*cast_type
)
1419 typedef struct value
*unary_ftype (struct type
*expect_type
,
1420 struct expression
*exp
,
1421 enum noside noside
, enum exp_opcode op
,
1422 struct value
*arg1
);
1424 /* Base class for unary operations. */
1425 template<enum exp_opcode OP
, unary_ftype FUNC
>
1426 class unop_operation
1427 : public maybe_constant_operation
<operation_up
>
1431 using maybe_constant_operation::maybe_constant_operation
;
1433 value
*evaluate (struct type
*expect_type
,
1434 struct expression
*exp
,
1435 enum noside noside
) override
1437 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1438 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1441 enum exp_opcode
opcode () const override
1445 /* Unary operations that can also be turned into agent expressions in
1447 template<enum exp_opcode OP
, unary_ftype FUNC
>
1448 class usual_ax_unop_operation
1449 : public unop_operation
<OP
, FUNC
>
1451 using unop_operation
<OP
, FUNC
>::unop_operation
;
1455 void do_generate_ax (struct expression
*exp
,
1456 struct agent_expr
*ax
,
1457 struct axs_value
*value
,
1458 struct type
*cast_type
)
1461 gen_expr_unop (exp
, OP
,
1462 std::get
<0> (this->m_storage
).get (),
1467 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1468 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1469 using unary_complement_operation
1470 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1471 using unary_logical_not_operation
1472 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1474 /* Handle pre- and post- increment and -decrement. */
1475 template<enum exp_opcode OP
, unary_ftype FUNC
>
1476 class unop_incr_operation
1477 : public tuple_holding_operation
<operation_up
>
1481 using tuple_holding_operation::tuple_holding_operation
;
1483 value
*evaluate (struct type
*expect_type
,
1484 struct expression
*exp
,
1485 enum noside noside
) override
1487 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1488 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1491 enum exp_opcode
opcode () const override
1495 using preinc_operation
1496 = unop_incr_operation
<UNOP_PREINCREMENT
, eval_op_preinc
>;
1497 using predec_operation
1498 = unop_incr_operation
<UNOP_PREDECREMENT
, eval_op_predec
>;
1499 using postinc_operation
1500 = unop_incr_operation
<UNOP_POSTINCREMENT
, eval_op_postinc
>;
1501 using postdec_operation
1502 = unop_incr_operation
<UNOP_POSTDECREMENT
, eval_op_postdec
>;
1504 /* Base class for implementations of UNOP_IND. */
1505 class unop_ind_base_operation
1506 : public tuple_holding_operation
<operation_up
>
1510 using tuple_holding_operation::tuple_holding_operation
;
1512 value
*evaluate (struct type
*expect_type
,
1513 struct expression
*exp
,
1514 enum noside noside
) override
1516 if (expect_type
!= nullptr && expect_type
->code () == TYPE_CODE_PTR
)
1517 expect_type
= check_typedef (expect_type
)->target_type ();
1518 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1519 return eval_op_ind (expect_type
, exp
, noside
, val
);
1522 value
*evaluate_for_address (struct expression
*exp
,
1523 enum noside noside
) override
;
1525 value
*evaluate_for_sizeof (struct expression
*exp
,
1526 enum noside noside
) override
;
1528 enum exp_opcode
opcode () const override
1529 { return UNOP_IND
; }
1532 /* Ordinary UNOP_IND implementation. */
1533 class unop_ind_operation
1534 : public unop_ind_base_operation
1538 using unop_ind_base_operation::unop_ind_base_operation
;
1542 void do_generate_ax (struct expression
*exp
,
1543 struct agent_expr
*ax
,
1544 struct axs_value
*value
,
1545 struct type
*cast_type
)
1548 gen_expr_unop (exp
, UNOP_IND
,
1549 std::get
<0> (this->m_storage
).get (),
1554 /* Implement OP_TYPE. */
1555 class type_operation
1556 : public tuple_holding_operation
<struct type
*>
1560 using tuple_holding_operation::tuple_holding_operation
;
1562 value
*evaluate (struct type
*expect_type
,
1563 struct expression
*exp
,
1564 enum noside noside
) override
1566 return eval_op_type (expect_type
, exp
, noside
, std::get
<0> (m_storage
));
1569 enum exp_opcode
opcode () const override
1572 bool constant_p () const override
1576 /* Implement the "typeof" operation. */
1577 class typeof_operation
1578 : public maybe_constant_operation
<operation_up
>
1582 using maybe_constant_operation::maybe_constant_operation
;
1584 value
*evaluate (struct type
*expect_type
,
1585 struct expression
*exp
,
1586 enum noside noside
) override
1588 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1589 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1590 EVAL_AVOID_SIDE_EFFECTS
);
1592 error (_("Attempt to use a type as an expression"));
1595 enum exp_opcode
opcode () const override
1596 { return OP_TYPEOF
; }
1599 /* Implement 'decltype'. */
1600 class decltype_operation
1601 : public maybe_constant_operation
<operation_up
>
1605 using maybe_constant_operation::maybe_constant_operation
;
1607 value
*evaluate (struct type
*expect_type
,
1608 struct expression
*exp
,
1609 enum noside noside
) override
1611 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
= result
->type ();
1627 if (!TYPE_IS_REFERENCE (type
))
1629 type
= lookup_lvalue_reference_type (type
);
1630 result
= value::allocate (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 value::allocate (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 return std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1689 enum exp_opcode
opcode () const override
1690 { return UNOP_ADDR
; }
1692 /* Return the subexpression. */
1693 const operation_up
&get_expression () const
1695 return std::get
<0> (m_storage
);
1700 void do_generate_ax (struct expression
*exp
,
1701 struct agent_expr
*ax
,
1702 struct axs_value
*value
,
1703 struct type
*cast_type
)
1706 gen_expr_unop (exp
, UNOP_ADDR
,
1707 std::get
<0> (this->m_storage
).get (),
1712 /* Implement 'sizeof'. */
1713 class unop_sizeof_operation
1714 : public maybe_constant_operation
<operation_up
>
1718 using maybe_constant_operation::maybe_constant_operation
;
1720 value
*evaluate (struct type
*expect_type
,
1721 struct expression
*exp
,
1722 enum noside noside
) override
1724 return std::get
<0> (m_storage
)->evaluate_for_sizeof (exp
, noside
);
1727 enum exp_opcode
opcode () const override
1728 { return UNOP_SIZEOF
; }
1732 void do_generate_ax (struct expression
*exp
,
1733 struct agent_expr
*ax
,
1734 struct axs_value
*value
,
1735 struct type
*cast_type
)
1739 /* Implement 'alignof'. */
1740 class unop_alignof_operation
1741 : public maybe_constant_operation
<operation_up
>
1745 using maybe_constant_operation::maybe_constant_operation
;
1747 value
*evaluate (struct type
*expect_type
,
1748 struct expression
*exp
,
1749 enum noside noside
) override
1751 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1752 EVAL_AVOID_SIDE_EFFECTS
);
1753 return eval_op_alignof (expect_type
, exp
, noside
, val
);
1756 enum exp_opcode
opcode () const override
1757 { return UNOP_ALIGNOF
; }
1760 /* Implement UNOP_MEMVAL. */
1761 class unop_memval_operation
1762 : public tuple_holding_operation
<operation_up
, struct type
*>
1766 using tuple_holding_operation::tuple_holding_operation
;
1768 value
*evaluate (struct type
*expect_type
,
1769 struct expression
*exp
,
1770 enum noside noside
) override
1772 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1773 return eval_op_memval (expect_type
, exp
, noside
, val
,
1774 std::get
<1> (m_storage
));
1777 value
*evaluate_for_sizeof (struct expression
*exp
,
1778 enum noside noside
) override
;
1780 value
*evaluate_for_address (struct expression
*exp
,
1781 enum noside noside
) override
;
1783 enum exp_opcode
opcode () const override
1784 { return UNOP_MEMVAL
; }
1786 /* Return the type referenced by this object. */
1787 struct type
*get_type () const
1789 return std::get
<1> (m_storage
);
1794 void do_generate_ax (struct expression
*exp
,
1795 struct agent_expr
*ax
,
1796 struct axs_value
*value
,
1797 struct type
*cast_type
)
1801 /* Implement UNOP_MEMVAL_TYPE. */
1802 class unop_memval_type_operation
1803 : public tuple_holding_operation
<operation_up
, operation_up
>
1807 using tuple_holding_operation::tuple_holding_operation
;
1809 value
*evaluate (struct type
*expect_type
,
1810 struct expression
*exp
,
1811 enum noside noside
) override
1814 = std::get
<0> (m_storage
)->evaluate (expect_type
, exp
,
1815 EVAL_AVOID_SIDE_EFFECTS
);
1816 struct type
*type
= typeval
->type ();
1817 value
*val
= std::get
<1> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1818 return eval_op_memval (expect_type
, exp
, noside
, val
, type
);
1821 value
*evaluate_for_sizeof (struct expression
*exp
,
1822 enum noside noside
) override
;
1824 value
*evaluate_for_address (struct expression
*exp
,
1825 enum noside noside
) override
;
1827 enum exp_opcode
opcode () const override
1828 { return UNOP_MEMVAL_TYPE
; }
1832 void do_generate_ax (struct expression
*exp
,
1833 struct agent_expr
*ax
,
1834 struct axs_value
*value
,
1835 struct type
*cast_type
)
1839 /* Implement the 'this' expression. */
1840 class op_this_operation
1841 : public tuple_holding_operation
<>
1845 using tuple_holding_operation::tuple_holding_operation
;
1847 value
*evaluate (struct type
*expect_type
,
1848 struct expression
*exp
,
1849 enum noside noside
) override
1851 return value_of_this (exp
->language_defn
);
1854 enum exp_opcode
opcode () const override
1859 void do_generate_ax (struct expression
*exp
,
1860 struct agent_expr
*ax
,
1861 struct axs_value
*value
,
1862 struct type
*cast_type
)
1866 /* Implement the "type instance" operation. */
1867 class type_instance_operation
1868 : public tuple_holding_operation
<type_instance_flags
, std::vector
<type
*>,
1873 using tuple_holding_operation::tuple_holding_operation
;
1875 value
*evaluate (struct type
*expect_type
,
1876 struct expression
*exp
,
1877 enum noside noside
) override
;
1879 enum exp_opcode
opcode () const override
1880 { return TYPE_INSTANCE
; }
1883 /* The assignment operator. */
1884 class assign_operation
1885 : public tuple_holding_operation
<operation_up
, operation_up
>
1889 using tuple_holding_operation::tuple_holding_operation
;
1891 value
*evaluate (struct type
*expect_type
,
1892 struct expression
*exp
,
1893 enum noside noside
) override
1895 value
*lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1896 /* Special-case assignments where the left-hand-side is a
1897 convenience variable -- in these, don't bother setting an
1898 expected type. This avoids a weird case where re-assigning a
1899 string or array to an internal variable could error with "Too
1900 many array elements". */
1901 struct type
*xtype
= (lhs
->lval () == lval_internalvar
1904 value
*rhs
= std::get
<1> (m_storage
)->evaluate (xtype
, exp
, noside
);
1906 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1908 if (binop_user_defined_p (BINOP_ASSIGN
, lhs
, rhs
))
1909 return value_x_binop (lhs
, rhs
, BINOP_ASSIGN
, OP_NULL
, noside
);
1911 return value_assign (lhs
, rhs
);
1914 enum exp_opcode
opcode () const override
1915 { return BINOP_ASSIGN
; }
1917 /* Return the left-hand-side of the assignment. */
1918 operation
*get_lhs () const
1920 return std::get
<0> (m_storage
).get ();
1925 void do_generate_ax (struct expression
*exp
,
1926 struct agent_expr
*ax
,
1927 struct axs_value
*value
,
1928 struct type
*cast_type
)
1932 /* Assignment with modification, like "+=". */
1933 class assign_modify_operation
1934 : public tuple_holding_operation
<exp_opcode
, operation_up
, operation_up
>
1938 using tuple_holding_operation::tuple_holding_operation
;
1940 value
*evaluate (struct type
*expect_type
,
1941 struct expression
*exp
,
1942 enum noside noside
) override
1944 value
*lhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1945 value
*rhs
= std::get
<2> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1946 return eval_binop_assign_modify (expect_type
, exp
, noside
,
1947 std::get
<0> (m_storage
), lhs
, rhs
);
1950 enum exp_opcode
opcode () const override
1951 { return BINOP_ASSIGN_MODIFY
; }
1955 void do_generate_ax (struct expression
*exp
,
1956 struct agent_expr
*ax
,
1957 struct axs_value
*value
,
1958 struct type
*cast_type
)
1962 /* Not a cast! Extract a value of a given type from the contents of a
1963 value. The new value is extracted from the least significant bytes
1964 of the old value. The new value's type must be no bigger than the
1966 class unop_extract_operation
1967 : public maybe_constant_operation
<operation_up
, struct type
*>
1971 using maybe_constant_operation::maybe_constant_operation
;
1973 value
*evaluate (struct type
*expect_type
, struct expression
*exp
,
1974 enum noside noside
) override
;
1976 enum exp_opcode
opcode () const override
1977 { return UNOP_EXTRACT
; }
1979 /* Return the type referenced by this object. */
1980 struct type
*get_type () const
1982 return std::get
<1> (m_storage
);
1987 void do_generate_ax (struct expression
*exp
,
1988 struct agent_expr
*ax
,
1989 struct axs_value
*value
,
1990 struct type
*cast_type
) override
;
1994 class unop_cast_operation
1995 : public maybe_constant_operation
<operation_up
, struct type
*>
1999 using maybe_constant_operation::maybe_constant_operation
;
2001 value
*evaluate (struct type
*expect_type
,
2002 struct expression
*exp
,
2003 enum noside noside
) override
2005 return std::get
<0> (m_storage
)->evaluate_for_cast (std::get
<1> (m_storage
),
2009 enum exp_opcode
opcode () const override
2010 { return UNOP_CAST
; }
2012 /* Return the type referenced by this object. */
2013 struct type
*get_type () const
2015 return std::get
<1> (m_storage
);
2020 void do_generate_ax (struct expression
*exp
,
2021 struct agent_expr
*ax
,
2022 struct axs_value
*value
,
2023 struct type
*cast_type
)
2027 /* A cast, but the type comes from an expression, not a "struct
2029 class unop_cast_type_operation
2030 : public maybe_constant_operation
<operation_up
, operation_up
>
2034 using maybe_constant_operation::maybe_constant_operation
;
2036 value
*evaluate (struct type
*expect_type
,
2037 struct expression
*exp
,
2038 enum noside noside
) override
2040 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2041 EVAL_AVOID_SIDE_EFFECTS
);
2042 return std::get
<1> (m_storage
)->evaluate_for_cast (val
->type (),
2046 enum exp_opcode
opcode () const override
2047 { return UNOP_CAST_TYPE
; }
2051 void do_generate_ax (struct expression
*exp
,
2052 struct agent_expr
*ax
,
2053 struct axs_value
*value
,
2054 struct type
*cast_type
)
2058 typedef value
*cxx_cast_ftype (struct type
*, value
*);
2060 /* This implements dynamic_cast and reinterpret_cast. static_cast and
2061 const_cast are handled by the ordinary case operations. */
2062 template<exp_opcode OP
, cxx_cast_ftype FUNC
>
2063 class cxx_cast_operation
2064 : public maybe_constant_operation
<operation_up
, operation_up
>
2068 using maybe_constant_operation::maybe_constant_operation
;
2070 value
*evaluate (struct type
*expect_type
,
2071 struct expression
*exp
,
2072 enum noside noside
) override
2074 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2075 EVAL_AVOID_SIDE_EFFECTS
);
2076 struct type
*type
= val
->type ();
2077 value
*rhs
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
2078 return FUNC (type
, rhs
);
2081 enum exp_opcode
opcode () const override
2085 using dynamic_cast_operation
= cxx_cast_operation
<UNOP_DYNAMIC_CAST
,
2086 value_dynamic_cast
>;
2087 using reinterpret_cast_operation
= cxx_cast_operation
<UNOP_REINTERPRET_CAST
,
2088 value_reinterpret_cast
>;
2090 /* Multi-dimensional subscripting. */
2091 class multi_subscript_operation
2092 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2096 using tuple_holding_operation::tuple_holding_operation
;
2098 value
*evaluate (struct type
*expect_type
,
2099 struct expression
*exp
,
2100 enum noside noside
) override
;
2102 enum exp_opcode
opcode () const override
2103 { return MULTI_SUBSCRIPT
; }
2106 /* The "&&" operator. */
2107 class logical_and_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_AND
; }
2123 void do_generate_ax (struct expression
*exp
,
2124 struct agent_expr
*ax
,
2125 struct axs_value
*value
,
2126 struct type
*cast_type
)
2130 /* The "||" operator. */
2131 class logical_or_operation
2132 : public maybe_constant_operation
<operation_up
, operation_up
>
2136 using maybe_constant_operation::maybe_constant_operation
;
2138 value
*evaluate (struct type
*expect_type
,
2139 struct expression
*exp
,
2140 enum noside noside
) override
;
2142 enum exp_opcode
opcode () const override
2143 { return BINOP_LOGICAL_OR
; }
2147 void do_generate_ax (struct expression
*exp
,
2148 struct agent_expr
*ax
,
2149 struct axs_value
*value
,
2150 struct type
*cast_type
)
2154 /* This class implements ADL (aka Koenig) function calls for C++. It
2155 holds the name of the function to call, the block in which the
2156 lookup should be done, and a vector of arguments. */
2157 class adl_func_operation
2158 : public tuple_holding_operation
<std::string
, const block
*,
2159 std::vector
<operation_up
>>
2163 using tuple_holding_operation::tuple_holding_operation
;
2165 value
*evaluate (struct type
*expect_type
,
2166 struct expression
*exp
,
2167 enum noside noside
) override
;
2169 enum exp_opcode
opcode () const override
2170 { return OP_ADL_FUNC
; }
2173 /* The OP_ARRAY operation. */
2174 class array_operation
2175 : public tuple_holding_operation
<int, int, std::vector
<operation_up
>>
2179 using tuple_holding_operation::tuple_holding_operation
;
2181 value
*evaluate (struct type
*expect_type
,
2182 struct expression
*exp
,
2183 enum noside noside
) override
;
2185 enum exp_opcode
opcode () const override
2186 { return OP_ARRAY
; }
2190 struct value
*evaluate_struct_tuple (struct value
*struct_val
,
2191 struct expression
*exp
,
2192 enum noside noside
, int nargs
);
2195 /* A function call. This holds the callee operation and the
2197 class funcall_operation
2198 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2202 using tuple_holding_operation::tuple_holding_operation
;
2204 value
*evaluate (struct type
*expect_type
,
2205 struct expression
*exp
,
2206 enum noside noside
) override
2208 return std::get
<0> (m_storage
)->evaluate_funcall (expect_type
, exp
, noside
,
2209 std::get
<1> (m_storage
));
2212 enum exp_opcode
opcode () const override
2213 { return OP_FUNCALL
; }
2216 } /* namespace expr */
2218 #endif /* EXPOP_H */