Introduce fortran_undetermined
[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
a00b7254
TT
600 value *evaluate_funcall (struct type *expect_type,
601 struct expression *exp,
602 enum noside noside,
603 const std::vector<operation_up> &args) override;
604
d5ab122c
TT
605 enum exp_opcode opcode () const override
606 { return OP_SCOPE; }
607
608protected:
609
610 void do_generate_ax (struct expression *exp,
611 struct agent_expr *ax,
612 struct axs_value *value,
613 struct type *cast_type)
614 override;
615};
616
e82a5afc
TT
617/* Compute the value of a variable. */
618class var_value_operation
619 : public maybe_constant_operation<symbol *, const block *>
620{
621public:
622
623 using maybe_constant_operation::maybe_constant_operation;
624
625 value *evaluate (struct type *expect_type,
626 struct expression *exp,
627 enum noside noside) override;
628
629 value *evaluate_with_coercion (struct expression *exp,
630 enum noside noside) override;
631
632 value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
633 override;
634
635 value *evaluate_for_cast (struct type *expect_type,
636 struct expression *exp,
637 enum noside noside) override;
638
639 value *evaluate_for_address (struct expression *exp, enum noside noside)
640 override;
641
a00b7254
TT
642 value *evaluate_funcall (struct type *expect_type,
643 struct expression *exp,
644 enum noside noside,
645 const std::vector<operation_up> &args) override;
646
e82a5afc
TT
647 enum exp_opcode opcode () const override
648 { return OP_VAR_VALUE; }
649
650protected:
651
652 void do_generate_ax (struct expression *exp,
653 struct agent_expr *ax,
654 struct axs_value *value,
655 struct type *cast_type)
656 override;
657};
658
d336c29e
TT
659class long_const_operation
660 : public tuple_holding_operation<struct type *, LONGEST>
661{
662public:
663
664 using tuple_holding_operation::tuple_holding_operation;
665
666 value *evaluate (struct type *expect_type,
667 struct expression *exp,
668 enum noside noside) override
669 {
670 return value_from_longest (std::get<0> (m_storage),
671 std::get<1> (m_storage));
672 }
673
674 enum exp_opcode opcode () const override
675 { return OP_LONG; }
676
677 bool constant_p () const override
678 { return true; }
679
680protected:
681
682 void do_generate_ax (struct expression *exp,
683 struct agent_expr *ax,
684 struct axs_value *value,
685 struct type *cast_type)
686 override;
687};
688
0c8effa3
TT
689class var_msym_value_operation
690 : public maybe_constant_operation<minimal_symbol *, struct objfile *>
691{
692public:
693
694 using maybe_constant_operation::maybe_constant_operation;
695
696 value *evaluate (struct type *expect_type,
697 struct expression *exp,
698 enum noside noside) override
699 {
700 return eval_op_var_msym_value (expect_type, exp, noside, m_outermost,
701 std::get<0> (m_storage),
702 std::get<1> (m_storage));
703 }
704
705 value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
706 override;
707
708 value *evaluate_for_address (struct expression *exp, enum noside noside)
709 override;
710
711 value *evaluate_for_cast (struct type *expect_type,
712 struct expression *exp,
713 enum noside noside) override;
714
a00b7254
TT
715 value *evaluate_funcall (struct type *expect_type,
716 struct expression *exp,
717 enum noside noside,
718 const std::vector<operation_up> &args) override
719 {
720 const char *name = std::get<0> (m_storage)->print_name ();
721 return operation::evaluate_funcall (expect_type, exp, noside, name, args);
722 }
723
0c8effa3
TT
724 enum exp_opcode opcode () const override
725 { return OP_VAR_MSYM_VALUE; }
726
727 void set_outermost () override
728 {
729 m_outermost = true;
730 }
731
732protected:
733
734 /* True if this is the outermost operation in the expression. */
735 bool m_outermost = false;
736
737 void do_generate_ax (struct expression *exp,
738 struct agent_expr *ax,
739 struct axs_value *value,
740 struct type *cast_type)
741 override;
742};
743
b5cc3923
TT
744class var_entry_value_operation
745 : public tuple_holding_operation<symbol *>
746{
747public:
748
749 using tuple_holding_operation::tuple_holding_operation;
750
751 value *evaluate (struct type *expect_type,
752 struct expression *exp,
753 enum noside noside) override
754 {
755 return eval_op_var_entry_value (expect_type, exp, noside,
756 std::get<0> (m_storage));
757 }
758
759 enum exp_opcode opcode () const override
760 { return OP_VAR_ENTRY_VALUE; }
761};
762
17679395
TT
763class func_static_var_operation
764 : public maybe_constant_operation<operation_up, std::string>
765{
766public:
767
768 using maybe_constant_operation::maybe_constant_operation;
769
770 value *evaluate (struct type *expect_type,
771 struct expression *exp,
772 enum noside noside) override
773 {
774 value *func = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
775 return eval_op_func_static_var (expect_type, exp, noside, func,
776 std::get<1> (m_storage).c_str ());
777 }
778
779 enum exp_opcode opcode () const override
780 { return OP_FUNC_STATIC_VAR; }
781};
782
247d935b
TT
783class last_operation
784 : public tuple_holding_operation<int>
785{
786public:
787
788 using tuple_holding_operation::tuple_holding_operation;
789
790 value *evaluate (struct type *expect_type,
791 struct expression *exp,
792 enum noside noside) override
793 {
794 return access_value_history (std::get<0> (m_storage));
795 }
796
797 enum exp_opcode opcode () const override
798 { return OP_LAST; }
799};
800
55bdbff8
TT
801class register_operation
802 : public tuple_holding_operation<std::string>
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 eval_op_register (expect_type, exp, noside,
813 std::get<0> (m_storage).c_str ());
814 }
815
816 enum exp_opcode opcode () const override
817 { return OP_REGISTER; }
818
819protected:
820
821 void do_generate_ax (struct expression *exp,
822 struct agent_expr *ax,
823 struct axs_value *value,
824 struct type *cast_type)
825 override;
826};
827
e6985c5e
TT
828class bool_operation
829 : public tuple_holding_operation<bool>
830{
831public:
832
833 using tuple_holding_operation::tuple_holding_operation;
834
835 value *evaluate (struct type *expect_type,
836 struct expression *exp,
837 enum noside noside) override
838 {
839 struct type *type = language_bool_type (exp->language_defn, exp->gdbarch);
840 return value_from_longest (type, std::get<0> (m_storage));
841 }
842
843 enum exp_opcode opcode () const override
844 { return OP_BOOL; }
845
846 bool constant_p () const override
847 { return true; }
848};
849
e6e01e16
TT
850class internalvar_operation
851 : public tuple_holding_operation<internalvar *>
852{
853public:
854
855 using tuple_holding_operation::tuple_holding_operation;
856
857 value *evaluate (struct type *expect_type,
858 struct expression *exp,
859 enum noside noside) override
860 {
861 return value_of_internalvar (exp->gdbarch,
862 std::get<0> (m_storage));
863 }
864
865 internalvar *get_internalvar () const
866 {
867 return std::get<0> (m_storage);
868 }
869
870 enum exp_opcode opcode () const override
871 { return OP_INTERNALVAR; }
872
873protected:
874
875 void do_generate_ax (struct expression *exp,
876 struct agent_expr *ax,
877 struct axs_value *value,
878 struct type *cast_type)
879 override;
880};
881
b50db09f
TT
882class string_operation
883 : public tuple_holding_operation<std::string>
884{
885public:
886
887 using tuple_holding_operation::tuple_holding_operation;
888
889 value *evaluate (struct type *expect_type,
890 struct expression *exp,
891 enum noside noside) override
892 {
893 const std::string &str = std::get<0> (m_storage);
894 return eval_op_string (expect_type, exp, noside,
895 str.size (), str.c_str ());
896 }
897
898 enum exp_opcode opcode () const override
899 { return OP_STRING; }
900};
901
1594e0bb
TT
902class ternop_slice_operation
903 : public maybe_constant_operation<operation_up, operation_up, operation_up>
904{
905public:
906
907 using maybe_constant_operation::maybe_constant_operation;
908
909 value *evaluate (struct type *expect_type,
910 struct expression *exp,
911 enum noside noside) override
912 {
913 struct value *array
914 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
915 struct value *low
916 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
917 struct value *upper
918 = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
919 return eval_op_ternop (expect_type, exp, noside, array, low, upper);
920 }
921
922 enum exp_opcode opcode () const override
923 { return TERNOP_SLICE; }
924};
925
9186293f
TT
926class ternop_cond_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 *val
938 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
939
940 if (value_logical_not (val))
941 return std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
942 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
943 }
944
945 enum exp_opcode opcode () const override
946 { return TERNOP_COND; }
947
948protected:
949
950 void do_generate_ax (struct expression *exp,
951 struct agent_expr *ax,
952 struct axs_value *value,
953 struct type *cast_type)
954 override;
955};
956
8cfd3e95
TT
957class complex_operation
958 : public maybe_constant_operation<operation_up, operation_up, struct type *>
959{
960public:
961
962 using maybe_constant_operation::maybe_constant_operation;
963
964 value *evaluate (struct type *expect_type,
965 struct expression *exp,
966 enum noside noside) override
967 {
968 value *real = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
969 value *imag = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
970 return value_literal_complex (real, imag,
971 std::get<2> (m_storage));
972 }
973
974 enum exp_opcode opcode () const override
975 { return OP_COMPLEX; }
976};
977
808b22cf
TT
978class structop_base_operation
979 : public tuple_holding_operation<operation_up, std::string>
980{
981public:
982
983 /* Used for completion. Return the field name. */
984 const std::string &get_string () const
985 {
986 return std::get<1> (m_storage);
987 }
988
989 /* Used for completion. Evaluate the LHS for type. */
990 value *evaluate_lhs (struct expression *exp)
991 {
992 return std::get<0> (m_storage)->evaluate (nullptr, exp,
993 EVAL_AVOID_SIDE_EFFECTS);
994 }
995
a00b7254
TT
996 value *evaluate_funcall (struct type *expect_type,
997 struct expression *exp,
998 enum noside noside,
999 const std::vector<operation_up> &args) override;
1000
808b22cf
TT
1001protected:
1002
1003 using tuple_holding_operation::tuple_holding_operation;
1004};
1005
1006class structop_operation
1007 : public structop_base_operation
1008{
1009public:
1010
1011 using structop_base_operation::structop_base_operation;
1012
1013 value *evaluate (struct type *expect_type,
1014 struct expression *exp,
1015 enum noside noside) override
1016 {
1017 value *val =std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1018 return eval_op_structop_struct (expect_type, exp, noside, val,
1019 std::get<1> (m_storage).c_str ());
1020 }
1021
1022 enum exp_opcode opcode () const override
1023 { return STRUCTOP_STRUCT; }
1024
1025protected:
1026
1027 void do_generate_ax (struct expression *exp,
1028 struct agent_expr *ax,
1029 struct axs_value *value,
1030 struct type *cast_type)
1031 override
1032 {
1033 gen_expr_structop (exp, STRUCTOP_STRUCT,
1034 std::get<0> (this->m_storage).get (),
1035 std::get<1> (this->m_storage).c_str (),
1036 ax, value);
1037 }
1038};
1039
ab0609be
TT
1040class structop_ptr_operation
1041 : public structop_base_operation
1042{
1043public:
1044
1045 using structop_base_operation::structop_base_operation;
1046
1047 value *evaluate (struct type *expect_type,
1048 struct expression *exp,
1049 enum noside noside) override
1050 {
1051 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1052 return eval_op_structop_ptr (expect_type, exp, noside, val,
1053 std::get<1> (m_storage).c_str ());
1054 }
1055
1056 enum exp_opcode opcode () const override
1057 { return STRUCTOP_PTR; }
1058
1059protected:
1060
1061 void do_generate_ax (struct expression *exp,
1062 struct agent_expr *ax,
1063 struct axs_value *value,
1064 struct type *cast_type)
1065 override
1066 {
1067 gen_expr_structop (exp, STRUCTOP_PTR,
1068 std::get<0> (this->m_storage).get (),
1069 std::get<1> (this->m_storage).c_str (),
1070 ax, value);
1071 }
1072};
1073
a00b7254 1074class structop_member_base
07f724a8
TT
1075 : public tuple_holding_operation<operation_up, operation_up>
1076{
1077public:
1078
1079 using tuple_holding_operation::tuple_holding_operation;
1080
a00b7254
TT
1081 value *evaluate_funcall (struct type *expect_type,
1082 struct expression *exp,
1083 enum noside noside,
1084 const std::vector<operation_up> &args) override;
1085};
1086
1087class structop_member_operation
1088 : public structop_member_base
1089{
1090public:
1091
1092 using structop_member_base::structop_member_base;
1093
07f724a8
TT
1094 value *evaluate (struct type *expect_type,
1095 struct expression *exp,
1096 enum noside noside) override
1097 {
1098 value *lhs
1099 = std::get<0> (m_storage)->evaluate_for_address (exp, noside);
1100 value *rhs
1101 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1102 return eval_op_member (expect_type, exp, noside, lhs, rhs);
1103 }
1104
1105 enum exp_opcode opcode () const override
1106 { return STRUCTOP_MEMBER; }
1107};
1108
1109class structop_mptr_operation
a00b7254 1110 : public structop_member_base
07f724a8
TT
1111{
1112public:
1113
a00b7254 1114 using structop_member_base::structop_member_base;
07f724a8
TT
1115
1116 value *evaluate (struct type *expect_type,
1117 struct expression *exp,
1118 enum noside noside) override
1119 {
1120 value *lhs
1121 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1122 value *rhs
1123 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1124 return eval_op_member (expect_type, exp, noside, lhs, rhs);
1125 }
1126
1127 enum exp_opcode opcode () const override
1128 { return STRUCTOP_MPTR; }
1129};
1130
e51e26a0
TT
1131class concat_operation
1132 : public maybe_constant_operation<operation_up, operation_up>
1133{
1134public:
1135
1136 using maybe_constant_operation::maybe_constant_operation;
1137
1138 value *evaluate (struct type *expect_type,
1139 struct expression *exp,
1140 enum noside noside) override
1141 {
1142 value *lhs
1143 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1144 value *rhs
1145 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1146 return eval_op_concat (expect_type, exp, noside, lhs, rhs);
1147 }
1148
1149 enum exp_opcode opcode () const override
1150 { return BINOP_CONCAT; }
1151};
1152
a94323b6
TT
1153class add_operation
1154 : public maybe_constant_operation<operation_up, operation_up>
1155{
1156public:
1157
1158 using maybe_constant_operation::maybe_constant_operation;
1159
1160 value *evaluate (struct type *expect_type,
1161 struct expression *exp,
1162 enum noside noside) override
1163 {
1164 value *lhs
1165 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1166 value *rhs
1167 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1168 return eval_op_add (expect_type, exp, noside, lhs, rhs);
1169 }
1170
1171 enum exp_opcode opcode () const override
1172 { return BINOP_ADD; }
1173
1174protected:
1175
1176 void do_generate_ax (struct expression *exp,
1177 struct agent_expr *ax,
1178 struct axs_value *value,
1179 struct type *cast_type)
1180 override
1181 {
1182 gen_expr_binop (exp, BINOP_ADD,
1183 std::get<0> (this->m_storage).get (),
1184 std::get<1> (this->m_storage).get (),
1185 ax, value);
1186 }
1187};
1188
5133d78b
TT
1189class sub_operation
1190 : public maybe_constant_operation<operation_up, operation_up>
1191{
1192public:
1193
1194 using maybe_constant_operation::maybe_constant_operation;
1195
1196 value *evaluate (struct type *expect_type,
1197 struct expression *exp,
1198 enum noside noside) override
1199 {
1200 value *lhs
1201 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
1202 value *rhs
1203 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
1204 return eval_op_sub (expect_type, exp, noside, lhs, rhs);
1205 }
1206
1207 enum exp_opcode opcode () const override
1208 { return BINOP_SUB; }
1209
1210protected:
1211
1212 void do_generate_ax (struct expression *exp,
1213 struct agent_expr *ax,
1214 struct axs_value *value,
1215 struct type *cast_type)
1216 override
1217 {
1218 gen_expr_binop (exp, BINOP_SUB,
1219 std::get<0> (this->m_storage).get (),
1220 std::get<1> (this->m_storage).get (),
1221 ax, value);
1222 }
1223};
1224
373907ff
TT
1225typedef struct value *binary_ftype (struct type *expect_type,
1226 struct expression *exp,
1227 enum noside noside, enum exp_opcode op,
1228 struct value *arg1, struct value *arg2);
1229
1230template<enum exp_opcode OP, binary_ftype FUNC>
1231class binop_operation
1232 : public maybe_constant_operation<operation_up, operation_up>
1233{
1234public:
1235
1236 using maybe_constant_operation::maybe_constant_operation;
1237
1238 value *evaluate (struct type *expect_type,
1239 struct expression *exp,
1240 enum noside noside) override
1241 {
1242 value *lhs
1243 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1244 value *rhs
1245 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1246 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
1247 }
1248
1249 enum exp_opcode opcode () const override
1250 { return OP; }
1251};
1252
1253template<enum exp_opcode OP, binary_ftype FUNC>
1254class usual_ax_binop_operation
1255 : public binop_operation<OP, FUNC>
1256{
1257public:
1258
1259 using binop_operation<OP, FUNC>::binop_operation;
1260
1261protected:
1262
1263 void do_generate_ax (struct expression *exp,
1264 struct agent_expr *ax,
1265 struct axs_value *value,
1266 struct type *cast_type)
1267 override
1268 {
1269 gen_expr_binop (exp, OP,
1270 std::get<0> (this->m_storage).get (),
1271 std::get<1> (this->m_storage).get (),
1272 ax, value);
1273 }
1274};
1275
1276using exp_operation = binop_operation<BINOP_EXP, eval_op_binary>;
1277using intdiv_operation = binop_operation<BINOP_INTDIV, eval_op_binary>;
1278using mod_operation = binop_operation<BINOP_MOD, eval_op_binary>;
1279
1280using mul_operation = usual_ax_binop_operation<BINOP_MUL, eval_op_binary>;
1281using div_operation = usual_ax_binop_operation<BINOP_DIV, eval_op_binary>;
1282using rem_operation = usual_ax_binop_operation<BINOP_REM, eval_op_binary>;
1283using lsh_operation = usual_ax_binop_operation<BINOP_LSH, eval_op_binary>;
1284using rsh_operation = usual_ax_binop_operation<BINOP_RSH, eval_op_binary>;
1285using bitwise_and_operation
1286 = usual_ax_binop_operation<BINOP_BITWISE_AND, eval_op_binary>;
1287using bitwise_ior_operation
1288 = usual_ax_binop_operation<BINOP_BITWISE_IOR, eval_op_binary>;
1289using bitwise_xor_operation
1290 = usual_ax_binop_operation<BINOP_BITWISE_XOR, eval_op_binary>;
1291
224d6424
TT
1292class subscript_operation
1293 : public usual_ax_binop_operation<BINOP_SUBSCRIPT, eval_op_subscript>
1294{
1295public:
1296 using usual_ax_binop_operation<BINOP_SUBSCRIPT,
1297 eval_op_subscript>::usual_ax_binop_operation;
1298
1299 value *evaluate_for_sizeof (struct expression *exp,
1300 enum noside noside) override;
1301};
1302
46916f2b
TT
1303/* Implementation of comparison operations. */
1304template<enum exp_opcode OP, binary_ftype FUNC>
1305class comparison_operation
1306 : public usual_ax_binop_operation<OP, FUNC>
1307{
1308public:
1309
1310 using usual_ax_binop_operation<OP, FUNC>::usual_ax_binop_operation;
1311
1312 value *evaluate (struct type *expect_type,
1313 struct expression *exp,
1314 enum noside noside) override
1315 {
1316 value *lhs
1317 = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside);
1318 value *rhs
1319 = std::get<1> (this->m_storage)->evaluate (value_type (lhs), exp,
1320 noside);
1321 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
1322 }
1323};
1324
1325using equal_operation = comparison_operation<BINOP_EQUAL, eval_op_equal>;
1326using notequal_operation
1327 = comparison_operation<BINOP_NOTEQUAL, eval_op_notequal>;
1328using less_operation = comparison_operation<BINOP_LESS, eval_op_less>;
1329using gtr_operation = comparison_operation<BINOP_GTR, eval_op_gtr>;
1330using geq_operation = comparison_operation<BINOP_GEQ, eval_op_geq>;
1331using leq_operation = comparison_operation<BINOP_LEQ, eval_op_leq>;
1332
d4eff4c1
TT
1333/* Implement the GDB '@' repeat operator. */
1334class repeat_operation
1335 : public binop_operation<BINOP_REPEAT, eval_op_repeat>
1336{
1337 using binop_operation<BINOP_REPEAT, eval_op_repeat>::binop_operation;
1338
1339protected:
1340
1341 void do_generate_ax (struct expression *exp,
1342 struct agent_expr *ax,
1343 struct axs_value *value,
1344 struct type *cast_type)
1345 override;
1346};
1347
ae64ba58
TT
1348/* C-style comma operator. */
1349class comma_operation
1350 : public maybe_constant_operation<operation_up, 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 /* The left-hand-side is only evaluated for side effects, so don't
1361 bother in other modes. */
1362 if (noside == EVAL_NORMAL)
1363 std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1364 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1365 }
1366
1367 enum exp_opcode opcode () const override
1368 { return BINOP_COMMA; }
1369
1370protected:
1371
1372 void do_generate_ax (struct expression *exp,
1373 struct agent_expr *ax,
1374 struct axs_value *value,
1375 struct type *cast_type)
1376 override;
1377};
1378
9307d17b
TT
1379typedef struct value *unary_ftype (struct type *expect_type,
1380 struct expression *exp,
1381 enum noside noside, enum exp_opcode op,
1382 struct value *arg1);
1383
1384/* Base class for unary operations. */
1385template<enum exp_opcode OP, unary_ftype FUNC>
1386class unop_operation
1387 : public maybe_constant_operation<operation_up>
1388{
1389public:
1390
1391 using maybe_constant_operation::maybe_constant_operation;
1392
1393 value *evaluate (struct type *expect_type,
1394 struct expression *exp,
1395 enum noside noside) override
1396 {
1397 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1398 return FUNC (expect_type, exp, noside, OP, val);
1399 }
1400
1401 enum exp_opcode opcode () const override
1402 { return OP; }
1403};
1404
1405/* Unary operations that can also be turned into agent expressions in
1406 the "usual" way. */
1407template<enum exp_opcode OP, unary_ftype FUNC>
1408class usual_ax_unop_operation
1409 : public unop_operation<OP, FUNC>
1410{
1411 using unop_operation<OP, FUNC>::unop_operation;
1412
1413protected:
1414
1415 void do_generate_ax (struct expression *exp,
1416 struct agent_expr *ax,
1417 struct axs_value *value,
1418 struct type *cast_type)
1419 override
1420 {
1421 gen_expr_unop (exp, OP,
1422 std::get<0> (this->m_storage).get (),
1423 ax, value);
1424 }
1425};
1426
1427using unary_plus_operation = usual_ax_unop_operation<UNOP_PLUS, eval_op_plus>;
1428using unary_neg_operation = usual_ax_unop_operation<UNOP_NEG, eval_op_neg>;
1429using unary_complement_operation
1430 = usual_ax_unop_operation<UNOP_COMPLEMENT, eval_op_complement>;
1431using unary_logical_not_operation
1432 = usual_ax_unop_operation<UNOP_LOGICAL_NOT, eval_op_lognot>;
1433
6d89e296
TT
1434/* Handle pre- and post- increment and -decrement. */
1435template<enum exp_opcode OP, unary_ftype FUNC>
1436class unop_incr_operation
1437 : public tuple_holding_operation<operation_up>
1438{
1439public:
1440
1441 using tuple_holding_operation::tuple_holding_operation;
1442
1443 value *evaluate (struct type *expect_type,
1444 struct expression *exp,
1445 enum noside noside) override
1446 {
1447 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1448 return FUNC (expect_type, exp, noside, OP, val);
1449 }
1450
1451 enum exp_opcode opcode () const override
1452 { return OP; }
1453};
1454
1455using preinc_operation
1456 = unop_incr_operation<UNOP_PREINCREMENT, eval_op_preinc>;
1457using predec_operation
1458 = unop_incr_operation<UNOP_PREDECREMENT, eval_op_predec>;
1459using postinc_operation
1460 = unop_incr_operation<UNOP_POSTINCREMENT, eval_op_postinc>;
1461using postdec_operation
1462 = unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>;
1463
876469ff
TT
1464/* Base class for implementations of UNOP_IND. */
1465class unop_ind_base_operation
1466 : public tuple_holding_operation<operation_up>
1467{
1468public:
1469
1470 using tuple_holding_operation::tuple_holding_operation;
1471
1472 value *evaluate (struct type *expect_type,
1473 struct expression *exp,
1474 enum noside noside) override
1475 {
1476 if (expect_type != nullptr && expect_type->code () == TYPE_CODE_PTR)
1477 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
1478 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1479 return eval_op_ind (expect_type, exp, noside, val);
1480 }
1481
1482 value *evaluate_for_address (struct expression *exp,
1483 enum noside noside) override;
1484
1485 value *evaluate_for_sizeof (struct expression *exp,
1486 enum noside noside) override;
1487
1488 enum exp_opcode opcode () const override
1489 { return UNOP_IND; }
1490};
1491
1492/* Ordinary UNOP_IND implementation. */
1493class unop_ind_operation
1494 : public unop_ind_base_operation
1495{
1496public:
1497
1498 using unop_ind_base_operation::unop_ind_base_operation;
1499
1500protected:
1501
1502 void do_generate_ax (struct expression *exp,
1503 struct agent_expr *ax,
1504 struct axs_value *value,
1505 struct type *cast_type)
1506 override
1507 {
1508 gen_expr_unop (exp, UNOP_IND,
1509 std::get<0> (this->m_storage).get (),
1510 ax, value);
1511 }
1512};
1513
5b5f5140
TT
1514/* Implement OP_TYPE. */
1515class type_operation
1516 : public tuple_holding_operation<struct type *>
1517{
1518public:
1519
1520 using tuple_holding_operation::tuple_holding_operation;
1521
1522 value *evaluate (struct type *expect_type,
1523 struct expression *exp,
1524 enum noside noside) override
1525 {
1526 return eval_op_type (expect_type, exp, noside, std::get<0> (m_storage));
1527 }
1528
1529 enum exp_opcode opcode () const override
1530 { return OP_TYPE; }
1531
1532 bool constant_p () const override
1533 { return true; }
1534};
1535
4efc574c
TT
1536/* Implement the "typeof" operation. */
1537class typeof_operation
1538 : public maybe_constant_operation<operation_up>
1539{
1540public:
1541
1542 using maybe_constant_operation::maybe_constant_operation;
1543
1544 value *evaluate (struct type *expect_type,
1545 struct expression *exp,
1546 enum noside noside) override
1547 {
1548 if (noside == EVAL_SKIP)
1549 return eval_skip_value (exp);
1550 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1551 return std::get<0> (m_storage)->evaluate (nullptr, exp,
1552 EVAL_AVOID_SIDE_EFFECTS);
1553 else
1554 error (_("Attempt to use a type as an expression"));
1555 }
1556
1557 enum exp_opcode opcode () const override
1558 { return OP_TYPEOF; }
1559};
1560
0af8829e
TT
1561/* Implement 'decltype'. */
1562class decltype_operation
1563 : public maybe_constant_operation<operation_up>
1564{
1565public:
1566
1567 using maybe_constant_operation::maybe_constant_operation;
1568
1569 value *evaluate (struct type *expect_type,
1570 struct expression *exp,
1571 enum noside noside) override
1572 {
1573 if (noside == EVAL_SKIP)
1574 return eval_skip_value (exp);
1575 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1576 {
1577 value *result
1578 = std::get<0> (m_storage)->evaluate (nullptr, exp,
1579 EVAL_AVOID_SIDE_EFFECTS);
1580 enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
1581 if (sub_op == BINOP_SUBSCRIPT
1582 || sub_op == STRUCTOP_MEMBER
1583 || sub_op == STRUCTOP_MPTR
1584 || sub_op == UNOP_IND
1585 || sub_op == STRUCTOP_STRUCT
1586 || sub_op == STRUCTOP_PTR
1587 || sub_op == OP_SCOPE)
1588 {
1589 struct type *type = value_type (result);
1590
1591 if (!TYPE_IS_REFERENCE (type))
1592 {
1593 type = lookup_lvalue_reference_type (type);
1594 result = allocate_value (type);
1595 }
1596 }
1597
1598 return result;
1599 }
1600 else
1601 error (_("Attempt to use a type as an expression"));
1602 }
1603
1604 enum exp_opcode opcode () const override
1605 { return OP_DECLTYPE; }
1606};
1607
929f3aa7
TT
1608/* Implement 'typeid'. */
1609class typeid_operation
1610 : public tuple_holding_operation<operation_up>
1611{
1612public:
1613
1614 using tuple_holding_operation::tuple_holding_operation;
1615
1616 value *evaluate (struct type *expect_type,
1617 struct expression *exp,
1618 enum noside noside) override
1619 {
1620 enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
1621 enum noside sub_noside
1622 = ((sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
1623 ? EVAL_AVOID_SIDE_EFFECTS
1624 : noside);
1625
1626 value *result = std::get<0> (m_storage)->evaluate (nullptr, exp,
1627 sub_noside);
1628 if (noside != EVAL_NORMAL)
1629 return allocate_value (cplus_typeid_type (exp->gdbarch));
1630 return cplus_typeid (result);
1631 }
1632
1633 enum exp_opcode opcode () const override
1634 { return OP_TYPEID; }
1635};
1636
14aff815
TT
1637/* Implement the address-of operation. */
1638class unop_addr_operation
1639 : public maybe_constant_operation<operation_up>
1640{
1641public:
1642
1643 using maybe_constant_operation::maybe_constant_operation;
1644
1645 value *evaluate (struct type *expect_type,
1646 struct expression *exp,
1647 enum noside noside) override
1648 {
1649 /* C++: check for and handle pointer to members. */
1650 if (noside == EVAL_SKIP)
1651 return eval_skip_value (exp);
1652 else
1653 return std::get<0> (m_storage)->evaluate_for_address (exp, noside);
1654 }
1655
1656 enum exp_opcode opcode () const override
1657 { return UNOP_ADDR; }
1658
2f98abe1
TT
1659 /* Return the subexpression. */
1660 const operation_up &get_expression () const
1661 {
1662 return std::get<0> (m_storage);
1663 }
1664
14aff815
TT
1665protected:
1666
1667 void do_generate_ax (struct expression *exp,
1668 struct agent_expr *ax,
1669 struct axs_value *value,
1670 struct type *cast_type)
1671 override
1672 {
1673 gen_expr_unop (exp, UNOP_ADDR,
1674 std::get<0> (this->m_storage).get (),
1675 ax, value);
1676 }
1677};
1678
85d23bda
TT
1679/* Implement 'sizeof'. */
1680class unop_sizeof_operation
1681 : public maybe_constant_operation<operation_up>
1682{
1683public:
1684
1685 using maybe_constant_operation::maybe_constant_operation;
1686
1687 value *evaluate (struct type *expect_type,
1688 struct expression *exp,
1689 enum noside noside) override
1690 {
1691 if (noside == EVAL_SKIP)
1692 return eval_skip_value (exp);
1693 return std::get<0> (m_storage)->evaluate_for_sizeof (exp, noside);
1694 }
1695
1696 enum exp_opcode opcode () const override
1697 { return UNOP_SIZEOF; }
1698
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
ae4bb61e
TT
1708/* Implement 'alignof'. */
1709class unop_alignof_operation
1710 : public maybe_constant_operation<operation_up>
1711{
1712public:
1713
1714 using maybe_constant_operation::maybe_constant_operation;
1715
1716 value *evaluate (struct type *expect_type,
1717 struct expression *exp,
1718 enum noside noside) override
1719 {
1720 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1721 EVAL_AVOID_SIDE_EFFECTS);
1722 return eval_op_alignof (expect_type, exp, noside, val);
1723 }
1724
1725 enum exp_opcode opcode () const override
1726 { return UNOP_ALIGNOF; }
1727};
1728
cbc18219
TT
1729/* Implement UNOP_MEMVAL. */
1730class unop_memval_operation
1731 : public tuple_holding_operation<operation_up, struct type *>
1732{
1733public:
1734
1735 using tuple_holding_operation::tuple_holding_operation;
1736
1737 value *evaluate (struct type *expect_type,
1738 struct expression *exp,
1739 enum noside noside) override
1740 {
1741 value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
1742 return eval_op_memval (expect_type, exp, noside, val,
1743 std::get<1> (m_storage));
1744 }
1745
1746 value *evaluate_for_sizeof (struct expression *exp,
1747 enum noside noside) override;
1748
1749 value *evaluate_for_address (struct expression *exp,
1750 enum noside noside) override;
1751
1752 enum exp_opcode opcode () const override
1753 { return UNOP_MEMVAL; }
1754
1755protected:
1756
1757 void do_generate_ax (struct expression *exp,
1758 struct agent_expr *ax,
1759 struct axs_value *value,
1760 struct type *cast_type)
1761 override;
1762};
1763
1764/* Implement UNOP_MEMVAL_TYPE. */
1765class unop_memval_type_operation
1766 : public tuple_holding_operation<operation_up, operation_up>
1767{
1768public:
1769
1770 using tuple_holding_operation::tuple_holding_operation;
1771
1772 value *evaluate (struct type *expect_type,
1773 struct expression *exp,
1774 enum noside noside) override
1775 {
1776 value *typeval
1777 = std::get<0> (m_storage)->evaluate (expect_type, exp,
1778 EVAL_AVOID_SIDE_EFFECTS);
1779 struct type *type = value_type (typeval);
1780 value *val = std::get<1> (m_storage)->evaluate (expect_type, exp, noside);
1781 return eval_op_memval (expect_type, exp, noside, val, type);
1782 }
1783
1784 value *evaluate_for_sizeof (struct expression *exp,
1785 enum noside noside) override;
1786
1787 value *evaluate_for_address (struct expression *exp,
1788 enum noside noside) override;
1789
1790 enum exp_opcode opcode () const override
1791 { return UNOP_MEMVAL_TYPE; }
1792
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
f6b42326
TT
1802/* Implement the 'this' expression. */
1803class op_this_operation
1804 : public tuple_holding_operation<>
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 return value_of_this (exp->language_defn);
1815 }
1816
1817 enum exp_opcode opcode () const override
1818 { return OP_THIS; }
1819
1820protected:
1821
1822 void do_generate_ax (struct expression *exp,
1823 struct agent_expr *ax,
1824 struct axs_value *value,
1825 struct type *cast_type)
1826 override;
1827};
1828
44b675c8
TT
1829/* Implement the "type instance" operation. */
1830class type_instance_operation
1831 : public tuple_holding_operation<type_instance_flags, std::vector<type *>,
1832 operation_up>
1833{
1834public:
1835
1836 using tuple_holding_operation::tuple_holding_operation;
1837
1838 value *evaluate (struct type *expect_type,
1839 struct expression *exp,
1840 enum noside noside) override;
1841
1842 enum exp_opcode opcode () const override
1843 { return TYPE_INSTANCE; }
1844};
1845
40786782
TT
1846/* The assignment operator. */
1847class assign_operation
1848 : public tuple_holding_operation<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<0> (m_storage)->evaluate (nullptr, exp, noside);
1859 /* Special-case assignments where the left-hand-side is a
1860 convenience variable -- in these, don't bother setting an
1861 expected type. This avoids a weird case where re-assigning a
1862 string or array to an internal variable could error with "Too
1863 many array elements". */
1864 struct type *xtype = (VALUE_LVAL (lhs) == lval_internalvar
1865 ? nullptr
1866 : value_type (lhs));
1867 value *rhs = std::get<1> (m_storage)->evaluate (xtype, exp, noside);
1868
1869 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1870 return lhs;
1871 if (binop_user_defined_p (BINOP_ASSIGN, lhs, rhs))
1872 return value_x_binop (lhs, rhs, BINOP_ASSIGN, OP_NULL, noside);
1873 else
1874 return value_assign (lhs, rhs);
1875 }
1876
1877 enum exp_opcode opcode () const override
1878 { return BINOP_ASSIGN; }
1879
1880protected:
1881
1882 void do_generate_ax (struct expression *exp,
1883 struct agent_expr *ax,
1884 struct axs_value *value,
1885 struct type *cast_type)
1886 override;
1887};
1888
e5946e16
TT
1889/* Assignment with modification, like "+=". */
1890class assign_modify_operation
1891 : public tuple_holding_operation<exp_opcode, operation_up, operation_up>
1892{
1893public:
1894
1895 using tuple_holding_operation::tuple_holding_operation;
1896
1897 value *evaluate (struct type *expect_type,
1898 struct expression *exp,
1899 enum noside noside) override
1900 {
1901 value *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1902 value *rhs = std::get<2> (m_storage)->evaluate (expect_type, exp, noside);
1903 return eval_binop_assign_modify (expect_type, exp, noside,
1904 std::get<0> (m_storage), lhs, rhs);
1905 }
1906
1907 enum exp_opcode opcode () const override
1908 { return BINOP_ASSIGN_MODIFY; }
1909
1910protected:
1911
1912 void do_generate_ax (struct expression *exp,
1913 struct agent_expr *ax,
1914 struct axs_value *value,
1915 struct type *cast_type)
1916 override;
1917};
1918
165a813a
TT
1919/* A type cast. */
1920class unop_cast_operation
1921 : public maybe_constant_operation<operation_up, struct type *>
1922{
1923public:
1924
1925 using maybe_constant_operation::maybe_constant_operation;
1926
1927 value *evaluate (struct type *expect_type,
1928 struct expression *exp,
1929 enum noside noside) override
1930 {
1931 return std::get<0> (m_storage)->evaluate_for_cast (std::get<1> (m_storage),
1932 exp, noside);
1933 }
1934
1935 enum exp_opcode opcode () const override
1936 { return UNOP_CAST; }
1937
1938protected:
1939
1940 void do_generate_ax (struct expression *exp,
1941 struct agent_expr *ax,
1942 struct axs_value *value,
1943 struct type *cast_type)
1944 override;
1945};
1946
292382f4
TT
1947/* A cast, but the type comes from an expression, not a "struct
1948 type". */
1949class unop_cast_type_operation
1950 : public maybe_constant_operation<operation_up, operation_up>
1951{
1952public:
1953
1954 using maybe_constant_operation::maybe_constant_operation;
1955
1956 value *evaluate (struct type *expect_type,
1957 struct expression *exp,
1958 enum noside noside) override
1959 {
1960 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1961 EVAL_AVOID_SIDE_EFFECTS);
1962 return std::get<1> (m_storage)->evaluate_for_cast (value_type (val),
1963 exp, noside);
1964 }
1965
1966 enum exp_opcode opcode () const override
1967 { return UNOP_CAST_TYPE; }
1968
1969protected:
1970
1971 void do_generate_ax (struct expression *exp,
1972 struct agent_expr *ax,
1973 struct axs_value *value,
1974 struct type *cast_type)
1975 override;
1976};
1977
d9ad79d8
TT
1978typedef value *cxx_cast_ftype (struct type *, value *);
1979
1980/* This implements dynamic_cast and reinterpret_cast. static_cast and
1981 const_cast are handled by the ordinary case operations. */
1982template<exp_opcode OP, cxx_cast_ftype FUNC>
1983class cxx_cast_operation
1984 : public maybe_constant_operation<operation_up, operation_up>
1985{
1986public:
1987
1988 using maybe_constant_operation::maybe_constant_operation;
1989
1990 value *evaluate (struct type *expect_type,
1991 struct expression *exp,
1992 enum noside noside) override
1993 {
1994 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
1995 EVAL_AVOID_SIDE_EFFECTS);
1996 struct type *type = value_type (val);
1997 value *rhs = std::get<1> (m_storage)->evaluate (type, exp, noside);
1998 if (noside == EVAL_SKIP)
1999 return eval_skip_value (exp);
2000 return FUNC (type, rhs);
2001 }
2002
2003 enum exp_opcode opcode () const override
2004 { return OP; }
2005};
2006
2007using dynamic_cast_operation = cxx_cast_operation<UNOP_DYNAMIC_CAST,
2008 value_dynamic_cast>;
2009using reinterpret_cast_operation = cxx_cast_operation<UNOP_REINTERPRET_CAST,
2010 value_reinterpret_cast>;
2011
821e72d7
TT
2012/* Multi-dimensional subscripting. */
2013class multi_subscript_operation
2014 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
2015{
2016public:
2017
2018 using tuple_holding_operation::tuple_holding_operation;
2019
2020 value *evaluate (struct type *expect_type,
2021 struct expression *exp,
2022 enum noside noside) override;
2023
2024 enum exp_opcode opcode () const override
2025 { return MULTI_SUBSCRIPT; }
2026};
2027
5019124b
TT
2028/* The "&&" operator. */
2029class logical_and_operation
2030 : public maybe_constant_operation<operation_up, operation_up>
2031{
2032public:
2033
2034 using maybe_constant_operation::maybe_constant_operation;
2035
2036 value *evaluate (struct type *expect_type,
2037 struct expression *exp,
2038 enum noside noside) override;
2039
2040 enum exp_opcode opcode () const override
2041 { return BINOP_LOGICAL_AND; }
2042
2043protected:
2044
2045 void do_generate_ax (struct expression *exp,
2046 struct agent_expr *ax,
2047 struct axs_value *value,
2048 struct type *cast_type)
2049 override;
2050};
2051
2052/* The "||" operator. */
2053class logical_or_operation
2054 : public maybe_constant_operation<operation_up, operation_up>
2055{
2056public:
2057
2058 using maybe_constant_operation::maybe_constant_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 BINOP_LOGICAL_OR; }
2066
2067protected:
2068
2069 void do_generate_ax (struct expression *exp,
2070 struct agent_expr *ax,
2071 struct axs_value *value,
2072 struct type *cast_type)
2073 override;
2074};
2075
e4479080
TT
2076/* This class implements ADL (aka Koenig) function calls for C++. It
2077 holds the name of the function to call, the block in which the
2078 lookup should be done, and a vector of arguments. */
2079class adl_func_operation
2080 : public tuple_holding_operation<std::string, const block *,
2081 std::vector<operation_up>>
2082{
2083public:
2084
2085 using tuple_holding_operation::tuple_holding_operation;
2086
2087 value *evaluate (struct type *expect_type,
2088 struct expression *exp,
2089 enum noside noside) override;
2090
2091 enum exp_opcode opcode () const override
2092 { return OP_ADL_FUNC; }
2093};
2094
1c02eb30
TT
2095/* The OP_ARRAY operation. */
2096class array_operation
2097 : public tuple_holding_operation<int, int, std::vector<operation_up>>
2098{
2099public:
2100
2101 using tuple_holding_operation::tuple_holding_operation;
2102
2103 value *evaluate (struct type *expect_type,
2104 struct expression *exp,
2105 enum noside noside) override;
2106
2107 enum exp_opcode opcode () const override
2108 { return OP_ARRAY; }
2109
2110private:
2111
2112 struct value *evaluate_struct_tuple (struct value *struct_val,
2113 struct expression *exp,
2114 enum noside noside, int nargs);
2115};
2116
a00b7254
TT
2117/* A function call. This holds the callee operation and the
2118 arguments. */
2119class funcall_operation
2120 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
2121{
2122public:
2123
2124 using tuple_holding_operation::tuple_holding_operation;
2125
2126 value *evaluate (struct type *expect_type,
2127 struct expression *exp,
2128 enum noside noside) override
2129 {
2130 return std::get<0> (m_storage)->evaluate_funcall (expect_type, exp, noside,
2131 std::get<1> (m_storage));
2132 }
2133
2134 enum exp_opcode opcode () const override
2135 { return OP_FUNCALL; }
2136};
2137
e2803273
TT
2138} /* namespace expr */
2139
2140#endif /* EXPOP_H */
This page took 0.124299 seconds and 4 git commands to generate.