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