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