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
);
196 /* The check_objfile overloads are used to check whether a particular
197 component of some operation references an objfile. The passed-in
198 objfile will never be a debug objfile. */
200 /* See if EXP_OBJFILE matches OBJFILE. */
202 check_objfile (struct objfile
*exp_objfile
, struct objfile
*objfile
)
204 if (exp_objfile
->separate_debug_objfile_backlink
)
205 exp_objfile
= exp_objfile
->separate_debug_objfile_backlink
;
206 return exp_objfile
== objfile
;
210 check_objfile (struct type
*type
, struct objfile
*objfile
)
212 struct objfile
*ty_objfile
= type
->objfile_owner ();
213 if (ty_objfile
!= nullptr)
214 return check_objfile (ty_objfile
, objfile
);
219 check_objfile (struct symbol
*sym
, struct objfile
*objfile
)
221 return check_objfile (symbol_objfile (sym
), objfile
);
225 check_objfile (const struct block
*block
, struct objfile
*objfile
)
227 return check_objfile (block_objfile (block
), objfile
);
231 check_objfile (minimal_symbol
*minsym
, struct objfile
*objfile
)
233 /* This may seem strange but minsyms are only used with an objfile
239 check_objfile (internalvar
*ivar
, struct objfile
*objfile
)
245 check_objfile (const std::string
&str
, struct objfile
*objfile
)
251 check_objfile (const operation_up
&op
, struct objfile
*objfile
)
253 return op
->uses_objfile (objfile
);
257 check_objfile (enum exp_opcode val
, struct objfile
*objfile
)
263 check_objfile (ULONGEST val
, struct objfile
*objfile
)
270 check_objfile (enum_flags
<T
> val
, struct objfile
*objfile
)
277 check_objfile (const std::vector
<T
> &collection
, struct objfile
*objfile
)
279 for (const auto &item
: collection
)
281 if (check_objfile (item
, objfile
))
287 template<typename S
, typename T
>
289 check_objfile (const std::pair
<S
, T
> &item
, struct objfile
*objfile
)
291 return (check_objfile (item
.first
, objfile
)
292 || check_objfile (item
.second
, objfile
));
296 dump_for_expression (struct ui_file
*stream
, int depth
,
297 const operation_up
&op
)
299 op
->dump (stream
, depth
);
302 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
304 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
305 const std::string
&str
);
306 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
308 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
310 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
312 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
314 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
315 minimal_symbol
*msym
);
316 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
318 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
319 type_instance_flags flags
);
320 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
321 enum c_string_type_values flags
);
322 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
323 enum range_flag flags
);
324 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
329 dump_for_expression (struct ui_file
*stream
, int depth
,
330 const std::vector
<T
> &vals
)
332 fprintf_filtered (stream
, _("%*sVector:\n"), depth
, "");
333 for (auto &item
: vals
)
334 dump_for_expression (stream
, depth
+ 1, item
);
337 template<typename X
, typename Y
>
339 dump_for_expression (struct ui_file
*stream
, int depth
,
340 const std::pair
<X
, Y
> &vals
)
342 dump_for_expression (stream
, depth
, vals
.first
);
343 dump_for_expression (stream
, depth
, vals
.second
);
346 /* Base class for most concrete operations. This class holds data,
347 specified via template parameters, and supplies generic
348 implementations of the 'dump' and 'uses_objfile' methods. */
349 template<typename
... Arg
>
350 class tuple_holding_operation
: public operation
354 explicit tuple_holding_operation (Arg
... args
)
355 : m_storage (std::forward
<Arg
> (args
)...)
359 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation
);
361 bool uses_objfile (struct objfile
*objfile
) const override
363 return do_check_objfile
<0, Arg
...> (objfile
, m_storage
);
366 void dump (struct ui_file
*stream
, int depth
) const override
368 dump_for_expression (stream
, depth
, opcode ());
369 do_dump
<0, Arg
...> (stream
, depth
+ 1, m_storage
);
374 /* Storage for the data. */
375 std::tuple
<Arg
...> m_storage
;
379 /* do_dump does the work of dumping the data. */
380 template<int I
, typename
... T
>
381 typename
std::enable_if
<I
== sizeof... (T
), void>::type
382 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
387 template<int I
, typename
... T
>
388 typename
std::enable_if
<I
< sizeof... (T
), void>::type
389 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
392 dump_for_expression (stream
, depth
, std::get
<I
> (value
));
393 do_dump
<I
+ 1, T
...> (stream
, depth
, value
);
396 /* do_check_objfile does the work of checking whether this object
397 refers to OBJFILE. */
398 template<int I
, typename
... T
>
399 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
400 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
406 template<int I
, typename
... T
>
407 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
408 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
411 if (check_objfile (std::get
<I
> (value
), objfile
))
413 return do_check_objfile
<I
+ 1, T
...> (objfile
, value
);
417 /* The check_constant overloads are used to decide whether a given
418 concrete operation is a constant. This is done by checking the
422 check_constant (const operation_up
&item
)
424 return item
->constant_p ();
428 check_constant (struct minimal_symbol
*msym
)
434 check_constant (struct type
*type
)
440 check_constant (const struct block
*block
)
446 check_constant (const std::string
&str
)
452 check_constant (struct objfile
*objfile
)
458 check_constant (ULONGEST cst
)
464 check_constant (struct symbol
*sym
)
466 enum address_class sc
= SYMBOL_CLASS (sym
);
467 return (sc
== LOC_BLOCK
469 || sc
== LOC_CONST_BYTES
475 check_constant (const std::vector
<T
> &collection
)
477 for (const auto &item
: collection
)
478 if (!check_constant (item
))
483 template<typename S
, typename T
>
485 check_constant (const std::pair
<S
, T
> &item
)
487 return check_constant (item
.first
) && check_constant (item
.second
);
490 /* Base class for concrete operations. This class supplies an
491 implementation of 'constant_p' that works by checking the
493 template<typename
... Arg
>
494 class maybe_constant_operation
495 : public tuple_holding_operation
<Arg
...>
499 using tuple_holding_operation
<Arg
...>::tuple_holding_operation
;
501 bool constant_p () const override
503 return do_check_constant
<0, Arg
...> (this->m_storage
);
508 template<int I
, typename
... T
>
509 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
510 do_check_constant (const std::tuple
<T
...> &value
) const
515 template<int I
, typename
... T
>
516 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
517 do_check_constant (const std::tuple
<T
...> &value
) const
519 if (!check_constant (std::get
<I
> (value
)))
521 return do_check_constant
<I
+ 1, T
...> (value
);
525 /* A floating-point constant. The constant is encoded in the target
528 typedef std::array
<gdb_byte
, 16> float_data
;
530 /* An operation that holds a floating-point constant of a given
533 This does not need the facilities provided by
534 tuple_holding_operation, so it does not use it. */
535 class float_const_operation
540 float_const_operation (struct type
*type
, float_data data
)
546 value
*evaluate (struct type
*expect_type
,
547 struct expression
*exp
,
548 enum noside noside
) override
550 return value_from_contents (m_type
, m_data
.data ());
553 enum exp_opcode
opcode () const override
556 bool constant_p () const override
559 void dump (struct ui_file
*stream
, int depth
) const override
;
567 class scope_operation
568 : public maybe_constant_operation
<struct type
*, std::string
>
572 using maybe_constant_operation::maybe_constant_operation
;
574 value
*evaluate (struct type
*expect_type
,
575 struct expression
*exp
,
576 enum noside noside
) override
578 return eval_op_scope (expect_type
, exp
, noside
,
579 std::get
<0> (m_storage
),
580 std::get
<1> (m_storage
).c_str ());
583 value
*evaluate_for_address (struct expression
*exp
,
584 enum noside noside
) override
;
586 enum exp_opcode
opcode () const override
591 void do_generate_ax (struct expression
*exp
,
592 struct agent_expr
*ax
,
593 struct axs_value
*value
,
594 struct type
*cast_type
)
598 class long_const_operation
599 : public tuple_holding_operation
<struct type
*, LONGEST
>
603 using tuple_holding_operation::tuple_holding_operation
;
605 value
*evaluate (struct type
*expect_type
,
606 struct expression
*exp
,
607 enum noside noside
) override
609 return value_from_longest (std::get
<0> (m_storage
),
610 std::get
<1> (m_storage
));
613 enum exp_opcode
opcode () const override
616 bool constant_p () const override
621 void do_generate_ax (struct expression
*exp
,
622 struct agent_expr
*ax
,
623 struct axs_value
*value
,
624 struct type
*cast_type
)
628 class var_msym_value_operation
629 : public maybe_constant_operation
<minimal_symbol
*, struct objfile
*>
633 using maybe_constant_operation::maybe_constant_operation
;
635 value
*evaluate (struct type
*expect_type
,
636 struct expression
*exp
,
637 enum noside noside
) override
639 return eval_op_var_msym_value (expect_type
, exp
, noside
, m_outermost
,
640 std::get
<0> (m_storage
),
641 std::get
<1> (m_storage
));
644 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
647 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
650 value
*evaluate_for_cast (struct type
*expect_type
,
651 struct expression
*exp
,
652 enum noside noside
) override
;
654 enum exp_opcode
opcode () const override
655 { return OP_VAR_MSYM_VALUE
; }
657 void set_outermost () override
664 /* True if this is the outermost operation in the expression. */
665 bool m_outermost
= false;
667 void do_generate_ax (struct expression
*exp
,
668 struct agent_expr
*ax
,
669 struct axs_value
*value
,
670 struct type
*cast_type
)
674 class var_entry_value_operation
675 : public tuple_holding_operation
<symbol
*>
679 using tuple_holding_operation::tuple_holding_operation
;
681 value
*evaluate (struct type
*expect_type
,
682 struct expression
*exp
,
683 enum noside noside
) override
685 return eval_op_var_entry_value (expect_type
, exp
, noside
,
686 std::get
<0> (m_storage
));
689 enum exp_opcode
opcode () const override
690 { return OP_VAR_ENTRY_VALUE
; }
693 class func_static_var_operation
694 : public maybe_constant_operation
<operation_up
, std::string
>
698 using maybe_constant_operation::maybe_constant_operation
;
700 value
*evaluate (struct type
*expect_type
,
701 struct expression
*exp
,
702 enum noside noside
) override
704 value
*func
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
705 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
706 std::get
<1> (m_storage
).c_str ());
709 enum exp_opcode
opcode () const override
710 { return OP_FUNC_STATIC_VAR
; }
714 : public tuple_holding_operation
<int>
718 using tuple_holding_operation::tuple_holding_operation
;
720 value
*evaluate (struct type
*expect_type
,
721 struct expression
*exp
,
722 enum noside noside
) override
724 return access_value_history (std::get
<0> (m_storage
));
727 enum exp_opcode
opcode () const override
731 class register_operation
732 : public tuple_holding_operation
<std::string
>
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 return eval_op_register (expect_type
, exp
, noside
,
743 std::get
<0> (m_storage
).c_str ());
746 enum exp_opcode
opcode () const override
747 { return OP_REGISTER
; }
751 void do_generate_ax (struct expression
*exp
,
752 struct agent_expr
*ax
,
753 struct axs_value
*value
,
754 struct type
*cast_type
)
759 : public tuple_holding_operation
<bool>
763 using tuple_holding_operation::tuple_holding_operation
;
765 value
*evaluate (struct type
*expect_type
,
766 struct expression
*exp
,
767 enum noside noside
) override
769 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
770 return value_from_longest (type
, std::get
<0> (m_storage
));
773 enum exp_opcode
opcode () const override
776 bool constant_p () const override
780 class internalvar_operation
781 : public tuple_holding_operation
<internalvar
*>
785 using tuple_holding_operation::tuple_holding_operation
;
787 value
*evaluate (struct type
*expect_type
,
788 struct expression
*exp
,
789 enum noside noside
) override
791 return value_of_internalvar (exp
->gdbarch
,
792 std::get
<0> (m_storage
));
795 internalvar
*get_internalvar () const
797 return std::get
<0> (m_storage
);
800 enum exp_opcode
opcode () const override
801 { return OP_INTERNALVAR
; }
805 void do_generate_ax (struct expression
*exp
,
806 struct agent_expr
*ax
,
807 struct axs_value
*value
,
808 struct type
*cast_type
)
812 class string_operation
813 : public tuple_holding_operation
<std::string
>
817 using tuple_holding_operation::tuple_holding_operation
;
819 value
*evaluate (struct type
*expect_type
,
820 struct expression
*exp
,
821 enum noside noside
) override
823 const std::string
&str
= std::get
<0> (m_storage
);
824 return eval_op_string (expect_type
, exp
, noside
,
825 str
.size (), str
.c_str ());
828 enum exp_opcode
opcode () const override
829 { return OP_STRING
; }
832 class ternop_slice_operation
833 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
837 using maybe_constant_operation::maybe_constant_operation
;
839 value
*evaluate (struct type
*expect_type
,
840 struct expression
*exp
,
841 enum noside noside
) override
844 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
846 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
848 = std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
849 return eval_op_ternop (expect_type
, exp
, noside
, array
, low
, upper
);
852 enum exp_opcode
opcode () const override
853 { return TERNOP_SLICE
; }
856 class ternop_cond_operation
857 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
861 using maybe_constant_operation::maybe_constant_operation
;
863 value
*evaluate (struct type
*expect_type
,
864 struct expression
*exp
,
865 enum noside noside
) override
868 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
870 if (value_logical_not (val
))
871 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
872 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
875 enum exp_opcode
opcode () const override
876 { return TERNOP_COND
; }
880 void do_generate_ax (struct expression
*exp
,
881 struct agent_expr
*ax
,
882 struct axs_value
*value
,
883 struct type
*cast_type
)
887 class complex_operation
888 : public maybe_constant_operation
<operation_up
, operation_up
, struct type
*>
892 using maybe_constant_operation::maybe_constant_operation
;
894 value
*evaluate (struct type
*expect_type
,
895 struct expression
*exp
,
896 enum noside noside
) override
898 value
*real
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
899 value
*imag
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
900 return value_literal_complex (real
, imag
,
901 std::get
<2> (m_storage
));
904 enum exp_opcode
opcode () const override
905 { return OP_COMPLEX
; }
908 class structop_base_operation
909 : public tuple_holding_operation
<operation_up
, std::string
>
913 /* Used for completion. Return the field name. */
914 const std::string
&get_string () const
916 return std::get
<1> (m_storage
);
919 /* Used for completion. Evaluate the LHS for type. */
920 value
*evaluate_lhs (struct expression
*exp
)
922 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
923 EVAL_AVOID_SIDE_EFFECTS
);
928 using tuple_holding_operation::tuple_holding_operation
;
931 class structop_operation
932 : public structop_base_operation
936 using structop_base_operation::structop_base_operation
;
938 value
*evaluate (struct type
*expect_type
,
939 struct expression
*exp
,
940 enum noside noside
) override
942 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
943 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
944 std::get
<1> (m_storage
).c_str ());
947 enum exp_opcode
opcode () const override
948 { return STRUCTOP_STRUCT
; }
952 void do_generate_ax (struct expression
*exp
,
953 struct agent_expr
*ax
,
954 struct axs_value
*value
,
955 struct type
*cast_type
)
958 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
959 std::get
<0> (this->m_storage
).get (),
960 std::get
<1> (this->m_storage
).c_str (),
965 class structop_ptr_operation
966 : public structop_base_operation
970 using structop_base_operation::structop_base_operation
;
972 value
*evaluate (struct type
*expect_type
,
973 struct expression
*exp
,
974 enum noside noside
) override
976 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
977 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
978 std::get
<1> (m_storage
).c_str ());
981 enum exp_opcode
opcode () const override
982 { return STRUCTOP_PTR
; }
986 void do_generate_ax (struct expression
*exp
,
987 struct agent_expr
*ax
,
988 struct axs_value
*value
,
989 struct type
*cast_type
)
992 gen_expr_structop (exp
, STRUCTOP_PTR
,
993 std::get
<0> (this->m_storage
).get (),
994 std::get
<1> (this->m_storage
).c_str (),
999 class structop_member_operation
1000 : public tuple_holding_operation
<operation_up
, operation_up
>
1004 using tuple_holding_operation::tuple_holding_operation
;
1006 value
*evaluate (struct type
*expect_type
,
1007 struct expression
*exp
,
1008 enum noside noside
) override
1011 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1013 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1014 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1017 enum exp_opcode
opcode () const override
1018 { return STRUCTOP_MEMBER
; }
1021 class structop_mptr_operation
1022 : public tuple_holding_operation
<operation_up
, operation_up
>
1026 using tuple_holding_operation::tuple_holding_operation
;
1028 value
*evaluate (struct type
*expect_type
,
1029 struct expression
*exp
,
1030 enum noside noside
) override
1033 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1035 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1036 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1039 enum exp_opcode
opcode () const override
1040 { return STRUCTOP_MPTR
; }
1043 class concat_operation
1044 : public maybe_constant_operation
<operation_up
, operation_up
>
1048 using maybe_constant_operation::maybe_constant_operation
;
1050 value
*evaluate (struct type
*expect_type
,
1051 struct expression
*exp
,
1052 enum noside noside
) override
1055 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1057 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1058 return eval_op_concat (expect_type
, exp
, noside
, lhs
, rhs
);
1061 enum exp_opcode
opcode () const override
1062 { return BINOP_CONCAT
; }
1066 : public maybe_constant_operation
<operation_up
, operation_up
>
1070 using maybe_constant_operation::maybe_constant_operation
;
1072 value
*evaluate (struct type
*expect_type
,
1073 struct expression
*exp
,
1074 enum noside noside
) override
1077 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1079 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1080 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1083 enum exp_opcode
opcode () const override
1084 { return BINOP_ADD
; }
1088 void do_generate_ax (struct expression
*exp
,
1089 struct agent_expr
*ax
,
1090 struct axs_value
*value
,
1091 struct type
*cast_type
)
1094 gen_expr_binop (exp
, BINOP_ADD
,
1095 std::get
<0> (this->m_storage
).get (),
1096 std::get
<1> (this->m_storage
).get (),
1102 : public maybe_constant_operation
<operation_up
, operation_up
>
1106 using maybe_constant_operation::maybe_constant_operation
;
1108 value
*evaluate (struct type
*expect_type
,
1109 struct expression
*exp
,
1110 enum noside noside
) override
1113 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1115 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1116 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1119 enum exp_opcode
opcode () const override
1120 { return BINOP_SUB
; }
1124 void do_generate_ax (struct expression
*exp
,
1125 struct agent_expr
*ax
,
1126 struct axs_value
*value
,
1127 struct type
*cast_type
)
1130 gen_expr_binop (exp
, BINOP_SUB
,
1131 std::get
<0> (this->m_storage
).get (),
1132 std::get
<1> (this->m_storage
).get (),
1137 typedef struct value
*binary_ftype (struct type
*expect_type
,
1138 struct expression
*exp
,
1139 enum noside noside
, enum exp_opcode op
,
1140 struct value
*arg1
, struct value
*arg2
);
1142 template<enum exp_opcode OP
, binary_ftype FUNC
>
1143 class binop_operation
1144 : public maybe_constant_operation
<operation_up
, operation_up
>
1148 using maybe_constant_operation::maybe_constant_operation
;
1150 value
*evaluate (struct type
*expect_type
,
1151 struct expression
*exp
,
1152 enum noside noside
) override
1155 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1157 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1158 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1161 enum exp_opcode
opcode () const override
1165 template<enum exp_opcode OP
, binary_ftype FUNC
>
1166 class usual_ax_binop_operation
1167 : public binop_operation
<OP
, FUNC
>
1171 using binop_operation
<OP
, FUNC
>::binop_operation
;
1175 void do_generate_ax (struct expression
*exp
,
1176 struct agent_expr
*ax
,
1177 struct axs_value
*value
,
1178 struct type
*cast_type
)
1181 gen_expr_binop (exp
, OP
,
1182 std::get
<0> (this->m_storage
).get (),
1183 std::get
<1> (this->m_storage
).get (),
1188 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1189 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1190 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1192 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1193 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1194 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1195 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1196 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1197 using bitwise_and_operation
1198 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1199 using bitwise_ior_operation
1200 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1201 using bitwise_xor_operation
1202 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1204 class subscript_operation
1205 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1208 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1209 eval_op_subscript
>::usual_ax_binop_operation
;
1211 value
*evaluate_for_sizeof (struct expression
*exp
,
1212 enum noside noside
) override
;
1215 /* Implementation of comparison operations. */
1216 template<enum exp_opcode OP
, binary_ftype FUNC
>
1217 class comparison_operation
1218 : public usual_ax_binop_operation
<OP
, FUNC
>
1222 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1224 value
*evaluate (struct type
*expect_type
,
1225 struct expression
*exp
,
1226 enum noside noside
) override
1229 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1231 = std::get
<1> (this->m_storage
)->evaluate (value_type (lhs
), exp
,
1233 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1237 using equal_operation
= comparison_operation
<BINOP_EQUAL
, eval_op_equal
>;
1238 using notequal_operation
1239 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1240 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1241 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1242 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1243 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1245 /* Implement the GDB '@' repeat operator. */
1246 class repeat_operation
1247 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1249 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1253 void do_generate_ax (struct expression
*exp
,
1254 struct agent_expr
*ax
,
1255 struct axs_value
*value
,
1256 struct type
*cast_type
)
1260 /* C-style comma operator. */
1261 class comma_operation
1262 : public maybe_constant_operation
<operation_up
, operation_up
>
1266 using maybe_constant_operation::maybe_constant_operation
;
1268 value
*evaluate (struct type
*expect_type
,
1269 struct expression
*exp
,
1270 enum noside noside
) override
1272 /* The left-hand-side is only evaluated for side effects, so don't
1273 bother in other modes. */
1274 if (noside
== EVAL_NORMAL
)
1275 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1276 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1279 enum exp_opcode
opcode () const override
1280 { return BINOP_COMMA
; }
1284 void do_generate_ax (struct expression
*exp
,
1285 struct agent_expr
*ax
,
1286 struct axs_value
*value
,
1287 struct type
*cast_type
)
1291 typedef struct value
*unary_ftype (struct type
*expect_type
,
1292 struct expression
*exp
,
1293 enum noside noside
, enum exp_opcode op
,
1294 struct value
*arg1
);
1296 /* Base class for unary operations. */
1297 template<enum exp_opcode OP
, unary_ftype FUNC
>
1298 class unop_operation
1299 : public maybe_constant_operation
<operation_up
>
1303 using maybe_constant_operation::maybe_constant_operation
;
1305 value
*evaluate (struct type
*expect_type
,
1306 struct expression
*exp
,
1307 enum noside noside
) override
1309 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1310 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1313 enum exp_opcode
opcode () const override
1317 /* Unary operations that can also be turned into agent expressions in
1319 template<enum exp_opcode OP
, unary_ftype FUNC
>
1320 class usual_ax_unop_operation
1321 : public unop_operation
<OP
, FUNC
>
1323 using unop_operation
<OP
, FUNC
>::unop_operation
;
1327 void do_generate_ax (struct expression
*exp
,
1328 struct agent_expr
*ax
,
1329 struct axs_value
*value
,
1330 struct type
*cast_type
)
1333 gen_expr_unop (exp
, OP
,
1334 std::get
<0> (this->m_storage
).get (),
1339 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1340 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1341 using unary_complement_operation
1342 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1343 using unary_logical_not_operation
1344 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1346 /* Handle pre- and post- increment and -decrement. */
1347 template<enum exp_opcode OP
, unary_ftype FUNC
>
1348 class unop_incr_operation
1349 : public tuple_holding_operation
<operation_up
>
1353 using tuple_holding_operation::tuple_holding_operation
;
1355 value
*evaluate (struct type
*expect_type
,
1356 struct expression
*exp
,
1357 enum noside noside
) override
1359 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1360 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1363 enum exp_opcode
opcode () const override
1367 using preinc_operation
1368 = unop_incr_operation
<UNOP_PREINCREMENT
, eval_op_preinc
>;
1369 using predec_operation
1370 = unop_incr_operation
<UNOP_PREDECREMENT
, eval_op_predec
>;
1371 using postinc_operation
1372 = unop_incr_operation
<UNOP_POSTINCREMENT
, eval_op_postinc
>;
1373 using postdec_operation
1374 = unop_incr_operation
<UNOP_POSTDECREMENT
, eval_op_postdec
>;
1376 /* Base class for implementations of UNOP_IND. */
1377 class unop_ind_base_operation
1378 : public tuple_holding_operation
<operation_up
>
1382 using tuple_holding_operation::tuple_holding_operation
;
1384 value
*evaluate (struct type
*expect_type
,
1385 struct expression
*exp
,
1386 enum noside noside
) override
1388 if (expect_type
!= nullptr && expect_type
->code () == TYPE_CODE_PTR
)
1389 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1390 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1391 return eval_op_ind (expect_type
, exp
, noside
, val
);
1394 value
*evaluate_for_address (struct expression
*exp
,
1395 enum noside noside
) override
;
1397 value
*evaluate_for_sizeof (struct expression
*exp
,
1398 enum noside noside
) override
;
1400 enum exp_opcode
opcode () const override
1401 { return UNOP_IND
; }
1404 /* Ordinary UNOP_IND implementation. */
1405 class unop_ind_operation
1406 : public unop_ind_base_operation
1410 using unop_ind_base_operation::unop_ind_base_operation
;
1414 void do_generate_ax (struct expression
*exp
,
1415 struct agent_expr
*ax
,
1416 struct axs_value
*value
,
1417 struct type
*cast_type
)
1420 gen_expr_unop (exp
, UNOP_IND
,
1421 std::get
<0> (this->m_storage
).get (),
1426 /* Implement OP_TYPE. */
1427 class type_operation
1428 : public tuple_holding_operation
<struct type
*>
1432 using tuple_holding_operation::tuple_holding_operation
;
1434 value
*evaluate (struct type
*expect_type
,
1435 struct expression
*exp
,
1436 enum noside noside
) override
1438 return eval_op_type (expect_type
, exp
, noside
, std::get
<0> (m_storage
));
1441 enum exp_opcode
opcode () const override
1444 bool constant_p () const override
1448 /* Implement the "typeof" operation. */
1449 class typeof_operation
1450 : public maybe_constant_operation
<operation_up
>
1454 using maybe_constant_operation::maybe_constant_operation
;
1456 value
*evaluate (struct type
*expect_type
,
1457 struct expression
*exp
,
1458 enum noside noside
) override
1460 if (noside
== EVAL_SKIP
)
1461 return eval_skip_value (exp
);
1462 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1463 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1464 EVAL_AVOID_SIDE_EFFECTS
);
1466 error (_("Attempt to use a type as an expression"));
1469 enum exp_opcode
opcode () const override
1470 { return OP_TYPEOF
; }
1473 /* Implement 'decltype'. */
1474 class decltype_operation
1475 : public maybe_constant_operation
<operation_up
>
1479 using maybe_constant_operation::maybe_constant_operation
;
1481 value
*evaluate (struct type
*expect_type
,
1482 struct expression
*exp
,
1483 enum noside noside
) override
1485 if (noside
== EVAL_SKIP
)
1486 return eval_skip_value (exp
);
1487 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1490 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1491 EVAL_AVOID_SIDE_EFFECTS
);
1492 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1493 if (sub_op
== BINOP_SUBSCRIPT
1494 || sub_op
== STRUCTOP_MEMBER
1495 || sub_op
== STRUCTOP_MPTR
1496 || sub_op
== UNOP_IND
1497 || sub_op
== STRUCTOP_STRUCT
1498 || sub_op
== STRUCTOP_PTR
1499 || sub_op
== OP_SCOPE
)
1501 struct type
*type
= value_type (result
);
1503 if (!TYPE_IS_REFERENCE (type
))
1505 type
= lookup_lvalue_reference_type (type
);
1506 result
= allocate_value (type
);
1513 error (_("Attempt to use a type as an expression"));
1516 enum exp_opcode
opcode () const override
1517 { return OP_DECLTYPE
; }
1520 /* Implement 'typeid'. */
1521 class typeid_operation
1522 : public tuple_holding_operation
<operation_up
>
1526 using tuple_holding_operation::tuple_holding_operation
;
1528 value
*evaluate (struct type
*expect_type
,
1529 struct expression
*exp
,
1530 enum noside noside
) override
1532 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1533 enum noside sub_noside
1534 = ((sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
1535 ? EVAL_AVOID_SIDE_EFFECTS
1538 value
*result
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1540 if (noside
!= EVAL_NORMAL
)
1541 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
1542 return cplus_typeid (result
);
1545 enum exp_opcode
opcode () const override
1546 { return OP_TYPEID
; }
1549 /* Implement the address-of operation. */
1550 class unop_addr_operation
1551 : public maybe_constant_operation
<operation_up
>
1555 using maybe_constant_operation::maybe_constant_operation
;
1557 value
*evaluate (struct type
*expect_type
,
1558 struct expression
*exp
,
1559 enum noside noside
) override
1561 /* C++: check for and handle pointer to members. */
1562 if (noside
== EVAL_SKIP
)
1563 return eval_skip_value (exp
);
1565 return std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1568 enum exp_opcode
opcode () const override
1569 { return UNOP_ADDR
; }
1573 void do_generate_ax (struct expression
*exp
,
1574 struct agent_expr
*ax
,
1575 struct axs_value
*value
,
1576 struct type
*cast_type
)
1579 gen_expr_unop (exp
, UNOP_ADDR
,
1580 std::get
<0> (this->m_storage
).get (),
1585 } /* namespace expr */
1587 #endif /* EXPOP_H */