Build gdb.opt/inline-*.exp tests at -O0, rely on __attribute__((always_inline))
[deliverable/binutils-gdb.git] / gdb / jv-exp.y
CommitLineData
c906108c 1/* YACC parser for Java expressions, for GDB.
618f726f 2 Copyright (C) 1997-2016 Free Software Foundation, Inc.
c906108c 3
5b1ba0e5 4 This file is part of GDB.
c906108c 5
5b1ba0e5
NS
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
c906108c 10
5b1ba0e5
NS
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
c906108c 15
5b1ba0e5
NS
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
18
19/* Parse a Java expression from text in a string,
20 and return the result as a struct expression pointer.
21 That structure contains arithmetic operations in reverse polish,
22 with constants represented by operations that are followed by special data.
23 See expression.h for the details of the format.
24 What is important here is that it can be built up sequentially
25 during the process of parsing; the lower levels of the tree always
26 come first in the result. Well, almost always; see ArrayAccess.
27
28 Note that malloc's and realloc's in this file are transformed to
29 xmalloc and xrealloc respectively by the same sed command in the
30 makefile that remaps any other malloc/realloc inserted by the parser
31 generator. Doing this with #defines and trying to control the interaction
32 with include files (<malloc.h> and <stdlib.h> for example) just became
33 too messy, particularly when such includes can be inserted at random
34 times by the parser generator. */
35
36%{
37
38#include "defs.h"
c906108c
SS
39#include <ctype.h>
40#include "expression.h"
41#include "value.h"
42#include "parser-defs.h"
43#include "language.h"
44#include "jv-lang.h"
45#include "bfd.h" /* Required by objfiles.h. */
46#include "symfile.h" /* Required by objfiles.h. */
47#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
fe898f56 48#include "block.h"
d7561cbb 49#include "completer.h"
c906108c 50
410a0ff2
SDJ
51#define parse_type(ps) builtin_type (parse_gdbarch (ps))
52#define parse_java_type(ps) builtin_java_type (parse_gdbarch (ps))
3e79cecf 53
b3f11165
PA
54/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
55 etc). */
56#define GDB_YY_REMAP_PREFIX java_
57#include "yy-remap.h"
f461f5cf 58
410a0ff2
SDJ
59/* The state of the parser, used internally when we are parsing the
60 expression. */
61
62static struct parser_state *pstate = NULL;
63
a14ed312 64int yyparse (void);
c906108c 65
a14ed312 66static int yylex (void);
c906108c 67
a14ed312 68void yyerror (char *);
c906108c 69
a14ed312 70static struct type *java_type_from_name (struct stoken);
410a0ff2
SDJ
71static void push_expression_name (struct parser_state *, struct stoken);
72static void push_fieldnames (struct parser_state *, struct stoken);
c906108c 73
a14ed312 74static struct expression *copy_exp (struct expression *, int);
410a0ff2 75static void insert_exp (struct parser_state *, int, struct expression *);
c906108c
SS
76
77%}
78
79/* Although the yacc "value" of an expression is not used,
80 since the result is stored in the structure being created,
81 other node types do have values. */
82
83%union
84 {
85 LONGEST lval;
86 struct {
87 LONGEST val;
88 struct type *type;
89 } typed_val_int;
90 struct {
91 DOUBLEST dval;
92 struct type *type;
93 } typed_val_float;
94 struct symbol *sym;
95 struct type *tval;
96 struct stoken sval;
97 struct ttype tsym;
98 struct symtoken ssym;
99 struct block *bval;
100 enum exp_opcode opcode;
101 struct internalvar *ivar;
102 int *ivec;
103 }
104
105%{
106/* YYSTYPE gets defined by %union */
410a0ff2
SDJ
107static int parse_number (struct parser_state *, const char *, int,
108 int, YYSTYPE *);
c906108c
SS
109%}
110
111%type <lval> rcurly Dims Dims_opt
112%type <tval> ClassOrInterfaceType ClassType /* ReferenceType Type ArrayType */
113%type <tval> IntegralType FloatingPointType NumericType PrimitiveType ArrayType PrimitiveOrArrayType
114
115%token <typed_val_int> INTEGER_LITERAL
116%token <typed_val_float> FLOATING_POINT_LITERAL
117
118%token <sval> IDENTIFIER
119%token <sval> STRING_LITERAL
120%token <lval> BOOLEAN_LITERAL
121%token <tsym> TYPENAME
122%type <sval> Name SimpleName QualifiedName ForcedName
123
124/* A NAME_OR_INT is a symbol which is not known in the symbol table,
125 but which would parse as a valid number in the current input radix.
126 E.g. "c" when input_radix==16. Depending on the parse, it will be
127 turned into a name or into a number. */
128
129%token <sval> NAME_OR_INT
130
131%token ERROR
132
133/* Special type cases, put in to allow the parser to distinguish different
134 legal basetypes. */
135%token LONG SHORT BYTE INT CHAR BOOLEAN DOUBLE FLOAT
136
137%token VARIABLE
138
139%token <opcode> ASSIGN_MODIFY
140
8343f86c 141%token SUPER NEW
c906108c
SS
142
143%left ','
144%right '=' ASSIGN_MODIFY
145%right '?'
146%left OROR
147%left ANDAND
148%left '|'
149%left '^'
150%left '&'
151%left EQUAL NOTEQUAL
152%left '<' '>' LEQ GEQ
153%left LSH RSH
154%left '+' '-'
155%left '*' '/' '%'
156%right INCREMENT DECREMENT
157%right '.' '[' '('
158
159\f
160%%
161
162start : exp1
163 | type_exp
164 ;
165
166type_exp: PrimitiveOrArrayType
167 {
410a0ff2
SDJ
168 write_exp_elt_opcode (pstate, OP_TYPE);
169 write_exp_elt_type (pstate, $1);
170 write_exp_elt_opcode (pstate, OP_TYPE);
c906108c
SS
171 }
172 ;
173
174PrimitiveOrArrayType:
175 PrimitiveType
176 | ArrayType
177 ;
178
179StringLiteral:
180 STRING_LITERAL
181 {
410a0ff2
SDJ
182 write_exp_elt_opcode (pstate, OP_STRING);
183 write_exp_string (pstate, $1);
184 write_exp_elt_opcode (pstate, OP_STRING);
c906108c
SS
185 }
186;
187
188Literal:
189 INTEGER_LITERAL
410a0ff2
SDJ
190 { write_exp_elt_opcode (pstate, OP_LONG);
191 write_exp_elt_type (pstate, $1.type);
192 write_exp_elt_longcst (pstate, (LONGEST)($1.val));
193 write_exp_elt_opcode (pstate, OP_LONG); }
c906108c
SS
194| NAME_OR_INT
195 { YYSTYPE val;
410a0ff2
SDJ
196 parse_number (pstate, $1.ptr, $1.length, 0, &val);
197 write_exp_elt_opcode (pstate, OP_LONG);
198 write_exp_elt_type (pstate, val.typed_val_int.type);
199 write_exp_elt_longcst (pstate,
200 (LONGEST) val.typed_val_int.val);
201 write_exp_elt_opcode (pstate, OP_LONG);
c906108c
SS
202 }
203| FLOATING_POINT_LITERAL
410a0ff2
SDJ
204 { write_exp_elt_opcode (pstate, OP_DOUBLE);
205 write_exp_elt_type (pstate, $1.type);
206 write_exp_elt_dblcst (pstate, $1.dval);
207 write_exp_elt_opcode (pstate, OP_DOUBLE); }
c906108c 208| BOOLEAN_LITERAL
410a0ff2
SDJ
209 { write_exp_elt_opcode (pstate, OP_LONG);
210 write_exp_elt_type (pstate,
211 parse_java_type (pstate)->builtin_boolean);
212 write_exp_elt_longcst (pstate, (LONGEST)$1);
213 write_exp_elt_opcode (pstate, OP_LONG); }
c906108c
SS
214| StringLiteral
215 ;
216
217/* UNUSED:
218Type:
219 PrimitiveType
220| ReferenceType
221;
222*/
223
224PrimitiveType:
225 NumericType
226| BOOLEAN
410a0ff2 227 { $$ = parse_java_type (pstate)->builtin_boolean; }
c906108c
SS
228;
229
230NumericType:
231 IntegralType
232| FloatingPointType
233;
234
235IntegralType:
236 BYTE
410a0ff2 237 { $$ = parse_java_type (pstate)->builtin_byte; }
c906108c 238| SHORT
410a0ff2 239 { $$ = parse_java_type (pstate)->builtin_short; }
c906108c 240| INT
410a0ff2 241 { $$ = parse_java_type (pstate)->builtin_int; }
c906108c 242| LONG
410a0ff2 243 { $$ = parse_java_type (pstate)->builtin_long; }
c906108c 244| CHAR
410a0ff2 245 { $$ = parse_java_type (pstate)->builtin_char; }
c906108c
SS
246;
247
248FloatingPointType:
249 FLOAT
410a0ff2 250 { $$ = parse_java_type (pstate)->builtin_float; }
c906108c 251| DOUBLE
410a0ff2 252 { $$ = parse_java_type (pstate)->builtin_double; }
c906108c
SS
253;
254
255/* UNUSED:
256ReferenceType:
257 ClassOrInterfaceType
258| ArrayType
259;
260*/
261
262ClassOrInterfaceType:
263 Name
264 { $$ = java_type_from_name ($1); }
265;
266
267ClassType:
268 ClassOrInterfaceType
269;
270
271ArrayType:
272 PrimitiveType Dims
273 { $$ = java_array_type ($1, $2); }
274| Name Dims
275 { $$ = java_array_type (java_type_from_name ($1), $2); }
276;
277
278Name:
279 IDENTIFIER
280| QualifiedName
281;
282
283ForcedName:
284 SimpleName
285| QualifiedName
286;
287
288SimpleName:
289 IDENTIFIER
290| NAME_OR_INT
291;
292
293QualifiedName:
294 Name '.' SimpleName
295 { $$.length = $1.length + $3.length + 1;
296 if ($1.ptr + $1.length + 1 == $3.ptr
297 && $1.ptr[$1.length] == '.')
1777feb0 298 $$.ptr = $1.ptr; /* Optimization. */
c906108c
SS
299 else
300 {
d7561cbb
KS
301 char *buf;
302
224c3ddb 303 buf = (char *) malloc ($$.length + 1);
d7561cbb
KS
304 make_cleanup (free, buf);
305 sprintf (buf, "%.*s.%.*s",
c906108c 306 $1.length, $1.ptr, $3.length, $3.ptr);
d7561cbb 307 $$.ptr = buf;
c906108c
SS
308 } }
309;
310
311/*
312type_exp: type
313 { write_exp_elt_opcode(OP_TYPE);
314 write_exp_elt_type($1);
315 write_exp_elt_opcode(OP_TYPE);}
316 ;
317 */
318
319/* Expressions, including the comma operator. */
320exp1 : Expression
321 | exp1 ',' Expression
410a0ff2 322 { write_exp_elt_opcode (pstate, BINOP_COMMA); }
c906108c
SS
323 ;
324
325Primary:
326 PrimaryNoNewArray
327| ArrayCreationExpression
328;
329
330PrimaryNoNewArray:
331 Literal
c906108c
SS
332| '(' Expression ')'
333| ClassInstanceCreationExpression
334| FieldAccess
335| MethodInvocation
336| ArrayAccess
337| lcurly ArgumentList rcurly
410a0ff2
SDJ
338 { write_exp_elt_opcode (pstate, OP_ARRAY);
339 write_exp_elt_longcst (pstate, (LONGEST) 0);
340 write_exp_elt_longcst (pstate, (LONGEST) $3);
341 write_exp_elt_opcode (pstate, OP_ARRAY); }
c906108c
SS
342;
343
344lcurly:
345 '{'
346 { start_arglist (); }
347;
348
349rcurly:
350 '}'
351 { $$ = end_arglist () - 1; }
352;
353
354ClassInstanceCreationExpression:
355 NEW ClassType '(' ArgumentList_opt ')'
8c554d79
TT
356 { internal_error (__FILE__, __LINE__,
357 _("FIXME - ClassInstanceCreationExpression")); }
c906108c
SS
358;
359
360ArgumentList:
361 Expression
362 { arglist_len = 1; }
363| ArgumentList ',' Expression
364 { arglist_len++; }
365;
366
367ArgumentList_opt:
368 /* EMPTY */
369 { arglist_len = 0; }
370| ArgumentList
371;
372
373ArrayCreationExpression:
374 NEW PrimitiveType DimExprs Dims_opt
8c554d79
TT
375 { internal_error (__FILE__, __LINE__,
376 _("FIXME - ArrayCreationExpression")); }
c906108c 377| NEW ClassOrInterfaceType DimExprs Dims_opt
8c554d79
TT
378 { internal_error (__FILE__, __LINE__,
379 _("FIXME - ArrayCreationExpression")); }
c906108c
SS
380;
381
382DimExprs:
383 DimExpr
384| DimExprs DimExpr
385;
386
387DimExpr:
388 '[' Expression ']'
389;
390
391Dims:
392 '[' ']'
393 { $$ = 1; }
394| Dims '[' ']'
395 { $$ = $1 + 1; }
396;
397
398Dims_opt:
399 Dims
400| /* EMPTY */
401 { $$ = 0; }
402;
403
404FieldAccess:
405 Primary '.' SimpleName
410a0ff2 406 { push_fieldnames (pstate, $3); }
c906108c 407| VARIABLE '.' SimpleName
410a0ff2 408 { push_fieldnames (pstate, $3); }
c906108c
SS
409/*| SUPER '.' SimpleName { FIXME } */
410;
411
987504bb
JJ
412FuncStart:
413 Name '('
410a0ff2 414 { push_expression_name (pstate, $1); }
987504bb
JJ
415;
416
c906108c 417MethodInvocation:
987504bb
JJ
418 FuncStart
419 { start_arglist(); }
420 ArgumentList_opt ')'
410a0ff2
SDJ
421 { write_exp_elt_opcode (pstate, OP_FUNCALL);
422 write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
423 write_exp_elt_opcode (pstate, OP_FUNCALL); }
c906108c 424| Primary '.' SimpleName '(' ArgumentList_opt ')'
987504bb 425 { error (_("Form of method invocation not implemented")); }
c906108c 426| SUPER '.' SimpleName '(' ArgumentList_opt ')'
987504bb 427 { error (_("Form of method invocation not implemented")); }
c906108c
SS
428;
429
430ArrayAccess:
431 Name '[' Expression ']'
432 {
433 /* Emit code for the Name now, then exchange it in the
434 expout array with the Expression's code. We could
435 introduce a OP_SWAP code or a reversed version of
436 BINOP_SUBSCRIPT, but that makes the rest of GDB pay
437 for our parsing kludges. */
438 struct expression *name_expr;
439
410a0ff2
SDJ
440 push_expression_name (pstate, $1);
441 name_expr = copy_exp (pstate->expout, pstate->expout_ptr);
442 pstate->expout_ptr -= name_expr->nelts;
443 insert_exp (pstate,
444 pstate->expout_ptr
445 - length_of_subexp (pstate->expout,
446 pstate->expout_ptr),
c906108c
SS
447 name_expr);
448 free (name_expr);
410a0ff2 449 write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT);
c906108c
SS
450 }
451| VARIABLE '[' Expression ']'
410a0ff2 452 { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
c906108c 453| PrimaryNoNewArray '[' Expression ']'
410a0ff2 454 { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
c906108c
SS
455;
456
457PostfixExpression:
458 Primary
459| Name
410a0ff2 460 { push_expression_name (pstate, $1); }
c906108c 461| VARIABLE
1777feb0 462 /* Already written by write_dollar_variable. */
c906108c
SS
463| PostIncrementExpression
464| PostDecrementExpression
465;
466
467PostIncrementExpression:
468 PostfixExpression INCREMENT
410a0ff2 469 { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
c906108c
SS
470;
471
472PostDecrementExpression:
473 PostfixExpression DECREMENT
410a0ff2 474 { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); }
c906108c
SS
475;
476
477UnaryExpression:
478 PreIncrementExpression
479| PreDecrementExpression
480| '+' UnaryExpression
481| '-' UnaryExpression
410a0ff2 482 { write_exp_elt_opcode (pstate, UNOP_NEG); }
c906108c 483| '*' UnaryExpression
410a0ff2
SDJ
484 { write_exp_elt_opcode (pstate,
485 UNOP_IND); } /*FIXME not in Java */
c906108c
SS
486| UnaryExpressionNotPlusMinus
487;
488
489PreIncrementExpression:
490 INCREMENT UnaryExpression
410a0ff2 491 { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); }
c906108c
SS
492;
493
494PreDecrementExpression:
495 DECREMENT UnaryExpression
410a0ff2 496 { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); }
c906108c
SS
497;
498
499UnaryExpressionNotPlusMinus:
500 PostfixExpression
501| '~' UnaryExpression
410a0ff2 502 { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
c906108c 503| '!' UnaryExpression
410a0ff2 504 { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
c906108c
SS
505| CastExpression
506 ;
507
508CastExpression:
509 '(' PrimitiveType Dims_opt ')' UnaryExpression
410a0ff2
SDJ
510 { write_exp_elt_opcode (pstate, UNOP_CAST);
511 write_exp_elt_type (pstate, java_array_type ($2, $3));
512 write_exp_elt_opcode (pstate, UNOP_CAST); }
c906108c
SS
513| '(' Expression ')' UnaryExpressionNotPlusMinus
514 {
410a0ff2
SDJ
515 int last_exp_size = length_of_subexp (pstate->expout,
516 pstate->expout_ptr);
c906108c
SS
517 struct type *type;
518 int i;
410a0ff2
SDJ
519 int base = pstate->expout_ptr - last_exp_size - 3;
520
521 if (base < 0
522 || pstate->expout->elts[base+2].opcode != OP_TYPE)
8c554d79 523 error (_("Invalid cast expression"));
410a0ff2 524 type = pstate->expout->elts[base+1].type;
c906108c 525 /* Remove the 'Expression' and slide the
1777feb0 526 UnaryExpressionNotPlusMinus down to replace it. */
c906108c 527 for (i = 0; i < last_exp_size; i++)
410a0ff2
SDJ
528 pstate->expout->elts[base + i]
529 = pstate->expout->elts[base + i + 3];
530 pstate->expout_ptr -= 3;
c906108c
SS
531 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
532 type = lookup_pointer_type (type);
410a0ff2
SDJ
533 write_exp_elt_opcode (pstate, UNOP_CAST);
534 write_exp_elt_type (pstate, type);
535 write_exp_elt_opcode (pstate, UNOP_CAST);
c906108c
SS
536 }
537| '(' Name Dims ')' UnaryExpressionNotPlusMinus
410a0ff2
SDJ
538 { write_exp_elt_opcode (pstate, UNOP_CAST);
539 write_exp_elt_type (pstate,
540 java_array_type (java_type_from_name
541 ($2), $3));
542 write_exp_elt_opcode (pstate, UNOP_CAST); }
c906108c
SS
543;
544
545
546MultiplicativeExpression:
547 UnaryExpression
548| MultiplicativeExpression '*' UnaryExpression
410a0ff2 549 { write_exp_elt_opcode (pstate, BINOP_MUL); }
c906108c 550| MultiplicativeExpression '/' UnaryExpression
410a0ff2 551 { write_exp_elt_opcode (pstate, BINOP_DIV); }
c906108c 552| MultiplicativeExpression '%' UnaryExpression
410a0ff2 553 { write_exp_elt_opcode (pstate, BINOP_REM); }
c906108c
SS
554;
555
556AdditiveExpression:
557 MultiplicativeExpression
558| AdditiveExpression '+' MultiplicativeExpression
410a0ff2 559 { write_exp_elt_opcode (pstate, BINOP_ADD); }
c906108c 560| AdditiveExpression '-' MultiplicativeExpression
410a0ff2 561 { write_exp_elt_opcode (pstate, BINOP_SUB); }
c906108c
SS
562;
563
564ShiftExpression:
565 AdditiveExpression
566| ShiftExpression LSH AdditiveExpression
410a0ff2 567 { write_exp_elt_opcode (pstate, BINOP_LSH); }
c906108c 568| ShiftExpression RSH AdditiveExpression
410a0ff2 569 { write_exp_elt_opcode (pstate, BINOP_RSH); }
c906108c
SS
570/* | ShiftExpression >>> AdditiveExpression { FIXME } */
571;
572
573RelationalExpression:
574 ShiftExpression
575| RelationalExpression '<' ShiftExpression
410a0ff2 576 { write_exp_elt_opcode (pstate, BINOP_LESS); }
c906108c 577| RelationalExpression '>' ShiftExpression
410a0ff2 578 { write_exp_elt_opcode (pstate, BINOP_GTR); }
c906108c 579| RelationalExpression LEQ ShiftExpression
410a0ff2 580 { write_exp_elt_opcode (pstate, BINOP_LEQ); }
c906108c 581| RelationalExpression GEQ ShiftExpression
410a0ff2 582 { write_exp_elt_opcode (pstate, BINOP_GEQ); }
c906108c
SS
583/* | RelationalExpresion INSTANCEOF ReferenceType { FIXME } */
584;
585
586EqualityExpression:
587 RelationalExpression
588| EqualityExpression EQUAL RelationalExpression
410a0ff2 589 { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
c906108c 590| EqualityExpression NOTEQUAL RelationalExpression
410a0ff2 591 { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
c906108c
SS
592;
593
594AndExpression:
595 EqualityExpression
596| AndExpression '&' EqualityExpression
410a0ff2 597 { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
c906108c
SS
598;
599
600ExclusiveOrExpression:
601 AndExpression
602| ExclusiveOrExpression '^' AndExpression
410a0ff2 603 { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
c906108c
SS
604;
605InclusiveOrExpression:
606 ExclusiveOrExpression
607| InclusiveOrExpression '|' ExclusiveOrExpression
410a0ff2 608 { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
c906108c
SS
609;
610
611ConditionalAndExpression:
612 InclusiveOrExpression
613| ConditionalAndExpression ANDAND InclusiveOrExpression
410a0ff2 614 { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
c906108c
SS
615;
616
617ConditionalOrExpression:
618 ConditionalAndExpression
619| ConditionalOrExpression OROR ConditionalAndExpression
410a0ff2 620 { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
c906108c
SS
621;
622
623ConditionalExpression:
624 ConditionalOrExpression
625| ConditionalOrExpression '?' Expression ':' ConditionalExpression
410a0ff2 626 { write_exp_elt_opcode (pstate, TERNOP_COND); }
c906108c
SS
627;
628
629AssignmentExpression:
630 ConditionalExpression
631| Assignment
632;
633
634Assignment:
635 LeftHandSide '=' ConditionalExpression
410a0ff2 636 { write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
c906108c 637| LeftHandSide ASSIGN_MODIFY ConditionalExpression
410a0ff2
SDJ
638 { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY);
639 write_exp_elt_opcode (pstate, $2);
640 write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); }
c906108c
SS
641;
642
643LeftHandSide:
644 ForcedName
410a0ff2 645 { push_expression_name (pstate, $1); }
c906108c 646| VARIABLE
1777feb0 647 /* Already written by write_dollar_variable. */
c906108c
SS
648| FieldAccess
649| ArrayAccess
650;
651
652
653Expression:
654 AssignmentExpression
655;
656
657%%
658/* Take care of parsing a number (anything that starts with a digit).
659 Set yylval and return the token type; update lexptr.
660 LEN is the number of characters in it. */
661
662/*** Needs some error checking for the float case ***/
663
664static int
410a0ff2
SDJ
665parse_number (struct parser_state *par_state,
666 const char *p, int len, int parsed_float, YYSTYPE *putithere)
c906108c 667{
710122da 668 ULONGEST n = 0;
c906108c
SS
669 ULONGEST limit, limit_div_base;
670
710122da
DC
671 int c;
672 int base = input_radix;
c906108c
SS
673
674 struct type *type;
675
676 if (parsed_float)
677 {
d30f5e1f
DE
678 const char *suffix;
679 int suffix_len;
680
681 if (! parse_float (p, len, &putithere->typed_val_float.dval, &suffix))
c906108c 682 return ERROR;
c906108c 683
d30f5e1f 684 suffix_len = p + len - suffix;
c906108c 685
d30f5e1f 686 if (suffix_len == 0)
410a0ff2
SDJ
687 putithere->typed_val_float.type
688 = parse_type (par_state)->builtin_double;
d30f5e1f
DE
689 else if (suffix_len == 1)
690 {
691 /* See if it has `f' or `d' suffix (float or double). */
692 if (tolower (*suffix) == 'f')
693 putithere->typed_val_float.type =
410a0ff2 694 parse_type (par_state)->builtin_float;
d30f5e1f
DE
695 else if (tolower (*suffix) == 'd')
696 putithere->typed_val_float.type =
410a0ff2 697 parse_type (par_state)->builtin_double;
d30f5e1f
DE
698 else
699 return ERROR;
700 }
c906108c
SS
701 else
702 return ERROR;
703
704 return FLOATING_POINT_LITERAL;
705 }
706
707 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
708 if (p[0] == '0')
709 switch (p[1])
710 {
711 case 'x':
712 case 'X':
713 if (len >= 3)
714 {
715 p += 2;
716 base = 16;
717 len -= 2;
718 }
719 break;
720
721 case 't':
722 case 'T':
723 case 'd':
724 case 'D':
725 if (len >= 3)
726 {
727 p += 2;
728 base = 10;
729 len -= 2;
730 }
731 break;
732
733 default:
734 base = 8;
735 break;
736 }
737
738 c = p[len-1];
1777feb0 739 /* A paranoid calculation of (1<<64)-1. */
c906108c 740 limit = (ULONGEST)0xffffffff;
551792a5 741 limit = ((limit << 16) << 16) | limit;
c906108c
SS
742 if (c == 'l' || c == 'L')
743 {
410a0ff2 744 type = parse_java_type (par_state)->builtin_long;
c906108c 745 len--;
c906108c
SS
746 }
747 else
748 {
410a0ff2 749 type = parse_java_type (par_state)->builtin_int;
c906108c
SS
750 }
751 limit_div_base = limit / (ULONGEST) base;
752
753 while (--len >= 0)
754 {
755 c = *p++;
756 if (c >= '0' && c <= '9')
757 c -= '0';
758 else if (c >= 'A' && c <= 'Z')
759 c -= 'A' - 10;
760 else if (c >= 'a' && c <= 'z')
761 c -= 'a' - 10;
762 else
763 return ERROR; /* Char not a digit */
764 if (c >= base)
765 return ERROR;
766 if (n > limit_div_base
767 || (n *= base) > limit - c)
8c554d79 768 error (_("Numeric constant too large"));
c906108c
SS
769 n += c;
770 }
771
385fa495 772 /* If the type is bigger than a 32-bit signed integer can be, implicitly
df4df182 773 promote to long. Java does not do this, so mark it as
410a0ff2
SDJ
774 parse_type (par_state)->builtin_uint64 rather than
775 parse_java_type (par_state)->builtin_long.
df4df182
UW
776 0x80000000 will become -0x80000000 instead of 0x80000000L, because we
777 don't know the sign at this point. */
410a0ff2
SDJ
778 if (type == parse_java_type (par_state)->builtin_int
779 && n > (ULONGEST)0x80000000)
780 type = parse_type (par_state)->builtin_uint64;
551792a5
DJ
781
782 putithere->typed_val_int.val = n;
783 putithere->typed_val_int.type = type;
784
785 return INTEGER_LITERAL;
c906108c
SS
786}
787
788struct token
789{
fe978cb0 790 char *oper;
c906108c
SS
791 int token;
792 enum exp_opcode opcode;
793};
794
795static const struct token tokentab3[] =
796 {
797 {">>=", ASSIGN_MODIFY, BINOP_RSH},
798 {"<<=", ASSIGN_MODIFY, BINOP_LSH}
799 };
800
801static const struct token tokentab2[] =
802 {
803 {"+=", ASSIGN_MODIFY, BINOP_ADD},
804 {"-=", ASSIGN_MODIFY, BINOP_SUB},
805 {"*=", ASSIGN_MODIFY, BINOP_MUL},
806 {"/=", ASSIGN_MODIFY, BINOP_DIV},
807 {"%=", ASSIGN_MODIFY, BINOP_REM},
808 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR},
809 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND},
810 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR},
811 {"++", INCREMENT, BINOP_END},
812 {"--", DECREMENT, BINOP_END},
813 {"&&", ANDAND, BINOP_END},
814 {"||", OROR, BINOP_END},
815 {"<<", LSH, BINOP_END},
816 {">>", RSH, BINOP_END},
817 {"==", EQUAL, BINOP_END},
818 {"!=", NOTEQUAL, BINOP_END},
819 {"<=", LEQ, BINOP_END},
820 {">=", GEQ, BINOP_END}
821 };
822
823/* Read one token, getting characters through lexptr. */
824
825static int
09be204e 826yylex (void)
c906108c
SS
827{
828 int c;
829 int namelen;
830 unsigned int i;
d7561cbb
KS
831 const char *tokstart;
832 const char *tokptr;
c906108c
SS
833 int tempbufindex;
834 static char *tempbuf;
835 static int tempbufsize;
836
837 retry:
838
065432a8
PM
839 prev_lexptr = lexptr;
840
c906108c
SS
841 tokstart = lexptr;
842 /* See if it is a special token of length 3. */
843 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
fe978cb0 844 if (strncmp (tokstart, tokentab3[i].oper, 3) == 0)
c906108c
SS
845 {
846 lexptr += 3;
847 yylval.opcode = tokentab3[i].opcode;
848 return tokentab3[i].token;
849 }
850
851 /* See if it is a special token of length 2. */
852 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
fe978cb0 853 if (strncmp (tokstart, tokentab2[i].oper, 2) == 0)
c906108c
SS
854 {
855 lexptr += 2;
856 yylval.opcode = tokentab2[i].opcode;
857 return tokentab2[i].token;
858 }
859
860 switch (c = *tokstart)
861 {
862 case 0:
863 return 0;
864
865 case ' ':
866 case '\t':
867 case '\n':
868 lexptr++;
869 goto retry;
870
871 case '\'':
872 /* We either have a character constant ('0' or '\177' for example)
873 or we have a quoted symbol reference ('foo(int,int)' in C++
1777feb0 874 for example). */
c906108c
SS
875 lexptr++;
876 c = *lexptr++;
877 if (c == '\\')
410a0ff2 878 c = parse_escape (parse_gdbarch (pstate), &lexptr);
c906108c 879 else if (c == '\'')
8c554d79 880 error (_("Empty character constant"));
c906108c
SS
881
882 yylval.typed_val_int.val = c;
410a0ff2 883 yylval.typed_val_int.type = parse_java_type (pstate)->builtin_char;
c906108c
SS
884
885 c = *lexptr++;
886 if (c != '\'')
887 {
888 namelen = skip_quoted (tokstart) - tokstart;
889 if (namelen > 2)
890 {
891 lexptr = tokstart + namelen;
892 if (lexptr[-1] != '\'')
8c554d79 893 error (_("Unmatched single quote"));
c906108c
SS
894 namelen -= 2;
895 tokstart++;
896 goto tryname;
897 }
8c554d79 898 error (_("Invalid character constant"));
c906108c
SS
899 }
900 return INTEGER_LITERAL;
901
902 case '(':
903 paren_depth++;
904 lexptr++;
905 return c;
906
907 case ')':
908 if (paren_depth == 0)
909 return 0;
910 paren_depth--;
911 lexptr++;
912 return c;
913
914 case ',':
915 if (comma_terminates && paren_depth == 0)
916 return 0;
917 lexptr++;
918 return c;
919
920 case '.':
921 /* Might be a floating point number. */
922 if (lexptr[1] < '0' || lexptr[1] > '9')
1777feb0 923 goto symbol; /* Nope, must be a symbol. */
c906108c
SS
924 /* FALL THRU into number case. */
925
926 case '0':
927 case '1':
928 case '2':
929 case '3':
930 case '4':
931 case '5':
932 case '6':
933 case '7':
934 case '8':
935 case '9':
936 {
937 /* It's a number. */
938 int got_dot = 0, got_e = 0, toktype;
d7561cbb 939 const char *p = tokstart;
c906108c
SS
940 int hex = input_radix > 10;
941
942 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
943 {
944 p += 2;
945 hex = 1;
946 }
947 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
948 {
949 p += 2;
950 hex = 0;
951 }
952
953 for (;; ++p)
954 {
955 /* This test includes !hex because 'e' is a valid hex digit
956 and thus does not indicate a floating point number when
957 the radix is hex. */
958 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
959 got_dot = got_e = 1;
960 /* This test does not include !hex, because a '.' always indicates
961 a decimal floating point number regardless of the radix. */
962 else if (!got_dot && *p == '.')
963 got_dot = 1;
964 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
965 && (*p == '-' || *p == '+'))
966 /* This is the sign of the exponent, not the end of the
967 number. */
968 continue;
969 /* We will take any letters or digits. parse_number will
970 complain if past the radix, or if L or U are not final. */
971 else if ((*p < '0' || *p > '9')
972 && ((*p < 'a' || *p > 'z')
973 && (*p < 'A' || *p > 'Z')))
974 break;
975 }
410a0ff2
SDJ
976 toktype = parse_number (pstate, tokstart, p - tokstart,
977 got_dot|got_e, &yylval);
c906108c
SS
978 if (toktype == ERROR)
979 {
980 char *err_copy = (char *) alloca (p - tokstart + 1);
981
982 memcpy (err_copy, tokstart, p - tokstart);
983 err_copy[p - tokstart] = 0;
8c554d79 984 error (_("Invalid number \"%s\""), err_copy);
c906108c
SS
985 }
986 lexptr = p;
987 return toktype;
988 }
989
990 case '+':
991 case '-':
992 case '*':
993 case '/':
994 case '%':
995 case '|':
996 case '&':
997 case '^':
998 case '~':
999 case '!':
1000 case '<':
1001 case '>':
1002 case '[':
1003 case ']':
1004 case '?':
1005 case ':':
1006 case '=':
1007 case '{':
1008 case '}':
1009 symbol:
1010 lexptr++;
1011 return c;
1012
1013 case '"':
1014
1015 /* Build the gdb internal form of the input string in tempbuf,
1016 translating any standard C escape forms seen. Note that the
1017 buffer is null byte terminated *only* for the convenience of
1018 debugging gdb itself and printing the buffer contents when
1019 the buffer contains no embedded nulls. Gdb does not depend
1020 upon the buffer being null byte terminated, it uses the length
1021 string instead. This allows gdb to handle C strings (as well
1022 as strings in other languages) with embedded null bytes */
1023
1024 tokptr = ++tokstart;
1025 tempbufindex = 0;
1026
1027 do {
1028 /* Grow the static temp buffer if necessary, including allocating
1777feb0 1029 the first one on demand. */
c906108c
SS
1030 if (tempbufindex + 1 >= tempbufsize)
1031 {
1032 tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
1033 }
1034 switch (*tokptr)
1035 {
1036 case '\0':
1037 case '"':
1777feb0 1038 /* Do nothing, loop will terminate. */
c906108c
SS
1039 break;
1040 case '\\':
1041 tokptr++;
410a0ff2 1042 c = parse_escape (parse_gdbarch (pstate), &tokptr);
c906108c
SS
1043 if (c == -1)
1044 {
1045 continue;
1046 }
1047 tempbuf[tempbufindex++] = c;
1048 break;
1049 default:
1050 tempbuf[tempbufindex++] = *tokptr++;
1051 break;
1052 }
1053 } while ((*tokptr != '"') && (*tokptr != '\0'));
1054 if (*tokptr++ != '"')
1055 {
8c554d79 1056 error (_("Unterminated string in expression"));
c906108c
SS
1057 }
1058 tempbuf[tempbufindex] = '\0'; /* See note above */
1059 yylval.sval.ptr = tempbuf;
1060 yylval.sval.length = tempbufindex;
1061 lexptr = tokptr;
1062 return (STRING_LITERAL);
1063 }
1064
1065 if (!(c == '_' || c == '$'
1066 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1067 /* We must have come across a bad character (e.g. ';'). */
8c554d79 1068 error (_("Invalid character '%c' in expression"), c);
c906108c
SS
1069
1070 /* It's a name. See how long it is. */
1071 namelen = 0;
1072 for (c = tokstart[namelen];
1073 (c == '_'
1074 || c == '$'
1075 || (c >= '0' && c <= '9')
1076 || (c >= 'a' && c <= 'z')
1077 || (c >= 'A' && c <= 'Z')
1078 || c == '<');
1079 )
1080 {
1081 if (c == '<')
1082 {
1083 int i = namelen;
1084 while (tokstart[++i] && tokstart[i] != '>');
1085 if (tokstart[i] == '>')
1086 namelen = i;
1087 }
1088 c = tokstart[++namelen];
1089 }
1090
1091 /* The token "if" terminates the expression and is NOT
1092 removed from the input stream. */
1093 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1094 {
1095 return 0;
1096 }
1097
1098 lexptr += namelen;
1099
1100 tryname:
1101
1102 /* Catch specific keywords. Should be done with a data structure. */
1103 switch (namelen)
1104 {
1105 case 7:
1e5e79d0 1106 if (strncmp (tokstart, "boolean", 7) == 0)
c906108c
SS
1107 return BOOLEAN;
1108 break;
1109 case 6:
1e5e79d0 1110 if (strncmp (tokstart, "double", 6) == 0)
c906108c
SS
1111 return DOUBLE;
1112 break;
1113 case 5:
1e5e79d0 1114 if (strncmp (tokstart, "short", 5) == 0)
c906108c 1115 return SHORT;
1e5e79d0 1116 if (strncmp (tokstart, "false", 5) == 0)
c906108c
SS
1117 {
1118 yylval.lval = 0;
1119 return BOOLEAN_LITERAL;
1120 }
1e5e79d0 1121 if (strncmp (tokstart, "super", 5) == 0)
c906108c 1122 return SUPER;
1e5e79d0 1123 if (strncmp (tokstart, "float", 5) == 0)
c906108c
SS
1124 return FLOAT;
1125 break;
1126 case 4:
1e5e79d0 1127 if (strncmp (tokstart, "long", 4) == 0)
c906108c 1128 return LONG;
1e5e79d0 1129 if (strncmp (tokstart, "byte", 4) == 0)
c906108c 1130 return BYTE;
1e5e79d0 1131 if (strncmp (tokstart, "char", 4) == 0)
c906108c 1132 return CHAR;
1e5e79d0 1133 if (strncmp (tokstart, "true", 4) == 0)
c906108c
SS
1134 {
1135 yylval.lval = 1;
1136 return BOOLEAN_LITERAL;
1137 }
c906108c
SS
1138 break;
1139 case 3:
bf896cb0 1140 if (strncmp (tokstart, "int", 3) == 0)
c906108c 1141 return INT;
bf896cb0 1142 if (strncmp (tokstart, "new", 3) == 0)
c906108c
SS
1143 return NEW;
1144 break;
1145 default:
1146 break;
1147 }
1148
1149 yylval.sval.ptr = tokstart;
1150 yylval.sval.length = namelen;
1151
1152 if (*tokstart == '$')
1153 {
410a0ff2 1154 write_dollar_variable (pstate, yylval.sval);
c906108c
SS
1155 return VARIABLE;
1156 }
1157
1158 /* Input names that aren't symbols but ARE valid hex numbers,
1159 when the input radix permits them, can be names or numbers
1160 depending on the parse. Note we support radixes > 16 here. */
1161 if (((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
1162 (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1163 {
1164 YYSTYPE newlval; /* Its value is ignored. */
410a0ff2 1165 int hextype = parse_number (pstate, tokstart, namelen, 0, &newlval);
c906108c
SS
1166 if (hextype == INTEGER_LITERAL)
1167 return NAME_OR_INT;
1168 }
1169 return IDENTIFIER;
1170}
1171
410a0ff2
SDJ
1172int
1173java_parse (struct parser_state *par_state)
1174{
1175 int result;
1176 struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
1177
1178 /* Setting up the parser state. */
1179 gdb_assert (par_state != NULL);
1180 pstate = par_state;
1181
1182 result = yyparse ();
1183 do_cleanups (c);
1184
1185 return result;
1186}
1187
c906108c 1188void
09be204e 1189yyerror (char *msg)
c906108c 1190{
065432a8
PM
1191 if (prev_lexptr)
1192 lexptr = prev_lexptr;
1193
8c554d79
TT
1194 if (msg)
1195 error (_("%s: near `%s'"), msg, lexptr);
1196 else
1197 error (_("error in expression, near `%s'"), lexptr);
c906108c
SS
1198}
1199
1200static struct type *
09be204e 1201java_type_from_name (struct stoken name)
c906108c
SS
1202{
1203 char *tmp = copy_name (name);
1204 struct type *typ = java_lookup_class (tmp);
1205 if (typ == NULL || TYPE_CODE (typ) != TYPE_CODE_STRUCT)
8c554d79 1206 error (_("No class named `%s'"), tmp);
c906108c
SS
1207 return typ;
1208}
1209
1210/* If NAME is a valid variable name in this scope, push it and return 1.
1777feb0 1211 Otherwise, return 0. */
c906108c
SS
1212
1213static int
410a0ff2 1214push_variable (struct parser_state *par_state, struct stoken name)
c906108c
SS
1215{
1216 char *tmp = copy_name (name);
1993b719 1217 struct field_of_this_result is_a_field_of_this;
d12307c1 1218 struct block_symbol sym;
410a0ff2 1219
176620f1 1220 sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN,
2570f2b7 1221 &is_a_field_of_this);
d12307c1 1222 if (sym.symbol && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
c906108c 1223 {
d12307c1 1224 if (symbol_read_needs_frame (sym.symbol))
c906108c
SS
1225 {
1226 if (innermost_block == 0 ||
d12307c1
PMR
1227 contained_in (sym.block, innermost_block))
1228 innermost_block = sym.block;
c906108c
SS
1229 }
1230
410a0ff2 1231 write_exp_elt_opcode (par_state, OP_VAR_VALUE);
63e43d3a 1232 write_exp_elt_block (par_state, sym.block);
d12307c1 1233 write_exp_elt_sym (par_state, sym.symbol);
410a0ff2 1234 write_exp_elt_opcode (par_state, OP_VAR_VALUE);
c906108c
SS
1235 return 1;
1236 }
1993b719 1237 if (is_a_field_of_this.type != NULL)
c906108c
SS
1238 {
1239 /* it hangs off of `this'. Must not inadvertently convert from a
1240 method call to data ref. */
1241 if (innermost_block == 0 ||
d12307c1
PMR
1242 contained_in (sym.block, innermost_block))
1243 innermost_block = sym.block;
410a0ff2
SDJ
1244 write_exp_elt_opcode (par_state, OP_THIS);
1245 write_exp_elt_opcode (par_state, OP_THIS);
1246 write_exp_elt_opcode (par_state, STRUCTOP_PTR);
1247 write_exp_string (par_state, name);
1248 write_exp_elt_opcode (par_state, STRUCTOP_PTR);
c906108c
SS
1249 return 1;
1250 }
1251 return 0;
1252}
1253
1254/* Assuming a reference expression has been pushed, emit the
dc5000e7 1255 STRUCTOP_PTR ops to access the field named NAME. If NAME is a
1777feb0 1256 qualified name (has '.'), generate a field access for each part. */
c906108c
SS
1257
1258static void
410a0ff2 1259push_fieldnames (struct parser_state *par_state, struct stoken name)
c906108c
SS
1260{
1261 int i;
1262 struct stoken token;
1263 token.ptr = name.ptr;
1264 for (i = 0; ; i++)
1265 {
1266 if (i == name.length || name.ptr[i] == '.')
1267 {
1777feb0 1268 /* token.ptr is start of current field name. */
c906108c 1269 token.length = &name.ptr[i] - token.ptr;
410a0ff2
SDJ
1270 write_exp_elt_opcode (par_state, STRUCTOP_PTR);
1271 write_exp_string (par_state, token);
1272 write_exp_elt_opcode (par_state, STRUCTOP_PTR);
c906108c
SS
1273 token.ptr += token.length + 1;
1274 }
1275 if (i >= name.length)
1276 break;
1277 }
1278}
1279
1280/* Helper routine for push_expression_name.
1281 Handle a qualified name, where DOT_INDEX is the index of the first '.' */
1282
1283static void
410a0ff2
SDJ
1284push_qualified_expression_name (struct parser_state *par_state,
1285 struct stoken name, int dot_index)
c906108c
SS
1286{
1287 struct stoken token;
1288 char *tmp;
1289 struct type *typ;
1290
1291 token.ptr = name.ptr;
1292 token.length = dot_index;
1293
410a0ff2 1294 if (push_variable (par_state, token))
c906108c
SS
1295 {
1296 token.ptr = name.ptr + dot_index + 1;
1297 token.length = name.length - dot_index - 1;
410a0ff2 1298 push_fieldnames (par_state, token);
c906108c
SS
1299 return;
1300 }
1301
1302 token.ptr = name.ptr;
1303 for (;;)
1304 {
1305 token.length = dot_index;
1306 tmp = copy_name (token);
1307 typ = java_lookup_class (tmp);
1308 if (typ != NULL)
1309 {
1310 if (dot_index == name.length)
1311 {
410a0ff2
SDJ
1312 write_exp_elt_opcode (par_state, OP_TYPE);
1313 write_exp_elt_type (par_state, typ);
1314 write_exp_elt_opcode (par_state, OP_TYPE);
c906108c
SS
1315 return;
1316 }
1317 dot_index++; /* Skip '.' */
1318 name.ptr += dot_index;
1319 name.length -= dot_index;
1320 dot_index = 0;
1321 while (dot_index < name.length && name.ptr[dot_index] != '.')
1322 dot_index++;
1323 token.ptr = name.ptr;
1324 token.length = dot_index;
410a0ff2
SDJ
1325 write_exp_elt_opcode (par_state, OP_SCOPE);
1326 write_exp_elt_type (par_state, typ);
1327 write_exp_string (par_state, token);
1328 write_exp_elt_opcode (par_state, OP_SCOPE);
c906108c
SS
1329 if (dot_index < name.length)
1330 {
1331 dot_index++;
1332 name.ptr += dot_index;
1333 name.length -= dot_index;
410a0ff2 1334 push_fieldnames (par_state, name);
c906108c
SS
1335 }
1336 return;
1337 }
1338 else if (dot_index >= name.length)
1339 break;
1340 dot_index++; /* Skip '.' */
1341 while (dot_index < name.length && name.ptr[dot_index] != '.')
1342 dot_index++;
1343 }
8c554d79 1344 error (_("unknown type `%.*s'"), name.length, name.ptr);
c906108c
SS
1345}
1346
1347/* Handle Name in an expression (or LHS).
1777feb0 1348 Handle VAR, TYPE, TYPE.FIELD1....FIELDN and VAR.FIELD1....FIELDN. */
c906108c
SS
1349
1350static void
410a0ff2 1351push_expression_name (struct parser_state *par_state, struct stoken name)
c906108c
SS
1352{
1353 char *tmp;
1354 struct type *typ;
c906108c
SS
1355 int i;
1356
1357 for (i = 0; i < name.length; i++)
1358 {
1359 if (name.ptr[i] == '.')
1360 {
1777feb0 1361 /* It's a Qualified Expression Name. */
410a0ff2 1362 push_qualified_expression_name (par_state, name, i);
c906108c
SS
1363 return;
1364 }
1365 }
1366
1777feb0 1367 /* It's a Simple Expression Name. */
c906108c 1368
410a0ff2 1369 if (push_variable (par_state, name))
c906108c
SS
1370 return;
1371 tmp = copy_name (name);
1372 typ = java_lookup_class (tmp);
1373 if (typ != NULL)
1374 {
410a0ff2
SDJ
1375 write_exp_elt_opcode (par_state, OP_TYPE);
1376 write_exp_elt_type (par_state, typ);
1377 write_exp_elt_opcode (par_state, OP_TYPE);
c906108c
SS
1378 }
1379 else
1380 {
7c7b6655 1381 struct bound_minimal_symbol msymbol;
c906108c 1382
7c7b6655
TT
1383 msymbol = lookup_bound_minimal_symbol (tmp);
1384 if (msymbol.minsym != NULL)
410a0ff2 1385 write_exp_msymbol (par_state, msymbol);
c906108c 1386 else if (!have_full_symbols () && !have_partial_symbols ())
8c554d79 1387 error (_("No symbol table is loaded. Use the \"file\" command"));
c906108c 1388 else
8c56c1b9 1389 error (_("No symbol \"%s\" in current context."), tmp);
c906108c
SS
1390 }
1391
1392}
1393
1394
1395/* The following two routines, copy_exp and insert_exp, aren't specific to
1396 Java, so they could go in parse.c, but their only purpose is to support
1397 the parsing kludges we use in this file, so maybe it's best to isolate
1398 them here. */
1399
1400/* Copy the expression whose last element is at index ENDPOS - 1 in EXPR
1401 into a freshly malloc'ed struct expression. Its language_defn is set
1402 to null. */
1403static struct expression *
09be204e 1404copy_exp (struct expression *expr, int endpos)
c906108c
SS
1405{
1406 int len = length_of_subexp (expr, endpos);
fe978cb0
PA
1407 struct expression *newobj
1408 = (struct expression *) malloc (sizeof (*newobj) + EXP_ELEM_TO_BYTES (len));
410a0ff2 1409
fe978cb0
PA
1410 newobj->nelts = len;
1411 memcpy (newobj->elts, expr->elts + endpos - len, EXP_ELEM_TO_BYTES (len));
1412 newobj->language_defn = 0;
c906108c 1413
fe978cb0 1414 return newobj;
c906108c
SS
1415}
1416
1417/* Insert the expression NEW into the current expression (expout) at POS. */
1418static void
fe978cb0 1419insert_exp (struct parser_state *par_state, int pos, struct expression *newobj)
c906108c 1420{
fe978cb0 1421 int newlen = newobj->nelts;
410a0ff2 1422 int i;
c906108c
SS
1423
1424 /* Grow expout if necessary. In this function's only use at present,
1425 this should never be necessary. */
410a0ff2 1426 increase_expout_size (par_state, newlen);
c906108c 1427
410a0ff2
SDJ
1428 for (i = par_state->expout_ptr - 1; i >= pos; i--)
1429 par_state->expout->elts[i + newlen] = par_state->expout->elts[i];
c906108c 1430
fe978cb0 1431 memcpy (par_state->expout->elts + pos, newobj->elts,
410a0ff2
SDJ
1432 EXP_ELEM_TO_BYTES (newlen));
1433 par_state->expout_ptr += newlen;
c906108c 1434}
This page took 1.397303 seconds and 4 git commands to generate.