]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Definitions for expressions stored in reversed prefix form, for GDB. |
35fcebce | 2 | Copyright 1986, 1989, 1992 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
35fcebce | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
35fcebce PB |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
35fcebce | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
35fcebce PB |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #if !defined (EXPRESSION_H) | |
21 | #define EXPRESSION_H 1 | |
bd5635a1 | 22 | |
54bbbfb4 FF |
23 | #ifdef __STDC__ |
24 | struct block; /* Forward declaration for prototypes */ | |
25 | #endif | |
26 | ||
bd5635a1 RP |
27 | /* Definitions for saved C expressions. */ |
28 | ||
29 | /* An expression is represented as a vector of union exp_element's. | |
30 | Each exp_element is an opcode, except that some opcodes cause | |
31 | the following exp_element to be treated as a long or double constant | |
32 | or as a variable. The opcodes are obeyed, using a stack for temporaries. | |
33 | The value is left on the temporary stack at the end. */ | |
34 | ||
35 | /* When it is necessary to include a string, | |
36 | it can occupy as many exp_elements as it needs. | |
37 | We find the length of the string using strlen, | |
38 | divide to find out how many exp_elements are used up, | |
39 | and skip that many. Strings, like numbers, are indicated | |
40 | by the preceding opcode. */ | |
41 | ||
42 | enum exp_opcode | |
43 | { | |
35fcebce PB |
44 | /* Used when it's necessary to pass an opcode which will be ignored, |
45 | or to catch uninitialized values. */ | |
46 | OP_NULL, | |
47 | ||
bd5635a1 RP |
48 | /* BINOP_... operate on two values computed by following subexpressions, |
49 | replacing them by one result value. They take no immediate arguments. */ | |
50 | BINOP_ADD, /* + */ | |
51 | BINOP_SUB, /* - */ | |
52 | BINOP_MUL, /* * */ | |
53 | BINOP_DIV, /* / */ | |
54 | BINOP_REM, /* % */ | |
76a0ffb4 | 55 | BINOP_MOD, /* mod (Knuth 1.2.4) */ |
bd5635a1 RP |
56 | BINOP_LSH, /* << */ |
57 | BINOP_RSH, /* >> */ | |
54bbbfb4 FF |
58 | BINOP_LOGICAL_AND, /* && */ |
59 | BINOP_LOGICAL_OR, /* || */ | |
60 | BINOP_BITWISE_AND, /* & */ | |
61 | BINOP_BITWISE_IOR, /* | */ | |
62 | BINOP_BITWISE_XOR, /* ^ */ | |
bd5635a1 RP |
63 | BINOP_EQUAL, /* == */ |
64 | BINOP_NOTEQUAL, /* != */ | |
65 | BINOP_LESS, /* < */ | |
66 | BINOP_GTR, /* > */ | |
67 | BINOP_LEQ, /* <= */ | |
68 | BINOP_GEQ, /* >= */ | |
69 | BINOP_REPEAT, /* @ */ | |
70 | BINOP_ASSIGN, /* = */ | |
71 | BINOP_COMMA, /* , */ | |
72 | BINOP_SUBSCRIPT, /* x[y] */ | |
73 | BINOP_EXP, /* Exponentiation */ | |
74 | ||
75 | /* C++. */ | |
76 | BINOP_MIN, /* <? */ | |
77 | BINOP_MAX, /* >? */ | |
78 | BINOP_SCOPE, /* :: */ | |
79 | ||
80 | /* STRUCTOP_MEMBER is used for pointer-to-member constructs. | |
81 | X . * Y translates into X STRUCTOP_MEMBER Y. */ | |
82 | STRUCTOP_MEMBER, | |
83 | /* STRUCTOP_MPTR is used for pointer-to-member constructs | |
84 | when X is a pointer instead of an aggregate. */ | |
85 | STRUCTOP_MPTR, | |
86 | /* end of C++. */ | |
87 | ||
35fcebce PB |
88 | /* For Modula-2 integer division DIV */ |
89 | BINOP_INTDIV, | |
bd5635a1 RP |
90 | |
91 | BINOP_ASSIGN_MODIFY, /* +=, -=, *=, and so on. | |
92 | The following exp_element is another opcode, | |
93 | a BINOP_, saying how to modify. | |
94 | Then comes another BINOP_ASSIGN_MODIFY, | |
95 | making three exp_elements in total. */ | |
96 | ||
35fcebce PB |
97 | /* Modula-2 standard (binary) procedures*/ |
98 | BINOP_VAL, | |
99 | BINOP_INCL, | |
100 | BINOP_EXCL, | |
101 | ||
102 | /* This must be the highest BINOP_ value, for expprint.c. */ | |
103 | BINOP_END, | |
104 | ||
bd5635a1 RP |
105 | /* Operates on three values computed by following subexpressions. */ |
106 | TERNOP_COND, /* ?: */ | |
107 | ||
54bbbfb4 FF |
108 | /* Multidimensional subscript operator, such as Modula-2 x[a,b,...]. |
109 | The dimensionality is encoded in the operator, like the number of | |
110 | function arguments in OP_FUNCALL, I.E. <OP><dimension><OP>. | |
111 | The value of the first following subexpression is subscripted | |
112 | by each of the next following subexpressions, one per dimension. */ | |
113 | ||
114 | MULTI_SUBSCRIPT, | |
115 | ||
bd5635a1 RP |
116 | /* The OP_... series take immediate following arguments. |
117 | After the arguments come another OP_... (the same one) | |
118 | so that the grouping can be recognized from the end. */ | |
119 | ||
120 | /* OP_LONG is followed by a type pointer in the next exp_element | |
121 | and the long constant value in the following exp_element. | |
122 | Then comes another OP_LONG. | |
123 | Thus, the operation occupies four exp_elements. */ | |
124 | ||
125 | OP_LONG, | |
126 | /* OP_DOUBLE is similar but takes a double constant instead of a long one. */ | |
127 | OP_DOUBLE, | |
128 | /* OP_VAR_VALUE takes one struct symbol * in the following exp_element, | |
129 | followed by another OP_VAR_VALUE, making three exp_elements. */ | |
130 | OP_VAR_VALUE, | |
131 | /* OP_LAST is followed by an integer in the next exp_element. | |
132 | The integer is zero for the last value printed, | |
133 | or it is the absolute number of a history element. | |
134 | With another OP_LAST at the end, this makes three exp_elements. */ | |
135 | OP_LAST, | |
136 | /* OP_REGISTER is followed by an integer in the next exp_element. | |
137 | This is the number of a register to fetch (as an int). | |
138 | With another OP_REGISTER at the end, this makes three exp_elements. */ | |
139 | OP_REGISTER, | |
140 | /* OP_INTERNALVAR is followed by an internalvar ptr in the next exp_element. | |
141 | With another OP_INTERNALVAR at the end, this makes three exp_elements. */ | |
142 | OP_INTERNALVAR, | |
143 | /* OP_FUNCALL is followed by an integer in the next exp_element. | |
144 | The integer is the number of args to the function call. | |
145 | That many plus one values from following subexpressions | |
146 | are used, the first one being the function. | |
147 | The integer is followed by a repeat of OP_FUNCALL, | |
148 | making three exp_elements. */ | |
149 | OP_FUNCALL, | |
150 | /* OP_STRING represents a string constant. | |
151 | Its format is the same as that of a STRUCTOP, but the string | |
152 | data is just made into a string constant when the operation | |
153 | is executed. */ | |
154 | OP_STRING, | |
155 | ||
156 | /* UNOP_CAST is followed by a type pointer in the next exp_element. | |
157 | With another UNOP_CAST at the end, this makes three exp_elements. | |
158 | It casts the value of the following subexpression. */ | |
159 | UNOP_CAST, | |
160 | /* UNOP_MEMVAL is followed by a type pointer in the next exp_element | |
161 | With another UNOP_MEMVAL at the end, this makes three exp_elements. | |
162 | It casts the contents of the word addressed by the value of the | |
163 | following subexpression. */ | |
164 | UNOP_MEMVAL, | |
165 | /* UNOP_... operate on one value from a following subexpression | |
166 | and replace it with a result. They take no immediate arguments. */ | |
167 | UNOP_NEG, /* Unary - */ | |
54bbbfb4 FF |
168 | UNOP_LOGICAL_NOT, /* Unary ! */ |
169 | UNOP_COMPLEMENT, /* Unary ~ */ | |
bd5635a1 RP |
170 | UNOP_IND, /* Unary * */ |
171 | UNOP_ADDR, /* Unary & */ | |
172 | UNOP_PREINCREMENT, /* ++ before an expression */ | |
173 | UNOP_POSTINCREMENT, /* ++ after an expression */ | |
174 | UNOP_PREDECREMENT, /* -- before an expression */ | |
175 | UNOP_POSTDECREMENT, /* -- after an expression */ | |
176 | UNOP_SIZEOF, /* Unary sizeof (followed by expression) */ | |
177 | ||
35fcebce PB |
178 | UNOP_PLUS, /* Unary plus */ |
179 | ||
180 | UNOP_CAP, /* Modula-2 standard (unary) procedures */ | |
181 | UNOP_CHR, | |
182 | UNOP_ORD, | |
183 | UNOP_ABS, | |
184 | UNOP_FLOAT, | |
185 | UNOP_HIGH, | |
186 | UNOP_MAX, | |
187 | UNOP_MIN, | |
188 | UNOP_ODD, | |
189 | UNOP_TRUNC, | |
190 | ||
191 | OP_BOOL, /* Modula-2 builtin BOOLEAN type */ | |
192 | OP_M2_STRING, /* Modula-2 string constants */ | |
193 | ||
bd5635a1 RP |
194 | /* STRUCTOP_... operate on a value from a following subexpression |
195 | by extracting a structure component specified by a string | |
196 | that appears in the following exp_elements (as many as needed). | |
197 | STRUCTOP_STRUCT is used for "." and STRUCTOP_PTR for "->". | |
198 | They differ only in the error message given in case the value is | |
199 | not suitable or the structure component specified is not found. | |
200 | ||
201 | The length of the string follows in the next exp_element, | |
202 | (after the string), followed by another STRUCTOP_... code. */ | |
203 | STRUCTOP_STRUCT, | |
204 | STRUCTOP_PTR, | |
205 | ||
206 | /* C++ */ | |
207 | /* OP_THIS is just a placeholder for the class instance variable. | |
208 | It just comes in a tight (OP_THIS, OP_THIS) pair. */ | |
209 | OP_THIS, | |
210 | ||
211 | /* OP_SCOPE surrounds a type name and a field name. The type | |
212 | name is encoded as one element, but the field name stays as | |
213 | a string, which, of course, is variable length. */ | |
214 | OP_SCOPE, | |
215 | ||
35fcebce PB |
216 | /* OP_TYPE is for parsing types, and used with the "ptype" command |
217 | so we can look up types that are qualified by scope, either with | |
218 | the GDB "::" operator, or the Modula-2 '.' operator. */ | |
219 | OP_TYPE | |
bd5635a1 RP |
220 | }; |
221 | ||
222 | union exp_element | |
223 | { | |
224 | enum exp_opcode opcode; | |
225 | struct symbol *symbol; | |
226 | LONGEST longconst; | |
227 | double doubleconst; | |
228 | char string; | |
229 | struct type *type; | |
230 | struct internalvar *internalvar; | |
231 | }; | |
232 | ||
233 | struct expression | |
234 | { | |
35fcebce | 235 | const struct language_defn *language_defn; /* language it was entered in */ |
bd5635a1 RP |
236 | int nelts; |
237 | union exp_element elts[1]; | |
238 | }; | |
239 | ||
35fcebce PB |
240 | /* From parse.c */ |
241 | ||
242 | extern struct expression * | |
243 | parse_expression PARAMS ((char *)); | |
244 | ||
245 | extern struct expression * | |
246 | parse_exp_1 PARAMS ((char **, struct block *, int)); | |
bd5635a1 RP |
247 | |
248 | /* The innermost context required by the stack and register variables | |
249 | we've encountered so far. To use this, set it to NULL, then call | |
35fcebce | 250 | parse_<whatever>, then look at it. */ |
bd5635a1 RP |
251 | extern struct block *innermost_block; |
252 | ||
35fcebce PB |
253 | /* From expprint.c */ |
254 | ||
255 | extern void | |
256 | print_expression PARAMS ((struct expression *, FILE *)); | |
257 | ||
258 | extern char * | |
259 | op_string PARAMS ((enum exp_opcode)); | |
260 | ||
54bbbfb4 FF |
261 | /* To enable dumping of all parsed expressions in a human readable |
262 | form, define DEBUG_EXPRESSIONS. This is a compile time constant | |
263 | at the moment, since it's not clear that this feature is important | |
264 | enough to include by default. */ | |
265 | ||
266 | #ifdef DEBUG_EXPRESSIONS | |
267 | extern void | |
268 | dump_expression PARAMS ((struct expression *, FILE *, char *)); | |
269 | #define DUMP_EXPRESSION(exp,file,note) dump_expression ((exp), (file), (note)) | |
270 | #else | |
271 | #define DUMP_EXPRESSION(exp,file,note) /* Null expansion */ | |
272 | #endif /* DEBUG_EXPRESSIONS */ | |
273 | ||
35fcebce | 274 | #endif /* !defined (EXPRESSION_H) */ |