gdb-3.1
[deliverable/binutils-gdb.git] / gdb / expread.tab.c
CommitLineData
bb7592f0 1
2# line 31 "expread.y"
3#include "defs.h"
4#include "param.h"
5#include "symtab.h"
6#include "frame.h"
7#include "expression.h"
8
9#include <stdio.h>
10
11static struct expression *expout;
12static int expout_size;
13static int expout_ptr;
14
15static int yylex ();
e91b87a3 16static void yyerror ();
bb7592f0 17static void write_exp_elt ();
bb7592f0 18static void write_exp_string ();
19static void start_arglist ();
20static int end_arglist ();
21static void free_funcalls ();
22static char *copy_name ();
23
24/* If this is nonzero, this block is used as the lexical context
25 for symbol names. */
26
27static struct block *expression_context_block;
28
e91b87a3 29/* The innermost context required by the stack and register variables
30 we've encountered so far. */
31struct block *innermost_block;
32
33/* The block in which the most recently discovered symbol was found. */
34struct block *block_found;
35
bb7592f0 36/* Number of arguments seen so far in innermost function call. */
37static int arglist_len;
38
39/* Data structure for saving values of arglist_len
40 for function calls whose arguments contain other function calls. */
41
42struct funcall
43 {
44 struct funcall *next;
45 int arglist_len;
46 };
47
48struct funcall *funcall_chain;
49
50/* This kind of datum is used to represent the name
51 of a symbol token. */
52
53struct stoken
54 {
55 char *ptr;
56 int length;
57 };
58
e91b87a3 59# line 92 "expread.y"
bb7592f0 60typedef union
61 {
62 long lval;
63 double dval;
64 struct symbol *sym;
65 struct type *tval;
66 struct stoken sval;
67 int voidval;
68 struct block *bval;
69 enum exp_opcode opcode;
70 struct internalvar *ivar;
71
72 struct type **tvec;
73 int *ivec;
74 } YYSTYPE;
75# define INT 257
76# define CHAR 258
77# define FLOAT 259
78# define NAME 260
79# define TYPENAME 261
80# define STRING 262
81# define STRUCT 263
82# define UNION 264
83# define ENUM 265
84# define SIZEOF 266
85# define UNSIGNED 267
86# define COLONCOLON 268
87# define LAST 269
88# define REGNAME 270
89# define VARIABLE 271
90# define ASSIGN_MODIFY 272
91# define THIS 273
92# define ABOVE_COMMA 274
93# define OR 275
94# define AND 276
95# define EQUAL 277
96# define NOTEQUAL 278
97# define LEQ 279
98# define GEQ 280
99# define LSH 281
100# define RSH 282
101# define UNARY 283
102# define INCREMENT 284
103# define DECREMENT 285
104# define ARROW 286
105#define yyclearin yychar = -1
106#define yyerrok yyerrflag = 0
107extern int yychar;
108extern short yyerrflag;
109#ifndef YYMAXDEPTH
110#define YYMAXDEPTH 150
111#endif
112YYSTYPE yylval, yyval;
113# define YYERRCODE 256
114
e91b87a3 115# line 630 "expread.y"
bb7592f0 116
117\f
118/* Begin counting arguments for a function call,
119 saving the data about any containing call. */
120
121static void
122start_arglist ()
123{
124 register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall));
125
126 new->next = funcall_chain;
127 new->arglist_len = arglist_len;
128 arglist_len = 0;
129 funcall_chain = new;
130}
131
132/* Return the number of arguments in a function call just terminated,
133 and restore the data for the containing function call. */
134
135static int
136end_arglist ()
137{
138 register int val = arglist_len;
139 register struct funcall *call = funcall_chain;
140 funcall_chain = call->next;
141 arglist_len = call->arglist_len;
142 free (call);
143 return val;
144}
145
146/* Free everything in the funcall chain.
147 Used when there is an error inside parsing. */
148
149static void
150free_funcalls ()
151{
152 register struct funcall *call, *next;
153
154 for (call = funcall_chain; call; call = next)
155 {
156 next = call->next;
157 free (call);
158 }
159}
160\f
161/* This page contains the functions for adding data to the struct expression
162 being constructed. */
163
164/* Add one element to the end of the expression. */
165
e91b87a3 166/* To avoid a bug in the Sun 4 compiler, we pass things that can fit into
167 a register through here */
168
bb7592f0 169static void
170write_exp_elt (expelt)
e91b87a3 171 union exp_element expelt;
bb7592f0 172{
bb7592f0 173 if (expout_ptr >= expout_size)
174 {
175 expout_size *= 2;
176 expout = (struct expression *) xrealloc (expout,
177 sizeof (struct expression)
178 + expout_size * sizeof (union exp_element));
179 }
e91b87a3 180 expout->elts[expout_ptr++] = expelt;
181}
182
183static void
184write_exp_elt_opcode (expelt)
185 enum exp_opcode expelt;
186{
187 union exp_element tmp;
188
189 tmp.opcode = expelt;
190
191 write_exp_elt (tmp);
bb7592f0 192}
193
bb7592f0 194static void
e91b87a3 195write_exp_elt_sym (expelt)
196 struct symbol *expelt;
197{
198 union exp_element tmp;
199
200 tmp.symbol = expelt;
201
202 write_exp_elt (tmp);
203}
204
205static void
206write_exp_elt_longcst (expelt)
207 LONGEST expelt;
208{
209 union exp_element tmp;
210
211 tmp.longconst = expelt;
212
213 write_exp_elt (tmp);
214}
215
216static void
217write_exp_elt_dblcst (expelt)
bb7592f0 218 double expelt;
219{
e91b87a3 220 union exp_element tmp;
bb7592f0 221
e91b87a3 222 tmp.doubleconst = expelt;
223
224 write_exp_elt (tmp);
225}
226
227static void
228write_exp_elt_type (expelt)
229 struct type *expelt;
230{
231 union exp_element tmp;
232
233 tmp.type = expelt;
234
235 write_exp_elt (tmp);
236}
237
238static void
239write_exp_elt_intern (expelt)
240 struct internalvar *expelt;
241{
242 union exp_element tmp;
243
244 tmp.internalvar = expelt;
245
246 write_exp_elt (tmp);
bb7592f0 247}
248
249/* Add a string constant to the end of the expression.
250 Follow it by its length in bytes, as a separate exp_element. */
251
252static void
253write_exp_string (str)
254 struct stoken str;
255{
256 register int len = str.length;
257 register int lenelt
258 = (len + sizeof (union exp_element)) / sizeof (union exp_element);
259
260 expout_ptr += lenelt;
261
262 if (expout_ptr >= expout_size)
263 {
264 expout_size = max (expout_size * 2, expout_ptr + 10);
e91b87a3 265 expout = (struct expression *)
266 xrealloc (expout, (sizeof (struct expression)
267 + (expout_size * sizeof (union exp_element))));
bb7592f0 268 }
269 bcopy (str.ptr, (char *) &expout->elts[expout_ptr - lenelt], len);
270 ((char *) &expout->elts[expout_ptr - lenelt])[len] = 0;
e91b87a3 271 write_exp_elt_longcst (len);
bb7592f0 272}
273\f
274/* During parsing of a C expression, the pointer to the next character
275 is in this variable. */
276
277static char *lexptr;
278
279/* Tokens that refer to names do so with explicit pointer and length,
280 so they can share the storage that lexptr is parsing.
281
282 When it is necessary to pass a name to a function that expects
283 a null-terminated string, the substring is copied out
284 into a block of storage that namecopy points to.
285
286 namecopy is allocated once, guaranteed big enough, for each parsing. */
287
288static char *namecopy;
289
290/* Current depth in parentheses within the expression. */
291
292static int paren_depth;
293
294/* Nonzero means stop parsing on first comma (if not within parentheses). */
295
296static int comma_terminates;
297
298/* Take care of parsing a number (anything that starts with a digit).
299 Set yylval and return the token type; update lexptr.
300 LEN is the number of characters in it. */
301
302/*** Needs some error checking for the float case ***/
303
304static int
305parse_number (olen)
306 int olen;
307{
308 register char *p = lexptr;
309 register long n = 0;
310 register int c;
311 register int base = 10;
312 register int len = olen;
313 char *err_copy;
314
315 extern double atof ();
316
317 for (c = 0; c < len; c++)
318 if (p[c] == '.')
319 {
320 /* It's a float since it contains a point. */
321 yylval.dval = atof (p);
322 lexptr += len;
323 return FLOAT;
324 }
325
326 if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2)))
327 {
328 p += 2;
329 base = 16;
330 len -= 2;
331 }
332 else if (*p == '0')
333 base = 8;
334
335 while (len-- > 0)
336 {
337 c = *p++;
e91b87a3 338 if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
339 if (c != 'l')
340 n *= base;
bb7592f0 341 if (c >= '0' && c <= '9')
342 n += c - '0';
343 else
344 {
bb7592f0 345 if (base == 16 && c >= 'a' && c <= 'f')
346 n += c - 'a' + 10;
347 else if (len == 0 && c == 'l')
348 ;
349 else
350 {
351 err_copy = (char *) alloca (olen + 1);
352 bcopy (lexptr, err_copy, olen);
353 err_copy[olen] = 0;
354 error ("Invalid number \"%s\".", err_copy);
355 }
356 }
357 }
358
359 lexptr = p;
360 yylval.lval = n;
361 return INT;
362}
363
364struct token
365{
366 char *operator;
367 int token;
368 enum exp_opcode opcode;
369};
370
371static struct token tokentab3[] =
372 {
373 {">>=", ASSIGN_MODIFY, BINOP_RSH},
374 {"<<=", ASSIGN_MODIFY, BINOP_LSH}
375 };
376
377static struct token tokentab2[] =
378 {
379 {"+=", ASSIGN_MODIFY, BINOP_ADD},
380 {"-=", ASSIGN_MODIFY, BINOP_SUB},
381 {"*=", ASSIGN_MODIFY, BINOP_MUL},
382 {"/=", ASSIGN_MODIFY, BINOP_DIV},
383 {"%=", ASSIGN_MODIFY, BINOP_REM},
384 {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
385 {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
386 {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
387 {"++", INCREMENT, BINOP_END},
388 {"--", DECREMENT, BINOP_END},
389 {"->", ARROW, BINOP_END},
390 {"&&", AND, BINOP_END},
391 {"||", OR, BINOP_END},
392 {"::", COLONCOLON, BINOP_END},
393 {"<<", LSH, BINOP_END},
394 {">>", RSH, BINOP_END},
395 {"==", EQUAL, BINOP_END},
396 {"!=", NOTEQUAL, BINOP_END},
397 {"<=", LEQ, BINOP_END},
398 {">=", GEQ, BINOP_END}
399 };
400
e91b87a3 401/* assign machine-independent names to certain registers
402 * (unless overridden by the REGISTER_NAMES table)
403 */
404struct std_regs {
405 char *name;
406 int regnum;
407} std_regs[] = {
408#ifdef PC_REGNUM
409 { "pc", PC_REGNUM },
410#endif
411#ifdef FP_REGNUM
412 { "fp", FP_REGNUM },
413#endif
414#ifdef SP_REGNUM
415 { "sp", SP_REGNUM },
416#endif
417#ifdef PS_REGNUM
418 { "ps", PS_REGNUM },
419#endif
420};
421
422#define NUM_STD_REGS (sizeof std_regs / sizeof std_regs[0])
423
bb7592f0 424/* Read one token, getting characters through lexptr. */
425
426static int
427yylex ()
428{
429 register int c;
430 register int namelen;
431 register int i;
432 register char *tokstart;
433
434 retry:
435
436 tokstart = lexptr;
437 /* See if it is a special token of length 3. */
438 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
439 if (!strncmp (tokstart, tokentab3[i].operator, 3))
440 {
441 lexptr += 3;
442 yylval.opcode = tokentab3[i].opcode;
443 return tokentab3[i].token;
444 }
445
446 /* See if it is a special token of length 2. */
447 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
448 if (!strncmp (tokstart, tokentab2[i].operator, 2))
449 {
450 lexptr += 2;
451 yylval.opcode = tokentab2[i].opcode;
452 return tokentab2[i].token;
453 }
454
455 switch (c = *tokstart)
456 {
457 case 0:
458 return 0;
459
460 case ' ':
461 case '\t':
462 case '\n':
463 lexptr++;
464 goto retry;
465
466 case '\'':
467 lexptr++;
468 c = *lexptr++;
469 if (c == '\\')
470 c = parse_escape (&lexptr);
471 yylval.lval = c;
472 c = *lexptr++;
473 if (c != '\'')
474 error ("Invalid character constant.");
475 return CHAR;
476
477 case '(':
478 paren_depth++;
479 lexptr++;
480 return c;
481
482 case ')':
483 if (paren_depth == 0)
484 return 0;
485 paren_depth--;
486 lexptr++;
487 return c;
488
489 case ',':
490 if (comma_terminates && paren_depth == 0)
491 return 0;
492 lexptr++;
493 return c;
494
495 case '+':
496 case '-':
497 case '*':
498 case '/':
499 case '%':
500 case '|':
501 case '&':
502 case '^':
503 case '~':
504 case '!':
505 case '@':
506 case '<':
507 case '>':
508 case '[':
509 case ']':
510 case '.':
511 case '?':
512 case ':':
513 case '=':
514 case '{':
515 case '}':
516 lexptr++;
517 return c;
518
519 case '"':
520 for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
521 if (c == '\\')
522 {
523 c = tokstart[++namelen];
524 if (c >= '0' && c <= '9')
525 {
526 c = tokstart[++namelen];
527 if (c >= '0' && c <= '9')
528 c = tokstart[++namelen];
529 }
530 }
531 yylval.sval.ptr = tokstart + 1;
532 yylval.sval.length = namelen - 1;
533 lexptr += namelen + 1;
534 return STRING;
535 }
536 if (c >= '0' && c <= '9')
537 {
538 /* It's a number */
539 for (namelen = 0;
540 c = tokstart[namelen],
541 (c == '_' || c == '$' || c == '.' || (c >= '0' && c <= '9')
542 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
543 namelen++)
544 ;
545 return parse_number (namelen);
546 }
547
548 if (!(c == '_' || c == '$'
549 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
550 error ("Invalid token in expression.");
551
552 /* It is a name. See how long it is. */
553
554 for (namelen = 0;
555 c = tokstart[namelen],
556 (c == '_' || c == '$' || (c >= '0' && c <= '9')
557 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
558 namelen++)
559 ;
560
561 /* The token "if" terminates the expression and is NOT
562 removed from the input stream. */
563 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
564 {
565 return 0;
566 }
567
568 lexptr += namelen;
569
570 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
571 and $$digits (equivalent to $<-digits> if you could type that).
572 Make token type LAST, and put the number (the digits) in yylval. */
573
574 if (*tokstart == '$')
575 {
576 register int negate = 0;
577 c = 1;
578 /* Double dollar means negate the number and add -1 as well.
579 Thus $$ alone means -1. */
580 if (namelen >= 2 && tokstart[1] == '$')
581 {
582 negate = 1;
583 c = 2;
584 }
585 if (c == namelen)
586 {
587 /* Just dollars (one or two) */
588 yylval.lval = - negate;
589 return LAST;
590 }
591 /* Is the rest of the token digits? */
592 for (; c < namelen; c++)
593 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
594 break;
595 if (c == namelen)
596 {
597 yylval.lval = atoi (tokstart + 1 + negate);
598 if (negate)
599 yylval.lval = - yylval.lval;
600 return LAST;
601 }
602 }
603
604 /* Handle tokens that refer to machine registers:
605 $ followed by a register name. */
606
e91b87a3 607 if (*tokstart == '$') {
bb7592f0 608 for (c = 0; c < NUM_REGS; c++)
609 if (namelen - 1 == strlen (reg_names[c])
610 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
611 {
612 yylval.lval = c;
613 return REGNAME;
614 }
e91b87a3 615 for (c = 0; c < NUM_STD_REGS; c++)
616 if (namelen - 1 == strlen (std_regs[c].name)
617 && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
618 {
619 yylval.lval = std_regs[c].regnum;
620 return REGNAME;
621 }
622 }
bb7592f0 623 if (namelen == 6 && !strncmp (tokstart, "struct", 6))
624 {
625 return STRUCT;
626 }
627 if (namelen == 5)
628 {
629 if (!strncmp (tokstart, "union", 5))
630 {
631 return UNION;
632 }
633 }
634 if (namelen == 4)
635 {
636 if (!strncmp (tokstart, "enum", 4))
637 {
638 return ENUM;
639 }
e91b87a3 640 if (!strncmp (tokstart, "this", 4)
641 && lookup_symbol ("$this", expression_context_block,
642 VAR_NAMESPACE, 0))
643 return THIS;
bb7592f0 644 }
645 if (namelen == 6 && !strncmp (tokstart, "sizeof", 6))
646 {
647 return SIZEOF;
648 }
649 if (namelen == 8 && !strncmp (tokstart, "unsigned", 6))
650 {
651 return UNSIGNED;
652 }
653 yylval.sval.ptr = tokstart;
654 yylval.sval.length = namelen;
655
656 /* Any other names starting in $ are debugger internal variables. */
657
658 if (*tokstart == '$')
659 {
660 yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
661 return VARIABLE;
662 }
663
664 /* Use token-type TYPENAME for symbols that happen to be defined
665 currently as names of types; NAME for other symbols.
666 The caller is not constrained to care about the distinction. */
667 if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
668 return TYPENAME;
669 return NAME;
670}
671
e91b87a3 672static void
bb7592f0 673yyerror ()
674{
675 error ("Invalid syntax in expression.");
676}
677
678/* Return a null-terminated temporary copy of the name
679 of a string token. */
680
681static char *
682copy_name (token)
683 struct stoken token;
684{
685 bcopy (token.ptr, namecopy, token.length);
686 namecopy[token.length] = 0;
687 return namecopy;
688}
689\f
690/* Reverse an expression from suffix form (in which it is constructed)
691 to prefix form (in which we can conveniently print or execute it). */
692
693static void prefixify_subexp ();
694
695static void
696prefixify_expression (expr)
697 register struct expression *expr;
698{
699 register int len = sizeof (struct expression) +
700 expr->nelts * sizeof (union exp_element);
701 register struct expression *temp;
702 register int inpos = expr->nelts, outpos = 0;
703
704 temp = (struct expression *) alloca (len);
705
706 /* Copy the original expression into temp. */
707 bcopy (expr, temp, len);
708
709 prefixify_subexp (temp, expr, inpos, outpos);
710}
711
712/* Return the number of exp_elements in the subexpression of EXPR
713 whose last exp_element is at index ENDPOS - 1 in EXPR. */
714
715static int
716length_of_subexp (expr, endpos)
717 register struct expression *expr;
718 register int endpos;
719{
720 register int oplen = 1;
721 register int args = 0;
722 register int i;
723
724 if (endpos < 0)
725 error ("?error in length_of_subexp");
726
727 i = (int) expr->elts[endpos - 1].opcode;
728
729 switch (i)
730 {
731 /* C++ */
732 case OP_SCOPE:
733 oplen = 4 + ((expr->elts[endpos - 2].longconst
734 + sizeof (union exp_element))
735 / sizeof (union exp_element));
736 break;
737
738 case OP_LONG:
739 case OP_DOUBLE:
740 oplen = 4;
741 break;
742
743 case OP_VAR_VALUE:
744 case OP_LAST:
745 case OP_REGISTER:
746 case OP_INTERNALVAR:
747 oplen = 3;
748 break;
749
750 case OP_FUNCALL:
751 oplen = 3;
752 args = 1 + expr->elts[endpos - 2].longconst;
753 break;
754
755 case UNOP_CAST:
756 case UNOP_MEMVAL:
757 oplen = 3;
758 args = 1;
759 break;
760
761 case STRUCTOP_STRUCT:
762 case STRUCTOP_PTR:
763 args = 1;
764 case OP_STRING:
765 oplen = 3 + ((expr->elts[endpos - 2].longconst
766 + sizeof (union exp_element))
767 / sizeof (union exp_element));
768 break;
769
770 case TERNOP_COND:
771 args = 3;
772 break;
773
774 case BINOP_ASSIGN_MODIFY:
775 oplen = 3;
776 args = 2;
777 break;
778
779 /* C++ */
780 case OP_THIS:
781 oplen = 2;
782 break;
783
784 default:
785 args = 1 + (i < (int) BINOP_END);
786 }
787
788 while (args > 0)
789 {
790 oplen += length_of_subexp (expr, endpos - oplen);
791 args--;
792 }
793
794 return oplen;
795}
796
797/* Copy the subexpression ending just before index INEND in INEXPR
798 into OUTEXPR, starting at index OUTBEG.
799 In the process, convert it from suffix to prefix form. */
800
801static void
802prefixify_subexp (inexpr, outexpr, inend, outbeg)
803 register struct expression *inexpr;
804 struct expression *outexpr;
805 register int inend;
806 int outbeg;
807{
808 register int oplen = 1;
809 register int args = 0;
810 register int i;
811 int *arglens;
812 enum exp_opcode opcode;
813
814 /* Compute how long the last operation is (in OPLEN),
815 and also how many preceding subexpressions serve as
816 arguments for it (in ARGS). */
817
818 opcode = inexpr->elts[inend - 1].opcode;
819 switch (opcode)
820 {
821 /* C++ */
822 case OP_SCOPE:
823 oplen = 4 + ((inexpr->elts[inend - 2].longconst
824 + sizeof (union exp_element))
825 / sizeof (union exp_element));
826 break;
827
828 case OP_LONG:
829 case OP_DOUBLE:
830 oplen = 4;
831 break;
832
833 case OP_VAR_VALUE:
834 case OP_LAST:
835 case OP_REGISTER:
836 case OP_INTERNALVAR:
837 oplen = 3;
838 break;
839
840 case OP_FUNCALL:
841 oplen = 3;
842 args = 1 + inexpr->elts[inend - 2].longconst;
843 break;
844
845 case UNOP_CAST:
846 case UNOP_MEMVAL:
847 oplen = 3;
848 args = 1;
849 break;
850
851 case STRUCTOP_STRUCT:
852 case STRUCTOP_PTR:
853 args = 1;
854 case OP_STRING:
855 oplen = 3 + ((inexpr->elts[inend - 2].longconst
856 + sizeof (union exp_element))
857 / sizeof (union exp_element));
858
859 break;
860
861 case TERNOP_COND:
862 args = 3;
863 break;
864
865 case BINOP_ASSIGN_MODIFY:
866 oplen = 3;
867 args = 2;
868 break;
869
870 /* C++ */
871 case OP_THIS:
872 oplen = 2;
873 break;
874
875 default:
876 args = 1 + ((int) opcode < (int) BINOP_END);
877 }
878
879 /* Copy the final operator itself, from the end of the input
880 to the beginning of the output. */
881 inend -= oplen;
882 bcopy (&inexpr->elts[inend], &outexpr->elts[outbeg],
883 oplen * sizeof (union exp_element));
884 outbeg += oplen;
885
886 /* Find the lengths of the arg subexpressions. */
887 arglens = (int *) alloca (args * sizeof (int));
888 for (i = args - 1; i >= 0; i--)
889 {
890 oplen = length_of_subexp (inexpr, inend);
891 arglens[i] = oplen;
892 inend -= oplen;
893 }
894
895 /* Now copy each subexpression, preserving the order of
896 the subexpressions, but prefixifying each one.
897 In this loop, inend starts at the beginning of
898 the expression this level is working on
899 and marches forward over the arguments.
900 outbeg does similarly in the output. */
901 for (i = 0; i < args; i++)
902 {
903 oplen = arglens[i];
904 inend += oplen;
905 prefixify_subexp (inexpr, outexpr, inend, outbeg);
906 outbeg += oplen;
907 }
908}
909\f
910/* This page contains the two entry points to this file. */
911
912/* Read a C expression from the string *STRINGPTR points to,
913 parse it, and return a pointer to a struct expression that we malloc.
914 Use block BLOCK as the lexical context for variable names;
915 if BLOCK is zero, use the block of the selected stack frame.
916 Meanwhile, advance *STRINGPTR to point after the expression,
917 at the first nonwhite character that is not part of the expression
918 (possibly a null character).
919
920 If COMMA is nonzero, stop if a comma is reached. */
921
922struct expression *
923parse_c_1 (stringptr, block, comma)
924 char **stringptr;
925 struct block *block;
926{
927 struct cleanup *old_chain;
928
929 lexptr = *stringptr;
930
e91b87a3 931 paren_depth = 0;
932
bb7592f0 933 comma_terminates = comma;
934
935 if (lexptr == 0 || *lexptr == 0)
936 error_no_arg ("expression to compute");
937
938 old_chain = make_cleanup (free_funcalls, 0);
939 funcall_chain = 0;
940
941 expression_context_block = block ? block : get_selected_block ();
942
943 namecopy = (char *) alloca (strlen (lexptr) + 1);
944 expout_size = 10;
945 expout_ptr = 0;
e91b87a3 946 expout = (struct expression *)
947 xmalloc (sizeof (struct expression)
948 + expout_size * sizeof (union exp_element));
bb7592f0 949 make_cleanup (free_current_contents, &expout);
950 if (yyparse ())
951 yyerror ();
952 discard_cleanups (old_chain);
953 expout->nelts = expout_ptr;
954 expout = (struct expression *)
955 xrealloc (expout,
956 sizeof (struct expression)
957 + expout_ptr * sizeof (union exp_element));
958 prefixify_expression (expout);
959 *stringptr = lexptr;
960 return expout;
961}
962
963/* Parse STRING as an expression, and complain if this fails
964 to use up all of the contents of STRING. */
965
966struct expression *
967parse_c_expression (string)
968 char *string;
969{
970 register struct expression *exp;
971 exp = parse_c_1 (&string, 0, 0);
972 if (*string)
973 error ("Junk after end of expression.");
974 return exp;
975}
976short yyexca[] ={
977-1, 1,
978 0, -1,
979 -2, 0,
980-1, 26,
981 268, 79,
982 -2, 64,
983-1, 124,
984 268, 60,
985 -2, 61,
986 };
987# define YYNPROD 81
988# define YYLAST 696
989short yyact[]={
990
991 43, 54, 140, 39, 123, 41, 44, 120, 45, 37,
992 42, 78, 77, 73, 39, 29, 30, 31, 142, 32,
993 37, 131, 33, 52, 60, 53, 59, 40, 80, 81,
994 143, 148, 33, 135, 149, 43, 54, 59, 39, 135,
995 41, 44, 71, 45, 37, 42, 137, 129, 122, 138,
996 90, 33, 144, 92, 38, 23, 74, 55, 52, 60,
997 53, 59, 40, 146, 118, 38, 119, 88, 117, 17,
998 43, 54, 1, 39, 0, 41, 44, 0, 45, 37,
999 42, 128, 118, 0, 119, 0, 117, 56, 0, 38,
1000 0, 0, 55, 52, 0, 53, 59, 40, 7, 0,
1001 0, 75, 2, 5, 0, 13, 0, 4, 0, 0,
1002 6, 43, 54, 115, 39, 0, 41, 44, 0, 45,
1003 37, 42, 56, 0, 38, 0, 118, 55, 119, 132,
1004 117, 0, 0, 0, 52, 0, 53, 59, 40, 7,
1005 91, 0, 0, 0, 5, 0, 70, 0, 4, 0,
1006 0, 6, 0, 43, 54, 0, 39, 56, 41, 44,
1007 0, 45, 37, 42, 0, 38, 0, 0, 55, 116,
1008 118, 0, 119, 121, 117, 0, 52, 0, 53, 59,
1009 40, 0, 0, 0, 0, 0, 0, 147, 12, 0,
1010 0, 8, 150, 0, 145, 0, 43, 54, 56, 39,
1011 0, 41, 44, 0, 45, 37, 42, 38, 0, 0,
1012 55, 0, 0, 0, 0, 0, 0, 0, 0, 52,
1013 0, 53, 59, 40, 0, 0, 0, 0, 0, 12,
1014 39, 0, 8, 0, 0, 61, 37, 0, 58, 57,
1015 48, 49, 50, 51, 46, 47, 0, 34, 35, 36,
1016 38, 80, 81, 59, 40, 0, 0, 0, 34, 35,
1017 36, 0, 43, 0, 0, 39, 0, 41, 80, 81,
1018 61, 37, 42, 58, 57, 48, 49, 50, 51, 46,
1019 47, 38, 34, 35, 36, 80, 81, 0, 59, 40,
1020 0, 0, 0, 0, 43, 0, 0, 39, 0, 41,
1021 44, 0, 45, 37, 42, 0, 0, 0, 0, 57,
1022 48, 49, 50, 51, 46, 47, 38, 34, 35, 36,
1023 59, 40, 14, 15, 16, 26, 28, 21, 29, 30,
1024 31, 11, 32, 25, 18, 19, 20, 0, 22, 0,
1025 0, 0, 0, 0, 0, 0, 0, 0, 38, 9,
1026 10, 48, 49, 50, 51, 46, 47, 0, 34, 35,
1027 36, 0, 0, 14, 15, 16, 26, 28, 21, 29,
1028 30, 31, 11, 32, 25, 18, 19, 20, 43, 22,
1029 0, 39, 0, 41, 44, 0, 45, 37, 42, 0,
1030 9, 10, 0, 48, 49, 50, 51, 46, 47, 0,
1031 34, 35, 36, 43, 59, 40, 39, 0, 41, 44,
1032 24, 45, 37, 42, 73, 0, 29, 30, 31, 0,
1033 32, 0, 0, 72, 76, 0, 52, 0, 53, 59,
1034 40, 0, 38, 0, 0, 0, 48, 49, 50, 51,
1035 46, 47, 0, 34, 35, 36, 43, 0, 0, 39,
1036 0, 41, 44, 27, 45, 37, 42, 38, 0, 0,
1037 0, 0, 0, 0, 0, 0, 0, 0, 0, 52,
1038 0, 53, 59, 40, 34, 35, 36, 0, 0, 79,
1039 0, 76, 0, 82, 83, 84, 85, 0, 0, 0,
1040 87, 89, 0, 0, 0, 0, 0, 0, 0, 0,
1041 38, 0, 0, 0, 0, 0, 0, 0, 0, 34,
1042 35, 36, 0, 0, 0, 0, 0, 0, 0, 0,
1043 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1044 134, 124, 125, 0, 0, 0, 0, 0, 46, 47,
1045 3, 34, 35, 36, 0, 62, 63, 64, 65, 66,
1046 67, 68, 69, 0, 0, 72, 0, 0, 0, 0,
1047 72, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1048 0, 0, 0, 0, 86, 0, 0, 125, 0, 0,
1049 0, 93, 94, 95, 96, 97, 98, 99, 100, 101,
1050 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
1051 112, 113, 114, 0, 0, 0, 0, 0, 0, 0,
1052 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1053 0, 0, 0, 0, 0, 34, 35, 36, 0, 126,
1054 0, 127, 0, 130, 0, 0, 0, 0, 0, 0,
1055 0, 0, 0, 48, 49, 50, 51, 46, 47, 0,
1056 34, 35, 36, 0, 0, 0, 0, 133, 0, 0,
1057 0, 0, 136, 0, 0, 0, 0, 0, 0, 0,
1058 0, 0, 139, 136, 0, 0, 0, 0, 0, 141,
1059 0, 0, 0, 0, 0, 0, 0, 0, 50, 51,
1060 46, 47, 0, 34, 35, 36 };
1061short yypact[]={
1062
1063 65,-1000, -22, -2, 65, 65, 65, 65, 65, 65,
1064 65, 106,-248, 65,-1000,-1000,-1000,-1000,-1000,-1000,
1065-1000,-1000,-1000,-256,-257,-232,-1000,-1000,-1000,-232,
1066-232,-232,-232, 65,-1000,-1000, 25, 8, 65,-1000,
1067 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
1068 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
1069 65, 65, -26, -26, -26, -26, -26, -26, -26, -26,
1070 65, 44,-261,-1000, 132, 7,-264,-232,-232,-1000,
1071-1000,-1000,-1000,-1000,-1000,-1000, -2,-1000, 65,-1000,
1072 65, -12, 65, -26, 190, 190, 190, 225, 225, 341,
1073 341, 409, 409, 257, 257, 257, 257, 366, 159, 116,
1074 74, 33, -37, -2, -2, 88, 65,-1000,-1000,-248,
1075 -3, 65,-1000, -9,-1000,-1000, 190, 190,-1000, 5,
1076 -2, 65, 65, -26,-266,-1000, -26,-1000, 65, -2,
1077 -24, -2, -11, 12, 153,-1000, -10, 26,-1000,-248,
1078 26 };
1079short yypgo[]={
1080
1081 0, 540, 101, 72, 69, 42, 410, 63, 55, 453,
1082 53, 47 };
1083short yyr1[]={
1084
1085 0, 3, 2, 2, 1, 1, 1, 1, 1, 1,
1086 1, 1, 1, 1, 1, 1, 1, 1, 1, 10,
1087 1, 11, 11, 11, 1, 1, 1, 1, 1, 1,
1088 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1089 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1090 1, 1, 1, 1, 1, 1, 1, 1, 1, 8,
1091 8, 4, 4, 4, 4, 5, 5, 5, 5, 5,
1092 5, 5, 6, 6, 6, 6, 6, 7, 7, 9,
1093 9 };
1094short yyr2[]={
1095
1096 0, 1, 1, 3, 2, 2, 2, 2, 2, 2,
1097 2, 2, 2, 2, 3, 4, 3, 4, 4, 0,
1098 5, 0, 1, 3, 4, 4, 3, 3, 3, 3,
1099 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1100 3, 3, 3, 3, 3, 3, 5, 3, 3, 1,
1101 1, 1, 1, 1, 1, 1, 4, 1, 1, 1,
1102 3, 3, 3, 2, 1, 1, 2, 2, 3, 6,
1103 8, 9, 1, 2, 2, 2, 2, 1, 3, 1,
1104 1 };
1105short yychk[]={
1106
1107-1000, -3, -2, -1, 42, 38, 45, 33, 126, 284,
1108 285, 266, 123, 40, 257, 258, 259, -4, 269, 270,
1109 271, 262, 273, -8, -6, 268, 260, -9, 261, 263,
1110 264, 265, 267, 44, 284, 285, 286, 46, 91, 40,
1111 64, 42, 47, 37, 43, 45, 281, 282, 277, 278,
1112 279, 280, 60, 62, 38, 94, 124, 276, 275, 63,
1113 61, 272, -1, -1, -1, -1, -1, -1, -1, -1,
1114 40, -5, -6, 261, -5, -2, -6, 268, 268, -9,
1115 260, 261, -9, -9, -9, -9, -1, -9, 42, -9,
1116 42, -2, -10, -1, -1, -1, -1, -1, -1, -1,
1117 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1118 -1, -1, -1, -1, -1, -5, 125, 42, 38, 40,
1119 268, 41, 41, 268, -9, -9, -1, -1, 93, -11,
1120 -1, 58, 41, -1, -6, 42, -1, 41, 44, -1,
1121 268, -1, 42, 41, 40, 41, -7, -5, 41, 44,
1122 -5 };
1123short yydef[]={
1124
1125 0, -2, 1, 2, 0, 0, 0, 0, 0, 0,
1126 0, 0, 0, 0, 49, 50, 51, 52, 53, 54,
1127 55, 57, 58, 0, 0, 0, -2, 59, 72, 0,
1128 0, 0, 0, 0, 11, 12, 0, 0, 0, 19,
1129 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1130 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1131 0, 0, 4, 5, 6, 7, 8, 9, 10, 13,
1132 0, 0, 65, 72, 0, 0, 65, 0, 0, 63,
1133 79, 80, 73, 74, 75, 76, 3, 14, 0, 16,
1134 0, 0, 21, 27, 28, 29, 30, 31, 32, 33,
1135 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
1136 44, 45, 0, 47, 48, 0, 0, 66, 67, 0,
1137 0, 0, 26, 0, -2, 62, 15, 17, 18, 0,
1138 22, 0, 56, 24, 0, 68, 25, 20, 0, 46,
1139 0, 23, 0, 69, 0, 70, 0, 77, 71, 0,
1140 78 };
1141#ifndef lint
e91b87a3 1142static char yaccpar_sccsid[] = "@(#)yaccpar 1.5 86/08/27 SMI"; /* from UCB 4.1 83/02/11 */
bb7592f0 1143#endif
1144
1145#
1146# define YYFLAG -1000
1147# define YYERROR goto yyerrlab
1148# define YYACCEPT return(0)
1149# define YYABORT return(1)
1150
1151/* parser for yacc output */
1152
1153#ifdef YYDEBUG
1154int yydebug = 0; /* 1 for debugging */
1155#endif
1156YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
1157int yychar = -1; /* current input token number */
1158int yynerrs = 0; /* number of errors */
1159short yyerrflag = 0; /* error recovery flag */
1160
1161yyparse() {
1162
1163 short yys[YYMAXDEPTH];
1164 short yyj, yym;
1165 register YYSTYPE *yypvt;
1166 register short yystate, *yyps, yyn;
1167 register YYSTYPE *yypv;
1168 register short *yyxi;
1169
1170 yystate = 0;
1171 yychar = -1;
1172 yynerrs = 0;
1173 yyerrflag = 0;
1174 yyps= &yys[-1];
1175 yypv= &yyv[-1];
1176
1177 yystack: /* put a state and value onto the stack */
1178
1179#ifdef YYDEBUG
1180 if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar );
1181#endif
1182 if( ++yyps>= &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
1183 *yyps = yystate;
1184 ++yypv;
1185 *yypv = yyval;
1186
1187 yynewstate:
1188
1189 yyn = yypact[yystate];
1190
1191 if( yyn<= YYFLAG ) goto yydefault; /* simple state */
1192
1193 if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
1194 if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
1195
1196 if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
1197 yychar = -1;
1198 yyval = yylval;
1199 yystate = yyn;
1200 if( yyerrflag > 0 ) --yyerrflag;
1201 goto yystack;
1202 }
1203
1204 yydefault:
1205 /* default state action */
1206
1207 if( (yyn=yydef[yystate]) == -2 ) {
1208 if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
1209 /* look through exception table */
1210
1211 for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
1212
1213 while( *(yyxi+=2) >= 0 ){
1214 if( *yyxi == yychar ) break;
1215 }
1216 if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */
1217 }
1218
1219 if( yyn == 0 ){ /* error */
1220 /* error ... attempt to resume parsing */
1221
1222 switch( yyerrflag ){
1223
1224 case 0: /* brand new error */
1225
1226 yyerror( "syntax error" );
1227 yyerrlab:
1228 ++yynerrs;
1229
1230 case 1:
1231 case 2: /* incompletely recovered error ... try again */
1232
1233 yyerrflag = 3;
1234
1235 /* find a state where "error" is a legal shift action */
1236
1237 while ( yyps >= yys ) {
1238 yyn = yypact[*yyps] + YYERRCODE;
1239 if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
1240 yystate = yyact[yyn]; /* simulate a shift of "error" */
1241 goto yystack;
1242 }
1243 yyn = yypact[*yyps];
1244
1245 /* the current yyps has no shift onn "error", pop stack */
1246
1247#ifdef YYDEBUG
1248 if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
1249#endif
1250 --yyps;
1251 --yypv;
1252 }
1253
1254 /* there is no state on the stack with an error shift ... abort */
1255
1256 yyabort:
1257 return(1);
1258
1259
1260 case 3: /* no shift yet; clobber input char */
1261
1262#ifdef YYDEBUG
1263 if( yydebug ) printf( "error recovery discards char %d\n", yychar );
1264#endif
1265
1266 if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
1267 yychar = -1;
1268 goto yynewstate; /* try again in the same state */
1269
1270 }
1271
1272 }
1273
1274 /* reduction by production yyn */
1275
1276#ifdef YYDEBUG
1277 if( yydebug ) printf("reduce %d\n",yyn);
1278#endif
1279 yyps -= yyr2[yyn];
1280 yypvt = yypv;
1281 yypv -= yyr2[yyn];
1282 yyval = yypv[1];
1283 yym=yyn;
1284 /* consult goto table to find next state */
1285 yyn = yyr1[yyn];
1286 yyj = yypgo[yyn] + *yyps + 1;
1287 if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
1288 switch(yym){
1289
1290case 3:
e91b87a3 1291# line 165 "expread.y"
1292{ write_exp_elt_opcode (BINOP_COMMA); } break;
bb7592f0 1293case 4:
e91b87a3 1294# line 170 "expread.y"
1295{ write_exp_elt_opcode (UNOP_IND); } break;
bb7592f0 1296case 5:
e91b87a3 1297# line 173 "expread.y"
1298{ write_exp_elt_opcode (UNOP_ADDR); } break;
bb7592f0 1299case 6:
e91b87a3 1300# line 176 "expread.y"
1301{ write_exp_elt_opcode (UNOP_NEG); } break;
bb7592f0 1302case 7:
e91b87a3 1303# line 180 "expread.y"
1304{ write_exp_elt_opcode (UNOP_ZEROP); } break;
bb7592f0 1305case 8:
e91b87a3 1306# line 184 "expread.y"
1307{ write_exp_elt_opcode (UNOP_LOGNOT); } break;
bb7592f0 1308case 9:
e91b87a3 1309# line 188 "expread.y"
1310{ write_exp_elt_opcode (UNOP_PREINCREMENT); } break;
bb7592f0 1311case 10:
e91b87a3 1312# line 192 "expread.y"
1313{ write_exp_elt_opcode (UNOP_PREDECREMENT); } break;
bb7592f0 1314case 11:
e91b87a3 1315# line 196 "expread.y"
1316{ write_exp_elt_opcode (UNOP_POSTINCREMENT); } break;
bb7592f0 1317case 12:
e91b87a3 1318# line 200 "expread.y"
1319{ write_exp_elt_opcode (UNOP_POSTDECREMENT); } break;
bb7592f0 1320case 13:
e91b87a3 1321# line 204 "expread.y"
1322{ write_exp_elt_opcode (UNOP_SIZEOF); } break;
bb7592f0 1323case 14:
e91b87a3 1324# line 208 "expread.y"
1325{ write_exp_elt_opcode (STRUCTOP_PTR);
bb7592f0 1326 write_exp_string (yypvt[-0].sval);
e91b87a3 1327 write_exp_elt_opcode (STRUCTOP_PTR); } break;
bb7592f0 1328case 15:
e91b87a3 1329# line 214 "expread.y"
1330{ write_exp_elt_opcode (STRUCTOP_MPTR); } break;
bb7592f0 1331case 16:
e91b87a3 1332# line 218 "expread.y"
1333{ write_exp_elt_opcode (STRUCTOP_STRUCT);
bb7592f0 1334 write_exp_string (yypvt[-0].sval);
e91b87a3 1335 write_exp_elt_opcode (STRUCTOP_STRUCT); } break;
bb7592f0 1336case 17:
e91b87a3 1337# line 224 "expread.y"
1338{ write_exp_elt_opcode (STRUCTOP_MEMBER); } break;
bb7592f0 1339case 18:
bb7592f0 1340# line 228 "expread.y"
e91b87a3 1341{ write_exp_elt_opcode (BINOP_SUBSCRIPT); } break;
1342case 19:
1343# line 234 "expread.y"
bb7592f0 1344{ start_arglist (); } break;
1345case 20:
e91b87a3 1346# line 236 "expread.y"
1347{ write_exp_elt_opcode (OP_FUNCALL);
1348 write_exp_elt_longcst (end_arglist ());
1349 write_exp_elt_opcode (OP_FUNCALL); } break;
bb7592f0 1350case 22:
e91b87a3 1351# line 245 "expread.y"
bb7592f0 1352{ arglist_len = 1; } break;
1353case 23:
e91b87a3 1354# line 249 "expread.y"
bb7592f0 1355{ arglist_len++; } break;
1356case 24:
bb7592f0 1357# line 253 "expread.y"
e91b87a3 1358{ write_exp_elt_opcode (UNOP_MEMVAL);
1359 write_exp_elt_type (yypvt[-2].tval);
1360 write_exp_elt_opcode (UNOP_MEMVAL); } break;
1361case 25:
bb7592f0 1362# line 259 "expread.y"
e91b87a3 1363{ write_exp_elt_opcode (UNOP_CAST);
1364 write_exp_elt_type (yypvt[-2].tval);
1365 write_exp_elt_opcode (UNOP_CAST); } break;
1366case 26:
1367# line 265 "expread.y"
bb7592f0 1368{ } break;
1369case 27:
e91b87a3 1370# line 271 "expread.y"
1371{ write_exp_elt_opcode (BINOP_REPEAT); } break;
bb7592f0 1372case 28:
e91b87a3 1373# line 275 "expread.y"
1374{ write_exp_elt_opcode (BINOP_MUL); } break;
bb7592f0 1375case 29:
e91b87a3 1376# line 279 "expread.y"
1377{ write_exp_elt_opcode (BINOP_DIV); } break;
bb7592f0 1378case 30:
e91b87a3 1379# line 283 "expread.y"
1380{ write_exp_elt_opcode (BINOP_REM); } break;
bb7592f0 1381case 31:
e91b87a3 1382# line 287 "expread.y"
1383{ write_exp_elt_opcode (BINOP_ADD); } break;
bb7592f0 1384case 32:
e91b87a3 1385# line 291 "expread.y"
1386{ write_exp_elt_opcode (BINOP_SUB); } break;
bb7592f0 1387case 33:
e91b87a3 1388# line 295 "expread.y"
1389{ write_exp_elt_opcode (BINOP_LSH); } break;
bb7592f0 1390case 34:
e91b87a3 1391# line 299 "expread.y"
1392{ write_exp_elt_opcode (BINOP_RSH); } break;
bb7592f0 1393case 35:
e91b87a3 1394# line 303 "expread.y"
1395{ write_exp_elt_opcode (BINOP_EQUAL); } break;
bb7592f0 1396case 36:
e91b87a3 1397# line 307 "expread.y"
1398{ write_exp_elt_opcode (BINOP_NOTEQUAL); } break;
bb7592f0 1399case 37:
e91b87a3 1400# line 311 "expread.y"
1401{ write_exp_elt_opcode (BINOP_LEQ); } break;
bb7592f0 1402case 38:
e91b87a3 1403# line 315 "expread.y"
1404{ write_exp_elt_opcode (BINOP_GEQ); } break;
bb7592f0 1405case 39:
e91b87a3 1406# line 319 "expread.y"
1407{ write_exp_elt_opcode (BINOP_LESS); } break;
bb7592f0 1408case 40:
e91b87a3 1409# line 323 "expread.y"
1410{ write_exp_elt_opcode (BINOP_GTR); } break;
bb7592f0 1411case 41:
e91b87a3 1412# line 327 "expread.y"
1413{ write_exp_elt_opcode (BINOP_LOGAND); } break;
bb7592f0 1414case 42:
e91b87a3 1415# line 331 "expread.y"
1416{ write_exp_elt_opcode (BINOP_LOGXOR); } break;
bb7592f0 1417case 43:
e91b87a3 1418# line 335 "expread.y"
1419{ write_exp_elt_opcode (BINOP_LOGIOR); } break;
bb7592f0 1420case 44:
e91b87a3 1421# line 339 "expread.y"
1422{ write_exp_elt_opcode (BINOP_AND); } break;
bb7592f0 1423case 45:
e91b87a3 1424# line 343 "expread.y"
1425{ write_exp_elt_opcode (BINOP_OR); } break;
bb7592f0 1426case 46:
e91b87a3 1427# line 347 "expread.y"
1428{ write_exp_elt_opcode (TERNOP_COND); } break;
bb7592f0 1429case 47:
e91b87a3 1430# line 351 "expread.y"
1431{ write_exp_elt_opcode (BINOP_ASSIGN); } break;
bb7592f0 1432case 48:
bb7592f0 1433# line 355 "expread.y"
e91b87a3 1434{ write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
1435 write_exp_elt_opcode (yypvt[-1].opcode);
1436 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } break;
1437case 49:
1438# line 361 "expread.y"
1439{ write_exp_elt_opcode (OP_LONG);
1440 write_exp_elt_type (builtin_type_long);
1441 write_exp_elt_longcst (yypvt[-0].lval);
1442 write_exp_elt_opcode (OP_LONG); } break;
bb7592f0 1443case 50:
e91b87a3 1444# line 368 "expread.y"
1445{ write_exp_elt_opcode (OP_LONG);
1446 write_exp_elt_type (builtin_type_char);
1447 write_exp_elt_longcst (yypvt[-0].lval);
1448 write_exp_elt_opcode (OP_LONG); } break;
bb7592f0 1449case 51:
e91b87a3 1450# line 375 "expread.y"
1451{ write_exp_elt_opcode (OP_DOUBLE);
1452 write_exp_elt_type (builtin_type_double);
1453 write_exp_elt_dblcst (yypvt[-0].dval);
1454 write_exp_elt_opcode (OP_DOUBLE); } break;
bb7592f0 1455case 53:
bb7592f0 1456# line 385 "expread.y"
e91b87a3 1457{ write_exp_elt_opcode (OP_LAST);
1458 write_exp_elt_longcst (yypvt[-0].lval);
1459 write_exp_elt_opcode (OP_LAST); } break;
1460case 54:
bb7592f0 1461# line 391 "expread.y"
e91b87a3 1462{ write_exp_elt_opcode (OP_REGISTER);
1463 write_exp_elt_longcst (yypvt[-0].lval);
1464 write_exp_elt_opcode (OP_REGISTER); } break;
1465case 55:
bb7592f0 1466# line 397 "expread.y"
e91b87a3 1467{ write_exp_elt_opcode (OP_INTERNALVAR);
1468 write_exp_elt_intern (yypvt[-0].ivar);
1469 write_exp_elt_opcode (OP_INTERNALVAR); } break;
1470case 56:
1471# line 403 "expread.y"
1472{ write_exp_elt_opcode (OP_LONG);
1473 write_exp_elt_type (builtin_type_int);
1474 write_exp_elt_longcst ((long) TYPE_LENGTH (yypvt[-1].tval));
1475 write_exp_elt_opcode (OP_LONG); } break;
bb7592f0 1476case 57:
e91b87a3 1477# line 410 "expread.y"
1478{ write_exp_elt_opcode (OP_STRING);
bb7592f0 1479 write_exp_string (yypvt[-0].sval);
e91b87a3 1480 write_exp_elt_opcode (OP_STRING); } break;
bb7592f0 1481case 58:
e91b87a3 1482# line 417 "expread.y"
1483{ write_exp_elt_opcode (OP_THIS);
1484 write_exp_elt_opcode (OP_THIS); } break;
bb7592f0 1485case 59:
e91b87a3 1486# line 424 "expread.y"
bb7592f0 1487{
1488 struct symtab *tem = lookup_symtab (copy_name (yypvt[-0].sval));
1489 struct symbol *sym;
1490
1491 if (tem)
1492 yyval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), 1);
1493 else
1494 {
1495 sym = lookup_symbol (copy_name (yypvt[-0].sval),
1496 expression_context_block,
e91b87a3 1497 VAR_NAMESPACE, 0);
bb7592f0 1498 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1499 yyval.bval = SYMBOL_BLOCK_VALUE (sym);
1500 else
1501 error ("No file or function \"%s\".",
1502 copy_name (yypvt[-0].sval));
1503 }
1504 } break;
1505case 60:
e91b87a3 1506# line 445 "expread.y"
1507{ struct symbol *tem
1508 = lookup_symbol (copy_name (yypvt[-0].sval), yypvt[-2].bval, VAR_NAMESPACE, 0);
bb7592f0 1509 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
1510 error ("No function \"%s\" in specified context.",
1511 copy_name (yypvt[-0].sval));
e91b87a3 1512 yyval.bval = SYMBOL_BLOCK_VALUE (tem); } break;
bb7592f0 1513case 61:
e91b87a3 1514# line 454 "expread.y"
1515{ struct symbol *sym;
1516 sym = lookup_symbol (copy_name (yypvt[-0].sval), yypvt[-2].bval, VAR_NAMESPACE, 0);
bb7592f0 1517 if (sym == 0)
1518 error ("No symbol \"%s\" in specified context.",
1519 copy_name (yypvt[-0].sval));
e91b87a3 1520 write_exp_elt_opcode (OP_VAR_VALUE);
1521 write_exp_elt_sym (sym);
1522 write_exp_elt_opcode (OP_VAR_VALUE); } break;
bb7592f0 1523case 62:
e91b87a3 1524# line 465 "expread.y"
bb7592f0 1525{
1526 struct type *type = yypvt[-2].tval;
1527 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1528 && TYPE_CODE (type) != TYPE_CODE_UNION)
1529 error ("`%s' is not defined as an aggregate type.",
1530 TYPE_NAME (type));
1531
e91b87a3 1532 write_exp_elt_opcode (OP_SCOPE);
1533 write_exp_elt_type (type);
bb7592f0 1534 write_exp_string (yypvt[-0].sval);
e91b87a3 1535 write_exp_elt_opcode (OP_SCOPE);
bb7592f0 1536 } break;
1537case 63:
e91b87a3 1538# line 478 "expread.y"
bb7592f0 1539{
1540 char *name = copy_name (yypvt[-0].sval);
1541 struct symbol *sym;
1542 int i;
1543
e91b87a3 1544 sym = lookup_symbol (name, 0, VAR_NAMESPACE, 0);
bb7592f0 1545 if (sym)
1546 {
e91b87a3 1547 write_exp_elt_opcode (OP_VAR_VALUE);
1548 write_exp_elt_sym (sym);
1549 write_exp_elt_opcode (OP_VAR_VALUE);
bb7592f0 1550 break;
1551 }
1552 for (i = 0; i < misc_function_count; i++)
1553 if (!strcmp (misc_function_vector[i].name, name))
1554 break;
1555
1556 if (i < misc_function_count)
1557 {
e91b87a3 1558 write_exp_elt_opcode (OP_LONG);
1559 write_exp_elt_type (builtin_type_int);
1560 write_exp_elt_longcst (misc_function_vector[i].address);
1561 write_exp_elt_opcode (OP_LONG);
1562 write_exp_elt_opcode (UNOP_MEMVAL);
1563 write_exp_elt_type (builtin_type_char);
1564 write_exp_elt_opcode (UNOP_MEMVAL);
bb7592f0 1565 }
1566 else
e91b87a3 1567 if (symtab_list == 0
1568 && partial_symtab_list == 0)
bb7592f0 1569 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1570 else
1571 error ("No symbol \"%s\" in current context.", name);
1572 } break;
1573case 64:
e91b87a3 1574# line 515 "expread.y"
bb7592f0 1575{ struct symbol *sym;
e91b87a3 1576 int is_a_field_of_this;
1577
1578 sym = lookup_symbol (copy_name (yypvt[-0].sval),
1579 expression_context_block,
1580 VAR_NAMESPACE,
1581 &is_a_field_of_this);
bb7592f0 1582 if (sym)
1583 {
e91b87a3 1584 switch (sym->class)
1585 {
1586 case LOC_REGISTER:
1587 case LOC_ARG:
1588 case LOC_LOCAL:
1589 if (innermost_block == 0 ||
1590 contained_in (block_found,
1591 innermost_block))
1592 innermost_block = block_found;
1593 }
1594 write_exp_elt_opcode (OP_VAR_VALUE);
1595 write_exp_elt_sym (sym);
1596 write_exp_elt_opcode (OP_VAR_VALUE);
bb7592f0 1597 }
e91b87a3 1598 else if (is_a_field_of_this)
bb7592f0 1599 {
e91b87a3 1600 /* C++: it hangs off of `this'. Must
bb7592f0 1601 not inadvertently convert from a method call
1602 to data ref. */
e91b87a3 1603 if (innermost_block == 0 ||
1604 contained_in (block_found, innermost_block))
1605 innermost_block = block_found;
1606 write_exp_elt_opcode (OP_THIS);
1607 write_exp_elt_opcode (OP_THIS);
1608 write_exp_elt_opcode (STRUCTOP_PTR);
1609 write_exp_string (yypvt[-0].sval);
1610 write_exp_elt_opcode (STRUCTOP_PTR);
1611 }
1612 else
1613 {
1614 register int i;
1615 register char *arg = copy_name (yypvt[-0].sval);
1616
bb7592f0 1617 for (i = 0; i < misc_function_count; i++)
1618 if (!strcmp (misc_function_vector[i].name, arg))
1619 break;
1620
1621 if (i < misc_function_count)
1622 {
e91b87a3 1623 write_exp_elt_opcode (OP_LONG);
1624 write_exp_elt_type (builtin_type_int);
1625 write_exp_elt_longcst (misc_function_vector[i].address);
1626 write_exp_elt_opcode (OP_LONG);
1627 write_exp_elt_opcode (UNOP_MEMVAL);
1628 write_exp_elt_type (builtin_type_char);
1629 write_exp_elt_opcode (UNOP_MEMVAL);
bb7592f0 1630 }
e91b87a3 1631 else if (symtab_list == 0
1632 && partial_symtab_list == 0)
1633 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
bb7592f0 1634 else
e91b87a3 1635 error ("No symbol \"%s\" in current context.",
1636 copy_name (yypvt[-0].sval));
bb7592f0 1637 }
1638 } break;
1639case 66:
e91b87a3 1640# line 583 "expread.y"
bb7592f0 1641{ yyval.tval = lookup_pointer_type (yypvt[-1].tval); } break;
1642case 67:
e91b87a3 1643# line 585 "expread.y"
bb7592f0 1644{ yyval.tval = lookup_reference_type (yypvt[-1].tval); } break;
1645case 68:
e91b87a3 1646# line 587 "expread.y"
bb7592f0 1647{ yyval.tval = lookup_member_type (builtin_type_int, yypvt[-2].tval); } break;
1648case 69:
e91b87a3 1649# line 589 "expread.y"
bb7592f0 1650{ yyval.tval = lookup_member_type (yypvt[-5].tval, yypvt[-3].tval); } break;
1651case 70:
e91b87a3 1652# line 591 "expread.y"
1653{ yyval.tval = lookup_member_type (lookup_function_type (yypvt[-7].tval)); } break;
bb7592f0 1654case 71:
e91b87a3 1655# line 593 "expread.y"
1656{ yyval.tval = lookup_member_type (lookup_function_type (yypvt[-8].tval));
bb7592f0 1657 free (yypvt[-1].tvec); } break;
1658case 72:
e91b87a3 1659# line 599 "expread.y"
bb7592f0 1660{ yyval.tval = lookup_typename (copy_name (yypvt[-0].sval),
1661 expression_context_block, 0); } break;
1662case 73:
e91b87a3 1663# line 602 "expread.y"
bb7592f0 1664{ yyval.tval = lookup_struct (copy_name (yypvt[-0].sval),
1665 expression_context_block); } break;
1666case 74:
e91b87a3 1667# line 605 "expread.y"
bb7592f0 1668{ yyval.tval = lookup_union (copy_name (yypvt[-0].sval),
1669 expression_context_block); } break;
1670case 75:
e91b87a3 1671# line 608 "expread.y"
bb7592f0 1672{ yyval.tval = lookup_enum (copy_name (yypvt[-0].sval),
1673 expression_context_block); } break;
1674case 76:
e91b87a3 1675# line 611 "expread.y"
bb7592f0 1676{ yyval.tval = lookup_unsigned_typename (copy_name (yypvt[-0].sval)); } break;
1677case 77:
e91b87a3 1678# line 616 "expread.y"
bb7592f0 1679{ yyval.tvec = (struct type **)xmalloc (sizeof (struct type *) * 2);
1680 yyval.tvec[0] = (struct type *)0;
1681 yyval.tvec[1] = yypvt[-0].tval;
1682 } break;
1683case 78:
e91b87a3 1684# line 621 "expread.y"
bb7592f0 1685{ int len = sizeof (struct type *) * ++(yypvt[-2].ivec[0]);
1686 yyval.tvec = (struct type **)xrealloc (yypvt[-2].tvec, len);
1687 yyval.tvec[yyval.ivec[0]] = yypvt[-0].tval;
1688 } break;
1689 }
1690 goto yystack; /* stack new state and value */
1691
1692 }
This page took 0.092646 seconds and 4 git commands to generate.