1 /* Definitions for expressions stored in reversed prefix form, for GDB.
3 Copyright (C) 1986, 1989, 1992, 1994, 2000, 2003, 2005, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
6 This file is part of GDB.
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
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #if !defined (EXPRESSION_H)
22 #define EXPRESSION_H 1
25 #include "symtab.h" /* Needed for "struct block" type. */
26 #include "doublest.h" /* Needed for DOUBLEST. */
29 /* Definitions for saved C expressions. */
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. */
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. */
46 /* Used when it's necessary to pass an opcode which will be ignored,
47 or to catch uninitialized values. */
50 /* BINOP_... operate on two values computed by following subexpressions,
51 replacing them by one result value. They take no immediate arguments. */
58 BINOP_MOD, /* mod (Knuth 1.2.4) */
61 BINOP_LOGICAL_AND, /* && */
62 BINOP_LOGICAL_OR, /* || */
63 BINOP_BITWISE_AND, /* & */
64 BINOP_BITWISE_IOR, /* | */
65 BINOP_BITWISE_XOR, /* ^ */
67 BINOP_NOTEQUAL, /* != */
75 BINOP_SUBSCRIPT, /* x[y] */
76 BINOP_EXP, /* Exponentiation */
83 /* STRUCTOP_MEMBER is used for pointer-to-member constructs.
84 X . * Y translates into X STRUCTOP_MEMBER Y. */
87 /* STRUCTOP_MPTR is used for pointer-to-member constructs
88 when X is a pointer instead of an aggregate. */
91 /* TYPE_INSTANCE is used when the user specifies a specific
92 type instantiation for overloaded methods/functions.
95 TYPE_INSTANCE num_types type0 ... typeN num_types TYPE_INSTANCE */
100 /* For Modula-2 integer division DIV */
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. */
109 /* Modula-2 standard (binary) procedures */
114 /* Concatenate two operands, such as character strings or bitstrings.
115 If the first operand is a integer expression, then it means concatenate
116 the second operand with itself that many times. */
119 /* For (the deleted) Chill and Pascal. */
120 BINOP_IN, /* Returns 1 iff ARG1 IN ARG2. */
122 /* This is the "colon operator" used various places in (the
126 /* This must be the highest BINOP_ value, for expprint.c. */
129 /* Operates on three values computed by following subexpressions. */
130 TERNOP_COND, /* ?: */
132 /* A sub-string/sub-array. (the deleted) Chill syntax:
133 OP1(OP2:OP3). Return elements OP2 through OP3 of OP1. */
136 /* A sub-string/sub-array. (The deleted) Chill syntax: OP1(OP2 UP
137 OP3). Return OP3 elements of OP1, starting with element
141 /* Multidimensional subscript operator, such as Modula-2 x[a,b,...].
142 The dimensionality is encoded in the operator, like the number of
143 function arguments in OP_FUNCALL, I.E. <OP><dimension><OP>.
144 The value of the first following subexpression is subscripted
145 by each of the next following subexpressions, one per dimension. */
148 /* The OP_... series take immediate following arguments.
149 After the arguments come another OP_... (the same one)
150 so that the grouping can be recognized from the end. */
152 /* OP_LONG is followed by a type pointer in the next exp_element
153 and the long constant value in the following exp_element.
154 Then comes another OP_LONG.
155 Thus, the operation occupies four exp_elements. */
158 /* OP_DOUBLE is similar but takes a DOUBLEST constant instead of a long. */
161 /* OP_VAR_VALUE takes one struct block * in the following element,
162 and one struct symbol * in the following exp_element, followed by
163 another OP_VAR_VALUE, making four exp_elements. If the block is
164 non-NULL, evaluate the symbol relative to the innermost frame
165 executing in that block; if the block is NULL use the selected frame. */
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. */
174 /* OP_REGISTER is followed by a string in the next exp_element.
175 This is the name of a register to fetch. */
178 /* OP_INTERNALVAR is followed by an internalvar ptr in the next exp_element.
179 With another OP_INTERNALVAR at the end, this makes three exp_elements. */
182 /* OP_FUNCALL is followed by an integer in the next exp_element.
183 The integer is the number of args to the function call.
184 That many plus one values from following subexpressions
185 are used, the first one being the function.
186 The integer is followed by a repeat of OP_FUNCALL,
187 making three exp_elements. */
190 /* OP_OBJC_MSGCALL is followed by a string in the next exp_element and then an
191 integer. The string is the selector string. The integer is the number
192 of arguments to the message call. That many plus one values are used,
193 the first one being the object pointer. This is an Objective C message */
196 /* This is EXACTLY like OP_FUNCALL but is semantically different.
197 In F77, array subscript expressions, substring expressions
198 and function calls are all exactly the same syntactically. They may
199 only be disambiguated at runtime. Thus this operator, which
200 indicates that we have found something of the form <name> ( <stuff> ) */
201 OP_F77_UNDETERMINED_ARGLIST,
203 /* OP_COMPLEX takes a type in the following element, followed by another
204 OP_COMPLEX, making three exp_elements. It is followed by two double
205 args, and converts them into a complex number of the given type. */
208 /* OP_STRING represents a string constant.
209 Its format is the same as that of a STRUCTOP, but the string
210 data is just made into a string constant when the operation
214 /* OP_BITSTRING represents a packed bitstring constant.
215 Its format is the same as that of a STRUCTOP, but the bitstring
216 data is just made into a bitstring constant when the operation
220 /* OP_ARRAY creates an array constant out of the following subexpressions.
221 It is followed by two exp_elements, the first containing an integer
222 that is the lower bound of the array and the second containing another
223 integer that is the upper bound of the array. The second integer is
224 followed by a repeat of OP_ARRAY, making four exp_elements total.
225 The bounds are used to compute the number of following subexpressions
226 to consume, as well as setting the bounds in the created array constant.
227 The type of the elements is taken from the type of the first subexp,
228 and they must all match. */
231 /* UNOP_CAST is followed by a type pointer in the next exp_element.
232 With another UNOP_CAST at the end, this makes three exp_elements.
233 It casts the value of the following subexpression. */
236 /* The C++ dynamic_cast operator. */
239 /* The C++ reinterpret_cast operator. */
240 UNOP_REINTERPRET_CAST,
242 /* UNOP_MEMVAL is followed by a type pointer in the next exp_element
243 With another UNOP_MEMVAL at the end, this makes three exp_elements.
244 It casts the contents of the word addressed by the value of the
245 following subexpression. */
248 /* UNOP_MEMVAL_TLS is followed by a `struct objfile' pointer in the next
249 exp_element and a type pointer in the following exp_element.
250 With another UNOP_MEMVAL_TLS at the end, this makes four exp_elements.
251 It casts the contents of the word offsetted by the value of the
252 following subexpression from the TLS specified by `struct objfile'. */
255 /* UNOP_... operate on one value from a following subexpression
256 and replace it with a result. They take no immediate arguments. */
258 UNOP_NEG, /* Unary - */
259 UNOP_LOGICAL_NOT, /* Unary ! */
260 UNOP_COMPLEMENT, /* Unary ~ */
261 UNOP_IND, /* Unary * */
262 UNOP_ADDR, /* Unary & */
263 UNOP_PREINCREMENT, /* ++ before an expression */
264 UNOP_POSTINCREMENT, /* ++ after an expression */
265 UNOP_PREDECREMENT, /* -- before an expression */
266 UNOP_POSTDECREMENT, /* -- after an expression */
267 UNOP_SIZEOF, /* Unary sizeof (followed by expression) */
269 UNOP_PLUS, /* Unary plus */
271 UNOP_CAP, /* Modula-2 standard (unary) procedures */
282 /* (The deleted) Chill builtin functions. */
283 UNOP_LOWER, UNOP_UPPER, UNOP_LENGTH, UNOP_CARD, UNOP_CHMAX, UNOP_CHMIN,
285 OP_BOOL, /* Modula-2 builtin BOOLEAN type */
286 OP_M2_STRING, /* Modula-2 string constants */
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.
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. */
302 /* C++: OP_THIS is just a placeholder for the class instance variable.
303 It just comes in a tight (OP_THIS, OP_THIS) pair. */
306 /* Objective-C: OP_OBJC_SELF is just a placeholder for the class instance
307 variable. It just comes in a tight (OP_OBJC_SELF, OP_OBJC_SELF) pair. */
310 /* Objective C: "@selector" pseudo-operator */
313 /* OP_SCOPE surrounds a type name and a field name. The type
314 name is encoded as one element, but the field name stays as
315 a string, which, of course, is variable length. */
318 /* Used to represent named structure field values in brace
319 initializers (or tuples as they are called in (the deleted)
322 The gcc C syntax is NAME:VALUE or .NAME=VALUE, the (the
323 deleted) Chill syntax is .NAME:VALUE. Multiple labels (as in
324 the (the deleted) Chill syntax .NAME1,.NAME2:VALUE) is
325 represented as if it were .NAME1:(.NAME2:VALUE) (though that is
326 not valid (the deleted) Chill syntax).
328 The NAME is represented as for STRUCTOP_STRUCT; VALUE follows. */
331 /* OP_TYPE is for parsing types, and used with the "ptype" command
332 so we can look up types that are qualified by scope, either with
333 the GDB "::" operator, or the Modula-2 '.' operator. */
336 /* An un-looked-up identifier. */
339 /* An Objective C Foundation Class NSString constant */
342 /* A F90 array range operator (for "exp:exp", "exp:", ":exp" and ":"). */
345 /* OP_DECFLOAT is followed by a type pointer in the next exp_element
346 and a dec long constant value in the following exp_element.
347 Then comes another OP_DECFLOAT. */
350 /* OP_ADL_FUNC specifies that the function is to be looked up in an
351 Argument Dependent manner (Koenig lookup). */
354 /* First extension operator. Individual language modules define
355 extra operators in *.inc include files below always starting with
356 numbering at OP_EXTENDED0:
357 BINOP_MOGRIFY = OP_EXTENDED0,
362 /* Last possible extension operator. Defined to provide an
363 explicit and finite number of extended operators. */
364 OP_EXTENDED_LAST = 0xff,
365 /* NOTE: Eventually, we expect to convert to an object-oriented
366 formulation for expression operators that does away with the
367 need for these extension operators, and indeed for this
368 entire enumeration type. Therefore, consider the OP_EXTENDED
369 definitions to be a temporary measure. */
371 /* Each language specific set of operators starts at OP_EXTENDED0. */
372 #include "ada-operator.inc"
374 /* Existing only to swallow the last comma (',') from last .inc file. */
380 enum exp_opcode opcode;
381 struct symbol *symbol;
383 DOUBLEST doubleconst;
384 gdb_byte decfloatconst[16];
385 /* Really sizeof (union exp_element) characters (or less for the last
386 element of a string). */
389 struct internalvar *internalvar;
391 struct objfile *objfile;
396 const struct language_defn *language_defn; /* language it was entered in */
397 struct gdbarch *gdbarch; /* architecture it was parsed in */
399 union exp_element elts[1];
402 /* Macros for converting between number of expression elements and bytes
403 to store that many expression elements. */
405 #define EXP_ELEM_TO_BYTES(elements) \
406 ((elements) * sizeof (union exp_element))
407 #define BYTES_TO_EXP_ELEM(bytes) \
408 (((bytes) + sizeof (union exp_element) - 1) / sizeof (union exp_element))
412 extern struct expression *parse_expression (char *);
414 extern struct type *parse_field_expression (char *, char **);
416 extern struct expression *parse_exp_1 (char **, struct block *, int);
418 /* For use by parsers; set if we want to parse an expression and
419 attempt to complete a field name. */
420 extern int in_parse_field;
422 /* The innermost context required by the stack and register variables
423 we've encountered so far. To use this, set it to NULL, then call
424 parse_<whatever>, then look at it. */
425 extern struct block *innermost_block;
429 /* Values of NOSIDE argument to eval_subexp. */
434 EVAL_SKIP, /* Only effect is to increment pos. */
435 EVAL_AVOID_SIDE_EFFECTS /* Don't modify any variables or
436 call any functions. The value
437 returned will have the correct
438 type, and will have an
439 approximately correct lvalue
440 type (inaccuracy: anything that is
441 listed as being in a register in
442 the function in which it was
443 declared will be lval_register). */
446 extern struct value *evaluate_subexp_standard
447 (struct type *, struct expression *, int *, enum noside);
449 /* From expprint.c */
451 extern void print_expression (struct expression *, struct ui_file *);
453 extern char *op_string (enum exp_opcode);
455 extern void dump_raw_expression (struct expression *, struct ui_file *, char *);
456 extern void dump_prefix_expression (struct expression *, struct ui_file *);
458 #endif /* !defined (EXPRESSION_H) */