Automatic date update in version.in
[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,
9c79936b 56 bound_minimal_symbol msymbol);
b5cc3923
TT
57extern struct value *eval_op_var_entry_value (struct type *expect_type,
58 struct expression *exp,
59 enum noside noside, symbol *sym);
17679395
TT
60extern 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);
55bdbff8
TT
64extern struct value *eval_op_register (struct type *expect_type,
65 struct expression *exp,
66 enum noside noside, const char *name);
b50db09f
TT
67extern struct value *eval_op_string (struct type *expect_type,
68 struct expression *exp,
69 enum noside noside, int len,
70 const char *string);
1594e0bb
TT
71extern 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);
808b22cf
TT
76extern 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);
ab0609be
TT
81extern 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);
07f724a8
TT
86extern struct value *eval_op_member (struct type *expect_type,
87 struct expression *exp,
88 enum noside noside,
89 struct value *arg1, struct value *arg2);
e51e26a0
TT
90extern struct value *eval_op_concat (struct type *expect_type,
91 struct expression *exp,
92 enum noside noside,
93 struct value *arg1, struct value *arg2);
a94323b6
TT
94extern struct value *eval_op_add (struct type *expect_type,
95 struct expression *exp,
96 enum noside noside,
97 struct value *arg1, struct value *arg2);
5133d78b
TT
98extern struct value *eval_op_sub (struct type *expect_type,
99 struct expression *exp,
100 enum noside noside,
101 struct value *arg1, struct value *arg2);
373907ff
TT
102extern 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);
224d6424
TT
106extern 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);
46916f2b
TT
111extern 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);
116extern 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);
121extern 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);
126extern 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);
131extern 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);
136extern 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);
d4eff4c1
TT
141extern 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);
9307d17b
TT
146extern 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);
150extern 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);
154extern 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);
159extern 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);
6d89e296
TT
164extern 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);
169extern 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);
174extern 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);
179extern 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);
876469ff
TT
184extern struct value *eval_op_ind (struct type *expect_type,
185 struct expression *exp,
186 enum noside noside,
187 struct value *arg1);
5b5f5140
TT
188extern struct value *eval_op_type (struct type *expect_type,
189 struct expression *exp,
190 enum noside noside, struct type *type);
ae4bb61e
TT
191extern struct value *eval_op_alignof (struct type *expect_type,
192 struct expression *exp,
193 enum noside noside,
194 struct value *arg1);
cbc18219
TT
195extern struct value *eval_op_memval (struct type *expect_type,
196 struct expression *exp,
197 enum noside noside,
198 struct value *arg1, struct type *type);
e5946e16
TT
199extern 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);
d5ab122c 205
e2803273
TT
206namespace expr
207{
208
a88c4354
TT
209class ada_component;
210
e2803273
TT
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. */
216static inline bool
217check_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
9e5e03df 224static inline bool
e2803273
TT
225check_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
9e5e03df 233static inline bool
e2803273
TT
234check_objfile (struct symbol *sym, struct objfile *objfile)
235{
236 return check_objfile (symbol_objfile (sym), objfile);
237}
238
9e5e03df 239static inline bool
e2803273
TT
240check_objfile (const struct block *block, struct objfile *objfile)
241{
242 return check_objfile (block_objfile (block), objfile);
243}
244
9e5e03df
TT
245static inline bool
246check_objfile (const block_symbol &sym, struct objfile *objfile)
247{
248 return (check_objfile (sym.symbol, objfile)
249 || check_objfile (sym.block, objfile));
250}
251
e2803273 252static inline bool
9c79936b 253check_objfile (bound_minimal_symbol minsym, struct objfile *objfile)
e2803273 254{
9c79936b 255 return check_objfile (minsym.objfile, objfile);
e2803273
TT
256}
257
258static inline bool
259check_objfile (internalvar *ivar, struct objfile *objfile)
260{
261 return false;
262}
263
264static inline bool
265check_objfile (const std::string &str, struct objfile *objfile)
266{
267 return false;
268}
269
9e5e03df 270static inline bool
e2803273
TT
271check_objfile (const operation_up &op, struct objfile *objfile)
272{
273 return op->uses_objfile (objfile);
274}
275
276static inline bool
277check_objfile (enum exp_opcode val, struct objfile *objfile)
278{
279 return false;
280}
281
282static inline bool
283check_objfile (ULONGEST val, struct objfile *objfile)
284{
285 return false;
286}
287
288template<typename T>
289static inline bool
290check_objfile (enum_flags<T> val, struct objfile *objfile)
291{
292 return false;
293}
294
295template<typename T>
9e5e03df 296static inline bool
e2803273
TT
297check_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
307template<typename S, typename T>
9e5e03df 308static inline bool
e2803273
TT
309check_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
a88c4354
TT
315extern bool check_objfile (const std::unique_ptr<ada_component> &comp,
316 struct objfile *objfile);
317
de401988
TT
318static inline void
319dump_for_expression (struct ui_file *stream, int depth,
320 const operation_up &op)
321{
322 op->dump (stream, depth);
323}
324
325extern void dump_for_expression (struct ui_file *stream, int depth,
326 enum exp_opcode op);
327extern void dump_for_expression (struct ui_file *stream, int depth,
328 const std::string &str);
329extern void dump_for_expression (struct ui_file *stream, int depth,
330 struct type *type);
331extern void dump_for_expression (struct ui_file *stream, int depth,
332 CORE_ADDR addr);
333extern void dump_for_expression (struct ui_file *stream, int depth,
334 internalvar *ivar);
335extern void dump_for_expression (struct ui_file *stream, int depth,
336 symbol *sym);
9e5e03df
TT
337extern void dump_for_expression (struct ui_file *stream, int depth,
338 const block_symbol &sym);
de401988 339extern void dump_for_expression (struct ui_file *stream, int depth,
9c79936b 340 bound_minimal_symbol msym);
de401988
TT
341extern void dump_for_expression (struct ui_file *stream, int depth,
342 const block *bl);
343extern void dump_for_expression (struct ui_file *stream, int depth,
344 type_instance_flags flags);
345extern void dump_for_expression (struct ui_file *stream, int depth,
346 enum c_string_type_values flags);
347extern void dump_for_expression (struct ui_file *stream, int depth,
348 enum range_flag flags);
a88c4354
TT
349extern void dump_for_expression (struct ui_file *stream, int depth,
350 const std::unique_ptr<ada_component> &comp);
de401988
TT
351
352template<typename T>
353void
354dump_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
362template<typename X, typename Y>
363void
364dump_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
e2803273
TT
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. */
374template<typename... Arg>
375class tuple_holding_operation : public operation
376{
377public:
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 {
de401988
TT
393 dump_for_expression (stream, depth, opcode ());
394 do_dump<0, Arg...> (stream, depth + 1, m_storage);
e2803273
TT
395 }
396
397protected:
398
399 /* Storage for the data. */
400 std::tuple<Arg...> m_storage;
401
402private:
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 {
de401988 417 dump_for_expression (stream, depth, std::get<I> (value));
e2803273
TT
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
446static inline bool
447check_constant (const operation_up &item)
448{
449 return item->constant_p ();
450}
451
452static inline bool
9c79936b 453check_constant (bound_minimal_symbol msym)
e2803273
TT
454{
455 return false;
456}
457
458static inline bool
459check_constant (struct type *type)
460{
461 return true;
462}
463
464static inline bool
465check_constant (const struct block *block)
466{
467 return true;
468}
469
470static inline bool
471check_constant (const std::string &str)
472{
473 return true;
474}
475
e2803273
TT
476static inline bool
477check_constant (ULONGEST cst)
478{
479 return true;
480}
481
482static inline bool
483check_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
9e5e03df
TT
492static inline bool
493check_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
e2803273
TT
500template<typename T>
501static inline bool
502check_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
510template<typename S, typename T>
511static inline bool
512check_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. */
520template<typename... Arg>
521class maybe_constant_operation
522 : public tuple_holding_operation<Arg...>
523{
524public:
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
533private:
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
cae26a0c
TT
552/* A floating-point constant. The constant is encoded in the target
553 format. */
554
555typedef 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. */
562class float_const_operation
563 : public operation
564{
565public:
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
588private:
589
590 struct type *m_type;
591 float_data m_data;
592};
593
d5ab122c
TT
594class scope_operation
595 : public maybe_constant_operation<struct type *, std::string>
596{
597public:
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
a00b7254
TT
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
d5ab122c
TT
618 enum exp_opcode opcode () const override
619 { return OP_SCOPE; }
620
621protected:
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
e82a5afc
TT
630/* Compute the value of a variable. */
631class var_value_operation
9e5e03df 632 : public maybe_constant_operation<block_symbol>
e82a5afc
TT
633{
634public:
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
a00b7254
TT
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
e82a5afc
TT
660 enum exp_opcode opcode () const override
661 { return OP_VAR_VALUE; }
662
413403fc
TT
663 /* Return the symbol referenced by this object. */
664 symbol *get_symbol () const
665 {
9e5e03df 666 return std::get<0> (m_storage).symbol;
413403fc
TT
667 }
668
e82a5afc
TT
669protected:
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
d336c29e
TT
678class long_const_operation
679 : public tuple_holding_operation<struct type *, LONGEST>
680{
681public:
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
699protected:
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
0c8effa3 708class var_msym_value_operation
9c79936b 709 : public maybe_constant_operation<bound_minimal_symbol>
0c8effa3
TT
710{
711public:
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,
9c79936b 720 std::get<0> (m_storage));
0c8effa3
TT
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
a00b7254
TT
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 {
9c79936b 738 const char *name = std::get<0> (m_storage).minsym->print_name ();
a00b7254
TT
739 return operation::evaluate_funcall (expect_type, exp, noside, name, args);
740 }
741
0c8effa3
TT
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
750protected:
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
b5cc3923
TT
762class var_entry_value_operation
763 : public tuple_holding_operation<symbol *>
764{
765public:
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
17679395
TT
781class func_static_var_operation
782 : public maybe_constant_operation<operation_up, std::string>
783{
784public:
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
247d935b
TT
801class last_operation
802 : public tuple_holding_operation<int>
803{
804public:
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
55bdbff8
TT
819class register_operation
820 : public tuple_holding_operation<std::string>
821{
822public:
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
413403fc
TT
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
55bdbff8
TT
843protected:
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
e6985c5e
TT
852class bool_operation
853 : public tuple_holding_operation<bool>
854{
855public:
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
e6e01e16
TT
874class internalvar_operation
875 : public tuple_holding_operation<internalvar *>
876{
877public:
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
897protected:
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
b50db09f
TT
906class string_operation
907 : public tuple_holding_operation<std::string>
908{
909public:
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
1594e0bb
TT
926class ternop_slice_operation
927 : public maybe_constant_operation<operation_up, operation_up, operation_up>
928{
929public:
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
9186293f
TT
950class ternop_cond_operation
951 : public maybe_constant_operation<operation_up, operation_up, operation_up>
952{
953public:
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
972protected:
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
8cfd3e95
TT
981class complex_operation
982 : public maybe_constant_operation<operation_up, operation_up, struct type *>
983{
984public:
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
808b22cf
TT
1002class structop_base_operation
1003 : public tuple_holding_operation<operation_up, std::string>
1004{
1005public:
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
a00b7254
TT
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
808b22cf
TT
1025protected:
1026
1027 using tuple_holding_operation::tuple_holding_operation;
1028};
1029
1030class structop_operation
1031 : public structop_base_operation
1032{
1033public:
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
1049protected:
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
ab0609be
TT
1064class structop_ptr_operation
1065 : public structop_base_operation
1066{
1067public:
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
1083protected:
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
a00b7254 1098class structop_member_base
07f724a8
TT
1099 : public tuple_holding_operation<operation_up, operation_up>
1100{
1101public:
1102
1103 using tuple_holding_operation::tuple_holding_operation;
1104
a00b7254
TT
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
1111class structop_member_operation
1112 : public structop_member_base
1113{
1114public:
1115
1116 using structop_member_base::structop_member_base;
1117
07f724a8
TT
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
1133class structop_mptr_operation
a00b7254 1134 : public structop_member_base
07f724a8
TT
1135{
1136public:
1137
a00b7254 1138 using structop_member_base::structop_member_base;
07f724a8
TT
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
e51e26a0
TT
1155class concat_operation
1156 : public maybe_constant_operation<operation_up, operation_up>
1157{
1158public:
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
a94323b6
TT
1177class add_operation
1178 : public maybe_constant_operation<operation_up, operation_up>
1179{
1180public:
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
1198protected:
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
5133d78b
TT
1213class sub_operation
1214 : public maybe_constant_operation<operation_up, operation_up>
1215{
1216public:
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
1234protected:
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
373907ff
TT
1249typedef 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
1254template<enum exp_opcode OP, binary_ftype FUNC>
1255class binop_operation
1256 : public maybe_constant_operation<operation_up, operation_up>
1257{
1258public:
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
1277template<enum exp_opcode OP, binary_ftype FUNC>
1278class usual_ax_binop_operation
1279 : public binop_operation<OP, FUNC>
1280{
1281public:
1282
1283 using binop_operation<OP, FUNC>::binop_operation;
1284
1285protected:
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
1300using exp_operation = binop_operation<BINOP_EXP, eval_op_binary>;
1301using intdiv_operation = binop_operation<BINOP_INTDIV, eval_op_binary>;
1302using mod_operation = binop_operation<BINOP_MOD, eval_op_binary>;
1303
1304using mul_operation = usual_ax_binop_operation<BINOP_MUL, eval_op_binary>;
1305using div_operation = usual_ax_binop_operation<BINOP_DIV, eval_op_binary>;
1306using rem_operation = usual_ax_binop_operation<BINOP_REM, eval_op_binary>;
1307using lsh_operation = usual_ax_binop_operation<BINOP_LSH, eval_op_binary>;
1308using rsh_operation = usual_ax_binop_operation<BINOP_RSH, eval_op_binary>;
1309using bitwise_and_operation
1310 = usual_ax_binop_operation<BINOP_BITWISE_AND, eval_op_binary>;
1311using bitwise_ior_operation
1312 = usual_ax_binop_operation<BINOP_BITWISE_IOR, eval_op_binary>;
1313using bitwise_xor_operation
1314 = usual_ax_binop_operation<BINOP_BITWISE_XOR, eval_op_binary>;
1315
224d6424
TT
1316class subscript_operation
1317 : public usual_ax_binop_operation<BINOP_SUBSCRIPT, eval_op_subscript>
1318{
1319public:
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
46916f2b
TT
1327/* Implementation of comparison operations. */
1328template<enum exp_opcode OP, binary_ftype FUNC>
1329class comparison_operation
1330 : public usual_ax_binop_operation<OP, FUNC>
1331{
1332public:
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
413403fc
TT
1349class equal_operation
1350 : public comparison_operation<BINOP_EQUAL, eval_op_equal>
1351{
1352public:
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
46916f2b
TT
1367using notequal_operation
1368 = comparison_operation<BINOP_NOTEQUAL, eval_op_notequal>;
1369using less_operation = comparison_operation<BINOP_LESS, eval_op_less>;
1370using gtr_operation = comparison_operation<BINOP_GTR, eval_op_gtr>;
1371using geq_operation = comparison_operation<BINOP_GEQ, eval_op_geq>;
1372using leq_operation = comparison_operation<BINOP_LEQ, eval_op_leq>;
1373
d4eff4c1
TT
1374/* Implement the GDB '@' repeat operator. */
1375class repeat_operation
1376 : public binop_operation<BINOP_REPEAT, eval_op_repeat>
1377{
1378 using binop_operation<BINOP_REPEAT, eval_op_repeat>::binop_operation;
1379
1380protected:
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
ae64ba58
TT
1389/* C-style comma operator. */
1390class comma_operation
1391 : public maybe_constant_operation<operation_up, operation_up>
1392{
1393public:
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
1411protected:
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
9307d17b
TT
1420typedef 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. */
1426template<enum exp_opcode OP, unary_ftype FUNC>
1427class unop_operation
1428 : public maybe_constant_operation<operation_up>
1429{
1430public:
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. */
1448template<enum exp_opcode OP, unary_ftype FUNC>
1449class usual_ax_unop_operation
1450 : public unop_operation<OP, FUNC>
1451{
1452 using unop_operation<OP, FUNC>::unop_operation;
1453
1454protected:
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
1468using unary_plus_operation = usual_ax_unop_operation<UNOP_PLUS, eval_op_plus>;
1469using unary_neg_operation = usual_ax_unop_operation<UNOP_NEG, eval_op_neg>;
1470using unary_complement_operation
1471 = usual_ax_unop_operation<UNOP_COMPLEMENT, eval_op_complement>;
1472using unary_logical_not_operation
1473 = usual_ax_unop_operation<UNOP_LOGICAL_NOT, eval_op_lognot>;
1474
6d89e296
TT
1475/* Handle pre- and post- increment and -decrement. */
1476template<enum exp_opcode OP, unary_ftype FUNC>
1477class unop_incr_operation
1478 : public tuple_holding_operation<operation_up>
1479{
1480public:
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
1496using preinc_operation
1497 = unop_incr_operation<UNOP_PREINCREMENT, eval_op_preinc>;
1498using predec_operation
1499 = unop_incr_operation<UNOP_PREDECREMENT, eval_op_predec>;
1500using postinc_operation
1501 = unop_incr_operation<UNOP_POSTINCREMENT, eval_op_postinc>;
1502using postdec_operation
1503 = unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>;
1504
876469ff
TT
1505/* Base class for implementations of UNOP_IND. */
1506class unop_ind_base_operation
1507 : public tuple_holding_operation<operation_up>
1508{
1509public:
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. */
1534class unop_ind_operation
1535 : public unop_ind_base_operation
1536{
1537public:
1538
1539 using unop_ind_base_operation::unop_ind_base_operation;
1540
1541protected:
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
5b5f5140
TT
1555/* Implement OP_TYPE. */
1556class type_operation
1557 : public tuple_holding_operation<struct type *>
1558{
1559public:
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
4efc574c
TT
1577/* Implement the "typeof" operation. */
1578class typeof_operation
1579 : public maybe_constant_operation<operation_up>
1580{
1581public:
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 {
0b2b0b82 1589 if (noside == EVAL_AVOID_SIDE_EFFECTS)
4efc574c
TT
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
0af8829e
TT
1600/* Implement 'decltype'. */
1601class decltype_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 {
0b2b0b82 1612 if (noside == EVAL_AVOID_SIDE_EFFECTS)
0af8829e
TT
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
929f3aa7
TT
1645/* Implement 'typeid'. */
1646class typeid_operation
1647 : public tuple_holding_operation<operation_up>
1648{
1649public:
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
14aff815
TT
1674/* Implement the address-of operation. */
1675class unop_addr_operation
1676 : public maybe_constant_operation<operation_up>
1677{
1678public:
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. */
0b2b0b82 1687 return std::get<0> (m_storage)->evaluate_for_address (exp, noside);
14aff815
TT
1688 }
1689
1690 enum exp_opcode opcode () const override
1691 { return UNOP_ADDR; }
1692
2f98abe1
TT
1693 /* Return the subexpression. */
1694 const operation_up &get_expression () const
1695 {
1696 return std::get<0> (m_storage);
1697 }
1698
14aff815
TT
1699protected:
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
85d23bda
TT
1713/* Implement 'sizeof'. */
1714class unop_sizeof_operation
1715 : public maybe_constant_operation<operation_up>
1716{
1717public:
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 {
85d23bda
TT
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
1731protected:
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
ae4bb61e
TT
1740/* Implement 'alignof'. */
1741class unop_alignof_operation
1742 : public maybe_constant_operation<operation_up>
1743{
1744public:
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
cbc18219
TT
1761/* Implement UNOP_MEMVAL. */
1762class unop_memval_operation
1763 : public tuple_holding_operation<operation_up, struct type *>
1764{
1765public:
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
413403fc
TT
1787 /* Return the type referenced by this object. */
1788 struct type *get_type () const
1789 {
1790 return std::get<1> (m_storage);
1791 }
1792
cbc18219
TT
1793protected:
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. */
1803class unop_memval_type_operation
1804 : public tuple_holding_operation<operation_up, operation_up>
1805{
1806public:
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
1831protected:
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
f6b42326
TT
1840/* Implement the 'this' expression. */
1841class op_this_operation
1842 : public tuple_holding_operation<>
1843{
1844public:
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
1858protected:
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
44b675c8
TT
1867/* Implement the "type instance" operation. */
1868class type_instance_operation
1869 : public tuple_holding_operation<type_instance_flags, std::vector<type *>,
1870 operation_up>
1871{
1872public:
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
40786782
TT
1884/* The assignment operator. */
1885class assign_operation
1886 : public tuple_holding_operation<operation_up, operation_up>
1887{
1888public:
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
0b2b0b82 1907 if (noside == EVAL_AVOID_SIDE_EFFECTS)
40786782
TT
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
413403fc
TT
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
40786782
TT
1924protected:
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
e5946e16
TT
1933/* Assignment with modification, like "+=". */
1934class assign_modify_operation
1935 : public tuple_holding_operation<exp_opcode, operation_up, operation_up>
1936{
1937public:
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
1954protected:
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
165a813a
TT
1963/* A type cast. */
1964class unop_cast_operation
1965 : public maybe_constant_operation<operation_up, struct type *>
1966{
1967public:
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
413403fc
TT
1982 /* Return the type referenced by this object. */
1983 struct type *get_type () const
1984 {
1985 return std::get<1> (m_storage);
1986 }
1987
165a813a
TT
1988protected:
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
292382f4
TT
1997/* A cast, but the type comes from an expression, not a "struct
1998 type". */
1999class unop_cast_type_operation
2000 : public maybe_constant_operation<operation_up, operation_up>
2001{
2002public:
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
2019protected:
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
d9ad79d8
TT
2028typedef 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. */
2032template<exp_opcode OP, cxx_cast_ftype FUNC>
2033class cxx_cast_operation
2034 : public maybe_constant_operation<operation_up, operation_up>
2035{
2036public:
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);
d9ad79d8
TT
2048 return FUNC (type, rhs);
2049 }
2050
2051 enum exp_opcode opcode () const override
2052 { return OP; }
2053};
2054
2055using dynamic_cast_operation = cxx_cast_operation<UNOP_DYNAMIC_CAST,
2056 value_dynamic_cast>;
2057using reinterpret_cast_operation = cxx_cast_operation<UNOP_REINTERPRET_CAST,
2058 value_reinterpret_cast>;
2059
821e72d7
TT
2060/* Multi-dimensional subscripting. */
2061class multi_subscript_operation
2062 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
2063{
2064public:
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
5019124b
TT
2076/* The "&&" operator. */
2077class logical_and_operation
2078 : public maybe_constant_operation<operation_up, operation_up>
2079{
2080public:
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
2091protected:
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. */
2101class logical_or_operation
2102 : public maybe_constant_operation<operation_up, operation_up>
2103{
2104public:
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
2115protected:
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
e4479080
TT
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. */
2127class adl_func_operation
2128 : public tuple_holding_operation<std::string, const block *,
2129 std::vector<operation_up>>
2130{
2131public:
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
1c02eb30
TT
2143/* The OP_ARRAY operation. */
2144class array_operation
2145 : public tuple_holding_operation<int, int, std::vector<operation_up>>
2146{
2147public:
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
2158private:
2159
2160 struct value *evaluate_struct_tuple (struct value *struct_val,
2161 struct expression *exp,
2162 enum noside noside, int nargs);
2163};
2164
a00b7254
TT
2165/* A function call. This holds the callee operation and the
2166 arguments. */
2167class funcall_operation
2168 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
2169{
2170public:
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
e2803273
TT
2186} /* namespace expr */
2187
2188#endif /* EXPOP_H */
This page took 0.146374 seconds and 4 git commands to generate.