Introduce unop_cast_operation
[deliverable/binutils-gdb.git] / gdb / expop.h
1 /* Definitions for expressions in GDB
2
3 Copyright (C) 2020 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #ifndef EXPOP_H
21 #define EXPOP_H
22
23 #include "block.h"
24 #include "c-lang.h"
25 #include "cp-abi.h"
26 #include "expression.h"
27 #include "objfiles.h"
28 #include "gdbsupport/traits.h"
29 #include "gdbsupport/enum-flags.h"
30
31 struct agent_expr;
32 struct axs_value;
33
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);
47
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 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,
63 enum noside noside,
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,
71 const char *string);
72 extern struct value *eval_op_ternop (struct type *expect_type,
73 struct expression *exp,
74 enum noside noside,
75 struct value *array, struct value *low,
76 struct value *upper);
77 extern struct value *eval_op_structop_struct (struct type *expect_type,
78 struct expression *exp,
79 enum noside noside,
80 struct value *arg1,
81 const char *string);
82 extern struct value *eval_op_structop_ptr (struct type *expect_type,
83 struct expression *exp,
84 enum noside noside,
85 struct value *arg1,
86 const char *string);
87 extern struct value *eval_op_member (struct type *expect_type,
88 struct expression *exp,
89 enum noside noside,
90 struct value *arg1, struct value *arg2);
91 extern struct value *eval_op_concat (struct type *expect_type,
92 struct expression *exp,
93 enum noside noside,
94 struct value *arg1, struct value *arg2);
95 extern struct value *eval_op_add (struct type *expect_type,
96 struct expression *exp,
97 enum noside noside,
98 struct value *arg1, struct value *arg2);
99 extern struct value *eval_op_sub (struct type *expect_type,
100 struct expression *exp,
101 enum noside noside,
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,
110 struct value *arg1,
111 struct value *arg2);
112 extern struct value *eval_op_equal (struct type *expect_type,
113 struct expression *exp,
114 enum noside noside, enum exp_opcode op,
115 struct value *arg1,
116 struct value *arg2);
117 extern struct value *eval_op_notequal (struct type *expect_type,
118 struct expression *exp,
119 enum noside noside, enum exp_opcode op,
120 struct value *arg1,
121 struct value *arg2);
122 extern struct value *eval_op_less (struct type *expect_type,
123 struct expression *exp,
124 enum noside noside, enum exp_opcode op,
125 struct value *arg1,
126 struct value *arg2);
127 extern struct value *eval_op_gtr (struct type *expect_type,
128 struct expression *exp,
129 enum noside noside, enum exp_opcode op,
130 struct value *arg1,
131 struct value *arg2);
132 extern struct value *eval_op_geq (struct type *expect_type,
133 struct expression *exp,
134 enum noside noside, enum exp_opcode op,
135 struct value *arg1,
136 struct value *arg2);
137 extern struct value *eval_op_leq (struct type *expect_type,
138 struct expression *exp,
139 enum noside noside, enum exp_opcode op,
140 struct value *arg1,
141 struct value *arg2);
142 extern struct value *eval_op_repeat (struct type *expect_type,
143 struct expression *exp,
144 enum noside noside, enum exp_opcode op,
145 struct value *arg1,
146 struct value *arg2);
147 extern struct value *eval_op_plus (struct type *expect_type,
148 struct expression *exp,
149 enum noside noside, enum exp_opcode op,
150 struct value *arg1);
151 extern struct value *eval_op_neg (struct type *expect_type,
152 struct expression *exp,
153 enum noside noside, enum exp_opcode op,
154 struct value *arg1);
155 extern struct value *eval_op_complement (struct type *expect_type,
156 struct expression *exp,
157 enum noside noside,
158 enum exp_opcode op,
159 struct value *arg1);
160 extern struct value *eval_op_lognot (struct type *expect_type,
161 struct expression *exp,
162 enum noside noside,
163 enum exp_opcode op,
164 struct value *arg1);
165 extern struct value *eval_op_preinc (struct type *expect_type,
166 struct expression *exp,
167 enum noside noside,
168 enum exp_opcode op,
169 struct value *arg1);
170 extern struct value *eval_op_predec (struct type *expect_type,
171 struct expression *exp,
172 enum noside noside,
173 enum exp_opcode op,
174 struct value *arg1);
175 extern struct value *eval_op_postinc (struct type *expect_type,
176 struct expression *exp,
177 enum noside noside,
178 enum exp_opcode op,
179 struct value *arg1);
180 extern struct value *eval_op_postdec (struct type *expect_type,
181 struct expression *exp,
182 enum noside noside,
183 enum exp_opcode op,
184 struct value *arg1);
185 extern struct value *eval_op_ind (struct type *expect_type,
186 struct expression *exp,
187 enum noside noside,
188 struct value *arg1);
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,
194 enum noside noside,
195 struct value *arg1);
196 extern struct value *eval_op_memval (struct type *expect_type,
197 struct expression *exp,
198 enum noside noside,
199 struct value *arg1, struct type *type);
200 extern struct value *eval_binop_assign_modify (struct type *expect_type,
201 struct expression *exp,
202 enum noside noside,
203 enum exp_opcode op,
204 struct value *arg1,
205 struct value *arg2);
206
207 namespace expr
208 {
209
210 /* The check_objfile overloads are used to check whether a particular
211 component of some operation references an objfile. The passed-in
212 objfile will never be a debug objfile. */
213
214 /* See if EXP_OBJFILE matches OBJFILE. */
215 static inline bool
216 check_objfile (struct objfile *exp_objfile, struct objfile *objfile)
217 {
218 if (exp_objfile->separate_debug_objfile_backlink)
219 exp_objfile = exp_objfile->separate_debug_objfile_backlink;
220 return exp_objfile == objfile;
221 }
222
223 static inline bool
224 check_objfile (struct type *type, struct objfile *objfile)
225 {
226 struct objfile *ty_objfile = type->objfile_owner ();
227 if (ty_objfile != nullptr)
228 return check_objfile (ty_objfile, objfile);
229 return false;
230 }
231
232 static inline bool
233 check_objfile (struct symbol *sym, struct objfile *objfile)
234 {
235 return check_objfile (symbol_objfile (sym), objfile);
236 }
237
238 static inline bool
239 check_objfile (const struct block *block, struct objfile *objfile)
240 {
241 return check_objfile (block_objfile (block), objfile);
242 }
243
244 static inline bool
245 check_objfile (minimal_symbol *minsym, struct objfile *objfile)
246 {
247 /* This may seem strange but minsyms are only used with an objfile
248 as well. */
249 return false;
250 }
251
252 static inline bool
253 check_objfile (internalvar *ivar, struct objfile *objfile)
254 {
255 return false;
256 }
257
258 static inline bool
259 check_objfile (const std::string &str, struct objfile *objfile)
260 {
261 return false;
262 }
263
264 static inline bool
265 check_objfile (const operation_up &op, struct objfile *objfile)
266 {
267 return op->uses_objfile (objfile);
268 }
269
270 static inline bool
271 check_objfile (enum exp_opcode val, struct objfile *objfile)
272 {
273 return false;
274 }
275
276 static inline bool
277 check_objfile (ULONGEST val, struct objfile *objfile)
278 {
279 return false;
280 }
281
282 template<typename T>
283 static inline bool
284 check_objfile (enum_flags<T> val, struct objfile *objfile)
285 {
286 return false;
287 }
288
289 template<typename T>
290 static inline bool
291 check_objfile (const std::vector<T> &collection, struct objfile *objfile)
292 {
293 for (const auto &item : collection)
294 {
295 if (check_objfile (item, objfile))
296 return true;
297 }
298 return false;
299 }
300
301 template<typename S, typename T>
302 static inline bool
303 check_objfile (const std::pair<S, T> &item, struct objfile *objfile)
304 {
305 return (check_objfile (item.first, objfile)
306 || check_objfile (item.second, objfile));
307 }
308
309 static inline void
310 dump_for_expression (struct ui_file *stream, int depth,
311 const operation_up &op)
312 {
313 op->dump (stream, depth);
314 }
315
316 extern void dump_for_expression (struct ui_file *stream, int depth,
317 enum exp_opcode op);
318 extern void dump_for_expression (struct ui_file *stream, int depth,
319 const std::string &str);
320 extern void dump_for_expression (struct ui_file *stream, int depth,
321 struct type *type);
322 extern void dump_for_expression (struct ui_file *stream, int depth,
323 CORE_ADDR addr);
324 extern void dump_for_expression (struct ui_file *stream, int depth,
325 internalvar *ivar);
326 extern void dump_for_expression (struct ui_file *stream, int depth,
327 symbol *sym);
328 extern void dump_for_expression (struct ui_file *stream, int depth,
329 minimal_symbol *msym);
330 extern void dump_for_expression (struct ui_file *stream, int depth,
331 const block *bl);
332 extern void dump_for_expression (struct ui_file *stream, int depth,
333 type_instance_flags flags);
334 extern void dump_for_expression (struct ui_file *stream, int depth,
335 enum c_string_type_values flags);
336 extern void dump_for_expression (struct ui_file *stream, int depth,
337 enum range_flag flags);
338 extern void dump_for_expression (struct ui_file *stream, int depth,
339 objfile *objf);
340
341 template<typename T>
342 void
343 dump_for_expression (struct ui_file *stream, int depth,
344 const std::vector<T> &vals)
345 {
346 fprintf_filtered (stream, _("%*sVector:\n"), depth, "");
347 for (auto &item : vals)
348 dump_for_expression (stream, depth + 1, item);
349 }
350
351 template<typename X, typename Y>
352 void
353 dump_for_expression (struct ui_file *stream, int depth,
354 const std::pair<X, Y> &vals)
355 {
356 dump_for_expression (stream, depth, vals.first);
357 dump_for_expression (stream, depth, vals.second);
358 }
359
360 /* Base class for most concrete operations. This class holds data,
361 specified via template parameters, and supplies generic
362 implementations of the 'dump' and 'uses_objfile' methods. */
363 template<typename... Arg>
364 class tuple_holding_operation : public operation
365 {
366 public:
367
368 explicit tuple_holding_operation (Arg... args)
369 : m_storage (std::forward<Arg> (args)...)
370 {
371 }
372
373 DISABLE_COPY_AND_ASSIGN (tuple_holding_operation);
374
375 bool uses_objfile (struct objfile *objfile) const override
376 {
377 return do_check_objfile<0, Arg...> (objfile, m_storage);
378 }
379
380 void dump (struct ui_file *stream, int depth) const override
381 {
382 dump_for_expression (stream, depth, opcode ());
383 do_dump<0, Arg...> (stream, depth + 1, m_storage);
384 }
385
386 protected:
387
388 /* Storage for the data. */
389 std::tuple<Arg...> m_storage;
390
391 private:
392
393 /* do_dump does the work of dumping the data. */
394 template<int I, typename... T>
395 typename std::enable_if<I == sizeof... (T), void>::type
396 do_dump (struct ui_file *stream, int depth, const std::tuple<T...> &value)
397 const
398 {
399 }
400
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)
404 const
405 {
406 dump_for_expression (stream, depth, std::get<I> (value));
407 do_dump<I + 1, T...> (stream, depth, value);
408 }
409
410 /* do_check_objfile does the work of checking whether this object
411 refers to OBJFILE. */
412 template<int I, typename... T>
413 typename std::enable_if<I == sizeof... (T), bool>::type
414 do_check_objfile (struct objfile *objfile, const std::tuple<T...> &value)
415 const
416 {
417 return false;
418 }
419
420 template<int I, typename... T>
421 typename std::enable_if<I < sizeof... (T), bool>::type
422 do_check_objfile (struct objfile *objfile, const std::tuple<T...> &value)
423 const
424 {
425 if (check_objfile (std::get<I> (value), objfile))
426 return true;
427 return do_check_objfile<I + 1, T...> (objfile, value);
428 }
429 };
430
431 /* The check_constant overloads are used to decide whether a given
432 concrete operation is a constant. This is done by checking the
433 operands. */
434
435 static inline bool
436 check_constant (const operation_up &item)
437 {
438 return item->constant_p ();
439 }
440
441 static inline bool
442 check_constant (struct minimal_symbol *msym)
443 {
444 return false;
445 }
446
447 static inline bool
448 check_constant (struct type *type)
449 {
450 return true;
451 }
452
453 static inline bool
454 check_constant (const struct block *block)
455 {
456 return true;
457 }
458
459 static inline bool
460 check_constant (const std::string &str)
461 {
462 return true;
463 }
464
465 static inline bool
466 check_constant (struct objfile *objfile)
467 {
468 return true;
469 }
470
471 static inline bool
472 check_constant (ULONGEST cst)
473 {
474 return true;
475 }
476
477 static inline bool
478 check_constant (struct symbol *sym)
479 {
480 enum address_class sc = SYMBOL_CLASS (sym);
481 return (sc == LOC_BLOCK
482 || sc == LOC_CONST
483 || sc == LOC_CONST_BYTES
484 || sc == LOC_LABEL);
485 }
486
487 template<typename T>
488 static inline bool
489 check_constant (const std::vector<T> &collection)
490 {
491 for (const auto &item : collection)
492 if (!check_constant (item))
493 return false;
494 return true;
495 }
496
497 template<typename S, typename T>
498 static inline bool
499 check_constant (const std::pair<S, T> &item)
500 {
501 return check_constant (item.first) && check_constant (item.second);
502 }
503
504 /* Base class for concrete operations. This class supplies an
505 implementation of 'constant_p' that works by checking the
506 operands. */
507 template<typename... Arg>
508 class maybe_constant_operation
509 : public tuple_holding_operation<Arg...>
510 {
511 public:
512
513 using tuple_holding_operation<Arg...>::tuple_holding_operation;
514
515 bool constant_p () const override
516 {
517 return do_check_constant<0, Arg...> (this->m_storage);
518 }
519
520 private:
521
522 template<int I, typename... T>
523 typename std::enable_if<I == sizeof... (T), bool>::type
524 do_check_constant (const std::tuple<T...> &value) const
525 {
526 return true;
527 }
528
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
532 {
533 if (!check_constant (std::get<I> (value)))
534 return false;
535 return do_check_constant<I + 1, T...> (value);
536 }
537 };
538
539 /* A floating-point constant. The constant is encoded in the target
540 format. */
541
542 typedef std::array<gdb_byte, 16> float_data;
543
544 /* An operation that holds a floating-point constant of a given
545 type.
546
547 This does not need the facilities provided by
548 tuple_holding_operation, so it does not use it. */
549 class float_const_operation
550 : public operation
551 {
552 public:
553
554 float_const_operation (struct type *type, float_data data)
555 : m_type (type),
556 m_data (data)
557 {
558 }
559
560 value *evaluate (struct type *expect_type,
561 struct expression *exp,
562 enum noside noside) override
563 {
564 return value_from_contents (m_type, m_data.data ());
565 }
566
567 enum exp_opcode opcode () const override
568 { return OP_FLOAT; }
569
570 bool constant_p () const override
571 { return true; }
572
573 void dump (struct ui_file *stream, int depth) const override;
574
575 private:
576
577 struct type *m_type;
578 float_data m_data;
579 };
580
581 class scope_operation
582 : public maybe_constant_operation<struct type *, std::string>
583 {
584 public:
585
586 using maybe_constant_operation::maybe_constant_operation;
587
588 value *evaluate (struct type *expect_type,
589 struct expression *exp,
590 enum noside noside) override
591 {
592 return eval_op_scope (expect_type, exp, noside,
593 std::get<0> (m_storage),
594 std::get<1> (m_storage).c_str ());
595 }
596
597 value *evaluate_for_address (struct expression *exp,
598 enum noside noside) override;
599
600 enum exp_opcode opcode () const override
601 { return OP_SCOPE; }
602
603 protected:
604
605 void do_generate_ax (struct expression *exp,
606 struct agent_expr *ax,
607 struct axs_value *value,
608 struct type *cast_type)
609 override;
610 };
611
612 class long_const_operation
613 : public tuple_holding_operation<struct type *, LONGEST>
614 {
615 public:
616
617 using tuple_holding_operation::tuple_holding_operation;
618
619 value *evaluate (struct type *expect_type,
620 struct expression *exp,
621 enum noside noside) override
622 {
623 return value_from_longest (std::get<0> (m_storage),
624 std::get<1> (m_storage));
625 }
626
627 enum exp_opcode opcode () const override
628 { return OP_LONG; }
629
630 bool constant_p () const override
631 { return true; }
632
633 protected:
634
635 void do_generate_ax (struct expression *exp,
636 struct agent_expr *ax,
637 struct axs_value *value,
638 struct type *cast_type)
639 override;
640 };
641
642 class var_msym_value_operation
643 : public maybe_constant_operation<minimal_symbol *, struct objfile *>
644 {
645 public:
646
647 using maybe_constant_operation::maybe_constant_operation;
648
649 value *evaluate (struct type *expect_type,
650 struct expression *exp,
651 enum noside noside) override
652 {
653 return eval_op_var_msym_value (expect_type, exp, noside, m_outermost,
654 std::get<0> (m_storage),
655 std::get<1> (m_storage));
656 }
657
658 value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
659 override;
660
661 value *evaluate_for_address (struct expression *exp, enum noside noside)
662 override;
663
664 value *evaluate_for_cast (struct type *expect_type,
665 struct expression *exp,
666 enum noside noside) override;
667
668 enum exp_opcode opcode () const override
669 { return OP_VAR_MSYM_VALUE; }
670
671 void set_outermost () override
672 {
673 m_outermost = true;
674 }
675
676 protected:
677
678 /* True if this is the outermost operation in the expression. */
679 bool m_outermost = false;
680
681 void do_generate_ax (struct expression *exp,
682 struct agent_expr *ax,
683 struct axs_value *value,
684 struct type *cast_type)
685 override;
686 };
687
688 class var_entry_value_operation
689 : public tuple_holding_operation<symbol *>
690 {
691 public:
692
693 using tuple_holding_operation::tuple_holding_operation;
694
695 value *evaluate (struct type *expect_type,
696 struct expression *exp,
697 enum noside noside) override
698 {
699 return eval_op_var_entry_value (expect_type, exp, noside,
700 std::get<0> (m_storage));
701 }
702
703 enum exp_opcode opcode () const override
704 { return OP_VAR_ENTRY_VALUE; }
705 };
706
707 class func_static_var_operation
708 : public maybe_constant_operation<operation_up, std::string>
709 {
710 public:
711
712 using maybe_constant_operation::maybe_constant_operation;
713
714 value *evaluate (struct type *expect_type,
715 struct expression *exp,
716 enum noside noside) override
717 {
718 value *func = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
719 return eval_op_func_static_var (expect_type, exp, noside, func,
720 std::get<1> (m_storage).c_str ());
721 }
722
723 enum exp_opcode opcode () const override
724 { return OP_FUNC_STATIC_VAR; }
725 };
726
727 class last_operation
728 : public tuple_holding_operation<int>
729 {
730 public:
731
732 using tuple_holding_operation::tuple_holding_operation;
733
734 value *evaluate (struct type *expect_type,
735 struct expression *exp,
736 enum noside noside) override
737 {
738 return access_value_history (std::get<0> (m_storage));
739 }
740
741 enum exp_opcode opcode () const override
742 { return OP_LAST; }
743 };
744
745 class register_operation
746 : public tuple_holding_operation<std::string>
747 {
748 public:
749
750 using tuple_holding_operation::tuple_holding_operation;
751
752 value *evaluate (struct type *expect_type,
753 struct expression *exp,
754 enum noside noside) override
755 {
756 return eval_op_register (expect_type, exp, noside,
757 std::get<0> (m_storage).c_str ());
758 }
759
760 enum exp_opcode opcode () const override
761 { return OP_REGISTER; }
762
763 protected:
764
765 void do_generate_ax (struct expression *exp,
766 struct agent_expr *ax,
767 struct axs_value *value,
768 struct type *cast_type)
769 override;
770 };
771
772 class bool_operation
773 : public tuple_holding_operation<bool>
774 {
775 public:
776
777 using tuple_holding_operation::tuple_holding_operation;
778
779 value *evaluate (struct type *expect_type,
780 struct expression *exp,
781 enum noside noside) override
782 {
783 struct type *type = language_bool_type (exp->language_defn, exp->gdbarch);
784 return value_from_longest (type, std::get<0> (m_storage));
785 }
786
787 enum exp_opcode opcode () const override
788 { return OP_BOOL; }
789
790 bool constant_p () const override
791 { return true; }
792 };
793
794 class internalvar_operation
795 : public tuple_holding_operation<internalvar *>
796 {
797 public:
798
799 using tuple_holding_operation::tuple_holding_operation;
800
801 value *evaluate (struct type *expect_type,
802 struct expression *exp,
803 enum noside noside) override
804 {
805 return value_of_internalvar (exp->gdbarch,
806 std::get<0> (m_storage));
807 }
808
809 internalvar *get_internalvar () const
810 {
811 return std::get<0> (m_storage);
812 }
813
814 enum exp_opcode opcode () const override
815 { return OP_INTERNALVAR; }
816
817 protected:
818
819 void do_generate_ax (struct expression *exp,
820 struct agent_expr *ax,
821 struct axs_value *value,
822 struct type *cast_type)
823 override;
824 };
825
826 class string_operation
827 : public tuple_holding_operation<std::string>
828 {
829 public:
830
831 using tuple_holding_operation::tuple_holding_operation;
832
833 value *evaluate (struct type *expect_type,
834 struct expression *exp,
835 enum noside noside) override
836 {
837 const std::string &str = std::get<0> (m_storage);
838 return eval_op_string (expect_type, exp, noside,
839 str.size (), str.c_str ());
840 }
841
842 enum exp_opcode opcode () const override
843 { return OP_STRING; }
844 };
845
846 class ternop_slice_operation
847 : public maybe_constant_operation<operation_up, operation_up, operation_up>
848 {
849 public:
850
851 using maybe_constant_operation::maybe_constant_operation;
852
853 value *evaluate (struct type *expect_type,
854 struct expression *exp,
855 enum noside noside) override
856 {
857 struct value *array
858 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
859 struct value *low
860 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
861 struct value *upper
862 = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
863 return eval_op_ternop (expect_type, exp, noside, array, low, upper);
864 }
865
866 enum exp_opcode opcode () const override
867 { return TERNOP_SLICE; }
868 };
869
870 class ternop_cond_operation
871 : public maybe_constant_operation<operation_up, operation_up, operation_up>
872 {
873 public:
874
875 using maybe_constant_operation::maybe_constant_operation;
876
877 value *evaluate (struct type *expect_type,
878 struct expression *exp,
879 enum noside noside) override
880 {
881 struct value *val
882 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
883
884 if (value_logical_not (val))
885 return std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
886 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
887 }
888
889 enum exp_opcode opcode () const override
890 { return TERNOP_COND; }
891
892 protected:
893
894 void do_generate_ax (struct expression *exp,
895 struct agent_expr *ax,
896 struct axs_value *value,
897 struct type *cast_type)
898 override;
899 };
900
901 class complex_operation
902 : public maybe_constant_operation<operation_up, operation_up, struct type *>
903 {
904 public:
905
906 using maybe_constant_operation::maybe_constant_operation;
907
908 value *evaluate (struct type *expect_type,
909 struct expression *exp,
910 enum noside noside) override
911 {
912 value *real = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
913 value *imag = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
914 return value_literal_complex (real, imag,
915 std::get<2> (m_storage));
916 }
917
918 enum exp_opcode opcode () const override
919 { return OP_COMPLEX; }
920 };
921
922 class structop_base_operation
923 : public tuple_holding_operation<operation_up, std::string>
924 {
925 public:
926
927 /* Used for completion. Return the field name. */
928 const std::string &get_string () const
929 {
930 return std::get<1> (m_storage);
931 }
932
933 /* Used for completion. Evaluate the LHS for type. */
934 value *evaluate_lhs (struct expression *exp)
935 {
936 return std::get<0> (m_storage)->evaluate (nullptr, exp,
937 EVAL_AVOID_SIDE_EFFECTS);
938 }
939
940 protected:
941
942 using tuple_holding_operation::tuple_holding_operation;
943 };
944
945 class structop_operation
946 : public structop_base_operation
947 {
948 public:
949
950 using structop_base_operation::structop_base_operation;
951
952 value *evaluate (struct type *expect_type,
953 struct expression *exp,
954 enum noside noside) override
955 {
956 value *val =std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
957 return eval_op_structop_struct (expect_type, exp, noside, val,
958 std::get<1> (m_storage).c_str ());
959 }
960
961 enum exp_opcode opcode () const override
962 { return STRUCTOP_STRUCT; }
963
964 protected:
965
966 void do_generate_ax (struct expression *exp,
967 struct agent_expr *ax,
968 struct axs_value *value,
969 struct type *cast_type)
970 override
971 {
972 gen_expr_structop (exp, STRUCTOP_STRUCT,
973 std::get<0> (this->m_storage).get (),
974 std::get<1> (this->m_storage).c_str (),
975 ax, value);
976 }
977 };
978
979 class structop_ptr_operation
980 : public structop_base_operation
981 {
982 public:
983
984 using structop_base_operation::structop_base_operation;
985
986 value *evaluate (struct type *expect_type,
987 struct expression *exp,
988 enum noside noside) override
989 {
990 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
991 return eval_op_structop_ptr (expect_type, exp, noside, val,
992 std::get<1> (m_storage).c_str ());
993 }
994
995 enum exp_opcode opcode () const override
996 { return STRUCTOP_PTR; }
997
998 protected:
999
1000 void do_generate_ax (struct expression *exp,
1001 struct agent_expr *ax,
1002 struct axs_value *value,
1003 struct type *cast_type)
1004 override
1005 {
1006 gen_expr_structop (exp, STRUCTOP_PTR,
1007 std::get<0> (this->m_storage).get (),
1008 std::get<1> (this->m_storage).c_str (),
1009 ax, value);
1010 }
1011 };
1012
1013 class structop_member_operation
1014 : public tuple_holding_operation<operation_up, operation_up>
1015 {
1016 public:
1017
1018 using tuple_holding_operation::tuple_holding_operation;
1019
1020 value *evaluate (struct type *expect_type,
1021 struct expression *exp,
1022 enum noside noside) override
1023 {
1024 value *lhs
1025 = std::get<0> (m_storage)->evaluate_for_address (exp, noside);
1026 value *rhs
1027 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1028 return eval_op_member (expect_type, exp, noside, lhs, rhs);
1029 }
1030
1031 enum exp_opcode opcode () const override
1032 { return STRUCTOP_MEMBER; }
1033 };
1034
1035 class structop_mptr_operation
1036 : public tuple_holding_operation<operation_up, operation_up>
1037 {
1038 public:
1039
1040 using tuple_holding_operation::tuple_holding_operation;
1041
1042 value *evaluate (struct type *expect_type,
1043 struct expression *exp,
1044 enum noside noside) override
1045 {
1046 value *lhs
1047 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1048 value *rhs
1049 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1050 return eval_op_member (expect_type, exp, noside, lhs, rhs);
1051 }
1052
1053 enum exp_opcode opcode () const override
1054 { return STRUCTOP_MPTR; }
1055 };
1056
1057 class concat_operation
1058 : public maybe_constant_operation<operation_up, operation_up>
1059 {
1060 public:
1061
1062 using maybe_constant_operation::maybe_constant_operation;
1063
1064 value *evaluate (struct type *expect_type,
1065 struct expression *exp,
1066 enum noside noside) override
1067 {
1068 value *lhs
1069 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1070 value *rhs
1071 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1072 return eval_op_concat (expect_type, exp, noside, lhs, rhs);
1073 }
1074
1075 enum exp_opcode opcode () const override
1076 { return BINOP_CONCAT; }
1077 };
1078
1079 class add_operation
1080 : public maybe_constant_operation<operation_up, operation_up>
1081 {
1082 public:
1083
1084 using maybe_constant_operation::maybe_constant_operation;
1085
1086 value *evaluate (struct type *expect_type,
1087 struct expression *exp,
1088 enum noside noside) override
1089 {
1090 value *lhs
1091 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1092 value *rhs
1093 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1094 return eval_op_add (expect_type, exp, noside, lhs, rhs);
1095 }
1096
1097 enum exp_opcode opcode () const override
1098 { return BINOP_ADD; }
1099
1100 protected:
1101
1102 void do_generate_ax (struct expression *exp,
1103 struct agent_expr *ax,
1104 struct axs_value *value,
1105 struct type *cast_type)
1106 override
1107 {
1108 gen_expr_binop (exp, BINOP_ADD,
1109 std::get<0> (this->m_storage).get (),
1110 std::get<1> (this->m_storage).get (),
1111 ax, value);
1112 }
1113 };
1114
1115 class sub_operation
1116 : public maybe_constant_operation<operation_up, operation_up>
1117 {
1118 public:
1119
1120 using maybe_constant_operation::maybe_constant_operation;
1121
1122 value *evaluate (struct type *expect_type,
1123 struct expression *exp,
1124 enum noside noside) override
1125 {
1126 value *lhs
1127 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1128 value *rhs
1129 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1130 return eval_op_sub (expect_type, exp, noside, lhs, rhs);
1131 }
1132
1133 enum exp_opcode opcode () const override
1134 { return BINOP_SUB; }
1135
1136 protected:
1137
1138 void do_generate_ax (struct expression *exp,
1139 struct agent_expr *ax,
1140 struct axs_value *value,
1141 struct type *cast_type)
1142 override
1143 {
1144 gen_expr_binop (exp, BINOP_SUB,
1145 std::get<0> (this->m_storage).get (),
1146 std::get<1> (this->m_storage).get (),
1147 ax, value);
1148 }
1149 };
1150
1151 typedef struct value *binary_ftype (struct type *expect_type,
1152 struct expression *exp,
1153 enum noside noside, enum exp_opcode op,
1154 struct value *arg1, struct value *arg2);
1155
1156 template<enum exp_opcode OP, binary_ftype FUNC>
1157 class binop_operation
1158 : public maybe_constant_operation<operation_up, operation_up>
1159 {
1160 public:
1161
1162 using maybe_constant_operation::maybe_constant_operation;
1163
1164 value *evaluate (struct type *expect_type,
1165 struct expression *exp,
1166 enum noside noside) override
1167 {
1168 value *lhs
1169 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1170 value *rhs
1171 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1172 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
1173 }
1174
1175 enum exp_opcode opcode () const override
1176 { return OP; }
1177 };
1178
1179 template<enum exp_opcode OP, binary_ftype FUNC>
1180 class usual_ax_binop_operation
1181 : public binop_operation<OP, FUNC>
1182 {
1183 public:
1184
1185 using binop_operation<OP, FUNC>::binop_operation;
1186
1187 protected:
1188
1189 void do_generate_ax (struct expression *exp,
1190 struct agent_expr *ax,
1191 struct axs_value *value,
1192 struct type *cast_type)
1193 override
1194 {
1195 gen_expr_binop (exp, OP,
1196 std::get<0> (this->m_storage).get (),
1197 std::get<1> (this->m_storage).get (),
1198 ax, value);
1199 }
1200 };
1201
1202 using exp_operation = binop_operation<BINOP_EXP, eval_op_binary>;
1203 using intdiv_operation = binop_operation<BINOP_INTDIV, eval_op_binary>;
1204 using mod_operation = binop_operation<BINOP_MOD, eval_op_binary>;
1205
1206 using mul_operation = usual_ax_binop_operation<BINOP_MUL, eval_op_binary>;
1207 using div_operation = usual_ax_binop_operation<BINOP_DIV, eval_op_binary>;
1208 using rem_operation = usual_ax_binop_operation<BINOP_REM, eval_op_binary>;
1209 using lsh_operation = usual_ax_binop_operation<BINOP_LSH, eval_op_binary>;
1210 using rsh_operation = usual_ax_binop_operation<BINOP_RSH, eval_op_binary>;
1211 using bitwise_and_operation
1212 = usual_ax_binop_operation<BINOP_BITWISE_AND, eval_op_binary>;
1213 using bitwise_ior_operation
1214 = usual_ax_binop_operation<BINOP_BITWISE_IOR, eval_op_binary>;
1215 using bitwise_xor_operation
1216 = usual_ax_binop_operation<BINOP_BITWISE_XOR, eval_op_binary>;
1217
1218 class subscript_operation
1219 : public usual_ax_binop_operation<BINOP_SUBSCRIPT, eval_op_subscript>
1220 {
1221 public:
1222 using usual_ax_binop_operation<BINOP_SUBSCRIPT,
1223 eval_op_subscript>::usual_ax_binop_operation;
1224
1225 value *evaluate_for_sizeof (struct expression *exp,
1226 enum noside noside) override;
1227 };
1228
1229 /* Implementation of comparison operations. */
1230 template<enum exp_opcode OP, binary_ftype FUNC>
1231 class comparison_operation
1232 : public usual_ax_binop_operation<OP, FUNC>
1233 {
1234 public:
1235
1236 using usual_ax_binop_operation<OP, FUNC>::usual_ax_binop_operation;
1237
1238 value *evaluate (struct type *expect_type,
1239 struct expression *exp,
1240 enum noside noside) override
1241 {
1242 value *lhs
1243 = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside);
1244 value *rhs
1245 = std::get<1> (this->m_storage)->evaluate (value_type (lhs), exp,
1246 noside);
1247 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
1248 }
1249 };
1250
1251 using equal_operation = comparison_operation<BINOP_EQUAL, eval_op_equal>;
1252 using notequal_operation
1253 = comparison_operation<BINOP_NOTEQUAL, eval_op_notequal>;
1254 using less_operation = comparison_operation<BINOP_LESS, eval_op_less>;
1255 using gtr_operation = comparison_operation<BINOP_GTR, eval_op_gtr>;
1256 using geq_operation = comparison_operation<BINOP_GEQ, eval_op_geq>;
1257 using leq_operation = comparison_operation<BINOP_LEQ, eval_op_leq>;
1258
1259 /* Implement the GDB '@' repeat operator. */
1260 class repeat_operation
1261 : public binop_operation<BINOP_REPEAT, eval_op_repeat>
1262 {
1263 using binop_operation<BINOP_REPEAT, eval_op_repeat>::binop_operation;
1264
1265 protected:
1266
1267 void do_generate_ax (struct expression *exp,
1268 struct agent_expr *ax,
1269 struct axs_value *value,
1270 struct type *cast_type)
1271 override;
1272 };
1273
1274 /* C-style comma operator. */
1275 class comma_operation
1276 : public maybe_constant_operation<operation_up, operation_up>
1277 {
1278 public:
1279
1280 using maybe_constant_operation::maybe_constant_operation;
1281
1282 value *evaluate (struct type *expect_type,
1283 struct expression *exp,
1284 enum noside noside) override
1285 {
1286 /* The left-hand-side is only evaluated for side effects, so don't
1287 bother in other modes. */
1288 if (noside == EVAL_NORMAL)
1289 std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1290 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1291 }
1292
1293 enum exp_opcode opcode () const override
1294 { return BINOP_COMMA; }
1295
1296 protected:
1297
1298 void do_generate_ax (struct expression *exp,
1299 struct agent_expr *ax,
1300 struct axs_value *value,
1301 struct type *cast_type)
1302 override;
1303 };
1304
1305 typedef struct value *unary_ftype (struct type *expect_type,
1306 struct expression *exp,
1307 enum noside noside, enum exp_opcode op,
1308 struct value *arg1);
1309
1310 /* Base class for unary operations. */
1311 template<enum exp_opcode OP, unary_ftype FUNC>
1312 class unop_operation
1313 : public maybe_constant_operation<operation_up>
1314 {
1315 public:
1316
1317 using maybe_constant_operation::maybe_constant_operation;
1318
1319 value *evaluate (struct type *expect_type,
1320 struct expression *exp,
1321 enum noside noside) override
1322 {
1323 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1324 return FUNC (expect_type, exp, noside, OP, val);
1325 }
1326
1327 enum exp_opcode opcode () const override
1328 { return OP; }
1329 };
1330
1331 /* Unary operations that can also be turned into agent expressions in
1332 the "usual" way. */
1333 template<enum exp_opcode OP, unary_ftype FUNC>
1334 class usual_ax_unop_operation
1335 : public unop_operation<OP, FUNC>
1336 {
1337 using unop_operation<OP, FUNC>::unop_operation;
1338
1339 protected:
1340
1341 void do_generate_ax (struct expression *exp,
1342 struct agent_expr *ax,
1343 struct axs_value *value,
1344 struct type *cast_type)
1345 override
1346 {
1347 gen_expr_unop (exp, OP,
1348 std::get<0> (this->m_storage).get (),
1349 ax, value);
1350 }
1351 };
1352
1353 using unary_plus_operation = usual_ax_unop_operation<UNOP_PLUS, eval_op_plus>;
1354 using unary_neg_operation = usual_ax_unop_operation<UNOP_NEG, eval_op_neg>;
1355 using unary_complement_operation
1356 = usual_ax_unop_operation<UNOP_COMPLEMENT, eval_op_complement>;
1357 using unary_logical_not_operation
1358 = usual_ax_unop_operation<UNOP_LOGICAL_NOT, eval_op_lognot>;
1359
1360 /* Handle pre- and post- increment and -decrement. */
1361 template<enum exp_opcode OP, unary_ftype FUNC>
1362 class unop_incr_operation
1363 : public tuple_holding_operation<operation_up>
1364 {
1365 public:
1366
1367 using tuple_holding_operation::tuple_holding_operation;
1368
1369 value *evaluate (struct type *expect_type,
1370 struct expression *exp,
1371 enum noside noside) override
1372 {
1373 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1374 return FUNC (expect_type, exp, noside, OP, val);
1375 }
1376
1377 enum exp_opcode opcode () const override
1378 { return OP; }
1379 };
1380
1381 using preinc_operation
1382 = unop_incr_operation<UNOP_PREINCREMENT, eval_op_preinc>;
1383 using predec_operation
1384 = unop_incr_operation<UNOP_PREDECREMENT, eval_op_predec>;
1385 using postinc_operation
1386 = unop_incr_operation<UNOP_POSTINCREMENT, eval_op_postinc>;
1387 using postdec_operation
1388 = unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>;
1389
1390 /* Base class for implementations of UNOP_IND. */
1391 class unop_ind_base_operation
1392 : public tuple_holding_operation<operation_up>
1393 {
1394 public:
1395
1396 using tuple_holding_operation::tuple_holding_operation;
1397
1398 value *evaluate (struct type *expect_type,
1399 struct expression *exp,
1400 enum noside noside) override
1401 {
1402 if (expect_type != nullptr && expect_type->code () == TYPE_CODE_PTR)
1403 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
1404 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1405 return eval_op_ind (expect_type, exp, noside, val);
1406 }
1407
1408 value *evaluate_for_address (struct expression *exp,
1409 enum noside noside) override;
1410
1411 value *evaluate_for_sizeof (struct expression *exp,
1412 enum noside noside) override;
1413
1414 enum exp_opcode opcode () const override
1415 { return UNOP_IND; }
1416 };
1417
1418 /* Ordinary UNOP_IND implementation. */
1419 class unop_ind_operation
1420 : public unop_ind_base_operation
1421 {
1422 public:
1423
1424 using unop_ind_base_operation::unop_ind_base_operation;
1425
1426 protected:
1427
1428 void do_generate_ax (struct expression *exp,
1429 struct agent_expr *ax,
1430 struct axs_value *value,
1431 struct type *cast_type)
1432 override
1433 {
1434 gen_expr_unop (exp, UNOP_IND,
1435 std::get<0> (this->m_storage).get (),
1436 ax, value);
1437 }
1438 };
1439
1440 /* Implement OP_TYPE. */
1441 class type_operation
1442 : public tuple_holding_operation<struct type *>
1443 {
1444 public:
1445
1446 using tuple_holding_operation::tuple_holding_operation;
1447
1448 value *evaluate (struct type *expect_type,
1449 struct expression *exp,
1450 enum noside noside) override
1451 {
1452 return eval_op_type (expect_type, exp, noside, std::get<0> (m_storage));
1453 }
1454
1455 enum exp_opcode opcode () const override
1456 { return OP_TYPE; }
1457
1458 bool constant_p () const override
1459 { return true; }
1460 };
1461
1462 /* Implement the "typeof" operation. */
1463 class typeof_operation
1464 : public maybe_constant_operation<operation_up>
1465 {
1466 public:
1467
1468 using maybe_constant_operation::maybe_constant_operation;
1469
1470 value *evaluate (struct type *expect_type,
1471 struct expression *exp,
1472 enum noside noside) override
1473 {
1474 if (noside == EVAL_SKIP)
1475 return eval_skip_value (exp);
1476 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1477 return std::get<0> (m_storage)->evaluate (nullptr, exp,
1478 EVAL_AVOID_SIDE_EFFECTS);
1479 else
1480 error (_("Attempt to use a type as an expression"));
1481 }
1482
1483 enum exp_opcode opcode () const override
1484 { return OP_TYPEOF; }
1485 };
1486
1487 /* Implement 'decltype'. */
1488 class decltype_operation
1489 : public maybe_constant_operation<operation_up>
1490 {
1491 public:
1492
1493 using maybe_constant_operation::maybe_constant_operation;
1494
1495 value *evaluate (struct type *expect_type,
1496 struct expression *exp,
1497 enum noside noside) override
1498 {
1499 if (noside == EVAL_SKIP)
1500 return eval_skip_value (exp);
1501 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1502 {
1503 value *result
1504 = std::get<0> (m_storage)->evaluate (nullptr, exp,
1505 EVAL_AVOID_SIDE_EFFECTS);
1506 enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
1507 if (sub_op == BINOP_SUBSCRIPT
1508 || sub_op == STRUCTOP_MEMBER
1509 || sub_op == STRUCTOP_MPTR
1510 || sub_op == UNOP_IND
1511 || sub_op == STRUCTOP_STRUCT
1512 || sub_op == STRUCTOP_PTR
1513 || sub_op == OP_SCOPE)
1514 {
1515 struct type *type = value_type (result);
1516
1517 if (!TYPE_IS_REFERENCE (type))
1518 {
1519 type = lookup_lvalue_reference_type (type);
1520 result = allocate_value (type);
1521 }
1522 }
1523
1524 return result;
1525 }
1526 else
1527 error (_("Attempt to use a type as an expression"));
1528 }
1529
1530 enum exp_opcode opcode () const override
1531 { return OP_DECLTYPE; }
1532 };
1533
1534 /* Implement 'typeid'. */
1535 class typeid_operation
1536 : public tuple_holding_operation<operation_up>
1537 {
1538 public:
1539
1540 using tuple_holding_operation::tuple_holding_operation;
1541
1542 value *evaluate (struct type *expect_type,
1543 struct expression *exp,
1544 enum noside noside) override
1545 {
1546 enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
1547 enum noside sub_noside
1548 = ((sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
1549 ? EVAL_AVOID_SIDE_EFFECTS
1550 : noside);
1551
1552 value *result = std::get<0> (m_storage)->evaluate (nullptr, exp,
1553 sub_noside);
1554 if (noside != EVAL_NORMAL)
1555 return allocate_value (cplus_typeid_type (exp->gdbarch));
1556 return cplus_typeid (result);
1557 }
1558
1559 enum exp_opcode opcode () const override
1560 { return OP_TYPEID; }
1561 };
1562
1563 /* Implement the address-of operation. */
1564 class unop_addr_operation
1565 : public maybe_constant_operation<operation_up>
1566 {
1567 public:
1568
1569 using maybe_constant_operation::maybe_constant_operation;
1570
1571 value *evaluate (struct type *expect_type,
1572 struct expression *exp,
1573 enum noside noside) override
1574 {
1575 /* C++: check for and handle pointer to members. */
1576 if (noside == EVAL_SKIP)
1577 return eval_skip_value (exp);
1578 else
1579 return std::get<0> (m_storage)->evaluate_for_address (exp, noside);
1580 }
1581
1582 enum exp_opcode opcode () const override
1583 { return UNOP_ADDR; }
1584
1585 protected:
1586
1587 void do_generate_ax (struct expression *exp,
1588 struct agent_expr *ax,
1589 struct axs_value *value,
1590 struct type *cast_type)
1591 override
1592 {
1593 gen_expr_unop (exp, UNOP_ADDR,
1594 std::get<0> (this->m_storage).get (),
1595 ax, value);
1596 }
1597 };
1598
1599 /* Implement 'sizeof'. */
1600 class unop_sizeof_operation
1601 : public maybe_constant_operation<operation_up>
1602 {
1603 public:
1604
1605 using maybe_constant_operation::maybe_constant_operation;
1606
1607 value *evaluate (struct type *expect_type,
1608 struct expression *exp,
1609 enum noside noside) override
1610 {
1611 if (noside == EVAL_SKIP)
1612 return eval_skip_value (exp);
1613 return std::get<0> (m_storage)->evaluate_for_sizeof (exp, noside);
1614 }
1615
1616 enum exp_opcode opcode () const override
1617 { return UNOP_SIZEOF; }
1618
1619 protected:
1620
1621 void do_generate_ax (struct expression *exp,
1622 struct agent_expr *ax,
1623 struct axs_value *value,
1624 struct type *cast_type)
1625 override;
1626 };
1627
1628 /* Implement 'alignof'. */
1629 class unop_alignof_operation
1630 : public maybe_constant_operation<operation_up>
1631 {
1632 public:
1633
1634 using maybe_constant_operation::maybe_constant_operation;
1635
1636 value *evaluate (struct type *expect_type,
1637 struct expression *exp,
1638 enum noside noside) override
1639 {
1640 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1641 EVAL_AVOID_SIDE_EFFECTS);
1642 return eval_op_alignof (expect_type, exp, noside, val);
1643 }
1644
1645 enum exp_opcode opcode () const override
1646 { return UNOP_ALIGNOF; }
1647 };
1648
1649 /* Implement UNOP_MEMVAL. */
1650 class unop_memval_operation
1651 : public tuple_holding_operation<operation_up, struct type *>
1652 {
1653 public:
1654
1655 using tuple_holding_operation::tuple_holding_operation;
1656
1657 value *evaluate (struct type *expect_type,
1658 struct expression *exp,
1659 enum noside noside) override
1660 {
1661 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1662 return eval_op_memval (expect_type, exp, noside, val,
1663 std::get<1> (m_storage));
1664 }
1665
1666 value *evaluate_for_sizeof (struct expression *exp,
1667 enum noside noside) override;
1668
1669 value *evaluate_for_address (struct expression *exp,
1670 enum noside noside) override;
1671
1672 enum exp_opcode opcode () const override
1673 { return UNOP_MEMVAL; }
1674
1675 protected:
1676
1677 void do_generate_ax (struct expression *exp,
1678 struct agent_expr *ax,
1679 struct axs_value *value,
1680 struct type *cast_type)
1681 override;
1682 };
1683
1684 /* Implement UNOP_MEMVAL_TYPE. */
1685 class unop_memval_type_operation
1686 : public tuple_holding_operation<operation_up, operation_up>
1687 {
1688 public:
1689
1690 using tuple_holding_operation::tuple_holding_operation;
1691
1692 value *evaluate (struct type *expect_type,
1693 struct expression *exp,
1694 enum noside noside) override
1695 {
1696 value *typeval
1697 = std::get<0> (m_storage)->evaluate (expect_type, exp,
1698 EVAL_AVOID_SIDE_EFFECTS);
1699 struct type *type = value_type (typeval);
1700 value *val = std::get<1> (m_storage)->evaluate (expect_type, exp, noside);
1701 return eval_op_memval (expect_type, exp, noside, val, type);
1702 }
1703
1704 value *evaluate_for_sizeof (struct expression *exp,
1705 enum noside noside) override;
1706
1707 value *evaluate_for_address (struct expression *exp,
1708 enum noside noside) override;
1709
1710 enum exp_opcode opcode () const override
1711 { return UNOP_MEMVAL_TYPE; }
1712
1713 protected:
1714
1715 void do_generate_ax (struct expression *exp,
1716 struct agent_expr *ax,
1717 struct axs_value *value,
1718 struct type *cast_type)
1719 override;
1720 };
1721
1722 /* Implement the 'this' expression. */
1723 class op_this_operation
1724 : public tuple_holding_operation<>
1725 {
1726 public:
1727
1728 using tuple_holding_operation::tuple_holding_operation;
1729
1730 value *evaluate (struct type *expect_type,
1731 struct expression *exp,
1732 enum noside noside) override
1733 {
1734 return value_of_this (exp->language_defn);
1735 }
1736
1737 enum exp_opcode opcode () const override
1738 { return OP_THIS; }
1739
1740 protected:
1741
1742 void do_generate_ax (struct expression *exp,
1743 struct agent_expr *ax,
1744 struct axs_value *value,
1745 struct type *cast_type)
1746 override;
1747 };
1748
1749 /* Implement the "type instance" operation. */
1750 class type_instance_operation
1751 : public tuple_holding_operation<type_instance_flags, std::vector<type *>,
1752 operation_up>
1753 {
1754 public:
1755
1756 using tuple_holding_operation::tuple_holding_operation;
1757
1758 value *evaluate (struct type *expect_type,
1759 struct expression *exp,
1760 enum noside noside) override;
1761
1762 enum exp_opcode opcode () const override
1763 { return TYPE_INSTANCE; }
1764 };
1765
1766 /* The assignment operator. */
1767 class assign_operation
1768 : public tuple_holding_operation<operation_up, operation_up>
1769 {
1770 public:
1771
1772 using tuple_holding_operation::tuple_holding_operation;
1773
1774 value *evaluate (struct type *expect_type,
1775 struct expression *exp,
1776 enum noside noside) override
1777 {
1778 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1779 /* Special-case assignments where the left-hand-side is a
1780 convenience variable -- in these, don't bother setting an
1781 expected type. This avoids a weird case where re-assigning a
1782 string or array to an internal variable could error with "Too
1783 many array elements". */
1784 struct type *xtype = (VALUE_LVAL (lhs) == lval_internalvar
1785 ? nullptr
1786 : value_type (lhs));
1787 value *rhs = std::get<1> (m_storage)->evaluate (xtype, exp, noside);
1788
1789 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1790 return lhs;
1791 if (binop_user_defined_p (BINOP_ASSIGN, lhs, rhs))
1792 return value_x_binop (lhs, rhs, BINOP_ASSIGN, OP_NULL, noside);
1793 else
1794 return value_assign (lhs, rhs);
1795 }
1796
1797 enum exp_opcode opcode () const override
1798 { return BINOP_ASSIGN; }
1799
1800 protected:
1801
1802 void do_generate_ax (struct expression *exp,
1803 struct agent_expr *ax,
1804 struct axs_value *value,
1805 struct type *cast_type)
1806 override;
1807 };
1808
1809 /* Assignment with modification, like "+=". */
1810 class assign_modify_operation
1811 : public tuple_holding_operation<exp_opcode, operation_up, operation_up>
1812 {
1813 public:
1814
1815 using tuple_holding_operation::tuple_holding_operation;
1816
1817 value *evaluate (struct type *expect_type,
1818 struct expression *exp,
1819 enum noside noside) override
1820 {
1821 value *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1822 value *rhs = std::get<2> (m_storage)->evaluate (expect_type, exp, noside);
1823 return eval_binop_assign_modify (expect_type, exp, noside,
1824 std::get<0> (m_storage), lhs, rhs);
1825 }
1826
1827 enum exp_opcode opcode () const override
1828 { return BINOP_ASSIGN_MODIFY; }
1829
1830 protected:
1831
1832 void do_generate_ax (struct expression *exp,
1833 struct agent_expr *ax,
1834 struct axs_value *value,
1835 struct type *cast_type)
1836 override;
1837 };
1838
1839 /* A type cast. */
1840 class unop_cast_operation
1841 : public maybe_constant_operation<operation_up, struct type *>
1842 {
1843 public:
1844
1845 using maybe_constant_operation::maybe_constant_operation;
1846
1847 value *evaluate (struct type *expect_type,
1848 struct expression *exp,
1849 enum noside noside) override
1850 {
1851 return std::get<0> (m_storage)->evaluate_for_cast (std::get<1> (m_storage),
1852 exp, noside);
1853 }
1854
1855 enum exp_opcode opcode () const override
1856 { return UNOP_CAST; }
1857
1858 protected:
1859
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;
1865 };
1866
1867 } /* namespace expr */
1868
1869 #endif /* EXPOP_H */
This page took 0.076378 seconds and 5 git commands to generate.