Introduce array_operation
[deliverable/binutils-gdb.git] / gdb / expop.h
CommitLineData
e2803273
TT
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
31struct agent_expr;
32struct axs_value;
33
75f9892d
TT
34extern 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);
38extern 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);
9307d17b
TT
43extern 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);
75f9892d 47
d5ab122c
TT
48extern struct value *eval_op_scope (struct type *expect_type,
49 struct expression *exp,
50 enum noside noside,
51 struct type *type, const char *string);
0c8effa3
TT
52extern 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);
b5cc3923
TT
58extern struct value *eval_op_var_entry_value (struct type *expect_type,
59 struct expression *exp,
60 enum noside noside, symbol *sym);
17679395
TT
61extern 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);
55bdbff8
TT
65extern struct value *eval_op_register (struct type *expect_type,
66 struct expression *exp,
67 enum noside noside, const char *name);
b50db09f
TT
68extern struct value *eval_op_string (struct type *expect_type,
69 struct expression *exp,
70 enum noside noside, int len,
71 const char *string);
1594e0bb
TT
72extern 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);
808b22cf
TT
77extern 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);
ab0609be
TT
82extern 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);
07f724a8
TT
87extern struct value *eval_op_member (struct type *expect_type,
88 struct expression *exp,
89 enum noside noside,
90 struct value *arg1, struct value *arg2);
e51e26a0
TT
91extern struct value *eval_op_concat (struct type *expect_type,
92 struct expression *exp,
93 enum noside noside,
94 struct value *arg1, struct value *arg2);
a94323b6
TT
95extern struct value *eval_op_add (struct type *expect_type,
96 struct expression *exp,
97 enum noside noside,
98 struct value *arg1, struct value *arg2);
5133d78b
TT
99extern struct value *eval_op_sub (struct type *expect_type,
100 struct expression *exp,
101 enum noside noside,
102 struct value *arg1, struct value *arg2);
373907ff
TT
103extern 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);
224d6424
TT
107extern 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);
46916f2b
TT
112extern 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);
117extern 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);
122extern 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);
127extern 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);
132extern 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);
137extern 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);
d4eff4c1
TT
142extern 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);
9307d17b
TT
147extern 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);
151extern 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);
155extern 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);
160extern 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);
6d89e296
TT
165extern 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);
170extern 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);
175extern 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);
180extern 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);
876469ff
TT
185extern struct value *eval_op_ind (struct type *expect_type,
186 struct expression *exp,
187 enum noside noside,
188 struct value *arg1);
5b5f5140
TT
189extern struct value *eval_op_type (struct type *expect_type,
190 struct expression *exp,
191 enum noside noside, struct type *type);
ae4bb61e
TT
192extern struct value *eval_op_alignof (struct type *expect_type,
193 struct expression *exp,
194 enum noside noside,
195 struct value *arg1);
cbc18219
TT
196extern struct value *eval_op_memval (struct type *expect_type,
197 struct expression *exp,
198 enum noside noside,
199 struct value *arg1, struct type *type);
e5946e16
TT
200extern 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);
d5ab122c 206
e2803273
TT
207namespace 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. */
215static inline bool
216check_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
223static inline bool
224check_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
232static inline bool
233check_objfile (struct symbol *sym, struct objfile *objfile)
234{
235 return check_objfile (symbol_objfile (sym), objfile);
236}
237
238static inline bool
239check_objfile (const struct block *block, struct objfile *objfile)
240{
241 return check_objfile (block_objfile (block), objfile);
242}
243
244static inline bool
245check_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
252static inline bool
253check_objfile (internalvar *ivar, struct objfile *objfile)
254{
255 return false;
256}
257
258static inline bool
259check_objfile (const std::string &str, struct objfile *objfile)
260{
261 return false;
262}
263
264static inline bool
265check_objfile (const operation_up &op, struct objfile *objfile)
266{
267 return op->uses_objfile (objfile);
268}
269
270static inline bool
271check_objfile (enum exp_opcode val, struct objfile *objfile)
272{
273 return false;
274}
275
276static inline bool
277check_objfile (ULONGEST val, struct objfile *objfile)
278{
279 return false;
280}
281
282template<typename T>
283static inline bool
284check_objfile (enum_flags<T> val, struct objfile *objfile)
285{
286 return false;
287}
288
289template<typename T>
290static inline bool
291check_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
301template<typename S, typename T>
302static inline bool
303check_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
de401988
TT
309static inline void
310dump_for_expression (struct ui_file *stream, int depth,
311 const operation_up &op)
312{
313 op->dump (stream, depth);
314}
315
316extern void dump_for_expression (struct ui_file *stream, int depth,
317 enum exp_opcode op);
318extern void dump_for_expression (struct ui_file *stream, int depth,
319 const std::string &str);
320extern void dump_for_expression (struct ui_file *stream, int depth,
321 struct type *type);
322extern void dump_for_expression (struct ui_file *stream, int depth,
323 CORE_ADDR addr);
324extern void dump_for_expression (struct ui_file *stream, int depth,
325 internalvar *ivar);
326extern void dump_for_expression (struct ui_file *stream, int depth,
327 symbol *sym);
328extern void dump_for_expression (struct ui_file *stream, int depth,
329 minimal_symbol *msym);
330extern void dump_for_expression (struct ui_file *stream, int depth,
331 const block *bl);
332extern void dump_for_expression (struct ui_file *stream, int depth,
333 type_instance_flags flags);
334extern void dump_for_expression (struct ui_file *stream, int depth,
335 enum c_string_type_values flags);
336extern void dump_for_expression (struct ui_file *stream, int depth,
337 enum range_flag flags);
338extern void dump_for_expression (struct ui_file *stream, int depth,
339 objfile *objf);
340
341template<typename T>
342void
343dump_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
351template<typename X, typename Y>
352void
353dump_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
e2803273
TT
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. */
363template<typename... Arg>
364class tuple_holding_operation : public operation
365{
366public:
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 {
de401988
TT
382 dump_for_expression (stream, depth, opcode ());
383 do_dump<0, Arg...> (stream, depth + 1, m_storage);
e2803273
TT
384 }
385
386protected:
387
388 /* Storage for the data. */
389 std::tuple<Arg...> m_storage;
390
391private:
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 {
de401988 406 dump_for_expression (stream, depth, std::get<I> (value));
e2803273
TT
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
435static inline bool
436check_constant (const operation_up &item)
437{
438 return item->constant_p ();
439}
440
441static inline bool
442check_constant (struct minimal_symbol *msym)
443{
444 return false;
445}
446
447static inline bool
448check_constant (struct type *type)
449{
450 return true;
451}
452
453static inline bool
454check_constant (const struct block *block)
455{
456 return true;
457}
458
459static inline bool
460check_constant (const std::string &str)
461{
462 return true;
463}
464
465static inline bool
466check_constant (struct objfile *objfile)
467{
468 return true;
469}
470
471static inline bool
472check_constant (ULONGEST cst)
473{
474 return true;
475}
476
477static inline bool
478check_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
487template<typename T>
488static inline bool
489check_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
497template<typename S, typename T>
498static inline bool
499check_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. */
507template<typename... Arg>
508class maybe_constant_operation
509 : public tuple_holding_operation<Arg...>
510{
511public:
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
520private:
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
cae26a0c
TT
539/* A floating-point constant. The constant is encoded in the target
540 format. */
541
542typedef 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. */
549class float_const_operation
550 : public operation
551{
552public:
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
575private:
576
577 struct type *m_type;
578 float_data m_data;
579};
580
d5ab122c
TT
581class scope_operation
582 : public maybe_constant_operation<struct type *, std::string>
583{
584public:
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
603protected:
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
e82a5afc
TT
612/* Compute the value of a variable. */
613class var_value_operation
614 : public maybe_constant_operation<symbol *, const block *>
615{
616public:
617
618 using maybe_constant_operation::maybe_constant_operation;
619
620 value *evaluate (struct type *expect_type,
621 struct expression *exp,
622 enum noside noside) override;
623
624 value *evaluate_with_coercion (struct expression *exp,
625 enum noside noside) override;
626
627 value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
628 override;
629
630 value *evaluate_for_cast (struct type *expect_type,
631 struct expression *exp,
632 enum noside noside) override;
633
634 value *evaluate_for_address (struct expression *exp, enum noside noside)
635 override;
636
637 enum exp_opcode opcode () const override
638 { return OP_VAR_VALUE; }
639
640protected:
641
642 void do_generate_ax (struct expression *exp,
643 struct agent_expr *ax,
644 struct axs_value *value,
645 struct type *cast_type)
646 override;
647};
648
d336c29e
TT
649class long_const_operation
650 : public tuple_holding_operation<struct type *, LONGEST>
651{
652public:
653
654 using tuple_holding_operation::tuple_holding_operation;
655
656 value *evaluate (struct type *expect_type,
657 struct expression *exp,
658 enum noside noside) override
659 {
660 return value_from_longest (std::get<0> (m_storage),
661 std::get<1> (m_storage));
662 }
663
664 enum exp_opcode opcode () const override
665 { return OP_LONG; }
666
667 bool constant_p () const override
668 { return true; }
669
670protected:
671
672 void do_generate_ax (struct expression *exp,
673 struct agent_expr *ax,
674 struct axs_value *value,
675 struct type *cast_type)
676 override;
677};
678
0c8effa3
TT
679class var_msym_value_operation
680 : public maybe_constant_operation<minimal_symbol *, struct objfile *>
681{
682public:
683
684 using maybe_constant_operation::maybe_constant_operation;
685
686 value *evaluate (struct type *expect_type,
687 struct expression *exp,
688 enum noside noside) override
689 {
690 return eval_op_var_msym_value (expect_type, exp, noside, m_outermost,
691 std::get<0> (m_storage),
692 std::get<1> (m_storage));
693 }
694
695 value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
696 override;
697
698 value *evaluate_for_address (struct expression *exp, enum noside noside)
699 override;
700
701 value *evaluate_for_cast (struct type *expect_type,
702 struct expression *exp,
703 enum noside noside) override;
704
705 enum exp_opcode opcode () const override
706 { return OP_VAR_MSYM_VALUE; }
707
708 void set_outermost () override
709 {
710 m_outermost = true;
711 }
712
713protected:
714
715 /* True if this is the outermost operation in the expression. */
716 bool m_outermost = false;
717
718 void do_generate_ax (struct expression *exp,
719 struct agent_expr *ax,
720 struct axs_value *value,
721 struct type *cast_type)
722 override;
723};
724
b5cc3923
TT
725class var_entry_value_operation
726 : public tuple_holding_operation<symbol *>
727{
728public:
729
730 using tuple_holding_operation::tuple_holding_operation;
731
732 value *evaluate (struct type *expect_type,
733 struct expression *exp,
734 enum noside noside) override
735 {
736 return eval_op_var_entry_value (expect_type, exp, noside,
737 std::get<0> (m_storage));
738 }
739
740 enum exp_opcode opcode () const override
741 { return OP_VAR_ENTRY_VALUE; }
742};
743
17679395
TT
744class func_static_var_operation
745 : public maybe_constant_operation<operation_up, std::string>
746{
747public:
748
749 using maybe_constant_operation::maybe_constant_operation;
750
751 value *evaluate (struct type *expect_type,
752 struct expression *exp,
753 enum noside noside) override
754 {
755 value *func = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
756 return eval_op_func_static_var (expect_type, exp, noside, func,
757 std::get<1> (m_storage).c_str ());
758 }
759
760 enum exp_opcode opcode () const override
761 { return OP_FUNC_STATIC_VAR; }
762};
763
247d935b
TT
764class last_operation
765 : public tuple_holding_operation<int>
766{
767public:
768
769 using tuple_holding_operation::tuple_holding_operation;
770
771 value *evaluate (struct type *expect_type,
772 struct expression *exp,
773 enum noside noside) override
774 {
775 return access_value_history (std::get<0> (m_storage));
776 }
777
778 enum exp_opcode opcode () const override
779 { return OP_LAST; }
780};
781
55bdbff8
TT
782class register_operation
783 : public tuple_holding_operation<std::string>
784{
785public:
786
787 using tuple_holding_operation::tuple_holding_operation;
788
789 value *evaluate (struct type *expect_type,
790 struct expression *exp,
791 enum noside noside) override
792 {
793 return eval_op_register (expect_type, exp, noside,
794 std::get<0> (m_storage).c_str ());
795 }
796
797 enum exp_opcode opcode () const override
798 { return OP_REGISTER; }
799
800protected:
801
802 void do_generate_ax (struct expression *exp,
803 struct agent_expr *ax,
804 struct axs_value *value,
805 struct type *cast_type)
806 override;
807};
808
e6985c5e
TT
809class bool_operation
810 : public tuple_holding_operation<bool>
811{
812public:
813
814 using tuple_holding_operation::tuple_holding_operation;
815
816 value *evaluate (struct type *expect_type,
817 struct expression *exp,
818 enum noside noside) override
819 {
820 struct type *type = language_bool_type (exp->language_defn, exp->gdbarch);
821 return value_from_longest (type, std::get<0> (m_storage));
822 }
823
824 enum exp_opcode opcode () const override
825 { return OP_BOOL; }
826
827 bool constant_p () const override
828 { return true; }
829};
830
e6e01e16
TT
831class internalvar_operation
832 : public tuple_holding_operation<internalvar *>
833{
834public:
835
836 using tuple_holding_operation::tuple_holding_operation;
837
838 value *evaluate (struct type *expect_type,
839 struct expression *exp,
840 enum noside noside) override
841 {
842 return value_of_internalvar (exp->gdbarch,
843 std::get<0> (m_storage));
844 }
845
846 internalvar *get_internalvar () const
847 {
848 return std::get<0> (m_storage);
849 }
850
851 enum exp_opcode opcode () const override
852 { return OP_INTERNALVAR; }
853
854protected:
855
856 void do_generate_ax (struct expression *exp,
857 struct agent_expr *ax,
858 struct axs_value *value,
859 struct type *cast_type)
860 override;
861};
862
b50db09f
TT
863class string_operation
864 : public tuple_holding_operation<std::string>
865{
866public:
867
868 using tuple_holding_operation::tuple_holding_operation;
869
870 value *evaluate (struct type *expect_type,
871 struct expression *exp,
872 enum noside noside) override
873 {
874 const std::string &str = std::get<0> (m_storage);
875 return eval_op_string (expect_type, exp, noside,
876 str.size (), str.c_str ());
877 }
878
879 enum exp_opcode opcode () const override
880 { return OP_STRING; }
881};
882
1594e0bb
TT
883class ternop_slice_operation
884 : public maybe_constant_operation<operation_up, operation_up, operation_up>
885{
886public:
887
888 using maybe_constant_operation::maybe_constant_operation;
889
890 value *evaluate (struct type *expect_type,
891 struct expression *exp,
892 enum noside noside) override
893 {
894 struct value *array
895 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
896 struct value *low
897 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
898 struct value *upper
899 = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
900 return eval_op_ternop (expect_type, exp, noside, array, low, upper);
901 }
902
903 enum exp_opcode opcode () const override
904 { return TERNOP_SLICE; }
905};
906
9186293f
TT
907class ternop_cond_operation
908 : public maybe_constant_operation<operation_up, operation_up, operation_up>
909{
910public:
911
912 using maybe_constant_operation::maybe_constant_operation;
913
914 value *evaluate (struct type *expect_type,
915 struct expression *exp,
916 enum noside noside) override
917 {
918 struct value *val
919 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
920
921 if (value_logical_not (val))
922 return std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
923 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
924 }
925
926 enum exp_opcode opcode () const override
927 { return TERNOP_COND; }
928
929protected:
930
931 void do_generate_ax (struct expression *exp,
932 struct agent_expr *ax,
933 struct axs_value *value,
934 struct type *cast_type)
935 override;
936};
937
8cfd3e95
TT
938class complex_operation
939 : public maybe_constant_operation<operation_up, operation_up, struct type *>
940{
941public:
942
943 using maybe_constant_operation::maybe_constant_operation;
944
945 value *evaluate (struct type *expect_type,
946 struct expression *exp,
947 enum noside noside) override
948 {
949 value *real = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
950 value *imag = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
951 return value_literal_complex (real, imag,
952 std::get<2> (m_storage));
953 }
954
955 enum exp_opcode opcode () const override
956 { return OP_COMPLEX; }
957};
958
808b22cf
TT
959class structop_base_operation
960 : public tuple_holding_operation<operation_up, std::string>
961{
962public:
963
964 /* Used for completion. Return the field name. */
965 const std::string &get_string () const
966 {
967 return std::get<1> (m_storage);
968 }
969
970 /* Used for completion. Evaluate the LHS for type. */
971 value *evaluate_lhs (struct expression *exp)
972 {
973 return std::get<0> (m_storage)->evaluate (nullptr, exp,
974 EVAL_AVOID_SIDE_EFFECTS);
975 }
976
977protected:
978
979 using tuple_holding_operation::tuple_holding_operation;
980};
981
982class structop_operation
983 : public structop_base_operation
984{
985public:
986
987 using structop_base_operation::structop_base_operation;
988
989 value *evaluate (struct type *expect_type,
990 struct expression *exp,
991 enum noside noside) override
992 {
993 value *val =std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
994 return eval_op_structop_struct (expect_type, exp, noside, val,
995 std::get<1> (m_storage).c_str ());
996 }
997
998 enum exp_opcode opcode () const override
999 { return STRUCTOP_STRUCT; }
1000
1001protected:
1002
1003 void do_generate_ax (struct expression *exp,
1004 struct agent_expr *ax,
1005 struct axs_value *value,
1006 struct type *cast_type)
1007 override
1008 {
1009 gen_expr_structop (exp, STRUCTOP_STRUCT,
1010 std::get<0> (this->m_storage).get (),
1011 std::get<1> (this->m_storage).c_str (),
1012 ax, value);
1013 }
1014};
1015
ab0609be
TT
1016class structop_ptr_operation
1017 : public structop_base_operation
1018{
1019public:
1020
1021 using structop_base_operation::structop_base_operation;
1022
1023 value *evaluate (struct type *expect_type,
1024 struct expression *exp,
1025 enum noside noside) override
1026 {
1027 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1028 return eval_op_structop_ptr (expect_type, exp, noside, val,
1029 std::get<1> (m_storage).c_str ());
1030 }
1031
1032 enum exp_opcode opcode () const override
1033 { return STRUCTOP_PTR; }
1034
1035protected:
1036
1037 void do_generate_ax (struct expression *exp,
1038 struct agent_expr *ax,
1039 struct axs_value *value,
1040 struct type *cast_type)
1041 override
1042 {
1043 gen_expr_structop (exp, STRUCTOP_PTR,
1044 std::get<0> (this->m_storage).get (),
1045 std::get<1> (this->m_storage).c_str (),
1046 ax, value);
1047 }
1048};
1049
07f724a8
TT
1050class structop_member_operation
1051 : public tuple_holding_operation<operation_up, operation_up>
1052{
1053public:
1054
1055 using tuple_holding_operation::tuple_holding_operation;
1056
1057 value *evaluate (struct type *expect_type,
1058 struct expression *exp,
1059 enum noside noside) override
1060 {
1061 value *lhs
1062 = std::get<0> (m_storage)->evaluate_for_address (exp, noside);
1063 value *rhs
1064 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1065 return eval_op_member (expect_type, exp, noside, lhs, rhs);
1066 }
1067
1068 enum exp_opcode opcode () const override
1069 { return STRUCTOP_MEMBER; }
1070};
1071
1072class structop_mptr_operation
1073 : public tuple_holding_operation<operation_up, operation_up>
1074{
1075public:
1076
1077 using tuple_holding_operation::tuple_holding_operation;
1078
1079 value *evaluate (struct type *expect_type,
1080 struct expression *exp,
1081 enum noside noside) override
1082 {
1083 value *lhs
1084 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1085 value *rhs
1086 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1087 return eval_op_member (expect_type, exp, noside, lhs, rhs);
1088 }
1089
1090 enum exp_opcode opcode () const override
1091 { return STRUCTOP_MPTR; }
1092};
1093
e51e26a0
TT
1094class concat_operation
1095 : public maybe_constant_operation<operation_up, operation_up>
1096{
1097public:
1098
1099 using maybe_constant_operation::maybe_constant_operation;
1100
1101 value *evaluate (struct type *expect_type,
1102 struct expression *exp,
1103 enum noside noside) override
1104 {
1105 value *lhs
1106 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1107 value *rhs
1108 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1109 return eval_op_concat (expect_type, exp, noside, lhs, rhs);
1110 }
1111
1112 enum exp_opcode opcode () const override
1113 { return BINOP_CONCAT; }
1114};
1115
a94323b6
TT
1116class add_operation
1117 : public maybe_constant_operation<operation_up, operation_up>
1118{
1119public:
1120
1121 using maybe_constant_operation::maybe_constant_operation;
1122
1123 value *evaluate (struct type *expect_type,
1124 struct expression *exp,
1125 enum noside noside) override
1126 {
1127 value *lhs
1128 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1129 value *rhs
1130 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1131 return eval_op_add (expect_type, exp, noside, lhs, rhs);
1132 }
1133
1134 enum exp_opcode opcode () const override
1135 { return BINOP_ADD; }
1136
1137protected:
1138
1139 void do_generate_ax (struct expression *exp,
1140 struct agent_expr *ax,
1141 struct axs_value *value,
1142 struct type *cast_type)
1143 override
1144 {
1145 gen_expr_binop (exp, BINOP_ADD,
1146 std::get<0> (this->m_storage).get (),
1147 std::get<1> (this->m_storage).get (),
1148 ax, value);
1149 }
1150};
1151
5133d78b
TT
1152class sub_operation
1153 : public maybe_constant_operation<operation_up, operation_up>
1154{
1155public:
1156
1157 using maybe_constant_operation::maybe_constant_operation;
1158
1159 value *evaluate (struct type *expect_type,
1160 struct expression *exp,
1161 enum noside noside) override
1162 {
1163 value *lhs
1164 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1165 value *rhs
1166 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1167 return eval_op_sub (expect_type, exp, noside, lhs, rhs);
1168 }
1169
1170 enum exp_opcode opcode () const override
1171 { return BINOP_SUB; }
1172
1173protected:
1174
1175 void do_generate_ax (struct expression *exp,
1176 struct agent_expr *ax,
1177 struct axs_value *value,
1178 struct type *cast_type)
1179 override
1180 {
1181 gen_expr_binop (exp, BINOP_SUB,
1182 std::get<0> (this->m_storage).get (),
1183 std::get<1> (this->m_storage).get (),
1184 ax, value);
1185 }
1186};
1187
373907ff
TT
1188typedef struct value *binary_ftype (struct type *expect_type,
1189 struct expression *exp,
1190 enum noside noside, enum exp_opcode op,
1191 struct value *arg1, struct value *arg2);
1192
1193template<enum exp_opcode OP, binary_ftype FUNC>
1194class binop_operation
1195 : public maybe_constant_operation<operation_up, operation_up>
1196{
1197public:
1198
1199 using maybe_constant_operation::maybe_constant_operation;
1200
1201 value *evaluate (struct type *expect_type,
1202 struct expression *exp,
1203 enum noside noside) override
1204 {
1205 value *lhs
1206 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1207 value *rhs
1208 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1209 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
1210 }
1211
1212 enum exp_opcode opcode () const override
1213 { return OP; }
1214};
1215
1216template<enum exp_opcode OP, binary_ftype FUNC>
1217class usual_ax_binop_operation
1218 : public binop_operation<OP, FUNC>
1219{
1220public:
1221
1222 using binop_operation<OP, FUNC>::binop_operation;
1223
1224protected:
1225
1226 void do_generate_ax (struct expression *exp,
1227 struct agent_expr *ax,
1228 struct axs_value *value,
1229 struct type *cast_type)
1230 override
1231 {
1232 gen_expr_binop (exp, OP,
1233 std::get<0> (this->m_storage).get (),
1234 std::get<1> (this->m_storage).get (),
1235 ax, value);
1236 }
1237};
1238
1239using exp_operation = binop_operation<BINOP_EXP, eval_op_binary>;
1240using intdiv_operation = binop_operation<BINOP_INTDIV, eval_op_binary>;
1241using mod_operation = binop_operation<BINOP_MOD, eval_op_binary>;
1242
1243using mul_operation = usual_ax_binop_operation<BINOP_MUL, eval_op_binary>;
1244using div_operation = usual_ax_binop_operation<BINOP_DIV, eval_op_binary>;
1245using rem_operation = usual_ax_binop_operation<BINOP_REM, eval_op_binary>;
1246using lsh_operation = usual_ax_binop_operation<BINOP_LSH, eval_op_binary>;
1247using rsh_operation = usual_ax_binop_operation<BINOP_RSH, eval_op_binary>;
1248using bitwise_and_operation
1249 = usual_ax_binop_operation<BINOP_BITWISE_AND, eval_op_binary>;
1250using bitwise_ior_operation
1251 = usual_ax_binop_operation<BINOP_BITWISE_IOR, eval_op_binary>;
1252using bitwise_xor_operation
1253 = usual_ax_binop_operation<BINOP_BITWISE_XOR, eval_op_binary>;
1254
224d6424
TT
1255class subscript_operation
1256 : public usual_ax_binop_operation<BINOP_SUBSCRIPT, eval_op_subscript>
1257{
1258public:
1259 using usual_ax_binop_operation<BINOP_SUBSCRIPT,
1260 eval_op_subscript>::usual_ax_binop_operation;
1261
1262 value *evaluate_for_sizeof (struct expression *exp,
1263 enum noside noside) override;
1264};
1265
46916f2b
TT
1266/* Implementation of comparison operations. */
1267template<enum exp_opcode OP, binary_ftype FUNC>
1268class comparison_operation
1269 : public usual_ax_binop_operation<OP, FUNC>
1270{
1271public:
1272
1273 using usual_ax_binop_operation<OP, FUNC>::usual_ax_binop_operation;
1274
1275 value *evaluate (struct type *expect_type,
1276 struct expression *exp,
1277 enum noside noside) override
1278 {
1279 value *lhs
1280 = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside);
1281 value *rhs
1282 = std::get<1> (this->m_storage)->evaluate (value_type (lhs), exp,
1283 noside);
1284 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
1285 }
1286};
1287
1288using equal_operation = comparison_operation<BINOP_EQUAL, eval_op_equal>;
1289using notequal_operation
1290 = comparison_operation<BINOP_NOTEQUAL, eval_op_notequal>;
1291using less_operation = comparison_operation<BINOP_LESS, eval_op_less>;
1292using gtr_operation = comparison_operation<BINOP_GTR, eval_op_gtr>;
1293using geq_operation = comparison_operation<BINOP_GEQ, eval_op_geq>;
1294using leq_operation = comparison_operation<BINOP_LEQ, eval_op_leq>;
1295
d4eff4c1
TT
1296/* Implement the GDB '@' repeat operator. */
1297class repeat_operation
1298 : public binop_operation<BINOP_REPEAT, eval_op_repeat>
1299{
1300 using binop_operation<BINOP_REPEAT, eval_op_repeat>::binop_operation;
1301
1302protected:
1303
1304 void do_generate_ax (struct expression *exp,
1305 struct agent_expr *ax,
1306 struct axs_value *value,
1307 struct type *cast_type)
1308 override;
1309};
1310
ae64ba58
TT
1311/* C-style comma operator. */
1312class comma_operation
1313 : public maybe_constant_operation<operation_up, operation_up>
1314{
1315public:
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 /* The left-hand-side is only evaluated for side effects, so don't
1324 bother in other modes. */
1325 if (noside == EVAL_NORMAL)
1326 std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1327 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1328 }
1329
1330 enum exp_opcode opcode () const override
1331 { return BINOP_COMMA; }
1332
1333protected:
1334
1335 void do_generate_ax (struct expression *exp,
1336 struct agent_expr *ax,
1337 struct axs_value *value,
1338 struct type *cast_type)
1339 override;
1340};
1341
9307d17b
TT
1342typedef struct value *unary_ftype (struct type *expect_type,
1343 struct expression *exp,
1344 enum noside noside, enum exp_opcode op,
1345 struct value *arg1);
1346
1347/* Base class for unary operations. */
1348template<enum exp_opcode OP, unary_ftype FUNC>
1349class unop_operation
1350 : public maybe_constant_operation<operation_up>
1351{
1352public:
1353
1354 using maybe_constant_operation::maybe_constant_operation;
1355
1356 value *evaluate (struct type *expect_type,
1357 struct expression *exp,
1358 enum noside noside) override
1359 {
1360 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1361 return FUNC (expect_type, exp, noside, OP, val);
1362 }
1363
1364 enum exp_opcode opcode () const override
1365 { return OP; }
1366};
1367
1368/* Unary operations that can also be turned into agent expressions in
1369 the "usual" way. */
1370template<enum exp_opcode OP, unary_ftype FUNC>
1371class usual_ax_unop_operation
1372 : public unop_operation<OP, FUNC>
1373{
1374 using unop_operation<OP, FUNC>::unop_operation;
1375
1376protected:
1377
1378 void do_generate_ax (struct expression *exp,
1379 struct agent_expr *ax,
1380 struct axs_value *value,
1381 struct type *cast_type)
1382 override
1383 {
1384 gen_expr_unop (exp, OP,
1385 std::get<0> (this->m_storage).get (),
1386 ax, value);
1387 }
1388};
1389
1390using unary_plus_operation = usual_ax_unop_operation<UNOP_PLUS, eval_op_plus>;
1391using unary_neg_operation = usual_ax_unop_operation<UNOP_NEG, eval_op_neg>;
1392using unary_complement_operation
1393 = usual_ax_unop_operation<UNOP_COMPLEMENT, eval_op_complement>;
1394using unary_logical_not_operation
1395 = usual_ax_unop_operation<UNOP_LOGICAL_NOT, eval_op_lognot>;
1396
6d89e296
TT
1397/* Handle pre- and post- increment and -decrement. */
1398template<enum exp_opcode OP, unary_ftype FUNC>
1399class unop_incr_operation
1400 : public tuple_holding_operation<operation_up>
1401{
1402public:
1403
1404 using tuple_holding_operation::tuple_holding_operation;
1405
1406 value *evaluate (struct type *expect_type,
1407 struct expression *exp,
1408 enum noside noside) override
1409 {
1410 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1411 return FUNC (expect_type, exp, noside, OP, val);
1412 }
1413
1414 enum exp_opcode opcode () const override
1415 { return OP; }
1416};
1417
1418using preinc_operation
1419 = unop_incr_operation<UNOP_PREINCREMENT, eval_op_preinc>;
1420using predec_operation
1421 = unop_incr_operation<UNOP_PREDECREMENT, eval_op_predec>;
1422using postinc_operation
1423 = unop_incr_operation<UNOP_POSTINCREMENT, eval_op_postinc>;
1424using postdec_operation
1425 = unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>;
1426
876469ff
TT
1427/* Base class for implementations of UNOP_IND. */
1428class unop_ind_base_operation
1429 : public tuple_holding_operation<operation_up>
1430{
1431public:
1432
1433 using tuple_holding_operation::tuple_holding_operation;
1434
1435 value *evaluate (struct type *expect_type,
1436 struct expression *exp,
1437 enum noside noside) override
1438 {
1439 if (expect_type != nullptr && expect_type->code () == TYPE_CODE_PTR)
1440 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
1441 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1442 return eval_op_ind (expect_type, exp, noside, val);
1443 }
1444
1445 value *evaluate_for_address (struct expression *exp,
1446 enum noside noside) override;
1447
1448 value *evaluate_for_sizeof (struct expression *exp,
1449 enum noside noside) override;
1450
1451 enum exp_opcode opcode () const override
1452 { return UNOP_IND; }
1453};
1454
1455/* Ordinary UNOP_IND implementation. */
1456class unop_ind_operation
1457 : public unop_ind_base_operation
1458{
1459public:
1460
1461 using unop_ind_base_operation::unop_ind_base_operation;
1462
1463protected:
1464
1465 void do_generate_ax (struct expression *exp,
1466 struct agent_expr *ax,
1467 struct axs_value *value,
1468 struct type *cast_type)
1469 override
1470 {
1471 gen_expr_unop (exp, UNOP_IND,
1472 std::get<0> (this->m_storage).get (),
1473 ax, value);
1474 }
1475};
1476
5b5f5140
TT
1477/* Implement OP_TYPE. */
1478class type_operation
1479 : public tuple_holding_operation<struct type *>
1480{
1481public:
1482
1483 using tuple_holding_operation::tuple_holding_operation;
1484
1485 value *evaluate (struct type *expect_type,
1486 struct expression *exp,
1487 enum noside noside) override
1488 {
1489 return eval_op_type (expect_type, exp, noside, std::get<0> (m_storage));
1490 }
1491
1492 enum exp_opcode opcode () const override
1493 { return OP_TYPE; }
1494
1495 bool constant_p () const override
1496 { return true; }
1497};
1498
4efc574c
TT
1499/* Implement the "typeof" operation. */
1500class typeof_operation
1501 : public maybe_constant_operation<operation_up>
1502{
1503public:
1504
1505 using maybe_constant_operation::maybe_constant_operation;
1506
1507 value *evaluate (struct type *expect_type,
1508 struct expression *exp,
1509 enum noside noside) override
1510 {
1511 if (noside == EVAL_SKIP)
1512 return eval_skip_value (exp);
1513 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1514 return std::get<0> (m_storage)->evaluate (nullptr, exp,
1515 EVAL_AVOID_SIDE_EFFECTS);
1516 else
1517 error (_("Attempt to use a type as an expression"));
1518 }
1519
1520 enum exp_opcode opcode () const override
1521 { return OP_TYPEOF; }
1522};
1523
0af8829e
TT
1524/* Implement 'decltype'. */
1525class decltype_operation
1526 : public maybe_constant_operation<operation_up>
1527{
1528public:
1529
1530 using maybe_constant_operation::maybe_constant_operation;
1531
1532 value *evaluate (struct type *expect_type,
1533 struct expression *exp,
1534 enum noside noside) override
1535 {
1536 if (noside == EVAL_SKIP)
1537 return eval_skip_value (exp);
1538 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1539 {
1540 value *result
1541 = std::get<0> (m_storage)->evaluate (nullptr, exp,
1542 EVAL_AVOID_SIDE_EFFECTS);
1543 enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
1544 if (sub_op == BINOP_SUBSCRIPT
1545 || sub_op == STRUCTOP_MEMBER
1546 || sub_op == STRUCTOP_MPTR
1547 || sub_op == UNOP_IND
1548 || sub_op == STRUCTOP_STRUCT
1549 || sub_op == STRUCTOP_PTR
1550 || sub_op == OP_SCOPE)
1551 {
1552 struct type *type = value_type (result);
1553
1554 if (!TYPE_IS_REFERENCE (type))
1555 {
1556 type = lookup_lvalue_reference_type (type);
1557 result = allocate_value (type);
1558 }
1559 }
1560
1561 return result;
1562 }
1563 else
1564 error (_("Attempt to use a type as an expression"));
1565 }
1566
1567 enum exp_opcode opcode () const override
1568 { return OP_DECLTYPE; }
1569};
1570
929f3aa7
TT
1571/* Implement 'typeid'. */
1572class typeid_operation
1573 : public tuple_holding_operation<operation_up>
1574{
1575public:
1576
1577 using tuple_holding_operation::tuple_holding_operation;
1578
1579 value *evaluate (struct type *expect_type,
1580 struct expression *exp,
1581 enum noside noside) override
1582 {
1583 enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
1584 enum noside sub_noside
1585 = ((sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
1586 ? EVAL_AVOID_SIDE_EFFECTS
1587 : noside);
1588
1589 value *result = std::get<0> (m_storage)->evaluate (nullptr, exp,
1590 sub_noside);
1591 if (noside != EVAL_NORMAL)
1592 return allocate_value (cplus_typeid_type (exp->gdbarch));
1593 return cplus_typeid (result);
1594 }
1595
1596 enum exp_opcode opcode () const override
1597 { return OP_TYPEID; }
1598};
1599
14aff815
TT
1600/* Implement the address-of operation. */
1601class unop_addr_operation
1602 : public maybe_constant_operation<operation_up>
1603{
1604public:
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 /* C++: check for and handle pointer to members. */
1613 if (noside == EVAL_SKIP)
1614 return eval_skip_value (exp);
1615 else
1616 return std::get<0> (m_storage)->evaluate_for_address (exp, noside);
1617 }
1618
1619 enum exp_opcode opcode () const override
1620 { return UNOP_ADDR; }
1621
1622protected:
1623
1624 void do_generate_ax (struct expression *exp,
1625 struct agent_expr *ax,
1626 struct axs_value *value,
1627 struct type *cast_type)
1628 override
1629 {
1630 gen_expr_unop (exp, UNOP_ADDR,
1631 std::get<0> (this->m_storage).get (),
1632 ax, value);
1633 }
1634};
1635
85d23bda
TT
1636/* Implement 'sizeof'. */
1637class unop_sizeof_operation
1638 : public maybe_constant_operation<operation_up>
1639{
1640public:
1641
1642 using maybe_constant_operation::maybe_constant_operation;
1643
1644 value *evaluate (struct type *expect_type,
1645 struct expression *exp,
1646 enum noside noside) override
1647 {
1648 if (noside == EVAL_SKIP)
1649 return eval_skip_value (exp);
1650 return std::get<0> (m_storage)->evaluate_for_sizeof (exp, noside);
1651 }
1652
1653 enum exp_opcode opcode () const override
1654 { return UNOP_SIZEOF; }
1655
1656protected:
1657
1658 void do_generate_ax (struct expression *exp,
1659 struct agent_expr *ax,
1660 struct axs_value *value,
1661 struct type *cast_type)
1662 override;
1663};
1664
ae4bb61e
TT
1665/* Implement 'alignof'. */
1666class unop_alignof_operation
1667 : public maybe_constant_operation<operation_up>
1668{
1669public:
1670
1671 using maybe_constant_operation::maybe_constant_operation;
1672
1673 value *evaluate (struct type *expect_type,
1674 struct expression *exp,
1675 enum noside noside) override
1676 {
1677 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1678 EVAL_AVOID_SIDE_EFFECTS);
1679 return eval_op_alignof (expect_type, exp, noside, val);
1680 }
1681
1682 enum exp_opcode opcode () const override
1683 { return UNOP_ALIGNOF; }
1684};
1685
cbc18219
TT
1686/* Implement UNOP_MEMVAL. */
1687class unop_memval_operation
1688 : public tuple_holding_operation<operation_up, struct type *>
1689{
1690public:
1691
1692 using tuple_holding_operation::tuple_holding_operation;
1693
1694 value *evaluate (struct type *expect_type,
1695 struct expression *exp,
1696 enum noside noside) override
1697 {
1698 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1699 return eval_op_memval (expect_type, exp, noside, val,
1700 std::get<1> (m_storage));
1701 }
1702
1703 value *evaluate_for_sizeof (struct expression *exp,
1704 enum noside noside) override;
1705
1706 value *evaluate_for_address (struct expression *exp,
1707 enum noside noside) override;
1708
1709 enum exp_opcode opcode () const override
1710 { return UNOP_MEMVAL; }
1711
1712protected:
1713
1714 void do_generate_ax (struct expression *exp,
1715 struct agent_expr *ax,
1716 struct axs_value *value,
1717 struct type *cast_type)
1718 override;
1719};
1720
1721/* Implement UNOP_MEMVAL_TYPE. */
1722class unop_memval_type_operation
1723 : public tuple_holding_operation<operation_up, operation_up>
1724{
1725public:
1726
1727 using tuple_holding_operation::tuple_holding_operation;
1728
1729 value *evaluate (struct type *expect_type,
1730 struct expression *exp,
1731 enum noside noside) override
1732 {
1733 value *typeval
1734 = std::get<0> (m_storage)->evaluate (expect_type, exp,
1735 EVAL_AVOID_SIDE_EFFECTS);
1736 struct type *type = value_type (typeval);
1737 value *val = std::get<1> (m_storage)->evaluate (expect_type, exp, noside);
1738 return eval_op_memval (expect_type, exp, noside, val, type);
1739 }
1740
1741 value *evaluate_for_sizeof (struct expression *exp,
1742 enum noside noside) override;
1743
1744 value *evaluate_for_address (struct expression *exp,
1745 enum noside noside) override;
1746
1747 enum exp_opcode opcode () const override
1748 { return UNOP_MEMVAL_TYPE; }
1749
1750protected:
1751
1752 void do_generate_ax (struct expression *exp,
1753 struct agent_expr *ax,
1754 struct axs_value *value,
1755 struct type *cast_type)
1756 override;
1757};
1758
f6b42326
TT
1759/* Implement the 'this' expression. */
1760class op_this_operation
1761 : public tuple_holding_operation<>
1762{
1763public:
1764
1765 using tuple_holding_operation::tuple_holding_operation;
1766
1767 value *evaluate (struct type *expect_type,
1768 struct expression *exp,
1769 enum noside noside) override
1770 {
1771 return value_of_this (exp->language_defn);
1772 }
1773
1774 enum exp_opcode opcode () const override
1775 { return OP_THIS; }
1776
1777protected:
1778
1779 void do_generate_ax (struct expression *exp,
1780 struct agent_expr *ax,
1781 struct axs_value *value,
1782 struct type *cast_type)
1783 override;
1784};
1785
44b675c8
TT
1786/* Implement the "type instance" operation. */
1787class type_instance_operation
1788 : public tuple_holding_operation<type_instance_flags, std::vector<type *>,
1789 operation_up>
1790{
1791public:
1792
1793 using tuple_holding_operation::tuple_holding_operation;
1794
1795 value *evaluate (struct type *expect_type,
1796 struct expression *exp,
1797 enum noside noside) override;
1798
1799 enum exp_opcode opcode () const override
1800 { return TYPE_INSTANCE; }
1801};
1802
40786782
TT
1803/* The assignment operator. */
1804class assign_operation
1805 : public tuple_holding_operation<operation_up, operation_up>
1806{
1807public:
1808
1809 using tuple_holding_operation::tuple_holding_operation;
1810
1811 value *evaluate (struct type *expect_type,
1812 struct expression *exp,
1813 enum noside noside) override
1814 {
1815 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1816 /* Special-case assignments where the left-hand-side is a
1817 convenience variable -- in these, don't bother setting an
1818 expected type. This avoids a weird case where re-assigning a
1819 string or array to an internal variable could error with "Too
1820 many array elements". */
1821 struct type *xtype = (VALUE_LVAL (lhs) == lval_internalvar
1822 ? nullptr
1823 : value_type (lhs));
1824 value *rhs = std::get<1> (m_storage)->evaluate (xtype, exp, noside);
1825
1826 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1827 return lhs;
1828 if (binop_user_defined_p (BINOP_ASSIGN, lhs, rhs))
1829 return value_x_binop (lhs, rhs, BINOP_ASSIGN, OP_NULL, noside);
1830 else
1831 return value_assign (lhs, rhs);
1832 }
1833
1834 enum exp_opcode opcode () const override
1835 { return BINOP_ASSIGN; }
1836
1837protected:
1838
1839 void do_generate_ax (struct expression *exp,
1840 struct agent_expr *ax,
1841 struct axs_value *value,
1842 struct type *cast_type)
1843 override;
1844};
1845
e5946e16
TT
1846/* Assignment with modification, like "+=". */
1847class assign_modify_operation
1848 : public tuple_holding_operation<exp_opcode, operation_up, operation_up>
1849{
1850public:
1851
1852 using tuple_holding_operation::tuple_holding_operation;
1853
1854 value *evaluate (struct type *expect_type,
1855 struct expression *exp,
1856 enum noside noside) override
1857 {
1858 value *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1859 value *rhs = std::get<2> (m_storage)->evaluate (expect_type, exp, noside);
1860 return eval_binop_assign_modify (expect_type, exp, noside,
1861 std::get<0> (m_storage), lhs, rhs);
1862 }
1863
1864 enum exp_opcode opcode () const override
1865 { return BINOP_ASSIGN_MODIFY; }
1866
1867protected:
1868
1869 void do_generate_ax (struct expression *exp,
1870 struct agent_expr *ax,
1871 struct axs_value *value,
1872 struct type *cast_type)
1873 override;
1874};
1875
165a813a
TT
1876/* A type cast. */
1877class unop_cast_operation
1878 : public maybe_constant_operation<operation_up, struct type *>
1879{
1880public:
1881
1882 using maybe_constant_operation::maybe_constant_operation;
1883
1884 value *evaluate (struct type *expect_type,
1885 struct expression *exp,
1886 enum noside noside) override
1887 {
1888 return std::get<0> (m_storage)->evaluate_for_cast (std::get<1> (m_storage),
1889 exp, noside);
1890 }
1891
1892 enum exp_opcode opcode () const override
1893 { return UNOP_CAST; }
1894
1895protected:
1896
1897 void do_generate_ax (struct expression *exp,
1898 struct agent_expr *ax,
1899 struct axs_value *value,
1900 struct type *cast_type)
1901 override;
1902};
1903
292382f4
TT
1904/* A cast, but the type comes from an expression, not a "struct
1905 type". */
1906class unop_cast_type_operation
1907 : public maybe_constant_operation<operation_up, operation_up>
1908{
1909public:
1910
1911 using maybe_constant_operation::maybe_constant_operation;
1912
1913 value *evaluate (struct type *expect_type,
1914 struct expression *exp,
1915 enum noside noside) override
1916 {
1917 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1918 EVAL_AVOID_SIDE_EFFECTS);
1919 return std::get<1> (m_storage)->evaluate_for_cast (value_type (val),
1920 exp, noside);
1921 }
1922
1923 enum exp_opcode opcode () const override
1924 { return UNOP_CAST_TYPE; }
1925
1926protected:
1927
1928 void do_generate_ax (struct expression *exp,
1929 struct agent_expr *ax,
1930 struct axs_value *value,
1931 struct type *cast_type)
1932 override;
1933};
1934
d9ad79d8
TT
1935typedef value *cxx_cast_ftype (struct type *, value *);
1936
1937/* This implements dynamic_cast and reinterpret_cast. static_cast and
1938 const_cast are handled by the ordinary case operations. */
1939template<exp_opcode OP, cxx_cast_ftype FUNC>
1940class cxx_cast_operation
1941 : public maybe_constant_operation<operation_up, operation_up>
1942{
1943public:
1944
1945 using maybe_constant_operation::maybe_constant_operation;
1946
1947 value *evaluate (struct type *expect_type,
1948 struct expression *exp,
1949 enum noside noside) override
1950 {
1951 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1952 EVAL_AVOID_SIDE_EFFECTS);
1953 struct type *type = value_type (val);
1954 value *rhs = std::get<1> (m_storage)->evaluate (type, exp, noside);
1955 if (noside == EVAL_SKIP)
1956 return eval_skip_value (exp);
1957 return FUNC (type, rhs);
1958 }
1959
1960 enum exp_opcode opcode () const override
1961 { return OP; }
1962};
1963
1964using dynamic_cast_operation = cxx_cast_operation<UNOP_DYNAMIC_CAST,
1965 value_dynamic_cast>;
1966using reinterpret_cast_operation = cxx_cast_operation<UNOP_REINTERPRET_CAST,
1967 value_reinterpret_cast>;
1968
821e72d7
TT
1969/* Multi-dimensional subscripting. */
1970class multi_subscript_operation
1971 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
1972{
1973public:
1974
1975 using tuple_holding_operation::tuple_holding_operation;
1976
1977 value *evaluate (struct type *expect_type,
1978 struct expression *exp,
1979 enum noside noside) override;
1980
1981 enum exp_opcode opcode () const override
1982 { return MULTI_SUBSCRIPT; }
1983};
1984
5019124b
TT
1985/* The "&&" operator. */
1986class logical_and_operation
1987 : public maybe_constant_operation<operation_up, operation_up>
1988{
1989public:
1990
1991 using maybe_constant_operation::maybe_constant_operation;
1992
1993 value *evaluate (struct type *expect_type,
1994 struct expression *exp,
1995 enum noside noside) override;
1996
1997 enum exp_opcode opcode () const override
1998 { return BINOP_LOGICAL_AND; }
1999
2000protected:
2001
2002 void do_generate_ax (struct expression *exp,
2003 struct agent_expr *ax,
2004 struct axs_value *value,
2005 struct type *cast_type)
2006 override;
2007};
2008
2009/* The "||" operator. */
2010class logical_or_operation
2011 : public maybe_constant_operation<operation_up, operation_up>
2012{
2013public:
2014
2015 using maybe_constant_operation::maybe_constant_operation;
2016
2017 value *evaluate (struct type *expect_type,
2018 struct expression *exp,
2019 enum noside noside) override;
2020
2021 enum exp_opcode opcode () const override
2022 { return BINOP_LOGICAL_OR; }
2023
2024protected:
2025
2026 void do_generate_ax (struct expression *exp,
2027 struct agent_expr *ax,
2028 struct axs_value *value,
2029 struct type *cast_type)
2030 override;
2031};
2032
e4479080
TT
2033/* This class implements ADL (aka Koenig) function calls for C++. It
2034 holds the name of the function to call, the block in which the
2035 lookup should be done, and a vector of arguments. */
2036class adl_func_operation
2037 : public tuple_holding_operation<std::string, const block *,
2038 std::vector<operation_up>>
2039{
2040public:
2041
2042 using tuple_holding_operation::tuple_holding_operation;
2043
2044 value *evaluate (struct type *expect_type,
2045 struct expression *exp,
2046 enum noside noside) override;
2047
2048 enum exp_opcode opcode () const override
2049 { return OP_ADL_FUNC; }
2050};
2051
1c02eb30
TT
2052/* The OP_ARRAY operation. */
2053class array_operation
2054 : public tuple_holding_operation<int, int, std::vector<operation_up>>
2055{
2056public:
2057
2058 using tuple_holding_operation::tuple_holding_operation;
2059
2060 value *evaluate (struct type *expect_type,
2061 struct expression *exp,
2062 enum noside noside) override;
2063
2064 enum exp_opcode opcode () const override
2065 { return OP_ARRAY; }
2066
2067private:
2068
2069 struct value *evaluate_struct_tuple (struct value *struct_val,
2070 struct expression *exp,
2071 enum noside noside, int nargs);
2072};
2073
e2803273
TT
2074} /* namespace expr */
2075
2076#endif /* EXPOP_H */
This page took 0.106651 seconds and 4 git commands to generate.