gdb-2.5.1
[deliverable/binutils-gdb.git] / gdb / expread.tab.c
1
2 /* A Bison parser, made from expread.y */
3
4 #define INT 258
5 #define CHAR 259
6 #define FLOAT 260
7 #define NAME 261
8 #define TYPENAME 262
9 #define STRING 263
10 #define STRUCT 264
11 #define UNION 265
12 #define ENUM 266
13 #define SIZEOF 267
14 #define UNSIGNED 268
15 #define COLONCOLON 269
16 #define LAST 270
17 #define REGNAME 271
18 #define VARIABLE 272
19 #define ASSIGN_MODIFY 273
20 #define THIS 274
21 #define ABOVE_COMMA 275
22 #define OR 276
23 #define AND 277
24 #define EQUAL 278
25 #define NOTEQUAL 279
26 #define LEQ 280
27 #define GEQ 281
28 #define LSH 282
29 #define RSH 283
30 #define UNARY 284
31 #define INCREMENT 285
32 #define DECREMENT 286
33 #define ARROW 287
34
35 #line 30 "expread.y"
36
37 #include "defs.h"
38 #include "param.h"
39 #include "symtab.h"
40 #include "frame.h"
41 #include "expression.h"
42
43 #include <stdio.h>
44
45 static struct expression *expout;
46 static int expout_size;
47 static int expout_ptr;
48
49 static int yylex ();
50 static yyerror ();
51 static void write_exp_elt ();
52 static void write_exp_string ();
53 static void start_arglist ();
54 static int end_arglist ();
55 static void free_funcalls ();
56 static char *copy_name ();
57
58 /* If this is nonzero, this block is used as the lexical context
59 for symbol names. */
60
61 static struct block *expression_context_block;
62
63 /* Number of arguments seen so far in innermost function call. */
64 static int arglist_len;
65
66 /* Data structure for saving values of arglist_len
67 for function calls whose arguments contain other function calls. */
68
69 struct funcall
70 {
71 struct funcall *next;
72 int arglist_len;
73 };
74
75 struct funcall *funcall_chain;
76
77 /* This kind of datum is used to represent the name
78 of a symbol token. */
79
80 struct stoken
81 {
82 char *ptr;
83 int length;
84 };
85
86 #line 85 "expread.y"
87 typedef union
88 {
89 long lval;
90 double dval;
91 struct symbol *sym;
92 struct type *tval;
93 struct stoken sval;
94 int voidval;
95 struct block *bval;
96 enum exp_opcode opcode;
97 struct internalvar *ivar;
98
99 struct type **tvec;
100 int *ivec;
101 } YYSTYPE;
102
103 #ifndef YYLTYPE
104 typedef
105 struct yyltype
106 {
107 int timestamp;
108 int first_line;
109 int first_column;
110 int last_line;
111 int last_column;
112 char *text;
113 }
114 yyltype;
115
116 #define YYLTYPE yyltype
117 #endif
118
119 #define YYACCEPT return(0)
120 #define YYABORT return(1)
121 #define YYERROR return(1)
122 #include <stdio.h>
123
124 #ifndef __STDC__
125 #define const
126 #endif
127
128
129
130 #define YYFINAL 152
131 #define YYFLAG -32768
132 #define YYNTBASE 57
133
134 #define YYTRANSLATE(x) ((unsigned)(x) <= 287 ? yytranslate[x] : 68)
135
136 static const char yytranslate[] = { 0,
137 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
138 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
139 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
140 2, 2, 48, 2, 2, 2, 40, 27, 2, 51,
141 52, 38, 36, 20, 37, 46, 39, 2, 2, 2,
142 2, 2, 2, 2, 2, 2, 2, 56, 2, 30,
143 22, 31, 55, 41, 2, 2, 2, 2, 2, 2,
144 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
145 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
146 47, 2, 50, 26, 2, 2, 2, 2, 2, 2,
147 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
148 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
149 2, 2, 53, 25, 54, 49, 2, 2, 2, 2,
150 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
151 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
152 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
153 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
154 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
155 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
156 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
157 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
158 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
160 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
161 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
163 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
164 16, 17, 18, 19, 21, 23, 24, 28, 29, 32,
165 33, 34, 35, 42, 43, 44, 45
166 };
167
168 static const short yyrline[] = { 0,
169 152, 156, 157, 162, 165, 168, 172, 176, 180, 184,
170 188, 192, 196, 200, 206, 210, 216, 220, 224, 228,
171 234, 237, 241, 245, 251, 257, 263, 267, 271, 275,
172 279, 283, 287, 291, 295, 299, 303, 307, 311, 315,
173 319, 323, 327, 331, 335, 339, 343, 347, 353, 360,
174 367, 374, 377, 383, 389, 395, 402, 409, 416, 437,
175 448, 461, 474, 510, 575, 576, 578, 580, 582, 584,
176 586, 592, 595, 598, 601, 604, 609, 614, 621, 622
177 };
178
179 static const char * const yytname[] = { 0,
180 "error","$illegal.","INT","CHAR","FLOAT","NAME","TYPENAME","STRING","STRUCT","UNION",
181 "ENUM","SIZEOF","UNSIGNED","COLONCOLON","LAST","REGNAME","VARIABLE","ASSIGN_MODIFY","THIS","','",
182 "ABOVE_COMMA","'='","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'",
183 "'>'","LEQ","GEQ","LSH","RSH","'+'","'-'","'*'","'/'","'%'",
184 "'@'","UNARY","INCREMENT","DECREMENT","ARROW","'.'","'['","'!'","'~'","']'",
185 "'('","')'","'{'","'}'","'?'","':'","start"
186 };
187
188 static const short yyr1[] = { 0,
189 57, 58, 58, 59, 59, 59, 59, 59, 59, 59,
190 59, 59, 59, 59, 59, 59, 59, 59, 60, 59,
191 61, 61, 61, 59, 59, 59, 59, 59, 59, 59,
192 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
193 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
194 59, 59, 59, 59, 59, 59, 59, 59, 62, 62,
195 63, 63, 63, 63, 64, 64, 64, 64, 64, 64,
196 64, 65, 65, 65, 65, 65, 66, 66, 67, 67
197 };
198
199 static const short yyr2[] = { 0,
200 1, 1, 3, 2, 2, 2, 2, 2, 2, 2,
201 2, 2, 2, 3, 4, 3, 4, 4, 0, 5,
202 0, 1, 3, 4, 4, 3, 3, 3, 3, 3,
203 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
204 3, 3, 3, 3, 3, 5, 3, 3, 1, 1,
205 1, 1, 1, 1, 1, 4, 1, 1, 1, 3,
206 3, 3, 2, 1, 1, 2, 2, 3, 6, 8,
207 9, 1, 2, 2, 2, 2, 1, 3, 1, 1
208 };
209
210 static const short yydefact[] = { 0,
211 49, 50, 51, 64, 72, 57, 0, 0, 0, 0,
212 0, 0, 53, 54, 55, 58, 0, 0, 0, 0,
213 0, 0, 0, 0, 0, 1, 2, 0, 52, 0,
214 59, 79, 80, 73, 74, 75, 0, 13, 76, 63,
215 5, 6, 4, 9, 10, 7, 8, 0, 0, 65,
216 72, 0, 65, 0, 0, 0, 0, 0, 0, 0,
217 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
218 0, 0, 0, 0, 0, 11, 12, 0, 0, 0,
219 19, 0, 0, 0, 0, 26, 67, 66, 0, 0,
220 0, 0, 0, 3, 48, 47, 45, 44, 43, 42,
221 41, 35, 36, 39, 40, 37, 38, 33, 34, 31,
222 32, 28, 29, 30, 27, 0, 14, 0, 16, 0,
223 21, 0, 61, 62, 56, 0, 25, 68, 24, 15,
224 17, 18, 22, 0, 0, 0, 0, 20, 46, 0,
225 23, 69, 0, 70, 77, 0, 0, 71, 78, 0,
226 0, 0
227 };
228
229 static const short yydefgoto[] = { 150,
230 48, 27, 121, 134, 28, 29, 49, 30, 146, 31
231 };
232
233 static const short yypact[] = { 125,
234 -32768,-32768,-32768, 1,-32768,-32768, 24, 24, 24, 176,
235 24, 24,-32768,-32768,-32768,-32768, 125, 125, 125, 125,
236 125, 125, 125, 125, 515, 0, 243, 14,-32768, 18,
237 -32768,-32768,-32768,-32768,-32768,-32768, 125, 472,-32768,-32768,
238 472, 472, 472, 472, 472, 472, 472, 21, 52, 19,
239 -32768, 58, 20, 125, 125, 125, 125, 125, 125, 125,
240 125, 125, 125, 125, 125, 125, 125, 125, 125, 125,
241 125, 125, 125, 125, 125,-32768,-32768, -1, 29, 125,
242 -32768, 125, 24, 24, 119,-32768,-32768,-32768, 515, 125,
243 32, 125, -14, 243, 243, 243, 275, 306, 336, 365,
244 393, 419, 419, 441, 441, 441, 441, 161, 161, 459,
245 459, 104, 104, 104, 472, 125,-32768, 125,-32768, 49,
246 125, 208, 26,-32768, 125, 57, 472,-32768, 472, 104,
247 104,-32768, 243, 22, 125, 38, 125,-32768, 243, 25,
248 243, 27, 16,-32768, 54, 23, 515,-32768, 54, 84,
249 86,-32768
250 };
251
252 static const short yypgoto[] = {-32768,
253 3, -10,-32768,-32768,-32768,-32768, -21, -23,-32768, 10
254 };
255
256
257 #define YYLAST 528
258
259
260 static const short yytable[] = { 38,
261 50, 53, 26, 52, 32, 33, 41, 42, 43, 44,
262 45, 46, 47, 50, -79, 85, 34, 35, 36, 54,
263 39, 40, 51, 128, 7, 8, 9, 83, 11, 32,
264 33, 84, 91, 93, 32, 33, 116, 32, 33, -60,
265 54, 137, 147, 94, 95, 96, 97, 98, 99, 100,
266 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
267 111, 112, 113, 114, 115, 126, 118, 144, 54, 128,
268 136, 122, 86, 138, 148, 140, 142, 143, 87, 127,
269 87, 129, 120, 151, 87, 152, 0, 117, 119, 88,
270 0, 88, 123, 124, 0, 88, 0, 0, 132, 0,
271 124, 0, 89, 90, 89, 130, 0, 131, 89, 0,
272 133, 92, 0, 0, 127, 0, 0, 0, 0, 53,
273 0, 145, 0, 53, 139, 149, 141, 1, 2, 3,
274 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
275 14, 15, 0, 16, 75, 87, 76, 77, 78, 79,
276 80, 17, 0, 0, 81, 0, 88, 0, 82, 0,
277 0, 18, 19, 0, 0, 0, 0, 20, 21, 89,
278 125, 0, 22, 23, 0, 24, 0, 25, 1, 2,
279 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
280 13, 14, 15, 0, 16, 0, 70, 71, 72, 73,
281 74, 75, 17, 76, 77, 78, 79, 80, 0, 0,
282 0, 81, 18, 19, 0, 82, 0, 0, 20, 21,
283 0, 0, 0, 22, 23, 55, 37, 0, 25, 56,
284 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
285 67, 68, 69, 70, 71, 72, 73, 74, 75, 0,
286 76, 77, 78, 79, 80, 0, 0, 0, 81, 0,
287 55, 0, 82, 135, 56, 57, 58, 59, 60, 61,
288 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
289 72, 73, 74, 75, 0, 76, 77, 78, 79, 80,
290 0, 0, 0, 81, 0, 0, 0, 82, 58, 59,
291 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
292 70, 71, 72, 73, 74, 75, 0, 76, 77, 78,
293 79, 80, 0, 0, 0, 81, 0, 0, 0, 82,
294 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
295 69, 70, 71, 72, 73, 74, 75, 0, 76, 77,
296 78, 79, 80, 0, 0, 0, 81, 0, 0, 0,
297 82, 60, 61, 62, 63, 64, 65, 66, 67, 68,
298 69, 70, 71, 72, 73, 74, 75, 0, 76, 77,
299 78, 79, 80, 0, 0, 0, 81, 0, 0, 0,
300 82, 61, 62, 63, 64, 65, 66, 67, 68, 69,
301 70, 71, 72, 73, 74, 75, 0, 76, 77, 78,
302 79, 80, 0, 0, 0, 81, 0, 0, 0, 82,
303 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
304 72, 73, 74, 75, 0, 76, 77, 78, 79, 80,
305 0, 0, 0, 81, 0, 0, 0, 82, 64, 65,
306 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
307 0, 76, 77, 78, 79, 80, 0, 0, 0, 81,
308 0, 0, 0, 82, 68, 69, 70, 71, 72, 73,
309 74, 75, 0, 76, 77, 78, 79, 80, 0, 0,
310 0, 81, 0, 0, 0, 82, 72, 73, 74, 75,
311 0, 76, 77, 78, 79, 80, 0, 0, 0, 81,
312 0, 0, 0, 82, 76, 77, 78, 79, 80, 0,
313 0, 51, 81, 7, 8, 9, 82, 11
314 };
315
316 static const short yycheck[] = { 10,
317 24, 25, 0, 25, 6, 7, 17, 18, 19, 20,
318 21, 22, 23, 37, 14, 37, 7, 8, 9, 20,
319 11, 12, 7, 38, 9, 10, 11, 14, 13, 6,
320 7, 14, 14, 14, 6, 7, 38, 6, 7, 14,
321 20, 20, 20, 54, 55, 56, 57, 58, 59, 60,
322 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
323 71, 72, 73, 74, 75, 89, 38, 52, 20, 38,
324 14, 82, 52, 52, 52, 38, 52, 51, 27, 90,
325 27, 92, 80, 0, 27, 0, -1, 78, 79, 38,
326 -1, 38, 83, 84, -1, 38, -1, -1, 50, -1,
327 91, -1, 51, 52, 51, 116, -1, 118, 51, -1,
328 121, 54, -1, -1, 125, -1, -1, -1, -1, 143,
329 -1, 143, -1, 147, 135, 147, 137, 3, 4, 5,
330 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
331 16, 17, -1, 19, 41, 27, 43, 44, 45, 46,
332 47, 27, -1, -1, 51, -1, 38, -1, 55, -1,
333 -1, 37, 38, -1, -1, -1, -1, 43, 44, 51,
334 52, -1, 48, 49, -1, 51, -1, 53, 3, 4,
335 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
336 15, 16, 17, -1, 19, -1, 36, 37, 38, 39,
337 40, 41, 27, 43, 44, 45, 46, 47, -1, -1,
338 -1, 51, 37, 38, -1, 55, -1, -1, 43, 44,
339 -1, -1, -1, 48, 49, 18, 51, -1, 53, 22,
340 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
341 33, 34, 35, 36, 37, 38, 39, 40, 41, -1,
342 43, 44, 45, 46, 47, -1, -1, -1, 51, -1,
343 18, -1, 55, 56, 22, 23, 24, 25, 26, 27,
344 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
345 38, 39, 40, 41, -1, 43, 44, 45, 46, 47,
346 -1, -1, -1, 51, -1, -1, -1, 55, 24, 25,
347 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
348 36, 37, 38, 39, 40, 41, -1, 43, 44, 45,
349 46, 47, -1, -1, -1, 51, -1, -1, -1, 55,
350 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
351 35, 36, 37, 38, 39, 40, 41, -1, 43, 44,
352 45, 46, 47, -1, -1, -1, 51, -1, -1, -1,
353 55, 26, 27, 28, 29, 30, 31, 32, 33, 34,
354 35, 36, 37, 38, 39, 40, 41, -1, 43, 44,
355 45, 46, 47, -1, -1, -1, 51, -1, -1, -1,
356 55, 27, 28, 29, 30, 31, 32, 33, 34, 35,
357 36, 37, 38, 39, 40, 41, -1, 43, 44, 45,
358 46, 47, -1, -1, -1, 51, -1, -1, -1, 55,
359 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
360 38, 39, 40, 41, -1, 43, 44, 45, 46, 47,
361 -1, -1, -1, 51, -1, -1, -1, 55, 30, 31,
362 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
363 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
364 -1, -1, -1, 55, 34, 35, 36, 37, 38, 39,
365 40, 41, -1, 43, 44, 45, 46, 47, -1, -1,
366 -1, 51, -1, -1, -1, 55, 38, 39, 40, 41,
367 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
368 -1, -1, -1, 55, 43, 44, 45, 46, 47, -1,
369 -1, 7, 51, 9, 10, 11, 55, 13
370 };
371 #define YYPURE 1
372
373 #line 2 "bison.simple"
374
375 /* Skeleton output parser for bison,
376 copyright (C) 1984 Bob Corbett and Richard Stallman
377
378 NO WARRANTY
379
380 BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
381 NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
382 WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
383 RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
384 WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
385 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
386 FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
387 AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
388 DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
389 CORRECTION.
390
391 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
392 STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
393 WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
394 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
395 OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
396 USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
397 DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
398 A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
399 PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
400 DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
401
402 GENERAL PUBLIC LICENSE TO COPY
403
404 1. You may copy and distribute verbatim copies of this source file
405 as you receive it, in any medium, provided that you conspicuously and
406 appropriately publish on each copy a valid copyright notice "Copyright
407 (C) 1985 Free Software Foundation, Inc."; and include following the
408 copyright notice a verbatim copy of the above disclaimer of warranty
409 and of this License. You may charge a distribution fee for the
410 physical act of transferring a copy.
411
412 2. You may modify your copy or copies of this source file or
413 any portion of it, and copy and distribute such modifications under
414 the terms of Paragraph 1 above, provided that you also do the following:
415
416 a) cause the modified files to carry prominent notices stating
417 that you changed the files and the date of any change; and
418
419 b) cause the whole of any work that you distribute or publish,
420 that in whole or in part contains or is a derivative of this
421 program or any part thereof, to be licensed at no charge to all
422 third parties on terms identical to those contained in this
423 License Agreement (except that you may choose to grant more
424 extensive warranty protection to third parties, at your option).
425
426 c) You may charge a distribution fee for the physical act of
427 transferring a copy, and you may at your option offer warranty
428 protection in exchange for a fee.
429
430 3. You may copy and distribute this program or any portion of it in
431 compiled, executable or object code form under the terms of Paragraphs
432 1 and 2 above provided that you do the following:
433
434 a) cause each such copy to be accompanied by the
435 corresponding machine-readable source code, which must
436 be distributed under the terms of Paragraphs 1 and 2 above; or,
437
438 b) cause each such copy to be accompanied by a
439 written offer, with no time limit, to give any third party
440 free (except for a nominal shipping charge) a machine readable
441 copy of the corresponding source code, to be distributed
442 under the terms of Paragraphs 1 and 2 above; or,
443
444 c) in the case of a recipient of this program in compiled, executable
445 or object code form (without the corresponding source code) you
446 shall cause copies you distribute to be accompanied by a copy
447 of the written offer of source code which you received along
448 with the copy you received.
449
450 4. You may not copy, sublicense, distribute or transfer this program
451 except as expressly provided under this License Agreement. Any attempt
452 otherwise to copy, sublicense, distribute or transfer this program is void and
453 your rights to use the program under this License agreement shall be
454 automatically terminated. However, parties who have received computer
455 software programs from you with this License Agreement will not have
456 their licenses terminated so long as such parties remain in full compliance.
457
458 5. If you wish to incorporate parts of this program into other free
459 programs whose distribution conditions are different, write to the Free
460 Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
461 worked out a simple rule that can be stated here, but we will often permit
462 this. We will be guided by the two goals of preserving the free status of
463 all derivatives of our free software and of promoting the sharing and reuse of
464 software.
465
466
467 In other words, you are welcome to use, share and improve this program.
468 You are forbidden to forbid anyone else to use, share and improve
469 what you give them. Help stamp out software-hoarding! */
470
471 /* This is the parser code that is written into each bison parser
472 when the %semantic_parser declaration is not specified in the grammar.
473 It was written by Richard Stallman by simplifying the hairy parser
474 used when %semantic_parser is specified. */
475
476 /* Note: there must be only one dollar sign in this file.
477 It is replaced by the list of actions, each action
478 as one case of the switch. */
479
480 #define yyerrok (yyerrstatus = 0)
481 #define yyclearin (yychar = YYEMPTY)
482 #define YYEMPTY -2
483 #define YYEOF 0
484 #define YYFAIL goto yyerrlab;
485
486 #define YYTERROR 1
487
488 #ifndef YYIMPURE
489 #define YYLEX yylex()
490 #endif
491
492 #ifndef YYPURE
493 #define YYLEX yylex(&yylval, &yylloc)
494 #endif
495
496 /* If nonreentrant, generate the variables here */
497
498 #ifndef YYIMPURE
499
500 int yychar; /* the lookahead symbol */
501 YYSTYPE yylval; /* the semantic value of the */
502 /* lookahead symbol */
503
504 YYLTYPE yylloc; /* location data for the lookahead */
505 /* symbol */
506
507 int yydebug = 0; /* nonzero means print parse trace */
508
509 #endif /* YYIMPURE */
510
511
512 /* YYMAXDEPTH indicates the initial size of the parser's stacks */
513
514 #ifndef YYMAXDEPTH
515 #define YYMAXDEPTH 200
516 #endif
517
518 /* YYMAXLIMIT is the maximum size the stacks can grow to
519 (effective only if the built-in stack extension method is used). */
520
521 #ifndef YYMAXLIMIT
522 #define YYMAXLIMIT 10000
523 #endif
524
525
526 #line 87 "bison.simple"
527 int
528 yyparse()
529 {
530 register int yystate;
531 register int yyn;
532 register short *yyssp;
533 register YYSTYPE *yyvsp;
534 YYLTYPE *yylsp;
535 int yyerrstatus; /* number of tokens to shift before error messages enabled */
536 int yychar1; /* lookahead token as an internal (translated) token number */
537
538 short yyssa[YYMAXDEPTH]; /* the state stack */
539 YYSTYPE yyvsa[YYMAXDEPTH]; /* the semantic value stack */
540 YYLTYPE yylsa[YYMAXDEPTH]; /* the location stack */
541
542 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
543 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
544 YYLTYPE *yyls = yylsa;
545
546 int yymaxdepth = YYMAXDEPTH;
547
548 #ifndef YYPURE
549
550 int yychar;
551 YYSTYPE yylval;
552 YYLTYPE yylloc;
553
554 extern int yydebug;
555
556 #endif
557
558
559 YYSTYPE yyval; /* the variable used to return */
560 /* semantic values from the action */
561 /* routines */
562
563 int yylen;
564
565 if (yydebug)
566 fprintf(stderr, "Starting parse\n");
567
568 yystate = 0;
569 yyerrstatus = 0;
570 yychar = YYEMPTY; /* Cause a token to be read. */
571
572 /* Initialize stack pointers.
573 Waste one element of value and location stack
574 so that they stay on the same level as the state stack. */
575
576 yyssp = yyss - 1;
577 yyvsp = yyvs;
578 yylsp = yyls;
579
580 /* Push a new state, which is found in yystate . */
581 /* In all cases, when you get here, the value and location stacks
582 have just been pushed. so pushing a state here evens the stacks. */
583 yynewstate:
584
585 *++yyssp = yystate;
586
587 if (yyssp >= yyss + yymaxdepth - 1)
588 {
589 /* Give user a chance to reallocate the stack */
590 /* Use copies of these so that the &'s don't force the real ones into memory. */
591 YYSTYPE *yyvs1 = yyvs;
592 YYLTYPE *yyls1 = yyls;
593 short *yyss1 = yyss;
594
595 /* Get the current used size of the three stacks, in elements. */
596 int size = yyssp - yyss + 1;
597
598 #ifdef yyoverflow
599 /* Each stack pointer address is followed by the size of
600 the data in use in that stack, in bytes. */
601 yyoverflow("parser stack overflow",
602 &yyss1, size * sizeof (*yyssp),
603 &yyvs1, size * sizeof (*yyvsp),
604 &yyls1, size * sizeof (*yylsp),
605 &yymaxdepth);
606
607 yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
608 #else /* no yyoverflow */
609 /* Extend the stack our own way. */
610 if (yymaxdepth >= YYMAXLIMIT)
611 yyerror("parser stack overflow");
612 yymaxdepth *= 2;
613 if (yymaxdepth > YYMAXLIMIT)
614 yymaxdepth = YYMAXLIMIT;
615 yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
616 bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
617 yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
618 bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
619 yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
620 bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
621 #endif /* no yyoverflow */
622
623 yyssp = yyss + size - 1;
624 yylsp = yyls + size - 1;
625 yyvsp = yyvs + size - 1;
626
627 if (yydebug)
628 fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
629
630 if (yyssp >= yyss + yymaxdepth - 1)
631 YYERROR;
632 }
633
634 if (yydebug)
635 fprintf(stderr, "Entering state %d\n", yystate);
636
637 /* Do appropriate processing given the current state. */
638 /* Read a lookahead token if we need one and don't already have one. */
639 yyresume:
640
641 /* First try to decide what to do without reference to lookahead token. */
642
643 yyn = yypact[yystate];
644 if (yyn == YYFLAG)
645 goto yydefault;
646
647 /* Not known => get a lookahead token if don't already have one. */
648
649 /* yychar is either YYEMPTY or YYEOF
650 or a valid token in external form. */
651
652 if (yychar == YYEMPTY)
653 {
654 yychar = YYLEX;
655 }
656
657 /* Convert token to internal form (in yychar1) for indexing tables with */
658
659 if (yychar <= 0) /* This means end of input. */
660 {
661 yychar1 = 0;
662 yychar = YYEOF; /* Don't call YYLEX any more */
663
664 if (yydebug)
665 fprintf(stderr, "Now at end of input.\n");
666 }
667 else
668 {
669 yychar1 = YYTRANSLATE(yychar);
670
671 if (yydebug)
672 fprintf(stderr, "Parsing next token; it is %d (%s)\n", yychar, yytname[yychar1]);
673 }
674
675 yyn += yychar1;
676 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
677 goto yydefault;
678
679 yyn = yytable[yyn];
680
681 /* yyn is what to do for this token type in this state.
682 Negative => reduce, -yyn is rule number.
683 Positive => shift, yyn is new state.
684 New state is final state => don't bother to shift,
685 just return success.
686 0, or most negative number => error. */
687
688 if (yyn < 0)
689 {
690 if (yyn == YYFLAG)
691 goto yyerrlab;
692 yyn = -yyn;
693 goto yyreduce;
694 }
695 else if (yyn == 0)
696 goto yyerrlab;
697
698 if (yyn == YYFINAL)
699 YYACCEPT;
700
701 /* Shift the lookahead token. */
702
703 if (yydebug)
704 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
705
706 /* Discard the token being shifted unless it is eof. */
707 if (yychar != YYEOF)
708 yychar = YYEMPTY;
709
710 *++yyvsp = yylval;
711 *++yylsp = yylloc;
712
713 /* count tokens shifted since error; after three, turn off error status. */
714 if (yyerrstatus) yyerrstatus--;
715
716 yystate = yyn;
717 goto yynewstate;
718
719 /* Do the default action for the current state. */
720 yydefault:
721
722 yyn = yydefact[yystate];
723 if (yyn == 0)
724 goto yyerrlab;
725
726 /* Do a reduction. yyn is the number of a rule to reduce with. */
727 yyreduce:
728 yylen = yyr2[yyn];
729 yyval = yyvsp[1-yylen]; /* implement default value of the action */
730
731 if (yydebug)
732 {
733 if (yylen == 1)
734 fprintf (stderr, "Reducing 1 value via line %d, ",
735 yyrline[yyn]);
736 else
737 fprintf (stderr, "Reducing %d values via line %d, ",
738 yylen, yyrline[yyn]);
739 }
740
741
742 switch (yyn) {
743
744 case 3:
745 #line 158 "expread.y"
746 { write_exp_elt (BINOP_COMMA); ;
747 break;}
748 case 4:
749 #line 163 "expread.y"
750 { write_exp_elt (UNOP_IND); ;
751 break;}
752 case 5:
753 #line 166 "expread.y"
754 { write_exp_elt (UNOP_ADDR); ;
755 break;}
756 case 6:
757 #line 169 "expread.y"
758 { write_exp_elt (UNOP_NEG); ;
759 break;}
760 case 7:
761 #line 173 "expread.y"
762 { write_exp_elt (UNOP_ZEROP); ;
763 break;}
764 case 8:
765 #line 177 "expread.y"
766 { write_exp_elt (UNOP_LOGNOT); ;
767 break;}
768 case 9:
769 #line 181 "expread.y"
770 { write_exp_elt (UNOP_PREINCREMENT); ;
771 break;}
772 case 10:
773 #line 185 "expread.y"
774 { write_exp_elt (UNOP_PREDECREMENT); ;
775 break;}
776 case 11:
777 #line 189 "expread.y"
778 { write_exp_elt (UNOP_POSTINCREMENT); ;
779 break;}
780 case 12:
781 #line 193 "expread.y"
782 { write_exp_elt (UNOP_POSTDECREMENT); ;
783 break;}
784 case 13:
785 #line 197 "expread.y"
786 { write_exp_elt (UNOP_SIZEOF); ;
787 break;}
788 case 14:
789 #line 201 "expread.y"
790 { write_exp_elt (STRUCTOP_PTR);
791 write_exp_string (yyvsp[0].sval);
792 write_exp_elt (STRUCTOP_PTR); ;
793 break;}
794 case 15:
795 #line 207 "expread.y"
796 { write_exp_elt (STRUCTOP_MPTR); ;
797 break;}
798 case 16:
799 #line 211 "expread.y"
800 { write_exp_elt (STRUCTOP_STRUCT);
801 write_exp_string (yyvsp[0].sval);
802 write_exp_elt (STRUCTOP_STRUCT); ;
803 break;}
804 case 17:
805 #line 217 "expread.y"
806 { write_exp_elt (STRUCTOP_MEMBER); ;
807 break;}
808 case 18:
809 #line 221 "expread.y"
810 { write_exp_elt (BINOP_SUBSCRIPT); ;
811 break;}
812 case 19:
813 #line 227 "expread.y"
814 { start_arglist (); ;
815 break;}
816 case 20:
817 #line 229 "expread.y"
818 { write_exp_elt (OP_FUNCALL);
819 write_exp_elt (end_arglist ());
820 write_exp_elt (OP_FUNCALL); ;
821 break;}
822 case 22:
823 #line 238 "expread.y"
824 { arglist_len = 1; ;
825 break;}
826 case 23:
827 #line 242 "expread.y"
828 { arglist_len++; ;
829 break;}
830 case 24:
831 #line 246 "expread.y"
832 { write_exp_elt (UNOP_MEMVAL);
833 write_exp_elt (yyvsp[-2].tval);
834 write_exp_elt (UNOP_MEMVAL); ;
835 break;}
836 case 25:
837 #line 252 "expread.y"
838 { write_exp_elt (UNOP_CAST);
839 write_exp_elt (yyvsp[-2].tval);
840 write_exp_elt (UNOP_CAST); ;
841 break;}
842 case 26:
843 #line 258 "expread.y"
844 { ;
845 break;}
846 case 27:
847 #line 264 "expread.y"
848 { write_exp_elt (BINOP_REPEAT); ;
849 break;}
850 case 28:
851 #line 268 "expread.y"
852 { write_exp_elt (BINOP_MUL); ;
853 break;}
854 case 29:
855 #line 272 "expread.y"
856 { write_exp_elt (BINOP_DIV); ;
857 break;}
858 case 30:
859 #line 276 "expread.y"
860 { write_exp_elt (BINOP_REM); ;
861 break;}
862 case 31:
863 #line 280 "expread.y"
864 { write_exp_elt (BINOP_ADD); ;
865 break;}
866 case 32:
867 #line 284 "expread.y"
868 { write_exp_elt (BINOP_SUB); ;
869 break;}
870 case 33:
871 #line 288 "expread.y"
872 { write_exp_elt (BINOP_LSH); ;
873 break;}
874 case 34:
875 #line 292 "expread.y"
876 { write_exp_elt (BINOP_RSH); ;
877 break;}
878 case 35:
879 #line 296 "expread.y"
880 { write_exp_elt (BINOP_EQUAL); ;
881 break;}
882 case 36:
883 #line 300 "expread.y"
884 { write_exp_elt (BINOP_NOTEQUAL); ;
885 break;}
886 case 37:
887 #line 304 "expread.y"
888 { write_exp_elt (BINOP_LEQ); ;
889 break;}
890 case 38:
891 #line 308 "expread.y"
892 { write_exp_elt (BINOP_GEQ); ;
893 break;}
894 case 39:
895 #line 312 "expread.y"
896 { write_exp_elt (BINOP_LESS); ;
897 break;}
898 case 40:
899 #line 316 "expread.y"
900 { write_exp_elt (BINOP_GTR); ;
901 break;}
902 case 41:
903 #line 320 "expread.y"
904 { write_exp_elt (BINOP_LOGAND); ;
905 break;}
906 case 42:
907 #line 324 "expread.y"
908 { write_exp_elt (BINOP_LOGXOR); ;
909 break;}
910 case 43:
911 #line 328 "expread.y"
912 { write_exp_elt (BINOP_LOGIOR); ;
913 break;}
914 case 44:
915 #line 332 "expread.y"
916 { write_exp_elt (BINOP_AND); ;
917 break;}
918 case 45:
919 #line 336 "expread.y"
920 { write_exp_elt (BINOP_OR); ;
921 break;}
922 case 46:
923 #line 340 "expread.y"
924 { write_exp_elt (TERNOP_COND); ;
925 break;}
926 case 47:
927 #line 344 "expread.y"
928 { write_exp_elt (BINOP_ASSIGN); ;
929 break;}
930 case 48:
931 #line 348 "expread.y"
932 { write_exp_elt (BINOP_ASSIGN_MODIFY);
933 write_exp_elt (yyvsp[-1].opcode);
934 write_exp_elt (BINOP_ASSIGN_MODIFY); ;
935 break;}
936 case 49:
937 #line 354 "expread.y"
938 { write_exp_elt (OP_LONG);
939 write_exp_elt (builtin_type_long);
940 write_exp_elt (yyvsp[0].lval);
941 write_exp_elt (OP_LONG); ;
942 break;}
943 case 50:
944 #line 361 "expread.y"
945 { write_exp_elt (OP_LONG);
946 write_exp_elt (builtin_type_char);
947 write_exp_elt (yyvsp[0].lval);
948 write_exp_elt (OP_LONG); ;
949 break;}
950 case 51:
951 #line 368 "expread.y"
952 { write_exp_elt (OP_DOUBLE);
953 write_exp_elt (builtin_type_double);
954 write_exp_elt (yyvsp[0].dval);
955 write_exp_elt (OP_DOUBLE); ;
956 break;}
957 case 53:
958 #line 378 "expread.y"
959 { write_exp_elt (OP_LAST);
960 write_exp_elt (yyvsp[0].lval);
961 write_exp_elt (OP_LAST); ;
962 break;}
963 case 54:
964 #line 384 "expread.y"
965 { write_exp_elt (OP_REGISTER);
966 write_exp_elt (yyvsp[0].lval);
967 write_exp_elt (OP_REGISTER); ;
968 break;}
969 case 55:
970 #line 390 "expread.y"
971 { write_exp_elt (OP_INTERNALVAR);
972 write_exp_elt (yyvsp[0].ivar);
973 write_exp_elt (OP_INTERNALVAR); ;
974 break;}
975 case 56:
976 #line 396 "expread.y"
977 { write_exp_elt (OP_LONG);
978 write_exp_elt (builtin_type_int);
979 write_exp_elt ((long) TYPE_LENGTH (yyvsp[-1].tval));
980 write_exp_elt (OP_LONG); ;
981 break;}
982 case 57:
983 #line 403 "expread.y"
984 { write_exp_elt (OP_STRING);
985 write_exp_string (yyvsp[0].sval);
986 write_exp_elt (OP_STRING); ;
987 break;}
988 case 58:
989 #line 410 "expread.y"
990 { write_exp_elt (OP_THIS);
991 write_exp_elt (OP_THIS); ;
992 break;}
993 case 59:
994 #line 417 "expread.y"
995 {
996 struct symtab *tem = lookup_symtab (copy_name (yyvsp[0].sval));
997 struct symbol *sym;
998
999 if (tem)
1000 yyval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), 1);
1001 else
1002 {
1003 sym = lookup_symbol (copy_name (yyvsp[0].sval),
1004 expression_context_block,
1005 VAR_NAMESPACE);
1006 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1007 yyval.bval = SYMBOL_BLOCK_VALUE (sym);
1008 else
1009 error ("No file or function \"%s\".",
1010 copy_name (yyvsp[0].sval));
1011 }
1012 ;
1013 break;}
1014 case 60:
1015 #line 438 "expread.y"
1016 {
1017 struct symbol *tem
1018 = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, VAR_NAMESPACE);
1019 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
1020 error ("No function \"%s\" in specified context.",
1021 copy_name (yyvsp[-2].bval));
1022 yyval.bval = SYMBOL_BLOCK_VALUE (tem);
1023 ;
1024 break;}
1025 case 61:
1026 #line 449 "expread.y"
1027 {
1028 struct symbol *sym;
1029 sym = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, VAR_NAMESPACE);
1030 if (sym == 0)
1031 error ("No symbol \"%s\" in specified context.",
1032 copy_name (yyvsp[0].sval));
1033 write_exp_elt (OP_VAR_VALUE);
1034 write_exp_elt (sym);
1035 write_exp_elt (OP_VAR_VALUE);
1036 ;
1037 break;}
1038 case 62:
1039 #line 462 "expread.y"
1040 {
1041 struct type *type = yyvsp[-2].tval;
1042 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1043 && TYPE_CODE (type) != TYPE_CODE_UNION)
1044 error ("`%s' is not defined as an aggregate type.",
1045 TYPE_NAME (type));
1046
1047 write_exp_elt (OP_SCOPE);
1048 write_exp_elt (type);
1049 write_exp_string (yyvsp[0].sval);
1050 write_exp_elt (OP_SCOPE);
1051 ;
1052 break;}
1053 case 63:
1054 #line 475 "expread.y"
1055 {
1056 char *name = copy_name (yyvsp[0].sval);
1057 struct symbol *sym;
1058 int i;
1059
1060 sym = lookup_symbol_2 (name, 0, VAR_NAMESPACE);
1061 if (sym)
1062 {
1063 write_exp_elt (OP_VAR_VALUE);
1064 write_exp_elt (sym);
1065 write_exp_elt (OP_VAR_VALUE);
1066 break;
1067 }
1068 for (i = 0; i < misc_function_count; i++)
1069 if (!strcmp (misc_function_vector[i].name, name))
1070 break;
1071
1072 if (i < misc_function_count)
1073 {
1074 write_exp_elt (OP_LONG);
1075 write_exp_elt (builtin_type_int);
1076 write_exp_elt (misc_function_vector[i].address);
1077 write_exp_elt (OP_LONG);
1078 write_exp_elt (UNOP_MEMVAL);
1079 write_exp_elt (builtin_type_char);
1080 write_exp_elt (UNOP_MEMVAL);
1081 }
1082 else
1083 if (symtab_list == 0)
1084 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1085 else
1086 error ("No symbol \"%s\" in current context.", name);
1087 ;
1088 break;}
1089 case 64:
1090 #line 511 "expread.y"
1091 { struct symbol *sym;
1092 sym = lookup_symbol_1 (copy_name (yyvsp[0].sval),
1093 expression_context_block,
1094 VAR_NAMESPACE);
1095 if (sym)
1096 {
1097 write_exp_elt (OP_VAR_VALUE);
1098 write_exp_elt (sym);
1099 write_exp_elt (OP_VAR_VALUE);
1100 }
1101 else
1102 {
1103 register char *arg = copy_name (yyvsp[0].sval);
1104 register int i;
1105 int v, val;
1106 /* C++: see if it hangs off of `this'. Must
1107 not inadvertently convert from a method call
1108 to data ref. */
1109 v = (int)value_of_this (0);
1110 if (v)
1111 {
1112 val = check_field (v, arg);
1113 if (val)
1114 {
1115 write_exp_elt (OP_THIS);
1116 write_exp_elt (OP_THIS);
1117 write_exp_elt (STRUCTOP_PTR);
1118 write_exp_string (yyvsp[0].sval);
1119 write_exp_elt (STRUCTOP_PTR);
1120 break;
1121 }
1122 }
1123 sym = lookup_symbol_2 (arg, 0, VAR_NAMESPACE);
1124 if (sym)
1125 {
1126 write_exp_elt (OP_VAR_VALUE);
1127 write_exp_elt (sym);
1128 write_exp_elt (OP_VAR_VALUE);
1129 break; /* YACC-dependent */
1130 }
1131 for (i = 0; i < misc_function_count; i++)
1132 if (!strcmp (misc_function_vector[i].name, arg))
1133 break;
1134
1135 if (i < misc_function_count)
1136 {
1137 write_exp_elt (OP_LONG);
1138 write_exp_elt (builtin_type_int);
1139 write_exp_elt (misc_function_vector[i].address);
1140 write_exp_elt (OP_LONG);
1141 write_exp_elt (UNOP_MEMVAL);
1142 write_exp_elt (builtin_type_char);
1143 write_exp_elt (UNOP_MEMVAL);
1144 }
1145 else
1146 if (symtab_list == 0)
1147 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1148 else
1149 error ("No symbol \"%s\" in current context.",
1150 copy_name (yyvsp[0].sval));
1151 }
1152 ;
1153 break;}
1154 case 66:
1155 #line 577 "expread.y"
1156 { yyval.tval = lookup_pointer_type (yyvsp[-1].tval); ;
1157 break;}
1158 case 67:
1159 #line 579 "expread.y"
1160 { yyval.tval = lookup_reference_type (yyvsp[-1].tval); ;
1161 break;}
1162 case 68:
1163 #line 581 "expread.y"
1164 { yyval.tval = lookup_member_pointer_type (builtin_type_int, yyvsp[-2].tval); ;
1165 break;}
1166 case 69:
1167 #line 583 "expread.y"
1168 { yyval.tval = lookup_member_pointer_type (yyvsp[-5].tval, yyvsp[-3].tval); ;
1169 break;}
1170 case 70:
1171 #line 585 "expread.y"
1172 { yyval.tval = lookup_member_pointer_type (lookup_function_type (yyvsp[-7].tval, 0), yyvsp[-5].tval); ;
1173 break;}
1174 case 71:
1175 #line 587 "expread.y"
1176 { yyval.tval = lookup_member_pointer_type (lookup_function_type (yyvsp[-8].tval, yyvsp[-1].tvec), yyvsp[-6].tval);
1177 free (yyvsp[-1].tvec); ;
1178 break;}
1179 case 72:
1180 #line 593 "expread.y"
1181 { yyval.tval = lookup_typename (copy_name (yyvsp[0].sval),
1182 expression_context_block, 0); ;
1183 break;}
1184 case 73:
1185 #line 596 "expread.y"
1186 { yyval.tval = lookup_struct (copy_name (yyvsp[0].sval),
1187 expression_context_block); ;
1188 break;}
1189 case 74:
1190 #line 599 "expread.y"
1191 { yyval.tval = lookup_union (copy_name (yyvsp[0].sval),
1192 expression_context_block); ;
1193 break;}
1194 case 75:
1195 #line 602 "expread.y"
1196 { yyval.tval = lookup_enum (copy_name (yyvsp[0].sval),
1197 expression_context_block); ;
1198 break;}
1199 case 76:
1200 #line 605 "expread.y"
1201 { yyval.tval = lookup_unsigned_typename (copy_name (yyvsp[0].sval)); ;
1202 break;}
1203 case 77:
1204 #line 610 "expread.y"
1205 { yyval.tvec = (struct type **)xmalloc (sizeof (struct type *) * 2);
1206 yyval.tvec[0] = (struct type *)0;
1207 yyval.tvec[1] = yyvsp[0].tval;
1208 ;
1209 break;}
1210 case 78:
1211 #line 615 "expread.y"
1212 { int len = sizeof (struct type *) * ++(yyvsp[-2].ivec[0]);
1213 yyval.tvec = (struct type **)xrealloc (yyvsp[-2].tvec, len);
1214 yyval.tvec[yyval.ivec[0]] = yyvsp[0].tval;
1215 ;
1216 break;}
1217 }
1218 /* the action file gets copied in in place of this dollarsign */
1219 #line 303 "bison.simple"
1220 \f
1221 yyvsp -= yylen;
1222 yylsp -= yylen;
1223 yyssp -= yylen;
1224
1225 if (yydebug)
1226 {
1227 short *ssp1 = yyss - 1;
1228 fprintf (stderr, "state stack now", yyssp-yyss);
1229 while (ssp1 != yyssp)
1230 fprintf (stderr, " %d", *++ssp1);
1231 fprintf (stderr, "\n");
1232 }
1233
1234 *++yyvsp = yyval;
1235
1236 yylsp++;
1237 if (yylen == 0)
1238 {
1239 yylsp->first_line = yylloc.first_line;
1240 yylsp->first_column = yylloc.first_column;
1241 yylsp->last_line = (yylsp-1)->last_line;
1242 yylsp->last_column = (yylsp-1)->last_column;
1243 yylsp->text = 0;
1244 }
1245 else
1246 {
1247 yylsp->last_line = (yylsp+yylen-1)->last_line;
1248 yylsp->last_column = (yylsp+yylen-1)->last_column;
1249 }
1250
1251 /* Now "shift" the result of the reduction.
1252 Determine what state that goes to,
1253 based on the state we popped back to
1254 and the rule number reduced by. */
1255
1256 yyn = yyr1[yyn];
1257
1258 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1259 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1260 yystate = yytable[yystate];
1261 else
1262 yystate = yydefgoto[yyn - YYNTBASE];
1263
1264 goto yynewstate;
1265
1266 yyerrlab: /* here on detecting error */
1267
1268 if (! yyerrstatus)
1269 /* If not already recovering from an error, report this error. */
1270 {
1271 #ifdef ESKIT
1272 db_yyerror("parse error", yyssp, yychar);
1273 #else
1274 yyerror("parse error");
1275 #endif
1276 }
1277
1278 if (yyerrstatus == 3)
1279 {
1280 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1281
1282 /* return failure if at end of input */
1283 if (yychar == YYEOF)
1284 YYERROR;
1285
1286 if (yydebug)
1287 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1288
1289 yychar = YYEMPTY;
1290 }
1291
1292 /* Else will try to reuse lookahead token
1293 after shifting the error token. */
1294
1295 yyerrstatus = 3; /* Each real token shifted decrements this */
1296
1297 goto yyerrhandle;
1298
1299 yyerrdefault: /* current state does not do anything special for the error token. */
1300
1301 #if 0
1302 /* This is wrong; only states that explicitly want error tokens
1303 should shift them. */
1304 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1305 if (yyn) goto yydefault;
1306 #endif
1307
1308 yyerrpop: /* pop the current state because it cannot handle the error token */
1309
1310 if (yyssp == yyss) YYERROR;
1311 yyvsp--;
1312 yylsp--;
1313 yystate = *--yyssp;
1314
1315 if (yydebug)
1316 {
1317 short *ssp1 = yyss - 1;
1318 fprintf (stderr, "Error: state stack now", yyssp-yyss);
1319 while (ssp1 != yyssp)
1320 fprintf (stderr, " %d", *++ssp1);
1321 fprintf (stderr, "\n");
1322 }
1323
1324 yyerrhandle:
1325
1326 yyn = yypact[yystate];
1327 if (yyn == YYFLAG)
1328 goto yyerrdefault;
1329
1330 yyn += YYTERROR;
1331 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1332 goto yyerrdefault;
1333
1334 yyn = yytable[yyn];
1335 if (yyn < 0)
1336 {
1337 if (yyn == YYFLAG)
1338 goto yyerrpop;
1339 yyn = -yyn;
1340 goto yyreduce;
1341 }
1342 else if (yyn == 0)
1343 goto yyerrpop;
1344
1345 if (yyn == YYFINAL)
1346 YYACCEPT;
1347
1348 if (yydebug)
1349 fprintf(stderr, "Shifting error token, ");
1350
1351 *++yyvsp = yylval;
1352 *++yylsp = yylloc;
1353
1354 yystate = yyn;
1355 goto yynewstate;
1356 }
1357 #line 624 "expread.y"
1358
1359 \f
1360 /* Begin counting arguments for a function call,
1361 saving the data about any containing call. */
1362
1363 static void
1364 start_arglist ()
1365 {
1366 register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall));
1367
1368 new->next = funcall_chain;
1369 new->arglist_len = arglist_len;
1370 arglist_len = 0;
1371 funcall_chain = new;
1372 }
1373
1374 /* Return the number of arguments in a function call just terminated,
1375 and restore the data for the containing function call. */
1376
1377 static int
1378 end_arglist ()
1379 {
1380 register int val = arglist_len;
1381 register struct funcall *call = funcall_chain;
1382 funcall_chain = call->next;
1383 arglist_len = call->arglist_len;
1384 free (call);
1385 return val;
1386 }
1387
1388 /* Free everything in the funcall chain.
1389 Used when there is an error inside parsing. */
1390
1391 static void
1392 free_funcalls ()
1393 {
1394 register struct funcall *call, *next;
1395
1396 for (call = funcall_chain; call; call = next)
1397 {
1398 next = call->next;
1399 free (call);
1400 }
1401 }
1402 \f
1403 /* This page contains the functions for adding data to the struct expression
1404 being constructed. */
1405
1406 /* Add one element to the end of the expression. */
1407
1408 static void
1409 write_exp_elt (expelt)
1410 union exp_element expelt;
1411 {
1412 if (expout_ptr >= expout_size)
1413 {
1414 expout_size *= 2;
1415 expout = (struct expression *) xrealloc (expout,
1416 sizeof (struct expression)
1417 + expout_size * sizeof (union exp_element));
1418 }
1419 expout->elts[expout_ptr++] = expelt;
1420 }
1421
1422 /* Add a string constant to the end of the expression.
1423 Follow it by its length in bytes, as a separate exp_element. */
1424
1425 static void
1426 write_exp_string (str)
1427 struct stoken str;
1428 {
1429 register int len = str.length;
1430 register int lenelt
1431 = (len + sizeof (union exp_element)) / sizeof (union exp_element);
1432
1433 expout_ptr += lenelt;
1434
1435 if (expout_ptr >= expout_size)
1436 {
1437 expout_size = max (expout_size * 2, expout_ptr + 10);
1438 expout = (struct expression *) xrealloc (expout,
1439 sizeof (struct expression)
1440 + expout_size * sizeof (union exp_element));
1441 }
1442 bcopy (str.ptr, (char *) &expout->elts[expout_ptr - lenelt], len);
1443 ((char *) &expout->elts[expout_ptr - lenelt])[len] = 0;
1444 write_exp_elt (len);
1445 }
1446 \f
1447 /* During parsing of a C expression, the pointer to the next character
1448 is in this variable. */
1449
1450 static char *lexptr;
1451
1452 /* Tokens that refer to names do so with explicit pointer and length,
1453 so they can share the storage that lexptr is parsing.
1454
1455 When it is necessary to pass a name to a function that expects
1456 a null-terminated string, the substring is copied out
1457 into a block of storage that namecopy points to.
1458
1459 namecopy is allocated once, guaranteed big enough, for each parsing. */
1460
1461 static char *namecopy;
1462
1463 /* Current depth in parentheses within the expression. */
1464
1465 static int paren_depth;
1466
1467 /* Nonzero means stop parsing on first comma (if not within parentheses). */
1468
1469 static int comma_terminates;
1470
1471 /* Take care of parsing a number (anything that starts with a digit).
1472 Set yylval and return the token type; update lexptr.
1473 LEN is the number of characters in it. */
1474
1475 /*** Needs some error checking for the float case ***/
1476
1477 static int
1478 parse_number (olen)
1479 int olen;
1480 {
1481 register char *p = lexptr;
1482 register long n = 0;
1483 register int c;
1484 register int base = 10;
1485 register int len = olen;
1486 char *err_copy;
1487
1488 extern double atof ();
1489
1490 for (c = 0; c < len; c++)
1491 if (p[c] == '.')
1492 {
1493 /* It's a float since it contains a point. */
1494 yylval.dval = atof (p);
1495 lexptr += len;
1496 return FLOAT;
1497 }
1498
1499 if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2)))
1500 {
1501 p += 2;
1502 base = 16;
1503 len -= 2;
1504 }
1505 else if (*p == '0')
1506 base = 8;
1507
1508 while (len-- > 0)
1509 {
1510 c = *p++;
1511 n *= base;
1512 if (c >= '0' && c <= '9')
1513 n += c - '0';
1514 else
1515 {
1516 if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
1517 if (base == 16 && c >= 'a' && c <= 'f')
1518 n += c - 'a' + 10;
1519 else if (len == 0 && c == 'l')
1520 ;
1521 else
1522 {
1523 err_copy = (char *) alloca (olen + 1);
1524 bcopy (lexptr, err_copy, olen);
1525 err_copy[olen] = 0;
1526 error ("Invalid number \"%s\".", err_copy);
1527 }
1528 }
1529 }
1530
1531 lexptr = p;
1532 yylval.lval = n;
1533 return INT;
1534 }
1535
1536 struct token
1537 {
1538 char *operator;
1539 int token;
1540 enum exp_opcode opcode;
1541 };
1542
1543 static struct token tokentab3[] =
1544 {
1545 {">>=", ASSIGN_MODIFY, BINOP_RSH},
1546 {"<<=", ASSIGN_MODIFY, BINOP_LSH}
1547 };
1548
1549 static struct token tokentab2[] =
1550 {
1551 {"+=", ASSIGN_MODIFY, BINOP_ADD},
1552 {"-=", ASSIGN_MODIFY, BINOP_SUB},
1553 {"*=", ASSIGN_MODIFY, BINOP_MUL},
1554 {"/=", ASSIGN_MODIFY, BINOP_DIV},
1555 {"%=", ASSIGN_MODIFY, BINOP_REM},
1556 {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
1557 {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
1558 {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
1559 {"++", INCREMENT, BINOP_END},
1560 {"--", DECREMENT, BINOP_END},
1561 {"->", ARROW, BINOP_END},
1562 {"&&", AND, BINOP_END},
1563 {"||", OR, BINOP_END},
1564 {"::", COLONCOLON, BINOP_END},
1565 {"<<", LSH, BINOP_END},
1566 {">>", RSH, BINOP_END},
1567 {"==", EQUAL, BINOP_END},
1568 {"!=", NOTEQUAL, BINOP_END},
1569 {"<=", LEQ, BINOP_END},
1570 {">=", GEQ, BINOP_END}
1571 };
1572
1573 /* Read one token, getting characters through lexptr. */
1574
1575 static int
1576 yylex ()
1577 {
1578 register int c;
1579 register int namelen;
1580 register int i;
1581 register char *tokstart;
1582
1583 retry:
1584
1585 tokstart = lexptr;
1586 /* See if it is a special token of length 3. */
1587 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
1588 if (!strncmp (tokstart, tokentab3[i].operator, 3))
1589 {
1590 lexptr += 3;
1591 yylval.opcode = tokentab3[i].opcode;
1592 return tokentab3[i].token;
1593 }
1594
1595 /* See if it is a special token of length 2. */
1596 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
1597 if (!strncmp (tokstart, tokentab2[i].operator, 2))
1598 {
1599 lexptr += 2;
1600 yylval.opcode = tokentab2[i].opcode;
1601 return tokentab2[i].token;
1602 }
1603
1604 switch (c = *tokstart)
1605 {
1606 case 0:
1607 return 0;
1608
1609 case ' ':
1610 case '\t':
1611 case '\n':
1612 lexptr++;
1613 goto retry;
1614
1615 case '\'':
1616 lexptr++;
1617 c = *lexptr++;
1618 if (c == '\\')
1619 c = parse_escape (&lexptr);
1620 yylval.lval = c;
1621 c = *lexptr++;
1622 if (c != '\'')
1623 error ("Invalid character constant.");
1624 return CHAR;
1625
1626 case '(':
1627 paren_depth++;
1628 lexptr++;
1629 return c;
1630
1631 case ')':
1632 if (paren_depth == 0)
1633 return 0;
1634 paren_depth--;
1635 lexptr++;
1636 return c;
1637
1638 case ',':
1639 if (comma_terminates && paren_depth == 0)
1640 return 0;
1641 lexptr++;
1642 return c;
1643
1644 case '+':
1645 case '-':
1646 case '*':
1647 case '/':
1648 case '%':
1649 case '|':
1650 case '&':
1651 case '^':
1652 case '~':
1653 case '!':
1654 case '@':
1655 case '<':
1656 case '>':
1657 case '[':
1658 case ']':
1659 case '.':
1660 case '?':
1661 case ':':
1662 case '=':
1663 case '{':
1664 case '}':
1665 lexptr++;
1666 return c;
1667
1668 case '"':
1669 for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
1670 if (c == '\\')
1671 {
1672 c = tokstart[++namelen];
1673 if (c >= '0' && c <= '9')
1674 {
1675 c = tokstart[++namelen];
1676 if (c >= '0' && c <= '9')
1677 c = tokstart[++namelen];
1678 }
1679 }
1680 yylval.sval.ptr = tokstart + 1;
1681 yylval.sval.length = namelen - 1;
1682 lexptr += namelen + 1;
1683 return STRING;
1684 }
1685 if (c >= '0' && c <= '9')
1686 {
1687 /* It's a number */
1688 for (namelen = 0;
1689 c = tokstart[namelen],
1690 (c == '_' || c == '$' || c == '.' || (c >= '0' && c <= '9')
1691 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1692 namelen++)
1693 ;
1694 return parse_number (namelen);
1695 }
1696
1697 if (!(c == '_' || c == '$'
1698 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1699 error ("Invalid token in expression.");
1700
1701 /* It is a name. See how long it is. */
1702
1703 for (namelen = 0;
1704 c = tokstart[namelen],
1705 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1706 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1707 namelen++)
1708 ;
1709
1710 /* The token "if" terminates the expression and is NOT
1711 removed from the input stream. */
1712 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1713 {
1714 return 0;
1715 }
1716
1717 lexptr += namelen;
1718
1719 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
1720 and $$digits (equivalent to $<-digits> if you could type that).
1721 Make token type LAST, and put the number (the digits) in yylval. */
1722
1723 if (*tokstart == '$')
1724 {
1725 register int negate = 0;
1726 c = 1;
1727 /* Double dollar means negate the number and add -1 as well.
1728 Thus $$ alone means -1. */
1729 if (namelen >= 2 && tokstart[1] == '$')
1730 {
1731 negate = 1;
1732 c = 2;
1733 }
1734 if (c == namelen)
1735 {
1736 /* Just dollars (one or two) */
1737 yylval.lval = - negate;
1738 return LAST;
1739 }
1740 /* Is the rest of the token digits? */
1741 for (; c < namelen; c++)
1742 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
1743 break;
1744 if (c == namelen)
1745 {
1746 yylval.lval = atoi (tokstart + 1 + negate);
1747 if (negate)
1748 yylval.lval = - yylval.lval;
1749 return LAST;
1750 }
1751 }
1752
1753 /* Handle tokens that refer to machine registers:
1754 $ followed by a register name. */
1755
1756 if (*tokstart == '$')
1757 for (c = 0; c < NUM_REGS; c++)
1758 if (namelen - 1 == strlen (reg_names[c])
1759 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
1760 {
1761 yylval.lval = c;
1762 return REGNAME;
1763 }
1764
1765 if (namelen == 6 && !strncmp (tokstart, "struct", 6))
1766 {
1767 return STRUCT;
1768 }
1769 if (namelen == 5)
1770 {
1771 if (!strncmp (tokstart, "union", 5))
1772 {
1773 return UNION;
1774 }
1775 }
1776 if (namelen == 4)
1777 {
1778 if (!strncmp (tokstart, "enum", 4))
1779 {
1780 return ENUM;
1781 }
1782 if (!strncmp (tokstart, "this", 4))
1783 {
1784 return THIS;
1785 }
1786 }
1787 if (namelen == 6 && !strncmp (tokstart, "sizeof", 6))
1788 {
1789 return SIZEOF;
1790 }
1791 if (namelen == 8 && !strncmp (tokstart, "unsigned", 6))
1792 {
1793 return UNSIGNED;
1794 }
1795 yylval.sval.ptr = tokstart;
1796 yylval.sval.length = namelen;
1797
1798 /* Any other names starting in $ are debugger internal variables. */
1799
1800 if (*tokstart == '$')
1801 {
1802 yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
1803 return VARIABLE;
1804 }
1805
1806 /* Use token-type TYPENAME for symbols that happen to be defined
1807 currently as names of types; NAME for other symbols.
1808 The caller is not constrained to care about the distinction. */
1809 if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
1810 return TYPENAME;
1811 return NAME;
1812 }
1813
1814 static
1815 yyerror ()
1816 {
1817 error ("Invalid syntax in expression.");
1818 }
1819
1820 /* Return a null-terminated temporary copy of the name
1821 of a string token. */
1822
1823 static char *
1824 copy_name (token)
1825 struct stoken token;
1826 {
1827 bcopy (token.ptr, namecopy, token.length);
1828 namecopy[token.length] = 0;
1829 return namecopy;
1830 }
1831 \f
1832 /* Reverse an expression from suffix form (in which it is constructed)
1833 to prefix form (in which we can conveniently print or execute it). */
1834
1835 static void prefixify_subexp ();
1836
1837 static void
1838 prefixify_expression (expr)
1839 register struct expression *expr;
1840 {
1841 register int len = sizeof (struct expression) +
1842 expr->nelts * sizeof (union exp_element);
1843 register struct expression *temp;
1844 register int inpos = expr->nelts, outpos = 0;
1845
1846 temp = (struct expression *) alloca (len);
1847
1848 /* Copy the original expression into temp. */
1849 bcopy (expr, temp, len);
1850
1851 prefixify_subexp (temp, expr, inpos, outpos);
1852 }
1853
1854 /* Return the number of exp_elements in the subexpression of EXPR
1855 whose last exp_element is at index ENDPOS - 1 in EXPR. */
1856
1857 static int
1858 length_of_subexp (expr, endpos)
1859 register struct expression *expr;
1860 register int endpos;
1861 {
1862 register int oplen = 1;
1863 register int args = 0;
1864 register int i;
1865
1866 if (endpos < 0)
1867 error ("?error in length_of_subexp");
1868
1869 i = (int) expr->elts[endpos - 1].opcode;
1870
1871 switch (i)
1872 {
1873 /* C++ */
1874 case OP_SCOPE:
1875 oplen = 4 + ((expr->elts[endpos - 2].longconst
1876 + sizeof (union exp_element))
1877 / sizeof (union exp_element));
1878 break;
1879
1880 case OP_LONG:
1881 case OP_DOUBLE:
1882 oplen = 4;
1883 break;
1884
1885 case OP_VAR_VALUE:
1886 case OP_LAST:
1887 case OP_REGISTER:
1888 case OP_INTERNALVAR:
1889 oplen = 3;
1890 break;
1891
1892 case OP_FUNCALL:
1893 oplen = 3;
1894 args = 1 + expr->elts[endpos - 2].longconst;
1895 break;
1896
1897 case UNOP_CAST:
1898 case UNOP_MEMVAL:
1899 oplen = 3;
1900 args = 1;
1901 break;
1902
1903 case STRUCTOP_STRUCT:
1904 case STRUCTOP_PTR:
1905 args = 1;
1906 case OP_STRING:
1907 oplen = 3 + ((expr->elts[endpos - 2].longconst
1908 + sizeof (union exp_element))
1909 / sizeof (union exp_element));
1910 break;
1911
1912 case TERNOP_COND:
1913 args = 3;
1914 break;
1915
1916 case BINOP_ASSIGN_MODIFY:
1917 oplen = 3;
1918 args = 2;
1919 break;
1920
1921 /* C++ */
1922 case OP_THIS:
1923 oplen = 2;
1924 break;
1925
1926 default:
1927 args = 1 + (i < (int) BINOP_END);
1928 }
1929
1930 while (args > 0)
1931 {
1932 oplen += length_of_subexp (expr, endpos - oplen);
1933 args--;
1934 }
1935
1936 return oplen;
1937 }
1938
1939 /* Copy the subexpression ending just before index INEND in INEXPR
1940 into OUTEXPR, starting at index OUTBEG.
1941 In the process, convert it from suffix to prefix form. */
1942
1943 static void
1944 prefixify_subexp (inexpr, outexpr, inend, outbeg)
1945 register struct expression *inexpr;
1946 struct expression *outexpr;
1947 register int inend;
1948 int outbeg;
1949 {
1950 register int oplen = 1;
1951 register int args = 0;
1952 register int i;
1953 int *arglens;
1954 enum exp_opcode opcode;
1955
1956 /* Compute how long the last operation is (in OPLEN),
1957 and also how many preceding subexpressions serve as
1958 arguments for it (in ARGS). */
1959
1960 opcode = inexpr->elts[inend - 1].opcode;
1961 switch (opcode)
1962 {
1963 /* C++ */
1964 case OP_SCOPE:
1965 oplen = 4 + ((inexpr->elts[inend - 2].longconst
1966 + sizeof (union exp_element))
1967 / sizeof (union exp_element));
1968 break;
1969
1970 case OP_LONG:
1971 case OP_DOUBLE:
1972 oplen = 4;
1973 break;
1974
1975 case OP_VAR_VALUE:
1976 case OP_LAST:
1977 case OP_REGISTER:
1978 case OP_INTERNALVAR:
1979 oplen = 3;
1980 break;
1981
1982 case OP_FUNCALL:
1983 oplen = 3;
1984 args = 1 + inexpr->elts[inend - 2].longconst;
1985 break;
1986
1987 case UNOP_CAST:
1988 case UNOP_MEMVAL:
1989 oplen = 3;
1990 args = 1;
1991 break;
1992
1993 case STRUCTOP_STRUCT:
1994 case STRUCTOP_PTR:
1995 args = 1;
1996 case OP_STRING:
1997 oplen = 3 + ((inexpr->elts[inend - 2].longconst
1998 + sizeof (union exp_element))
1999 / sizeof (union exp_element));
2000
2001 break;
2002
2003 case TERNOP_COND:
2004 args = 3;
2005 break;
2006
2007 case BINOP_ASSIGN_MODIFY:
2008 oplen = 3;
2009 args = 2;
2010 break;
2011
2012 /* C++ */
2013 case OP_THIS:
2014 oplen = 2;
2015 break;
2016
2017 default:
2018 args = 1 + ((int) opcode < (int) BINOP_END);
2019 }
2020
2021 /* Copy the final operator itself, from the end of the input
2022 to the beginning of the output. */
2023 inend -= oplen;
2024 bcopy (&inexpr->elts[inend], &outexpr->elts[outbeg],
2025 oplen * sizeof (union exp_element));
2026 outbeg += oplen;
2027
2028 /* Find the lengths of the arg subexpressions. */
2029 arglens = (int *) alloca (args * sizeof (int));
2030 for (i = args - 1; i >= 0; i--)
2031 {
2032 oplen = length_of_subexp (inexpr, inend);
2033 arglens[i] = oplen;
2034 inend -= oplen;
2035 }
2036
2037 /* Now copy each subexpression, preserving the order of
2038 the subexpressions, but prefixifying each one.
2039 In this loop, inend starts at the beginning of
2040 the expression this level is working on
2041 and marches forward over the arguments.
2042 outbeg does similarly in the output. */
2043 for (i = 0; i < args; i++)
2044 {
2045 oplen = arglens[i];
2046 inend += oplen;
2047 prefixify_subexp (inexpr, outexpr, inend, outbeg);
2048 outbeg += oplen;
2049 }
2050 }
2051 \f
2052 /* This page contains the two entry points to this file. */
2053
2054 /* Read a C expression from the string *STRINGPTR points to,
2055 parse it, and return a pointer to a struct expression that we malloc.
2056 Use block BLOCK as the lexical context for variable names;
2057 if BLOCK is zero, use the block of the selected stack frame.
2058 Meanwhile, advance *STRINGPTR to point after the expression,
2059 at the first nonwhite character that is not part of the expression
2060 (possibly a null character).
2061
2062 If COMMA is nonzero, stop if a comma is reached. */
2063
2064 struct expression *
2065 parse_c_1 (stringptr, block, comma)
2066 char **stringptr;
2067 struct block *block;
2068 {
2069 struct cleanup *old_chain;
2070
2071 lexptr = *stringptr;
2072
2073 comma_terminates = comma;
2074
2075 if (lexptr == 0 || *lexptr == 0)
2076 error_no_arg ("expression to compute");
2077
2078 old_chain = make_cleanup (free_funcalls, 0);
2079 funcall_chain = 0;
2080
2081 expression_context_block = block ? block : get_selected_block ();
2082
2083 namecopy = (char *) alloca (strlen (lexptr) + 1);
2084 expout_size = 10;
2085 expout_ptr = 0;
2086 expout = (struct expression *) xmalloc (sizeof (struct expression)
2087 + expout_size * sizeof (union exp_element));
2088 make_cleanup (free_current_contents, &expout);
2089 if (yyparse ())
2090 yyerror ();
2091 discard_cleanups (old_chain);
2092 expout->nelts = expout_ptr;
2093 expout = (struct expression *)
2094 xrealloc (expout,
2095 sizeof (struct expression)
2096 + expout_ptr * sizeof (union exp_element));
2097 prefixify_expression (expout);
2098 *stringptr = lexptr;
2099 return expout;
2100 }
2101
2102 /* Parse STRING as an expression, and complain if this fails
2103 to use up all of the contents of STRING. */
2104
2105 struct expression *
2106 parse_c_expression (string)
2107 char *string;
2108 {
2109 register struct expression *exp;
2110 exp = parse_c_1 (&string, 0, 0);
2111 if (*string)
2112 error ("Junk after end of expression.");
2113 return exp;
2114 }
This page took 0.09851 seconds and 5 git commands to generate.