1 /* Definitions for expressions stored in reversed prefix form, for GDB.
2 Copyright 1986, 1989, 1992, 1994 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #if !defined (EXPRESSION_H)
21 #define EXPRESSION_H 1
24 struct block; /* Forward declaration for prototypes */
27 /* Definitions for saved C expressions. */
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. */
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. */
44 /* Used when it's necessary to pass an opcode which will be ignored,
45 or to catch uninitialized values. */
48 /* BINOP_... operate on two values computed by following subexpressions,
49 replacing them by one result value. They take no immediate arguments. */
56 BINOP_MOD, /* mod (Knuth 1.2.4) */
59 BINOP_LOGICAL_AND, /* && */
60 BINOP_LOGICAL_OR, /* || */
61 BINOP_BITWISE_AND, /* & */
62 BINOP_BITWISE_IOR, /* | */
63 BINOP_BITWISE_XOR, /* ^ */
65 BINOP_NOTEQUAL, /* != */
73 BINOP_SUBSCRIPT, /* x[y] */
74 BINOP_EXP, /* Exponentiation */
82 /* STRUCTOP_MEMBER is used for pointer-to-member constructs.
83 X . * Y translates into X STRUCTOP_MEMBER Y. */
86 /* STRUCTOP_MPTR is used for pointer-to-member constructs
87 when X is a pointer instead of an aggregate. */
92 /* For Modula-2 integer division DIV */
95 BINOP_ASSIGN_MODIFY, /* +=, -=, *=, and so on.
96 The following exp_element is another opcode,
97 a BINOP_, saying how to modify.
98 Then comes another BINOP_ASSIGN_MODIFY,
99 making three exp_elements in total. */
101 /* Modula-2 standard (binary) procedures */
106 /* Concatenate two operands, such as character strings or bitstrings.
107 If the first operand is a integer expression, then it means concatenate
108 the second operand with itself that many times. */
111 /* For Chill and Pascal. */
112 BINOP_IN, /* Returns 1 iff ARG1 IN ARG2. */
114 /* This must be the highest BINOP_ value, for expprint.c. */
117 /* Operates on three values computed by following subexpressions. */
118 TERNOP_COND, /* ?: */
120 /* A sub-string/sub-array. Chill syntax: OP1(OP2:OP3).
121 Return elements OP2 through OP3 of OP1. */
124 /* A sub-string/sub-array. Chill syntax: OP1(OP2 UP OP3).
125 Return OP3 elements of OP1, starting with element OP2. */
128 /* Multidimensional subscript operator, such as Modula-2 x[a,b,...].
129 The dimensionality is encoded in the operator, like the number of
130 function arguments in OP_FUNCALL, I.E. <OP><dimension><OP>.
131 The value of the first following subexpression is subscripted
132 by each of the next following subexpressions, one per dimension. */
135 /* For Fortran array subscripting (column major style). Like the
136 Modula operator, we find that the dimensionality is
137 encoded in the operator. This operator is distinct
138 from the above one because it uses column-major array
139 ordering not row-major. */
142 /* The OP_... series take immediate following arguments.
143 After the arguments come another OP_... (the same one)
144 so that the grouping can be recognized from the end. */
146 /* OP_LONG is followed by a type pointer in the next exp_element
147 and the long constant value in the following exp_element.
148 Then comes another OP_LONG.
149 Thus, the operation occupies four exp_elements. */
152 /* OP_DOUBLE is similar but takes a double constant instead of a long. */
155 /* OP_VAR_VALUE takes one struct block * in the following element,
156 and one struct symbol * in the following exp_element, followed by
157 another OP_VAR_VALUE, making four exp_elements. If the block is
158 non-NULL, evaluate the symbol relative to the innermost frame
159 executing in that block; if the block is NULL use the selected frame. */
162 /* OP_LAST is followed by an integer in the next exp_element.
163 The integer is zero for the last value printed,
164 or it is the absolute number of a history element.
165 With another OP_LAST at the end, this makes three exp_elements. */
168 /* OP_REGISTER is followed by an integer in the next exp_element.
169 This is the number of a register to fetch (as an int).
170 With another OP_REGISTER at the end, this makes three exp_elements. */
173 /* OP_INTERNALVAR is followed by an internalvar ptr in the next exp_element.
174 With another OP_INTERNALVAR at the end, this makes three exp_elements. */
177 /* OP_FUNCALL is followed by an integer in the next exp_element.
178 The integer is the number of args to the function call.
179 That many plus one values from following subexpressions
180 are used, the first one being the function.
181 The integer is followed by a repeat of OP_FUNCALL,
182 making three exp_elements. */
185 /* This is EXACTLY like OP_FUNCALL but is semantically different.
186 In F77, array subscript expressions, substring expressions
187 and function calls are all exactly the same syntactically. They may
188 only be dismabiguated at runtime. Thus this operator, which
189 indicates that we have found something of the form <name> ( <stuff> ) */
190 OP_F77_UNDETERMINED_ARGLIST,
192 /* The following OP is a special one, it introduces a F77 complex
193 literal. It is followed by exactly two args that are doubles. */
196 /* The following OP introduces a F77 substring operator.
197 It should have a string type and two integer types that follow
198 indicating the "from" and "to" for the substring. */
201 /* OP_STRING represents a string constant.
202 Its format is the same as that of a STRUCTOP, but the string
203 data is just made into a string constant when the operation
207 /* OP_BITSTRING represents a packed bitstring constant.
208 Its format is the same as that of a STRUCTOP, but the bitstring
209 data is just made into a bitstring constant when the operation
213 /* OP_ARRAY creates an array constant out of the following subexpressions.
214 It is followed by two exp_elements, the first containing an integer
215 that is the lower bound of the array and the second containing another
216 integer that is the upper bound of the array. The second integer is
217 followed by a repeat of OP_ARRAY, making four exp_elements total.
218 The bounds are used to compute the number of following subexpressions
219 to consume, as well as setting the bounds in the created array constant.
220 The type of the elements is taken from the type of the first subexp,
221 and they must all match. */
224 /* UNOP_CAST is followed by a type pointer in the next exp_element.
225 With another UNOP_CAST at the end, this makes three exp_elements.
226 It casts the value of the following subexpression. */
229 /* UNOP_MEMVAL is followed by a type pointer in the next exp_element
230 With another UNOP_MEMVAL at the end, this makes three exp_elements.
231 It casts the contents of the word addressed by the value of the
232 following subexpression. */
235 /* UNOP_... operate on one value from a following subexpression
236 and replace it with a result. They take no immediate arguments. */
238 UNOP_NEG, /* Unary - */
239 UNOP_LOGICAL_NOT, /* Unary ! */
240 UNOP_COMPLEMENT, /* Unary ~ */
241 UNOP_IND, /* Unary * */
242 UNOP_ADDR, /* Unary & */
243 UNOP_PREINCREMENT, /* ++ before an expression */
244 UNOP_POSTINCREMENT, /* ++ after an expression */
245 UNOP_PREDECREMENT, /* -- before an expression */
246 UNOP_POSTDECREMENT, /* -- after an expression */
247 UNOP_SIZEOF, /* Unary sizeof (followed by expression) */
249 UNOP_PLUS, /* Unary plus */
251 UNOP_CAP, /* Modula-2 standard (unary) procedures */
262 OP_BOOL, /* Modula-2 builtin BOOLEAN type */
263 OP_M2_STRING, /* Modula-2 string constants */
265 /* STRUCTOP_... operate on a value from a following subexpression
266 by extracting a structure component specified by a string
267 that appears in the following exp_elements (as many as needed).
268 STRUCTOP_STRUCT is used for "." and STRUCTOP_PTR for "->".
269 They differ only in the error message given in case the value is
270 not suitable or the structure component specified is not found.
272 The length of the string follows the opcode, followed by
273 BYTES_TO_EXP_ELEM(length) elements containing the data of the
274 string, followed by the length again and the opcode again. */
280 /* OP_THIS is just a placeholder for the class instance variable.
281 It just comes in a tight (OP_THIS, OP_THIS) pair. */
284 /* OP_SCOPE surrounds a type name and a field name. The type
285 name is encoded as one element, but the field name stays as
286 a string, which, of course, is variable length. */
289 /* Used to represent named structure field values in brace initializers
290 (or tuples as they are called in Chill).
291 The gcc C syntax is NAME:VALUE or .NAME=VALUE, the Chill syntax is
292 .NAME:VALUE. Multiple labels (as in the Chill syntax
293 .NAME1,.NAME2:VALUE) is represented as if it were
294 .NAME1:(.NAME2:VALUE) (though that is not valid Chill syntax).
296 The NAME is represented as for STRUCTOP_STRUCT; VALUE follows. */
299 /* OP_TYPE is for parsing types, and used with the "ptype" command
300 so we can look up types that are qualified by scope, either with
301 the GDB "::" operator, or the Modula-2 '.' operator. */
307 enum exp_opcode opcode;
308 struct symbol *symbol;
311 /* Really sizeof (union exp_element) characters (or less for the last
312 element of a string). */
315 struct internalvar *internalvar;
321 const struct language_defn *language_defn; /* language it was entered in */
323 union exp_element elts[1];
326 /* Macros for converting between number of expression elements and bytes
327 to store that many expression elements. */
329 #define EXP_ELEM_TO_BYTES(elements) \
330 ((elements) * sizeof (union exp_element))
331 #define BYTES_TO_EXP_ELEM(bytes) \
332 (((bytes) + sizeof (union exp_element) - 1) / sizeof (union exp_element))
336 extern struct expression *parse_expression PARAMS ((char *));
338 extern struct expression *parse_exp_1 PARAMS ((char **, struct block *, int));
340 /* The innermost context required by the stack and register variables
341 we've encountered so far. To use this, set it to NULL, then call
342 parse_<whatever>, then look at it. */
343 extern struct block *innermost_block;
345 /* From expprint.c */
347 extern void print_expression PARAMS ((struct expression *, GDB_FILE *));
349 extern char *op_string PARAMS ((enum exp_opcode));
351 /* To enable dumping of all parsed expressions in a human readable
352 form, define DEBUG_EXPRESSIONS. This is a compile time constant
353 at the moment, since it's not clear that this feature is important
354 enough to include by default. */
356 #ifdef DEBUG_EXPRESSIONS
357 extern void dump_expression PARAMS ((struct expression *, GDB_FILE *, char *));
358 #define DUMP_EXPRESSION(exp,file,note) dump_expression ((exp), (file), (note))
360 #define DUMP_EXPRESSION(exp,file,note) /* Null expansion */
361 #endif /* DEBUG_EXPRESSIONS */
363 #endif /* !defined (EXPRESSION_H) */