]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/expression.h
pass prefix & exec_prefix, POSIXize recursive makes
[thirdparty/binutils-gdb.git] / gdb / expression.h
CommitLineData
bd5635a1 1/* Definitions for expressions stored in reversed prefix form, for GDB.
35fcebce 2 Copyright 1986, 1989, 1992 Free Software Foundation, Inc.
bd5635a1
RP
3
4This file is part of GDB.
5
35fcebce 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
35fcebce
PB
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
35fcebce 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
35fcebce
PB
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20#if !defined (EXPRESSION_H)
21#define EXPRESSION_H 1
bd5635a1
RP
22
23/* Definitions for saved C expressions. */
24
25/* An expression is represented as a vector of union exp_element's.
26 Each exp_element is an opcode, except that some opcodes cause
27 the following exp_element to be treated as a long or double constant
28 or as a variable. The opcodes are obeyed, using a stack for temporaries.
29 The value is left on the temporary stack at the end. */
30
31/* When it is necessary to include a string,
32 it can occupy as many exp_elements as it needs.
33 We find the length of the string using strlen,
34 divide to find out how many exp_elements are used up,
35 and skip that many. Strings, like numbers, are indicated
36 by the preceding opcode. */
37
38enum exp_opcode
39{
35fcebce
PB
40 /* Used when it's necessary to pass an opcode which will be ignored,
41 or to catch uninitialized values. */
42 OP_NULL,
43
bd5635a1
RP
44/* BINOP_... operate on two values computed by following subexpressions,
45 replacing them by one result value. They take no immediate arguments. */
46 BINOP_ADD, /* + */
47 BINOP_SUB, /* - */
48 BINOP_MUL, /* * */
49 BINOP_DIV, /* / */
50 BINOP_REM, /* % */
51 BINOP_LSH, /* << */
52 BINOP_RSH, /* >> */
53 BINOP_AND, /* && */
54 BINOP_OR, /* || */
55 BINOP_LOGAND, /* & */
56 BINOP_LOGIOR, /* | */
57 BINOP_LOGXOR, /* ^ */
58 BINOP_EQUAL, /* == */
59 BINOP_NOTEQUAL, /* != */
60 BINOP_LESS, /* < */
61 BINOP_GTR, /* > */
62 BINOP_LEQ, /* <= */
63 BINOP_GEQ, /* >= */
64 BINOP_REPEAT, /* @ */
65 BINOP_ASSIGN, /* = */
66 BINOP_COMMA, /* , */
67 BINOP_SUBSCRIPT, /* x[y] */
35fcebce 68 BINOP_MULTI_SUBSCRIPT, /* Modula-2 x[a,b,...] */
bd5635a1
RP
69 BINOP_EXP, /* Exponentiation */
70
71/* C++. */
72 BINOP_MIN, /* <? */
73 BINOP_MAX, /* >? */
74 BINOP_SCOPE, /* :: */
75
76 /* STRUCTOP_MEMBER is used for pointer-to-member constructs.
77 X . * Y translates into X STRUCTOP_MEMBER Y. */
78 STRUCTOP_MEMBER,
79 /* STRUCTOP_MPTR is used for pointer-to-member constructs
80 when X is a pointer instead of an aggregate. */
81 STRUCTOP_MPTR,
82/* end of C++. */
83
35fcebce
PB
84 /* For Modula-2 integer division DIV */
85 BINOP_INTDIV,
bd5635a1
RP
86
87 BINOP_ASSIGN_MODIFY, /* +=, -=, *=, and so on.
88 The following exp_element is another opcode,
89 a BINOP_, saying how to modify.
90 Then comes another BINOP_ASSIGN_MODIFY,
91 making three exp_elements in total. */
92
35fcebce
PB
93 /* Modula-2 standard (binary) procedures*/
94 BINOP_VAL,
95 BINOP_INCL,
96 BINOP_EXCL,
97
98 /* This must be the highest BINOP_ value, for expprint.c. */
99 BINOP_END,
100
bd5635a1
RP
101/* Operates on three values computed by following subexpressions. */
102 TERNOP_COND, /* ?: */
103
104/* The OP_... series take immediate following arguments.
105 After the arguments come another OP_... (the same one)
106 so that the grouping can be recognized from the end. */
107
108/* OP_LONG is followed by a type pointer in the next exp_element
109 and the long constant value in the following exp_element.
110 Then comes another OP_LONG.
111 Thus, the operation occupies four exp_elements. */
112
113 OP_LONG,
114/* OP_DOUBLE is similar but takes a double constant instead of a long one. */
115 OP_DOUBLE,
116/* OP_VAR_VALUE takes one struct symbol * in the following exp_element,
117 followed by another OP_VAR_VALUE, making three exp_elements. */
118 OP_VAR_VALUE,
119/* OP_LAST is followed by an integer in the next exp_element.
120 The integer is zero for the last value printed,
121 or it is the absolute number of a history element.
122 With another OP_LAST at the end, this makes three exp_elements. */
123 OP_LAST,
124/* OP_REGISTER is followed by an integer in the next exp_element.
125 This is the number of a register to fetch (as an int).
126 With another OP_REGISTER at the end, this makes three exp_elements. */
127 OP_REGISTER,
128/* OP_INTERNALVAR is followed by an internalvar ptr in the next exp_element.
129 With another OP_INTERNALVAR at the end, this makes three exp_elements. */
130 OP_INTERNALVAR,
131/* OP_FUNCALL is followed by an integer in the next exp_element.
132 The integer is the number of args to the function call.
133 That many plus one values from following subexpressions
134 are used, the first one being the function.
135 The integer is followed by a repeat of OP_FUNCALL,
136 making three exp_elements. */
137 OP_FUNCALL,
138/* OP_STRING represents a string constant.
139 Its format is the same as that of a STRUCTOP, but the string
140 data is just made into a string constant when the operation
141 is executed. */
142 OP_STRING,
143
144/* UNOP_CAST is followed by a type pointer in the next exp_element.
145 With another UNOP_CAST at the end, this makes three exp_elements.
146 It casts the value of the following subexpression. */
147 UNOP_CAST,
148/* UNOP_MEMVAL is followed by a type pointer in the next exp_element
149 With another UNOP_MEMVAL at the end, this makes three exp_elements.
150 It casts the contents of the word addressed by the value of the
151 following subexpression. */
152 UNOP_MEMVAL,
153/* UNOP_... operate on one value from a following subexpression
154 and replace it with a result. They take no immediate arguments. */
155 UNOP_NEG, /* Unary - */
156 UNOP_ZEROP, /* Unary ! */
157 UNOP_LOGNOT, /* Unary ~ */
158 UNOP_IND, /* Unary * */
159 UNOP_ADDR, /* Unary & */
160 UNOP_PREINCREMENT, /* ++ before an expression */
161 UNOP_POSTINCREMENT, /* ++ after an expression */
162 UNOP_PREDECREMENT, /* -- before an expression */
163 UNOP_POSTDECREMENT, /* -- after an expression */
164 UNOP_SIZEOF, /* Unary sizeof (followed by expression) */
165
35fcebce
PB
166 UNOP_PLUS, /* Unary plus */
167
168 UNOP_CAP, /* Modula-2 standard (unary) procedures */
169 UNOP_CHR,
170 UNOP_ORD,
171 UNOP_ABS,
172 UNOP_FLOAT,
173 UNOP_HIGH,
174 UNOP_MAX,
175 UNOP_MIN,
176 UNOP_ODD,
177 UNOP_TRUNC,
178
179 OP_BOOL, /* Modula-2 builtin BOOLEAN type */
180 OP_M2_STRING, /* Modula-2 string constants */
181
bd5635a1
RP
182/* STRUCTOP_... operate on a value from a following subexpression
183 by extracting a structure component specified by a string
184 that appears in the following exp_elements (as many as needed).
185 STRUCTOP_STRUCT is used for "." and STRUCTOP_PTR for "->".
186 They differ only in the error message given in case the value is
187 not suitable or the structure component specified is not found.
188
35fcebce
PB
189 After the sub-expression and before the string is a (struct type*).
190 This is normally NULL, but is used for the TYPE in a C++ qualified
191 reference like EXP.TYPE::NAME. (EXP.TYPE1::TYPE2::NAME does
192 not work, unfortunately.)
193
bd5635a1
RP
194 The length of the string follows in the next exp_element,
195 (after the string), followed by another STRUCTOP_... code. */
196 STRUCTOP_STRUCT,
197 STRUCTOP_PTR,
198
199/* C++ */
200 /* OP_THIS is just a placeholder for the class instance variable.
201 It just comes in a tight (OP_THIS, OP_THIS) pair. */
202 OP_THIS,
203
204 /* OP_SCOPE surrounds a type name and a field name. The type
205 name is encoded as one element, but the field name stays as
206 a string, which, of course, is variable length. */
207 OP_SCOPE,
208
35fcebce
PB
209 /* OP_TYPE is for parsing types, and used with the "ptype" command
210 so we can look up types that are qualified by scope, either with
211 the GDB "::" operator, or the Modula-2 '.' operator. */
212 OP_TYPE
bd5635a1
RP
213};
214
215union exp_element
216{
217 enum exp_opcode opcode;
218 struct symbol *symbol;
219 LONGEST longconst;
220 double doubleconst;
221 char string;
222 struct type *type;
223 struct internalvar *internalvar;
224};
225
226struct expression
227{
35fcebce 228 const struct language_defn *language_defn; /* language it was entered in */
bd5635a1
RP
229 int nelts;
230 union exp_element elts[1];
231};
232
35fcebce
PB
233/* From parse.c */
234
235extern struct expression *
236parse_expression PARAMS ((char *));
237
238extern struct expression *
239parse_exp_1 PARAMS ((char **, struct block *, int));
bd5635a1
RP
240
241/* The innermost context required by the stack and register variables
242 we've encountered so far. To use this, set it to NULL, then call
35fcebce 243 parse_<whatever>, then look at it. */
bd5635a1
RP
244extern struct block *innermost_block;
245
35fcebce
PB
246/* From expprint.c */
247
248extern void
249print_expression PARAMS ((struct expression *, FILE *));
250
251extern char *
252op_string PARAMS ((enum exp_opcode));
253
254#endif /* !defined (EXPRESSION_H) */