1 /* Definitions for expressions in GDB
3 Copyright (C) 2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "expression.h"
28 #include "gdbsupport/traits.h"
29 #include "gdbsupport/enum-flags.h"
34 extern void gen_expr_binop (struct expression
*exp
,
36 expr::operation
*lhs
, expr::operation
*rhs
,
37 struct agent_expr
*ax
, struct axs_value
*value
);
38 extern void gen_expr_structop (struct expression
*exp
,
42 struct agent_expr
*ax
, struct axs_value
*value
);
43 extern void gen_expr_unop (struct expression
*exp
,
46 struct agent_expr
*ax
, struct axs_value
*value
);
48 extern struct value
*eval_op_scope (struct type
*expect_type
,
49 struct expression
*exp
,
51 struct type
*type
, const char *string
);
52 extern struct value
*eval_op_var_msym_value (struct type
*expect_type
,
53 struct expression
*exp
,
56 bound_minimal_symbol msymbol
);
57 extern struct value
*eval_op_var_entry_value (struct type
*expect_type
,
58 struct expression
*exp
,
59 enum noside noside
, symbol
*sym
);
60 extern struct value
*eval_op_func_static_var (struct type
*expect_type
,
61 struct expression
*exp
,
63 value
*func
, const char *var
);
64 extern struct value
*eval_op_register (struct type
*expect_type
,
65 struct expression
*exp
,
66 enum noside noside
, const char *name
);
67 extern struct value
*eval_op_string (struct type
*expect_type
,
68 struct expression
*exp
,
69 enum noside noside
, int len
,
71 extern struct value
*eval_op_ternop (struct type
*expect_type
,
72 struct expression
*exp
,
74 struct value
*array
, struct value
*low
,
76 extern struct value
*eval_op_structop_struct (struct type
*expect_type
,
77 struct expression
*exp
,
81 extern struct value
*eval_op_structop_ptr (struct type
*expect_type
,
82 struct expression
*exp
,
86 extern struct value
*eval_op_member (struct type
*expect_type
,
87 struct expression
*exp
,
89 struct value
*arg1
, struct value
*arg2
);
90 extern struct value
*eval_op_concat (struct type
*expect_type
,
91 struct expression
*exp
,
93 struct value
*arg1
, struct value
*arg2
);
94 extern struct value
*eval_op_add (struct type
*expect_type
,
95 struct expression
*exp
,
97 struct value
*arg1
, struct value
*arg2
);
98 extern struct value
*eval_op_sub (struct type
*expect_type
,
99 struct expression
*exp
,
101 struct value
*arg1
, struct value
*arg2
);
102 extern struct value
*eval_op_binary (struct type
*expect_type
,
103 struct expression
*exp
,
104 enum noside noside
, enum exp_opcode op
,
105 struct value
*arg1
, struct value
*arg2
);
106 extern struct value
*eval_op_subscript (struct type
*expect_type
,
107 struct expression
*exp
,
108 enum noside noside
, enum exp_opcode op
,
111 extern struct value
*eval_op_equal (struct type
*expect_type
,
112 struct expression
*exp
,
113 enum noside noside
, enum exp_opcode op
,
116 extern struct value
*eval_op_notequal (struct type
*expect_type
,
117 struct expression
*exp
,
118 enum noside noside
, enum exp_opcode op
,
121 extern struct value
*eval_op_less (struct type
*expect_type
,
122 struct expression
*exp
,
123 enum noside noside
, enum exp_opcode op
,
126 extern struct value
*eval_op_gtr (struct type
*expect_type
,
127 struct expression
*exp
,
128 enum noside noside
, enum exp_opcode op
,
131 extern struct value
*eval_op_geq (struct type
*expect_type
,
132 struct expression
*exp
,
133 enum noside noside
, enum exp_opcode op
,
136 extern struct value
*eval_op_leq (struct type
*expect_type
,
137 struct expression
*exp
,
138 enum noside noside
, enum exp_opcode op
,
141 extern struct value
*eval_op_repeat (struct type
*expect_type
,
142 struct expression
*exp
,
143 enum noside noside
, enum exp_opcode op
,
146 extern struct value
*eval_op_plus (struct type
*expect_type
,
147 struct expression
*exp
,
148 enum noside noside
, enum exp_opcode op
,
150 extern struct value
*eval_op_neg (struct type
*expect_type
,
151 struct expression
*exp
,
152 enum noside noside
, enum exp_opcode op
,
154 extern struct value
*eval_op_complement (struct type
*expect_type
,
155 struct expression
*exp
,
159 extern struct value
*eval_op_lognot (struct type
*expect_type
,
160 struct expression
*exp
,
164 extern struct value
*eval_op_preinc (struct type
*expect_type
,
165 struct expression
*exp
,
169 extern struct value
*eval_op_predec (struct type
*expect_type
,
170 struct expression
*exp
,
174 extern struct value
*eval_op_postinc (struct type
*expect_type
,
175 struct expression
*exp
,
179 extern struct value
*eval_op_postdec (struct type
*expect_type
,
180 struct expression
*exp
,
184 extern struct value
*eval_op_ind (struct type
*expect_type
,
185 struct expression
*exp
,
188 extern struct value
*eval_op_type (struct type
*expect_type
,
189 struct expression
*exp
,
190 enum noside noside
, struct type
*type
);
191 extern struct value
*eval_op_alignof (struct type
*expect_type
,
192 struct expression
*exp
,
195 extern struct value
*eval_op_memval (struct type
*expect_type
,
196 struct expression
*exp
,
198 struct value
*arg1
, struct type
*type
);
199 extern struct value
*eval_binop_assign_modify (struct type
*expect_type
,
200 struct expression
*exp
,
211 /* The check_objfile overloads are used to check whether a particular
212 component of some operation references an objfile. The passed-in
213 objfile will never be a debug objfile. */
215 /* See if EXP_OBJFILE matches OBJFILE. */
217 check_objfile (struct objfile
*exp_objfile
, struct objfile
*objfile
)
219 if (exp_objfile
->separate_debug_objfile_backlink
)
220 exp_objfile
= exp_objfile
->separate_debug_objfile_backlink
;
221 return exp_objfile
== objfile
;
225 check_objfile (struct type
*type
, struct objfile
*objfile
)
227 struct objfile
*ty_objfile
= type
->objfile_owner ();
228 if (ty_objfile
!= nullptr)
229 return check_objfile (ty_objfile
, objfile
);
234 check_objfile (struct symbol
*sym
, struct objfile
*objfile
)
236 return check_objfile (symbol_objfile (sym
), objfile
);
240 check_objfile (const struct block
*block
, struct objfile
*objfile
)
242 return check_objfile (block_objfile (block
), objfile
);
246 check_objfile (bound_minimal_symbol minsym
, struct objfile
*objfile
)
248 return check_objfile (minsym
.objfile
, objfile
);
252 check_objfile (internalvar
*ivar
, struct objfile
*objfile
)
258 check_objfile (const std::string
&str
, struct objfile
*objfile
)
264 check_objfile (const operation_up
&op
, struct objfile
*objfile
)
266 return op
->uses_objfile (objfile
);
270 check_objfile (enum exp_opcode val
, struct objfile
*objfile
)
276 check_objfile (ULONGEST val
, struct objfile
*objfile
)
283 check_objfile (enum_flags
<T
> val
, struct objfile
*objfile
)
290 check_objfile (const std::vector
<T
> &collection
, struct objfile
*objfile
)
292 for (const auto &item
: collection
)
294 if (check_objfile (item
, objfile
))
300 template<typename S
, typename T
>
302 check_objfile (const std::pair
<S
, T
> &item
, struct objfile
*objfile
)
304 return (check_objfile (item
.first
, objfile
)
305 || check_objfile (item
.second
, objfile
));
308 extern bool check_objfile (const std::unique_ptr
<ada_component
> &comp
,
309 struct objfile
*objfile
);
312 dump_for_expression (struct ui_file
*stream
, int depth
,
313 const operation_up
&op
)
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
,
328 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
330 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
331 bound_minimal_symbol msym
);
332 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
334 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
335 type_instance_flags flags
);
336 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
337 enum c_string_type_values flags
);
338 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
339 enum range_flag flags
);
340 extern void dump_for_expression (struct ui_file
*stream
, int depth
,
341 const std::unique_ptr
<ada_component
> &comp
);
345 dump_for_expression (struct ui_file
*stream
, int depth
,
346 const std::vector
<T
> &vals
)
348 fprintf_filtered (stream
, _("%*sVector:\n"), depth
, "");
349 for (auto &item
: vals
)
350 dump_for_expression (stream
, depth
+ 1, item
);
353 template<typename X
, typename Y
>
355 dump_for_expression (struct ui_file
*stream
, int depth
,
356 const std::pair
<X
, Y
> &vals
)
358 dump_for_expression (stream
, depth
, vals
.first
);
359 dump_for_expression (stream
, depth
, vals
.second
);
362 /* Base class for most concrete operations. This class holds data,
363 specified via template parameters, and supplies generic
364 implementations of the 'dump' and 'uses_objfile' methods. */
365 template<typename
... Arg
>
366 class tuple_holding_operation
: public operation
370 explicit tuple_holding_operation (Arg
... args
)
371 : m_storage (std::forward
<Arg
> (args
)...)
375 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation
);
377 bool uses_objfile (struct objfile
*objfile
) const override
379 return do_check_objfile
<0, Arg
...> (objfile
, m_storage
);
382 void dump (struct ui_file
*stream
, int depth
) const override
384 dump_for_expression (stream
, depth
, opcode ());
385 do_dump
<0, Arg
...> (stream
, depth
+ 1, m_storage
);
390 /* Storage for the data. */
391 std::tuple
<Arg
...> m_storage
;
395 /* do_dump does the work of dumping the data. */
396 template<int I
, typename
... T
>
397 typename
std::enable_if
<I
== sizeof... (T
), void>::type
398 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
403 template<int I
, typename
... T
>
404 typename
std::enable_if
<I
< sizeof... (T
), void>::type
405 do_dump (struct ui_file
*stream
, int depth
, const std::tuple
<T
...> &value
)
408 dump_for_expression (stream
, depth
, std::get
<I
> (value
));
409 do_dump
<I
+ 1, T
...> (stream
, depth
, value
);
412 /* do_check_objfile does the work of checking whether this object
413 refers to OBJFILE. */
414 template<int I
, typename
... T
>
415 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
416 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
422 template<int I
, typename
... T
>
423 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
424 do_check_objfile (struct objfile
*objfile
, const std::tuple
<T
...> &value
)
427 if (check_objfile (std::get
<I
> (value
), objfile
))
429 return do_check_objfile
<I
+ 1, T
...> (objfile
, value
);
433 /* The check_constant overloads are used to decide whether a given
434 concrete operation is a constant. This is done by checking the
438 check_constant (const operation_up
&item
)
440 return item
->constant_p ();
444 check_constant (bound_minimal_symbol msym
)
450 check_constant (struct type
*type
)
456 check_constant (const struct block
*block
)
462 check_constant (const std::string
&str
)
468 check_constant (ULONGEST cst
)
474 check_constant (struct symbol
*sym
)
476 enum address_class sc
= SYMBOL_CLASS (sym
);
477 return (sc
== LOC_BLOCK
479 || sc
== LOC_CONST_BYTES
485 check_constant (const std::vector
<T
> &collection
)
487 for (const auto &item
: collection
)
488 if (!check_constant (item
))
493 template<typename S
, typename T
>
495 check_constant (const std::pair
<S
, T
> &item
)
497 return check_constant (item
.first
) && check_constant (item
.second
);
500 /* Base class for concrete operations. This class supplies an
501 implementation of 'constant_p' that works by checking the
503 template<typename
... Arg
>
504 class maybe_constant_operation
505 : public tuple_holding_operation
<Arg
...>
509 using tuple_holding_operation
<Arg
...>::tuple_holding_operation
;
511 bool constant_p () const override
513 return do_check_constant
<0, Arg
...> (this->m_storage
);
518 template<int I
, typename
... T
>
519 typename
std::enable_if
<I
== sizeof... (T
), bool>::type
520 do_check_constant (const std::tuple
<T
...> &value
) const
525 template<int I
, typename
... T
>
526 typename
std::enable_if
<I
< sizeof... (T
), bool>::type
527 do_check_constant (const std::tuple
<T
...> &value
) const
529 if (!check_constant (std::get
<I
> (value
)))
531 return do_check_constant
<I
+ 1, T
...> (value
);
535 /* A floating-point constant. The constant is encoded in the target
538 typedef std::array
<gdb_byte
, 16> float_data
;
540 /* An operation that holds a floating-point constant of a given
543 This does not need the facilities provided by
544 tuple_holding_operation, so it does not use it. */
545 class float_const_operation
550 float_const_operation (struct type
*type
, float_data data
)
556 value
*evaluate (struct type
*expect_type
,
557 struct expression
*exp
,
558 enum noside noside
) override
560 return value_from_contents (m_type
, m_data
.data ());
563 enum exp_opcode
opcode () const override
566 bool constant_p () const override
569 void dump (struct ui_file
*stream
, int depth
) const override
;
577 class scope_operation
578 : public maybe_constant_operation
<struct type
*, std::string
>
582 using maybe_constant_operation::maybe_constant_operation
;
584 value
*evaluate (struct type
*expect_type
,
585 struct expression
*exp
,
586 enum noside noside
) override
588 return eval_op_scope (expect_type
, exp
, noside
,
589 std::get
<0> (m_storage
),
590 std::get
<1> (m_storage
).c_str ());
593 value
*evaluate_for_address (struct expression
*exp
,
594 enum noside noside
) override
;
596 value
*evaluate_funcall (struct type
*expect_type
,
597 struct expression
*exp
,
599 const std::vector
<operation_up
> &args
) override
;
601 enum exp_opcode
opcode () const override
606 void do_generate_ax (struct expression
*exp
,
607 struct agent_expr
*ax
,
608 struct axs_value
*value
,
609 struct type
*cast_type
)
613 /* Compute the value of a variable. */
614 class var_value_operation
615 : public maybe_constant_operation
<symbol
*, const block
*>
619 using maybe_constant_operation::maybe_constant_operation
;
621 value
*evaluate (struct type
*expect_type
,
622 struct expression
*exp
,
623 enum noside noside
) override
;
625 value
*evaluate_with_coercion (struct expression
*exp
,
626 enum noside noside
) override
;
628 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
631 value
*evaluate_for_cast (struct type
*expect_type
,
632 struct expression
*exp
,
633 enum noside noside
) override
;
635 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
638 value
*evaluate_funcall (struct type
*expect_type
,
639 struct expression
*exp
,
641 const std::vector
<operation_up
> &args
) override
;
643 enum exp_opcode
opcode () const override
644 { return OP_VAR_VALUE
; }
646 /* Return the symbol referenced by this object. */
647 symbol
*get_symbol () const
649 return std::get
<0> (m_storage
);
654 void do_generate_ax (struct expression
*exp
,
655 struct agent_expr
*ax
,
656 struct axs_value
*value
,
657 struct type
*cast_type
)
661 class long_const_operation
662 : public tuple_holding_operation
<struct type
*, LONGEST
>
666 using tuple_holding_operation::tuple_holding_operation
;
668 value
*evaluate (struct type
*expect_type
,
669 struct expression
*exp
,
670 enum noside noside
) override
672 return value_from_longest (std::get
<0> (m_storage
),
673 std::get
<1> (m_storage
));
676 enum exp_opcode
opcode () const override
679 bool constant_p () const override
684 void do_generate_ax (struct expression
*exp
,
685 struct agent_expr
*ax
,
686 struct axs_value
*value
,
687 struct type
*cast_type
)
691 class var_msym_value_operation
692 : public maybe_constant_operation
<bound_minimal_symbol
>
696 using maybe_constant_operation::maybe_constant_operation
;
698 value
*evaluate (struct type
*expect_type
,
699 struct expression
*exp
,
700 enum noside noside
) override
702 return eval_op_var_msym_value (expect_type
, exp
, noside
, m_outermost
,
703 std::get
<0> (m_storage
));
706 value
*evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
709 value
*evaluate_for_address (struct expression
*exp
, enum noside noside
)
712 value
*evaluate_for_cast (struct type
*expect_type
,
713 struct expression
*exp
,
714 enum noside noside
) override
;
716 value
*evaluate_funcall (struct type
*expect_type
,
717 struct expression
*exp
,
719 const std::vector
<operation_up
> &args
) override
721 const char *name
= std::get
<0> (m_storage
).minsym
->print_name ();
722 return operation::evaluate_funcall (expect_type
, exp
, noside
, name
, args
);
725 enum exp_opcode
opcode () const override
726 { return OP_VAR_MSYM_VALUE
; }
728 void set_outermost () override
735 /* True if this is the outermost operation in the expression. */
736 bool m_outermost
= false;
738 void do_generate_ax (struct expression
*exp
,
739 struct agent_expr
*ax
,
740 struct axs_value
*value
,
741 struct type
*cast_type
)
745 class var_entry_value_operation
746 : public tuple_holding_operation
<symbol
*>
750 using tuple_holding_operation::tuple_holding_operation
;
752 value
*evaluate (struct type
*expect_type
,
753 struct expression
*exp
,
754 enum noside noside
) override
756 return eval_op_var_entry_value (expect_type
, exp
, noside
,
757 std::get
<0> (m_storage
));
760 enum exp_opcode
opcode () const override
761 { return OP_VAR_ENTRY_VALUE
; }
764 class func_static_var_operation
765 : public maybe_constant_operation
<operation_up
, std::string
>
769 using maybe_constant_operation::maybe_constant_operation
;
771 value
*evaluate (struct type
*expect_type
,
772 struct expression
*exp
,
773 enum noside noside
) override
775 value
*func
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
776 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
777 std::get
<1> (m_storage
).c_str ());
780 enum exp_opcode
opcode () const override
781 { return OP_FUNC_STATIC_VAR
; }
785 : public tuple_holding_operation
<int>
789 using tuple_holding_operation::tuple_holding_operation
;
791 value
*evaluate (struct type
*expect_type
,
792 struct expression
*exp
,
793 enum noside noside
) override
795 return access_value_history (std::get
<0> (m_storage
));
798 enum exp_opcode
opcode () const override
802 class register_operation
803 : public tuple_holding_operation
<std::string
>
807 using tuple_holding_operation::tuple_holding_operation
;
809 value
*evaluate (struct type
*expect_type
,
810 struct expression
*exp
,
811 enum noside noside
) override
813 return eval_op_register (expect_type
, exp
, noside
,
814 std::get
<0> (m_storage
).c_str ());
817 enum exp_opcode
opcode () const override
818 { return OP_REGISTER
; }
820 /* Return the name of the register. */
821 const char *get_name () const
823 return std::get
<0> (m_storage
).c_str ();
828 void do_generate_ax (struct expression
*exp
,
829 struct agent_expr
*ax
,
830 struct axs_value
*value
,
831 struct type
*cast_type
)
836 : public tuple_holding_operation
<bool>
840 using tuple_holding_operation::tuple_holding_operation
;
842 value
*evaluate (struct type
*expect_type
,
843 struct expression
*exp
,
844 enum noside noside
) override
846 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
847 return value_from_longest (type
, std::get
<0> (m_storage
));
850 enum exp_opcode
opcode () const override
853 bool constant_p () const override
857 class internalvar_operation
858 : public tuple_holding_operation
<internalvar
*>
862 using tuple_holding_operation::tuple_holding_operation
;
864 value
*evaluate (struct type
*expect_type
,
865 struct expression
*exp
,
866 enum noside noside
) override
868 return value_of_internalvar (exp
->gdbarch
,
869 std::get
<0> (m_storage
));
872 internalvar
*get_internalvar () const
874 return std::get
<0> (m_storage
);
877 enum exp_opcode
opcode () const override
878 { return OP_INTERNALVAR
; }
882 void do_generate_ax (struct expression
*exp
,
883 struct agent_expr
*ax
,
884 struct axs_value
*value
,
885 struct type
*cast_type
)
889 class string_operation
890 : public tuple_holding_operation
<std::string
>
894 using tuple_holding_operation::tuple_holding_operation
;
896 value
*evaluate (struct type
*expect_type
,
897 struct expression
*exp
,
898 enum noside noside
) override
900 const std::string
&str
= std::get
<0> (m_storage
);
901 return eval_op_string (expect_type
, exp
, noside
,
902 str
.size (), str
.c_str ());
905 enum exp_opcode
opcode () const override
906 { return OP_STRING
; }
909 class ternop_slice_operation
910 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
914 using maybe_constant_operation::maybe_constant_operation
;
916 value
*evaluate (struct type
*expect_type
,
917 struct expression
*exp
,
918 enum noside noside
) override
921 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
923 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
925 = std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
926 return eval_op_ternop (expect_type
, exp
, noside
, array
, low
, upper
);
929 enum exp_opcode
opcode () const override
930 { return TERNOP_SLICE
; }
933 class ternop_cond_operation
934 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
938 using maybe_constant_operation::maybe_constant_operation
;
940 value
*evaluate (struct type
*expect_type
,
941 struct expression
*exp
,
942 enum noside noside
) override
945 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
947 if (value_logical_not (val
))
948 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
949 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
952 enum exp_opcode
opcode () const override
953 { return TERNOP_COND
; }
957 void do_generate_ax (struct expression
*exp
,
958 struct agent_expr
*ax
,
959 struct axs_value
*value
,
960 struct type
*cast_type
)
964 class complex_operation
965 : public maybe_constant_operation
<operation_up
, operation_up
, struct type
*>
969 using maybe_constant_operation::maybe_constant_operation
;
971 value
*evaluate (struct type
*expect_type
,
972 struct expression
*exp
,
973 enum noside noside
) override
975 value
*real
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
976 value
*imag
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
977 return value_literal_complex (real
, imag
,
978 std::get
<2> (m_storage
));
981 enum exp_opcode
opcode () const override
982 { return OP_COMPLEX
; }
985 class structop_base_operation
986 : public tuple_holding_operation
<operation_up
, std::string
>
990 /* Used for completion. Return the field name. */
991 const std::string
&get_string () const
993 return std::get
<1> (m_storage
);
996 /* Used for completion. Evaluate the LHS for type. */
997 value
*evaluate_lhs (struct expression
*exp
)
999 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1000 EVAL_AVOID_SIDE_EFFECTS
);
1003 value
*evaluate_funcall (struct type
*expect_type
,
1004 struct expression
*exp
,
1006 const std::vector
<operation_up
> &args
) override
;
1010 using tuple_holding_operation::tuple_holding_operation
;
1013 class structop_operation
1014 : public structop_base_operation
1018 using structop_base_operation::structop_base_operation
;
1020 value
*evaluate (struct type
*expect_type
,
1021 struct expression
*exp
,
1022 enum noside noside
) override
1024 value
*val
=std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1025 return eval_op_structop_struct (expect_type
, exp
, noside
, val
,
1026 std::get
<1> (m_storage
).c_str ());
1029 enum exp_opcode
opcode () const override
1030 { return STRUCTOP_STRUCT
; }
1034 void do_generate_ax (struct expression
*exp
,
1035 struct agent_expr
*ax
,
1036 struct axs_value
*value
,
1037 struct type
*cast_type
)
1040 gen_expr_structop (exp
, STRUCTOP_STRUCT
,
1041 std::get
<0> (this->m_storage
).get (),
1042 std::get
<1> (this->m_storage
).c_str (),
1047 class structop_ptr_operation
1048 : public structop_base_operation
1052 using structop_base_operation::structop_base_operation
;
1054 value
*evaluate (struct type
*expect_type
,
1055 struct expression
*exp
,
1056 enum noside noside
) override
1058 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1059 return eval_op_structop_ptr (expect_type
, exp
, noside
, val
,
1060 std::get
<1> (m_storage
).c_str ());
1063 enum exp_opcode
opcode () const override
1064 { return STRUCTOP_PTR
; }
1068 void do_generate_ax (struct expression
*exp
,
1069 struct agent_expr
*ax
,
1070 struct axs_value
*value
,
1071 struct type
*cast_type
)
1074 gen_expr_structop (exp
, STRUCTOP_PTR
,
1075 std::get
<0> (this->m_storage
).get (),
1076 std::get
<1> (this->m_storage
).c_str (),
1081 class structop_member_base
1082 : public tuple_holding_operation
<operation_up
, operation_up
>
1086 using tuple_holding_operation::tuple_holding_operation
;
1088 value
*evaluate_funcall (struct type
*expect_type
,
1089 struct expression
*exp
,
1091 const std::vector
<operation_up
> &args
) override
;
1094 class structop_member_operation
1095 : public structop_member_base
1099 using structop_member_base::structop_member_base
;
1101 value
*evaluate (struct type
*expect_type
,
1102 struct expression
*exp
,
1103 enum noside noside
) override
1106 = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1108 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1109 return eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1112 enum exp_opcode
opcode () const override
1113 { return STRUCTOP_MEMBER
; }
1116 class structop_mptr_operation
1117 : public structop_member_base
1121 using structop_member_base::structop_member_base
;
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 eval_op_member (expect_type
, exp
, noside
, lhs
, rhs
);
1134 enum exp_opcode
opcode () const override
1135 { return STRUCTOP_MPTR
; }
1138 class concat_operation
1139 : public maybe_constant_operation
<operation_up
, operation_up
>
1143 using maybe_constant_operation::maybe_constant_operation
;
1145 value
*evaluate (struct type
*expect_type
,
1146 struct expression
*exp
,
1147 enum noside noside
) override
1150 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1152 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1153 return eval_op_concat (expect_type
, exp
, noside
, lhs
, rhs
);
1156 enum exp_opcode
opcode () const override
1157 { return BINOP_CONCAT
; }
1161 : public maybe_constant_operation
<operation_up
, operation_up
>
1165 using maybe_constant_operation::maybe_constant_operation
;
1167 value
*evaluate (struct type
*expect_type
,
1168 struct expression
*exp
,
1169 enum noside noside
) override
1172 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1174 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1175 return eval_op_add (expect_type
, exp
, noside
, lhs
, rhs
);
1178 enum exp_opcode
opcode () const override
1179 { return BINOP_ADD
; }
1183 void do_generate_ax (struct expression
*exp
,
1184 struct agent_expr
*ax
,
1185 struct axs_value
*value
,
1186 struct type
*cast_type
)
1189 gen_expr_binop (exp
, BINOP_ADD
,
1190 std::get
<0> (this->m_storage
).get (),
1191 std::get
<1> (this->m_storage
).get (),
1197 : public maybe_constant_operation
<operation_up
, operation_up
>
1201 using maybe_constant_operation::maybe_constant_operation
;
1203 value
*evaluate (struct type
*expect_type
,
1204 struct expression
*exp
,
1205 enum noside noside
) override
1208 = std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1210 = std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
1211 return eval_op_sub (expect_type
, exp
, noside
, lhs
, rhs
);
1214 enum exp_opcode
opcode () const override
1215 { return BINOP_SUB
; }
1219 void do_generate_ax (struct expression
*exp
,
1220 struct agent_expr
*ax
,
1221 struct axs_value
*value
,
1222 struct type
*cast_type
)
1225 gen_expr_binop (exp
, BINOP_SUB
,
1226 std::get
<0> (this->m_storage
).get (),
1227 std::get
<1> (this->m_storage
).get (),
1232 typedef struct value
*binary_ftype (struct type
*expect_type
,
1233 struct expression
*exp
,
1234 enum noside noside
, enum exp_opcode op
,
1235 struct value
*arg1
, struct value
*arg2
);
1237 template<enum exp_opcode OP
, binary_ftype FUNC
>
1238 class binop_operation
1239 : public maybe_constant_operation
<operation_up
, operation_up
>
1243 using maybe_constant_operation::maybe_constant_operation
;
1245 value
*evaluate (struct type
*expect_type
,
1246 struct expression
*exp
,
1247 enum noside noside
) override
1250 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1252 = std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1253 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1256 enum exp_opcode
opcode () const override
1260 template<enum exp_opcode OP
, binary_ftype FUNC
>
1261 class usual_ax_binop_operation
1262 : public binop_operation
<OP
, FUNC
>
1266 using binop_operation
<OP
, FUNC
>::binop_operation
;
1270 void do_generate_ax (struct expression
*exp
,
1271 struct agent_expr
*ax
,
1272 struct axs_value
*value
,
1273 struct type
*cast_type
)
1276 gen_expr_binop (exp
, OP
,
1277 std::get
<0> (this->m_storage
).get (),
1278 std::get
<1> (this->m_storage
).get (),
1283 using exp_operation
= binop_operation
<BINOP_EXP
, eval_op_binary
>;
1284 using intdiv_operation
= binop_operation
<BINOP_INTDIV
, eval_op_binary
>;
1285 using mod_operation
= binop_operation
<BINOP_MOD
, eval_op_binary
>;
1287 using mul_operation
= usual_ax_binop_operation
<BINOP_MUL
, eval_op_binary
>;
1288 using div_operation
= usual_ax_binop_operation
<BINOP_DIV
, eval_op_binary
>;
1289 using rem_operation
= usual_ax_binop_operation
<BINOP_REM
, eval_op_binary
>;
1290 using lsh_operation
= usual_ax_binop_operation
<BINOP_LSH
, eval_op_binary
>;
1291 using rsh_operation
= usual_ax_binop_operation
<BINOP_RSH
, eval_op_binary
>;
1292 using bitwise_and_operation
1293 = usual_ax_binop_operation
<BINOP_BITWISE_AND
, eval_op_binary
>;
1294 using bitwise_ior_operation
1295 = usual_ax_binop_operation
<BINOP_BITWISE_IOR
, eval_op_binary
>;
1296 using bitwise_xor_operation
1297 = usual_ax_binop_operation
<BINOP_BITWISE_XOR
, eval_op_binary
>;
1299 class subscript_operation
1300 : public usual_ax_binop_operation
<BINOP_SUBSCRIPT
, eval_op_subscript
>
1303 using usual_ax_binop_operation
<BINOP_SUBSCRIPT
,
1304 eval_op_subscript
>::usual_ax_binop_operation
;
1306 value
*evaluate_for_sizeof (struct expression
*exp
,
1307 enum noside noside
) override
;
1310 /* Implementation of comparison operations. */
1311 template<enum exp_opcode OP
, binary_ftype FUNC
>
1312 class comparison_operation
1313 : public usual_ax_binop_operation
<OP
, FUNC
>
1317 using usual_ax_binop_operation
<OP
, FUNC
>::usual_ax_binop_operation
;
1319 value
*evaluate (struct type
*expect_type
,
1320 struct expression
*exp
,
1321 enum noside noside
) override
1324 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
1326 = std::get
<1> (this->m_storage
)->evaluate (value_type (lhs
), exp
,
1328 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
1332 class equal_operation
1333 : public comparison_operation
<BINOP_EQUAL
, eval_op_equal
>
1337 using comparison_operation::comparison_operation
;
1339 operation
*get_lhs () const
1341 return std::get
<0> (m_storage
).get ();
1344 operation
*get_rhs () const
1346 return std::get
<1> (m_storage
).get ();
1350 using notequal_operation
1351 = comparison_operation
<BINOP_NOTEQUAL
, eval_op_notequal
>;
1352 using less_operation
= comparison_operation
<BINOP_LESS
, eval_op_less
>;
1353 using gtr_operation
= comparison_operation
<BINOP_GTR
, eval_op_gtr
>;
1354 using geq_operation
= comparison_operation
<BINOP_GEQ
, eval_op_geq
>;
1355 using leq_operation
= comparison_operation
<BINOP_LEQ
, eval_op_leq
>;
1357 /* Implement the GDB '@' repeat operator. */
1358 class repeat_operation
1359 : public binop_operation
<BINOP_REPEAT
, eval_op_repeat
>
1361 using binop_operation
<BINOP_REPEAT
, eval_op_repeat
>::binop_operation
;
1365 void do_generate_ax (struct expression
*exp
,
1366 struct agent_expr
*ax
,
1367 struct axs_value
*value
,
1368 struct type
*cast_type
)
1372 /* C-style comma operator. */
1373 class comma_operation
1374 : public maybe_constant_operation
<operation_up
, operation_up
>
1378 using maybe_constant_operation::maybe_constant_operation
;
1380 value
*evaluate (struct type
*expect_type
,
1381 struct expression
*exp
,
1382 enum noside noside
) override
1384 /* The left-hand-side is only evaluated for side effects, so don't
1385 bother in other modes. */
1386 if (noside
== EVAL_NORMAL
)
1387 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1388 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1391 enum exp_opcode
opcode () const override
1392 { return BINOP_COMMA
; }
1396 void do_generate_ax (struct expression
*exp
,
1397 struct agent_expr
*ax
,
1398 struct axs_value
*value
,
1399 struct type
*cast_type
)
1403 typedef struct value
*unary_ftype (struct type
*expect_type
,
1404 struct expression
*exp
,
1405 enum noside noside
, enum exp_opcode op
,
1406 struct value
*arg1
);
1408 /* Base class for unary operations. */
1409 template<enum exp_opcode OP
, unary_ftype FUNC
>
1410 class unop_operation
1411 : public maybe_constant_operation
<operation_up
>
1415 using maybe_constant_operation::maybe_constant_operation
;
1417 value
*evaluate (struct type
*expect_type
,
1418 struct expression
*exp
,
1419 enum noside noside
) override
1421 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1422 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1425 enum exp_opcode
opcode () const override
1429 /* Unary operations that can also be turned into agent expressions in
1431 template<enum exp_opcode OP
, unary_ftype FUNC
>
1432 class usual_ax_unop_operation
1433 : public unop_operation
<OP
, FUNC
>
1435 using unop_operation
<OP
, FUNC
>::unop_operation
;
1439 void do_generate_ax (struct expression
*exp
,
1440 struct agent_expr
*ax
,
1441 struct axs_value
*value
,
1442 struct type
*cast_type
)
1445 gen_expr_unop (exp
, OP
,
1446 std::get
<0> (this->m_storage
).get (),
1451 using unary_plus_operation
= usual_ax_unop_operation
<UNOP_PLUS
, eval_op_plus
>;
1452 using unary_neg_operation
= usual_ax_unop_operation
<UNOP_NEG
, eval_op_neg
>;
1453 using unary_complement_operation
1454 = usual_ax_unop_operation
<UNOP_COMPLEMENT
, eval_op_complement
>;
1455 using unary_logical_not_operation
1456 = usual_ax_unop_operation
<UNOP_LOGICAL_NOT
, eval_op_lognot
>;
1458 /* Handle pre- and post- increment and -decrement. */
1459 template<enum exp_opcode OP
, unary_ftype FUNC
>
1460 class unop_incr_operation
1461 : public tuple_holding_operation
<operation_up
>
1465 using tuple_holding_operation::tuple_holding_operation
;
1467 value
*evaluate (struct type
*expect_type
,
1468 struct expression
*exp
,
1469 enum noside noside
) override
1471 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1472 return FUNC (expect_type
, exp
, noside
, OP
, val
);
1475 enum exp_opcode
opcode () const override
1479 using preinc_operation
1480 = unop_incr_operation
<UNOP_PREINCREMENT
, eval_op_preinc
>;
1481 using predec_operation
1482 = unop_incr_operation
<UNOP_PREDECREMENT
, eval_op_predec
>;
1483 using postinc_operation
1484 = unop_incr_operation
<UNOP_POSTINCREMENT
, eval_op_postinc
>;
1485 using postdec_operation
1486 = unop_incr_operation
<UNOP_POSTDECREMENT
, eval_op_postdec
>;
1488 /* Base class for implementations of UNOP_IND. */
1489 class unop_ind_base_operation
1490 : public tuple_holding_operation
<operation_up
>
1494 using tuple_holding_operation::tuple_holding_operation
;
1496 value
*evaluate (struct type
*expect_type
,
1497 struct expression
*exp
,
1498 enum noside noside
) override
1500 if (expect_type
!= nullptr && expect_type
->code () == TYPE_CODE_PTR
)
1501 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1502 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1503 return eval_op_ind (expect_type
, exp
, noside
, val
);
1506 value
*evaluate_for_address (struct expression
*exp
,
1507 enum noside noside
) override
;
1509 value
*evaluate_for_sizeof (struct expression
*exp
,
1510 enum noside noside
) override
;
1512 enum exp_opcode
opcode () const override
1513 { return UNOP_IND
; }
1516 /* Ordinary UNOP_IND implementation. */
1517 class unop_ind_operation
1518 : public unop_ind_base_operation
1522 using unop_ind_base_operation::unop_ind_base_operation
;
1526 void do_generate_ax (struct expression
*exp
,
1527 struct agent_expr
*ax
,
1528 struct axs_value
*value
,
1529 struct type
*cast_type
)
1532 gen_expr_unop (exp
, UNOP_IND
,
1533 std::get
<0> (this->m_storage
).get (),
1538 /* Implement OP_TYPE. */
1539 class type_operation
1540 : public tuple_holding_operation
<struct type
*>
1544 using tuple_holding_operation::tuple_holding_operation
;
1546 value
*evaluate (struct type
*expect_type
,
1547 struct expression
*exp
,
1548 enum noside noside
) override
1550 return eval_op_type (expect_type
, exp
, noside
, std::get
<0> (m_storage
));
1553 enum exp_opcode
opcode () const override
1556 bool constant_p () const override
1560 /* Implement the "typeof" operation. */
1561 class typeof_operation
1562 : public maybe_constant_operation
<operation_up
>
1566 using maybe_constant_operation::maybe_constant_operation
;
1568 value
*evaluate (struct type
*expect_type
,
1569 struct expression
*exp
,
1570 enum noside noside
) override
1572 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1573 return std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1574 EVAL_AVOID_SIDE_EFFECTS
);
1576 error (_("Attempt to use a type as an expression"));
1579 enum exp_opcode
opcode () const override
1580 { return OP_TYPEOF
; }
1583 /* Implement 'decltype'. */
1584 class decltype_operation
1585 : public maybe_constant_operation
<operation_up
>
1589 using maybe_constant_operation::maybe_constant_operation
;
1591 value
*evaluate (struct type
*expect_type
,
1592 struct expression
*exp
,
1593 enum noside noside
) override
1595 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1598 = std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1599 EVAL_AVOID_SIDE_EFFECTS
);
1600 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1601 if (sub_op
== BINOP_SUBSCRIPT
1602 || sub_op
== STRUCTOP_MEMBER
1603 || sub_op
== STRUCTOP_MPTR
1604 || sub_op
== UNOP_IND
1605 || sub_op
== STRUCTOP_STRUCT
1606 || sub_op
== STRUCTOP_PTR
1607 || sub_op
== OP_SCOPE
)
1609 struct type
*type
= value_type (result
);
1611 if (!TYPE_IS_REFERENCE (type
))
1613 type
= lookup_lvalue_reference_type (type
);
1614 result
= allocate_value (type
);
1621 error (_("Attempt to use a type as an expression"));
1624 enum exp_opcode
opcode () const override
1625 { return OP_DECLTYPE
; }
1628 /* Implement 'typeid'. */
1629 class typeid_operation
1630 : public tuple_holding_operation
<operation_up
>
1634 using tuple_holding_operation::tuple_holding_operation
;
1636 value
*evaluate (struct type
*expect_type
,
1637 struct expression
*exp
,
1638 enum noside noside
) override
1640 enum exp_opcode sub_op
= std::get
<0> (m_storage
)->opcode ();
1641 enum noside sub_noside
1642 = ((sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
1643 ? EVAL_AVOID_SIDE_EFFECTS
1646 value
*result
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1648 if (noside
!= EVAL_NORMAL
)
1649 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
1650 return cplus_typeid (result
);
1653 enum exp_opcode
opcode () const override
1654 { return OP_TYPEID
; }
1657 /* Implement the address-of operation. */
1658 class unop_addr_operation
1659 : public maybe_constant_operation
<operation_up
>
1663 using maybe_constant_operation::maybe_constant_operation
;
1665 value
*evaluate (struct type
*expect_type
,
1666 struct expression
*exp
,
1667 enum noside noside
) override
1669 /* C++: check for and handle pointer to members. */
1670 return std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1673 enum exp_opcode
opcode () const override
1674 { return UNOP_ADDR
; }
1676 /* Return the subexpression. */
1677 const operation_up
&get_expression () const
1679 return std::get
<0> (m_storage
);
1684 void do_generate_ax (struct expression
*exp
,
1685 struct agent_expr
*ax
,
1686 struct axs_value
*value
,
1687 struct type
*cast_type
)
1690 gen_expr_unop (exp
, UNOP_ADDR
,
1691 std::get
<0> (this->m_storage
).get (),
1696 /* Implement 'sizeof'. */
1697 class unop_sizeof_operation
1698 : public maybe_constant_operation
<operation_up
>
1702 using maybe_constant_operation::maybe_constant_operation
;
1704 value
*evaluate (struct type
*expect_type
,
1705 struct expression
*exp
,
1706 enum noside noside
) override
1708 return std::get
<0> (m_storage
)->evaluate_for_sizeof (exp
, noside
);
1711 enum exp_opcode
opcode () const override
1712 { return UNOP_SIZEOF
; }
1716 void do_generate_ax (struct expression
*exp
,
1717 struct agent_expr
*ax
,
1718 struct axs_value
*value
,
1719 struct type
*cast_type
)
1723 /* Implement 'alignof'. */
1724 class unop_alignof_operation
1725 : public maybe_constant_operation
<operation_up
>
1729 using maybe_constant_operation::maybe_constant_operation
;
1731 value
*evaluate (struct type
*expect_type
,
1732 struct expression
*exp
,
1733 enum noside noside
) override
1735 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1736 EVAL_AVOID_SIDE_EFFECTS
);
1737 return eval_op_alignof (expect_type
, exp
, noside
, val
);
1740 enum exp_opcode
opcode () const override
1741 { return UNOP_ALIGNOF
; }
1744 /* Implement UNOP_MEMVAL. */
1745 class unop_memval_operation
1746 : public tuple_holding_operation
<operation_up
, struct type
*>
1750 using tuple_holding_operation::tuple_holding_operation
;
1752 value
*evaluate (struct type
*expect_type
,
1753 struct expression
*exp
,
1754 enum noside noside
) override
1756 value
*val
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1757 return eval_op_memval (expect_type
, exp
, noside
, val
,
1758 std::get
<1> (m_storage
));
1761 value
*evaluate_for_sizeof (struct expression
*exp
,
1762 enum noside noside
) override
;
1764 value
*evaluate_for_address (struct expression
*exp
,
1765 enum noside noside
) override
;
1767 enum exp_opcode
opcode () const override
1768 { return UNOP_MEMVAL
; }
1770 /* Return the type referenced by this object. */
1771 struct type
*get_type () const
1773 return std::get
<1> (m_storage
);
1778 void do_generate_ax (struct expression
*exp
,
1779 struct agent_expr
*ax
,
1780 struct axs_value
*value
,
1781 struct type
*cast_type
)
1785 /* Implement UNOP_MEMVAL_TYPE. */
1786 class unop_memval_type_operation
1787 : public tuple_holding_operation
<operation_up
, operation_up
>
1791 using tuple_holding_operation::tuple_holding_operation
;
1793 value
*evaluate (struct type
*expect_type
,
1794 struct expression
*exp
,
1795 enum noside noside
) override
1798 = std::get
<0> (m_storage
)->evaluate (expect_type
, exp
,
1799 EVAL_AVOID_SIDE_EFFECTS
);
1800 struct type
*type
= value_type (typeval
);
1801 value
*val
= std::get
<1> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1802 return eval_op_memval (expect_type
, exp
, noside
, val
, type
);
1805 value
*evaluate_for_sizeof (struct expression
*exp
,
1806 enum noside noside
) override
;
1808 value
*evaluate_for_address (struct expression
*exp
,
1809 enum noside noside
) override
;
1811 enum exp_opcode
opcode () const override
1812 { return UNOP_MEMVAL_TYPE
; }
1816 void do_generate_ax (struct expression
*exp
,
1817 struct agent_expr
*ax
,
1818 struct axs_value
*value
,
1819 struct type
*cast_type
)
1823 /* Implement the 'this' expression. */
1824 class op_this_operation
1825 : public tuple_holding_operation
<>
1829 using tuple_holding_operation::tuple_holding_operation
;
1831 value
*evaluate (struct type
*expect_type
,
1832 struct expression
*exp
,
1833 enum noside noside
) override
1835 return value_of_this (exp
->language_defn
);
1838 enum exp_opcode
opcode () const override
1843 void do_generate_ax (struct expression
*exp
,
1844 struct agent_expr
*ax
,
1845 struct axs_value
*value
,
1846 struct type
*cast_type
)
1850 /* Implement the "type instance" operation. */
1851 class type_instance_operation
1852 : public tuple_holding_operation
<type_instance_flags
, std::vector
<type
*>,
1857 using tuple_holding_operation::tuple_holding_operation
;
1859 value
*evaluate (struct type
*expect_type
,
1860 struct expression
*exp
,
1861 enum noside noside
) override
;
1863 enum exp_opcode
opcode () const override
1864 { return TYPE_INSTANCE
; }
1867 /* The assignment operator. */
1868 class assign_operation
1869 : public tuple_holding_operation
<operation_up
, operation_up
>
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 value
*lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1880 /* Special-case assignments where the left-hand-side is a
1881 convenience variable -- in these, don't bother setting an
1882 expected type. This avoids a weird case where re-assigning a
1883 string or array to an internal variable could error with "Too
1884 many array elements". */
1885 struct type
*xtype
= (VALUE_LVAL (lhs
) == lval_internalvar
1887 : value_type (lhs
));
1888 value
*rhs
= std::get
<1> (m_storage
)->evaluate (xtype
, exp
, noside
);
1890 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1892 if (binop_user_defined_p (BINOP_ASSIGN
, lhs
, rhs
))
1893 return value_x_binop (lhs
, rhs
, BINOP_ASSIGN
, OP_NULL
, noside
);
1895 return value_assign (lhs
, rhs
);
1898 enum exp_opcode
opcode () const override
1899 { return BINOP_ASSIGN
; }
1901 /* Return the left-hand-side of the assignment. */
1902 operation
*get_lhs () const
1904 return std::get
<0> (m_storage
).get ();
1909 void do_generate_ax (struct expression
*exp
,
1910 struct agent_expr
*ax
,
1911 struct axs_value
*value
,
1912 struct type
*cast_type
)
1916 /* Assignment with modification, like "+=". */
1917 class assign_modify_operation
1918 : public tuple_holding_operation
<exp_opcode
, operation_up
, operation_up
>
1922 using tuple_holding_operation::tuple_holding_operation
;
1924 value
*evaluate (struct type
*expect_type
,
1925 struct expression
*exp
,
1926 enum noside noside
) override
1928 value
*lhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1929 value
*rhs
= std::get
<2> (m_storage
)->evaluate (expect_type
, exp
, noside
);
1930 return eval_binop_assign_modify (expect_type
, exp
, noside
,
1931 std::get
<0> (m_storage
), lhs
, rhs
);
1934 enum exp_opcode
opcode () const override
1935 { return BINOP_ASSIGN_MODIFY
; }
1939 void do_generate_ax (struct expression
*exp
,
1940 struct agent_expr
*ax
,
1941 struct axs_value
*value
,
1942 struct type
*cast_type
)
1947 class unop_cast_operation
1948 : public maybe_constant_operation
<operation_up
, struct type
*>
1952 using maybe_constant_operation::maybe_constant_operation
;
1954 value
*evaluate (struct type
*expect_type
,
1955 struct expression
*exp
,
1956 enum noside noside
) override
1958 return std::get
<0> (m_storage
)->evaluate_for_cast (std::get
<1> (m_storage
),
1962 enum exp_opcode
opcode () const override
1963 { return UNOP_CAST
; }
1965 /* Return the type referenced by this object. */
1966 struct type
*get_type () const
1968 return std::get
<1> (m_storage
);
1973 void do_generate_ax (struct expression
*exp
,
1974 struct agent_expr
*ax
,
1975 struct axs_value
*value
,
1976 struct type
*cast_type
)
1980 /* A cast, but the type comes from an expression, not a "struct
1982 class unop_cast_type_operation
1983 : public maybe_constant_operation
<operation_up
, operation_up
>
1987 using maybe_constant_operation::maybe_constant_operation
;
1989 value
*evaluate (struct type
*expect_type
,
1990 struct expression
*exp
,
1991 enum noside noside
) override
1993 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
1994 EVAL_AVOID_SIDE_EFFECTS
);
1995 return std::get
<1> (m_storage
)->evaluate_for_cast (value_type (val
),
1999 enum exp_opcode
opcode () const override
2000 { return UNOP_CAST_TYPE
; }
2004 void do_generate_ax (struct expression
*exp
,
2005 struct agent_expr
*ax
,
2006 struct axs_value
*value
,
2007 struct type
*cast_type
)
2011 typedef value
*cxx_cast_ftype (struct type
*, value
*);
2013 /* This implements dynamic_cast and reinterpret_cast. static_cast and
2014 const_cast are handled by the ordinary case operations. */
2015 template<exp_opcode OP
, cxx_cast_ftype FUNC
>
2016 class cxx_cast_operation
2017 : public maybe_constant_operation
<operation_up
, operation_up
>
2021 using maybe_constant_operation::maybe_constant_operation
;
2023 value
*evaluate (struct type
*expect_type
,
2024 struct expression
*exp
,
2025 enum noside noside
) override
2027 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
2028 EVAL_AVOID_SIDE_EFFECTS
);
2029 struct type
*type
= value_type (val
);
2030 value
*rhs
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
2031 return FUNC (type
, rhs
);
2034 enum exp_opcode
opcode () const override
2038 using dynamic_cast_operation
= cxx_cast_operation
<UNOP_DYNAMIC_CAST
,
2039 value_dynamic_cast
>;
2040 using reinterpret_cast_operation
= cxx_cast_operation
<UNOP_REINTERPRET_CAST
,
2041 value_reinterpret_cast
>;
2043 /* Multi-dimensional subscripting. */
2044 class multi_subscript_operation
2045 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2049 using tuple_holding_operation::tuple_holding_operation
;
2051 value
*evaluate (struct type
*expect_type
,
2052 struct expression
*exp
,
2053 enum noside noside
) override
;
2055 enum exp_opcode
opcode () const override
2056 { return MULTI_SUBSCRIPT
; }
2059 /* The "&&" operator. */
2060 class logical_and_operation
2061 : public maybe_constant_operation
<operation_up
, operation_up
>
2065 using maybe_constant_operation::maybe_constant_operation
;
2067 value
*evaluate (struct type
*expect_type
,
2068 struct expression
*exp
,
2069 enum noside noside
) override
;
2071 enum exp_opcode
opcode () const override
2072 { return BINOP_LOGICAL_AND
; }
2076 void do_generate_ax (struct expression
*exp
,
2077 struct agent_expr
*ax
,
2078 struct axs_value
*value
,
2079 struct type
*cast_type
)
2083 /* The "||" operator. */
2084 class logical_or_operation
2085 : public maybe_constant_operation
<operation_up
, operation_up
>
2089 using maybe_constant_operation::maybe_constant_operation
;
2091 value
*evaluate (struct type
*expect_type
,
2092 struct expression
*exp
,
2093 enum noside noside
) override
;
2095 enum exp_opcode
opcode () const override
2096 { return BINOP_LOGICAL_OR
; }
2100 void do_generate_ax (struct expression
*exp
,
2101 struct agent_expr
*ax
,
2102 struct axs_value
*value
,
2103 struct type
*cast_type
)
2107 /* This class implements ADL (aka Koenig) function calls for C++. It
2108 holds the name of the function to call, the block in which the
2109 lookup should be done, and a vector of arguments. */
2110 class adl_func_operation
2111 : public tuple_holding_operation
<std::string
, const block
*,
2112 std::vector
<operation_up
>>
2116 using tuple_holding_operation::tuple_holding_operation
;
2118 value
*evaluate (struct type
*expect_type
,
2119 struct expression
*exp
,
2120 enum noside noside
) override
;
2122 enum exp_opcode
opcode () const override
2123 { return OP_ADL_FUNC
; }
2126 /* The OP_ARRAY operation. */
2127 class array_operation
2128 : public tuple_holding_operation
<int, int, std::vector
<operation_up
>>
2132 using tuple_holding_operation::tuple_holding_operation
;
2134 value
*evaluate (struct type
*expect_type
,
2135 struct expression
*exp
,
2136 enum noside noside
) override
;
2138 enum exp_opcode
opcode () const override
2139 { return OP_ARRAY
; }
2143 struct value
*evaluate_struct_tuple (struct value
*struct_val
,
2144 struct expression
*exp
,
2145 enum noside noside
, int nargs
);
2148 /* A function call. This holds the callee operation and the
2150 class funcall_operation
2151 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
2155 using tuple_holding_operation::tuple_holding_operation
;
2157 value
*evaluate (struct type
*expect_type
,
2158 struct expression
*exp
,
2159 enum noside noside
) override
2161 return std::get
<0> (m_storage
)->evaluate_funcall (expect_type
, exp
, noside
,
2162 std::get
<1> (m_storage
));
2165 enum exp_opcode
opcode () const override
2166 { return OP_FUNCALL
; }
2169 } /* namespace expr */
2171 #endif /* EXPOP_H */