]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/expression.h
2011-01-07 Michael Snyder <msnyder@vmware.com>
[thirdparty/binutils-gdb.git] / gdb / expression.h
CommitLineData
c906108c 1/* Definitions for expressions stored in reversed prefix form, for GDB.
1bac305b 2
4c38e0a4 3 Copyright (C) 1986, 1989, 1992, 1994, 2000, 2003, 2005, 2007, 2008, 2009,
7b6bb8da 4 2010, 2011 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
c5aa993b 11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b 18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
20
21#if !defined (EXPRESSION_H)
22#define EXPRESSION_H 1
23
24
0963b4bd 25#include "symtab.h" /* Needed for "struct block" type. */
d16aafd8 26#include "doublest.h" /* Needed for DOUBLEST. */
c906108c
SS
27
28
29/* Definitions for saved C expressions. */
30
31/* An expression is represented as a vector of union exp_element's.
32 Each exp_element is an opcode, except that some opcodes cause
33 the following exp_element to be treated as a long or double constant
34 or as a variable. The opcodes are obeyed, using a stack for temporaries.
35 The value is left on the temporary stack at the end. */
36
37/* When it is necessary to include a string,
38 it can occupy as many exp_elements as it needs.
39 We find the length of the string using strlen,
40 divide to find out how many exp_elements are used up,
41 and skip that many. Strings, like numbers, are indicated
42 by the preceding opcode. */
43
44enum exp_opcode
c5aa993b
JM
45 {
46 /* Used when it's necessary to pass an opcode which will be ignored,
47 or to catch uninitialized values. */
48 OP_NULL,
c906108c
SS
49
50/* BINOP_... operate on two values computed by following subexpressions,
51 replacing them by one result value. They take no immediate arguments. */
52
c5aa993b
JM
53 BINOP_ADD, /* + */
54 BINOP_SUB, /* - */
55 BINOP_MUL, /* * */
56 BINOP_DIV, /* / */
57 BINOP_REM, /* % */
58 BINOP_MOD, /* mod (Knuth 1.2.4) */
59 BINOP_LSH, /* << */
60 BINOP_RSH, /* >> */
61 BINOP_LOGICAL_AND, /* && */
62 BINOP_LOGICAL_OR, /* || */
63 BINOP_BITWISE_AND, /* & */
64 BINOP_BITWISE_IOR, /* | */
65 BINOP_BITWISE_XOR, /* ^ */
66 BINOP_EQUAL, /* == */
67 BINOP_NOTEQUAL, /* != */
68 BINOP_LESS, /* < */
69 BINOP_GTR, /* > */
70 BINOP_LEQ, /* <= */
71 BINOP_GEQ, /* >= */
72 BINOP_REPEAT, /* @ */
73 BINOP_ASSIGN, /* = */
74 BINOP_COMMA, /* , */
75 BINOP_SUBSCRIPT, /* x[y] */
76 BINOP_EXP, /* Exponentiation */
77
78 /* C++. */
79
80 BINOP_MIN, /* <? */
81 BINOP_MAX, /* >? */
c5aa993b
JM
82
83 /* STRUCTOP_MEMBER is used for pointer-to-member constructs.
0963b4bd 84 X . * Y translates into X STRUCTOP_MEMBER Y. */
c5aa993b
JM
85 STRUCTOP_MEMBER,
86
87 /* STRUCTOP_MPTR is used for pointer-to-member constructs
88 when X is a pointer instead of an aggregate. */
89 STRUCTOP_MPTR,
90
072bba3b
KS
91 /* TYPE_INSTANCE is used when the user specifies a specific
92 type instantiation for overloaded methods/functions.
93
94 The format is:
0963b4bd 95 TYPE_INSTANCE num_types type0 ... typeN num_types TYPE_INSTANCE. */
072bba3b
KS
96 TYPE_INSTANCE,
97
c5aa993b
JM
98 /* end of C++. */
99
0963b4bd 100 /* For Modula-2 integer division DIV. */
c5aa993b
JM
101 BINOP_INTDIV,
102
103 BINOP_ASSIGN_MODIFY, /* +=, -=, *=, and so on.
104 The following exp_element is another opcode,
105 a BINOP_, saying how to modify.
106 Then comes another BINOP_ASSIGN_MODIFY,
107 making three exp_elements in total. */
108
0963b4bd 109 /* Modula-2 standard (binary) procedures. */
c5aa993b 110 BINOP_VAL,
c5aa993b
JM
111
112 /* Concatenate two operands, such as character strings or bitstrings.
113 If the first operand is a integer expression, then it means concatenate
0963b4bd 114 the second operand with itself that many times. */
c5aa993b
JM
115 BINOP_CONCAT,
116
0963b4bd
MS
117 /* For (the deleted) Chill and Pascal. */
118 BINOP_IN, /* Returns 1 iff ARG1 IN ARG2. */
c5aa993b 119
1b831c93 120 /* This is the "colon operator" used various places in (the
0963b4bd 121 deleted) Chill. */
c5aa993b
JM
122 BINOP_RANGE,
123
124 /* This must be the highest BINOP_ value, for expprint.c. */
125 BINOP_END,
126
127 /* Operates on three values computed by following subexpressions. */
128 TERNOP_COND, /* ?: */
129
1b831c93 130 /* A sub-string/sub-array. (the deleted) Chill syntax:
db034ac5 131 OP1(OP2:OP3). Return elements OP2 through OP3 of OP1. */
c5aa993b
JM
132 TERNOP_SLICE,
133
1b831c93
AC
134 /* A sub-string/sub-array. (The deleted) Chill syntax: OP1(OP2 UP
135 OP3). Return OP3 elements of OP1, starting with element
0963b4bd 136 OP2. */
c5aa993b
JM
137 TERNOP_SLICE_COUNT,
138
139 /* Multidimensional subscript operator, such as Modula-2 x[a,b,...].
140 The dimensionality is encoded in the operator, like the number of
141 function arguments in OP_FUNCALL, I.E. <OP><dimension><OP>.
142 The value of the first following subexpression is subscripted
0963b4bd 143 by each of the next following subexpressions, one per dimension. */
c5aa993b
JM
144 MULTI_SUBSCRIPT,
145
146 /* The OP_... series take immediate following arguments.
147 After the arguments come another OP_... (the same one)
148 so that the grouping can be recognized from the end. */
149
150 /* OP_LONG is followed by a type pointer in the next exp_element
151 and the long constant value in the following exp_element.
152 Then comes another OP_LONG.
153 Thus, the operation occupies four exp_elements. */
154 OP_LONG,
155
3e43a32a
MS
156 /* OP_DOUBLE is similar but takes a DOUBLEST constant instead of a
157 long. */
c5aa993b
JM
158 OP_DOUBLE,
159
160 /* OP_VAR_VALUE takes one struct block * in the following element,
3e43a32a
MS
161 and one struct symbol * in the following exp_element, followed
162 by another OP_VAR_VALUE, making four exp_elements. If the
163 block is non-NULL, evaluate the symbol relative to the
164 innermost frame executing in that block; if the block is NULL
165 use the selected frame. */
c5aa993b
JM
166 OP_VAR_VALUE,
167
168 /* OP_LAST is followed by an integer in the next exp_element.
169 The integer is zero for the last value printed,
170 or it is the absolute number of a history element.
171 With another OP_LAST at the end, this makes three exp_elements. */
172 OP_LAST,
173
67f3407f
DJ
174 /* OP_REGISTER is followed by a string in the next exp_element.
175 This is the name of a register to fetch. */
c5aa993b
JM
176 OP_REGISTER,
177
3e43a32a
MS
178 /* OP_INTERNALVAR is followed by an internalvar ptr in the next
179 exp_element. With another OP_INTERNALVAR at the end, this
180 makes three exp_elements. */
c5aa993b
JM
181 OP_INTERNALVAR,
182
183 /* OP_FUNCALL is followed by an integer in the next exp_element.
184 The integer is the number of args to the function call.
185 That many plus one values from following subexpressions
186 are used, the first one being the function.
187 The integer is followed by a repeat of OP_FUNCALL,
188 making three exp_elements. */
189 OP_FUNCALL,
190
3e43a32a
MS
191 /* OP_OBJC_MSGCALL is followed by a string in the next exp_element
192 and then an integer. The string is the selector string. The
193 integer is the number of arguments to the message call. That
194 many plus one values are used, the first one being the object
0963b4bd 195 pointer. This is an Objective C message. */
646df18d 196 OP_OBJC_MSGCALL,
b01ab485 197
0963b4bd
MS
198 /* This is EXACTLY like OP_FUNCALL but is semantically different.
199 In F77, array subscript expressions, substring expressions and
200 function calls are all exactly the same syntactically. They
201 may only be disambiguated at runtime. Thus this operator,
202 which indicates that we have found something of the form
203 <name> ( <stuff> ). */
c5aa993b
JM
204 OP_F77_UNDETERMINED_ARGLIST,
205
c806c55a
UW
206 /* OP_COMPLEX takes a type in the following element, followed by another
207 OP_COMPLEX, making three exp_elements. It is followed by two double
0963b4bd 208 args, and converts them into a complex number of the given type. */
c5aa993b
JM
209 OP_COMPLEX,
210
211 /* OP_STRING represents a string constant.
212 Its format is the same as that of a STRUCTOP, but the string
213 data is just made into a string constant when the operation
214 is executed. */
215 OP_STRING,
216
217 /* OP_BITSTRING represents a packed bitstring constant.
218 Its format is the same as that of a STRUCTOP, but the bitstring
219 data is just made into a bitstring constant when the operation
220 is executed. */
221 OP_BITSTRING,
222
223 /* OP_ARRAY creates an array constant out of the following subexpressions.
224 It is followed by two exp_elements, the first containing an integer
225 that is the lower bound of the array and the second containing another
226 integer that is the upper bound of the array. The second integer is
227 followed by a repeat of OP_ARRAY, making four exp_elements total.
228 The bounds are used to compute the number of following subexpressions
229 to consume, as well as setting the bounds in the created array constant.
230 The type of the elements is taken from the type of the first subexp,
0963b4bd 231 and they must all match. */
c5aa993b
JM
232 OP_ARRAY,
233
234 /* UNOP_CAST is followed by a type pointer in the next exp_element.
235 With another UNOP_CAST at the end, this makes three exp_elements.
236 It casts the value of the following subexpression. */
237 UNOP_CAST,
238
4e8f195d
TT
239 /* The C++ dynamic_cast operator. */
240 UNOP_DYNAMIC_CAST,
241
242 /* The C++ reinterpret_cast operator. */
243 UNOP_REINTERPRET_CAST,
244
c5aa993b
JM
245 /* UNOP_MEMVAL is followed by a type pointer in the next exp_element
246 With another UNOP_MEMVAL at the end, this makes three exp_elements.
247 It casts the contents of the word addressed by the value of the
248 following subexpression. */
249 UNOP_MEMVAL,
250
9e35dae4
DJ
251 /* UNOP_MEMVAL_TLS is followed by a `struct objfile' pointer in the next
252 exp_element and a type pointer in the following exp_element.
253 With another UNOP_MEMVAL_TLS at the end, this makes four exp_elements.
254 It casts the contents of the word offsetted by the value of the
255 following subexpression from the TLS specified by `struct objfile'. */
256 UNOP_MEMVAL_TLS,
257
c5aa993b
JM
258 /* UNOP_... operate on one value from a following subexpression
259 and replace it with a result. They take no immediate arguments. */
260
261 UNOP_NEG, /* Unary - */
262 UNOP_LOGICAL_NOT, /* Unary ! */
263 UNOP_COMPLEMENT, /* Unary ~ */
264 UNOP_IND, /* Unary * */
265 UNOP_ADDR, /* Unary & */
266 UNOP_PREINCREMENT, /* ++ before an expression */
267 UNOP_POSTINCREMENT, /* ++ after an expression */
268 UNOP_PREDECREMENT, /* -- before an expression */
269 UNOP_POSTDECREMENT, /* -- after an expression */
270 UNOP_SIZEOF, /* Unary sizeof (followed by expression) */
271
272 UNOP_PLUS, /* Unary plus */
273
274 UNOP_CAP, /* Modula-2 standard (unary) procedures */
275 UNOP_CHR,
276 UNOP_ORD,
277 UNOP_ABS,
278 UNOP_FLOAT,
279 UNOP_HIGH,
280 UNOP_MAX,
281 UNOP_MIN,
282 UNOP_ODD,
283 UNOP_TRUNC,
284
c5aa993b
JM
285 OP_BOOL, /* Modula-2 builtin BOOLEAN type */
286 OP_M2_STRING, /* Modula-2 string constants */
287
288 /* STRUCTOP_... operate on a value from a following subexpression
289 by extracting a structure component specified by a string
290 that appears in the following exp_elements (as many as needed).
291 STRUCTOP_STRUCT is used for "." and STRUCTOP_PTR for "->".
292 They differ only in the error message given in case the value is
293 not suitable or the structure component specified is not found.
294
295 The length of the string follows the opcode, followed by
296 BYTES_TO_EXP_ELEM(length) elements containing the data of the
297 string, followed by the length again and the opcode again. */
298
299 STRUCTOP_STRUCT,
300 STRUCTOP_PTR,
301
b01ab485 302 /* C++: OP_THIS is just a placeholder for the class instance variable.
c5aa993b
JM
303 It just comes in a tight (OP_THIS, OP_THIS) pair. */
304 OP_THIS,
305
3e43a32a
MS
306 /* Objective-C: OP_OBJC_SELF is just a placeholder for the class
307 instance variable. It just comes in a tight (OP_OBJC_SELF,
308 OP_OBJC_SELF) pair. */
646df18d 309 OP_OBJC_SELF,
b01ab485 310
0963b4bd 311 /* Objective C: "@selector" pseudo-operator. */
646df18d 312 OP_OBJC_SELECTOR,
b01ab485 313
c5aa993b
JM
314 /* OP_SCOPE surrounds a type name and a field name. The type
315 name is encoded as one element, but the field name stays as
316 a string, which, of course, is variable length. */
317 OP_SCOPE,
318
db034ac5 319 /* Used to represent named structure field values in brace
1b831c93
AC
320 initializers (or tuples as they are called in (the deleted)
321 Chill).
db034ac5 322
1b831c93
AC
323 The gcc C syntax is NAME:VALUE or .NAME=VALUE, the (the
324 deleted) Chill syntax is .NAME:VALUE. Multiple labels (as in
325 the (the deleted) Chill syntax .NAME1,.NAME2:VALUE) is
db034ac5 326 represented as if it were .NAME1:(.NAME2:VALUE) (though that is
1b831c93 327 not valid (the deleted) Chill syntax).
c5aa993b 328
0963b4bd 329 The NAME is represented as for STRUCTOP_STRUCT; VALUE follows. */
c5aa993b
JM
330 OP_LABELED,
331
332 /* OP_TYPE is for parsing types, and used with the "ptype" command
333 so we can look up types that are qualified by scope, either with
0963b4bd 334 the GDB "::" operator, or the Modula-2 '.' operator. */
c5aa993b
JM
335 OP_TYPE,
336
0963b4bd 337 /* An un-looked-up identifier. */
c5aa993b
JM
338 OP_NAME,
339
0963b4bd 340 /* An Objective C Foundation Class NSString constant. */
5f9769d1
PH
341 OP_OBJC_NSSTRING,
342
c3e308a8 343 /* A F90 array range operator (for "exp:exp", "exp:", ":exp" and ":"). */
0b4e1325
WZ
344 OP_F90_RANGE,
345
27bc4d80
TJB
346 /* OP_DECFLOAT is followed by a type pointer in the next exp_element
347 and a dec long constant value in the following exp_element.
348 Then comes another OP_DECFLOAT. */
349 OP_DECFLOAT,
350
7322dca9
SW
351 /* OP_ADL_FUNC specifies that the function is to be looked up in an
352 Argument Dependent manner (Koenig lookup). */
353 OP_ADL_FUNC,
354
5f9769d1 355 /* First extension operator. Individual language modules define
8285870a
JK
356 extra operators in *.inc include files below always starting with
357 numbering at OP_EXTENDED0:
5f9769d1
PH
358 BINOP_MOGRIFY = OP_EXTENDED0,
359 BINOP_FROB,
8285870a 360 ... */
5f9769d1
PH
361 OP_EXTENDED0,
362
363 /* Last possible extension operator. Defined to provide an
0963b4bd 364 explicit and finite number of extended operators. */
8285870a 365 OP_EXTENDED_LAST = 0xff,
5f9769d1
PH
366 /* NOTE: Eventually, we expect to convert to an object-oriented
367 formulation for expression operators that does away with the
368 need for these extension operators, and indeed for this
369 entire enumeration type. Therefore, consider the OP_EXTENDED
0963b4bd 370 definitions to be a temporary measure. */
8285870a
JK
371
372 /* Each language specific set of operators starts at OP_EXTENDED0. */
373#include "ada-operator.inc"
374
375 /* Existing only to swallow the last comma (',') from last .inc file. */
376 OP_UNUSED_LAST
c5aa993b 377 };
c906108c
SS
378
379union exp_element
c5aa993b
JM
380 {
381 enum exp_opcode opcode;
382 struct symbol *symbol;
383 LONGEST longconst;
384 DOUBLEST doubleconst;
27bc4d80 385 gdb_byte decfloatconst[16];
c5aa993b
JM
386 /* Really sizeof (union exp_element) characters (or less for the last
387 element of a string). */
388 char string;
389 struct type *type;
390 struct internalvar *internalvar;
391 struct block *block;
9e35dae4 392 struct objfile *objfile;
c5aa993b 393 };
c906108c
SS
394
395struct expression
c5aa993b 396 {
3e43a32a 397 const struct language_defn *language_defn; /* language it was
0963b4bd
MS
398 entered in. */
399 struct gdbarch *gdbarch; /* architecture it was parsed in. */
c5aa993b
JM
400 int nelts;
401 union exp_element elts[1];
402 };
c906108c
SS
403
404/* Macros for converting between number of expression elements and bytes
0963b4bd 405 to store that many expression elements. */
c906108c
SS
406
407#define EXP_ELEM_TO_BYTES(elements) \
408 ((elements) * sizeof (union exp_element))
409#define BYTES_TO_EXP_ELEM(bytes) \
410 (((bytes) + sizeof (union exp_element) - 1) / sizeof (union exp_element))
411
412/* From parse.c */
413
a14ed312 414extern struct expression *parse_expression (char *);
c906108c 415
65d12d83
TT
416extern struct type *parse_field_expression (char *, char **);
417
a14ed312 418extern struct expression *parse_exp_1 (char **, struct block *, int);
c906108c 419
65d12d83
TT
420/* For use by parsers; set if we want to parse an expression and
421 attempt to complete a field name. */
422extern int in_parse_field;
423
c906108c
SS
424/* The innermost context required by the stack and register variables
425 we've encountered so far. To use this, set it to NULL, then call
426 parse_<whatever>, then look at it. */
427extern struct block *innermost_block;
428
429/* From eval.c */
430
389e51db 431/* Values of NOSIDE argument to eval_subexp. */
c906108c
SS
432
433enum noside
c5aa993b
JM
434 {
435 EVAL_NORMAL,
436 EVAL_SKIP, /* Only effect is to increment pos. */
437 EVAL_AVOID_SIDE_EFFECTS /* Don't modify any variables or
c906108c
SS
438 call any functions. The value
439 returned will have the correct
440 type, and will have an
441 approximately correct lvalue
442 type (inaccuracy: anything that is
443 listed as being in a register in
444 the function in which it was
445 declared will be lval_register). */
c5aa993b 446 };
c906108c 447
c5aa993b 448extern struct value *evaluate_subexp_standard
a14ed312 449 (struct type *, struct expression *, int *, enum noside);
c906108c
SS
450
451/* From expprint.c */
452
d9fcf2fb 453extern void print_expression (struct expression *, struct ui_file *);
c906108c 454
a14ed312 455extern char *op_string (enum exp_opcode);
c906108c 456
3e43a32a
MS
457extern void dump_raw_expression (struct expression *,
458 struct ui_file *, char *);
24daaebc 459extern void dump_prefix_expression (struct expression *, struct ui_file *);
c906108c 460
c5aa993b 461#endif /* !defined (EXPRESSION_H) */