]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/expread.tab.c
87de8f6fe13ccaa4877cdceb650d0958bd9a753e
[thirdparty/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 UINT 260
7 #define FLOAT 261
8 #define NAME 262
9 #define TYPENAME 263
10 #define BLOCKNAME 264
11 #define STRING 265
12 #define STRUCT 266
13 #define UNION 267
14 #define ENUM 268
15 #define SIZEOF 269
16 #define UNSIGNED 270
17 #define COLONCOLON 271
18 #define SIGNED 272
19 #define LONG 273
20 #define SHORT 274
21 #define INT_KEYWORD 275
22 #define LAST 276
23 #define REGNAME 277
24 #define VARIABLE 278
25 #define ASSIGN_MODIFY 279
26 #define THIS 280
27 #define ABOVE_COMMA 281
28 #define OR 282
29 #define AND 283
30 #define EQUAL 284
31 #define NOTEQUAL 285
32 #define LEQ 286
33 #define GEQ 287
34 #define LSH 288
35 #define RSH 289
36 #define UNARY 290
37 #define INCREMENT 291
38 #define DECREMENT 292
39 #define ARROW 293
40
41 #line 29 "expread.y"
42
43 #include "defs.h"
44 #include "param.h"
45 #include "symtab.h"
46 #include "frame.h"
47 #include "expression.h"
48
49 #include <stdio.h>
50 #include <a.out.h>
51
52 static struct expression *expout;
53 static int expout_size;
54 static int expout_ptr;
55
56 static int yylex ();
57 static void yyerror ();
58 static void write_exp_elt ();
59 static void write_exp_elt_opcode ();
60 static void write_exp_elt_sym ();
61 static void write_exp_elt_longcst ();
62 static void write_exp_elt_dblcst ();
63 static void write_exp_elt_type ();
64 static void write_exp_elt_intern ();
65 static void write_exp_string ();
66 static void start_arglist ();
67 static int end_arglist ();
68 static void free_funcalls ();
69 static char *copy_name ();
70
71 /* If this is nonzero, this block is used as the lexical context
72 for symbol names. */
73
74 static struct block *expression_context_block;
75
76 /* The innermost context required by the stack and register variables
77 we've encountered so far. */
78 struct block *innermost_block;
79
80 /* The block in which the most recently discovered symbol was found. */
81 struct block *block_found;
82
83 /* Number of arguments seen so far in innermost function call. */
84 static int arglist_len;
85
86 /* Data structure for saving values of arglist_len
87 for function calls whose arguments contain other function calls. */
88
89 struct funcall
90 {
91 struct funcall *next;
92 int arglist_len;
93 };
94
95 struct funcall *funcall_chain;
96
97 /* This kind of datum is used to represent the name
98 of a symbol token. */
99
100 struct stoken
101 {
102 char *ptr;
103 int length;
104 };
105
106 /* For parsing of complicated types.
107 An array should be preceded in the list by the size of the array. */
108 enum type_pieces
109 {tp_end = -1, tp_pointer, tp_reference, tp_array, tp_function};
110 static enum type_pieces *type_stack;
111 static int type_stack_depth, type_stack_size;
112
113 static void push_type ();
114 static enum type_pieces pop_type ();
115
116 /* Allow debugging of parsing. */
117 #define YYDEBUG 1
118
119 #line 111 "expread.y"
120 typedef union
121 {
122 LONGEST lval;
123 unsigned LONGEST ulval;
124 double dval;
125 struct symbol *sym;
126 struct type *tval;
127 struct stoken sval;
128 int voidval;
129 struct block *bval;
130 enum exp_opcode opcode;
131 struct internalvar *ivar;
132
133 struct type **tvec;
134 int *ivec;
135 } YYSTYPE;
136
137 #ifndef YYLTYPE
138 typedef
139 struct yyltype
140 {
141 int timestamp;
142 int first_line;
143 int first_column;
144 int last_line;
145 int last_column;
146 char *text;
147 }
148 yyltype;
149
150 #define YYLTYPE yyltype
151 #endif
152
153 #include <stdio.h>
154
155 #ifndef __STDC__
156 #define const
157 #endif
158
159
160
161 #define YYFINAL 185
162 #define YYFLAG -32768
163 #define YYNTBASE 63
164
165 #define YYTRANSLATE(x) ((unsigned)(x) <= 293 ? yytranslate[x] : 81)
166
167 static const char yytranslate[] = { 0,
168 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
169 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
170 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
171 2, 2, 56, 2, 2, 2, 48, 34, 2, 55,
172 59, 46, 44, 26, 45, 53, 47, 2, 2, 2,
173 2, 2, 2, 2, 2, 2, 2, 62, 2, 37,
174 28, 38, 29, 43, 2, 2, 2, 2, 2, 2,
175 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
176 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
177 54, 2, 58, 33, 2, 2, 2, 2, 2, 2,
178 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
179 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
180 2, 2, 60, 32, 61, 57, 2, 2, 2, 2,
181 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
182 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
183 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
184 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
185 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
186 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
187 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
188 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
189 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
190 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
191 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
193 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
194 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
195 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
196 27, 30, 31, 35, 36, 39, 40, 41, 42, 49,
197 50, 51, 52
198 };
199
200 static const short yyrline[] = { 0,
201 190, 194, 195, 200, 203, 206, 210, 214, 218, 222,
202 226, 230, 234, 238, 244, 248, 254, 258, 262, 266,
203 272, 275, 279, 283, 289, 295, 301, 305, 309, 313,
204 317, 321, 325, 329, 333, 337, 341, 345, 349, 353,
205 357, 361, 365, 369, 373, 377, 381, 385, 391, 401,
206 413, 420, 427, 430, 436, 442, 448, 455, 462, 469,
207 490, 499, 510, 523, 569, 646, 647, 682, 684, 686,
208 689, 691, 696, 702, 704, 708, 710, 714, 718, 719,
209 721, 723, 726, 733, 736, 738, 740, 742, 744, 746,
210 748, 750, 753, 756, 759, 761, 763, 766, 770, 771,
211 776, 781, 789, 794, 801, 802, 803, 806, 807
212 };
213
214 static const char * const yytname[] = { 0,
215 "error","$illegal.","INT","CHAR","UINT","FLOAT","NAME","TYPENAME","BLOCKNAME","STRING",
216 "STRUCT","UNION","ENUM","SIZEOF","UNSIGNED","COLONCOLON","SIGNED","LONG","SHORT","INT_KEYWORD",
217 "LAST","REGNAME","VARIABLE","ASSIGN_MODIFY","THIS","','","ABOVE_COMMA","'='","'?'","OR",
218 "AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'","'>'","LEQ","GEQ",
219 "LSH","RSH","'@'","'+'","'-'","'*'","'/'","'%'","UNARY","INCREMENT",
220 "DECREMENT","ARROW","'.'","'['","'('","'!'","'~'","']'","')'","'{'",
221 "'}'","':'","start"
222 };
223
224 static const short yyr1[] = { 0,
225 63, 64, 64, 65, 65, 65, 65, 65, 65, 65,
226 65, 65, 65, 65, 65, 65, 65, 65, 66, 65,
227 67, 67, 67, 65, 65, 65, 65, 65, 65, 65,
228 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
229 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
230 65, 65, 65, 65, 65, 65, 65, 65, 65, 68,
231 68, 69, 69, 69, 69, 70, 70, 71, 71, 71,
232 72, 72, 72, 72, 72, 73, 73, 74, 75, 75,
233 75, 75, 75, 76, 76, 76, 76, 76, 76, 76,
234 76, 76, 76, 76, 76, 76, 76, 76, 77, 77,
235 77, 77, 78, 78, 79, 79, 79, 80, 80
236 };
237
238 static const short yyr2[] = { 0,
239 1, 1, 3, 2, 2, 2, 2, 2, 2, 2,
240 2, 2, 2, 3, 4, 3, 4, 4, 0, 5,
241 0, 1, 3, 4, 4, 3, 3, 3, 3, 3,
242 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
243 3, 3, 3, 3, 3, 5, 3, 3, 1, 1,
244 1, 1, 1, 1, 1, 1, 4, 1, 1, 1,
245 3, 3, 3, 2, 1, 1, 2, 1, 2, 1,
246 3, 2, 1, 2, 1, 2, 3, 2, 1, 3,
247 6, 8, 9, 1, 1, 1, 1, 2, 3, 2,
248 3, 2, 2, 2, 2, 1, 2, 1, 1, 1,
249 1, 1, 1, 3, 1, 1, 1, 1, 1
250 };
251
252 static const short yydefact[] = { 0,
253 49, 51, 50, 52, 108, 84, 109, 58, 0, 0,
254 0, 0, 96, 0, 98, 86, 87, 85, 54, 55,
255 56, 59, 0, 0, 0, 0, 0, 0, 0, 0,
256 0, 1, 2, 0, 53, 0, 65, 105, 107, 106,
257 92, 93, 94, 0, 13, 99, 101, 102, 100, 95,
258 64, 101, 102, 97, 88, 90, 5, 6, 4, 9,
259 10, 0, 79, 0, 66, 7, 8, 0, 66, 0,
260 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
261 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
262 0, 0, 11, 12, 0, 0, 0, 19, 0, 0,
263 0, 89, 91, 26, 0, 0, 0, 68, 0, 0,
264 67, 70, 73, 75, 0, 0, 3, 48, 47, 0,
265 45, 44, 43, 42, 41, 35, 36, 39, 40, 37,
266 38, 33, 34, 27, 31, 32, 28, 29, 30, 0,
267 14, 0, 16, 0, 21, 62, 63, 57, 0, 25,
268 80, 69, 0, 76, 78, 0, 0, 72, 74, 24,
269 0, 15, 17, 18, 22, 0, 0, 77, 71, 46,
270 0, 20, 0, 23, 81, 0, 82, 103, 0, 0,
271 83, 104, 0, 0, 0
272 };
273
274 static const short yydefgoto[] = { 183,
275 62, 33, 145, 166, 34, 35, 63, 111, 112, 113,
276 114, 64, 36, 50, 179, 147, 37
277 };
278
279 static const short yypact[] = { 157,
280 -32768,-32768,-32768,-32768,-32768,-32768, -13,-32768, 105, 105,
281 105, 215, 82, 105, 178, -10, -4,-32768,-32768,-32768,
282 -32768,-32768, 157, 157, 157, 157, 157, 157, 157, 157,
283 239, 6, 284, 75,-32768, 79,-32768,-32768,-32768,-32768,
284 -32768,-32768,-32768, 157, 501,-32768, 66, 84,-32768,-32768,
285 -32768,-32768,-32768,-32768,-32768,-32768, 501, 501, 501, 501,
286 501, 67,-32768, -50, 69, 501, 501, -53, 138, 157,
287 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
288 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
289 157, 157,-32768,-32768, 111, 197, 157,-32768, 105, 105,
290 -28,-32768,-32768,-32768, 239, 157, 202, -21, 26, 51,
291 -32768, 62,-32768,-32768, 157, 63, 284, 284, 284, 249,
292 336, 360, 383, 405, 426, 445, 445, 460, 460, 460,
293 460, 473, 473, 485, 495, 495, 501, 501, 501, 157,
294 -32768, 157,-32768, -2, 157, 106,-32768, 32, 109, 501,
295 -32768,-32768, 77,-32768,-32768, 68, 72,-32768,-32768, 501,
296 157, 501, 501,-32768, 284, 70, 94,-32768,-32768, 311,
297 157,-32768, 83, 284, 92, 126,-32768, 93, 73, 239,
298 -32768, 93, 121, 150,-32768
299 };
300
301 static const short yypgoto[] = {-32768,
302 1, -12,-32768,-32768,-32768,-32768,-32768, -80,-32768, 41,
303 46, -25, -24, 166,-32768, 12,-32768
304 };
305
306
307 #define YYLAST 556
308
309
310 static const short yytable[] = { 45,
311 32, 105, -60, 65, 105, 68, 69, 115, 106, 55,
312 57, 58, 59, 60, 61, 56, 66, 67, 101, 65,
313 41, 42, 43, 70, 108, 51, 105, 152, 153, 156,
314 148, 70, 109, 110, 1, 2, 3, 4, 5, 6,
315 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
316 17, 18, 19, 20, 21, 164, 22, 117, 118, 119,
317 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
318 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
319 149, 26, 27, 154, 107, 102, 28, 29, 30, 46,
320 99, 31, 70, 150, 100, 171, 108, 144, 180, 47,
321 48, 49, 160, 103, 109, 110, 141, 143, 151, 155,
322 146, 38, 39, 40, 108, 109, 157, 38, 39, 40,
323 184, -61, 109, 110, 167, 104, 169, 162, 172, 163,
324 155, 181, 165, 6, 168, 150, 9, 10, 11, 173,
325 13, 175, 15, 16, 17, 18, 176, 105, 170, 185,
326 178, 69, 158, 116, 182, 69, 140, 159, 174, 1,
327 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
328 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
329 54, 22, 0, 108, 177, 46, 0, 0, 0, 0,
330 23, 109, 110, 0, 0, 52, 53, 49, 0, 0,
331 0, 24, 25, 38, 39, 40, 26, 27, 38, 39,
332 40, 28, 29, 30, 0, 0, 31, 1, 2, 3,
333 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
334 14, 15, 16, 17, 18, 19, 20, 21, 0, 22,
335 0, 0, 142, 0, 0, 0, 6, 151, 23, 9,
336 10, 11, 0, 13, 0, 15, 16, 17, 18, 24,
337 25, 0, 0, 0, 26, 27, 0, 0, 0, 44,
338 29, 30, 71, 0, 31, 0, 72, 73, 74, 75,
339 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
340 86, 87, 88, 89, 90, 91, 92, 0, 93, 94,
341 95, 96, 97, 98, 0, 0, 0, 71, 0, 0,
342 161, 72, 73, 74, 75, 76, 77, 78, 79, 80,
343 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
344 91, 92, 0, 93, 94, 95, 96, 97, 98, 73,
345 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
346 84, 85, 86, 87, 88, 89, 90, 91, 92, 0,
347 93, 94, 95, 96, 97, 98, 75, 76, 77, 78,
348 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
349 89, 90, 91, 92, 0, 93, 94, 95, 96, 97,
350 98, 76, 77, 78, 79, 80, 81, 82, 83, 84,
351 85, 86, 87, 88, 89, 90, 91, 92, 0, 93,
352 94, 95, 96, 97, 98, 77, 78, 79, 80, 81,
353 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
354 92, 0, 93, 94, 95, 96, 97, 98, 78, 79,
355 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
356 90, 91, 92, 0, 93, 94, 95, 96, 97, 98,
357 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
358 89, 90, 91, 92, 0, 93, 94, 95, 96, 97,
359 98, 81, 82, 83, 84, 85, 86, 87, 88, 89,
360 90, 91, 92, 0, 93, 94, 95, 96, 97, 98,
361 85, 86, 87, 88, 89, 90, 91, 92, 0, 93,
362 94, 95, 96, 97, 98, 87, 88, 89, 90, 91,
363 92, 0, 93, 94, 95, 96, 97, 98, 88, 89,
364 90, 91, 92, 0, 93, 94, 95, 96, 97, 98,
365 90, 91, 92, 0, 93, 94, 95, 96, 97, 98,
366 93, 94, 95, 96, 97, 98
367 };
368
369 static const short yycheck[] = { 12,
370 0, 55, 16, 28, 55, 31, 31, 61, 59, 20,
371 23, 24, 25, 26, 27, 20, 29, 30, 44, 44,
372 9, 10, 11, 26, 46, 14, 55, 108, 3, 110,
373 59, 26, 54, 55, 3, 4, 5, 6, 7, 8,
374 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
375 19, 20, 21, 22, 23, 58, 25, 70, 71, 72,
376 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
377 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
378 105, 50, 51, 58, 16, 20, 55, 56, 57, 8,
379 16, 60, 26, 106, 16, 26, 46, 97, 26, 18,
380 19, 20, 115, 20, 54, 55, 95, 96, 46, 59,
381 99, 7, 8, 9, 46, 54, 55, 7, 8, 9,
382 0, 16, 54, 55, 16, 59, 59, 140, 59, 142,
383 59, 59, 145, 8, 58, 148, 11, 12, 13, 46,
384 15, 59, 17, 18, 19, 20, 55, 55, 161, 0,
385 176, 176, 112, 16, 180, 180, 46, 112, 171, 3,
386 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
387 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
388 15, 25, -1, 46, 59, 8, -1, -1, -1, -1,
389 34, 54, 55, -1, -1, 18, 19, 20, -1, -1,
390 -1, 45, 46, 7, 8, 9, 50, 51, 7, 8,
391 9, 55, 56, 57, -1, -1, 60, 3, 4, 5,
392 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
393 16, 17, 18, 19, 20, 21, 22, 23, -1, 25,
394 -1, -1, 46, -1, -1, -1, 8, 46, 34, 11,
395 12, 13, -1, 15, -1, 17, 18, 19, 20, 45,
396 46, -1, -1, -1, 50, 51, -1, -1, -1, 55,
397 56, 57, 24, -1, 60, -1, 28, 29, 30, 31,
398 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
399 42, 43, 44, 45, 46, 47, 48, -1, 50, 51,
400 52, 53, 54, 55, -1, -1, -1, 24, -1, -1,
401 62, 28, 29, 30, 31, 32, 33, 34, 35, 36,
402 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
403 47, 48, -1, 50, 51, 52, 53, 54, 55, 29,
404 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
405 40, 41, 42, 43, 44, 45, 46, 47, 48, -1,
406 50, 51, 52, 53, 54, 55, 31, 32, 33, 34,
407 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
408 45, 46, 47, 48, -1, 50, 51, 52, 53, 54,
409 55, 32, 33, 34, 35, 36, 37, 38, 39, 40,
410 41, 42, 43, 44, 45, 46, 47, 48, -1, 50,
411 51, 52, 53, 54, 55, 33, 34, 35, 36, 37,
412 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
413 48, -1, 50, 51, 52, 53, 54, 55, 34, 35,
414 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
415 46, 47, 48, -1, 50, 51, 52, 53, 54, 55,
416 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
417 45, 46, 47, 48, -1, 50, 51, 52, 53, 54,
418 55, 37, 38, 39, 40, 41, 42, 43, 44, 45,
419 46, 47, 48, -1, 50, 51, 52, 53, 54, 55,
420 41, 42, 43, 44, 45, 46, 47, 48, -1, 50,
421 51, 52, 53, 54, 55, 43, 44, 45, 46, 47,
422 48, -1, 50, 51, 52, 53, 54, 55, 44, 45,
423 46, 47, 48, -1, 50, 51, 52, 53, 54, 55,
424 46, 47, 48, -1, 50, 51, 52, 53, 54, 55,
425 50, 51, 52, 53, 54, 55
426 };
427 #define YYPURE 1
428
429 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
430 #line 3 "bison.simple"
431
432 /* Skeleton output parser for bison,
433 Copyright (C) 1984 Bob Corbett and Richard Stallman
434
435 This program is free software; you can redistribute it and/or modify
436 it under the terms of the GNU General Public License as published by
437 the Free Software Foundation; either version 1, or (at your option)
438 any later version.
439
440 This program is distributed in the hope that it will be useful,
441 but WITHOUT ANY WARRANTY; without even the implied warranty of
442 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
443 GNU General Public License for more details.
444
445 You should have received a copy of the GNU General Public License
446 along with this program; if not, write to the Free Software
447 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
448
449
450 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
451 #include <alloca.h>
452 #endif
453
454 /* This is the parser code that is written into each bison parser
455 when the %semantic_parser declaration is not specified in the grammar.
456 It was written by Richard Stallman by simplifying the hairy parser
457 used when %semantic_parser is specified. */
458
459 /* Note: there must be only one dollar sign in this file.
460 It is replaced by the list of actions, each action
461 as one case of the switch. */
462
463 #define yyerrok (yyerrstatus = 0)
464 #define yyclearin (yychar = YYEMPTY)
465 #define YYEMPTY -2
466 #define YYEOF 0
467 #define YYFAIL goto yyerrlab;
468 #define YYACCEPT return(0)
469 #define YYABORT return(1)
470 #define YYERROR goto yyerrlab
471
472 #define YYTERROR 1
473 #define YYERRCODE 256
474
475 #ifndef YYIMPURE
476 #define YYLEX yylex()
477 #endif
478
479 #ifndef YYPURE
480 #define YYLEX yylex(&yylval, &yylloc)
481 #endif
482
483 /* If nonreentrant, generate the variables here */
484
485 #ifndef YYIMPURE
486
487 int yychar; /* the lookahead symbol */
488 YYSTYPE yylval; /* the semantic value of the */
489 /* lookahead symbol */
490
491 YYLTYPE yylloc; /* location data for the lookahead */
492 /* symbol */
493
494 int yynerrs; /* number of parse errors so far */
495 #endif /* YYIMPURE */
496
497 #if YYDEBUG != 0
498 int yydebug; /* nonzero means print parse trace */
499 /* Since this is uninitialized, it does not stop multiple parsers
500 from coexisting. */
501 #endif
502
503 /* YYMAXDEPTH indicates the initial size of the parser's stacks */
504
505 #ifndef YYMAXDEPTH
506 #define YYMAXDEPTH 200
507 #endif
508
509 /* YYMAXLIMIT is the maximum size the stacks can grow to
510 (effective only if the built-in stack extension method is used). */
511
512 #ifndef YYMAXLIMIT
513 #define YYMAXLIMIT 10000
514 #endif
515
516
517 #line 90 "bison.simple"
518 int
519 yyparse()
520 {
521 register int yystate;
522 register int yyn;
523 register short *yyssp;
524 register YYSTYPE *yyvsp;
525 YYLTYPE *yylsp;
526 int yyerrstatus; /* number of tokens to shift before error messages enabled */
527 int yychar1; /* lookahead token as an internal (translated) token number */
528
529 short yyssa[YYMAXDEPTH]; /* the state stack */
530 YYSTYPE yyvsa[YYMAXDEPTH]; /* the semantic value stack */
531 YYLTYPE yylsa[YYMAXDEPTH]; /* the location stack */
532
533 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
534 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
535 YYLTYPE *yyls = yylsa;
536
537 int yymaxdepth = YYMAXDEPTH;
538
539 #ifndef YYPURE
540 int yychar;
541 YYSTYPE yylval;
542 YYLTYPE yylloc;
543 int yynerrs;
544 #endif
545
546 YYSTYPE yyval; /* the variable used to return */
547 /* semantic values from the action */
548 /* routines */
549
550 int yylen;
551 void yyerror();
552 void bcopy();
553 int yylex();
554
555 #if YYDEBUG != 0
556 if (yydebug)
557 fprintf(stderr, "Starting parse\n");
558 #endif
559
560 yystate = 0;
561 yyerrstatus = 0;
562 yynerrs = 0;
563 yychar = YYEMPTY; /* Cause a token to be read. */
564
565 /* Initialize stack pointers.
566 Waste one element of value and location stack
567 so that they stay on the same level as the state stack. */
568
569 yyssp = yyss - 1;
570 yyvsp = yyvs;
571 yylsp = yyls;
572
573 /* Push a new state, which is found in yystate . */
574 /* In all cases, when you get here, the value and location stacks
575 have just been pushed. so pushing a state here evens the stacks. */
576 yynewstate:
577
578 *++yyssp = yystate;
579
580 if (yyssp >= yyss + yymaxdepth - 1)
581 {
582 /* Give user a chance to reallocate the stack */
583 /* Use copies of these so that the &'s don't force the real ones into memory. */
584 YYSTYPE *yyvs1 = yyvs;
585 #if defined(yyoverflow) || defined(YYLSP_NEEDED)
586 YYLTYPE *yyls1 = yyls;
587 #endif
588 short *yyss1 = yyss;
589
590 /* Get the current used size of the three stacks, in elements. */
591 int size = yyssp - yyss + 1;
592
593 #ifdef yyoverflow
594 /* Each stack pointer address is followed by the size of
595 the data in use in that stack, in bytes. */
596 yyoverflow("parser stack overflow",
597 &yyss1, size * sizeof (*yyssp),
598 &yyvs1, size * sizeof (*yyvsp),
599 &yyls1, size * sizeof (*yylsp),
600 &yymaxdepth);
601
602 yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
603 #else /* no yyoverflow */
604 /* Extend the stack our own way. */
605 if (yymaxdepth >= YYMAXLIMIT)
606 yyerror("parser stack overflow");
607 yymaxdepth *= 2;
608 if (yymaxdepth > YYMAXLIMIT)
609 yymaxdepth = YYMAXLIMIT;
610 yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
611 bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
612 yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
613 bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
614 #ifdef YYLSP_NEEDED
615 yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
616 bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
617 #endif
618 #endif /* no yyoverflow */
619
620 yyssp = yyss + size - 1;
621 yyvsp = yyvs + size - 1;
622 #ifdef YYLSP_NEEDED
623 yylsp = yyls + size - 1;
624 #endif
625
626 #if YYDEBUG != 0
627 if (yydebug)
628 fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
629 #endif
630
631 if (yyssp >= yyss + yymaxdepth - 1)
632 YYABORT;
633 }
634
635 #if YYDEBUG != 0
636 if (yydebug)
637 fprintf(stderr, "Entering state %d\n", yystate);
638 #endif
639
640 /* Do appropriate processing given the current state. */
641 /* Read a lookahead token if we need one and don't already have one. */
642
643 /* First try to decide what to do without reference to lookahead token. */
644
645 yyn = yypact[yystate];
646 if (yyn == YYFLAG)
647 goto yydefault;
648
649 /* Not known => get a lookahead token if don't already have one. */
650
651 /* yychar is either YYEMPTY or YYEOF
652 or a valid token in external form. */
653
654 if (yychar == YYEMPTY)
655 {
656 #if YYDEBUG != 0
657 if (yydebug)
658 fprintf(stderr, "Reading a token: ");
659 #endif
660 yychar = YYLEX;
661 }
662
663 /* Convert token to internal form (in yychar1) for indexing tables with */
664
665 if (yychar <= 0) /* This means end of input. */
666 {
667 yychar1 = 0;
668 yychar = YYEOF; /* Don't call YYLEX any more */
669
670 #if YYDEBUG != 0
671 if (yydebug)
672 fprintf(stderr, "Now at end of input.\n");
673 #endif
674 }
675 else
676 {
677 yychar1 = YYTRANSLATE(yychar);
678
679 #if YYDEBUG != 0
680 if (yydebug)
681 fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
682 #endif
683 }
684
685 yyn += yychar1;
686 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
687 goto yydefault;
688
689 yyn = yytable[yyn];
690
691 /* yyn is what to do for this token type in this state.
692 Negative => reduce, -yyn is rule number.
693 Positive => shift, yyn is new state.
694 New state is final state => don't bother to shift,
695 just return success.
696 0, or most negative number => error. */
697
698 if (yyn < 0)
699 {
700 if (yyn == YYFLAG)
701 goto yyerrlab;
702 yyn = -yyn;
703 goto yyreduce;
704 }
705 else if (yyn == 0)
706 goto yyerrlab;
707
708 if (yyn == YYFINAL)
709 YYACCEPT;
710
711 /* Shift the lookahead token. */
712
713 #if YYDEBUG != 0
714 if (yydebug)
715 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
716 #endif
717
718 /* Discard the token being shifted unless it is eof. */
719 if (yychar != YYEOF)
720 yychar = YYEMPTY;
721
722 *++yyvsp = yylval;
723 #ifdef YYLSP_NEEDED
724 *++yylsp = yylloc;
725 #endif
726
727 /* count tokens shifted since error; after three, turn off error status. */
728 if (yyerrstatus) yyerrstatus--;
729
730 yystate = yyn;
731 goto yynewstate;
732
733 /* Do the default action for the current state. */
734 yydefault:
735
736 yyn = yydefact[yystate];
737 if (yyn == 0)
738 goto yyerrlab;
739
740 /* Do a reduction. yyn is the number of a rule to reduce with. */
741 yyreduce:
742 yylen = yyr2[yyn];
743 yyval = yyvsp[1-yylen]; /* implement default value of the action */
744
745 #if YYDEBUG != 0
746 if (yydebug)
747 {
748 if (yylen == 1)
749 fprintf (stderr, "Reducing 1 value via line %d, ",
750 yyrline[yyn]);
751 else
752 fprintf (stderr, "Reducing %d values via line %d, ",
753 yylen, yyrline[yyn]);
754 }
755 #endif
756
757
758 switch (yyn) {
759
760 case 3:
761 #line 196 "expread.y"
762 { write_exp_elt_opcode (BINOP_COMMA); ;
763 break;}
764 case 4:
765 #line 201 "expread.y"
766 { write_exp_elt_opcode (UNOP_IND); ;
767 break;}
768 case 5:
769 #line 204 "expread.y"
770 { write_exp_elt_opcode (UNOP_ADDR); ;
771 break;}
772 case 6:
773 #line 207 "expread.y"
774 { write_exp_elt_opcode (UNOP_NEG); ;
775 break;}
776 case 7:
777 #line 211 "expread.y"
778 { write_exp_elt_opcode (UNOP_ZEROP); ;
779 break;}
780 case 8:
781 #line 215 "expread.y"
782 { write_exp_elt_opcode (UNOP_LOGNOT); ;
783 break;}
784 case 9:
785 #line 219 "expread.y"
786 { write_exp_elt_opcode (UNOP_PREINCREMENT); ;
787 break;}
788 case 10:
789 #line 223 "expread.y"
790 { write_exp_elt_opcode (UNOP_PREDECREMENT); ;
791 break;}
792 case 11:
793 #line 227 "expread.y"
794 { write_exp_elt_opcode (UNOP_POSTINCREMENT); ;
795 break;}
796 case 12:
797 #line 231 "expread.y"
798 { write_exp_elt_opcode (UNOP_POSTDECREMENT); ;
799 break;}
800 case 13:
801 #line 235 "expread.y"
802 { write_exp_elt_opcode (UNOP_SIZEOF); ;
803 break;}
804 case 14:
805 #line 239 "expread.y"
806 { write_exp_elt_opcode (STRUCTOP_PTR);
807 write_exp_string (yyvsp[0].sval);
808 write_exp_elt_opcode (STRUCTOP_PTR); ;
809 break;}
810 case 15:
811 #line 245 "expread.y"
812 { write_exp_elt_opcode (STRUCTOP_MPTR); ;
813 break;}
814 case 16:
815 #line 249 "expread.y"
816 { write_exp_elt_opcode (STRUCTOP_STRUCT);
817 write_exp_string (yyvsp[0].sval);
818 write_exp_elt_opcode (STRUCTOP_STRUCT); ;
819 break;}
820 case 17:
821 #line 255 "expread.y"
822 { write_exp_elt_opcode (STRUCTOP_MEMBER); ;
823 break;}
824 case 18:
825 #line 259 "expread.y"
826 { write_exp_elt_opcode (BINOP_SUBSCRIPT); ;
827 break;}
828 case 19:
829 #line 265 "expread.y"
830 { start_arglist (); ;
831 break;}
832 case 20:
833 #line 267 "expread.y"
834 { write_exp_elt_opcode (OP_FUNCALL);
835 write_exp_elt_longcst ((LONGEST) end_arglist ());
836 write_exp_elt_opcode (OP_FUNCALL); ;
837 break;}
838 case 22:
839 #line 276 "expread.y"
840 { arglist_len = 1; ;
841 break;}
842 case 23:
843 #line 280 "expread.y"
844 { arglist_len++; ;
845 break;}
846 case 24:
847 #line 284 "expread.y"
848 { write_exp_elt_opcode (UNOP_MEMVAL);
849 write_exp_elt_type (yyvsp[-2].tval);
850 write_exp_elt_opcode (UNOP_MEMVAL); ;
851 break;}
852 case 25:
853 #line 290 "expread.y"
854 { write_exp_elt_opcode (UNOP_CAST);
855 write_exp_elt_type (yyvsp[-2].tval);
856 write_exp_elt_opcode (UNOP_CAST); ;
857 break;}
858 case 26:
859 #line 296 "expread.y"
860 { ;
861 break;}
862 case 27:
863 #line 302 "expread.y"
864 { write_exp_elt_opcode (BINOP_REPEAT); ;
865 break;}
866 case 28:
867 #line 306 "expread.y"
868 { write_exp_elt_opcode (BINOP_MUL); ;
869 break;}
870 case 29:
871 #line 310 "expread.y"
872 { write_exp_elt_opcode (BINOP_DIV); ;
873 break;}
874 case 30:
875 #line 314 "expread.y"
876 { write_exp_elt_opcode (BINOP_REM); ;
877 break;}
878 case 31:
879 #line 318 "expread.y"
880 { write_exp_elt_opcode (BINOP_ADD); ;
881 break;}
882 case 32:
883 #line 322 "expread.y"
884 { write_exp_elt_opcode (BINOP_SUB); ;
885 break;}
886 case 33:
887 #line 326 "expread.y"
888 { write_exp_elt_opcode (BINOP_LSH); ;
889 break;}
890 case 34:
891 #line 330 "expread.y"
892 { write_exp_elt_opcode (BINOP_RSH); ;
893 break;}
894 case 35:
895 #line 334 "expread.y"
896 { write_exp_elt_opcode (BINOP_EQUAL); ;
897 break;}
898 case 36:
899 #line 338 "expread.y"
900 { write_exp_elt_opcode (BINOP_NOTEQUAL); ;
901 break;}
902 case 37:
903 #line 342 "expread.y"
904 { write_exp_elt_opcode (BINOP_LEQ); ;
905 break;}
906 case 38:
907 #line 346 "expread.y"
908 { write_exp_elt_opcode (BINOP_GEQ); ;
909 break;}
910 case 39:
911 #line 350 "expread.y"
912 { write_exp_elt_opcode (BINOP_LESS); ;
913 break;}
914 case 40:
915 #line 354 "expread.y"
916 { write_exp_elt_opcode (BINOP_GTR); ;
917 break;}
918 case 41:
919 #line 358 "expread.y"
920 { write_exp_elt_opcode (BINOP_LOGAND); ;
921 break;}
922 case 42:
923 #line 362 "expread.y"
924 { write_exp_elt_opcode (BINOP_LOGXOR); ;
925 break;}
926 case 43:
927 #line 366 "expread.y"
928 { write_exp_elt_opcode (BINOP_LOGIOR); ;
929 break;}
930 case 44:
931 #line 370 "expread.y"
932 { write_exp_elt_opcode (BINOP_AND); ;
933 break;}
934 case 45:
935 #line 374 "expread.y"
936 { write_exp_elt_opcode (BINOP_OR); ;
937 break;}
938 case 46:
939 #line 378 "expread.y"
940 { write_exp_elt_opcode (TERNOP_COND); ;
941 break;}
942 case 47:
943 #line 382 "expread.y"
944 { write_exp_elt_opcode (BINOP_ASSIGN); ;
945 break;}
946 case 48:
947 #line 386 "expread.y"
948 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
949 write_exp_elt_opcode (yyvsp[-1].opcode);
950 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); ;
951 break;}
952 case 49:
953 #line 392 "expread.y"
954 { write_exp_elt_opcode (OP_LONG);
955 if (yyvsp[0].lval == (int) yyvsp[0].lval || yyvsp[0].lval == (unsigned int) yyvsp[0].lval)
956 write_exp_elt_type (builtin_type_int);
957 else
958 write_exp_elt_type (BUILTIN_TYPE_LONGEST);
959 write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
960 write_exp_elt_opcode (OP_LONG); ;
961 break;}
962 case 50:
963 #line 402 "expread.y"
964 {
965 write_exp_elt_opcode (OP_LONG);
966 if (yyvsp[0].ulval == (unsigned int) yyvsp[0].ulval)
967 write_exp_elt_type (builtin_type_unsigned_int);
968 else
969 write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST);
970 write_exp_elt_longcst ((LONGEST) yyvsp[0].ulval);
971 write_exp_elt_opcode (OP_LONG);
972 ;
973 break;}
974 case 51:
975 #line 414 "expread.y"
976 { write_exp_elt_opcode (OP_LONG);
977 write_exp_elt_type (builtin_type_char);
978 write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
979 write_exp_elt_opcode (OP_LONG); ;
980 break;}
981 case 52:
982 #line 421 "expread.y"
983 { write_exp_elt_opcode (OP_DOUBLE);
984 write_exp_elt_type (builtin_type_double);
985 write_exp_elt_dblcst (yyvsp[0].dval);
986 write_exp_elt_opcode (OP_DOUBLE); ;
987 break;}
988 case 54:
989 #line 431 "expread.y"
990 { write_exp_elt_opcode (OP_LAST);
991 write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
992 write_exp_elt_opcode (OP_LAST); ;
993 break;}
994 case 55:
995 #line 437 "expread.y"
996 { write_exp_elt_opcode (OP_REGISTER);
997 write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
998 write_exp_elt_opcode (OP_REGISTER); ;
999 break;}
1000 case 56:
1001 #line 443 "expread.y"
1002 { write_exp_elt_opcode (OP_INTERNALVAR);
1003 write_exp_elt_intern (yyvsp[0].ivar);
1004 write_exp_elt_opcode (OP_INTERNALVAR); ;
1005 break;}
1006 case 57:
1007 #line 449 "expread.y"
1008 { write_exp_elt_opcode (OP_LONG);
1009 write_exp_elt_type (builtin_type_int);
1010 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH (yyvsp[-1].tval));
1011 write_exp_elt_opcode (OP_LONG); ;
1012 break;}
1013 case 58:
1014 #line 456 "expread.y"
1015 { write_exp_elt_opcode (OP_STRING);
1016 write_exp_string (yyvsp[0].sval);
1017 write_exp_elt_opcode (OP_STRING); ;
1018 break;}
1019 case 59:
1020 #line 463 "expread.y"
1021 { write_exp_elt_opcode (OP_THIS);
1022 write_exp_elt_opcode (OP_THIS); ;
1023 break;}
1024 case 60:
1025 #line 470 "expread.y"
1026 {
1027 struct symtab *tem = lookup_symtab (copy_name (yyvsp[0].sval));
1028 struct symbol *sym;
1029
1030 if (tem)
1031 yyval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), 1);
1032 else
1033 {
1034 sym = lookup_symbol (copy_name (yyvsp[0].sval),
1035 expression_context_block,
1036 VAR_NAMESPACE, 0);
1037 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1038 yyval.bval = SYMBOL_BLOCK_VALUE (sym);
1039 else
1040 error ("No file or function \"%s\".",
1041 copy_name (yyvsp[0].sval));
1042 }
1043 ;
1044 break;}
1045 case 61:
1046 #line 491 "expread.y"
1047 { struct symbol *tem
1048 = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, VAR_NAMESPACE, 0);
1049 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
1050 error ("No function \"%s\" in specified context.",
1051 copy_name (yyvsp[0].sval));
1052 yyval.bval = SYMBOL_BLOCK_VALUE (tem); ;
1053 break;}
1054 case 62:
1055 #line 500 "expread.y"
1056 { struct symbol *sym;
1057 sym = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, VAR_NAMESPACE, 0);
1058 if (sym == 0)
1059 error ("No symbol \"%s\" in specified context.",
1060 copy_name (yyvsp[0].sval));
1061 write_exp_elt_opcode (OP_VAR_VALUE);
1062 write_exp_elt_sym (sym);
1063 write_exp_elt_opcode (OP_VAR_VALUE); ;
1064 break;}
1065 case 63:
1066 #line 511 "expread.y"
1067 {
1068 struct type *type = yyvsp[-2].tval;
1069 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1070 && TYPE_CODE (type) != TYPE_CODE_UNION)
1071 error ("`%s' is not defined as an aggregate type.",
1072 TYPE_NAME (type));
1073
1074 write_exp_elt_opcode (OP_SCOPE);
1075 write_exp_elt_type (type);
1076 write_exp_string (yyvsp[0].sval);
1077 write_exp_elt_opcode (OP_SCOPE);
1078 ;
1079 break;}
1080 case 64:
1081 #line 524 "expread.y"
1082 {
1083 char *name = copy_name (yyvsp[0].sval);
1084 struct symbol *sym;
1085 int i;
1086
1087 sym = lookup_symbol (name, 0, VAR_NAMESPACE, 0);
1088 if (sym)
1089 {
1090 write_exp_elt_opcode (OP_VAR_VALUE);
1091 write_exp_elt_sym (sym);
1092 write_exp_elt_opcode (OP_VAR_VALUE);
1093 break;
1094 }
1095 for (i = 0; i < misc_function_count; i++)
1096 if (!strcmp (misc_function_vector[i].name, name))
1097 break;
1098
1099 if (i < misc_function_count)
1100 {
1101 enum misc_function_type mft =
1102 (enum misc_function_type)
1103 misc_function_vector[i].type;
1104
1105 write_exp_elt_opcode (OP_LONG);
1106 write_exp_elt_type (builtin_type_int);
1107 write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
1108 write_exp_elt_opcode (OP_LONG);
1109 write_exp_elt_opcode (UNOP_MEMVAL);
1110 if (mft == mf_data || mft == mf_bss)
1111 write_exp_elt_type (builtin_type_int);
1112 else if (mft == mf_text)
1113 write_exp_elt_type (lookup_function_type (builtin_type_int));
1114 else
1115 write_exp_elt_type (builtin_type_char);
1116 write_exp_elt_opcode (UNOP_MEMVAL);
1117 }
1118 else
1119 if (symtab_list == 0
1120 && partial_symtab_list == 0)
1121 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1122 else
1123 error ("No symbol \"%s\" in current context.", name);
1124 ;
1125 break;}
1126 case 65:
1127 #line 570 "expread.y"
1128 { struct symbol *sym;
1129 int is_a_field_of_this;
1130
1131 sym = lookup_symbol (copy_name (yyvsp[0].sval),
1132 expression_context_block,
1133 VAR_NAMESPACE,
1134 &is_a_field_of_this);
1135 if (sym)
1136 {
1137 switch (sym->class)
1138 {
1139 case LOC_REGISTER:
1140 case LOC_ARG:
1141 case LOC_LOCAL:
1142 if (innermost_block == 0 ||
1143 contained_in (block_found,
1144 innermost_block))
1145 innermost_block = block_found;
1146 }
1147 write_exp_elt_opcode (OP_VAR_VALUE);
1148 write_exp_elt_sym (sym);
1149 write_exp_elt_opcode (OP_VAR_VALUE);
1150 }
1151 else if (is_a_field_of_this)
1152 {
1153 /* C++: it hangs off of `this'. Must
1154 not inadvertently convert from a method call
1155 to data ref. */
1156 if (innermost_block == 0 ||
1157 contained_in (block_found, innermost_block))
1158 innermost_block = block_found;
1159 write_exp_elt_opcode (OP_THIS);
1160 write_exp_elt_opcode (OP_THIS);
1161 write_exp_elt_opcode (STRUCTOP_PTR);
1162 write_exp_string (yyvsp[0].sval);
1163 write_exp_elt_opcode (STRUCTOP_PTR);
1164 }
1165 else
1166 {
1167 register int i;
1168 register char *arg = copy_name (yyvsp[0].sval);
1169
1170 for (i = 0; i < misc_function_count; i++)
1171 if (!strcmp (misc_function_vector[i].name, arg))
1172 break;
1173
1174 if (i < misc_function_count)
1175 {
1176 enum misc_function_type mft =
1177 (enum misc_function_type)
1178 misc_function_vector[i].type;
1179
1180 write_exp_elt_opcode (OP_LONG);
1181 write_exp_elt_type (builtin_type_int);
1182 write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
1183 write_exp_elt_opcode (OP_LONG);
1184 write_exp_elt_opcode (UNOP_MEMVAL);
1185 if (mft == mf_data || mft == mf_bss)
1186 write_exp_elt_type (builtin_type_int);
1187 else if (mft == mf_text)
1188 write_exp_elt_type (lookup_function_type (builtin_type_int));
1189 else
1190 write_exp_elt_type (builtin_type_char);
1191 write_exp_elt_opcode (UNOP_MEMVAL);
1192 }
1193 else if (symtab_list == 0
1194 && partial_symtab_list == 0)
1195 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1196 else
1197 error ("No symbol \"%s\" in current context.",
1198 copy_name (yyvsp[0].sval));
1199 }
1200 ;
1201 break;}
1202 case 67:
1203 #line 648 "expread.y"
1204 {
1205 /* This is where the interesting stuff happens. */
1206 int done = 0;
1207 int array_size;
1208 struct type *follow_type = yyvsp[-1].tval;
1209
1210 while (!done)
1211 switch (pop_type ())
1212 {
1213 case tp_end:
1214 done = 1;
1215 break;
1216 case tp_pointer:
1217 follow_type = lookup_pointer_type (follow_type);
1218 break;
1219 case tp_reference:
1220 follow_type = lookup_reference_type (follow_type);
1221 break;
1222 case tp_array:
1223 array_size = (int) pop_type ();
1224 if (array_size != -1)
1225 follow_type = create_array_type (follow_type,
1226 array_size);
1227 else
1228 follow_type = lookup_pointer_type (follow_type);
1229 break;
1230 case tp_function:
1231 follow_type = lookup_function_type (follow_type);
1232 break;
1233 }
1234 yyval.tval = follow_type;
1235 ;
1236 break;}
1237 case 68:
1238 #line 683 "expread.y"
1239 { push_type (tp_pointer); yyval.voidval = 0; ;
1240 break;}
1241 case 69:
1242 #line 685 "expread.y"
1243 { push_type (tp_pointer); yyval.voidval = yyvsp[0].voidval; ;
1244 break;}
1245 case 71:
1246 #line 690 "expread.y"
1247 { yyval.voidval = yyvsp[-1].voidval; ;
1248 break;}
1249 case 72:
1250 #line 692 "expread.y"
1251 {
1252 push_type ((enum type_pieces) yyvsp[0].lval);
1253 push_type (tp_array);
1254 ;
1255 break;}
1256 case 73:
1257 #line 697 "expread.y"
1258 {
1259 push_type ((enum type_pieces) yyvsp[0].lval);
1260 push_type (tp_array);
1261 yyval.voidval = 0;
1262 ;
1263 break;}
1264 case 74:
1265 #line 703 "expread.y"
1266 { push_type (tp_function); ;
1267 break;}
1268 case 75:
1269 #line 705 "expread.y"
1270 { push_type (tp_function); ;
1271 break;}
1272 case 76:
1273 #line 709 "expread.y"
1274 { yyval.lval = -1; ;
1275 break;}
1276 case 77:
1277 #line 711 "expread.y"
1278 { yyval.lval = yyvsp[-1].lval; ;
1279 break;}
1280 case 78:
1281 #line 715 "expread.y"
1282 { yyval.voidval = 0; ;
1283 break;}
1284 case 80:
1285 #line 720 "expread.y"
1286 { yyval.tval = lookup_member_type (builtin_type_int, yyvsp[-2].tval); ;
1287 break;}
1288 case 81:
1289 #line 722 "expread.y"
1290 { yyval.tval = lookup_member_type (yyvsp[-5].tval, yyvsp[-3].tval); ;
1291 break;}
1292 case 82:
1293 #line 724 "expread.y"
1294 { yyval.tval = lookup_member_type
1295 (lookup_function_type (yyvsp[-7].tval), yyvsp[-5].tval); ;
1296 break;}
1297 case 83:
1298 #line 727 "expread.y"
1299 { yyval.tval = lookup_member_type
1300 (lookup_function_type (yyvsp[-8].tval), yyvsp[-6].tval);
1301 free (yyvsp[-1].tvec); ;
1302 break;}
1303 case 84:
1304 #line 734 "expread.y"
1305 { yyval.tval = lookup_typename (copy_name (yyvsp[0].sval),
1306 expression_context_block, 0); ;
1307 break;}
1308 case 85:
1309 #line 737 "expread.y"
1310 { yyval.tval = builtin_type_int; ;
1311 break;}
1312 case 86:
1313 #line 739 "expread.y"
1314 { yyval.tval = builtin_type_long; ;
1315 break;}
1316 case 87:
1317 #line 741 "expread.y"
1318 { yyval.tval = builtin_type_short; ;
1319 break;}
1320 case 88:
1321 #line 743 "expread.y"
1322 { yyval.tval = builtin_type_long; ;
1323 break;}
1324 case 89:
1325 #line 745 "expread.y"
1326 { yyval.tval = builtin_type_unsigned_long; ;
1327 break;}
1328 case 90:
1329 #line 747 "expread.y"
1330 { yyval.tval = builtin_type_short; ;
1331 break;}
1332 case 91:
1333 #line 749 "expread.y"
1334 { yyval.tval = builtin_type_unsigned_short; ;
1335 break;}
1336 case 92:
1337 #line 751 "expread.y"
1338 { yyval.tval = lookup_struct (copy_name (yyvsp[0].sval),
1339 expression_context_block); ;
1340 break;}
1341 case 93:
1342 #line 754 "expread.y"
1343 { yyval.tval = lookup_union (copy_name (yyvsp[0].sval),
1344 expression_context_block); ;
1345 break;}
1346 case 94:
1347 #line 757 "expread.y"
1348 { yyval.tval = lookup_enum (copy_name (yyvsp[0].sval),
1349 expression_context_block); ;
1350 break;}
1351 case 95:
1352 #line 760 "expread.y"
1353 { yyval.tval = lookup_unsigned_typename (copy_name (yyvsp[0].sval)); ;
1354 break;}
1355 case 96:
1356 #line 762 "expread.y"
1357 { yyval.tval = builtin_type_unsigned_int; ;
1358 break;}
1359 case 97:
1360 #line 764 "expread.y"
1361 { yyval.tval = lookup_typename (copy_name (yyvsp[0].sval),
1362 expression_context_block, 0); ;
1363 break;}
1364 case 98:
1365 #line 767 "expread.y"
1366 { yyval.tval = builtin_type_int; ;
1367 break;}
1368 case 100:
1369 #line 772 "expread.y"
1370 {
1371 yyval.sval.ptr = "int";
1372 yyval.sval.length = 3;
1373 ;
1374 break;}
1375 case 101:
1376 #line 777 "expread.y"
1377 {
1378 yyval.sval.ptr = "long";
1379 yyval.sval.length = 4;
1380 ;
1381 break;}
1382 case 102:
1383 #line 782 "expread.y"
1384 {
1385 yyval.sval.ptr = "short";
1386 yyval.sval.length = 5;
1387 ;
1388 break;}
1389 case 103:
1390 #line 790 "expread.y"
1391 { yyval.tvec = (struct type **)xmalloc (sizeof (struct type *) * 2);
1392 yyval.tvec[0] = (struct type *)0;
1393 yyval.tvec[1] = yyvsp[0].tval;
1394 ;
1395 break;}
1396 case 104:
1397 #line 795 "expread.y"
1398 { int len = sizeof (struct type *) * ++(yyvsp[-2].ivec[0]);
1399 yyval.tvec = (struct type **)xrealloc (yyvsp[-2].tvec, len);
1400 yyval.tvec[yyval.ivec[0]] = yyvsp[0].tval;
1401 ;
1402 break;}
1403 }
1404 /* the action file gets copied in in place of this dollarsign */
1405 #line 331 "bison.simple"
1406 \f
1407 yyvsp -= yylen;
1408 yyssp -= yylen;
1409 #ifdef YYLSP_NEEDED
1410 yylsp -= yylen;
1411 #endif
1412
1413 #if YYDEBUG != 0
1414 if (yydebug)
1415 {
1416 short *ssp1 = yyss - 1;
1417 fprintf (stderr, "state stack now");
1418 while (ssp1 != yyssp)
1419 fprintf (stderr, " %d", *++ssp1);
1420 fprintf (stderr, "\n");
1421 }
1422 #endif
1423
1424 *++yyvsp = yyval;
1425
1426 #ifdef YYLSP_NEEDED
1427 yylsp++;
1428 if (yylen == 0)
1429 {
1430 yylsp->first_line = yylloc.first_line;
1431 yylsp->first_column = yylloc.first_column;
1432 yylsp->last_line = (yylsp-1)->last_line;
1433 yylsp->last_column = (yylsp-1)->last_column;
1434 yylsp->text = 0;
1435 }
1436 else
1437 {
1438 yylsp->last_line = (yylsp+yylen-1)->last_line;
1439 yylsp->last_column = (yylsp+yylen-1)->last_column;
1440 }
1441 #endif
1442
1443 /* Now "shift" the result of the reduction.
1444 Determine what state that goes to,
1445 based on the state we popped back to
1446 and the rule number reduced by. */
1447
1448 yyn = yyr1[yyn];
1449
1450 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1451 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1452 yystate = yytable[yystate];
1453 else
1454 yystate = yydefgoto[yyn - YYNTBASE];
1455
1456 goto yynewstate;
1457
1458 yyerrlab: /* here on detecting error */
1459
1460 if (! yyerrstatus)
1461 /* If not already recovering from an error, report this error. */
1462 {
1463 ++yynerrs;
1464 yyerror("parse error");
1465 }
1466
1467 if (yyerrstatus == 3)
1468 {
1469 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1470
1471 /* return failure if at end of input */
1472 if (yychar == YYEOF)
1473 YYABORT;
1474
1475 #if YYDEBUG != 0
1476 if (yydebug)
1477 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1478 #endif
1479
1480 yychar = YYEMPTY;
1481 }
1482
1483 /* Else will try to reuse lookahead token
1484 after shifting the error token. */
1485
1486 yyerrstatus = 3; /* Each real token shifted decrements this */
1487
1488 goto yyerrhandle;
1489
1490 yyerrdefault: /* current state does not do anything special for the error token. */
1491
1492 #if 0
1493 /* This is wrong; only states that explicitly want error tokens
1494 should shift them. */
1495 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1496 if (yyn) goto yydefault;
1497 #endif
1498
1499 yyerrpop: /* pop the current state because it cannot handle the error token */
1500
1501 if (yyssp == yyss) YYABORT;
1502 yyvsp--;
1503 yystate = *--yyssp;
1504 #ifdef YYLSP_NEEDED
1505 yylsp--;
1506 #endif
1507
1508 #if YYDEBUG != 0
1509 if (yydebug)
1510 {
1511 short *ssp1 = yyss - 1;
1512 fprintf (stderr, "Error: state stack now");
1513 while (ssp1 != yyssp)
1514 fprintf (stderr, " %d", *++ssp1);
1515 fprintf (stderr, "\n");
1516 }
1517 #endif
1518
1519 yyerrhandle:
1520
1521 yyn = yypact[yystate];
1522 if (yyn == YYFLAG)
1523 goto yyerrdefault;
1524
1525 yyn += YYTERROR;
1526 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1527 goto yyerrdefault;
1528
1529 yyn = yytable[yyn];
1530 if (yyn < 0)
1531 {
1532 if (yyn == YYFLAG)
1533 goto yyerrpop;
1534 yyn = -yyn;
1535 goto yyreduce;
1536 }
1537 else if (yyn == 0)
1538 goto yyerrpop;
1539
1540 if (yyn == YYFINAL)
1541 YYACCEPT;
1542
1543 #if YYDEBUG != 0
1544 if (yydebug)
1545 fprintf(stderr, "Shifting error token, ");
1546 #endif
1547
1548 *++yyvsp = yylval;
1549 #ifdef YYLSP_NEEDED
1550 *++yylsp = yylloc;
1551 #endif
1552
1553 yystate = yyn;
1554 goto yynewstate;
1555 }
1556 #line 810 "expread.y"
1557
1558 \f
1559 /* Begin counting arguments for a function call,
1560 saving the data about any containing call. */
1561
1562 static void
1563 start_arglist ()
1564 {
1565 register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall));
1566
1567 new->next = funcall_chain;
1568 new->arglist_len = arglist_len;
1569 arglist_len = 0;
1570 funcall_chain = new;
1571 }
1572
1573 /* Return the number of arguments in a function call just terminated,
1574 and restore the data for the containing function call. */
1575
1576 static int
1577 end_arglist ()
1578 {
1579 register int val = arglist_len;
1580 register struct funcall *call = funcall_chain;
1581 funcall_chain = call->next;
1582 arglist_len = call->arglist_len;
1583 free (call);
1584 return val;
1585 }
1586
1587 /* Free everything in the funcall chain.
1588 Used when there is an error inside parsing. */
1589
1590 static void
1591 free_funcalls ()
1592 {
1593 register struct funcall *call, *next;
1594
1595 for (call = funcall_chain; call; call = next)
1596 {
1597 next = call->next;
1598 free (call);
1599 }
1600 }
1601 \f
1602 /* This page contains the functions for adding data to the struct expression
1603 being constructed. */
1604
1605 /* Add one element to the end of the expression. */
1606
1607 /* To avoid a bug in the Sun 4 compiler, we pass things that can fit into
1608 a register through here */
1609
1610 static void
1611 write_exp_elt (expelt)
1612 union exp_element expelt;
1613 {
1614 if (expout_ptr >= expout_size)
1615 {
1616 expout_size *= 2;
1617 expout = (struct expression *) xrealloc (expout,
1618 sizeof (struct expression)
1619 + expout_size * sizeof (union exp_element));
1620 }
1621 expout->elts[expout_ptr++] = expelt;
1622 }
1623
1624 static void
1625 write_exp_elt_opcode (expelt)
1626 enum exp_opcode expelt;
1627 {
1628 union exp_element tmp;
1629
1630 tmp.opcode = expelt;
1631
1632 write_exp_elt (tmp);
1633 }
1634
1635 static void
1636 write_exp_elt_sym (expelt)
1637 struct symbol *expelt;
1638 {
1639 union exp_element tmp;
1640
1641 tmp.symbol = expelt;
1642
1643 write_exp_elt (tmp);
1644 }
1645
1646 static void
1647 write_exp_elt_longcst (expelt)
1648 LONGEST expelt;
1649 {
1650 union exp_element tmp;
1651
1652 tmp.longconst = expelt;
1653
1654 write_exp_elt (tmp);
1655 }
1656
1657 static void
1658 write_exp_elt_dblcst (expelt)
1659 double expelt;
1660 {
1661 union exp_element tmp;
1662
1663 tmp.doubleconst = expelt;
1664
1665 write_exp_elt (tmp);
1666 }
1667
1668 static void
1669 write_exp_elt_type (expelt)
1670 struct type *expelt;
1671 {
1672 union exp_element tmp;
1673
1674 tmp.type = expelt;
1675
1676 write_exp_elt (tmp);
1677 }
1678
1679 static void
1680 write_exp_elt_intern (expelt)
1681 struct internalvar *expelt;
1682 {
1683 union exp_element tmp;
1684
1685 tmp.internalvar = expelt;
1686
1687 write_exp_elt (tmp);
1688 }
1689
1690 /* Add a string constant to the end of the expression.
1691 Follow it by its length in bytes, as a separate exp_element. */
1692
1693 static void
1694 write_exp_string (str)
1695 struct stoken str;
1696 {
1697 register int len = str.length;
1698 register int lenelt
1699 = (len + sizeof (union exp_element)) / sizeof (union exp_element);
1700
1701 expout_ptr += lenelt;
1702
1703 if (expout_ptr >= expout_size)
1704 {
1705 expout_size = max (expout_size * 2, expout_ptr + 10);
1706 expout = (struct expression *)
1707 xrealloc (expout, (sizeof (struct expression)
1708 + (expout_size * sizeof (union exp_element))));
1709 }
1710 bcopy (str.ptr, (char *) &expout->elts[expout_ptr - lenelt], len);
1711 ((char *) &expout->elts[expout_ptr - lenelt])[len] = 0;
1712 write_exp_elt_longcst ((LONGEST) len);
1713 }
1714 \f
1715 /* During parsing of a C expression, the pointer to the next character
1716 is in this variable. */
1717
1718 static char *lexptr;
1719
1720 /* Tokens that refer to names do so with explicit pointer and length,
1721 so they can share the storage that lexptr is parsing.
1722
1723 When it is necessary to pass a name to a function that expects
1724 a null-terminated string, the substring is copied out
1725 into a block of storage that namecopy points to.
1726
1727 namecopy is allocated once, guaranteed big enough, for each parsing. */
1728
1729 static char *namecopy;
1730
1731 /* Current depth in parentheses within the expression. */
1732
1733 static int paren_depth;
1734
1735 /* Nonzero means stop parsing on first comma (if not within parentheses). */
1736
1737 static int comma_terminates;
1738
1739 /* Take care of parsing a number (anything that starts with a digit).
1740 Set yylval and return the token type; update lexptr.
1741 LEN is the number of characters in it. */
1742
1743 /*** Needs some error checking for the float case ***/
1744
1745 static int
1746 parse_number (olen)
1747 int olen;
1748 {
1749 register char *p = lexptr;
1750 register LONGEST n = 0;
1751 register int c;
1752 register int base = 10;
1753 register int len = olen;
1754 char *err_copy;
1755 int unsigned_p = 0;
1756
1757 extern double atof ();
1758
1759 for (c = 0; c < len; c++)
1760 if (p[c] == '.')
1761 {
1762 /* It's a float since it contains a point. */
1763 yylval.dval = atof (p);
1764 lexptr += len;
1765 return FLOAT;
1766 }
1767
1768 if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2)))
1769 {
1770 p += 2;
1771 base = 16;
1772 len -= 2;
1773 }
1774 else if (*p == '0')
1775 base = 8;
1776
1777 while (len-- > 0)
1778 {
1779 c = *p++;
1780 if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
1781 if (c != 'l' && c != 'u')
1782 n *= base;
1783 if (c >= '0' && c <= '9')
1784 n += c - '0';
1785 else
1786 {
1787 if (base == 16 && c >= 'a' && c <= 'f')
1788 n += c - 'a' + 10;
1789 else if (len == 0 && c == 'l')
1790 ;
1791 else if (len == 0 && c == 'u')
1792 unsigned_p = 1;
1793 else if (base == 10 && len != 0 && (c == 'e' || c == 'E'))
1794 {
1795 /* Scientific notation, where we are unlucky enough not
1796 to have a '.' in the string. */
1797 yylval.dval = atof (lexptr);
1798 lexptr += olen;
1799 return FLOAT;
1800 }
1801 else
1802 {
1803 err_copy = (char *) alloca (olen + 1);
1804 bcopy (lexptr, err_copy, olen);
1805 err_copy[olen] = 0;
1806 error ("Invalid number \"%s\".", err_copy);
1807 }
1808 }
1809 }
1810
1811 lexptr = p;
1812 if (unsigned_p)
1813 {
1814 yylval.ulval = n;
1815 return UINT;
1816 }
1817 else
1818 {
1819 yylval.lval = n;
1820 return INT;
1821 }
1822 }
1823
1824 struct token
1825 {
1826 char *operator;
1827 int token;
1828 enum exp_opcode opcode;
1829 };
1830
1831 static struct token tokentab3[] =
1832 {
1833 {">>=", ASSIGN_MODIFY, BINOP_RSH},
1834 {"<<=", ASSIGN_MODIFY, BINOP_LSH}
1835 };
1836
1837 static struct token tokentab2[] =
1838 {
1839 {"+=", ASSIGN_MODIFY, BINOP_ADD},
1840 {"-=", ASSIGN_MODIFY, BINOP_SUB},
1841 {"*=", ASSIGN_MODIFY, BINOP_MUL},
1842 {"/=", ASSIGN_MODIFY, BINOP_DIV},
1843 {"%=", ASSIGN_MODIFY, BINOP_REM},
1844 {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
1845 {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
1846 {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
1847 {"++", INCREMENT, BINOP_END},
1848 {"--", DECREMENT, BINOP_END},
1849 {"->", ARROW, BINOP_END},
1850 {"&&", AND, BINOP_END},
1851 {"||", OR, BINOP_END},
1852 {"::", COLONCOLON, BINOP_END},
1853 {"<<", LSH, BINOP_END},
1854 {">>", RSH, BINOP_END},
1855 {"==", EQUAL, BINOP_END},
1856 {"!=", NOTEQUAL, BINOP_END},
1857 {"<=", LEQ, BINOP_END},
1858 {">=", GEQ, BINOP_END}
1859 };
1860
1861 /* assign machine-independent names to certain registers
1862 * (unless overridden by the REGISTER_NAMES table)
1863 */
1864 struct std_regs {
1865 char *name;
1866 int regnum;
1867 } std_regs[] = {
1868 #ifdef PC_REGNUM
1869 { "pc", PC_REGNUM },
1870 #endif
1871 #ifdef FP_REGNUM
1872 { "fp", FP_REGNUM },
1873 #endif
1874 #ifdef SP_REGNUM
1875 { "sp", SP_REGNUM },
1876 #endif
1877 #ifdef PS_REGNUM
1878 { "ps", PS_REGNUM },
1879 #endif
1880 };
1881
1882 #define NUM_STD_REGS (sizeof std_regs / sizeof std_regs[0])
1883
1884 /* Read one token, getting characters through lexptr. */
1885
1886 static int
1887 yylex ()
1888 {
1889 register int c;
1890 register int namelen;
1891 register int i;
1892 register char *tokstart;
1893
1894 retry:
1895
1896 tokstart = lexptr;
1897 /* See if it is a special token of length 3. */
1898 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
1899 if (!strncmp (tokstart, tokentab3[i].operator, 3))
1900 {
1901 lexptr += 3;
1902 yylval.opcode = tokentab3[i].opcode;
1903 return tokentab3[i].token;
1904 }
1905
1906 /* See if it is a special token of length 2. */
1907 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
1908 if (!strncmp (tokstart, tokentab2[i].operator, 2))
1909 {
1910 lexptr += 2;
1911 yylval.opcode = tokentab2[i].opcode;
1912 return tokentab2[i].token;
1913 }
1914
1915 switch (c = *tokstart)
1916 {
1917 case 0:
1918 return 0;
1919
1920 case ' ':
1921 case '\t':
1922 case '\n':
1923 lexptr++;
1924 goto retry;
1925
1926 case '\'':
1927 lexptr++;
1928 c = *lexptr++;
1929 if (c == '\\')
1930 c = parse_escape (&lexptr);
1931 yylval.lval = c;
1932 c = *lexptr++;
1933 if (c != '\'')
1934 error ("Invalid character constant.");
1935 return CHAR;
1936
1937 case '(':
1938 paren_depth++;
1939 lexptr++;
1940 return c;
1941
1942 case ')':
1943 if (paren_depth == 0)
1944 return 0;
1945 paren_depth--;
1946 lexptr++;
1947 return c;
1948
1949 case ',':
1950 if (comma_terminates && paren_depth == 0)
1951 return 0;
1952 lexptr++;
1953 return c;
1954
1955 case '.':
1956 /* Might be a floating point number. */
1957 if (lexptr[1] >= '0' && lexptr[1] <= '9')
1958 break; /* Falls into number code. */
1959
1960 case '+':
1961 case '-':
1962 case '*':
1963 case '/':
1964 case '%':
1965 case '|':
1966 case '&':
1967 case '^':
1968 case '~':
1969 case '!':
1970 case '@':
1971 case '<':
1972 case '>':
1973 case '[':
1974 case ']':
1975 case '?':
1976 case ':':
1977 case '=':
1978 case '{':
1979 case '}':
1980 lexptr++;
1981 return c;
1982
1983 case '"':
1984 for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
1985 if (c == '\\')
1986 {
1987 c = tokstart[++namelen];
1988 if (c >= '0' && c <= '9')
1989 {
1990 c = tokstart[++namelen];
1991 if (c >= '0' && c <= '9')
1992 c = tokstart[++namelen];
1993 }
1994 }
1995 yylval.sval.ptr = tokstart + 1;
1996 yylval.sval.length = namelen - 1;
1997 lexptr += namelen + 1;
1998 return STRING;
1999 }
2000
2001 /* Is it a number? */
2002 /* Note: We have already dealt with the case of the token '.'.
2003 See case '.' above. */
2004 if ((c >= '0' && c <= '9') || c == '.')
2005 {
2006 /* It's a number. */
2007 int got_dot = 0, got_e = 0;
2008 register char *p = tokstart;
2009 int hex = c == '0' && (p[1] == 'x' || p[1] == 'X');
2010 if (hex)
2011 p += 2;
2012 for (;; ++p)
2013 {
2014 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2015 got_dot = got_e = 1;
2016 else if (!hex && !got_dot && *p == '.')
2017 got_dot = 1;
2018 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2019 && (*p == '-' || *p == '+'))
2020 /* This is the sign of the exponent, not the end of the
2021 number. */
2022 continue;
2023 else if (*p < '0' || *p > '9'
2024 && (!hex || ((*p < 'a' || *p > 'f')
2025 && (*p < 'A' || *p > 'F'))))
2026 break;
2027 }
2028 return parse_number (p - tokstart);
2029 }
2030
2031 if (!(c == '_' || c == '$'
2032 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2033 error ("Invalid token in expression.");
2034
2035 /* It's a name. See how long it is. */
2036 namelen = 0;
2037 for (c = tokstart[namelen];
2038 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2039 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
2040 c = tokstart[++namelen])
2041 ;
2042
2043 /* The token "if" terminates the expression and is NOT
2044 removed from the input stream. */
2045 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
2046 {
2047 return 0;
2048 }
2049
2050 lexptr += namelen;
2051
2052 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
2053 and $$digits (equivalent to $<-digits> if you could type that).
2054 Make token type LAST, and put the number (the digits) in yylval. */
2055
2056 if (*tokstart == '$')
2057 {
2058 register int negate = 0;
2059 c = 1;
2060 /* Double dollar means negate the number and add -1 as well.
2061 Thus $$ alone means -1. */
2062 if (namelen >= 2 && tokstart[1] == '$')
2063 {
2064 negate = 1;
2065 c = 2;
2066 }
2067 if (c == namelen)
2068 {
2069 /* Just dollars (one or two) */
2070 yylval.lval = - negate;
2071 return LAST;
2072 }
2073 /* Is the rest of the token digits? */
2074 for (; c < namelen; c++)
2075 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
2076 break;
2077 if (c == namelen)
2078 {
2079 yylval.lval = atoi (tokstart + 1 + negate);
2080 if (negate)
2081 yylval.lval = - yylval.lval;
2082 return LAST;
2083 }
2084 }
2085
2086 /* Handle tokens that refer to machine registers:
2087 $ followed by a register name. */
2088
2089 if (*tokstart == '$') {
2090 for (c = 0; c < NUM_REGS; c++)
2091 if (namelen - 1 == strlen (reg_names[c])
2092 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
2093 {
2094 yylval.lval = c;
2095 return REGNAME;
2096 }
2097 for (c = 0; c < NUM_STD_REGS; c++)
2098 if (namelen - 1 == strlen (std_regs[c].name)
2099 && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
2100 {
2101 yylval.lval = std_regs[c].regnum;
2102 return REGNAME;
2103 }
2104 }
2105 /* Catch specific keywords. Should be done with a data structure. */
2106 switch (namelen)
2107 {
2108 case 8:
2109 if (!strncmp (tokstart, "unsigned", 8))
2110 return UNSIGNED;
2111 break;
2112 case 6:
2113 if (!strncmp (tokstart, "struct", 6))
2114 return STRUCT;
2115 if (!strncmp (tokstart, "signed", 6))
2116 return SIGNED;
2117 if (!strncmp (tokstart, "sizeof", 6))
2118 return SIZEOF;
2119 break;
2120 case 5:
2121 if (!strncmp (tokstart, "union", 5))
2122 return UNION;
2123 if (!strncmp (tokstart, "short", 5))
2124 return SHORT;
2125 break;
2126 case 4:
2127 if (!strncmp (tokstart, "enum", 4))
2128 return ENUM;
2129 if (!strncmp (tokstart, "long", 4))
2130 return LONG;
2131 if (!strncmp (tokstart, "this", 4)
2132 && lookup_symbol ("$this", expression_context_block,
2133 VAR_NAMESPACE, 0))
2134 return THIS;
2135 break;
2136 case 3:
2137 if (!strncmp (tokstart, "int", 3))
2138 return INT_KEYWORD;
2139 break;
2140 default:
2141 break;
2142 }
2143
2144 yylval.sval.ptr = tokstart;
2145 yylval.sval.length = namelen;
2146
2147 /* Any other names starting in $ are debugger internal variables. */
2148
2149 if (*tokstart == '$')
2150 {
2151 yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
2152 return VARIABLE;
2153 }
2154
2155 /* Use token-type BLOCKNAME for symbols that happen to be defined as
2156 functions or symtabs. If this is not so, then ...
2157 Use token-type TYPENAME for symbols that happen to be defined
2158 currently as names of types; NAME for other symbols.
2159 The caller is not constrained to care about the distinction. */
2160 {
2161 char *tmp = copy_name (yylval.sval);
2162 struct symbol *sym;
2163
2164 if (lookup_partial_symtab (tmp))
2165 return BLOCKNAME;
2166 sym = lookup_symbol (tmp, expression_context_block,
2167 VAR_NAMESPACE, 0);
2168 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2169 return BLOCKNAME;
2170 if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
2171 return TYPENAME;
2172 return NAME;
2173 }
2174 }
2175
2176 static void
2177 yyerror ()
2178 {
2179 error ("Invalid syntax in expression.");
2180 }
2181
2182 /* Return a null-terminated temporary copy of the name
2183 of a string token. */
2184
2185 static char *
2186 copy_name (token)
2187 struct stoken token;
2188 {
2189 bcopy (token.ptr, namecopy, token.length);
2190 namecopy[token.length] = 0;
2191 return namecopy;
2192 }
2193 \f
2194 /* Reverse an expression from suffix form (in which it is constructed)
2195 to prefix form (in which we can conveniently print or execute it). */
2196
2197 static void prefixify_subexp ();
2198
2199 static void
2200 prefixify_expression (expr)
2201 register struct expression *expr;
2202 {
2203 register int len = sizeof (struct expression) +
2204 expr->nelts * sizeof (union exp_element);
2205 register struct expression *temp;
2206 register int inpos = expr->nelts, outpos = 0;
2207
2208 temp = (struct expression *) alloca (len);
2209
2210 /* Copy the original expression into temp. */
2211 bcopy (expr, temp, len);
2212
2213 prefixify_subexp (temp, expr, inpos, outpos);
2214 }
2215
2216 /* Return the number of exp_elements in the subexpression of EXPR
2217 whose last exp_element is at index ENDPOS - 1 in EXPR. */
2218
2219 static int
2220 length_of_subexp (expr, endpos)
2221 register struct expression *expr;
2222 register int endpos;
2223 {
2224 register int oplen = 1;
2225 register int args = 0;
2226 register int i;
2227
2228 if (endpos < 0)
2229 error ("?error in length_of_subexp");
2230
2231 i = (int) expr->elts[endpos - 1].opcode;
2232
2233 switch (i)
2234 {
2235 /* C++ */
2236 case OP_SCOPE:
2237 oplen = 4 + ((expr->elts[endpos - 2].longconst
2238 + sizeof (union exp_element))
2239 / sizeof (union exp_element));
2240 break;
2241
2242 case OP_LONG:
2243 case OP_DOUBLE:
2244 oplen = 4;
2245 break;
2246
2247 case OP_VAR_VALUE:
2248 case OP_LAST:
2249 case OP_REGISTER:
2250 case OP_INTERNALVAR:
2251 oplen = 3;
2252 break;
2253
2254 case OP_FUNCALL:
2255 oplen = 3;
2256 args = 1 + expr->elts[endpos - 2].longconst;
2257 break;
2258
2259 case UNOP_CAST:
2260 case UNOP_MEMVAL:
2261 oplen = 3;
2262 args = 1;
2263 break;
2264
2265 case STRUCTOP_STRUCT:
2266 case STRUCTOP_PTR:
2267 args = 1;
2268 case OP_STRING:
2269 oplen = 3 + ((expr->elts[endpos - 2].longconst
2270 + sizeof (union exp_element))
2271 / sizeof (union exp_element));
2272 break;
2273
2274 case TERNOP_COND:
2275 args = 3;
2276 break;
2277
2278 case BINOP_ASSIGN_MODIFY:
2279 oplen = 3;
2280 args = 2;
2281 break;
2282
2283 /* C++ */
2284 case OP_THIS:
2285 oplen = 2;
2286 break;
2287
2288 default:
2289 args = 1 + (i < (int) BINOP_END);
2290 }
2291
2292 while (args > 0)
2293 {
2294 oplen += length_of_subexp (expr, endpos - oplen);
2295 args--;
2296 }
2297
2298 return oplen;
2299 }
2300
2301 /* Copy the subexpression ending just before index INEND in INEXPR
2302 into OUTEXPR, starting at index OUTBEG.
2303 In the process, convert it from suffix to prefix form. */
2304
2305 static void
2306 prefixify_subexp (inexpr, outexpr, inend, outbeg)
2307 register struct expression *inexpr;
2308 struct expression *outexpr;
2309 register int inend;
2310 int outbeg;
2311 {
2312 register int oplen = 1;
2313 register int args = 0;
2314 register int i;
2315 int *arglens;
2316 enum exp_opcode opcode;
2317
2318 /* Compute how long the last operation is (in OPLEN),
2319 and also how many preceding subexpressions serve as
2320 arguments for it (in ARGS). */
2321
2322 opcode = inexpr->elts[inend - 1].opcode;
2323 switch (opcode)
2324 {
2325 /* C++ */
2326 case OP_SCOPE:
2327 oplen = 4 + ((inexpr->elts[inend - 2].longconst
2328 + sizeof (union exp_element))
2329 / sizeof (union exp_element));
2330 break;
2331
2332 case OP_LONG:
2333 case OP_DOUBLE:
2334 oplen = 4;
2335 break;
2336
2337 case OP_VAR_VALUE:
2338 case OP_LAST:
2339 case OP_REGISTER:
2340 case OP_INTERNALVAR:
2341 oplen = 3;
2342 break;
2343
2344 case OP_FUNCALL:
2345 oplen = 3;
2346 args = 1 + inexpr->elts[inend - 2].longconst;
2347 break;
2348
2349 case UNOP_CAST:
2350 case UNOP_MEMVAL:
2351 oplen = 3;
2352 args = 1;
2353 break;
2354
2355 case STRUCTOP_STRUCT:
2356 case STRUCTOP_PTR:
2357 args = 1;
2358 case OP_STRING:
2359 oplen = 3 + ((inexpr->elts[inend - 2].longconst
2360 + sizeof (union exp_element))
2361 / sizeof (union exp_element));
2362
2363 break;
2364
2365 case TERNOP_COND:
2366 args = 3;
2367 break;
2368
2369 case BINOP_ASSIGN_MODIFY:
2370 oplen = 3;
2371 args = 2;
2372 break;
2373
2374 /* C++ */
2375 case OP_THIS:
2376 oplen = 2;
2377 break;
2378
2379 default:
2380 args = 1 + ((int) opcode < (int) BINOP_END);
2381 }
2382
2383 /* Copy the final operator itself, from the end of the input
2384 to the beginning of the output. */
2385 inend -= oplen;
2386 bcopy (&inexpr->elts[inend], &outexpr->elts[outbeg],
2387 oplen * sizeof (union exp_element));
2388 outbeg += oplen;
2389
2390 /* Find the lengths of the arg subexpressions. */
2391 arglens = (int *) alloca (args * sizeof (int));
2392 for (i = args - 1; i >= 0; i--)
2393 {
2394 oplen = length_of_subexp (inexpr, inend);
2395 arglens[i] = oplen;
2396 inend -= oplen;
2397 }
2398
2399 /* Now copy each subexpression, preserving the order of
2400 the subexpressions, but prefixifying each one.
2401 In this loop, inend starts at the beginning of
2402 the expression this level is working on
2403 and marches forward over the arguments.
2404 outbeg does similarly in the output. */
2405 for (i = 0; i < args; i++)
2406 {
2407 oplen = arglens[i];
2408 inend += oplen;
2409 prefixify_subexp (inexpr, outexpr, inend, outbeg);
2410 outbeg += oplen;
2411 }
2412 }
2413 \f
2414 /* This page contains the two entry points to this file. */
2415
2416 /* Read a C expression from the string *STRINGPTR points to,
2417 parse it, and return a pointer to a struct expression that we malloc.
2418 Use block BLOCK as the lexical context for variable names;
2419 if BLOCK is zero, use the block of the selected stack frame.
2420 Meanwhile, advance *STRINGPTR to point after the expression,
2421 at the first nonwhite character that is not part of the expression
2422 (possibly a null character).
2423
2424 If COMMA is nonzero, stop if a comma is reached. */
2425
2426 struct expression *
2427 parse_c_1 (stringptr, block, comma)
2428 char **stringptr;
2429 struct block *block;
2430 {
2431 struct cleanup *old_chain;
2432
2433 lexptr = *stringptr;
2434
2435 paren_depth = 0;
2436 type_stack_depth = 0;
2437
2438 comma_terminates = comma;
2439
2440 if (lexptr == 0 || *lexptr == 0)
2441 error_no_arg ("expression to compute");
2442
2443 old_chain = make_cleanup (free_funcalls, 0);
2444 funcall_chain = 0;
2445
2446 expression_context_block = block ? block : get_selected_block ();
2447
2448 namecopy = (char *) alloca (strlen (lexptr) + 1);
2449 expout_size = 10;
2450 expout_ptr = 0;
2451 expout = (struct expression *)
2452 xmalloc (sizeof (struct expression)
2453 + expout_size * sizeof (union exp_element));
2454 make_cleanup (free_current_contents, &expout);
2455 if (yyparse ())
2456 yyerror ();
2457 discard_cleanups (old_chain);
2458 expout->nelts = expout_ptr;
2459 expout = (struct expression *)
2460 xrealloc (expout,
2461 sizeof (struct expression)
2462 + expout_ptr * sizeof (union exp_element));
2463 prefixify_expression (expout);
2464 *stringptr = lexptr;
2465 return expout;
2466 }
2467
2468 /* Parse STRING as an expression, and complain if this fails
2469 to use up all of the contents of STRING. */
2470
2471 struct expression *
2472 parse_c_expression (string)
2473 char *string;
2474 {
2475 register struct expression *exp;
2476 exp = parse_c_1 (&string, 0, 0);
2477 if (*string)
2478 error ("Junk after end of expression.");
2479 return exp;
2480 }
2481
2482 static void
2483 push_type (tp)
2484 enum type_pieces tp;
2485 {
2486 if (type_stack_depth == type_stack_size)
2487 {
2488 type_stack_size *= 2;
2489 type_stack = (enum type_pieces *)
2490 xrealloc (type_stack, type_stack_size * sizeof (enum type_pieces));
2491 }
2492 type_stack[type_stack_depth++] = tp;
2493 }
2494
2495 static enum type_pieces
2496 pop_type ()
2497 {
2498 if (type_stack_depth)
2499 return type_stack[--type_stack_depth];
2500 return tp_end;
2501 }
2502
2503 void
2504 _initialize_expread ()
2505 {
2506 type_stack_size = 80;
2507 type_stack_depth = 0;
2508 type_stack = (enum type_pieces *)
2509 xmalloc (type_stack_size * sizeof (enum type_pieces));
2510 }