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