OSDN Git Service

2002-01-08 Michael Snyder <msnyder@redhat.com>
[pf3gnuchains/pf3gnuchains3x.git] / gdb / expression.h
1 /* Definitions for expressions stored in reversed prefix form, for GDB.
2    Copyright 1986, 1989, 1992, 1994, 2000 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
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.
10
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.
15
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., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
20
21 #if !defined (EXPRESSION_H)
22 #define EXPRESSION_H 1
23
24
25 #include "symtab.h"             /* Needed for "struct block" type. */
26 #include "doublest.h"           /* Needed for DOUBLEST.  */
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
44 enum exp_opcode
45   {
46     /* Used when it's necessary to pass an opcode which will be ignored,
47        or to catch uninitialized values.  */
48     OP_NULL,
49
50 /* BINOP_... operate on two values computed by following subexpressions,
51    replacing them by one result value.  They take no immediate arguments.  */
52
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,                  /* >? */
82
83     /* STRUCTOP_MEMBER is used for pointer-to-member constructs.
84        X . * Y translates into X STRUCTOP_MEMBER Y.  */
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
91     /* end of C++.  */
92
93     /* For Modula-2 integer division DIV */
94     BINOP_INTDIV,
95
96     BINOP_ASSIGN_MODIFY,        /* +=, -=, *=, and so on.
97                                    The following exp_element is another opcode,
98                                    a BINOP_, saying how to modify.
99                                    Then comes another BINOP_ASSIGN_MODIFY,
100                                    making three exp_elements in total.  */
101
102     /* Modula-2 standard (binary) procedures */
103     BINOP_VAL,
104     BINOP_INCL,
105     BINOP_EXCL,
106
107     /* Concatenate two operands, such as character strings or bitstrings.
108        If the first operand is a integer expression, then it means concatenate
109        the second operand with itself that many times. */
110     BINOP_CONCAT,
111
112     /* For Chill and Pascal. */
113     BINOP_IN,                   /* Returns 1 iff ARG1 IN ARG2. */
114
115     /* This is the "colon operator" used various places in Chill. */
116     BINOP_RANGE,
117
118     /* This must be the highest BINOP_ value, for expprint.c.  */
119     BINOP_END,
120
121     /* Operates on three values computed by following subexpressions.  */
122     TERNOP_COND,                /* ?: */
123
124     /* A sub-string/sub-array.  Chill syntax:  OP1(OP2:OP3).
125        Return elements OP2 through OP3 of OP1.  */
126     TERNOP_SLICE,
127
128     /* A sub-string/sub-array.  Chill syntax:  OP1(OP2 UP OP3).
129        Return OP3 elements of OP1, starting with element OP2. */
130     TERNOP_SLICE_COUNT,
131
132     /* Multidimensional subscript operator, such as Modula-2 x[a,b,...].
133        The dimensionality is encoded in the operator, like the number of
134        function arguments in OP_FUNCALL, I.E. <OP><dimension><OP>.
135        The value of the first following subexpression is subscripted
136        by each of the next following subexpressions, one per dimension. */
137     MULTI_SUBSCRIPT,
138
139     /* The OP_... series take immediate following arguments.
140        After the arguments come another OP_... (the same one)
141        so that the grouping can be recognized from the end.  */
142
143     /* OP_LONG is followed by a type pointer in the next exp_element
144        and the long constant value in the following exp_element.
145        Then comes another OP_LONG.
146        Thus, the operation occupies four exp_elements.  */
147     OP_LONG,
148
149     /* OP_DOUBLE is similar but takes a DOUBLEST constant instead of a long.  */
150     OP_DOUBLE,
151
152     /* OP_VAR_VALUE takes one struct block * in the following element,
153        and one struct symbol * in the following exp_element, followed by
154        another OP_VAR_VALUE, making four exp_elements.  If the block is
155        non-NULL, evaluate the symbol relative to the innermost frame
156        executing in that block; if the block is NULL use the selected frame.  */
157     OP_VAR_VALUE,
158
159     /* OP_LAST is followed by an integer in the next exp_element.
160        The integer is zero for the last value printed,
161        or it is the absolute number of a history element.
162        With another OP_LAST at the end, this makes three exp_elements.  */
163     OP_LAST,
164
165     /* OP_REGISTER is followed by an integer in the next exp_element.
166        This is the number of a register to fetch (as an int).
167        With another OP_REGISTER at the end, this makes three exp_elements.  */
168     OP_REGISTER,
169
170     /* OP_INTERNALVAR is followed by an internalvar ptr in the next exp_element.
171        With another OP_INTERNALVAR at the end, this makes three exp_elements.  */
172     OP_INTERNALVAR,
173
174     /* OP_FUNCALL is followed by an integer in the next exp_element.
175        The integer is the number of args to the function call.
176        That many plus one values from following subexpressions
177        are used, the first one being the function.
178        The integer is followed by a repeat of OP_FUNCALL,
179        making three exp_elements.  */
180     OP_FUNCALL,
181
182     /* This is EXACTLY like OP_FUNCALL but is semantically different.  
183        In F77, array subscript expressions, substring expressions
184        and function calls are  all exactly the same syntactically. They may 
185        only be dismabiguated at runtime.  Thus this operator, which 
186        indicates that we have found something of the form <name> ( <stuff> ) */
187     OP_F77_UNDETERMINED_ARGLIST,
188
189     /* The following OP is a special one, it introduces a F77 complex
190        literal. It is followed by exactly two args that are doubles.  */
191     OP_COMPLEX,
192
193     /* OP_STRING represents a string constant.
194        Its format is the same as that of a STRUCTOP, but the string
195        data is just made into a string constant when the operation
196        is executed.  */
197     OP_STRING,
198
199     /* OP_BITSTRING represents a packed bitstring constant.
200        Its format is the same as that of a STRUCTOP, but the bitstring
201        data is just made into a bitstring constant when the operation
202        is executed.  */
203     OP_BITSTRING,
204
205     /* OP_ARRAY creates an array constant out of the following subexpressions.
206        It is followed by two exp_elements, the first containing an integer
207        that is the lower bound of the array and the second containing another
208        integer that is the upper bound of the array.  The second integer is
209        followed by a repeat of OP_ARRAY, making four exp_elements total.
210        The bounds are used to compute the number of following subexpressions
211        to consume, as well as setting the bounds in the created array constant.
212        The type of the elements is taken from the type of the first subexp,
213        and they must all match. */
214     OP_ARRAY,
215
216     /* UNOP_CAST is followed by a type pointer in the next exp_element.
217        With another UNOP_CAST at the end, this makes three exp_elements.
218        It casts the value of the following subexpression.  */
219     UNOP_CAST,
220
221     /* UNOP_MEMVAL is followed by a type pointer in the next exp_element
222        With another UNOP_MEMVAL at the end, this makes three exp_elements.
223        It casts the contents of the word addressed by the value of the
224        following subexpression.  */
225     UNOP_MEMVAL,
226
227     /* UNOP_... operate on one value from a following subexpression
228        and replace it with a result.  They take no immediate arguments.  */
229
230     UNOP_NEG,                   /* Unary - */
231     UNOP_LOGICAL_NOT,           /* Unary ! */
232     UNOP_COMPLEMENT,            /* Unary ~ */
233     UNOP_IND,                   /* Unary * */
234     UNOP_ADDR,                  /* Unary & */
235     UNOP_PREINCREMENT,          /* ++ before an expression */
236     UNOP_POSTINCREMENT,         /* ++ after an expression */
237     UNOP_PREDECREMENT,          /* -- before an expression */
238     UNOP_POSTDECREMENT,         /* -- after an expression */
239     UNOP_SIZEOF,                /* Unary sizeof (followed by expression) */
240
241     UNOP_PLUS,                  /* Unary plus */
242
243     UNOP_CAP,                   /* Modula-2 standard (unary) procedures */
244     UNOP_CHR,
245     UNOP_ORD,
246     UNOP_ABS,
247     UNOP_FLOAT,
248     UNOP_HIGH,
249     UNOP_MAX,
250     UNOP_MIN,
251     UNOP_ODD,
252     UNOP_TRUNC,
253
254     /* Chill builtin functions. */
255     UNOP_LOWER, UNOP_UPPER, UNOP_LENGTH, UNOP_CARD, UNOP_CHMAX, UNOP_CHMIN,
256
257     OP_BOOL,                    /* Modula-2 builtin BOOLEAN type */
258     OP_M2_STRING,               /* Modula-2 string constants */
259
260     /* STRUCTOP_... operate on a value from a following subexpression
261        by extracting a structure component specified by a string
262        that appears in the following exp_elements (as many as needed).
263        STRUCTOP_STRUCT is used for "." and STRUCTOP_PTR for "->".
264        They differ only in the error message given in case the value is
265        not suitable or the structure component specified is not found.
266
267        The length of the string follows the opcode, followed by
268        BYTES_TO_EXP_ELEM(length) elements containing the data of the
269        string, followed by the length again and the opcode again.  */
270
271     STRUCTOP_STRUCT,
272     STRUCTOP_PTR,
273
274     /* C++ */
275     /* OP_THIS is just a placeholder for the class instance variable.
276        It just comes in a tight (OP_THIS, OP_THIS) pair.  */
277     OP_THIS,
278
279     /* OP_SCOPE surrounds a type name and a field name.  The type
280        name is encoded as one element, but the field name stays as
281        a string, which, of course, is variable length.  */
282     OP_SCOPE,
283
284     /* Used to represent named structure field values in brace initializers
285        (or tuples as they are called in Chill).
286        The gcc C syntax is NAME:VALUE or .NAME=VALUE, the Chill syntax is
287        .NAME:VALUE.  Multiple labels (as in the Chill syntax
288        .NAME1,.NAME2:VALUE) is represented as if it were
289        .NAME1:(.NAME2:VALUE) (though that is not valid Chill syntax).
290
291        The NAME is represented as for STRUCTOP_STRUCT;  VALUE follows. */
292     OP_LABELED,
293
294     /* OP_TYPE is for parsing types, and used with the "ptype" command
295        so we can look up types that are qualified by scope, either with
296        the GDB "::" operator, or the Modula-2 '.' operator. */
297     OP_TYPE,
298
299     /* An un-looked-up identifier. */
300     OP_NAME,
301
302     /* An unparsed expression.  Used for Scheme (for now at least) */
303     OP_EXPRSTRING
304   };
305
306 union exp_element
307   {
308     enum exp_opcode opcode;
309     struct symbol *symbol;
310     LONGEST longconst;
311     DOUBLEST doubleconst;
312     /* Really sizeof (union exp_element) characters (or less for the last
313        element of a string).  */
314     char string;
315     struct type *type;
316     struct internalvar *internalvar;
317     struct block *block;
318   };
319
320 struct expression
321   {
322     const struct language_defn *language_defn;  /* language it was entered in */
323     int nelts;
324     union exp_element elts[1];
325   };
326
327 /* Macros for converting between number of expression elements and bytes
328    to store that many expression elements. */
329
330 #define EXP_ELEM_TO_BYTES(elements) \
331     ((elements) * sizeof (union exp_element))
332 #define BYTES_TO_EXP_ELEM(bytes) \
333     (((bytes) + sizeof (union exp_element) - 1) / sizeof (union exp_element))
334
335 /* From parse.c */
336
337 extern struct expression *parse_expression (char *);
338
339 extern struct expression *parse_exp_1 (char **, struct block *, int);
340
341 /* The innermost context required by the stack and register variables
342    we've encountered so far.  To use this, set it to NULL, then call
343    parse_<whatever>, then look at it.  */
344 extern struct block *innermost_block;
345
346 /* From eval.c */
347
348 /* Values of NOSIDE argument to eval_subexp.  */
349
350 enum noside
351   {
352     EVAL_NORMAL,
353     EVAL_SKIP,                  /* Only effect is to increment pos.  */
354     EVAL_AVOID_SIDE_EFFECTS     /* Don't modify any variables or
355                                    call any functions.  The value
356                                    returned will have the correct
357                                    type, and will have an
358                                    approximately correct lvalue
359                                    type (inaccuracy: anything that is
360                                    listed as being in a register in
361                                    the function in which it was
362                                    declared will be lval_register).  */
363   };
364
365 extern struct value *evaluate_subexp_standard
366   (struct type *, struct expression *, int *, enum noside);
367
368 /* From expprint.c */
369
370 extern void print_expression (struct expression *, struct ui_file *);
371
372 extern char *op_string (enum exp_opcode);
373
374 extern void dump_prefix_expression (struct expression *,
375                                     struct ui_file *,
376                                     char *);
377 extern void dump_postfix_expression (struct expression *,
378                                      struct ui_file *,
379                                      char *);
380
381 #endif /* !defined (EXPRESSION_H) */