* config/arm/tm-arm.h (TARGET_DOUBLE_FORMAT): Define to use
[deliverable/binutils-gdb.git] / gdb / java-exp.y
CommitLineData
7a9eb4c4
PB
1/* YACC parser for Java expressions, for GDB.
2 Copyright (C) 1997.
3 Free Software Foundation, Inc.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21/* Parse a C expression from text in a string,
22 and return the result as a struct expression pointer.
23 That structure contains arithmetic operations in reverse polish,
24 with constants represented by operations that are followed by special data.
25 See expression.h for the details of the format.
26 What is important here is that it can be built up sequentially
27 during the process of parsing; the lower levels of the tree always
28 come first in the result.
29
30 Note that malloc's and realloc's in this file are transformed to
31 xmalloc and xrealloc respectively by the same sed command in the
32 makefile that remaps any other malloc/realloc inserted by the parser
33 generator. Doing this with #defines and trying to control the interaction
34 with include files (<malloc.h> and <stdlib.h> for example) just became
35 too messy, particularly when such includes can be inserted at random
36 times by the parser generator. */
37
38%{
39
40#include "defs.h"
41#include "gdb_string.h"
42#include <ctype.h>
43#include "expression.h"
44#include "value.h"
45#include "parser-defs.h"
46#include "language.h"
47#include "java-lang.h"
48#include "bfd.h" /* Required by objfiles.h. */
49#include "symfile.h" /* Required by objfiles.h. */
50#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
51
52/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
53 as well as gratuitiously global symbol names, so we can have multiple
54 yacc generated parsers in gdb. Note that these are only the variables
55 produced by yacc. If other parser generators (bison, byacc, etc) produce
56 additional global names that conflict at link time, then those parser
57 generators need to be fixed instead of adding those names to this list. */
58
59#define yymaxdepth java_maxdepth
60#define yyparse java_parse
61#define yylex java_lex
62#define yyerror java_error
63#define yylval java_lval
64#define yychar java_char
65#define yydebug java_debug
66#define yypact java_pact
67#define yyr1 java_r1
68#define yyr2 java_r2
69#define yydef java_def
70#define yychk java_chk
71#define yypgo java_pgo
72#define yyact java_act
73#define yyexca java_exca
74#define yyerrflag java_errflag
75#define yynerrs java_nerrs
76#define yyps java_ps
77#define yypv java_pv
78#define yys java_s
79#define yy_yys java_yys
80#define yystate java_state
81#define yytmp java_tmp
82#define yyv java_v
83#define yy_yyv java_yyv
84#define yyval java_val
85#define yylloc java_lloc
86#define yyreds java_reds /* With YYDEBUG defined */
87#define yytoks java_toks /* With YYDEBUG defined */
88#define yylhs java_yylhs
89#define yylen java_yylen
90#define yydefred java_yydefred
91#define yydgoto java_yydgoto
92#define yysindex java_yysindex
93#define yyrindex java_yyrindex
94#define yygindex java_yygindex
95#define yytable java_yytable
96#define yycheck java_yycheck
97
98#ifndef YYDEBUG
99#define YYDEBUG 0 /* Default to no yydebug support */
100#endif
101
102int
103yyparse PARAMS ((void));
104
105static int
106yylex PARAMS ((void));
107
108void
109yyerror PARAMS ((char *));
110
111static struct type * java_type_from_name PARAMS ((struct stoken));
112static void push_variable PARAMS ((struct stoken));
113
114%}
115
116/* Although the yacc "value" of an expression is not used,
117 since the result is stored in the structure being created,
118 other node types do have values. */
119
120%union
121 {
122 LONGEST lval;
123 struct {
124 LONGEST val;
125 struct type *type;
126 } typed_val_int;
127 struct {
128 DOUBLEST dval;
129 struct type *type;
130 } typed_val_float;
131 struct symbol *sym;
132 struct type *tval;
133 struct stoken sval;
134 struct ttype tsym;
135 struct symtoken ssym;
136 struct block *bval;
137 enum exp_opcode opcode;
138 struct internalvar *ivar;
139 int *ivec;
140 }
141
142%{
143/* YYSTYPE gets defined by %union */
144static int
145parse_number PARAMS ((char *, int, int, YYSTYPE *));
146%}
147
75a947c6 148%type <lval> rcurly Dims Dims_opt
7a9eb4c4
PB
149%type <tval> ClassOrInterfaceType ClassType /* ReferenceType Type ArrayType */
150%type <tval> IntegralType FloatingPointType NumericType PrimitiveType
151
152%token <typed_val_int> INTEGER_LITERAL
153%token <typed_val_float> FLOATING_POINT_LITERAL
154
155%token <sval> IDENTIFIER
156%token <sval> STRING_LITERAL
75a947c6 157%token <lval> BOOLEAN_LITERAL
7a9eb4c4
PB
158%token <tsym> TYPENAME
159%type <sval> Name SimpleName QualifiedName ForcedName
160
161/* A NAME_OR_INT is a symbol which is not known in the symbol table,
162 but which would parse as a valid number in the current input radix.
163 E.g. "c" when input_radix==16. Depending on the parse, it will be
164 turned into a name or into a number. */
165
166%token <sval> NAME_OR_INT
167
168%token ERROR
169
170/* Special type cases, put in to allow the parser to distinguish different
171 legal basetypes. */
172%token LONG SHORT BYTE INT CHAR BOOLEAN DOUBLE FLOAT
173
174%token VARIABLE
175
176%token <opcode> ASSIGN_MODIFY
177
75a947c6 178%token THIS SUPER NEW
7a9eb4c4
PB
179
180%left ','
181%right '=' ASSIGN_MODIFY
182%right '?'
183%left OROR
184%left ANDAND
185%left '|'
186%left '^'
187%left '&'
188%left EQUAL NOTEQUAL
189%left '<' '>' LEQ GEQ
190%left LSH RSH
191%left '+' '-'
192%left '*' '/' '%'
193%right INCREMENT DECREMENT
194%right '.' '[' '('
195
196\f
197%%
198
199start : exp1
200/* | type_exp FIXME */
201 ;
202
203StringLiteral:
204 STRING_LITERAL
205 {
206 write_exp_elt_opcode (OP_STRING);
207 write_exp_string ($1);
208 write_exp_elt_opcode (OP_STRING);
209 }
210;
211
7a9eb4c4
PB
212Literal :
213 INTEGER_LITERAL
214 { write_exp_elt_opcode (OP_LONG);
215 write_exp_elt_type ($1.type);
216 write_exp_elt_longcst ((LONGEST)($1.val));
217 write_exp_elt_opcode (OP_LONG); }
218| NAME_OR_INT
219 { YYSTYPE val;
220 parse_number ($1.ptr, $1.length, 0, &val);
221 write_exp_elt_opcode (OP_LONG);
222 write_exp_elt_type (val.typed_val_int.type);
223 write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
224 write_exp_elt_opcode (OP_LONG);
225 }
226| FLOATING_POINT_LITERAL
227 { write_exp_elt_opcode (OP_DOUBLE);
228 write_exp_elt_type ($1.type);
229 write_exp_elt_dblcst ($1.dval);
230 write_exp_elt_opcode (OP_DOUBLE); }
75a947c6 231| BOOLEAN_LITERAL
7a9eb4c4
PB
232 { write_exp_elt_opcode (OP_LONG);
233 write_exp_elt_type (java_boolean_type);
234 write_exp_elt_longcst ((LONGEST)$1);
235 write_exp_elt_opcode (OP_LONG); }
236| StringLiteral
237 ;
238
239/* UNUSED:
240Type:
241 PrimitiveType
242| ReferenceType
243;
244*/
245
246PrimitiveType:
247 NumericType
248| BOOLEAN
249 { $$ = java_boolean_type; }
250;
251
252NumericType:
253 IntegralType
254| FloatingPointType
255;
256
257IntegralType:
258 BYTE
259 { $$ = java_byte_type; }
260| SHORT
261 { $$ = java_short_type; }
262| INT
263 { $$ = java_int_type; }
264| LONG
265 { $$ = java_long_type; }
266| CHAR
267 { $$ = java_char_type; }
268;
269
270FloatingPointType:
271 FLOAT
272 { $$ = java_float_type; }
273| DOUBLE
274 { $$ = java_double_type; }
275;
276
277/* UNUSED:
278ReferenceType:
279 ClassOrInterfaceType
280| ArrayType
281;
282*/
283
284ClassOrInterfaceType:
285 Name
286 { $$ = java_type_from_name ($1); }
287;
288
289ClassType:
290 ClassOrInterfaceType
291;
292
293/* UNUSED:
294ArrayType:
295 PrimitiveType Dims
296 { $$ = java_array_type ($1, $2); }
297| Name Dims
298 { $$ = java_array_type (java_type_from_name ($1), $2); }
299;
300*/
301
302Name:
303 IDENTIFIER
304| QualifiedName
305;
306
307ForcedName:
308 SimpleName
309| QualifiedName
310;
311
312SimpleName:
313 IDENTIFIER
314| NAME_OR_INT
315;
316
317QualifiedName:
318 Name '.' SimpleName
319 { $$.length = $1.length + $3.length + 1;
320 if ($1.ptr + $1.length + 1 == $3.ptr
321 && $1.ptr[$1.length] == '.')
322 $$.ptr = $1.ptr; /* Optimization. */
323 else
324 {
325 $$.ptr = (char *) malloc ($$.length + 1);
326 make_cleanup (free, $$.ptr);
327 sprintf ($$.ptr, "%.*s.%.*s",
328 $1.length, $1.ptr, $3.length, $3.ptr);
329 } }
330;
331
332/*
333type_exp: type
334 { write_exp_elt_opcode(OP_TYPE);
335 write_exp_elt_type($1);
336 write_exp_elt_opcode(OP_TYPE);}
337 ;
338 */
339
340/* Expressions, including the comma operator. */
341exp1 : Expression
342 | exp1 ',' Expression
343 { write_exp_elt_opcode (BINOP_COMMA); }
344 ;
345
346Primary:
347 PrimaryNoNewArray
348| ArrayCreationExpression
349;
350
351PrimaryNoNewArray:
352 Literal
353| THIS
354 { write_exp_elt_opcode (OP_THIS);
355 write_exp_elt_opcode (OP_THIS); }
356| '(' Expression ')'
357| ClassInstanceCreationExpression
358| FieldAccess
359| MethodInvocation
360| ArrayAccess
361| lcurly ArgumentList rcurly
362 { write_exp_elt_opcode (OP_ARRAY);
363 write_exp_elt_longcst ((LONGEST) 0);
364 write_exp_elt_longcst ((LONGEST) $3);
365 write_exp_elt_opcode (OP_ARRAY); }
366;
367
368lcurly:
369 '{'
370 { start_arglist (); }
371;
372
373rcurly:
374 '}'
375 { $$ = end_arglist () - 1; }
376;
377
378ClassInstanceCreationExpression:
379 NEW ClassType '(' ArgumentList_opt ')'
380 { error ("FIXME - ClassInstanceCreationExpression"); }
381;
382
383ArgumentList:
384 Expression
385 { arglist_len = 1; }
386| ArgumentList ',' Expression
387 { arglist_len++; }
388;
389
390ArgumentList_opt:
391 /* EMPTY */
392 { arglist_len = 0; }
393| ArgumentList
394;
395
396ArrayCreationExpression:
397 NEW PrimitiveType DimExprs Dims_opt
398 { error ("FIXME - ArrayCreatiionExpression"); }
399| NEW ClassOrInterfaceType DimExprs Dims_opt
400 { error ("FIXME - ArrayCreatiionExpression"); }
401;
402
403DimExprs:
404 DimExpr
405| DimExprs DimExpr
406;
407
408DimExpr:
409 '[' Expression ']'
410;
411
412Dims:
413 '[' ']'
414 { $$ = 1; }
415| Dims '[' ']'
416 { $$ = $1 + 1; }
417;
418
419Dims_opt:
420 Dims
421| /* EMPTY */
422 { $$ = 0; }
423;
424
425FieldAccess:
426 Primary '.' SimpleName
427 { write_exp_elt_opcode (STRUCTOP_STRUCT);
428 write_exp_string ($3);
429 write_exp_elt_opcode (STRUCTOP_STRUCT); }
430/*| SUPER '.' SimpleName { FIXME } */
431;
432
433MethodInvocation:
434 Name '(' ArgumentList_opt ')'
435 { error ("method invocation not implemented"); }
436| Primary '.' SimpleName '(' ArgumentList_opt ')'
437 { error ("method invocation not implemented"); }
438| SUPER '.' SimpleName '(' ArgumentList_opt ')'
439 { error ("method invocation not implemented"); }
440;
441
442ArrayAccess:
443 Name '[' Expression ']'
444 { error ("ArrayAccess"); } /* FIXME - NASTY */
445| PrimaryNoNewArray '[' Expression ']'
446 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
447;
448
449PostfixExpression:
450 Primary
451| Name
452 { push_variable ($1); }
453| VARIABLE
454 /* Already written by write_dollar_variable. */
455| PostIncrementExpression
456| PostDecrementExpression
457;
458
459PostIncrementExpression:
460 PostfixExpression INCREMENT
461 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
462;
463
464PostDecrementExpression:
465 PostfixExpression DECREMENT
466 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
467;
468
469UnaryExpression:
470 PreIncrementExpression
471| PreDecrementExpression
472| '+' UnaryExpression
473| '-' UnaryExpression
474 { write_exp_elt_opcode (UNOP_NEG); }
475| '*' UnaryExpression
476 { write_exp_elt_opcode (UNOP_IND); } /*FIXME not in Java */
477| UnaryExpressionNotPlusMinus
478;
479
480PreIncrementExpression:
481 INCREMENT UnaryExpression
482 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
483;
484
485PreDecrementExpression:
486 DECREMENT UnaryExpression
487 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
488;
489
490UnaryExpressionNotPlusMinus:
491 PostfixExpression
492| '~' UnaryExpression
493 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
494| '!' UnaryExpression
495 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
496| CastExpression
497 ;
498
499CastExpression:
500 '(' PrimitiveType Dims_opt ')' UnaryExpression
501 { write_exp_elt_opcode (UNOP_CAST);
502 write_exp_elt_type (java_array_type ($2, $3));
503 write_exp_elt_opcode (UNOP_CAST); }
504| '(' Expression ')' UnaryExpressionNotPlusMinus /* FIXME */
505| '(' Name Dims ')' UnaryExpressionNotPlusMinus
506 { write_exp_elt_opcode (UNOP_CAST);
507 write_exp_elt_type (java_array_type (java_type_from_name ($2), $3));
508 write_exp_elt_opcode (UNOP_CAST); }
509;
510
511
512MultiplicativeExpression:
513 UnaryExpression
514| MultiplicativeExpression '*' UnaryExpression
515 { write_exp_elt_opcode (BINOP_MUL); }
516| MultiplicativeExpression '/' UnaryExpression
517 { write_exp_elt_opcode (BINOP_DIV); }
518| MultiplicativeExpression '%' UnaryExpression
519 { write_exp_elt_opcode (BINOP_REM); }
520;
521
522AdditiveExpression:
523 MultiplicativeExpression
524| AdditiveExpression '+' MultiplicativeExpression
525 { write_exp_elt_opcode (BINOP_ADD); }
526| AdditiveExpression '-' MultiplicativeExpression
527 { write_exp_elt_opcode (BINOP_SUB); }
528;
529
530ShiftExpression:
531 AdditiveExpression
532| ShiftExpression LSH AdditiveExpression
533 { write_exp_elt_opcode (BINOP_LSH); }
534| ShiftExpression RSH AdditiveExpression
535 { write_exp_elt_opcode (BINOP_RSH); }
536/* | ShiftExpression >>> AdditiveExpression { FIXME } */
537;
538
539RelationalExpression:
540 ShiftExpression
541| RelationalExpression '<' ShiftExpression
542 { write_exp_elt_opcode (BINOP_LESS); }
543| RelationalExpression '>' ShiftExpression
544 { write_exp_elt_opcode (BINOP_GTR); }
545| RelationalExpression LEQ ShiftExpression
546 { write_exp_elt_opcode (BINOP_LEQ); }
547| RelationalExpression GEQ ShiftExpression
548 { write_exp_elt_opcode (BINOP_GEQ); }
549/* | RelationalExpresion INSTANCEOF ReferenceType { FIXME } */
550;
551
552EqualityExpression:
553 RelationalExpression
554| EqualityExpression EQUAL RelationalExpression
555 { write_exp_elt_opcode (BINOP_EQUAL); }
556| EqualityExpression NOTEQUAL RelationalExpression
557 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
558;
559
560AndExpression:
561 EqualityExpression
562| AndExpression '&' EqualityExpression
563 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
564;
565
566ExclusiveOrExpression:
567 AndExpression
568| ExclusiveOrExpression '^' AndExpression
569 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
570;
571InclusiveOrExpression:
572 ExclusiveOrExpression
573| InclusiveOrExpression '|' ExclusiveOrExpression
574 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
575;
576
577ConditionalAndExpression:
578 InclusiveOrExpression
579| ConditionalAndExpression ANDAND InclusiveOrExpression
580 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
581;
582
583ConditionalOrExpression:
584 ConditionalAndExpression
585| ConditionalOrExpression OROR ConditionalAndExpression
586 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
587;
588
589ConditionalExpression:
590 ConditionalOrExpression
591| ConditionalOrExpression '?' Expression ':' ConditionalExpression
592 { write_exp_elt_opcode (TERNOP_COND); }
593;
594
595AssignmentExpression:
596 ConditionalExpression
597| Assignment
598;
599
600Assignment:
601 LeftHandSide '=' ConditionalExpression
602 { write_exp_elt_opcode (BINOP_ASSIGN); }
603| LeftHandSide ASSIGN_MODIFY ConditionalExpression
604 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
605 write_exp_elt_opcode ($2);
606 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
607;
608
609LeftHandSide:
610 ForcedName
611 { push_variable ($1); }
612| VARIABLE
613 /* Already written by write_dollar_variable. */
614| FieldAccess
615| ArrayAccess
616;
617
618
619Expression:
620 AssignmentExpression
621;
622
623%%
624/* Take care of parsing a number (anything that starts with a digit).
625 Set yylval and return the token type; update lexptr.
626 LEN is the number of characters in it. */
627
628/*** Needs some error checking for the float case ***/
629
630static int
631parse_number (p, len, parsed_float, putithere)
632 register char *p;
633 register int len;
634 int parsed_float;
635 YYSTYPE *putithere;
636{
637 register ULONGEST n = 0;
638 ULONGEST limit, limit_div_base;
639
640 register int c;
641 register int base = input_radix;
642 int unsigned_p = 0;
643
644 struct type *type;
645
646 if (parsed_float)
647 {
648 /* It's a float since it contains a point or an exponent. */
649
650 if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
651 sscanf (p, "%g", &putithere->typed_val_float.dval);
652 else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
653 sscanf (p, "%lg", &putithere->typed_val_float.dval);
654 else
655 {
656#ifdef PRINTF_HAS_LONG_DOUBLE
657 sscanf (p, "%Lg", &putithere->typed_val_float.dval);
658#else
659 /* Scan it into a double, then assign it to the long double.
660 This at least wins with values representable in the range
661 of doubles. */
662 double temp;
663 sscanf (p, "%lg", &temp);
664 putithere->typed_val_float.dval = temp;
665#endif
666 }
667
668 /* See if it has `f' or `d' suffix (float or double). */
669
670 c = tolower (p[len - 1]);
671
672 if (c == 'f' || c == 'F')
673 putithere->typed_val_float.type = builtin_type_float;
674 else if (isdigit (c) || c == '.' || c == 'd' || c == 'D')
675 putithere->typed_val_float.type = builtin_type_double;
676 else
677 return ERROR;
678
679 return FLOATING_POINT_LITERAL;
680}
681
682 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
683 if (p[0] == '0')
684 switch (p[1])
685 {
686 case 'x':
687 case 'X':
688 if (len >= 3)
689 {
690 p += 2;
691 base = 16;
692 len -= 2;
693 }
694 break;
695
696 case 't':
697 case 'T':
698 case 'd':
699 case 'D':
700 if (len >= 3)
701 {
702 p += 2;
703 base = 10;
704 len -= 2;
705 }
706 break;
707
708 default:
709 base = 8;
710 break;
711 }
712
713 c = p[len-1];
714 limit = (ULONGEST)0xffffffff;
715 if (c == 'l' || c == 'L')
716 {
717 type = java_long_type;
718 len--;
719 /* A paranoid calculation of (1<<64)-1. */
720 limit = ((limit << 16) << 16) | limit;
721 }
722 else
723 {
724 type = java_int_type;
725 }
726 limit_div_base = limit / (ULONGEST) base;
727
728 while (--len >= 0)
729 {
730 c = *p++;
731 if (c >= '0' && c <= '9')
732 c -= '0';
733 else
734 {
735 if (c >= 'A' && c <= 'Z')
736 c += 'a' - 'A';
737 if (c >= 'a' && c - 'a' + 10 < base)
738 c -= 'a' + 10;
739 else
740 return ERROR; /* Char not a digit */
741 }
742 if (c >= base)
743 return ERROR;
744 if (n > limit_div_base
745 || (n *= base) > limit - c)
746 error ("Numeric constant too large.");
747 n += c;
748 }
749
750 putithere->typed_val_int.val = n;
751 putithere->typed_val_int.type = type;
752 return INTEGER_LITERAL;
753}
754
755struct token
756{
757 char *operator;
758 int token;
759 enum exp_opcode opcode;
760};
761
762static const struct token tokentab3[] =
763 {
764 {">>=", ASSIGN_MODIFY, BINOP_RSH},
765 {"<<=", ASSIGN_MODIFY, BINOP_LSH}
766 };
767
768static const struct token tokentab2[] =
769 {
770 {"+=", ASSIGN_MODIFY, BINOP_ADD},
771 {"-=", ASSIGN_MODIFY, BINOP_SUB},
772 {"*=", ASSIGN_MODIFY, BINOP_MUL},
773 {"/=", ASSIGN_MODIFY, BINOP_DIV},
774 {"%=", ASSIGN_MODIFY, BINOP_REM},
775 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR},
776 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND},
777 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR},
778 {"++", INCREMENT, BINOP_END},
779 {"--", DECREMENT, BINOP_END},
780 {"&&", ANDAND, BINOP_END},
781 {"||", OROR, BINOP_END},
782 {"<<", LSH, BINOP_END},
783 {">>", RSH, BINOP_END},
784 {"==", EQUAL, BINOP_END},
785 {"!=", NOTEQUAL, BINOP_END},
786 {"<=", LEQ, BINOP_END},
787 {">=", GEQ, BINOP_END}
788 };
789
790/* Read one token, getting characters through lexptr. */
791
792static int
793yylex ()
794{
795 int c;
796 int namelen;
797 unsigned int i;
798 char *tokstart;
799 char *tokptr;
800 int tempbufindex;
801 static char *tempbuf;
802 static int tempbufsize;
803
804 retry:
805
806 tokstart = lexptr;
807 /* See if it is a special token of length 3. */
808 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
809 if (STREQN (tokstart, tokentab3[i].operator, 3))
810 {
811 lexptr += 3;
812 yylval.opcode = tokentab3[i].opcode;
813 return tokentab3[i].token;
814 }
815
816 /* See if it is a special token of length 2. */
817 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
818 if (STREQN (tokstart, tokentab2[i].operator, 2))
819 {
820 lexptr += 2;
821 yylval.opcode = tokentab2[i].opcode;
822 return tokentab2[i].token;
823 }
824
825 switch (c = *tokstart)
826 {
827 case 0:
828 return 0;
829
830 case ' ':
831 case '\t':
832 case '\n':
833 lexptr++;
834 goto retry;
835
836 case '\'':
837 /* We either have a character constant ('0' or '\177' for example)
838 or we have a quoted symbol reference ('foo(int,int)' in C++
839 for example). */
840 lexptr++;
841 c = *lexptr++;
842 if (c == '\\')
843 c = parse_escape (&lexptr);
844 else if (c == '\'')
845 error ("Empty character constant.");
846
847 yylval.typed_val_int.val = c;
848 yylval.typed_val_int.type = builtin_type_char;
849
850 c = *lexptr++;
851 if (c != '\'')
852 {
853 namelen = skip_quoted (tokstart) - tokstart;
854 if (namelen > 2)
855 {
856 lexptr = tokstart + namelen;
857 if (lexptr[-1] != '\'')
858 error ("Unmatched single quote.");
859 namelen -= 2;
860 tokstart++;
861 goto tryname;
862 }
863 error ("Invalid character constant.");
864 }
865 return INTEGER_LITERAL;
866
867 case '(':
868 paren_depth++;
869 lexptr++;
870 return c;
871
872 case ')':
873 if (paren_depth == 0)
874 return 0;
875 paren_depth--;
876 lexptr++;
877 return c;
878
879 case ',':
880 if (comma_terminates && paren_depth == 0)
881 return 0;
882 lexptr++;
883 return c;
884
885 case '.':
886 /* Might be a floating point number. */
887 if (lexptr[1] < '0' || lexptr[1] > '9')
888 goto symbol; /* Nope, must be a symbol. */
889 /* FALL THRU into number case. */
890
891 case '0':
892 case '1':
893 case '2':
894 case '3':
895 case '4':
896 case '5':
897 case '6':
898 case '7':
899 case '8':
900 case '9':
901 {
902 /* It's a number. */
903 int got_dot = 0, got_e = 0, toktype;
904 register char *p = tokstart;
905 int hex = input_radix > 10;
906
907 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
908 {
909 p += 2;
910 hex = 1;
911 }
912 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
913 {
914 p += 2;
915 hex = 0;
916 }
917
918 for (;; ++p)
919 {
920 /* This test includes !hex because 'e' is a valid hex digit
921 and thus does not indicate a floating point number when
922 the radix is hex. */
923 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
924 got_dot = got_e = 1;
925 /* This test does not include !hex, because a '.' always indicates
926 a decimal floating point number regardless of the radix. */
927 else if (!got_dot && *p == '.')
928 got_dot = 1;
929 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
930 && (*p == '-' || *p == '+'))
931 /* This is the sign of the exponent, not the end of the
932 number. */
933 continue;
934 /* We will take any letters or digits. parse_number will
935 complain if past the radix, or if L or U are not final. */
936 else if ((*p < '0' || *p > '9')
937 && ((*p < 'a' || *p > 'z')
938 && (*p < 'A' || *p > 'Z')))
939 break;
940 }
941 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
942 if (toktype == ERROR)
943 {
944 char *err_copy = (char *) alloca (p - tokstart + 1);
945
946 memcpy (err_copy, tokstart, p - tokstart);
947 err_copy[p - tokstart] = 0;
948 error ("Invalid number \"%s\".", err_copy);
949 }
950 lexptr = p;
951 return toktype;
952 }
953
954 case '+':
955 case '-':
956 case '*':
957 case '/':
958 case '%':
959 case '|':
960 case '&':
961 case '^':
962 case '~':
963 case '!':
964 case '<':
965 case '>':
966 case '[':
967 case ']':
968 case '?':
969 case ':':
970 case '=':
971 case '{':
972 case '}':
973 symbol:
974 lexptr++;
975 return c;
976
977 case '"':
978
979 /* Build the gdb internal form of the input string in tempbuf,
980 translating any standard C escape forms seen. Note that the
981 buffer is null byte terminated *only* for the convenience of
982 debugging gdb itself and printing the buffer contents when
983 the buffer contains no embedded nulls. Gdb does not depend
984 upon the buffer being null byte terminated, it uses the length
985 string instead. This allows gdb to handle C strings (as well
986 as strings in other languages) with embedded null bytes */
987
988 tokptr = ++tokstart;
989 tempbufindex = 0;
990
991 do {
992 /* Grow the static temp buffer if necessary, including allocating
993 the first one on demand. */
994 if (tempbufindex + 1 >= tempbufsize)
995 {
996 tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
997 }
998 switch (*tokptr)
999 {
1000 case '\0':
1001 case '"':
1002 /* Do nothing, loop will terminate. */
1003 break;
1004 case '\\':
1005 tokptr++;
1006 c = parse_escape (&tokptr);
1007 if (c == -1)
1008 {
1009 continue;
1010 }
1011 tempbuf[tempbufindex++] = c;
1012 break;
1013 default:
1014 tempbuf[tempbufindex++] = *tokptr++;
1015 break;
1016 }
1017 } while ((*tokptr != '"') && (*tokptr != '\0'));
1018 if (*tokptr++ != '"')
1019 {
1020 error ("Unterminated string in expression.");
1021 }
1022 tempbuf[tempbufindex] = '\0'; /* See note above */
1023 yylval.sval.ptr = tempbuf;
1024 yylval.sval.length = tempbufindex;
1025 lexptr = tokptr;
1026 return (STRING_LITERAL);
1027 }
1028
1029 if (!(c == '_' || c == '$'
1030 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1031 /* We must have come across a bad character (e.g. ';'). */
1032 error ("Invalid character '%c' in expression.", c);
1033
1034 /* It's a name. See how long it is. */
1035 namelen = 0;
1036 for (c = tokstart[namelen];
1037 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1038 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
1039 {
1040 if (c == '<')
1041 {
1042 int i = namelen;
1043 while (tokstart[++i] && tokstart[i] != '>');
1044 if (tokstart[i] == '>')
1045 namelen = i;
1046 }
1047 c = tokstart[++namelen];
1048 }
1049
1050 /* The token "if" terminates the expression and is NOT
1051 removed from the input stream. */
1052 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1053 {
1054 return 0;
1055 }
1056
1057 lexptr += namelen;
1058
1059 tryname:
1060
1061 /* Catch specific keywords. Should be done with a data structure. */
1062 switch (namelen)
1063 {
1064 case 7:
1065 if (STREQN (tokstart, "boolean", 7))
1066 return BOOLEAN;
1067 break;
1068 case 6:
1069 if (STREQN (tokstart, "double", 6))
1070 return DOUBLE;
1071 break;
1072 case 5:
1073 if (STREQN (tokstart, "short", 5))
1074 return SHORT;
1075 if (STREQN (tokstart, "false", 5))
75a947c6
PB
1076 {
1077 yylval.lval = 0;
1078 return BOOLEAN_LITERAL;
1079 }
7a9eb4c4
PB
1080 if (STREQN (tokstart, "super", 5))
1081 return SUPER;
1082 if (STREQN (tokstart, "float", 5))
1083 return FLOAT;
1084 break;
1085 case 4:
1086 if (STREQN (tokstart, "long", 4))
1087 return LONG;
1088 if (STREQN (tokstart, "byte", 4))
1089 return BYTE;
1090 if (STREQN (tokstart, "char", 4))
1091 return CHAR;
1092 if (STREQN (tokstart, "true", 4))
75a947c6
PB
1093 {
1094 yylval.lval = 1;
1095 return BOOLEAN_LITERAL;
1096 }
7a9eb4c4
PB
1097 if (current_language->la_language == language_cplus
1098 && STREQN (tokstart, "this", 4))
1099 {
1100 static const char this_name[] =
1101 { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' };
1102
1103 if (lookup_symbol (this_name, expression_context_block,
1104 VAR_NAMESPACE, (int *) NULL,
1105 (struct symtab **) NULL))
1106 return THIS;
1107 }
1108 break;
1109 case 3:
1110 if (STREQN (tokstart, "int", 3))
1111 return INT;
1112 if (STREQN (tokstart, "new", 3))
1113 return NEW;
1114 break;
1115 default:
1116 break;
1117 }
1118
1119 yylval.sval.ptr = tokstart;
1120 yylval.sval.length = namelen;
1121
1122 if (*tokstart == '$')
1123 {
1124 write_dollar_variable (yylval.sval);
1125 return VARIABLE;
1126 }
1127
1128 /* Input names that aren't symbols but ARE valid hex numbers,
1129 when the input radix permits them, can be names or numbers
1130 depending on the parse. Note we support radixes > 16 here. */
1131 if (((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
1132 (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1133 {
1134 YYSTYPE newlval; /* Its value is ignored. */
1135 int hextype = parse_number (tokstart, namelen, 0, &newlval);
1136 if (hextype == INTEGER_LITERAL)
1137 return NAME_OR_INT;
1138 }
1139 return IDENTIFIER;
1140}
1141
1142void
1143yyerror (msg)
1144 char *msg;
1145{
1146 error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
1147}
1148
1149static struct type *
1150java_type_from_name (name)
1151 struct stoken name;
1152
1153{
1154 char *tmp = copy_name (name);
1155 struct type *typ = java_lookup_class (tmp);
1156 if (typ == NULL || TYPE_CODE (typ) != TYPE_CODE_STRUCT)
1157 error ("No class named %s.", tmp);
1158 return typ;
1159}
1160
1161static void
1162push_variable (name)
1163 struct stoken name;
1164
1165{
1166 char *tmp = copy_name (name);
1167 int is_a_field_of_this = 0;
1168 struct symbol *sym;
1169 struct type *typ;
1170 sym = lookup_symbol (tmp, expression_context_block, VAR_NAMESPACE,
1171 &is_a_field_of_this, (struct symtab **) NULL);
1172 if (sym)
1173 {
1174 if (symbol_read_needs_frame (sym))
1175 {
1176 if (innermost_block == 0 ||
1177 contained_in (block_found, innermost_block))
1178 innermost_block = block_found;
1179 }
1180
1181 write_exp_elt_opcode (OP_VAR_VALUE);
1182 /* We want to use the selected frame, not another more inner frame
1183 which happens to be in the same block. */
1184 write_exp_elt_block (NULL);
1185 write_exp_elt_sym (sym);
1186 write_exp_elt_opcode (OP_VAR_VALUE);
1187 return;
1188 }
1189 if (is_a_field_of_this)
1190 {
1191 /* it hangs off of `this'. Must not inadvertently convert from a
1192 method call to data ref. */
1193 if (innermost_block == 0 ||
1194 contained_in (block_found, innermost_block))
1195 innermost_block = block_found;
1196 write_exp_elt_opcode (OP_THIS);
1197 write_exp_elt_opcode (OP_THIS);
1198 write_exp_elt_opcode (STRUCTOP_PTR);
1199 write_exp_string (name);
1200 write_exp_elt_opcode (STRUCTOP_PTR);
1201 return;
1202 }
1203
1204 typ = java_lookup_class (tmp);
1205 if (typ != NULL)
1206 {
1207 write_exp_elt_opcode(OP_TYPE);
1208 write_exp_elt_type(typ);
1209 write_exp_elt_opcode(OP_TYPE);
1210 }
1211 else
1212 {
1213 struct minimal_symbol *msymbol;
1214
1215 msymbol = lookup_minimal_symbol (tmp, NULL, NULL);
1216 if (msymbol != NULL)
1217 {
1218 write_exp_msymbol (msymbol,
1219 lookup_function_type (builtin_type_int),
1220 builtin_type_int);
1221 }
1222 else if (!have_full_symbols () && !have_partial_symbols ())
1223 error ("No symbol table is loaded. Use the \"file\" command.");
1224 else
1225 error ("No symbol \"%s\" in current context.", tmp);
1226 }
1227
1228}
This page took 0.09362 seconds and 4 git commands to generate.