Implement Ada multiplicative operators
[deliverable/binutils-gdb.git] / gdb / ada-exp.h
1 /* Definitions for Ada expressions
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 ADA_EXP_H
21 #define ADA_EXP_H
22
23 #include "expop.h"
24
25 extern struct value *ada_unop_neg (struct type *expect_type,
26 struct expression *exp,
27 enum noside noside, enum exp_opcode op,
28 struct value *arg1);
29 extern struct value *ada_atr_tag (struct type *expect_type,
30 struct expression *exp,
31 enum noside noside, enum exp_opcode op,
32 struct value *arg1);
33 extern struct value *ada_atr_size (struct type *expect_type,
34 struct expression *exp,
35 enum noside noside, enum exp_opcode op,
36 struct value *arg1);
37 extern struct value *ada_abs (struct type *expect_type,
38 struct expression *exp,
39 enum noside noside, enum exp_opcode op,
40 struct value *arg1);
41 extern struct value *ada_unop_in_range (struct type *expect_type,
42 struct expression *exp,
43 enum noside noside, enum exp_opcode op,
44 struct value *arg1, struct type *type);
45 extern struct value *ada_mult_binop (struct type *expect_type,
46 struct expression *exp,
47 enum noside noside, enum exp_opcode op,
48 struct value *arg1, struct value *arg2);
49
50 namespace expr
51 {
52
53 /* In Ada, some generic operations must be wrapped with a handler that
54 handles some Ada-specific type conversions. */
55 class ada_wrapped_operation
56 : public tuple_holding_operation<operation_up>
57 {
58 public:
59
60 using tuple_holding_operation::tuple_holding_operation;
61
62 value *evaluate (struct type *expect_type,
63 struct expression *exp,
64 enum noside noside) override;
65
66 enum exp_opcode opcode () const override
67 { return std::get<0> (m_storage)->opcode (); }
68 };
69
70 /* An Ada string constant. */
71 class ada_string_operation
72 : public string_operation
73 {
74 public:
75
76 using string_operation::string_operation;
77
78 value *evaluate (struct type *expect_type,
79 struct expression *exp,
80 enum noside noside) override;
81 };
82
83 /* The Ada TYPE'(EXP) construct. */
84 class ada_qual_operation
85 : public tuple_holding_operation<operation_up, struct type *>
86 {
87 public:
88
89 using tuple_holding_operation::tuple_holding_operation;
90
91 value *evaluate (struct type *expect_type,
92 struct expression *exp,
93 enum noside noside) override;
94
95 enum exp_opcode opcode () const override
96 { return UNOP_QUAL; }
97 };
98
99 /* Ternary in-range operator. */
100 class ada_ternop_range_operation
101 : public tuple_holding_operation<operation_up, operation_up, operation_up>
102 {
103 public:
104
105 using tuple_holding_operation::tuple_holding_operation;
106
107 value *evaluate (struct type *expect_type,
108 struct expression *exp,
109 enum noside noside) override;
110
111 enum exp_opcode opcode () const override
112 { return TERNOP_IN_RANGE; }
113 };
114
115 using ada_neg_operation = unop_operation<UNOP_NEG, ada_unop_neg>;
116 using ada_atr_tag_operation = unop_operation<OP_ATR_TAG, ada_atr_tag>;
117 using ada_atr_size_operation = unop_operation<OP_ATR_SIZE, ada_atr_size>;
118 using ada_abs_operation = unop_operation<UNOP_ABS, ada_abs>;
119
120 /* The in-range operation, given a type. */
121 class ada_unop_range_operation
122 : public tuple_holding_operation<operation_up, struct type *>
123 {
124 public:
125
126 using tuple_holding_operation::tuple_holding_operation;
127
128 value *evaluate (struct type *expect_type,
129 struct expression *exp,
130 enum noside noside) override
131 {
132 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
133 return ada_unop_in_range (expect_type, exp, noside, UNOP_IN_RANGE,
134 val, std::get<1> (m_storage));
135 }
136
137 enum exp_opcode opcode () const override
138 { return UNOP_IN_RANGE; }
139 };
140
141 /* The Ada + and - operators. */
142 class ada_binop_addsub_operation
143 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
144 {
145 public:
146
147 using tuple_holding_operation::tuple_holding_operation;
148
149 value *evaluate (struct type *expect_type,
150 struct expression *exp,
151 enum noside noside) override;
152
153 enum exp_opcode opcode () const override
154 { return std::get<0> (m_storage); }
155 };
156
157 using ada_binop_mul_operation = binop_operation<BINOP_MUL, ada_mult_binop>;
158 using ada_binop_div_operation = binop_operation<BINOP_DIV, ada_mult_binop>;
159 using ada_binop_rem_operation = binop_operation<BINOP_REM, ada_mult_binop>;
160 using ada_binop_mod_operation = binop_operation<BINOP_MOD, ada_mult_binop>;
161
162 } /* namespace expr */
163
164 #endif /* ADA_EXP_H */
This page took 0.110797 seconds and 5 git commands to generate.