1 /* Definitions for expressions in GDB
3 Copyright (C) 2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "expression.h"
28 #include "gdbsupport/traits.h"
29 #include "gdbsupport/enum-flags.h"
34 extern void gen_expr_binop (struct expression *exp,
36 expr::operation *lhs, expr::operation *rhs,
37 struct agent_expr *ax, struct axs_value *value);
38 extern void gen_expr_structop (struct expression *exp,
42 struct agent_expr *ax, struct axs_value *value);
43 extern void gen_expr_unop (struct expression *exp,
46 struct agent_expr *ax, struct axs_value *value);
48 extern struct value *eval_op_scope (struct type *expect_type,
49 struct expression *exp,
51 struct type *type, const char *string);
52 extern struct value *eval_op_var_msym_value (struct type *expect_type,
53 struct expression *exp,
56 minimal_symbol *msymbol,
57 struct objfile *objfile);
58 extern struct value *eval_op_var_entry_value (struct type *expect_type,
59 struct expression *exp,
60 enum noside noside, symbol *sym);
61 extern struct value *eval_op_func_static_var (struct type *expect_type,
62 struct expression *exp,
64 value *func, const char *var);
65 extern struct value *eval_op_register (struct type *expect_type,
66 struct expression *exp,
67 enum noside noside, const char *name);
68 extern struct value *eval_op_string (struct type *expect_type,
69 struct expression *exp,
70 enum noside noside, int len,
72 extern struct value *eval_op_ternop (struct type *expect_type,
73 struct expression *exp,
75 struct value *array, struct value *low,
77 extern struct value *eval_op_structop_struct (struct type *expect_type,
78 struct expression *exp,
82 extern struct value *eval_op_structop_ptr (struct type *expect_type,
83 struct expression *exp,
87 extern struct value *eval_op_member (struct type *expect_type,
88 struct expression *exp,
90 struct value *arg1, struct value *arg2);
91 extern struct value *eval_op_concat (struct type *expect_type,
92 struct expression *exp,
94 struct value *arg1, struct value *arg2);
95 extern struct value *eval_op_add (struct type *expect_type,
96 struct expression *exp,
98 struct value *arg1, struct value *arg2);
99 extern struct value *eval_op_sub (struct type *expect_type,
100 struct expression *exp,
102 struct value *arg1, struct value *arg2);
103 extern struct value *eval_op_binary (struct type *expect_type,
104 struct expression *exp,
105 enum noside noside, enum exp_opcode op,
106 struct value *arg1, struct value *arg2);
107 extern struct value *eval_op_subscript (struct type *expect_type,
108 struct expression *exp,
109 enum noside noside, enum exp_opcode op,
112 extern struct value *eval_op_equal (struct type *expect_type,
113 struct expression *exp,
114 enum noside noside, enum exp_opcode op,
117 extern struct value *eval_op_notequal (struct type *expect_type,
118 struct expression *exp,
119 enum noside noside, enum exp_opcode op,
122 extern struct value *eval_op_less (struct type *expect_type,
123 struct expression *exp,
124 enum noside noside, enum exp_opcode op,
127 extern struct value *eval_op_gtr (struct type *expect_type,
128 struct expression *exp,
129 enum noside noside, enum exp_opcode op,
132 extern struct value *eval_op_geq (struct type *expect_type,
133 struct expression *exp,
134 enum noside noside, enum exp_opcode op,
137 extern struct value *eval_op_leq (struct type *expect_type,
138 struct expression *exp,
139 enum noside noside, enum exp_opcode op,
142 extern struct value *eval_op_repeat (struct type *expect_type,
143 struct expression *exp,
144 enum noside noside, enum exp_opcode op,
147 extern struct value *eval_op_plus (struct type *expect_type,
148 struct expression *exp,
149 enum noside noside, enum exp_opcode op,
151 extern struct value *eval_op_neg (struct type *expect_type,
152 struct expression *exp,
153 enum noside noside, enum exp_opcode op,
155 extern struct value *eval_op_complement (struct type *expect_type,
156 struct expression *exp,
160 extern struct value *eval_op_lognot (struct type *expect_type,
161 struct expression *exp,
165 extern struct value *eval_op_preinc (struct type *expect_type,
166 struct expression *exp,
170 extern struct value *eval_op_predec (struct type *expect_type,
171 struct expression *exp,
175 extern struct value *eval_op_postinc (struct type *expect_type,
176 struct expression *exp,
180 extern struct value *eval_op_postdec (struct type *expect_type,
181 struct expression *exp,
185 extern struct value *eval_op_ind (struct type *expect_type,
186 struct expression *exp,
189 extern struct value *eval_op_type (struct type *expect_type,
190 struct expression *exp,
191 enum noside noside, struct type *type);
192 extern struct value *eval_op_alignof (struct type *expect_type,
193 struct expression *exp,
196 extern struct value *eval_op_memval (struct type *expect_type,
197 struct expression *exp,
199 struct value *arg1, struct type *type);
200 extern struct value *eval_binop_assign_modify (struct type *expect_type,
201 struct expression *exp,
212 /* The check_objfile overloads are used to check whether a particular
213 component of some operation references an objfile. The passed-in
214 objfile will never be a debug objfile. */
216 /* See if EXP_OBJFILE matches OBJFILE. */
218 check_objfile (struct objfile *exp_objfile, struct objfile *objfile)
220 if (exp_objfile->separate_debug_objfile_backlink)
221 exp_objfile = exp_objfile->separate_debug_objfile_backlink;
222 return exp_objfile == objfile;
226 check_objfile (struct type *type, struct objfile *objfile)
228 struct objfile *ty_objfile = type->objfile_owner ();
229 if (ty_objfile != nullptr)
230 return check_objfile (ty_objfile, objfile);
235 check_objfile (struct symbol *sym, struct objfile *objfile)
237 return check_objfile (symbol_objfile (sym), objfile);
241 check_objfile (const struct block *block, struct objfile *objfile)
243 return check_objfile (block_objfile (block), objfile);
247 check_objfile (minimal_symbol *minsym, struct objfile *objfile)
249 /* This may seem strange but minsyms are only used with an objfile
255 check_objfile (internalvar *ivar, struct objfile *objfile)
261 check_objfile (const std::string &str, struct objfile *objfile)
267 check_objfile (const operation_up &op, struct objfile *objfile)
269 return op->uses_objfile (objfile);
273 check_objfile (enum exp_opcode val, struct objfile *objfile)
279 check_objfile (ULONGEST val, struct objfile *objfile)
286 check_objfile (enum_flags<T> val, struct objfile *objfile)
293 check_objfile (const std::vector<T> &collection, struct objfile *objfile)
295 for (const auto &item : collection)
297 if (check_objfile (item, objfile))
303 template<typename S, typename T>
305 check_objfile (const std::pair<S, T> &item, struct objfile *objfile)
307 return (check_objfile (item.first, objfile)
308 || check_objfile (item.second, objfile));
311 extern bool check_objfile (const std::unique_ptr<ada_component> &comp,
312 struct objfile *objfile);
315 dump_for_expression (struct ui_file *stream, int depth,
316 const operation_up &op)
318 op->dump (stream, depth);
321 extern void dump_for_expression (struct ui_file *stream, int depth,
323 extern void dump_for_expression (struct ui_file *stream, int depth,
324 const std::string &str);
325 extern void dump_for_expression (struct ui_file *stream, int depth,
327 extern void dump_for_expression (struct ui_file *stream, int depth,
329 extern void dump_for_expression (struct ui_file *stream, int depth,
331 extern void dump_for_expression (struct ui_file *stream, int depth,
333 extern void dump_for_expression (struct ui_file *stream, int depth,
334 minimal_symbol *msym);
335 extern void dump_for_expression (struct ui_file *stream, int depth,
337 extern void dump_for_expression (struct ui_file *stream, int depth,
338 type_instance_flags flags);
339 extern void dump_for_expression (struct ui_file *stream, int depth,
340 enum c_string_type_values flags);
341 extern void dump_for_expression (struct ui_file *stream, int depth,
342 enum range_flag flags);
343 extern void dump_for_expression (struct ui_file *stream, int depth,
345 extern void dump_for_expression (struct ui_file *stream, int depth,
346 const std::unique_ptr<ada_component> &comp);
350 dump_for_expression (struct ui_file *stream, int depth,
351 const std::vector<T> &vals)
353 fprintf_filtered (stream, _("%*sVector:\n"), depth, "");
354 for (auto &item : vals)
355 dump_for_expression (stream, depth + 1, item);
358 template<typename X, typename Y>
360 dump_for_expression (struct ui_file *stream, int depth,
361 const std::pair<X, Y> &vals)
363 dump_for_expression (stream, depth, vals.first);
364 dump_for_expression (stream, depth, vals.second);
367 /* Base class for most concrete operations. This class holds data,
368 specified via template parameters, and supplies generic
369 implementations of the 'dump' and 'uses_objfile' methods. */
370 template<typename... Arg>
371 class tuple_holding_operation : public operation
375 explicit tuple_holding_operation (Arg... args)
376 : m_storage (std::forward<Arg> (args)...)
380 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation);
382 bool uses_objfile (struct objfile *objfile) const override
384 return do_check_objfile<0, Arg...> (objfile, m_storage);
387 void dump (struct ui_file *stream, int depth) const override
389 dump_for_expression (stream, depth, opcode ());
390 do_dump<0, Arg...> (stream, depth + 1, m_storage);
395 /* Storage for the data. */
396 std::tuple<Arg...> m_storage;
400 /* do_dump does the work of dumping the data. */
401 template<int I, typename... T>
402 typename std::enable_if<I == sizeof... (T), void>::type
403 do_dump (struct ui_file *stream, int depth, const std::tuple<T...> &value)
408 template<int I, typename... T>
409 typename std::enable_if<I < sizeof... (T), void>::type
410 do_dump (struct ui_file *stream, int depth, const std::tuple<T...> &value)
413 dump_for_expression (stream, depth, std::get<I> (value));
414 do_dump<I + 1, T...> (stream, depth, value);
417 /* do_check_objfile does the work of checking whether this object
418 refers to OBJFILE. */
419 template<int I, typename... T>
420 typename std::enable_if<I == sizeof... (T), bool>::type
421 do_check_objfile (struct objfile *objfile, const std::tuple<T...> &value)
427 template<int I, typename... T>
428 typename std::enable_if<I < sizeof... (T), bool>::type
429 do_check_objfile (struct objfile *objfile, const std::tuple<T...> &value)
432 if (check_objfile (std::get<I> (value), objfile))
434 return do_check_objfile<I + 1, T...> (objfile, value);
438 /* The check_constant overloads are used to decide whether a given
439 concrete operation is a constant. This is done by checking the
443 check_constant (const operation_up &item)
445 return item->constant_p ();
449 check_constant (struct minimal_symbol *msym)
455 check_constant (struct type *type)
461 check_constant (const struct block *block)
467 check_constant (const std::string &str)
473 check_constant (struct objfile *objfile)
479 check_constant (ULONGEST cst)
485 check_constant (struct symbol *sym)
487 enum address_class sc = SYMBOL_CLASS (sym);
488 return (sc == LOC_BLOCK
490 || sc == LOC_CONST_BYTES
496 check_constant (const std::vector<T> &collection)
498 for (const auto &item : collection)
499 if (!check_constant (item))
504 template<typename S, typename T>
506 check_constant (const std::pair<S, T> &item)
508 return check_constant (item.first) && check_constant (item.second);
511 /* Base class for concrete operations. This class supplies an
512 implementation of 'constant_p' that works by checking the
514 template<typename... Arg>
515 class maybe_constant_operation
516 : public tuple_holding_operation<Arg...>
520 using tuple_holding_operation<Arg...>::tuple_holding_operation;
522 bool constant_p () const override
524 return do_check_constant<0, Arg...> (this->m_storage);
529 template<int I, typename... T>
530 typename std::enable_if<I == sizeof... (T), bool>::type
531 do_check_constant (const std::tuple<T...> &value) const
536 template<int I, typename... T>
537 typename std::enable_if<I < sizeof... (T), bool>::type
538 do_check_constant (const std::tuple<T...> &value) const
540 if (!check_constant (std::get<I> (value)))
542 return do_check_constant<I + 1, T...> (value);
546 /* A floating-point constant. The constant is encoded in the target
549 typedef std::array<gdb_byte, 16> float_data;
551 /* An operation that holds a floating-point constant of a given
554 This does not need the facilities provided by
555 tuple_holding_operation, so it does not use it. */
556 class float_const_operation
561 float_const_operation (struct type *type, float_data data)
567 value *evaluate (struct type *expect_type,
568 struct expression *exp,
569 enum noside noside) override
571 return value_from_contents (m_type, m_data.data ());
574 enum exp_opcode opcode () const override
577 bool constant_p () const override
580 void dump (struct ui_file *stream, int depth) const override;
588 class scope_operation
589 : public maybe_constant_operation<struct type *, std::string>
593 using maybe_constant_operation::maybe_constant_operation;
595 value *evaluate (struct type *expect_type,
596 struct expression *exp,
597 enum noside noside) override
599 return eval_op_scope (expect_type, exp, noside,
600 std::get<0> (m_storage),
601 std::get<1> (m_storage).c_str ());
604 value *evaluate_for_address (struct expression *exp,
605 enum noside noside) override;
607 value *evaluate_funcall (struct type *expect_type,
608 struct expression *exp,
610 const std::vector<operation_up> &args) override;
612 enum exp_opcode opcode () const override
617 void do_generate_ax (struct expression *exp,
618 struct agent_expr *ax,
619 struct axs_value *value,
620 struct type *cast_type)
624 /* Compute the value of a variable. */
625 class var_value_operation
626 : public maybe_constant_operation<symbol *, const block *>
630 using maybe_constant_operation::maybe_constant_operation;
632 value *evaluate (struct type *expect_type,
633 struct expression *exp,
634 enum noside noside) override;
636 value *evaluate_with_coercion (struct expression *exp,
637 enum noside noside) override;
639 value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
642 value *evaluate_for_cast (struct type *expect_type,
643 struct expression *exp,
644 enum noside noside) override;
646 value *evaluate_for_address (struct expression *exp, enum noside noside)
649 value *evaluate_funcall (struct type *expect_type,
650 struct expression *exp,
652 const std::vector<operation_up> &args) override;
654 enum exp_opcode opcode () const override
655 { return OP_VAR_VALUE; }
659 void do_generate_ax (struct expression *exp,
660 struct agent_expr *ax,
661 struct axs_value *value,
662 struct type *cast_type)
666 class long_const_operation
667 : public tuple_holding_operation<struct type *, LONGEST>
671 using tuple_holding_operation::tuple_holding_operation;
673 value *evaluate (struct type *expect_type,
674 struct expression *exp,
675 enum noside noside) override
677 return value_from_longest (std::get<0> (m_storage),
678 std::get<1> (m_storage));
681 enum exp_opcode opcode () const override
684 bool constant_p () const override
689 void do_generate_ax (struct expression *exp,
690 struct agent_expr *ax,
691 struct axs_value *value,
692 struct type *cast_type)
696 class var_msym_value_operation
697 : public maybe_constant_operation<minimal_symbol *, struct objfile *>
701 using maybe_constant_operation::maybe_constant_operation;
703 value *evaluate (struct type *expect_type,
704 struct expression *exp,
705 enum noside noside) override
707 return eval_op_var_msym_value (expect_type, exp, noside, m_outermost,
708 std::get<0> (m_storage),
709 std::get<1> (m_storage));
712 value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
715 value *evaluate_for_address (struct expression *exp, enum noside noside)
718 value *evaluate_for_cast (struct type *expect_type,
719 struct expression *exp,
720 enum noside noside) override;
722 value *evaluate_funcall (struct type *expect_type,
723 struct expression *exp,
725 const std::vector<operation_up> &args) override
727 const char *name = std::get<0> (m_storage)->print_name ();
728 return operation::evaluate_funcall (expect_type, exp, noside, name, args);
731 enum exp_opcode opcode () const override
732 { return OP_VAR_MSYM_VALUE; }
734 void set_outermost () override
741 /* True if this is the outermost operation in the expression. */
742 bool m_outermost = false;
744 void do_generate_ax (struct expression *exp,
745 struct agent_expr *ax,
746 struct axs_value *value,
747 struct type *cast_type)
751 class var_entry_value_operation
752 : public tuple_holding_operation<symbol *>
756 using tuple_holding_operation::tuple_holding_operation;
758 value *evaluate (struct type *expect_type,
759 struct expression *exp,
760 enum noside noside) override
762 return eval_op_var_entry_value (expect_type, exp, noside,
763 std::get<0> (m_storage));
766 enum exp_opcode opcode () const override
767 { return OP_VAR_ENTRY_VALUE; }
770 class func_static_var_operation
771 : public maybe_constant_operation<operation_up, std::string>
775 using maybe_constant_operation::maybe_constant_operation;
777 value *evaluate (struct type *expect_type,
778 struct expression *exp,
779 enum noside noside) override
781 value *func = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
782 return eval_op_func_static_var (expect_type, exp, noside, func,
783 std::get<1> (m_storage).c_str ());
786 enum exp_opcode opcode () const override
787 { return OP_FUNC_STATIC_VAR; }
791 : public tuple_holding_operation<int>
795 using tuple_holding_operation::tuple_holding_operation;
797 value *evaluate (struct type *expect_type,
798 struct expression *exp,
799 enum noside noside) override
801 return access_value_history (std::get<0> (m_storage));
804 enum exp_opcode opcode () const override
808 class register_operation
809 : public tuple_holding_operation<std::string>
813 using tuple_holding_operation::tuple_holding_operation;
815 value *evaluate (struct type *expect_type,
816 struct expression *exp,
817 enum noside noside) override
819 return eval_op_register (expect_type, exp, noside,
820 std::get<0> (m_storage).c_str ());
823 enum exp_opcode opcode () const override
824 { return OP_REGISTER; }
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 using equal_operation = comparison_operation<BINOP_EQUAL, eval_op_equal>;
1333 using notequal_operation
1334 = comparison_operation<BINOP_NOTEQUAL, eval_op_notequal>;
1335 using less_operation = comparison_operation<BINOP_LESS, eval_op_less>;
1336 using gtr_operation = comparison_operation<BINOP_GTR, eval_op_gtr>;
1337 using geq_operation = comparison_operation<BINOP_GEQ, eval_op_geq>;
1338 using leq_operation = comparison_operation<BINOP_LEQ, eval_op_leq>;
1340 /* Implement the GDB '@' repeat operator. */
1341 class repeat_operation
1342 : public binop_operation<BINOP_REPEAT, eval_op_repeat>
1344 using binop_operation<BINOP_REPEAT, eval_op_repeat>::binop_operation;
1348 void do_generate_ax (struct expression *exp,
1349 struct agent_expr *ax,
1350 struct axs_value *value,
1351 struct type *cast_type)
1355 /* C-style comma operator. */
1356 class comma_operation
1357 : public maybe_constant_operation<operation_up, operation_up>
1361 using maybe_constant_operation::maybe_constant_operation;
1363 value *evaluate (struct type *expect_type,
1364 struct expression *exp,
1365 enum noside noside) override
1367 /* The left-hand-side is only evaluated for side effects, so don't
1368 bother in other modes. */
1369 if (noside == EVAL_NORMAL)
1370 std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1371 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1374 enum exp_opcode opcode () const override
1375 { return BINOP_COMMA; }
1379 void do_generate_ax (struct expression *exp,
1380 struct agent_expr *ax,
1381 struct axs_value *value,
1382 struct type *cast_type)
1386 typedef struct value *unary_ftype (struct type *expect_type,
1387 struct expression *exp,
1388 enum noside noside, enum exp_opcode op,
1389 struct value *arg1);
1391 /* Base class for unary operations. */
1392 template<enum exp_opcode OP, unary_ftype FUNC>
1393 class unop_operation
1394 : public maybe_constant_operation<operation_up>
1398 using maybe_constant_operation::maybe_constant_operation;
1400 value *evaluate (struct type *expect_type,
1401 struct expression *exp,
1402 enum noside noside) override
1404 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1405 return FUNC (expect_type, exp, noside, OP, val);
1408 enum exp_opcode opcode () const override
1412 /* Unary operations that can also be turned into agent expressions in
1414 template<enum exp_opcode OP, unary_ftype FUNC>
1415 class usual_ax_unop_operation
1416 : public unop_operation<OP, FUNC>
1418 using unop_operation<OP, FUNC>::unop_operation;
1422 void do_generate_ax (struct expression *exp,
1423 struct agent_expr *ax,
1424 struct axs_value *value,
1425 struct type *cast_type)
1428 gen_expr_unop (exp, OP,
1429 std::get<0> (this->m_storage).get (),
1434 using unary_plus_operation = usual_ax_unop_operation<UNOP_PLUS, eval_op_plus>;
1435 using unary_neg_operation = usual_ax_unop_operation<UNOP_NEG, eval_op_neg>;
1436 using unary_complement_operation
1437 = usual_ax_unop_operation<UNOP_COMPLEMENT, eval_op_complement>;
1438 using unary_logical_not_operation
1439 = usual_ax_unop_operation<UNOP_LOGICAL_NOT, eval_op_lognot>;
1441 /* Handle pre- and post- increment and -decrement. */
1442 template<enum exp_opcode OP, unary_ftype FUNC>
1443 class unop_incr_operation
1444 : public tuple_holding_operation<operation_up>
1448 using tuple_holding_operation::tuple_holding_operation;
1450 value *evaluate (struct type *expect_type,
1451 struct expression *exp,
1452 enum noside noside) override
1454 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1455 return FUNC (expect_type, exp, noside, OP, val);
1458 enum exp_opcode opcode () const override
1462 using preinc_operation
1463 = unop_incr_operation<UNOP_PREINCREMENT, eval_op_preinc>;
1464 using predec_operation
1465 = unop_incr_operation<UNOP_PREDECREMENT, eval_op_predec>;
1466 using postinc_operation
1467 = unop_incr_operation<UNOP_POSTINCREMENT, eval_op_postinc>;
1468 using postdec_operation
1469 = unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>;
1471 /* Base class for implementations of UNOP_IND. */
1472 class unop_ind_base_operation
1473 : public tuple_holding_operation<operation_up>
1477 using tuple_holding_operation::tuple_holding_operation;
1479 value *evaluate (struct type *expect_type,
1480 struct expression *exp,
1481 enum noside noside) override
1483 if (expect_type != nullptr && expect_type->code () == TYPE_CODE_PTR)
1484 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
1485 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1486 return eval_op_ind (expect_type, exp, noside, val);
1489 value *evaluate_for_address (struct expression *exp,
1490 enum noside noside) override;
1492 value *evaluate_for_sizeof (struct expression *exp,
1493 enum noside noside) override;
1495 enum exp_opcode opcode () const override
1496 { return UNOP_IND; }
1499 /* Ordinary UNOP_IND implementation. */
1500 class unop_ind_operation
1501 : public unop_ind_base_operation
1505 using unop_ind_base_operation::unop_ind_base_operation;
1509 void do_generate_ax (struct expression *exp,
1510 struct agent_expr *ax,
1511 struct axs_value *value,
1512 struct type *cast_type)
1515 gen_expr_unop (exp, UNOP_IND,
1516 std::get<0> (this->m_storage).get (),
1521 /* Implement OP_TYPE. */
1522 class type_operation
1523 : public tuple_holding_operation<struct type *>
1527 using tuple_holding_operation::tuple_holding_operation;
1529 value *evaluate (struct type *expect_type,
1530 struct expression *exp,
1531 enum noside noside) override
1533 return eval_op_type (expect_type, exp, noside, std::get<0> (m_storage));
1536 enum exp_opcode opcode () const override
1539 bool constant_p () const override
1543 /* Implement the "typeof" operation. */
1544 class typeof_operation
1545 : public maybe_constant_operation<operation_up>
1549 using maybe_constant_operation::maybe_constant_operation;
1551 value *evaluate (struct type *expect_type,
1552 struct expression *exp,
1553 enum noside noside) override
1555 if (noside == EVAL_SKIP)
1556 return eval_skip_value (exp);
1557 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1558 return std::get<0> (m_storage)->evaluate (nullptr, exp,
1559 EVAL_AVOID_SIDE_EFFECTS);
1561 error (_("Attempt to use a type as an expression"));
1564 enum exp_opcode opcode () const override
1565 { return OP_TYPEOF; }
1568 /* Implement 'decltype'. */
1569 class decltype_operation
1570 : public maybe_constant_operation<operation_up>
1574 using maybe_constant_operation::maybe_constant_operation;
1576 value *evaluate (struct type *expect_type,
1577 struct expression *exp,
1578 enum noside noside) override
1580 if (noside == EVAL_SKIP)
1581 return eval_skip_value (exp);
1582 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1585 = std::get<0> (m_storage)->evaluate (nullptr, exp,
1586 EVAL_AVOID_SIDE_EFFECTS);
1587 enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
1588 if (sub_op == BINOP_SUBSCRIPT
1589 || sub_op == STRUCTOP_MEMBER
1590 || sub_op == STRUCTOP_MPTR
1591 || sub_op == UNOP_IND
1592 || sub_op == STRUCTOP_STRUCT
1593 || sub_op == STRUCTOP_PTR
1594 || sub_op == OP_SCOPE)
1596 struct type *type = value_type (result);
1598 if (!TYPE_IS_REFERENCE (type))
1600 type = lookup_lvalue_reference_type (type);
1601 result = allocate_value (type);
1608 error (_("Attempt to use a type as an expression"));
1611 enum exp_opcode opcode () const override
1612 { return OP_DECLTYPE; }
1615 /* Implement 'typeid'. */
1616 class typeid_operation
1617 : public tuple_holding_operation<operation_up>
1621 using tuple_holding_operation::tuple_holding_operation;
1623 value *evaluate (struct type *expect_type,
1624 struct expression *exp,
1625 enum noside noside) override
1627 enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
1628 enum noside sub_noside
1629 = ((sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
1630 ? EVAL_AVOID_SIDE_EFFECTS
1633 value *result = std::get<0> (m_storage)->evaluate (nullptr, exp,
1635 if (noside != EVAL_NORMAL)
1636 return allocate_value (cplus_typeid_type (exp->gdbarch));
1637 return cplus_typeid (result);
1640 enum exp_opcode opcode () const override
1641 { return OP_TYPEID; }
1644 /* Implement the address-of operation. */
1645 class unop_addr_operation
1646 : public maybe_constant_operation<operation_up>
1650 using maybe_constant_operation::maybe_constant_operation;
1652 value *evaluate (struct type *expect_type,
1653 struct expression *exp,
1654 enum noside noside) override
1656 /* C++: check for and handle pointer to members. */
1657 if (noside == EVAL_SKIP)
1658 return eval_skip_value (exp);
1660 return std::get<0> (m_storage)->evaluate_for_address (exp, noside);
1663 enum exp_opcode opcode () const override
1664 { return UNOP_ADDR; }
1666 /* Return the subexpression. */
1667 const operation_up &get_expression () const
1669 return std::get<0> (m_storage);
1674 void do_generate_ax (struct expression *exp,
1675 struct agent_expr *ax,
1676 struct axs_value *value,
1677 struct type *cast_type)
1680 gen_expr_unop (exp, UNOP_ADDR,
1681 std::get<0> (this->m_storage).get (),
1686 /* Implement 'sizeof'. */
1687 class unop_sizeof_operation
1688 : public maybe_constant_operation<operation_up>
1692 using maybe_constant_operation::maybe_constant_operation;
1694 value *evaluate (struct type *expect_type,
1695 struct expression *exp,
1696 enum noside noside) override
1698 if (noside == EVAL_SKIP)
1699 return eval_skip_value (exp);
1700 return std::get<0> (m_storage)->evaluate_for_sizeof (exp, noside);
1703 enum exp_opcode opcode () const override
1704 { return UNOP_SIZEOF; }
1708 void do_generate_ax (struct expression *exp,
1709 struct agent_expr *ax,
1710 struct axs_value *value,
1711 struct type *cast_type)
1715 /* Implement 'alignof'. */
1716 class unop_alignof_operation
1717 : public maybe_constant_operation<operation_up>
1721 using maybe_constant_operation::maybe_constant_operation;
1723 value *evaluate (struct type *expect_type,
1724 struct expression *exp,
1725 enum noside noside) override
1727 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1728 EVAL_AVOID_SIDE_EFFECTS);
1729 return eval_op_alignof (expect_type, exp, noside, val);
1732 enum exp_opcode opcode () const override
1733 { return UNOP_ALIGNOF; }
1736 /* Implement UNOP_MEMVAL. */
1737 class unop_memval_operation
1738 : public tuple_holding_operation<operation_up, struct type *>
1742 using tuple_holding_operation::tuple_holding_operation;
1744 value *evaluate (struct type *expect_type,
1745 struct expression *exp,
1746 enum noside noside) override
1748 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1749 return eval_op_memval (expect_type, exp, noside, val,
1750 std::get<1> (m_storage));
1753 value *evaluate_for_sizeof (struct expression *exp,
1754 enum noside noside) override;
1756 value *evaluate_for_address (struct expression *exp,
1757 enum noside noside) override;
1759 enum exp_opcode opcode () const override
1760 { return UNOP_MEMVAL; }
1764 void do_generate_ax (struct expression *exp,
1765 struct agent_expr *ax,
1766 struct axs_value *value,
1767 struct type *cast_type)
1771 /* Implement UNOP_MEMVAL_TYPE. */
1772 class unop_memval_type_operation
1773 : public tuple_holding_operation<operation_up, operation_up>
1777 using tuple_holding_operation::tuple_holding_operation;
1779 value *evaluate (struct type *expect_type,
1780 struct expression *exp,
1781 enum noside noside) override
1784 = std::get<0> (m_storage)->evaluate (expect_type, exp,
1785 EVAL_AVOID_SIDE_EFFECTS);
1786 struct type *type = value_type (typeval);
1787 value *val = std::get<1> (m_storage)->evaluate (expect_type, exp, noside);
1788 return eval_op_memval (expect_type, exp, noside, val, type);
1791 value *evaluate_for_sizeof (struct expression *exp,
1792 enum noside noside) override;
1794 value *evaluate_for_address (struct expression *exp,
1795 enum noside noside) override;
1797 enum exp_opcode opcode () const override
1798 { return UNOP_MEMVAL_TYPE; }
1802 void do_generate_ax (struct expression *exp,
1803 struct agent_expr *ax,
1804 struct axs_value *value,
1805 struct type *cast_type)
1809 /* Implement the 'this' expression. */
1810 class op_this_operation
1811 : public tuple_holding_operation<>
1815 using tuple_holding_operation::tuple_holding_operation;
1817 value *evaluate (struct type *expect_type,
1818 struct expression *exp,
1819 enum noside noside) override
1821 return value_of_this (exp->language_defn);
1824 enum exp_opcode opcode () const override
1829 void do_generate_ax (struct expression *exp,
1830 struct agent_expr *ax,
1831 struct axs_value *value,
1832 struct type *cast_type)
1836 /* Implement the "type instance" operation. */
1837 class type_instance_operation
1838 : public tuple_holding_operation<type_instance_flags, std::vector<type *>,
1843 using tuple_holding_operation::tuple_holding_operation;
1845 value *evaluate (struct type *expect_type,
1846 struct expression *exp,
1847 enum noside noside) override;
1849 enum exp_opcode opcode () const override
1850 { return TYPE_INSTANCE; }
1853 /* The assignment operator. */
1854 class assign_operation
1855 : public tuple_holding_operation<operation_up, operation_up>
1859 using tuple_holding_operation::tuple_holding_operation;
1861 value *evaluate (struct type *expect_type,
1862 struct expression *exp,
1863 enum noside noside) override
1865 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1866 /* Special-case assignments where the left-hand-side is a
1867 convenience variable -- in these, don't bother setting an
1868 expected type. This avoids a weird case where re-assigning a
1869 string or array to an internal variable could error with "Too
1870 many array elements". */
1871 struct type *xtype = (VALUE_LVAL (lhs) == lval_internalvar
1873 : value_type (lhs));
1874 value *rhs = std::get<1> (m_storage)->evaluate (xtype, exp, noside);
1876 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1878 if (binop_user_defined_p (BINOP_ASSIGN, lhs, rhs))
1879 return value_x_binop (lhs, rhs, BINOP_ASSIGN, OP_NULL, noside);
1881 return value_assign (lhs, rhs);
1884 enum exp_opcode opcode () const override
1885 { return BINOP_ASSIGN; }
1889 void do_generate_ax (struct expression *exp,
1890 struct agent_expr *ax,
1891 struct axs_value *value,
1892 struct type *cast_type)
1896 /* Assignment with modification, like "+=". */
1897 class assign_modify_operation
1898 : public tuple_holding_operation<exp_opcode, operation_up, operation_up>
1902 using tuple_holding_operation::tuple_holding_operation;
1904 value *evaluate (struct type *expect_type,
1905 struct expression *exp,
1906 enum noside noside) override
1908 value *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1909 value *rhs = std::get<2> (m_storage)->evaluate (expect_type, exp, noside);
1910 return eval_binop_assign_modify (expect_type, exp, noside,
1911 std::get<0> (m_storage), lhs, rhs);
1914 enum exp_opcode opcode () const override
1915 { return BINOP_ASSIGN_MODIFY; }
1919 void do_generate_ax (struct expression *exp,
1920 struct agent_expr *ax,
1921 struct axs_value *value,
1922 struct type *cast_type)
1927 class unop_cast_operation
1928 : public maybe_constant_operation<operation_up, struct type *>
1932 using maybe_constant_operation::maybe_constant_operation;
1934 value *evaluate (struct type *expect_type,
1935 struct expression *exp,
1936 enum noside noside) override
1938 return std::get<0> (m_storage)->evaluate_for_cast (std::get<1> (m_storage),
1942 enum exp_opcode opcode () const override
1943 { return UNOP_CAST; }
1947 void do_generate_ax (struct expression *exp,
1948 struct agent_expr *ax,
1949 struct axs_value *value,
1950 struct type *cast_type)
1954 /* A cast, but the type comes from an expression, not a "struct
1956 class unop_cast_type_operation
1957 : public maybe_constant_operation<operation_up, operation_up>
1961 using maybe_constant_operation::maybe_constant_operation;
1963 value *evaluate (struct type *expect_type,
1964 struct expression *exp,
1965 enum noside noside) override
1967 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1968 EVAL_AVOID_SIDE_EFFECTS);
1969 return std::get<1> (m_storage)->evaluate_for_cast (value_type (val),
1973 enum exp_opcode opcode () const override
1974 { return UNOP_CAST_TYPE; }
1978 void do_generate_ax (struct expression *exp,
1979 struct agent_expr *ax,
1980 struct axs_value *value,
1981 struct type *cast_type)
1985 typedef value *cxx_cast_ftype (struct type *, value *);
1987 /* This implements dynamic_cast and reinterpret_cast. static_cast and
1988 const_cast are handled by the ordinary case operations. */
1989 template<exp_opcode OP, cxx_cast_ftype FUNC>
1990 class cxx_cast_operation
1991 : public maybe_constant_operation<operation_up, operation_up>
1995 using maybe_constant_operation::maybe_constant_operation;
1997 value *evaluate (struct type *expect_type,
1998 struct expression *exp,
1999 enum noside noside) override
2001 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
2002 EVAL_AVOID_SIDE_EFFECTS);
2003 struct type *type = value_type (val);
2004 value *rhs = std::get<1> (m_storage)->evaluate (type, exp, noside);
2005 if (noside == EVAL_SKIP)
2006 return eval_skip_value (exp);
2007 return FUNC (type, rhs);
2010 enum exp_opcode opcode () const override
2014 using dynamic_cast_operation = cxx_cast_operation<UNOP_DYNAMIC_CAST,
2015 value_dynamic_cast>;
2016 using reinterpret_cast_operation = cxx_cast_operation<UNOP_REINTERPRET_CAST,
2017 value_reinterpret_cast>;
2019 /* Multi-dimensional subscripting. */
2020 class multi_subscript_operation
2021 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
2025 using tuple_holding_operation::tuple_holding_operation;
2027 value *evaluate (struct type *expect_type,
2028 struct expression *exp,
2029 enum noside noside) override;
2031 enum exp_opcode opcode () const override
2032 { return MULTI_SUBSCRIPT; }
2035 /* The "&&" operator. */
2036 class logical_and_operation
2037 : public maybe_constant_operation<operation_up, operation_up>
2041 using maybe_constant_operation::maybe_constant_operation;
2043 value *evaluate (struct type *expect_type,
2044 struct expression *exp,
2045 enum noside noside) override;
2047 enum exp_opcode opcode () const override
2048 { return BINOP_LOGICAL_AND; }
2052 void do_generate_ax (struct expression *exp,
2053 struct agent_expr *ax,
2054 struct axs_value *value,
2055 struct type *cast_type)
2059 /* The "||" operator. */
2060 class logical_or_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_OR; }
2076 void do_generate_ax (struct expression *exp,
2077 struct agent_expr *ax,
2078 struct axs_value *value,
2079 struct type *cast_type)
2083 /* This class implements ADL (aka Koenig) function calls for C++. It
2084 holds the name of the function to call, the block in which the
2085 lookup should be done, and a vector of arguments. */
2086 class adl_func_operation
2087 : public tuple_holding_operation<std::string, const block *,
2088 std::vector<operation_up>>
2092 using tuple_holding_operation::tuple_holding_operation;
2094 value *evaluate (struct type *expect_type,
2095 struct expression *exp,
2096 enum noside noside) override;
2098 enum exp_opcode opcode () const override
2099 { return OP_ADL_FUNC; }
2102 /* The OP_ARRAY operation. */
2103 class array_operation
2104 : public tuple_holding_operation<int, int, std::vector<operation_up>>
2108 using tuple_holding_operation::tuple_holding_operation;
2110 value *evaluate (struct type *expect_type,
2111 struct expression *exp,
2112 enum noside noside) override;
2114 enum exp_opcode opcode () const override
2115 { return OP_ARRAY; }
2119 struct value *evaluate_struct_tuple (struct value *struct_val,
2120 struct expression *exp,
2121 enum noside noside, int nargs);
2124 /* A function call. This holds the callee operation and the
2126 class funcall_operation
2127 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
2131 using tuple_holding_operation::tuple_holding_operation;
2133 value *evaluate (struct type *expect_type,
2134 struct expression *exp,
2135 enum noside noside) override
2137 return std::get<0> (m_storage)->evaluate_funcall (expect_type, exp, noside,
2138 std::get<1> (m_storage));
2141 enum exp_opcode opcode () const override
2142 { return OP_FUNCALL; }
2145 } /* namespace expr */
2147 #endif /* EXPOP_H */