arm, objdump: print obsolote warning when 26-bit set in instructions
[binutils-gdb.git] / gdb / expop.h
blobaf031f53133244e773d719983efe3a2088d0545a
1 /* Definitions for expressions in GDB
3 Copyright (C) 2020-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef EXPOP_H
21 #define EXPOP_H
23 #include "c-lang.h"
24 #include "cp-abi.h"
25 #include "expression.h"
26 #include "language.h"
27 #include "objfiles.h"
28 #include "gdbsupport/traits.h"
29 #include "gdbsupport/enum-flags.h"
31 struct agent_expr;
32 struct axs_value;
34 extern void gen_expr_binop (struct expression *exp,
35 enum exp_opcode op,
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,
39 enum exp_opcode op,
40 expr::operation *lhs,
41 const char *name,
42 struct agent_expr *ax, struct axs_value *value);
43 extern void gen_expr_unop (struct expression *exp,
44 enum exp_opcode op,
45 expr::operation *lhs,
46 struct agent_expr *ax, struct axs_value *value);
48 extern struct value *eval_op_scope (struct type *expect_type,
49 struct expression *exp,
50 enum noside noside,
51 struct type *type, const char *string);
52 extern struct value *eval_op_var_msym_value (struct type *expect_type,
53 struct expression *exp,
54 enum noside noside,
55 bool outermost_p,
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,
62 enum noside noside,
63 value *func, const char *var);
64 extern struct value *eval_op_register (struct type *expect_type,
65 struct expression *exp,
66 enum noside noside, const char *name);
67 extern struct value *eval_op_structop_struct (struct type *expect_type,
68 struct expression *exp,
69 enum noside noside,
70 struct value *arg1,
71 const char *string);
72 extern struct value *eval_op_structop_ptr (struct type *expect_type,
73 struct expression *exp,
74 enum noside noside,
75 struct value *arg1,
76 const char *string);
77 extern struct value *eval_op_member (struct type *expect_type,
78 struct expression *exp,
79 enum noside noside,
80 struct value *arg1, struct value *arg2);
81 extern struct value *eval_op_add (struct type *expect_type,
82 struct expression *exp,
83 enum noside noside,
84 struct value *arg1, struct value *arg2);
85 extern struct value *eval_op_sub (struct type *expect_type,
86 struct expression *exp,
87 enum noside noside,
88 struct value *arg1, struct value *arg2);
89 extern struct value *eval_op_binary (struct type *expect_type,
90 struct expression *exp,
91 enum noside noside, enum exp_opcode op,
92 struct value *arg1, struct value *arg2);
93 extern struct value *eval_op_subscript (struct type *expect_type,
94 struct expression *exp,
95 enum noside noside, enum exp_opcode op,
96 struct value *arg1,
97 struct value *arg2);
98 extern struct value *eval_op_equal (struct type *expect_type,
99 struct expression *exp,
100 enum noside noside, enum exp_opcode op,
101 struct value *arg1,
102 struct value *arg2);
103 extern struct value *eval_op_notequal (struct type *expect_type,
104 struct expression *exp,
105 enum noside noside, enum exp_opcode op,
106 struct value *arg1,
107 struct value *arg2);
108 extern struct value *eval_op_less (struct type *expect_type,
109 struct expression *exp,
110 enum noside noside, enum exp_opcode op,
111 struct value *arg1,
112 struct value *arg2);
113 extern struct value *eval_op_gtr (struct type *expect_type,
114 struct expression *exp,
115 enum noside noside, enum exp_opcode op,
116 struct value *arg1,
117 struct value *arg2);
118 extern struct value *eval_op_geq (struct type *expect_type,
119 struct expression *exp,
120 enum noside noside, enum exp_opcode op,
121 struct value *arg1,
122 struct value *arg2);
123 extern struct value *eval_op_leq (struct type *expect_type,
124 struct expression *exp,
125 enum noside noside, enum exp_opcode op,
126 struct value *arg1,
127 struct value *arg2);
128 extern struct value *eval_op_repeat (struct type *expect_type,
129 struct expression *exp,
130 enum noside noside, enum exp_opcode op,
131 struct value *arg1,
132 struct value *arg2);
133 extern struct value *eval_op_plus (struct type *expect_type,
134 struct expression *exp,
135 enum noside noside, enum exp_opcode op,
136 struct value *arg1);
137 extern struct value *eval_op_neg (struct type *expect_type,
138 struct expression *exp,
139 enum noside noside, enum exp_opcode op,
140 struct value *arg1);
141 extern struct value *eval_op_complement (struct type *expect_type,
142 struct expression *exp,
143 enum noside noside,
144 enum exp_opcode op,
145 struct value *arg1);
146 extern struct value *eval_op_lognot (struct type *expect_type,
147 struct expression *exp,
148 enum noside noside,
149 enum exp_opcode op,
150 struct value *arg1);
151 extern struct value *eval_op_preinc (struct type *expect_type,
152 struct expression *exp,
153 enum noside noside,
154 enum exp_opcode op,
155 struct value *arg1);
156 extern struct value *eval_op_predec (struct type *expect_type,
157 struct expression *exp,
158 enum noside noside,
159 enum exp_opcode op,
160 struct value *arg1);
161 extern struct value *eval_op_postinc (struct type *expect_type,
162 struct expression *exp,
163 enum noside noside,
164 enum exp_opcode op,
165 struct value *arg1);
166 extern struct value *eval_op_postdec (struct type *expect_type,
167 struct expression *exp,
168 enum noside noside,
169 enum exp_opcode op,
170 struct value *arg1);
171 extern struct value *eval_op_ind (struct type *expect_type,
172 struct expression *exp,
173 enum noside noside,
174 struct value *arg1);
175 extern struct value *eval_op_alignof (struct type *expect_type,
176 struct expression *exp,
177 enum noside noside,
178 struct value *arg1);
179 extern struct value *eval_op_memval (struct type *expect_type,
180 struct expression *exp,
181 enum noside noside,
182 struct value *arg1, struct type *type);
183 extern struct value *eval_binop_assign_modify (struct type *expect_type,
184 struct expression *exp,
185 enum noside noside,
186 enum exp_opcode op,
187 struct value *arg1,
188 struct value *arg2);
190 namespace expr
193 class ada_component;
195 /* The check_objfile overloads are used to check whether a particular
196 component of some operation references an objfile. The passed-in
197 objfile will never be a debug objfile. */
199 /* See if EXP_OBJFILE matches OBJFILE. */
200 static inline bool
201 check_objfile (struct objfile *exp_objfile, struct objfile *objfile)
203 if (exp_objfile->separate_debug_objfile_backlink)
204 exp_objfile = exp_objfile->separate_debug_objfile_backlink;
205 return exp_objfile == objfile;
208 static inline bool
209 check_objfile (struct type *type, struct objfile *objfile)
211 struct objfile *ty_objfile = type->objfile_owner ();
212 if (ty_objfile != nullptr)
213 return check_objfile (ty_objfile, objfile);
214 return false;
217 static inline bool
218 check_objfile (struct symbol *sym, struct objfile *objfile)
220 return check_objfile (sym->objfile (), objfile);
223 extern bool check_objfile (const struct block *block,
224 struct objfile *objfile);
226 static inline bool
227 check_objfile (const block_symbol &sym, struct objfile *objfile)
229 return (check_objfile (sym.symbol, objfile)
230 || check_objfile (sym.block, objfile));
233 static inline bool
234 check_objfile (bound_minimal_symbol minsym, struct objfile *objfile)
236 return check_objfile (minsym.objfile, objfile);
239 static inline bool
240 check_objfile (internalvar *ivar, struct objfile *objfile)
242 return false;
245 static inline bool
246 check_objfile (const std::string &str, struct objfile *objfile)
248 return false;
251 static inline bool
252 check_objfile (const operation_up &op, struct objfile *objfile)
254 return op->uses_objfile (objfile);
257 static inline bool
258 check_objfile (enum exp_opcode val, struct objfile *objfile)
260 return false;
263 static inline bool
264 check_objfile (ULONGEST val, struct objfile *objfile)
266 return false;
269 static inline bool
270 check_objfile (const gdb_mpz &val, struct objfile *objfile)
272 return false;
275 template<typename T>
276 static inline bool
277 check_objfile (enum_flags<T> val, struct objfile *objfile)
279 return false;
282 template<typename T>
283 static inline bool
284 check_objfile (const std::vector<T> &collection, struct objfile *objfile)
286 for (const auto &item : collection)
288 if (check_objfile (item, objfile))
289 return true;
291 return false;
294 template<typename S, typename T>
295 static inline bool
296 check_objfile (const std::pair<S, T> &item, struct objfile *objfile)
298 return (check_objfile (item.first, objfile)
299 || check_objfile (item.second, objfile));
302 extern bool check_objfile (const std::unique_ptr<ada_component> &comp,
303 struct objfile *objfile);
305 static inline void
306 dump_for_expression (struct ui_file *stream, int depth,
307 const operation_up &op)
309 if (op == nullptr)
310 gdb_printf (stream, _("%*snullptr\n"), depth, "");
311 else
312 op->dump (stream, depth);
315 extern void dump_for_expression (struct ui_file *stream, int depth,
316 enum exp_opcode op);
317 extern void dump_for_expression (struct ui_file *stream, int depth,
318 const std::string &str);
319 extern void dump_for_expression (struct ui_file *stream, int depth,
320 struct type *type);
321 extern void dump_for_expression (struct ui_file *stream, int depth,
322 CORE_ADDR addr);
323 extern void dump_for_expression (struct ui_file *stream, int depth,
324 const gdb_mpz &addr);
325 extern void dump_for_expression (struct ui_file *stream, int depth,
326 internalvar *ivar);
327 extern void dump_for_expression (struct ui_file *stream, int depth,
328 symbol *sym);
329 extern void dump_for_expression (struct ui_file *stream, int depth,
330 const block_symbol &sym);
331 extern void dump_for_expression (struct ui_file *stream, int depth,
332 bound_minimal_symbol msym);
333 extern void dump_for_expression (struct ui_file *stream, int depth,
334 const block *bl);
335 extern void dump_for_expression (struct ui_file *stream, int depth,
336 type_instance_flags flags);
337 extern void dump_for_expression (struct ui_file *stream, int depth,
338 enum c_string_type_values flags);
339 extern void dump_for_expression (struct ui_file *stream, int depth,
340 enum range_flag flags);
341 extern void dump_for_expression (struct ui_file *stream, int depth,
342 const std::unique_ptr<ada_component> &comp);
344 template<typename T>
345 void
346 dump_for_expression (struct ui_file *stream, int depth,
347 const std::vector<T> &vals)
349 gdb_printf (stream, _("%*sVector:\n"), depth, "");
350 for (auto &item : vals)
351 dump_for_expression (stream, depth + 1, item);
354 template<typename X, typename Y>
355 void
356 dump_for_expression (struct ui_file *stream, int depth,
357 const std::pair<X, Y> &vals)
359 dump_for_expression (stream, depth, vals.first);
360 dump_for_expression (stream, depth, vals.second);
363 /* Base class for most concrete operations. This class holds data,
364 specified via template parameters, and supplies generic
365 implementations of the 'dump' and 'uses_objfile' methods. */
366 template<typename... Arg>
367 class tuple_holding_operation : public operation
369 public:
371 explicit tuple_holding_operation (Arg... args)
372 : m_storage (std::forward<Arg> (args)...)
376 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation);
378 bool uses_objfile (struct objfile *objfile) const override
380 return do_check_objfile<0, Arg...> (objfile, m_storage);
383 void dump (struct ui_file *stream, int depth) const override
385 dump_for_expression (stream, depth, opcode ());
386 do_dump<0, Arg...> (stream, depth + 1, m_storage);
389 protected:
391 /* Storage for the data. */
392 std::tuple<Arg...> m_storage;
394 private:
396 /* do_dump does the work of dumping the data. */
397 template<int I, typename... T>
398 typename std::enable_if<I == sizeof... (T), void>::type
399 do_dump (struct ui_file *stream, int depth, const std::tuple<T...> &value)
400 const
404 template<int I, typename... T>
405 typename std::enable_if<I < sizeof... (T), void>::type
406 do_dump (struct ui_file *stream, int depth, const std::tuple<T...> &value)
407 const
409 dump_for_expression (stream, depth, std::get<I> (value));
410 do_dump<I + 1, T...> (stream, depth, value);
413 /* do_check_objfile does the work of checking whether this object
414 refers to OBJFILE. */
415 template<int I, typename... T>
416 typename std::enable_if<I == sizeof... (T), bool>::type
417 do_check_objfile (struct objfile *objfile, const std::tuple<T...> &value)
418 const
420 return false;
423 template<int I, typename... T>
424 typename std::enable_if<I < sizeof... (T), bool>::type
425 do_check_objfile (struct objfile *objfile, const std::tuple<T...> &value)
426 const
428 if (check_objfile (std::get<I> (value), objfile))
429 return true;
430 return do_check_objfile<I + 1, T...> (objfile, value);
434 /* The check_constant overloads are used to decide whether a given
435 concrete operation is a constant. This is done by checking the
436 operands. */
438 static inline bool
439 check_constant (const operation_up &item)
441 return item->constant_p ();
444 static inline bool
445 check_constant (bound_minimal_symbol msym)
447 return false;
450 static inline bool
451 check_constant (struct type *type)
453 return true;
456 static inline bool
457 check_constant (const struct block *block)
459 return true;
462 static inline bool
463 check_constant (const std::string &str)
465 return true;
468 static inline bool
469 check_constant (ULONGEST cst)
471 return true;
474 static inline bool
475 check_constant (const gdb_mpz &cst)
477 return true;
480 static inline bool
481 check_constant (struct symbol *sym)
483 enum address_class sc = sym->aclass ();
484 return (sc == LOC_BLOCK
485 || sc == LOC_CONST
486 || sc == LOC_CONST_BYTES
487 || sc == LOC_LABEL);
490 static inline bool
491 check_constant (const block_symbol &sym)
493 /* We know the block is constant, so we only need to check the
494 symbol. */
495 return check_constant (sym.symbol);
498 template<typename T>
499 static inline bool
500 check_constant (const std::vector<T> &collection)
502 for (const auto &item : collection)
503 if (!check_constant (item))
504 return false;
505 return true;
508 template<typename S, typename T>
509 static inline bool
510 check_constant (const std::pair<S, T> &item)
512 return check_constant (item.first) && check_constant (item.second);
515 /* Base class for concrete operations. This class supplies an
516 implementation of 'constant_p' that works by checking the
517 operands. */
518 template<typename... Arg>
519 class maybe_constant_operation
520 : public tuple_holding_operation<Arg...>
522 public:
524 using tuple_holding_operation<Arg...>::tuple_holding_operation;
526 bool constant_p () const override
528 return do_check_constant<0, Arg...> (this->m_storage);
531 private:
533 template<int I, typename... T>
534 typename std::enable_if<I == sizeof... (T), bool>::type
535 do_check_constant (const std::tuple<T...> &value) const
537 return true;
540 template<int I, typename... T>
541 typename std::enable_if<I < sizeof... (T), bool>::type
542 do_check_constant (const std::tuple<T...> &value) const
544 if (!check_constant (std::get<I> (value)))
545 return false;
546 return do_check_constant<I + 1, T...> (value);
550 /* A floating-point constant. The constant is encoded in the target
551 format. */
553 typedef std::array<gdb_byte, 16> float_data;
555 /* An operation that holds a floating-point constant of a given
556 type.
558 This does not need the facilities provided by
559 tuple_holding_operation, so it does not use it. */
560 class float_const_operation
561 : public operation
563 public:
565 float_const_operation (struct type *type, float_data data)
566 : m_type (type),
567 m_data (data)
571 value *evaluate (struct type *expect_type,
572 struct expression *exp,
573 enum noside noside) override
575 return value_from_contents (m_type, m_data.data ());
578 enum exp_opcode opcode () const override
579 { return OP_FLOAT; }
581 bool constant_p () const override
582 { return true; }
584 void dump (struct ui_file *stream, int depth) const override;
586 private:
588 struct type *m_type;
589 float_data m_data;
592 class scope_operation
593 : public maybe_constant_operation<struct type *, std::string>
595 public:
597 using maybe_constant_operation::maybe_constant_operation;
599 value *evaluate (struct type *expect_type,
600 struct expression *exp,
601 enum noside noside) override
603 return eval_op_scope (expect_type, exp, noside,
604 std::get<0> (m_storage),
605 std::get<1> (m_storage).c_str ());
608 value *evaluate_for_address (struct expression *exp,
609 enum noside noside) override;
611 value *evaluate_funcall (struct type *expect_type,
612 struct expression *exp,
613 enum noside noside,
614 const std::vector<operation_up> &args) override;
616 enum exp_opcode opcode () const override
617 { return OP_SCOPE; }
619 protected:
621 void do_generate_ax (struct expression *exp,
622 struct agent_expr *ax,
623 struct axs_value *value,
624 struct type *cast_type)
625 override;
628 /* Compute the value of a variable. */
629 class var_value_operation
630 : public maybe_constant_operation<block_symbol>
632 public:
634 using maybe_constant_operation::maybe_constant_operation;
636 value *evaluate (struct type *expect_type,
637 struct expression *exp,
638 enum noside noside) override;
640 value *evaluate_with_coercion (struct expression *exp,
641 enum noside noside) override;
643 value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
644 override;
646 value *evaluate_for_cast (struct type *expect_type,
647 struct expression *exp,
648 enum noside noside) override;
650 value *evaluate_for_address (struct expression *exp, enum noside noside)
651 override;
653 value *evaluate_funcall (struct type *expect_type,
654 struct expression *exp,
655 enum noside noside,
656 const std::vector<operation_up> &args) override;
658 enum exp_opcode opcode () const override
659 { return OP_VAR_VALUE; }
661 /* Return the symbol referenced by this object. */
662 symbol *get_symbol () const
664 return std::get<0> (m_storage).symbol;
667 protected:
669 void do_generate_ax (struct expression *exp,
670 struct agent_expr *ax,
671 struct axs_value *value,
672 struct type *cast_type)
673 override;
676 class long_const_operation
677 : public tuple_holding_operation<struct type *, gdb_mpz>
679 public:
681 using tuple_holding_operation::tuple_holding_operation;
683 long_const_operation (struct type *type, LONGEST val)
684 : long_const_operation (type, gdb_mpz (val))
687 value *evaluate (struct type *expect_type,
688 struct expression *exp,
689 enum noside noside) override
691 return value_from_mpz (std::get<0> (m_storage), std::get<1> (m_storage));
694 enum exp_opcode opcode () const override
695 { return OP_LONG; }
697 bool constant_p () const override
698 { return true; }
700 protected:
702 LONGEST as_longest () const
703 { return std::get<1> (m_storage).as_integer_truncate<LONGEST> (); }
705 void do_generate_ax (struct expression *exp,
706 struct agent_expr *ax,
707 struct axs_value *value,
708 struct type *cast_type)
709 override;
712 class var_msym_value_operation
713 : public maybe_constant_operation<bound_minimal_symbol>
715 public:
717 using maybe_constant_operation::maybe_constant_operation;
719 value *evaluate (struct type *expect_type,
720 struct expression *exp,
721 enum noside noside) override
723 return eval_op_var_msym_value (expect_type, exp, noside, m_outermost,
724 std::get<0> (m_storage));
727 value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
728 override;
730 value *evaluate_for_address (struct expression *exp, enum noside noside)
731 override;
733 value *evaluate_for_cast (struct type *expect_type,
734 struct expression *exp,
735 enum noside noside) override;
737 value *evaluate_funcall (struct type *expect_type,
738 struct expression *exp,
739 enum noside noside,
740 const std::vector<operation_up> &args) override
742 const char *name = std::get<0> (m_storage).minsym->print_name ();
743 return operation::evaluate_funcall (expect_type, exp, noside, name, args);
746 enum exp_opcode opcode () const override
747 { return OP_VAR_MSYM_VALUE; }
749 void set_outermost () override
751 m_outermost = true;
754 protected:
756 /* True if this is the outermost operation in the expression. */
757 bool m_outermost = false;
759 void do_generate_ax (struct expression *exp,
760 struct agent_expr *ax,
761 struct axs_value *value,
762 struct type *cast_type)
763 override;
766 class var_entry_value_operation
767 : public tuple_holding_operation<symbol *>
769 public:
771 using tuple_holding_operation::tuple_holding_operation;
773 value *evaluate (struct type *expect_type,
774 struct expression *exp,
775 enum noside noside) override
777 return eval_op_var_entry_value (expect_type, exp, noside,
778 std::get<0> (m_storage));
781 enum exp_opcode opcode () const override
782 { return OP_VAR_ENTRY_VALUE; }
785 class func_static_var_operation
786 : public maybe_constant_operation<operation_up, std::string>
788 public:
790 using maybe_constant_operation::maybe_constant_operation;
792 value *evaluate (struct type *expect_type,
793 struct expression *exp,
794 enum noside noside) override
796 value *func = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
797 return eval_op_func_static_var (expect_type, exp, noside, func,
798 std::get<1> (m_storage).c_str ());
801 enum exp_opcode opcode () const override
802 { return OP_FUNC_STATIC_VAR; }
805 class last_operation
806 : public tuple_holding_operation<int>
808 public:
810 using tuple_holding_operation::tuple_holding_operation;
812 value *evaluate (struct type *expect_type,
813 struct expression *exp,
814 enum noside noside) override
816 return access_value_history (std::get<0> (m_storage));
819 enum exp_opcode opcode () const override
820 { return OP_LAST; }
823 class register_operation
824 : public tuple_holding_operation<std::string>
826 public:
828 using tuple_holding_operation::tuple_holding_operation;
830 value *evaluate (struct type *expect_type,
831 struct expression *exp,
832 enum noside noside) override
834 return eval_op_register (expect_type, exp, noside,
835 std::get<0> (m_storage).c_str ());
838 enum exp_opcode opcode () const override
839 { return OP_REGISTER; }
841 /* Return the name of the register. */
842 const char *get_name () const
844 return std::get<0> (m_storage).c_str ();
847 protected:
849 void do_generate_ax (struct expression *exp,
850 struct agent_expr *ax,
851 struct axs_value *value,
852 struct type *cast_type)
853 override;
856 class bool_operation
857 : public tuple_holding_operation<bool>
859 public:
861 using tuple_holding_operation::tuple_holding_operation;
863 value *evaluate (struct type *expect_type,
864 struct expression *exp,
865 enum noside noside) override
867 struct type *type = language_bool_type (exp->language_defn, exp->gdbarch);
868 return value_from_longest (type, std::get<0> (m_storage));
871 enum exp_opcode opcode () const override
872 { return OP_BOOL; }
874 bool constant_p () const override
875 { return true; }
878 class internalvar_operation
879 : public tuple_holding_operation<internalvar *>
881 public:
883 using tuple_holding_operation::tuple_holding_operation;
885 value *evaluate (struct type *expect_type,
886 struct expression *exp,
887 enum noside noside) override
889 return value_of_internalvar (exp->gdbarch,
890 std::get<0> (m_storage));
893 internalvar *get_internalvar () const
895 return std::get<0> (m_storage);
898 enum exp_opcode opcode () const override
899 { return OP_INTERNALVAR; }
901 protected:
903 void do_generate_ax (struct expression *exp,
904 struct agent_expr *ax,
905 struct axs_value *value,
906 struct type *cast_type)
907 override;
910 class string_operation
911 : public tuple_holding_operation<std::string>
913 public:
915 using tuple_holding_operation::tuple_holding_operation;
917 value *evaluate (struct type *expect_type,
918 struct expression *exp,
919 enum noside noside) override;
921 enum exp_opcode opcode () const override
922 { return OP_STRING; }
925 class ternop_slice_operation
926 : public maybe_constant_operation<operation_up, operation_up, operation_up>
928 public:
930 using maybe_constant_operation::maybe_constant_operation;
932 value *evaluate (struct type *expect_type,
933 struct expression *exp,
934 enum noside noside) override;
936 enum exp_opcode opcode () const override
937 { return TERNOP_SLICE; }
940 class ternop_cond_operation
941 : public maybe_constant_operation<operation_up, operation_up, operation_up>
943 public:
945 using maybe_constant_operation::maybe_constant_operation;
947 value *evaluate (struct type *expect_type,
948 struct expression *exp,
949 enum noside noside) override
951 struct value *val
952 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
954 if (value_logical_not (val))
955 return std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
956 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
959 enum exp_opcode opcode () const override
960 { return TERNOP_COND; }
962 protected:
964 void do_generate_ax (struct expression *exp,
965 struct agent_expr *ax,
966 struct axs_value *value,
967 struct type *cast_type)
968 override;
971 class complex_operation
972 : public maybe_constant_operation<operation_up, operation_up, struct type *>
974 public:
976 using maybe_constant_operation::maybe_constant_operation;
978 value *evaluate (struct type *expect_type,
979 struct expression *exp,
980 enum noside noside) override
982 value *real = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
983 value *imag = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
984 return value_literal_complex (real, imag,
985 std::get<2> (m_storage));
988 enum exp_opcode opcode () const override
989 { return OP_COMPLEX; }
992 class structop_base_operation
993 : public tuple_holding_operation<operation_up, std::string>
995 public:
997 /* Used for completion. Return the field name. */
998 const std::string &get_string () const
1000 return std::get<1> (m_storage);
1003 value *evaluate_funcall (struct type *expect_type,
1004 struct expression *exp,
1005 enum noside noside,
1006 const std::vector<operation_up> &args) override;
1008 /* Try to complete this operation in the context of EXP. TRACKER is
1009 the completion tracker to update. Return true if completion was
1010 possible, false otherwise. */
1011 virtual bool complete (struct expression *exp, completion_tracker &tracker)
1013 return complete (exp, tracker, "");
1016 protected:
1018 /* Do the work of the public 'complete' method. PREFIX is prepended
1019 to each result. */
1020 bool complete (struct expression *exp, completion_tracker &tracker,
1021 const char *prefix);
1023 using tuple_holding_operation::tuple_holding_operation;
1026 class structop_operation
1027 : public structop_base_operation
1029 public:
1031 using structop_base_operation::structop_base_operation;
1033 value *evaluate (struct type *expect_type,
1034 struct expression *exp,
1035 enum noside noside) override
1037 value *val =std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1038 return eval_op_structop_struct (expect_type, exp, noside, val,
1039 std::get<1> (m_storage).c_str ());
1042 enum exp_opcode opcode () const override
1043 { return STRUCTOP_STRUCT; }
1045 protected:
1047 void do_generate_ax (struct expression *exp,
1048 struct agent_expr *ax,
1049 struct axs_value *value,
1050 struct type *cast_type)
1051 override
1053 gen_expr_structop (exp, STRUCTOP_STRUCT,
1054 std::get<0> (this->m_storage).get (),
1055 std::get<1> (this->m_storage).c_str (),
1056 ax, value);
1060 class structop_ptr_operation
1061 : public structop_base_operation
1063 public:
1065 using structop_base_operation::structop_base_operation;
1067 value *evaluate (struct type *expect_type,
1068 struct expression *exp,
1069 enum noside noside) override
1071 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1072 return eval_op_structop_ptr (expect_type, exp, noside, val,
1073 std::get<1> (m_storage).c_str ());
1076 enum exp_opcode opcode () const override
1077 { return STRUCTOP_PTR; }
1079 protected:
1081 void do_generate_ax (struct expression *exp,
1082 struct agent_expr *ax,
1083 struct axs_value *value,
1084 struct type *cast_type)
1085 override
1087 gen_expr_structop (exp, STRUCTOP_PTR,
1088 std::get<0> (this->m_storage).get (),
1089 std::get<1> (this->m_storage).c_str (),
1090 ax, value);
1094 class structop_member_base
1095 : public tuple_holding_operation<operation_up, operation_up>
1097 public:
1099 using tuple_holding_operation::tuple_holding_operation;
1101 value *evaluate_funcall (struct type *expect_type,
1102 struct expression *exp,
1103 enum noside noside,
1104 const std::vector<operation_up> &args) override;
1107 class structop_member_operation
1108 : public structop_member_base
1110 public:
1112 using structop_member_base::structop_member_base;
1114 value *evaluate (struct type *expect_type,
1115 struct expression *exp,
1116 enum noside noside) override
1118 value *lhs
1119 = std::get<0> (m_storage)->evaluate_for_address (exp, noside);
1120 value *rhs
1121 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1122 return eval_op_member (expect_type, exp, noside, lhs, rhs);
1125 enum exp_opcode opcode () const override
1126 { return STRUCTOP_MEMBER; }
1129 class structop_mptr_operation
1130 : public structop_member_base
1132 public:
1134 using structop_member_base::structop_member_base;
1136 value *evaluate (struct type *expect_type,
1137 struct expression *exp,
1138 enum noside noside) override
1140 value *lhs
1141 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1142 value *rhs
1143 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1144 return eval_op_member (expect_type, exp, noside, lhs, rhs);
1147 enum exp_opcode opcode () const override
1148 { return STRUCTOP_MPTR; }
1151 class concat_operation
1152 : public maybe_constant_operation<operation_up, operation_up>
1154 public:
1156 using maybe_constant_operation::maybe_constant_operation;
1158 value *evaluate (struct type *expect_type,
1159 struct expression *exp,
1160 enum noside noside) override
1162 value *lhs
1163 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1164 value *rhs
1165 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1166 return value_concat (lhs, rhs);
1169 enum exp_opcode opcode () const override
1170 { return BINOP_CONCAT; }
1173 class add_operation
1174 : public maybe_constant_operation<operation_up, operation_up>
1176 public:
1178 using maybe_constant_operation::maybe_constant_operation;
1180 value *evaluate (struct type *expect_type,
1181 struct expression *exp,
1182 enum noside noside) override
1184 value *lhs
1185 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1186 value *rhs
1187 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1188 return eval_op_add (expect_type, exp, noside, lhs, rhs);
1191 enum exp_opcode opcode () const override
1192 { return BINOP_ADD; }
1194 protected:
1196 void do_generate_ax (struct expression *exp,
1197 struct agent_expr *ax,
1198 struct axs_value *value,
1199 struct type *cast_type)
1200 override
1202 gen_expr_binop (exp, BINOP_ADD,
1203 std::get<0> (this->m_storage).get (),
1204 std::get<1> (this->m_storage).get (),
1205 ax, value);
1209 class sub_operation
1210 : public maybe_constant_operation<operation_up, operation_up>
1212 public:
1214 using maybe_constant_operation::maybe_constant_operation;
1216 value *evaluate (struct type *expect_type,
1217 struct expression *exp,
1218 enum noside noside) override
1220 value *lhs
1221 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1222 value *rhs
1223 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1224 return eval_op_sub (expect_type, exp, noside, lhs, rhs);
1227 enum exp_opcode opcode () const override
1228 { return BINOP_SUB; }
1230 protected:
1232 void do_generate_ax (struct expression *exp,
1233 struct agent_expr *ax,
1234 struct axs_value *value,
1235 struct type *cast_type)
1236 override
1238 gen_expr_binop (exp, BINOP_SUB,
1239 std::get<0> (this->m_storage).get (),
1240 std::get<1> (this->m_storage).get (),
1241 ax, value);
1245 typedef struct value *binary_ftype (struct type *expect_type,
1246 struct expression *exp,
1247 enum noside noside, enum exp_opcode op,
1248 struct value *arg1, struct value *arg2);
1250 template<enum exp_opcode OP, binary_ftype FUNC>
1251 class binop_operation
1252 : public maybe_constant_operation<operation_up, operation_up>
1254 public:
1256 using maybe_constant_operation::maybe_constant_operation;
1258 value *evaluate (struct type *expect_type,
1259 struct expression *exp,
1260 enum noside noside) override
1262 value *lhs
1263 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1264 value *rhs
1265 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1266 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
1269 enum exp_opcode opcode () const override
1270 { return OP; }
1273 template<enum exp_opcode OP, binary_ftype FUNC>
1274 class usual_ax_binop_operation
1275 : public binop_operation<OP, FUNC>
1277 public:
1279 using binop_operation<OP, FUNC>::binop_operation;
1281 protected:
1283 void do_generate_ax (struct expression *exp,
1284 struct agent_expr *ax,
1285 struct axs_value *value,
1286 struct type *cast_type)
1287 override
1289 gen_expr_binop (exp, OP,
1290 std::get<0> (this->m_storage).get (),
1291 std::get<1> (this->m_storage).get (),
1292 ax, value);
1296 using exp_operation = binop_operation<BINOP_EXP, eval_op_binary>;
1297 using intdiv_operation = binop_operation<BINOP_INTDIV, eval_op_binary>;
1298 using mod_operation = binop_operation<BINOP_MOD, eval_op_binary>;
1300 using mul_operation = usual_ax_binop_operation<BINOP_MUL, eval_op_binary>;
1301 using div_operation = usual_ax_binop_operation<BINOP_DIV, eval_op_binary>;
1302 using rem_operation = usual_ax_binop_operation<BINOP_REM, eval_op_binary>;
1303 using lsh_operation = usual_ax_binop_operation<BINOP_LSH, eval_op_binary>;
1304 using rsh_operation = usual_ax_binop_operation<BINOP_RSH, eval_op_binary>;
1305 using bitwise_and_operation
1306 = usual_ax_binop_operation<BINOP_BITWISE_AND, eval_op_binary>;
1307 using bitwise_ior_operation
1308 = usual_ax_binop_operation<BINOP_BITWISE_IOR, eval_op_binary>;
1309 using bitwise_xor_operation
1310 = usual_ax_binop_operation<BINOP_BITWISE_XOR, eval_op_binary>;
1312 class subscript_operation
1313 : public usual_ax_binop_operation<BINOP_SUBSCRIPT, eval_op_subscript>
1315 public:
1316 using usual_ax_binop_operation<BINOP_SUBSCRIPT,
1317 eval_op_subscript>::usual_ax_binop_operation;
1319 value *evaluate_for_sizeof (struct expression *exp,
1320 enum noside noside) override;
1323 /* Implementation of comparison operations. */
1324 template<enum exp_opcode OP, binary_ftype FUNC>
1325 class comparison_operation
1326 : public usual_ax_binop_operation<OP, FUNC>
1328 public:
1330 using usual_ax_binop_operation<OP, FUNC>::usual_ax_binop_operation;
1332 value *evaluate (struct type *expect_type,
1333 struct expression *exp,
1334 enum noside noside) override
1336 value *lhs
1337 = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside);
1338 value *rhs
1339 = std::get<1> (this->m_storage)->evaluate (lhs->type (), exp,
1340 noside);
1341 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
1345 class equal_operation
1346 : public comparison_operation<BINOP_EQUAL, eval_op_equal>
1348 public:
1350 using comparison_operation::comparison_operation;
1352 operation *get_lhs () const
1354 return std::get<0> (m_storage).get ();
1357 operation *get_rhs () const
1359 return std::get<1> (m_storage).get ();
1363 using notequal_operation
1364 = comparison_operation<BINOP_NOTEQUAL, eval_op_notequal>;
1365 using less_operation = comparison_operation<BINOP_LESS, eval_op_less>;
1366 using gtr_operation = comparison_operation<BINOP_GTR, eval_op_gtr>;
1367 using geq_operation = comparison_operation<BINOP_GEQ, eval_op_geq>;
1368 using leq_operation = comparison_operation<BINOP_LEQ, eval_op_leq>;
1370 /* Implement the GDB '@' repeat operator. */
1371 class repeat_operation
1372 : public binop_operation<BINOP_REPEAT, eval_op_repeat>
1374 using binop_operation<BINOP_REPEAT, eval_op_repeat>::binop_operation;
1376 protected:
1378 void do_generate_ax (struct expression *exp,
1379 struct agent_expr *ax,
1380 struct axs_value *value,
1381 struct type *cast_type)
1382 override;
1385 /* C-style comma operator. */
1386 class comma_operation
1387 : public maybe_constant_operation<operation_up, operation_up>
1389 public:
1391 using maybe_constant_operation::maybe_constant_operation;
1393 value *evaluate (struct type *expect_type,
1394 struct expression *exp,
1395 enum noside noside) override
1397 /* The left-hand-side is only evaluated for side effects, so don't
1398 bother in other modes. */
1399 if (noside == EVAL_NORMAL)
1400 std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1401 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1404 enum exp_opcode opcode () const override
1405 { return BINOP_COMMA; }
1407 protected:
1409 void do_generate_ax (struct expression *exp,
1410 struct agent_expr *ax,
1411 struct axs_value *value,
1412 struct type *cast_type)
1413 override;
1416 typedef struct value *unary_ftype (struct type *expect_type,
1417 struct expression *exp,
1418 enum noside noside, enum exp_opcode op,
1419 struct value *arg1);
1421 /* Base class for unary operations. */
1422 template<enum exp_opcode OP, unary_ftype FUNC>
1423 class unop_operation
1424 : public maybe_constant_operation<operation_up>
1426 public:
1428 using maybe_constant_operation::maybe_constant_operation;
1430 value *evaluate (struct type *expect_type,
1431 struct expression *exp,
1432 enum noside noside) override
1434 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1435 return FUNC (expect_type, exp, noside, OP, val);
1438 enum exp_opcode opcode () const override
1439 { return OP; }
1442 /* Unary operations that can also be turned into agent expressions in
1443 the "usual" way. */
1444 template<enum exp_opcode OP, unary_ftype FUNC>
1445 class usual_ax_unop_operation
1446 : public unop_operation<OP, FUNC>
1448 using unop_operation<OP, FUNC>::unop_operation;
1450 protected:
1452 void do_generate_ax (struct expression *exp,
1453 struct agent_expr *ax,
1454 struct axs_value *value,
1455 struct type *cast_type)
1456 override
1458 gen_expr_unop (exp, OP,
1459 std::get<0> (this->m_storage).get (),
1460 ax, value);
1464 using unary_plus_operation = usual_ax_unop_operation<UNOP_PLUS, eval_op_plus>;
1465 using unary_neg_operation = usual_ax_unop_operation<UNOP_NEG, eval_op_neg>;
1466 using unary_complement_operation
1467 = usual_ax_unop_operation<UNOP_COMPLEMENT, eval_op_complement>;
1468 using unary_logical_not_operation
1469 = usual_ax_unop_operation<UNOP_LOGICAL_NOT, eval_op_lognot>;
1471 /* Handle pre- and post- increment and -decrement. */
1472 template<enum exp_opcode OP, unary_ftype FUNC>
1473 class unop_incr_operation
1474 : public tuple_holding_operation<operation_up>
1476 public:
1478 using tuple_holding_operation::tuple_holding_operation;
1480 value *evaluate (struct type *expect_type,
1481 struct expression *exp,
1482 enum noside noside) override
1484 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1485 return FUNC (expect_type, exp, noside, OP, val);
1488 enum exp_opcode opcode () const override
1489 { return OP; }
1492 using preinc_operation
1493 = unop_incr_operation<UNOP_PREINCREMENT, eval_op_preinc>;
1494 using predec_operation
1495 = unop_incr_operation<UNOP_PREDECREMENT, eval_op_predec>;
1496 using postinc_operation
1497 = unop_incr_operation<UNOP_POSTINCREMENT, eval_op_postinc>;
1498 using postdec_operation
1499 = unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>;
1501 /* Base class for implementations of UNOP_IND. */
1502 class unop_ind_base_operation
1503 : public tuple_holding_operation<operation_up>
1505 public:
1507 using tuple_holding_operation::tuple_holding_operation;
1509 value *evaluate (struct type *expect_type,
1510 struct expression *exp,
1511 enum noside noside) override
1513 value *val
1514 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1515 return eval_op_ind (expect_type, exp, noside, val);
1518 value *evaluate_for_address (struct expression *exp,
1519 enum noside noside) override;
1521 value *evaluate_for_sizeof (struct expression *exp,
1522 enum noside noside) override;
1524 enum exp_opcode opcode () const override
1525 { return UNOP_IND; }
1528 /* Ordinary UNOP_IND implementation. */
1529 class unop_ind_operation
1530 : public unop_ind_base_operation
1532 public:
1534 using unop_ind_base_operation::unop_ind_base_operation;
1536 protected:
1538 void do_generate_ax (struct expression *exp,
1539 struct agent_expr *ax,
1540 struct axs_value *value,
1541 struct type *cast_type)
1542 override
1544 gen_expr_unop (exp, UNOP_IND,
1545 std::get<0> (this->m_storage).get (),
1546 ax, value);
1550 /* Implement OP_TYPE. */
1551 class type_operation
1552 : public tuple_holding_operation<struct type *>
1554 public:
1556 using tuple_holding_operation::tuple_holding_operation;
1558 value *evaluate (struct type *expect_type,
1559 struct expression *exp,
1560 enum noside noside) override;
1562 enum exp_opcode opcode () const override
1563 { return OP_TYPE; }
1565 bool constant_p () const override
1566 { return true; }
1568 bool type_p () const override
1569 { return true; }
1572 /* Implement the "typeof" operation. */
1573 class typeof_operation
1574 : public maybe_constant_operation<operation_up>
1576 public:
1578 using maybe_constant_operation::maybe_constant_operation;
1580 value *evaluate (struct type *expect_type,
1581 struct expression *exp,
1582 enum noside noside) override
1584 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1585 return std::get<0> (m_storage)->evaluate (nullptr, exp,
1586 EVAL_AVOID_SIDE_EFFECTS);
1587 else
1588 error (_("Attempt to use a type as an expression"));
1591 enum exp_opcode opcode () const override
1592 { return OP_TYPEOF; }
1594 bool type_p () const override
1595 { return true; }
1598 /* Implement 'decltype'. */
1599 class decltype_operation
1600 : public maybe_constant_operation<operation_up>
1602 public:
1604 using maybe_constant_operation::maybe_constant_operation;
1606 value *evaluate (struct type *expect_type,
1607 struct expression *exp,
1608 enum noside noside) override
1610 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1612 value *result
1613 = std::get<0> (m_storage)->evaluate (nullptr, exp,
1614 EVAL_AVOID_SIDE_EFFECTS);
1615 enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
1616 if (sub_op == BINOP_SUBSCRIPT
1617 || sub_op == STRUCTOP_MEMBER
1618 || sub_op == STRUCTOP_MPTR
1619 || sub_op == UNOP_IND
1620 || sub_op == STRUCTOP_STRUCT
1621 || sub_op == STRUCTOP_PTR
1622 || sub_op == OP_SCOPE)
1624 struct type *type = result->type ();
1626 if (!TYPE_IS_REFERENCE (type))
1628 type = lookup_lvalue_reference_type (type);
1629 result = value::allocate (type);
1633 return result;
1635 else
1636 error (_("Attempt to use a type as an expression"));
1639 enum exp_opcode opcode () const override
1640 { return OP_DECLTYPE; }
1642 bool type_p () const override
1643 { return true; }
1646 /* Implement 'typeid'. */
1647 class typeid_operation
1648 : public tuple_holding_operation<operation_up>
1650 public:
1652 using tuple_holding_operation::tuple_holding_operation;
1654 value *evaluate (struct type *expect_type,
1655 struct expression *exp,
1656 enum noside noside) override
1658 enum noside sub_noside
1659 = (std::get<0> (m_storage)->type_p ()
1660 ? EVAL_AVOID_SIDE_EFFECTS
1661 : noside);
1663 value *result = std::get<0> (m_storage)->evaluate (nullptr, exp,
1664 sub_noside);
1665 if (noside != EVAL_NORMAL)
1666 return value::allocate (cplus_typeid_type (exp->gdbarch));
1667 return cplus_typeid (result);
1670 enum exp_opcode opcode () const override
1671 { return OP_TYPEID; }
1674 /* Implement the address-of operation. */
1675 class unop_addr_operation
1676 : public maybe_constant_operation<operation_up>
1678 public:
1680 using maybe_constant_operation::maybe_constant_operation;
1682 value *evaluate (struct type *expect_type,
1683 struct expression *exp,
1684 enum noside noside) override
1686 /* C++: check for and handle pointer to members. */
1687 return std::get<0> (m_storage)->evaluate_for_address (exp, noside);
1690 enum exp_opcode opcode () const override
1691 { return UNOP_ADDR; }
1693 /* Return the subexpression. */
1694 const operation_up &get_expression () const
1696 return std::get<0> (m_storage);
1699 protected:
1701 void do_generate_ax (struct expression *exp,
1702 struct agent_expr *ax,
1703 struct axs_value *value,
1704 struct type *cast_type)
1705 override
1707 gen_expr_unop (exp, UNOP_ADDR,
1708 std::get<0> (this->m_storage).get (),
1709 ax, value);
1713 /* Implement 'sizeof'. */
1714 class unop_sizeof_operation
1715 : public maybe_constant_operation<operation_up>
1717 public:
1719 using maybe_constant_operation::maybe_constant_operation;
1721 value *evaluate (struct type *expect_type,
1722 struct expression *exp,
1723 enum noside noside) override
1725 return std::get<0> (m_storage)->evaluate_for_sizeof (exp, noside);
1728 enum exp_opcode opcode () const override
1729 { return UNOP_SIZEOF; }
1731 protected:
1733 void do_generate_ax (struct expression *exp,
1734 struct agent_expr *ax,
1735 struct axs_value *value,
1736 struct type *cast_type)
1737 override;
1740 /* Implement 'alignof'. */
1741 class unop_alignof_operation
1742 : public maybe_constant_operation<operation_up>
1744 public:
1746 using maybe_constant_operation::maybe_constant_operation;
1748 value *evaluate (struct type *expect_type,
1749 struct expression *exp,
1750 enum noside noside) override
1752 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1753 EVAL_AVOID_SIDE_EFFECTS);
1754 return eval_op_alignof (expect_type, exp, noside, val);
1757 enum exp_opcode opcode () const override
1758 { return UNOP_ALIGNOF; }
1761 /* Implement UNOP_MEMVAL. */
1762 class unop_memval_operation
1763 : public tuple_holding_operation<operation_up, struct type *>
1765 public:
1767 using tuple_holding_operation::tuple_holding_operation;
1769 value *evaluate (struct type *expect_type,
1770 struct expression *exp,
1771 enum noside noside) override
1773 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1774 return eval_op_memval (expect_type, exp, noside, val,
1775 std::get<1> (m_storage));
1778 value *evaluate_for_sizeof (struct expression *exp,
1779 enum noside noside) override;
1781 value *evaluate_for_address (struct expression *exp,
1782 enum noside noside) override;
1784 enum exp_opcode opcode () const override
1785 { return UNOP_MEMVAL; }
1787 /* Return the type referenced by this object. */
1788 struct type *get_type () const
1790 return std::get<1> (m_storage);
1793 protected:
1795 void do_generate_ax (struct expression *exp,
1796 struct agent_expr *ax,
1797 struct axs_value *value,
1798 struct type *cast_type)
1799 override;
1802 /* Implement UNOP_MEMVAL_TYPE. */
1803 class unop_memval_type_operation
1804 : public tuple_holding_operation<operation_up, operation_up>
1806 public:
1808 using tuple_holding_operation::tuple_holding_operation;
1810 value *evaluate (struct type *expect_type,
1811 struct expression *exp,
1812 enum noside noside) override
1814 value *typeval
1815 = std::get<0> (m_storage)->evaluate (expect_type, exp,
1816 EVAL_AVOID_SIDE_EFFECTS);
1817 struct type *type = typeval->type ();
1818 value *val = std::get<1> (m_storage)->evaluate (expect_type, exp, noside);
1819 return eval_op_memval (expect_type, exp, noside, val, type);
1822 value *evaluate_for_sizeof (struct expression *exp,
1823 enum noside noside) override;
1825 value *evaluate_for_address (struct expression *exp,
1826 enum noside noside) override;
1828 enum exp_opcode opcode () const override
1829 { return UNOP_MEMVAL_TYPE; }
1831 protected:
1833 void do_generate_ax (struct expression *exp,
1834 struct agent_expr *ax,
1835 struct axs_value *value,
1836 struct type *cast_type)
1837 override;
1840 /* Implement the 'this' expression. */
1841 class op_this_operation
1842 : public tuple_holding_operation<>
1844 public:
1846 using tuple_holding_operation::tuple_holding_operation;
1848 value *evaluate (struct type *expect_type,
1849 struct expression *exp,
1850 enum noside noside) override
1852 return value_of_this (exp->language_defn);
1855 enum exp_opcode opcode () const override
1856 { return OP_THIS; }
1858 protected:
1860 void do_generate_ax (struct expression *exp,
1861 struct agent_expr *ax,
1862 struct axs_value *value,
1863 struct type *cast_type)
1864 override;
1867 /* Implement the "type instance" operation. */
1868 class type_instance_operation
1869 : public tuple_holding_operation<type_instance_flags, std::vector<type *>,
1870 operation_up>
1872 public:
1874 using tuple_holding_operation::tuple_holding_operation;
1876 value *evaluate (struct type *expect_type,
1877 struct expression *exp,
1878 enum noside noside) override;
1880 enum exp_opcode opcode () const override
1881 { return TYPE_INSTANCE; }
1884 /* The assignment operator. */
1885 class assign_operation
1886 : public tuple_holding_operation<operation_up, operation_up>
1888 public:
1890 using tuple_holding_operation::tuple_holding_operation;
1892 value *evaluate (struct type *expect_type,
1893 struct expression *exp,
1894 enum noside noside) override
1896 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1897 /* Special-case assignments where the left-hand-side is a
1898 convenience variable -- in these, don't bother setting an
1899 expected type. This avoids a weird case where re-assigning a
1900 string or array to an internal variable could error with "Too
1901 many array elements". */
1902 struct type *xtype = (lhs->lval () == lval_internalvar
1903 ? nullptr
1904 : lhs->type ());
1905 value *rhs = std::get<1> (m_storage)->evaluate (xtype, exp, noside);
1907 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1908 return lhs;
1909 if (binop_user_defined_p (BINOP_ASSIGN, lhs, rhs))
1910 return value_x_binop (lhs, rhs, BINOP_ASSIGN, OP_NULL, noside);
1911 else
1912 return value_assign (lhs, rhs);
1915 enum exp_opcode opcode () const override
1916 { return BINOP_ASSIGN; }
1918 /* Return the left-hand-side of the assignment. */
1919 operation *get_lhs () const
1921 return std::get<0> (m_storage).get ();
1924 protected:
1926 void do_generate_ax (struct expression *exp,
1927 struct agent_expr *ax,
1928 struct axs_value *value,
1929 struct type *cast_type)
1930 override;
1933 /* Assignment with modification, like "+=". */
1934 class assign_modify_operation
1935 : public tuple_holding_operation<exp_opcode, operation_up, operation_up>
1937 public:
1939 using tuple_holding_operation::tuple_holding_operation;
1941 value *evaluate (struct type *expect_type,
1942 struct expression *exp,
1943 enum noside noside) override
1945 value *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1946 value *rhs = std::get<2> (m_storage)->evaluate (expect_type, exp, noside);
1947 return eval_binop_assign_modify (expect_type, exp, noside,
1948 std::get<0> (m_storage), lhs, rhs);
1951 enum exp_opcode opcode () const override
1952 { return BINOP_ASSIGN_MODIFY; }
1954 protected:
1956 void do_generate_ax (struct expression *exp,
1957 struct agent_expr *ax,
1958 struct axs_value *value,
1959 struct type *cast_type)
1960 override;
1963 /* Not a cast! Extract a value of a given type from the contents of a
1964 value. The new value is extracted from the least significant bytes
1965 of the old value. The new value's type must be no bigger than the
1966 old values type. */
1967 class unop_extract_operation
1968 : public maybe_constant_operation<operation_up, struct type *>
1970 public:
1972 using maybe_constant_operation::maybe_constant_operation;
1974 value *evaluate (struct type *expect_type, struct expression *exp,
1975 enum noside noside) override;
1977 enum exp_opcode opcode () const override
1978 { return UNOP_EXTRACT; }
1980 /* Return the type referenced by this object. */
1981 struct type *get_type () const
1983 return std::get<1> (m_storage);
1986 protected:
1988 void do_generate_ax (struct expression *exp,
1989 struct agent_expr *ax,
1990 struct axs_value *value,
1991 struct type *cast_type) override;
1994 /* A type cast. */
1995 class unop_cast_operation
1996 : public maybe_constant_operation<operation_up, struct type *>
1998 public:
2000 using maybe_constant_operation::maybe_constant_operation;
2002 value *evaluate (struct type *expect_type,
2003 struct expression *exp,
2004 enum noside noside) override
2006 return std::get<0> (m_storage)->evaluate_for_cast (std::get<1> (m_storage),
2007 exp, noside);
2010 enum exp_opcode opcode () const override
2011 { return UNOP_CAST; }
2013 /* Return the type referenced by this object. */
2014 struct type *get_type () const
2016 return std::get<1> (m_storage);
2019 protected:
2021 void do_generate_ax (struct expression *exp,
2022 struct agent_expr *ax,
2023 struct axs_value *value,
2024 struct type *cast_type)
2025 override;
2028 /* A cast, but the type comes from an expression, not a "struct
2029 type". */
2030 class unop_cast_type_operation
2031 : public maybe_constant_operation<operation_up, operation_up>
2033 public:
2035 using maybe_constant_operation::maybe_constant_operation;
2037 value *evaluate (struct type *expect_type,
2038 struct expression *exp,
2039 enum noside noside) override
2041 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
2042 EVAL_AVOID_SIDE_EFFECTS);
2043 return std::get<1> (m_storage)->evaluate_for_cast (val->type (),
2044 exp, noside);
2047 enum exp_opcode opcode () const override
2048 { return UNOP_CAST_TYPE; }
2050 protected:
2052 void do_generate_ax (struct expression *exp,
2053 struct agent_expr *ax,
2054 struct axs_value *value,
2055 struct type *cast_type)
2056 override;
2059 typedef value *cxx_cast_ftype (struct type *, value *);
2061 /* This implements dynamic_cast and reinterpret_cast. static_cast and
2062 const_cast are handled by the ordinary case operations. */
2063 template<exp_opcode OP, cxx_cast_ftype FUNC>
2064 class cxx_cast_operation
2065 : public maybe_constant_operation<operation_up, operation_up>
2067 public:
2069 using maybe_constant_operation::maybe_constant_operation;
2071 value *evaluate (struct type *expect_type,
2072 struct expression *exp,
2073 enum noside noside) override
2075 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
2076 EVAL_AVOID_SIDE_EFFECTS);
2077 struct type *type = val->type ();
2078 value *rhs = std::get<1> (m_storage)->evaluate (type, exp, noside);
2079 return FUNC (type, rhs);
2082 enum exp_opcode opcode () const override
2083 { return OP; }
2086 using dynamic_cast_operation = cxx_cast_operation<UNOP_DYNAMIC_CAST,
2087 value_dynamic_cast>;
2088 using reinterpret_cast_operation = cxx_cast_operation<UNOP_REINTERPRET_CAST,
2089 value_reinterpret_cast>;
2091 /* Multi-dimensional subscripting. */
2092 class multi_subscript_operation
2093 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
2095 public:
2097 using tuple_holding_operation::tuple_holding_operation;
2099 value *evaluate (struct type *expect_type,
2100 struct expression *exp,
2101 enum noside noside) override;
2103 enum exp_opcode opcode () const override
2104 { return MULTI_SUBSCRIPT; }
2107 /* The "&&" operator. */
2108 class logical_and_operation
2109 : public maybe_constant_operation<operation_up, operation_up>
2111 public:
2113 using maybe_constant_operation::maybe_constant_operation;
2115 value *evaluate (struct type *expect_type,
2116 struct expression *exp,
2117 enum noside noside) override;
2119 enum exp_opcode opcode () const override
2120 { return BINOP_LOGICAL_AND; }
2122 protected:
2124 void do_generate_ax (struct expression *exp,
2125 struct agent_expr *ax,
2126 struct axs_value *value,
2127 struct type *cast_type)
2128 override;
2131 /* The "||" operator. */
2132 class logical_or_operation
2133 : public maybe_constant_operation<operation_up, operation_up>
2135 public:
2137 using maybe_constant_operation::maybe_constant_operation;
2139 value *evaluate (struct type *expect_type,
2140 struct expression *exp,
2141 enum noside noside) override;
2143 enum exp_opcode opcode () const override
2144 { return BINOP_LOGICAL_OR; }
2146 protected:
2148 void do_generate_ax (struct expression *exp,
2149 struct agent_expr *ax,
2150 struct axs_value *value,
2151 struct type *cast_type)
2152 override;
2155 /* This class implements ADL (aka Koenig) function calls for C++. It
2156 holds the name of the function to call, the block in which the
2157 lookup should be done, and a vector of arguments. */
2158 class adl_func_operation
2159 : public tuple_holding_operation<std::string, const block *,
2160 std::vector<operation_up>>
2162 public:
2164 using tuple_holding_operation::tuple_holding_operation;
2166 value *evaluate (struct type *expect_type,
2167 struct expression *exp,
2168 enum noside noside) override;
2170 enum exp_opcode opcode () const override
2171 { return OP_ADL_FUNC; }
2174 /* The OP_ARRAY operation. */
2175 class array_operation
2176 : public tuple_holding_operation<int, int, std::vector<operation_up>>
2178 public:
2180 using tuple_holding_operation::tuple_holding_operation;
2182 value *evaluate (struct type *expect_type,
2183 struct expression *exp,
2184 enum noside noside) override;
2186 enum exp_opcode opcode () const override
2187 { return OP_ARRAY; }
2189 private:
2191 struct value *evaluate_struct_tuple (struct value *struct_val,
2192 struct expression *exp,
2193 enum noside noside, int nargs);
2196 /* A function call. This holds the callee operation and the
2197 arguments. */
2198 class funcall_operation
2199 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
2201 public:
2203 using tuple_holding_operation::tuple_holding_operation;
2205 value *evaluate (struct type *expect_type,
2206 struct expression *exp,
2207 enum noside noside) override
2209 return std::get<0> (m_storage)->evaluate_funcall (expect_type, exp, noside,
2210 std::get<1> (m_storage));
2213 enum exp_opcode opcode () const override
2214 { return OP_FUNCALL; }
2217 } /* namespace expr */
2219 #endif /* EXPOP_H */