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