Convert f-exp.y to use operations
[deliverable/binutils-gdb.git] / gdb / f-exp.y
1
2 /* YACC parser for Fortran expressions, for GDB.
3 Copyright (C) 1986-2021 Free Software Foundation, Inc.
4
5 Contributed by Motorola. Adapted from the C parser by Farooq Butt
6 (fmbutt@engage.sps.mot.com).
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23 /* This was blantantly ripped off the C expression parser, please
24 be aware of that as you look at its basic structure -FMB */
25
26 /* Parse a F77 expression from text in a string,
27 and return the result as a struct expression pointer.
28 That structure contains arithmetic operations in reverse polish,
29 with constants represented by operations that are followed by special data.
30 See expression.h for the details of the format.
31 What is important here is that it can be built up sequentially
32 during the process of parsing; the lower levels of the tree always
33 come first in the result.
34
35 Note that malloc's and realloc's in this file are transformed to
36 xmalloc and xrealloc respectively by the same sed command in the
37 makefile that remaps any other malloc/realloc inserted by the parser
38 generator. Doing this with #defines and trying to control the interaction
39 with include files (<malloc.h> and <stdlib.h> for example) just became
40 too messy, particularly when such includes can be inserted at random
41 times by the parser generator. */
42
43 %{
44
45 #include "defs.h"
46 #include "expression.h"
47 #include "value.h"
48 #include "parser-defs.h"
49 #include "language.h"
50 #include "f-lang.h"
51 #include "bfd.h" /* Required by objfiles.h. */
52 #include "symfile.h" /* Required by objfiles.h. */
53 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
54 #include "block.h"
55 #include <ctype.h>
56 #include <algorithm>
57 #include "type-stack.h"
58 #include "f-exp.h"
59
60 #define parse_type(ps) builtin_type (ps->gdbarch ())
61 #define parse_f_type(ps) builtin_f_type (ps->gdbarch ())
62
63 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
64 etc). */
65 #define GDB_YY_REMAP_PREFIX f_
66 #include "yy-remap.h"
67
68 /* The state of the parser, used internally when we are parsing the
69 expression. */
70
71 static struct parser_state *pstate = NULL;
72
73 /* Depth of parentheses. */
74 static int paren_depth;
75
76 /* The current type stack. */
77 static struct type_stack *type_stack;
78
79 int yyparse (void);
80
81 static int yylex (void);
82
83 static void yyerror (const char *);
84
85 static void growbuf_by_size (int);
86
87 static int match_string_literal (void);
88
89 static void push_kind_type (LONGEST val, struct type *type);
90
91 static struct type *convert_to_kind_type (struct type *basetype, int kind);
92
93 using namespace expr;
94 %}
95
96 /* Although the yacc "value" of an expression is not used,
97 since the result is stored in the structure being created,
98 other node types do have values. */
99
100 %union
101 {
102 LONGEST lval;
103 struct {
104 LONGEST val;
105 struct type *type;
106 } typed_val;
107 struct {
108 gdb_byte val[16];
109 struct type *type;
110 } typed_val_float;
111 struct symbol *sym;
112 struct type *tval;
113 struct stoken sval;
114 struct ttype tsym;
115 struct symtoken ssym;
116 int voidval;
117 enum exp_opcode opcode;
118 struct internalvar *ivar;
119
120 struct type **tvec;
121 int *ivec;
122 }
123
124 %{
125 /* YYSTYPE gets defined by %union */
126 static int parse_number (struct parser_state *, const char *, int,
127 int, YYSTYPE *);
128 %}
129
130 %type <voidval> exp type_exp start variable
131 %type <tval> type typebase
132 %type <tvec> nonempty_typelist
133 /* %type <bval> block */
134
135 /* Fancy type parsing. */
136 %type <voidval> func_mod direct_abs_decl abs_decl
137 %type <tval> ptype
138
139 %token <typed_val> INT
140 %token <typed_val_float> FLOAT
141
142 /* Both NAME and TYPENAME tokens represent symbols in the input,
143 and both convey their data as strings.
144 But a TYPENAME is a string that happens to be defined as a typedef
145 or builtin type name (such as int or char)
146 and a NAME is any other symbol.
147 Contexts where this distinction is not important can use the
148 nonterminal "name", which matches either NAME or TYPENAME. */
149
150 %token <sval> STRING_LITERAL
151 %token <lval> BOOLEAN_LITERAL
152 %token <ssym> NAME
153 %token <tsym> TYPENAME
154 %token <voidval> COMPLETE
155 %type <sval> name
156 %type <ssym> name_not_typename
157
158 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
159 but which would parse as a valid number in the current input radix.
160 E.g. "c" when input_radix==16. Depending on the parse, it will be
161 turned into a name or into a number. */
162
163 %token <ssym> NAME_OR_INT
164
165 %token SIZEOF KIND
166 %token ERROR
167
168 /* Special type cases, put in to allow the parser to distinguish different
169 legal basetypes. */
170 %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD
171 %token LOGICAL_S8_KEYWORD
172 %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
173 %token COMPLEX_KEYWORD
174 %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD
175 %token BOOL_AND BOOL_OR BOOL_NOT
176 %token SINGLE DOUBLE PRECISION
177 %token <lval> CHARACTER
178
179 %token <sval> DOLLAR_VARIABLE
180
181 %token <opcode> ASSIGN_MODIFY
182 %token <opcode> UNOP_INTRINSIC BINOP_INTRINSIC
183 %token <opcode> UNOP_OR_BINOP_INTRINSIC
184
185 %left ','
186 %left ABOVE_COMMA
187 %right '=' ASSIGN_MODIFY
188 %right '?'
189 %left BOOL_OR
190 %right BOOL_NOT
191 %left BOOL_AND
192 %left '|'
193 %left '^'
194 %left '&'
195 %left EQUAL NOTEQUAL
196 %left LESSTHAN GREATERTHAN LEQ GEQ
197 %left LSH RSH
198 %left '@'
199 %left '+' '-'
200 %left '*' '/'
201 %right STARSTAR
202 %right '%'
203 %right UNARY
204 %right '('
205
206 \f
207 %%
208
209 start : exp
210 | type_exp
211 ;
212
213 type_exp: type
214 { pstate->push_new<type_operation> ($1); }
215 ;
216
217 exp : '(' exp ')'
218 { }
219 ;
220
221 /* Expressions, not including the comma operator. */
222 exp : '*' exp %prec UNARY
223 { pstate->wrap<unop_ind_operation> (); }
224 ;
225
226 exp : '&' exp %prec UNARY
227 { pstate->wrap<unop_addr_operation> (); }
228 ;
229
230 exp : '-' exp %prec UNARY
231 { pstate->wrap<unary_neg_operation> (); }
232 ;
233
234 exp : BOOL_NOT exp %prec UNARY
235 { pstate->wrap<unary_logical_not_operation> (); }
236 ;
237
238 exp : '~' exp %prec UNARY
239 { pstate->wrap<unary_complement_operation> (); }
240 ;
241
242 exp : SIZEOF exp %prec UNARY
243 { pstate->wrap<unop_sizeof_operation> (); }
244 ;
245
246 exp : KIND '(' exp ')' %prec UNARY
247 { pstate->wrap<fortran_kind_operation> (); }
248 ;
249
250 exp : UNOP_OR_BINOP_INTRINSIC '('
251 { pstate->start_arglist (); }
252 one_or_two_args ')'
253 {
254 int n = pstate->end_arglist ();
255 gdb_assert (n == 1 || n == 2);
256 if ($1 == FORTRAN_ASSOCIATED)
257 {
258 if (n == 1)
259 pstate->wrap<fortran_associated_1arg> ();
260 else
261 pstate->wrap2<fortran_associated_2arg> ();
262 }
263 else
264 {
265 std::vector<operation_up> args
266 = pstate->pop_vector (n);
267 gdb_assert ($1 == FORTRAN_LBOUND
268 || $1 == FORTRAN_UBOUND);
269 operation_up op;
270 if (n == 1)
271 op.reset
272 (new fortran_bound_1arg ($1,
273 std::move (args[0])));
274 else
275 op.reset
276 (new fortran_bound_2arg ($1,
277 std::move (args[0]),
278 std::move (args[1])));
279 pstate->push (std::move (op));
280 }
281 }
282 ;
283
284 one_or_two_args
285 : exp
286 { pstate->arglist_len = 1; }
287 | exp ',' exp
288 { pstate->arglist_len = 2; }
289 ;
290
291 /* No more explicit array operators, we treat everything in F77 as
292 a function call. The disambiguation as to whether we are
293 doing a subscript operation or a function call is done
294 later in eval.c. */
295
296 exp : exp '('
297 { pstate->start_arglist (); }
298 arglist ')'
299 {
300 std::vector<operation_up> args
301 = pstate->pop_vector (pstate->end_arglist ());
302 pstate->push_new<fortran_undetermined>
303 (pstate->pop (), std::move (args));
304 }
305 ;
306
307 exp : UNOP_INTRINSIC '(' exp ')'
308 {
309 switch ($1)
310 {
311 case UNOP_ABS:
312 pstate->wrap<fortran_abs_operation> ();
313 break;
314 case UNOP_FORTRAN_FLOOR:
315 pstate->wrap<fortran_floor_operation> ();
316 break;
317 case UNOP_FORTRAN_CEILING:
318 pstate->wrap<fortran_ceil_operation> ();
319 break;
320 case UNOP_FORTRAN_ALLOCATED:
321 pstate->wrap<fortran_allocated_operation> ();
322 break;
323 default:
324 gdb_assert_not_reached ("unhandled intrinsic");
325 }
326 }
327 ;
328
329 exp : BINOP_INTRINSIC '(' exp ',' exp ')'
330 {
331 switch ($1)
332 {
333 case BINOP_MOD:
334 pstate->wrap2<fortran_mod_operation> ();
335 break;
336 case BINOP_FORTRAN_MODULO:
337 pstate->wrap2<fortran_modulo_operation> ();
338 break;
339 case BINOP_FORTRAN_CMPLX:
340 pstate->wrap2<fortran_cmplx_operation> ();
341 break;
342 default:
343 gdb_assert_not_reached ("unhandled intrinsic");
344 }
345 }
346 ;
347
348 arglist :
349 ;
350
351 arglist : exp
352 { pstate->arglist_len = 1; }
353 ;
354
355 arglist : subrange
356 { pstate->arglist_len = 1; }
357 ;
358
359 arglist : arglist ',' exp %prec ABOVE_COMMA
360 { pstate->arglist_len++; }
361 ;
362
363 arglist : arglist ',' subrange %prec ABOVE_COMMA
364 { pstate->arglist_len++; }
365 ;
366
367 /* There are four sorts of subrange types in F90. */
368
369 subrange: exp ':' exp %prec ABOVE_COMMA
370 {
371 operation_up high = pstate->pop ();
372 operation_up low = pstate->pop ();
373 pstate->push_new<fortran_range_operation>
374 (RANGE_STANDARD, std::move (low),
375 std::move (high), operation_up ());
376 }
377 ;
378
379 subrange: exp ':' %prec ABOVE_COMMA
380 {
381 operation_up low = pstate->pop ();
382 pstate->push_new<fortran_range_operation>
383 (RANGE_HIGH_BOUND_DEFAULT, std::move (low),
384 operation_up (), operation_up ());
385 }
386 ;
387
388 subrange: ':' exp %prec ABOVE_COMMA
389 {
390 operation_up high = pstate->pop ();
391 pstate->push_new<fortran_range_operation>
392 (RANGE_LOW_BOUND_DEFAULT, operation_up (),
393 std::move (high), operation_up ());
394 }
395 ;
396
397 subrange: ':' %prec ABOVE_COMMA
398 {
399 pstate->push_new<fortran_range_operation>
400 (RANGE_LOW_BOUND_DEFAULT
401 | RANGE_HIGH_BOUND_DEFAULT,
402 operation_up (), operation_up (),
403 operation_up ());
404 }
405 ;
406
407 /* And each of the four subrange types can also have a stride. */
408 subrange: exp ':' exp ':' exp %prec ABOVE_COMMA
409 {
410 operation_up stride = pstate->pop ();
411 operation_up high = pstate->pop ();
412 operation_up low = pstate->pop ();
413 pstate->push_new<fortran_range_operation>
414 (RANGE_STANDARD | RANGE_HAS_STRIDE,
415 std::move (low), std::move (high),
416 std::move (stride));
417 }
418 ;
419
420 subrange: exp ':' ':' exp %prec ABOVE_COMMA
421 {
422 operation_up stride = pstate->pop ();
423 operation_up low = pstate->pop ();
424 pstate->push_new<fortran_range_operation>
425 (RANGE_HIGH_BOUND_DEFAULT
426 | RANGE_HAS_STRIDE,
427 std::move (low), operation_up (),
428 std::move (stride));
429 }
430 ;
431
432 subrange: ':' exp ':' exp %prec ABOVE_COMMA
433 {
434 operation_up stride = pstate->pop ();
435 operation_up high = pstate->pop ();
436 pstate->push_new<fortran_range_operation>
437 (RANGE_LOW_BOUND_DEFAULT
438 | RANGE_HAS_STRIDE,
439 operation_up (), std::move (high),
440 std::move (stride));
441 }
442 ;
443
444 subrange: ':' ':' exp %prec ABOVE_COMMA
445 {
446 operation_up stride = pstate->pop ();
447 pstate->push_new<fortran_range_operation>
448 (RANGE_LOW_BOUND_DEFAULT
449 | RANGE_HIGH_BOUND_DEFAULT
450 | RANGE_HAS_STRIDE,
451 operation_up (), operation_up (),
452 std::move (stride));
453 }
454 ;
455
456 complexnum: exp ',' exp
457 { }
458 ;
459
460 exp : '(' complexnum ')'
461 {
462 operation_up rhs = pstate->pop ();
463 operation_up lhs = pstate->pop ();
464 pstate->push_new<complex_operation>
465 (std::move (lhs), std::move (rhs),
466 parse_f_type (pstate)->builtin_complex_s16);
467 }
468 ;
469
470 exp : '(' type ')' exp %prec UNARY
471 {
472 pstate->push_new<unop_cast_operation>
473 (pstate->pop (), $2);
474 }
475 ;
476
477 exp : exp '%' name
478 {
479 pstate->push_new<structop_operation>
480 (pstate->pop (), copy_name ($3));
481 }
482 ;
483
484 exp : exp '%' name COMPLETE
485 {
486 structop_base_operation *op
487 = new structop_operation (pstate->pop (),
488 copy_name ($3));
489 pstate->mark_struct_expression (op);
490 pstate->push (operation_up (op));
491 }
492 ;
493
494 exp : exp '%' COMPLETE
495 {
496 structop_base_operation *op
497 = new structop_operation (pstate->pop (), "");
498 pstate->mark_struct_expression (op);
499 pstate->push (operation_up (op));
500 }
501 ;
502
503 /* Binary operators in order of decreasing precedence. */
504
505 exp : exp '@' exp
506 { pstate->wrap2<repeat_operation> (); }
507 ;
508
509 exp : exp STARSTAR exp
510 { pstate->wrap2<exp_operation> (); }
511 ;
512
513 exp : exp '*' exp
514 { pstate->wrap2<mul_operation> (); }
515 ;
516
517 exp : exp '/' exp
518 { pstate->wrap2<div_operation> (); }
519 ;
520
521 exp : exp '+' exp
522 { pstate->wrap2<add_operation> (); }
523 ;
524
525 exp : exp '-' exp
526 { pstate->wrap2<sub_operation> (); }
527 ;
528
529 exp : exp LSH exp
530 { pstate->wrap2<lsh_operation> (); }
531 ;
532
533 exp : exp RSH exp
534 { pstate->wrap2<rsh_operation> (); }
535 ;
536
537 exp : exp EQUAL exp
538 { pstate->wrap2<equal_operation> (); }
539 ;
540
541 exp : exp NOTEQUAL exp
542 { pstate->wrap2<notequal_operation> (); }
543 ;
544
545 exp : exp LEQ exp
546 { pstate->wrap2<leq_operation> (); }
547 ;
548
549 exp : exp GEQ exp
550 { pstate->wrap2<geq_operation> (); }
551 ;
552
553 exp : exp LESSTHAN exp
554 { pstate->wrap2<less_operation> (); }
555 ;
556
557 exp : exp GREATERTHAN exp
558 { pstate->wrap2<gtr_operation> (); }
559 ;
560
561 exp : exp '&' exp
562 { pstate->wrap2<bitwise_and_operation> (); }
563 ;
564
565 exp : exp '^' exp
566 { pstate->wrap2<bitwise_xor_operation> (); }
567 ;
568
569 exp : exp '|' exp
570 { pstate->wrap2<bitwise_ior_operation> (); }
571 ;
572
573 exp : exp BOOL_AND exp
574 { pstate->wrap2<logical_and_operation> (); }
575 ;
576
577
578 exp : exp BOOL_OR exp
579 { pstate->wrap2<logical_or_operation> (); }
580 ;
581
582 exp : exp '=' exp
583 { pstate->wrap2<assign_operation> (); }
584 ;
585
586 exp : exp ASSIGN_MODIFY exp
587 {
588 operation_up rhs = pstate->pop ();
589 operation_up lhs = pstate->pop ();
590 pstate->push_new<assign_modify_operation>
591 ($2, std::move (lhs), std::move (rhs));
592 }
593 ;
594
595 exp : INT
596 {
597 pstate->push_new<long_const_operation>
598 ($1.type, $1.val);
599 }
600 ;
601
602 exp : NAME_OR_INT
603 { YYSTYPE val;
604 parse_number (pstate, $1.stoken.ptr,
605 $1.stoken.length, 0, &val);
606 pstate->push_new<long_const_operation>
607 (val.typed_val.type,
608 val.typed_val.val);
609 }
610 ;
611
612 exp : FLOAT
613 {
614 float_data data;
615 std::copy (std::begin ($1.val), std::end ($1.val),
616 std::begin (data));
617 pstate->push_new<float_const_operation> ($1.type, data);
618 }
619 ;
620
621 exp : variable
622 ;
623
624 exp : DOLLAR_VARIABLE
625 { pstate->push_dollar ($1); }
626 ;
627
628 exp : SIZEOF '(' type ')' %prec UNARY
629 {
630 $3 = check_typedef ($3);
631 pstate->push_new<long_const_operation>
632 (parse_f_type (pstate)->builtin_integer,
633 TYPE_LENGTH ($3));
634 }
635 ;
636
637 exp : BOOLEAN_LITERAL
638 { pstate->push_new<bool_operation> ($1); }
639 ;
640
641 exp : STRING_LITERAL
642 {
643 pstate->push_new<string_operation>
644 (copy_name ($1));
645 }
646 ;
647
648 variable: name_not_typename
649 { struct block_symbol sym = $1.sym;
650 std::string name = copy_name ($1.stoken);
651 pstate->push_symbol (name.c_str (), sym);
652 }
653 ;
654
655
656 type : ptype
657 ;
658
659 ptype : typebase
660 | typebase abs_decl
661 {
662 /* This is where the interesting stuff happens. */
663 int done = 0;
664 int array_size;
665 struct type *follow_type = $1;
666 struct type *range_type;
667
668 while (!done)
669 switch (type_stack->pop ())
670 {
671 case tp_end:
672 done = 1;
673 break;
674 case tp_pointer:
675 follow_type = lookup_pointer_type (follow_type);
676 break;
677 case tp_reference:
678 follow_type = lookup_lvalue_reference_type (follow_type);
679 break;
680 case tp_array:
681 array_size = type_stack->pop_int ();
682 if (array_size != -1)
683 {
684 range_type =
685 create_static_range_type ((struct type *) NULL,
686 parse_f_type (pstate)
687 ->builtin_integer,
688 0, array_size - 1);
689 follow_type =
690 create_array_type ((struct type *) NULL,
691 follow_type, range_type);
692 }
693 else
694 follow_type = lookup_pointer_type (follow_type);
695 break;
696 case tp_function:
697 follow_type = lookup_function_type (follow_type);
698 break;
699 case tp_kind:
700 {
701 int kind_val = type_stack->pop_int ();
702 follow_type
703 = convert_to_kind_type (follow_type, kind_val);
704 }
705 break;
706 }
707 $$ = follow_type;
708 }
709 ;
710
711 abs_decl: '*'
712 { type_stack->push (tp_pointer); $$ = 0; }
713 | '*' abs_decl
714 { type_stack->push (tp_pointer); $$ = $2; }
715 | '&'
716 { type_stack->push (tp_reference); $$ = 0; }
717 | '&' abs_decl
718 { type_stack->push (tp_reference); $$ = $2; }
719 | direct_abs_decl
720 ;
721
722 direct_abs_decl: '(' abs_decl ')'
723 { $$ = $2; }
724 | '(' KIND '=' INT ')'
725 { push_kind_type ($4.val, $4.type); }
726 | '*' INT
727 { push_kind_type ($2.val, $2.type); }
728 | direct_abs_decl func_mod
729 { type_stack->push (tp_function); }
730 | func_mod
731 { type_stack->push (tp_function); }
732 ;
733
734 func_mod: '(' ')'
735 { $$ = 0; }
736 | '(' nonempty_typelist ')'
737 { free ($2); $$ = 0; }
738 ;
739
740 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
741 : TYPENAME
742 { $$ = $1.type; }
743 | INT_KEYWORD
744 { $$ = parse_f_type (pstate)->builtin_integer; }
745 | INT_S2_KEYWORD
746 { $$ = parse_f_type (pstate)->builtin_integer_s2; }
747 | CHARACTER
748 { $$ = parse_f_type (pstate)->builtin_character; }
749 | LOGICAL_S8_KEYWORD
750 { $$ = parse_f_type (pstate)->builtin_logical_s8; }
751 | LOGICAL_KEYWORD
752 { $$ = parse_f_type (pstate)->builtin_logical; }
753 | LOGICAL_S2_KEYWORD
754 { $$ = parse_f_type (pstate)->builtin_logical_s2; }
755 | LOGICAL_S1_KEYWORD
756 { $$ = parse_f_type (pstate)->builtin_logical_s1; }
757 | REAL_KEYWORD
758 { $$ = parse_f_type (pstate)->builtin_real; }
759 | REAL_S8_KEYWORD
760 { $$ = parse_f_type (pstate)->builtin_real_s8; }
761 | REAL_S16_KEYWORD
762 { $$ = parse_f_type (pstate)->builtin_real_s16; }
763 | COMPLEX_KEYWORD
764 { $$ = parse_f_type (pstate)->builtin_complex_s8; }
765 | COMPLEX_S8_KEYWORD
766 { $$ = parse_f_type (pstate)->builtin_complex_s8; }
767 | COMPLEX_S16_KEYWORD
768 { $$ = parse_f_type (pstate)->builtin_complex_s16; }
769 | COMPLEX_S32_KEYWORD
770 { $$ = parse_f_type (pstate)->builtin_complex_s32; }
771 | SINGLE PRECISION
772 { $$ = parse_f_type (pstate)->builtin_real;}
773 | DOUBLE PRECISION
774 { $$ = parse_f_type (pstate)->builtin_real_s8;}
775 | SINGLE COMPLEX_KEYWORD
776 { $$ = parse_f_type (pstate)->builtin_complex_s8;}
777 | DOUBLE COMPLEX_KEYWORD
778 { $$ = parse_f_type (pstate)->builtin_complex_s16;}
779 ;
780
781 nonempty_typelist
782 : type
783 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
784 $<ivec>$[0] = 1; /* Number of types in vector */
785 $$[1] = $1;
786 }
787 | nonempty_typelist ',' type
788 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
789 $$ = (struct type **) realloc ((char *) $1, len);
790 $$[$<ivec>$[0]] = $3;
791 }
792 ;
793
794 name : NAME
795 { $$ = $1.stoken; }
796 ;
797
798 name_not_typename : NAME
799 /* These would be useful if name_not_typename was useful, but it is just
800 a fake for "variable", so these cause reduce/reduce conflicts because
801 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
802 =exp) or just an exp. If name_not_typename was ever used in an lvalue
803 context where only a name could occur, this might be useful.
804 | NAME_OR_INT
805 */
806 ;
807
808 %%
809
810 /* Take care of parsing a number (anything that starts with a digit).
811 Set yylval and return the token type; update lexptr.
812 LEN is the number of characters in it. */
813
814 /*** Needs some error checking for the float case ***/
815
816 static int
817 parse_number (struct parser_state *par_state,
818 const char *p, int len, int parsed_float, YYSTYPE *putithere)
819 {
820 LONGEST n = 0;
821 LONGEST prevn = 0;
822 int c;
823 int base = input_radix;
824 int unsigned_p = 0;
825 int long_p = 0;
826 ULONGEST high_bit;
827 struct type *signed_type;
828 struct type *unsigned_type;
829
830 if (parsed_float)
831 {
832 /* It's a float since it contains a point or an exponent. */
833 /* [dD] is not understood as an exponent by parse_float,
834 change it to 'e'. */
835 char *tmp, *tmp2;
836
837 tmp = xstrdup (p);
838 for (tmp2 = tmp; *tmp2; ++tmp2)
839 if (*tmp2 == 'd' || *tmp2 == 'D')
840 *tmp2 = 'e';
841
842 /* FIXME: Should this use different types? */
843 putithere->typed_val_float.type = parse_f_type (pstate)->builtin_real_s8;
844 bool parsed = parse_float (tmp, len,
845 putithere->typed_val_float.type,
846 putithere->typed_val_float.val);
847 free (tmp);
848 return parsed? FLOAT : ERROR;
849 }
850
851 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
852 if (p[0] == '0')
853 switch (p[1])
854 {
855 case 'x':
856 case 'X':
857 if (len >= 3)
858 {
859 p += 2;
860 base = 16;
861 len -= 2;
862 }
863 break;
864
865 case 't':
866 case 'T':
867 case 'd':
868 case 'D':
869 if (len >= 3)
870 {
871 p += 2;
872 base = 10;
873 len -= 2;
874 }
875 break;
876
877 default:
878 base = 8;
879 break;
880 }
881
882 while (len-- > 0)
883 {
884 c = *p++;
885 if (isupper (c))
886 c = tolower (c);
887 if (len == 0 && c == 'l')
888 long_p = 1;
889 else if (len == 0 && c == 'u')
890 unsigned_p = 1;
891 else
892 {
893 int i;
894 if (c >= '0' && c <= '9')
895 i = c - '0';
896 else if (c >= 'a' && c <= 'f')
897 i = c - 'a' + 10;
898 else
899 return ERROR; /* Char not a digit */
900 if (i >= base)
901 return ERROR; /* Invalid digit in this base */
902 n *= base;
903 n += i;
904 }
905 /* Portably test for overflow (only works for nonzero values, so make
906 a second check for zero). */
907 if ((prevn >= n) && n != 0)
908 unsigned_p=1; /* Try something unsigned */
909 /* If range checking enabled, portably test for unsigned overflow. */
910 if (RANGE_CHECK && n != 0)
911 {
912 if ((unsigned_p && (unsigned)prevn >= (unsigned)n))
913 range_error (_("Overflow on numeric constant."));
914 }
915 prevn = n;
916 }
917
918 /* If the number is too big to be an int, or it's got an l suffix
919 then it's a long. Work out if this has to be a long by
920 shifting right and seeing if anything remains, and the
921 target int size is different to the target long size.
922
923 In the expression below, we could have tested
924 (n >> gdbarch_int_bit (parse_gdbarch))
925 to see if it was zero,
926 but too many compilers warn about that, when ints and longs
927 are the same size. So we shift it twice, with fewer bits
928 each time, for the same result. */
929
930 if ((gdbarch_int_bit (par_state->gdbarch ())
931 != gdbarch_long_bit (par_state->gdbarch ())
932 && ((n >> 2)
933 >> (gdbarch_int_bit (par_state->gdbarch ())-2))) /* Avoid
934 shift warning */
935 || long_p)
936 {
937 high_bit = ((ULONGEST)1)
938 << (gdbarch_long_bit (par_state->gdbarch ())-1);
939 unsigned_type = parse_type (par_state)->builtin_unsigned_long;
940 signed_type = parse_type (par_state)->builtin_long;
941 }
942 else
943 {
944 high_bit =
945 ((ULONGEST)1) << (gdbarch_int_bit (par_state->gdbarch ()) - 1);
946 unsigned_type = parse_type (par_state)->builtin_unsigned_int;
947 signed_type = parse_type (par_state)->builtin_int;
948 }
949
950 putithere->typed_val.val = n;
951
952 /* If the high bit of the worked out type is set then this number
953 has to be unsigned. */
954
955 if (unsigned_p || (n & high_bit))
956 putithere->typed_val.type = unsigned_type;
957 else
958 putithere->typed_val.type = signed_type;
959
960 return INT;
961 }
962
963 /* Called to setup the type stack when we encounter a '(kind=N)' type
964 modifier, performs some bounds checking on 'N' and then pushes this to
965 the type stack followed by the 'tp_kind' marker. */
966 static void
967 push_kind_type (LONGEST val, struct type *type)
968 {
969 int ival;
970
971 if (type->is_unsigned ())
972 {
973 ULONGEST uval = static_cast <ULONGEST> (val);
974 if (uval > INT_MAX)
975 error (_("kind value out of range"));
976 ival = static_cast <int> (uval);
977 }
978 else
979 {
980 if (val > INT_MAX || val < 0)
981 error (_("kind value out of range"));
982 ival = static_cast <int> (val);
983 }
984
985 type_stack->push (ival);
986 type_stack->push (tp_kind);
987 }
988
989 /* Called when a type has a '(kind=N)' modifier after it, for example
990 'character(kind=1)'. The BASETYPE is the type described by 'character'
991 in our example, and KIND is the integer '1'. This function returns a
992 new type that represents the basetype of a specific kind. */
993 static struct type *
994 convert_to_kind_type (struct type *basetype, int kind)
995 {
996 if (basetype == parse_f_type (pstate)->builtin_character)
997 {
998 /* Character of kind 1 is a special case, this is the same as the
999 base character type. */
1000 if (kind == 1)
1001 return parse_f_type (pstate)->builtin_character;
1002 }
1003 else if (basetype == parse_f_type (pstate)->builtin_complex_s8)
1004 {
1005 if (kind == 4)
1006 return parse_f_type (pstate)->builtin_complex_s8;
1007 else if (kind == 8)
1008 return parse_f_type (pstate)->builtin_complex_s16;
1009 else if (kind == 16)
1010 return parse_f_type (pstate)->builtin_complex_s32;
1011 }
1012 else if (basetype == parse_f_type (pstate)->builtin_real)
1013 {
1014 if (kind == 4)
1015 return parse_f_type (pstate)->builtin_real;
1016 else if (kind == 8)
1017 return parse_f_type (pstate)->builtin_real_s8;
1018 else if (kind == 16)
1019 return parse_f_type (pstate)->builtin_real_s16;
1020 }
1021 else if (basetype == parse_f_type (pstate)->builtin_logical)
1022 {
1023 if (kind == 1)
1024 return parse_f_type (pstate)->builtin_logical_s1;
1025 else if (kind == 2)
1026 return parse_f_type (pstate)->builtin_logical_s2;
1027 else if (kind == 4)
1028 return parse_f_type (pstate)->builtin_logical;
1029 else if (kind == 8)
1030 return parse_f_type (pstate)->builtin_logical_s8;
1031 }
1032 else if (basetype == parse_f_type (pstate)->builtin_integer)
1033 {
1034 if (kind == 2)
1035 return parse_f_type (pstate)->builtin_integer_s2;
1036 else if (kind == 4)
1037 return parse_f_type (pstate)->builtin_integer;
1038 else if (kind == 8)
1039 return parse_f_type (pstate)->builtin_integer_s8;
1040 }
1041
1042 error (_("unsupported kind %d for type %s"),
1043 kind, TYPE_SAFE_NAME (basetype));
1044
1045 /* Should never get here. */
1046 return nullptr;
1047 }
1048
1049 struct token
1050 {
1051 /* The string to match against. */
1052 const char *oper;
1053
1054 /* The lexer token to return. */
1055 int token;
1056
1057 /* The expression opcode to embed within the token. */
1058 enum exp_opcode opcode;
1059
1060 /* When this is true the string in OPER is matched exactly including
1061 case, when this is false OPER is matched case insensitively. */
1062 bool case_sensitive;
1063 };
1064
1065 /* List of Fortran operators. */
1066
1067 static const struct token fortran_operators[] =
1068 {
1069 { ".and.", BOOL_AND, BINOP_END, false },
1070 { ".or.", BOOL_OR, BINOP_END, false },
1071 { ".not.", BOOL_NOT, BINOP_END, false },
1072 { ".eq.", EQUAL, BINOP_END, false },
1073 { ".eqv.", EQUAL, BINOP_END, false },
1074 { ".neqv.", NOTEQUAL, BINOP_END, false },
1075 { ".xor.", NOTEQUAL, BINOP_END, false },
1076 { "==", EQUAL, BINOP_END, false },
1077 { ".ne.", NOTEQUAL, BINOP_END, false },
1078 { "/=", NOTEQUAL, BINOP_END, false },
1079 { ".le.", LEQ, BINOP_END, false },
1080 { "<=", LEQ, BINOP_END, false },
1081 { ".ge.", GEQ, BINOP_END, false },
1082 { ">=", GEQ, BINOP_END, false },
1083 { ".gt.", GREATERTHAN, BINOP_END, false },
1084 { ">", GREATERTHAN, BINOP_END, false },
1085 { ".lt.", LESSTHAN, BINOP_END, false },
1086 { "<", LESSTHAN, BINOP_END, false },
1087 { "**", STARSTAR, BINOP_EXP, false },
1088 };
1089
1090 /* Holds the Fortran representation of a boolean, and the integer value we
1091 substitute in when one of the matching strings is parsed. */
1092 struct f77_boolean_val
1093 {
1094 /* The string representing a Fortran boolean. */
1095 const char *name;
1096
1097 /* The integer value to replace it with. */
1098 int value;
1099 };
1100
1101 /* The set of Fortran booleans. These are matched case insensitively. */
1102 static const struct f77_boolean_val boolean_values[] =
1103 {
1104 { ".true.", 1 },
1105 { ".false.", 0 }
1106 };
1107
1108 static const struct token f77_keywords[] =
1109 {
1110 /* Historically these have always been lowercase only in GDB. */
1111 { "complex_16", COMPLEX_S16_KEYWORD, BINOP_END, true },
1112 { "complex_32", COMPLEX_S32_KEYWORD, BINOP_END, true },
1113 { "character", CHARACTER, BINOP_END, true },
1114 { "integer_2", INT_S2_KEYWORD, BINOP_END, true },
1115 { "logical_1", LOGICAL_S1_KEYWORD, BINOP_END, true },
1116 { "logical_2", LOGICAL_S2_KEYWORD, BINOP_END, true },
1117 { "logical_8", LOGICAL_S8_KEYWORD, BINOP_END, true },
1118 { "complex_8", COMPLEX_S8_KEYWORD, BINOP_END, true },
1119 { "integer", INT_KEYWORD, BINOP_END, true },
1120 { "logical", LOGICAL_KEYWORD, BINOP_END, true },
1121 { "real_16", REAL_S16_KEYWORD, BINOP_END, true },
1122 { "complex", COMPLEX_KEYWORD, BINOP_END, true },
1123 { "sizeof", SIZEOF, BINOP_END, true },
1124 { "real_8", REAL_S8_KEYWORD, BINOP_END, true },
1125 { "real", REAL_KEYWORD, BINOP_END, true },
1126 { "single", SINGLE, BINOP_END, true },
1127 { "double", DOUBLE, BINOP_END, true },
1128 { "precision", PRECISION, BINOP_END, true },
1129 /* The following correspond to actual functions in Fortran and are case
1130 insensitive. */
1131 { "kind", KIND, BINOP_END, false },
1132 { "abs", UNOP_INTRINSIC, UNOP_ABS, false },
1133 { "mod", BINOP_INTRINSIC, BINOP_MOD, false },
1134 { "floor", UNOP_INTRINSIC, UNOP_FORTRAN_FLOOR, false },
1135 { "ceiling", UNOP_INTRINSIC, UNOP_FORTRAN_CEILING, false },
1136 { "modulo", BINOP_INTRINSIC, BINOP_FORTRAN_MODULO, false },
1137 { "cmplx", BINOP_INTRINSIC, BINOP_FORTRAN_CMPLX, false },
1138 { "lbound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_LBOUND, false },
1139 { "ubound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_UBOUND, false },
1140 { "allocated", UNOP_INTRINSIC, UNOP_FORTRAN_ALLOCATED, false },
1141 { "associated", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ASSOCIATED, false },
1142 };
1143
1144 /* Implementation of a dynamically expandable buffer for processing input
1145 characters acquired through lexptr and building a value to return in
1146 yylval. Ripped off from ch-exp.y */
1147
1148 static char *tempbuf; /* Current buffer contents */
1149 static int tempbufsize; /* Size of allocated buffer */
1150 static int tempbufindex; /* Current index into buffer */
1151
1152 #define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */
1153
1154 #define CHECKBUF(size) \
1155 do { \
1156 if (tempbufindex + (size) >= tempbufsize) \
1157 { \
1158 growbuf_by_size (size); \
1159 } \
1160 } while (0);
1161
1162
1163 /* Grow the static temp buffer if necessary, including allocating the
1164 first one on demand. */
1165
1166 static void
1167 growbuf_by_size (int count)
1168 {
1169 int growby;
1170
1171 growby = std::max (count, GROWBY_MIN_SIZE);
1172 tempbufsize += growby;
1173 if (tempbuf == NULL)
1174 tempbuf = (char *) malloc (tempbufsize);
1175 else
1176 tempbuf = (char *) realloc (tempbuf, tempbufsize);
1177 }
1178
1179 /* Blatantly ripped off from ch-exp.y. This routine recognizes F77
1180 string-literals.
1181
1182 Recognize a string literal. A string literal is a nonzero sequence
1183 of characters enclosed in matching single quotes, except that
1184 a single character inside single quotes is a character literal, which
1185 we reject as a string literal. To embed the terminator character inside
1186 a string, it is simply doubled (I.E. 'this''is''one''string') */
1187
1188 static int
1189 match_string_literal (void)
1190 {
1191 const char *tokptr = pstate->lexptr;
1192
1193 for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
1194 {
1195 CHECKBUF (1);
1196 if (*tokptr == *pstate->lexptr)
1197 {
1198 if (*(tokptr + 1) == *pstate->lexptr)
1199 tokptr++;
1200 else
1201 break;
1202 }
1203 tempbuf[tempbufindex++] = *tokptr;
1204 }
1205 if (*tokptr == '\0' /* no terminator */
1206 || tempbufindex == 0) /* no string */
1207 return 0;
1208 else
1209 {
1210 tempbuf[tempbufindex] = '\0';
1211 yylval.sval.ptr = tempbuf;
1212 yylval.sval.length = tempbufindex;
1213 pstate->lexptr = ++tokptr;
1214 return STRING_LITERAL;
1215 }
1216 }
1217
1218 /* This is set if a NAME token appeared at the very end of the input
1219 string, with no whitespace separating the name from the EOF. This
1220 is used only when parsing to do field name completion. */
1221 static bool saw_name_at_eof;
1222
1223 /* This is set if the previously-returned token was a structure
1224 operator '%'. */
1225 static bool last_was_structop;
1226
1227 /* Read one token, getting characters through lexptr. */
1228
1229 static int
1230 yylex (void)
1231 {
1232 int c;
1233 int namelen;
1234 unsigned int token;
1235 const char *tokstart;
1236 bool saw_structop = last_was_structop;
1237
1238 last_was_structop = false;
1239
1240 retry:
1241
1242 pstate->prev_lexptr = pstate->lexptr;
1243
1244 tokstart = pstate->lexptr;
1245
1246 /* First of all, let us make sure we are not dealing with the
1247 special tokens .true. and .false. which evaluate to 1 and 0. */
1248
1249 if (*pstate->lexptr == '.')
1250 {
1251 for (int i = 0; i < ARRAY_SIZE (boolean_values); i++)
1252 {
1253 if (strncasecmp (tokstart, boolean_values[i].name,
1254 strlen (boolean_values[i].name)) == 0)
1255 {
1256 pstate->lexptr += strlen (boolean_values[i].name);
1257 yylval.lval = boolean_values[i].value;
1258 return BOOLEAN_LITERAL;
1259 }
1260 }
1261 }
1262
1263 /* See if it is a Fortran operator. */
1264 for (int i = 0; i < ARRAY_SIZE (fortran_operators); i++)
1265 if (strncasecmp (tokstart, fortran_operators[i].oper,
1266 strlen (fortran_operators[i].oper)) == 0)
1267 {
1268 gdb_assert (!fortran_operators[i].case_sensitive);
1269 pstate->lexptr += strlen (fortran_operators[i].oper);
1270 yylval.opcode = fortran_operators[i].opcode;
1271 return fortran_operators[i].token;
1272 }
1273
1274 switch (c = *tokstart)
1275 {
1276 case 0:
1277 if (saw_name_at_eof)
1278 {
1279 saw_name_at_eof = false;
1280 return COMPLETE;
1281 }
1282 else if (pstate->parse_completion && saw_structop)
1283 return COMPLETE;
1284 return 0;
1285
1286 case ' ':
1287 case '\t':
1288 case '\n':
1289 pstate->lexptr++;
1290 goto retry;
1291
1292 case '\'':
1293 token = match_string_literal ();
1294 if (token != 0)
1295 return (token);
1296 break;
1297
1298 case '(':
1299 paren_depth++;
1300 pstate->lexptr++;
1301 return c;
1302
1303 case ')':
1304 if (paren_depth == 0)
1305 return 0;
1306 paren_depth--;
1307 pstate->lexptr++;
1308 return c;
1309
1310 case ',':
1311 if (pstate->comma_terminates && paren_depth == 0)
1312 return 0;
1313 pstate->lexptr++;
1314 return c;
1315
1316 case '.':
1317 /* Might be a floating point number. */
1318 if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9')
1319 goto symbol; /* Nope, must be a symbol. */
1320 /* FALL THRU. */
1321
1322 case '0':
1323 case '1':
1324 case '2':
1325 case '3':
1326 case '4':
1327 case '5':
1328 case '6':
1329 case '7':
1330 case '8':
1331 case '9':
1332 {
1333 /* It's a number. */
1334 int got_dot = 0, got_e = 0, got_d = 0, toktype;
1335 const char *p = tokstart;
1336 int hex = input_radix > 10;
1337
1338 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1339 {
1340 p += 2;
1341 hex = 1;
1342 }
1343 else if (c == '0' && (p[1]=='t' || p[1]=='T'
1344 || p[1]=='d' || p[1]=='D'))
1345 {
1346 p += 2;
1347 hex = 0;
1348 }
1349
1350 for (;; ++p)
1351 {
1352 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1353 got_dot = got_e = 1;
1354 else if (!hex && !got_d && (*p == 'd' || *p == 'D'))
1355 got_dot = got_d = 1;
1356 else if (!hex && !got_dot && *p == '.')
1357 got_dot = 1;
1358 else if (((got_e && (p[-1] == 'e' || p[-1] == 'E'))
1359 || (got_d && (p[-1] == 'd' || p[-1] == 'D')))
1360 && (*p == '-' || *p == '+'))
1361 /* This is the sign of the exponent, not the end of the
1362 number. */
1363 continue;
1364 /* We will take any letters or digits. parse_number will
1365 complain if past the radix, or if L or U are not final. */
1366 else if ((*p < '0' || *p > '9')
1367 && ((*p < 'a' || *p > 'z')
1368 && (*p < 'A' || *p > 'Z')))
1369 break;
1370 }
1371 toktype = parse_number (pstate, tokstart, p - tokstart,
1372 got_dot|got_e|got_d,
1373 &yylval);
1374 if (toktype == ERROR)
1375 {
1376 char *err_copy = (char *) alloca (p - tokstart + 1);
1377
1378 memcpy (err_copy, tokstart, p - tokstart);
1379 err_copy[p - tokstart] = 0;
1380 error (_("Invalid number \"%s\"."), err_copy);
1381 }
1382 pstate->lexptr = p;
1383 return toktype;
1384 }
1385
1386 case '%':
1387 last_was_structop = true;
1388 /* Fall through. */
1389 case '+':
1390 case '-':
1391 case '*':
1392 case '/':
1393 case '|':
1394 case '&':
1395 case '^':
1396 case '~':
1397 case '!':
1398 case '@':
1399 case '<':
1400 case '>':
1401 case '[':
1402 case ']':
1403 case '?':
1404 case ':':
1405 case '=':
1406 case '{':
1407 case '}':
1408 symbol:
1409 pstate->lexptr++;
1410 return c;
1411 }
1412
1413 if (!(c == '_' || c == '$' || c ==':'
1414 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1415 /* We must have come across a bad character (e.g. ';'). */
1416 error (_("Invalid character '%c' in expression."), c);
1417
1418 namelen = 0;
1419 for (c = tokstart[namelen];
1420 (c == '_' || c == '$' || c == ':' || (c >= '0' && c <= '9')
1421 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1422 c = tokstart[++namelen]);
1423
1424 /* The token "if" terminates the expression and is NOT
1425 removed from the input stream. */
1426
1427 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1428 return 0;
1429
1430 pstate->lexptr += namelen;
1431
1432 /* Catch specific keywords. */
1433
1434 for (int i = 0; i < ARRAY_SIZE (f77_keywords); i++)
1435 if (strlen (f77_keywords[i].oper) == namelen
1436 && ((!f77_keywords[i].case_sensitive
1437 && strncasecmp (tokstart, f77_keywords[i].oper, namelen) == 0)
1438 || (f77_keywords[i].case_sensitive
1439 && strncmp (tokstart, f77_keywords[i].oper, namelen) == 0)))
1440 {
1441 yylval.opcode = f77_keywords[i].opcode;
1442 return f77_keywords[i].token;
1443 }
1444
1445 yylval.sval.ptr = tokstart;
1446 yylval.sval.length = namelen;
1447
1448 if (*tokstart == '$')
1449 return DOLLAR_VARIABLE;
1450
1451 /* Use token-type TYPENAME for symbols that happen to be defined
1452 currently as names of types; NAME for other symbols.
1453 The caller is not constrained to care about the distinction. */
1454 {
1455 std::string tmp = copy_name (yylval.sval);
1456 struct block_symbol result;
1457 enum domain_enum_tag lookup_domains[] =
1458 {
1459 STRUCT_DOMAIN,
1460 VAR_DOMAIN,
1461 MODULE_DOMAIN
1462 };
1463 int hextype;
1464
1465 for (int i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
1466 {
1467 result = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
1468 lookup_domains[i], NULL);
1469 if (result.symbol && SYMBOL_CLASS (result.symbol) == LOC_TYPEDEF)
1470 {
1471 yylval.tsym.type = SYMBOL_TYPE (result.symbol);
1472 return TYPENAME;
1473 }
1474
1475 if (result.symbol)
1476 break;
1477 }
1478
1479 yylval.tsym.type
1480 = language_lookup_primitive_type (pstate->language (),
1481 pstate->gdbarch (), tmp.c_str ());
1482 if (yylval.tsym.type != NULL)
1483 return TYPENAME;
1484
1485 /* Input names that aren't symbols but ARE valid hex numbers,
1486 when the input radix permits them, can be names or numbers
1487 depending on the parse. Note we support radixes > 16 here. */
1488 if (!result.symbol
1489 && ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10)
1490 || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1491 {
1492 YYSTYPE newlval; /* Its value is ignored. */
1493 hextype = parse_number (pstate, tokstart, namelen, 0, &newlval);
1494 if (hextype == INT)
1495 {
1496 yylval.ssym.sym = result;
1497 yylval.ssym.is_a_field_of_this = false;
1498 return NAME_OR_INT;
1499 }
1500 }
1501
1502 if (pstate->parse_completion && *pstate->lexptr == '\0')
1503 saw_name_at_eof = true;
1504
1505 /* Any other kind of symbol */
1506 yylval.ssym.sym = result;
1507 yylval.ssym.is_a_field_of_this = false;
1508 return NAME;
1509 }
1510 }
1511
1512 int
1513 f_language::parser (struct parser_state *par_state) const
1514 {
1515 /* Setting up the parser state. */
1516 scoped_restore pstate_restore = make_scoped_restore (&pstate);
1517 scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
1518 parser_debug);
1519 gdb_assert (par_state != NULL);
1520 pstate = par_state;
1521 last_was_structop = false;
1522 saw_name_at_eof = false;
1523 paren_depth = 0;
1524
1525 struct type_stack stack;
1526 scoped_restore restore_type_stack = make_scoped_restore (&type_stack,
1527 &stack);
1528
1529 int result = yyparse ();
1530 if (!result)
1531 pstate->set_operation (pstate->pop ());
1532 return result;
1533 }
1534
1535 static void
1536 yyerror (const char *msg)
1537 {
1538 if (pstate->prev_lexptr)
1539 pstate->lexptr = pstate->prev_lexptr;
1540
1541 error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
1542 }
This page took 0.0603939999999999 seconds and 5 git commands to generate.