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
,
169 /* The check_objfile overloads are used to check whether a particular
170 component of some operation references an objfile. The passed-in
171 objfile will never be a debug objfile. */
173 /* See if EXP_OBJFILE matches OBJFILE. */
175 check_objfile (struct objfile
*exp_objfile
, struct objfile
*objfile
)
177 if (exp_objfile
->separate_debug_objfile_backlink
)
178 exp_objfile
= exp_objfile
->separate_debug_objfile_backlink
;
179 return exp_objfile
== objfile
;
183 check_objfile (struct type
*type
, struct objfile
*objfile
)
185 struct objfile
*ty_objfile
= type
->objfile_owner ();
186 if (ty_objfile
!= nullptr)
187 return check_objfile (ty_objfile
, objfile
);
192 check_objfile (struct symbol
*sym
, struct objfile
*objfile
)
194 return check_objfile (symbol_objfile (sym
), objfile
);
198 check_objfile (const struct block
*block
, struct objfile
*objfile
)
200 return check_objfile (block_objfile (block
), objfile
);
204 check_objfile (minimal_symbol
*minsym
, struct objfile
*objfile
)
206 /* This may seem strange but minsyms are only used with an objfile
212 check_objfile (internalvar
*ivar
, struct objfile
*objfile
)
218 check_objfile (const std::string
&str
, struct objfile
*objfile
)
224 check_objfile (const operation_up
&op
, struct objfile
*objfile
)
226 return op
->uses_objfile (objfile
);
230 check_objfile (enum exp_opcode val
, struct objfile
*objfile
)
236 check_objfile (ULONGEST val
, struct objfile
*objfile
)
243 check_objfile (enum_flags
<T
> val
, struct objfile
*objfile
)
250 check_objfile (const std::vector
<T
> &collection
, struct objfile
*objfile
)
252 for (const auto &item
: collection
)
254 if (check_objfile (item
, objfile
))
260 template<typename S
, typename T
>
262 check_objfile (const std::pair
<S
, T
> &item
, struct objfile
*objfile
)
264 return (check_objfile (item
.first
, objfile
)
265 || check_objfile (item
.second
, objfile
));
269 dump_for_expression (struct ui_file
*stream
, int depth
,
270 const operation_up
&op
)
272 op
->dump (stream
, depth
);
275 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
277 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
278 const std::string
&str
);
279 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
281 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
283 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
285 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
287 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
288 minimal_symbol
*msym
);
289 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
291 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
292 type_instance_flags flags
);
293 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
294 enum c_string_type_values flags
);
295 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
296 enum range_flag flags
);
297 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
302 dump_for_expression (struct ui_file
*stream
, int depth
,
303 const std::vector
<T
> &vals
)
305 fprintf_filtered (stream
, _("%*sVector:\n"), depth
, "");
306 for (auto &item
: vals
)
307 dump_for_expression (stream
, depth
+ 1, item
);
310 template<typename X
, typename Y
>
312 dump_for_expression (struct ui_file
*stream
, int depth
,
313 const std::pair
<X
, Y
> &vals
)
315 dump_for_expression (stream
, depth
, vals
.first
);
316 dump_for_expression (stream
, depth
, vals
.second
);
319 /* Base class for most concrete operations. This class holds data,
320 specified via template parameters, and supplies generic
321 implementations of the 'dump' and 'uses_objfile' methods. */
322 template<typename
... Arg
>
323 class tuple_holding_operation
: public operation
327 explicit tuple_holding_operation (Arg
... args
)
328 : m_storage (std::forward
<Arg
> (args
)...)
332 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation
);
334 bool uses_objfile (struct objfile
*objfile
) const override
336 return do_check_objfile
<0, Arg
...> (objfile
, m_storage
);
339 void dump (struct ui_file
*stream
, int depth
) const override
341 dump_for_expression (stream
, depth
, opcode ());
342 do_dump
<0, Arg
...> (stream
, depth
+ 1, m_storage
);
347 /* Storage for the data. */
348 std::tuple
<Arg
...> m_storage
;
352 /* do_dump does the work of dumping the data. */
353 template<int I
, typename
... T
>
354 typename
std::enable_if
<I
== sizeof... (T
), void>::type
355 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
360 template<int I
, typename
... T
>
361 typename
std::enable_if
<I
< sizeof... (T
), void>::type
362 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
365 dump_for_expression (stream
, depth
, std::get
<I
> (value
));
366 do_dump
<I
+ 1, T
...> (stream
, depth
, value
);
369 /* do_check_objfile does the work of checking whether this object
370 refers to OBJFILE. */
371 template<int I
, typename
... T
>
372 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
373 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
379 template<int I
, typename
... T
>
380 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
381 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
384 if (check_objfile (std::get
<I
> (value
), objfile
))
386 return do_check_objfile
<I
+ 1, T
...> (objfile
, value
);
390 /* The check_constant overloads are used to decide whether a given
391 concrete operation is a constant. This is done by checking the
395 check_constant (const operation_up
&item
)
397 return item
->constant_p ();
401 check_constant (struct minimal_symbol
*msym
)
407 check_constant (struct type
*type
)
413 check_constant (const struct block
*block
)
419 check_constant (const std::string
&str
)
425 check_constant (struct objfile
*objfile
)
431 check_constant (ULONGEST cst
)
437 check_constant (struct symbol
*sym
)
439 enum address_class sc
= SYMBOL_CLASS (sym
);
440 return (sc
== LOC_BLOCK
442 || sc
== LOC_CONST_BYTES
448 check_constant (const std::vector
<T
> &collection
)
450 for (const auto &item
: collection
)
451 if (!check_constant (item
))
456 template<typename S
, typename T
>
458 check_constant (const std::pair
<S
, T
> &item
)
460 return check_constant (item
.first
) && check_constant (item
.second
);
463 /* Base class for concrete operations. This class supplies an
464 implementation of 'constant_p' that works by checking the
466 template<typename
... Arg
>
467 class maybe_constant_operation
468 : public tuple_holding_operation
<Arg
...>
472 using tuple_holding_operation
<Arg
...>::tuple_holding_operation
;
474 bool constant_p () const override
476 return do_check_constant
<0, Arg
...> (this->m_storage
);
481 template<int I
, typename
... T
>
482 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
483 do_check_constant (const std::tuple
<T
...> &value
) const
488 template<int I
, typename
... T
>
489 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
490 do_check_constant (const std::tuple
<T
...> &value
) const
492 if (!check_constant (std::get
<I
> (value
)))
494 return do_check_constant
<I
+ 1, T
...> (value
);
498 /* A floating-point constant. The constant is encoded in the target
501 typedef std::array
<gdb_byte
, 16> float_data
;
503 /* An operation that holds a floating-point constant of a given
506 This does not need the facilities provided by
507 tuple_holding_operation, so it does not use it. */
508 class float_const_operation
513 float_const_operation (struct type
*type
, float_data data
)
519 value
*evaluate (struct type
*expect_type
,
520 struct expression
*exp
,
521 enum noside noside
) override
523 return value_from_contents (m_type
, m_data
.data ());
526 enum exp_opcode
opcode () const override
529 bool constant_p () const override
532 void dump (struct ui_file
*stream
, int depth
) const override
;
540 class scope_operation
541 : public maybe_constant_operation
<struct type
*, std::string
>
545 using maybe_constant_operation::maybe_constant_operation
;
547 value
*evaluate (struct type
*expect_type
,
548 struct expression
*exp
,
549 enum noside noside
) override
551 return eval_op_scope (expect_type
, exp
, noside
,
552 std::get
<0> (m_storage
),
553 std::get
<1> (m_storage
).c_str ());
556 value
*evaluate_for_address (struct expression
*exp
,
557 enum noside noside
) override
;
559 enum exp_opcode
opcode () const override
564 void do_generate_ax (struct expression
*exp
,
565 struct agent_expr
*ax
,
566 struct axs_value
*value
,
567 struct type
*cast_type
)
571 class long_const_operation
572 : public tuple_holding_operation
<struct type
*, LONGEST
>
576 using tuple_holding_operation::tuple_holding_operation
;
578 value
*evaluate (struct type
*expect_type
,
579 struct expression
*exp
,
580 enum noside noside
) override
582 return value_from_longest (std::get
<0> (m_storage
),
583 std::get
<1> (m_storage
));
586 enum exp_opcode
opcode () const override
589 bool constant_p () const override
594 void do_generate_ax (struct expression
*exp
,
595 struct agent_expr
*ax
,
596 struct axs_value
*value
,
597 struct type
*cast_type
)
601 class var_msym_value_operation
602 : public maybe_constant_operation
<minimal_symbol
*, struct objfile
*>
606 using maybe_constant_operation::maybe_constant_operation
;
608 value
*evaluate (struct type
*expect_type
,
609 struct expression
*exp
,
610 enum noside noside
) override
612 return eval_op_var_msym_value (expect_type
, exp
, noside
, m_outermost
,
613 std::get
<0> (m_storage
),
614 std::get
<1> (m_storage
));
617 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
620 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
623 value
*evaluate_for_cast (struct type
*expect_type
,
624 struct expression
*exp
,
625 enum noside noside
) override
;
627 enum exp_opcode
opcode () const override
628 { return OP_VAR_MSYM_VALUE
; }
630 void set_outermost () override
637 /* True if this is the outermost operation in the expression. */
638 bool m_outermost
= false;
640 void do_generate_ax (struct expression
*exp
,
641 struct agent_expr
*ax
,
642 struct axs_value
*value
,
643 struct type
*cast_type
)
647 class var_entry_value_operation
648 : public tuple_holding_operation
<symbol
*>
652 using tuple_holding_operation::tuple_holding_operation
;
654 value
*evaluate (struct type
*expect_type
,
655 struct expression
*exp
,
656 enum noside noside
) override
658 return eval_op_var_entry_value (expect_type
, exp
, noside
,
659 std::get
<0> (m_storage
));
662 enum exp_opcode
opcode () const override
663 { return OP_VAR_ENTRY_VALUE
; }
666 class func_static_var_operation
667 : public maybe_constant_operation
<operation_up
, std::string
>
671 using maybe_constant_operation::maybe_constant_operation
;
673 value
*evaluate (struct type
*expect_type
,
674 struct expression
*exp
,
675 enum noside noside
) override
677 value
*func
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
678 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
679 std::get
<1> (m_storage
).c_str ());
682 enum exp_opcode
opcode () const override
683 { return OP_FUNC_STATIC_VAR
; }
687 : public tuple_holding_operation
<int>
691 using tuple_holding_operation::tuple_holding_operation
;
693 value
*evaluate (struct type
*expect_type
,
694 struct expression
*exp
,
695 enum noside noside
) override
697 return access_value_history (std::get
<0> (m_storage
));
700 enum exp_opcode
opcode () const override
704 class register_operation
705 : public tuple_holding_operation
<std::string
>
709 using tuple_holding_operation::tuple_holding_operation
;
711 value
*evaluate (struct type
*expect_type
,
712 struct expression
*exp
,
713 enum noside noside
) override
715 return eval_op_register (expect_type
, exp
, noside
,
716 std::get
<0> (m_storage
).c_str ());
719 enum exp_opcode
opcode () const override
720 { return OP_REGISTER
; }
724 void do_generate_ax (struct expression
*exp
,
725 struct agent_expr
*ax
,
726 struct axs_value
*value
,
727 struct type
*cast_type
)
732 : public tuple_holding_operation
<bool>
736 using tuple_holding_operation::tuple_holding_operation
;
738 value
*evaluate (struct type
*expect_type
,
739 struct expression
*exp
,
740 enum noside noside
) override
742 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
743 return value_from_longest (type
, std::get
<0> (m_storage
));
746 enum exp_opcode
opcode () const override
749 bool constant_p () const override
753 class internalvar_operation
754 : public tuple_holding_operation
<internalvar
*>
758 using tuple_holding_operation::tuple_holding_operation
;
760 value
*evaluate (struct type
*expect_type
,
761 struct expression
*exp
,
762 enum noside noside
) override
764 return value_of_internalvar (exp
->gdbarch
,
765 std::get
<0> (m_storage
));
768 internalvar
*get_internalvar () const
770 return std::get
<0> (m_storage
);
773 enum exp_opcode
opcode () const override
774 { return OP_INTERNALVAR
; }
778 void do_generate_ax (struct expression
*exp
,
779 struct agent_expr
*ax
,
780 struct axs_value
*value
,
781 struct type
*cast_type
)
785 class string_operation
786 : public tuple_holding_operation
<std::string
>
790 using tuple_holding_operation::tuple_holding_operation
;
792 value
*evaluate (struct type
*expect_type
,
793 struct expression
*exp
,
794 enum noside noside
) override
796 const std::string
&str
= std::get
<0> (m_storage
);
797 return eval_op_string (expect_type
, exp
, noside
,
798 str
.size (), str
.c_str ());
801 enum exp_opcode
opcode () const override
802 { return OP_STRING
; }
805 class ternop_slice_operation
806 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
810 using maybe_constant_operation::maybe_constant_operation
;
812 value
*evaluate (struct type
*expect_type
,
813 struct expression
*exp
,
814 enum noside noside
) override
817 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
819 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
821 = std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
822 return eval_op_ternop (expect_type
, exp
, noside
, array
, low
, upper
);
825 enum exp_opcode
opcode () const override
826 { return TERNOP_SLICE
; }
829 class ternop_cond_operation
830 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
834 using maybe_constant_operation::maybe_constant_operation
;
836 value
*evaluate (struct type
*expect_type
,
837 struct expression
*exp
,
838 enum noside noside
) override
841 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
843 if (value_logical_not (val
))
844 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
845 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
848 enum exp_opcode
opcode () const override
849 { return TERNOP_COND
; }
853 void do_generate_ax (struct expression
*exp
,
854 struct agent_expr
*ax
,
855 struct axs_value
*value
,
856 struct type
*cast_type
)
860 class complex_operation
861 : public maybe_constant_operation
<operation_up
, operation_up
, struct type
*>
865 using maybe_constant_operation::maybe_constant_operation
;
867 value
*evaluate (struct type
*expect_type
,
868 struct expression
*exp
,
869 enum noside noside
) override
871 value
*real
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
872 value
*imag
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
873 return value_literal_complex (real
, imag
,
874 std::get
<2> (m_storage
));
877 enum exp_opcode
opcode () const override
878 { return OP_COMPLEX
; }
881 class structop_base_operation
882 : public tuple_holding_operation
<operation_up
, std::string
>
886 /* Used for completion. Return the field name. */
887 const std::string
&get_string () const
889 return std::get
<1> (m_storage
);
892 /* Used for completion. Evaluate the LHS for type. */
893 value
*evaluate_lhs (struct expression
*exp
)
895 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
896 EVAL_AVOID_SIDE_EFFECTS
);
901 using tuple_holding_operation::tuple_holding_operation
;
904 class structop_operation
905 : public structop_base_operation
909 using structop_base_operation::structop_base_operation
;
911 value
*evaluate (struct type
*expect_type
,
912 struct expression
*exp
,
913 enum noside noside
) override
915 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
916 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
917 std::get
<1> (m_storage
).c_str ());
920 enum exp_opcode
opcode () const override
921 { return STRUCTOP_STRUCT
; }
925 void do_generate_ax (struct expression
*exp
,
926 struct agent_expr
*ax
,
927 struct axs_value
*value
,
928 struct type
*cast_type
)
931 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
932 std::get
<0> (this->m_storage
).get (),
933 std::get
<1> (this->m_storage
).c_str (),
938 class structop_ptr_operation
939 : public structop_base_operation
943 using structop_base_operation::structop_base_operation
;
945 value
*evaluate (struct type
*expect_type
,
946 struct expression
*exp
,
947 enum noside noside
) override
949 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
950 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
951 std::get
<1> (m_storage
).c_str ());
954 enum exp_opcode
opcode () const override
955 { return STRUCTOP_PTR
; }
959 void do_generate_ax (struct expression
*exp
,
960 struct agent_expr
*ax
,
961 struct axs_value
*value
,
962 struct type
*cast_type
)
965 gen_expr_structop (exp
, STRUCTOP_PTR
,
966 std::get
<0> (this->m_storage
).get (),
967 std::get
<1> (this->m_storage
).c_str (),
972 class structop_member_operation
973 : public tuple_holding_operation
<operation_up
, operation_up
>
977 using tuple_holding_operation::tuple_holding_operation
;
979 value
*evaluate (struct type
*expect_type
,
980 struct expression
*exp
,
981 enum noside noside
) override
984 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
986 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
987 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
990 enum exp_opcode
opcode () const override
991 { return STRUCTOP_MEMBER
; }
994 class structop_mptr_operation
995 : public tuple_holding_operation
<operation_up
, operation_up
>
999 using tuple_holding_operation::tuple_holding_operation
;
1001 value
*evaluate (struct type
*expect_type
,
1002 struct expression
*exp
,
1003 enum noside noside
) override
1006 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1008 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1009 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1012 enum exp_opcode
opcode () const override
1013 { return STRUCTOP_MPTR
; }
1016 class concat_operation
1017 : public maybe_constant_operation
<operation_up
, operation_up
>
1021 using maybe_constant_operation::maybe_constant_operation
;
1023 value
*evaluate (struct type
*expect_type
,
1024 struct expression
*exp
,
1025 enum noside noside
) override
1028 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1030 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1031 return eval_op_concat (expect_type
, exp
, noside
, lhs
, rhs
);
1034 enum exp_opcode
opcode () const override
1035 { return BINOP_CONCAT
; }
1039 : public maybe_constant_operation
<operation_up
, operation_up
>
1043 using maybe_constant_operation::maybe_constant_operation
;
1045 value
*evaluate (struct type
*expect_type
,
1046 struct expression
*exp
,
1047 enum noside noside
) override
1050 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1052 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1053 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1056 enum exp_opcode
opcode () const override
1057 { return BINOP_ADD
; }
1061 void do_generate_ax (struct expression
*exp
,
1062 struct agent_expr
*ax
,
1063 struct axs_value
*value
,
1064 struct type
*cast_type
)
1067 gen_expr_binop (exp
, BINOP_ADD
,
1068 std::get
<0> (this->m_storage
).get (),
1069 std::get
<1> (this->m_storage
).get (),
1075 : public maybe_constant_operation
<operation_up
, operation_up
>
1079 using maybe_constant_operation::maybe_constant_operation
;
1081 value
*evaluate (struct type
*expect_type
,
1082 struct expression
*exp
,
1083 enum noside noside
) override
1086 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1088 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1089 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1092 enum exp_opcode
opcode () const override
1093 { return BINOP_SUB
; }
1097 void do_generate_ax (struct expression
*exp
,
1098 struct agent_expr
*ax
,
1099 struct axs_value
*value
,
1100 struct type
*cast_type
)
1103 gen_expr_binop (exp
, BINOP_SUB
,
1104 std::get
<0> (this->m_storage
).get (),
1105 std::get
<1> (this->m_storage
).get (),
1110 typedef struct value
*binary_ftype (struct type
*expect_type
,
1111 struct expression
*exp
,
1112 enum noside noside
, enum exp_opcode op
,
1113 struct value
*arg1
, struct value
*arg2
);
1115 template<enum exp_opcode OP
, binary_ftype FUNC
>
1116 class binop_operation
1117 : public maybe_constant_operation
<operation_up
, operation_up
>
1121 using maybe_constant_operation::maybe_constant_operation
;
1123 value
*evaluate (struct type
*expect_type
,
1124 struct expression
*exp
,
1125 enum noside noside
) override
1128 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1130 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1131 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1134 enum exp_opcode
opcode () const override
1138 template<enum exp_opcode OP
, binary_ftype FUNC
>
1139 class usual_ax_binop_operation
1140 : public binop_operation
<OP
, FUNC
>
1144 using binop_operation
<OP
, FUNC
>::binop_operation
;
1148 void do_generate_ax (struct expression
*exp
,
1149 struct agent_expr
*ax
,
1150 struct axs_value
*value
,
1151 struct type
*cast_type
)
1154 gen_expr_binop (exp
, OP
,
1155 std::get
<0> (this->m_storage
).get (),
1156 std::get
<1> (this->m_storage
).get (),
1161 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1162 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1163 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1165 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1166 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1167 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1168 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1169 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1170 using bitwise_and_operation
1171 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1172 using bitwise_ior_operation
1173 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1174 using bitwise_xor_operation
1175 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1177 class subscript_operation
1178 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1181 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1182 eval_op_subscript
>::usual_ax_binop_operation
;
1184 value
*evaluate_for_sizeof (struct expression
*exp
,
1185 enum noside noside
) override
;
1188 /* Implementation of comparison operations. */
1189 template<enum exp_opcode OP
, binary_ftype FUNC
>
1190 class comparison_operation
1191 : public usual_ax_binop_operation
<OP
, FUNC
>
1195 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1197 value
*evaluate (struct type
*expect_type
,
1198 struct expression
*exp
,
1199 enum noside noside
) override
1202 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1204 = std::get
<1> (this->m_storage
)->evaluate (value_type (lhs
), exp
,
1206 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1210 using equal_operation
= comparison_operation
<BINOP_EQUAL
, eval_op_equal
>;
1211 using notequal_operation
1212 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1213 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1214 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1215 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1216 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1218 /* Implement the GDB '@' repeat operator. */
1219 class repeat_operation
1220 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1222 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1226 void do_generate_ax (struct expression
*exp
,
1227 struct agent_expr
*ax
,
1228 struct axs_value
*value
,
1229 struct type
*cast_type
)
1233 /* C-style comma operator. */
1234 class comma_operation
1235 : public maybe_constant_operation
<operation_up
, operation_up
>
1239 using maybe_constant_operation::maybe_constant_operation
;
1241 value
*evaluate (struct type
*expect_type
,
1242 struct expression
*exp
,
1243 enum noside noside
) override
1245 /* The left-hand-side is only evaluated for side effects, so don't
1246 bother in other modes. */
1247 if (noside
== EVAL_NORMAL
)
1248 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1249 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1252 enum exp_opcode
opcode () const override
1253 { return BINOP_COMMA
; }
1257 void do_generate_ax (struct expression
*exp
,
1258 struct agent_expr
*ax
,
1259 struct axs_value
*value
,
1260 struct type
*cast_type
)
1264 typedef struct value
*unary_ftype (struct type
*expect_type
,
1265 struct expression
*exp
,
1266 enum noside noside
, enum exp_opcode op
,
1267 struct value
*arg1
);
1269 /* Base class for unary operations. */
1270 template<enum exp_opcode OP
, unary_ftype FUNC
>
1271 class unop_operation
1272 : public maybe_constant_operation
<operation_up
>
1276 using maybe_constant_operation::maybe_constant_operation
;
1278 value
*evaluate (struct type
*expect_type
,
1279 struct expression
*exp
,
1280 enum noside noside
) override
1282 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1283 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1286 enum exp_opcode
opcode () const override
1290 /* Unary operations that can also be turned into agent expressions in
1292 template<enum exp_opcode OP
, unary_ftype FUNC
>
1293 class usual_ax_unop_operation
1294 : public unop_operation
<OP
, FUNC
>
1296 using unop_operation
<OP
, FUNC
>::unop_operation
;
1300 void do_generate_ax (struct expression
*exp
,
1301 struct agent_expr
*ax
,
1302 struct axs_value
*value
,
1303 struct type
*cast_type
)
1306 gen_expr_unop (exp
, OP
,
1307 std::get
<0> (this->m_storage
).get (),
1312 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1313 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1314 using unary_complement_operation
1315 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1316 using unary_logical_not_operation
1317 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1319 } /* namespace expr */
1321 #endif /* EXPOP_H */