gdb: remove symtab::blockvector
[binutils-gdb.git] / gdb / p-exp.y
1 /* YACC parser for Pascal expressions, for GDB.
2 Copyright (C) 2000-2022 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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/>. */
18
19 /* This file is derived from c-exp.y */
20
21 /* Parse a Pascal 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 /* Known bugs or limitations:
39 - pascal string operations are not supported at all.
40 - there are some problems with boolean types.
41 - Pascal type hexadecimal constants are not supported
42 because they conflict with the internal variables format.
43 Probably also lots of other problems, less well defined PM. */
44 %{
45
46 #include "defs.h"
47 #include <ctype.h>
48 #include "expression.h"
49 #include "value.h"
50 #include "parser-defs.h"
51 #include "language.h"
52 #include "p-lang.h"
53 #include "bfd.h" /* Required by objfiles.h. */
54 #include "symfile.h" /* Required by objfiles.h. */
55 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols. */
56 #include "block.h"
57 #include "completer.h"
58 #include "expop.h"
59
60 #define parse_type(ps) builtin_type (ps->gdbarch ())
61
62 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
63 etc). */
64 #define GDB_YY_REMAP_PREFIX pascal_
65 #include "yy-remap.h"
66
67 /* The state of the parser, used internally when we are parsing the
68 expression. */
69
70 static struct parser_state *pstate = NULL;
71
72 /* Depth of parentheses. */
73 static int paren_depth;
74
75 int yyparse (void);
76
77 static int yylex (void);
78
79 static void yyerror (const char *);
80
81 static char *uptok (const char *, int);
82
83 using namespace expr;
84 %}
85
86 /* Although the yacc "value" of an expression is not used,
87 since the result is stored in the structure being created,
88 other node types do have values. */
89
90 %union
91 {
92 LONGEST lval;
93 struct {
94 LONGEST val;
95 struct type *type;
96 } typed_val_int;
97 struct {
98 gdb_byte val[16];
99 struct type *type;
100 } typed_val_float;
101 struct symbol *sym;
102 struct type *tval;
103 struct stoken sval;
104 struct ttype tsym;
105 struct symtoken ssym;
106 int voidval;
107 const struct block *bval;
108 enum exp_opcode opcode;
109 struct internalvar *ivar;
110
111 struct type **tvec;
112 int *ivec;
113 }
114
115 %{
116 /* YYSTYPE gets defined by %union */
117 static int parse_number (struct parser_state *,
118 const char *, int, int, YYSTYPE *);
119
120 static struct type *current_type;
121 static int leftdiv_is_integer;
122 static void push_current_type (void);
123 static void pop_current_type (void);
124 static int search_field;
125 %}
126
127 %type <voidval> exp exp1 type_exp start normal_start variable qualified_name
128 %type <tval> type typebase
129 /* %type <bval> block */
130
131 /* Fancy type parsing. */
132 %type <tval> ptype
133
134 %token <typed_val_int> INT
135 %token <typed_val_float> FLOAT
136
137 /* Both NAME and TYPENAME tokens represent symbols in the input,
138 and both convey their data as strings.
139 But a TYPENAME is a string that happens to be defined as a typedef
140 or builtin type name (such as int or char)
141 and a NAME is any other symbol.
142 Contexts where this distinction is not important can use the
143 nonterminal "name", which matches either NAME or TYPENAME. */
144
145 %token <sval> STRING
146 %token <sval> FIELDNAME
147 %token <voidval> COMPLETE
148 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
149 %token <tsym> TYPENAME
150 %type <sval> name
151 %type <ssym> name_not_typename
152
153 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
154 but which would parse as a valid number in the current input radix.
155 E.g. "c" when input_radix==16. Depending on the parse, it will be
156 turned into a name or into a number. */
157
158 %token <ssym> NAME_OR_INT
159
160 %token STRUCT CLASS SIZEOF COLONCOLON
161 %token ERROR
162
163 /* Special type cases, put in to allow the parser to distinguish different
164 legal basetypes. */
165
166 %token <sval> DOLLAR_VARIABLE
167
168
169 /* Object pascal */
170 %token THIS
171 %token <lval> TRUEKEYWORD FALSEKEYWORD
172
173 %left ','
174 %left ABOVE_COMMA
175 %right ASSIGN
176 %left NOT
177 %left OR
178 %left XOR
179 %left ANDAND
180 %left '=' NOTEQUAL
181 %left '<' '>' LEQ GEQ
182 %left LSH RSH DIV MOD
183 %left '@'
184 %left '+' '-'
185 %left '*' '/'
186 %right UNARY INCREMENT DECREMENT
187 %right ARROW '.' '[' '('
188 %left '^'
189 %token <ssym> BLOCKNAME
190 %type <bval> block
191 %left COLONCOLON
192
193 \f
194 %%
195
196 start : { current_type = NULL;
197 search_field = 0;
198 leftdiv_is_integer = 0;
199 }
200 normal_start {}
201 ;
202
203 normal_start :
204 exp1
205 | type_exp
206 ;
207
208 type_exp: type
209 {
210 pstate->push_new<type_operation> ($1);
211 current_type = $1; } ;
212
213 /* Expressions, including the comma operator. */
214 exp1 : exp
215 | exp1 ',' exp
216 { pstate->wrap2<comma_operation> (); }
217 ;
218
219 /* Expressions, not including the comma operator. */
220 exp : exp '^' %prec UNARY
221 { pstate->wrap<unop_ind_operation> ();
222 if (current_type)
223 current_type = TYPE_TARGET_TYPE (current_type); }
224 ;
225
226 exp : '@' exp %prec UNARY
227 { pstate->wrap<unop_addr_operation> ();
228 if (current_type)
229 current_type = TYPE_POINTER_TYPE (current_type); }
230 ;
231
232 exp : '-' exp %prec UNARY
233 { pstate->wrap<unary_neg_operation> (); }
234 ;
235
236 exp : NOT exp %prec UNARY
237 { pstate->wrap<unary_logical_not_operation> (); }
238 ;
239
240 exp : INCREMENT '(' exp ')' %prec UNARY
241 { pstate->wrap<preinc_operation> (); }
242 ;
243
244 exp : DECREMENT '(' exp ')' %prec UNARY
245 { pstate->wrap<predec_operation> (); }
246 ;
247
248
249 field_exp : exp '.' %prec UNARY
250 { search_field = 1; }
251 ;
252
253 exp : field_exp FIELDNAME
254 {
255 pstate->push_new<structop_operation>
256 (pstate->pop (), copy_name ($2));
257 search_field = 0;
258 if (current_type)
259 {
260 while (current_type->code ()
261 == TYPE_CODE_PTR)
262 current_type =
263 TYPE_TARGET_TYPE (current_type);
264 current_type = lookup_struct_elt_type (
265 current_type, $2.ptr, 0);
266 }
267 }
268 ;
269
270
271 exp : field_exp name
272 {
273 pstate->push_new<structop_operation>
274 (pstate->pop (), copy_name ($2));
275 search_field = 0;
276 if (current_type)
277 {
278 while (current_type->code ()
279 == TYPE_CODE_PTR)
280 current_type =
281 TYPE_TARGET_TYPE (current_type);
282 current_type = lookup_struct_elt_type (
283 current_type, $2.ptr, 0);
284 }
285 }
286 ;
287 exp : field_exp name COMPLETE
288 {
289 structop_base_operation *op
290 = new structop_ptr_operation (pstate->pop (),
291 copy_name ($2));
292 pstate->mark_struct_expression (op);
293 pstate->push (operation_up (op));
294 }
295 ;
296 exp : field_exp COMPLETE
297 {
298 structop_base_operation *op
299 = new structop_ptr_operation (pstate->pop (), "");
300 pstate->mark_struct_expression (op);
301 pstate->push (operation_up (op));
302 }
303 ;
304
305 exp : exp '['
306 /* We need to save the current_type value. */
307 { const char *arrayname;
308 int arrayfieldindex
309 = pascal_is_string_type (current_type, NULL, NULL,
310 NULL, NULL, &arrayname);
311 if (arrayfieldindex)
312 {
313 current_type
314 = (current_type
315 ->field (arrayfieldindex - 1).type ());
316 pstate->push_new<structop_operation>
317 (pstate->pop (), arrayname);
318 }
319 push_current_type (); }
320 exp1 ']'
321 { pop_current_type ();
322 pstate->wrap2<subscript_operation> ();
323 if (current_type)
324 current_type = TYPE_TARGET_TYPE (current_type); }
325 ;
326
327 exp : exp '('
328 /* This is to save the value of arglist_len
329 being accumulated by an outer function call. */
330 { push_current_type ();
331 pstate->start_arglist (); }
332 arglist ')' %prec ARROW
333 {
334 std::vector<operation_up> args
335 = pstate->pop_vector (pstate->end_arglist ());
336 pstate->push_new<funcall_operation>
337 (pstate->pop (), std::move (args));
338 pop_current_type ();
339 if (current_type)
340 current_type = TYPE_TARGET_TYPE (current_type);
341 }
342 ;
343
344 arglist :
345 | exp
346 { pstate->arglist_len = 1; }
347 | arglist ',' exp %prec ABOVE_COMMA
348 { pstate->arglist_len++; }
349 ;
350
351 exp : type '(' exp ')' %prec UNARY
352 { if (current_type)
353 {
354 /* Allow automatic dereference of classes. */
355 if ((current_type->code () == TYPE_CODE_PTR)
356 && (TYPE_TARGET_TYPE (current_type)->code () == TYPE_CODE_STRUCT)
357 && (($1)->code () == TYPE_CODE_STRUCT))
358 pstate->wrap<unop_ind_operation> ();
359 }
360 pstate->push_new<unop_cast_operation>
361 (pstate->pop (), $1);
362 current_type = $1; }
363 ;
364
365 exp : '(' exp1 ')'
366 { }
367 ;
368
369 /* Binary operators in order of decreasing precedence. */
370
371 exp : exp '*' exp
372 { pstate->wrap2<mul_operation> (); }
373 ;
374
375 exp : exp '/' {
376 if (current_type && is_integral_type (current_type))
377 leftdiv_is_integer = 1;
378 }
379 exp
380 {
381 if (leftdiv_is_integer && current_type
382 && is_integral_type (current_type))
383 {
384 pstate->push_new<unop_cast_operation>
385 (pstate->pop (),
386 parse_type (pstate)->builtin_long_double);
387 current_type
388 = parse_type (pstate)->builtin_long_double;
389 leftdiv_is_integer = 0;
390 }
391
392 pstate->wrap2<div_operation> ();
393 }
394 ;
395
396 exp : exp DIV exp
397 { pstate->wrap2<intdiv_operation> (); }
398 ;
399
400 exp : exp MOD exp
401 { pstate->wrap2<rem_operation> (); }
402 ;
403
404 exp : exp '+' exp
405 { pstate->wrap2<add_operation> (); }
406 ;
407
408 exp : exp '-' exp
409 { pstate->wrap2<sub_operation> (); }
410 ;
411
412 exp : exp LSH exp
413 { pstate->wrap2<lsh_operation> (); }
414 ;
415
416 exp : exp RSH exp
417 { pstate->wrap2<rsh_operation> (); }
418 ;
419
420 exp : exp '=' exp
421 {
422 pstate->wrap2<equal_operation> ();
423 current_type = parse_type (pstate)->builtin_bool;
424 }
425 ;
426
427 exp : exp NOTEQUAL exp
428 {
429 pstate->wrap2<notequal_operation> ();
430 current_type = parse_type (pstate)->builtin_bool;
431 }
432 ;
433
434 exp : exp LEQ exp
435 {
436 pstate->wrap2<leq_operation> ();
437 current_type = parse_type (pstate)->builtin_bool;
438 }
439 ;
440
441 exp : exp GEQ exp
442 {
443 pstate->wrap2<geq_operation> ();
444 current_type = parse_type (pstate)->builtin_bool;
445 }
446 ;
447
448 exp : exp '<' exp
449 {
450 pstate->wrap2<less_operation> ();
451 current_type = parse_type (pstate)->builtin_bool;
452 }
453 ;
454
455 exp : exp '>' exp
456 {
457 pstate->wrap2<gtr_operation> ();
458 current_type = parse_type (pstate)->builtin_bool;
459 }
460 ;
461
462 exp : exp ANDAND exp
463 { pstate->wrap2<bitwise_and_operation> (); }
464 ;
465
466 exp : exp XOR exp
467 { pstate->wrap2<bitwise_xor_operation> (); }
468 ;
469
470 exp : exp OR exp
471 { pstate->wrap2<bitwise_ior_operation> (); }
472 ;
473
474 exp : exp ASSIGN exp
475 { pstate->wrap2<assign_operation> (); }
476 ;
477
478 exp : TRUEKEYWORD
479 {
480 pstate->push_new<bool_operation> ($1);
481 current_type = parse_type (pstate)->builtin_bool;
482 }
483 ;
484
485 exp : FALSEKEYWORD
486 {
487 pstate->push_new<bool_operation> ($1);
488 current_type = parse_type (pstate)->builtin_bool;
489 }
490 ;
491
492 exp : INT
493 {
494 pstate->push_new<long_const_operation>
495 ($1.type, $1.val);
496 current_type = $1.type;
497 }
498 ;
499
500 exp : NAME_OR_INT
501 { YYSTYPE val;
502 parse_number (pstate, $1.stoken.ptr,
503 $1.stoken.length, 0, &val);
504 pstate->push_new<long_const_operation>
505 (val.typed_val_int.type,
506 val.typed_val_int.val);
507 current_type = val.typed_val_int.type;
508 }
509 ;
510
511
512 exp : FLOAT
513 {
514 float_data data;
515 std::copy (std::begin ($1.val), std::end ($1.val),
516 std::begin (data));
517 pstate->push_new<float_const_operation> ($1.type, data);
518 }
519 ;
520
521 exp : variable
522 ;
523
524 exp : DOLLAR_VARIABLE
525 {
526 pstate->push_dollar ($1);
527
528 /* $ is the normal prefix for pascal
529 hexadecimal values but this conflicts
530 with the GDB use for debugger variables
531 so in expression to enter hexadecimal
532 values we still need to use C syntax with
533 0xff */
534 std::string tmp ($1.ptr, $1.length);
535 /* Handle current_type. */
536 struct internalvar *intvar
537 = lookup_only_internalvar (tmp.c_str () + 1);
538 if (intvar != nullptr)
539 {
540 scoped_value_mark mark;
541
542 value *val
543 = value_of_internalvar (pstate->gdbarch (),
544 intvar);
545 current_type = value_type (val);
546 }
547 }
548 ;
549
550 exp : SIZEOF '(' type ')' %prec UNARY
551 {
552 current_type = parse_type (pstate)->builtin_int;
553 $3 = check_typedef ($3);
554 pstate->push_new<long_const_operation>
555 (parse_type (pstate)->builtin_int,
556 TYPE_LENGTH ($3)); }
557 ;
558
559 exp : SIZEOF '(' exp ')' %prec UNARY
560 { pstate->wrap<unop_sizeof_operation> ();
561 current_type = parse_type (pstate)->builtin_int; }
562
563 exp : STRING
564 { /* C strings are converted into array constants with
565 an explicit null byte added at the end. Thus
566 the array upper bound is the string length.
567 There is no such thing in C as a completely empty
568 string. */
569 const char *sp = $1.ptr; int count = $1.length;
570
571 std::vector<operation_up> args (count + 1);
572 for (int i = 0; i < count; ++i)
573 args[i] = (make_operation<long_const_operation>
574 (parse_type (pstate)->builtin_char,
575 *sp++));
576 args[count] = (make_operation<long_const_operation>
577 (parse_type (pstate)->builtin_char,
578 '\0'));
579 pstate->push_new<array_operation>
580 (0, $1.length, std::move (args));
581 }
582 ;
583
584 /* Object pascal */
585 exp : THIS
586 {
587 struct value * this_val;
588 struct type * this_type;
589 pstate->push_new<op_this_operation> ();
590 /* We need type of this. */
591 this_val
592 = value_of_this_silent (pstate->language ());
593 if (this_val)
594 this_type = value_type (this_val);
595 else
596 this_type = NULL;
597 if (this_type)
598 {
599 if (this_type->code () == TYPE_CODE_PTR)
600 {
601 this_type = TYPE_TARGET_TYPE (this_type);
602 pstate->wrap<unop_ind_operation> ();
603 }
604 }
605
606 current_type = this_type;
607 }
608 ;
609
610 /* end of object pascal. */
611
612 block : BLOCKNAME
613 {
614 if ($1.sym.symbol != 0)
615 $$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol);
616 else
617 {
618 std::string copy = copy_name ($1.stoken);
619 struct symtab *tem =
620 lookup_symtab (copy.c_str ());
621 if (tem)
622 $$ = BLOCKVECTOR_BLOCK
623 (tem->compunit ()->blockvector (),
624 STATIC_BLOCK);
625 else
626 error (_("No file or function \"%s\"."),
627 copy.c_str ());
628 }
629 }
630 ;
631
632 block : block COLONCOLON name
633 {
634 std::string copy = copy_name ($3);
635 struct symbol *tem
636 = lookup_symbol (copy.c_str (), $1,
637 VAR_DOMAIN, NULL).symbol;
638
639 if (!tem || tem->aclass () != LOC_BLOCK)
640 error (_("No function \"%s\" in specified context."),
641 copy.c_str ());
642 $$ = SYMBOL_BLOCK_VALUE (tem); }
643 ;
644
645 variable: block COLONCOLON name
646 { struct block_symbol sym;
647
648 std::string copy = copy_name ($3);
649 sym = lookup_symbol (copy.c_str (), $1,
650 VAR_DOMAIN, NULL);
651 if (sym.symbol == 0)
652 error (_("No symbol \"%s\" in specified context."),
653 copy.c_str ());
654
655 pstate->push_new<var_value_operation> (sym);
656 }
657 ;
658
659 qualified_name: typebase COLONCOLON name
660 {
661 struct type *type = $1;
662
663 if (type->code () != TYPE_CODE_STRUCT
664 && type->code () != TYPE_CODE_UNION)
665 error (_("`%s' is not defined as an aggregate type."),
666 type->name ());
667
668 pstate->push_new<scope_operation>
669 (type, copy_name ($3));
670 }
671 ;
672
673 variable: qualified_name
674 | COLONCOLON name
675 {
676 std::string name = copy_name ($2);
677
678 struct block_symbol sym
679 = lookup_symbol (name.c_str (), nullptr,
680 VAR_DOMAIN, nullptr);
681 pstate->push_symbol (name.c_str (), sym);
682 }
683 ;
684
685 variable: name_not_typename
686 { struct block_symbol sym = $1.sym;
687
688 if (sym.symbol)
689 {
690 if (symbol_read_needs_frame (sym.symbol))
691 pstate->block_tracker->update (sym);
692
693 pstate->push_new<var_value_operation> (sym);
694 current_type = sym.symbol->type (); }
695 else if ($1.is_a_field_of_this)
696 {
697 struct value * this_val;
698 struct type * this_type;
699 /* Object pascal: it hangs off of `this'. Must
700 not inadvertently convert from a method call
701 to data ref. */
702 pstate->block_tracker->update (sym);
703 operation_up thisop
704 = make_operation<op_this_operation> ();
705 pstate->push_new<structop_operation>
706 (std::move (thisop), copy_name ($1.stoken));
707 /* We need type of this. */
708 this_val
709 = value_of_this_silent (pstate->language ());
710 if (this_val)
711 this_type = value_type (this_val);
712 else
713 this_type = NULL;
714 if (this_type)
715 current_type = lookup_struct_elt_type (
716 this_type,
717 copy_name ($1.stoken).c_str (), 0);
718 else
719 current_type = NULL;
720 }
721 else
722 {
723 struct bound_minimal_symbol msymbol;
724 std::string arg = copy_name ($1.stoken);
725
726 msymbol =
727 lookup_bound_minimal_symbol (arg.c_str ());
728 if (msymbol.minsym != NULL)
729 pstate->push_new<var_msym_value_operation>
730 (msymbol);
731 else if (!have_full_symbols ()
732 && !have_partial_symbols ())
733 error (_("No symbol table is loaded. "
734 "Use the \"file\" command."));
735 else
736 error (_("No symbol \"%s\" in current context."),
737 arg.c_str ());
738 }
739 }
740 ;
741
742
743 ptype : typebase
744 ;
745
746 /* We used to try to recognize more pointer to member types here, but
747 that didn't work (shift/reduce conflicts meant that these rules never
748 got executed). The problem is that
749 int (foo::bar::baz::bizzle)
750 is a function type but
751 int (foo::bar::baz::bizzle::*)
752 is a pointer to member type. Stroustrup loses again! */
753
754 type : ptype
755 ;
756
757 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
758 : '^' typebase
759 { $$ = lookup_pointer_type ($2); }
760 | TYPENAME
761 { $$ = $1.type; }
762 | STRUCT name
763 { $$
764 = lookup_struct (copy_name ($2).c_str (),
765 pstate->expression_context_block);
766 }
767 | CLASS name
768 { $$
769 = lookup_struct (copy_name ($2).c_str (),
770 pstate->expression_context_block);
771 }
772 /* "const" and "volatile" are curently ignored. A type qualifier
773 after the type is handled in the ptype rule. I think these could
774 be too. */
775 ;
776
777 name : NAME { $$ = $1.stoken; }
778 | BLOCKNAME { $$ = $1.stoken; }
779 | TYPENAME { $$ = $1.stoken; }
780 | NAME_OR_INT { $$ = $1.stoken; }
781 ;
782
783 name_not_typename : NAME
784 | BLOCKNAME
785 /* These would be useful if name_not_typename was useful, but it is just
786 a fake for "variable", so these cause reduce/reduce conflicts because
787 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
788 =exp) or just an exp. If name_not_typename was ever used in an lvalue
789 context where only a name could occur, this might be useful.
790 | NAME_OR_INT
791 */
792 ;
793
794 %%
795
796 /* Take care of parsing a number (anything that starts with a digit).
797 Set yylval and return the token type; update lexptr.
798 LEN is the number of characters in it. */
799
800 /*** Needs some error checking for the float case ***/
801
802 static int
803 parse_number (struct parser_state *par_state,
804 const char *p, int len, int parsed_float, YYSTYPE *putithere)
805 {
806 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
807 here, and we do kind of silly things like cast to unsigned. */
808 LONGEST n = 0;
809 LONGEST prevn = 0;
810 ULONGEST un;
811
812 int i = 0;
813 int c;
814 int base = input_radix;
815 int unsigned_p = 0;
816
817 /* Number of "L" suffixes encountered. */
818 int long_p = 0;
819
820 /* We have found a "L" or "U" suffix. */
821 int found_suffix = 0;
822
823 ULONGEST high_bit;
824 struct type *signed_type;
825 struct type *unsigned_type;
826
827 if (parsed_float)
828 {
829 /* Handle suffixes: 'f' for float, 'l' for long double.
830 FIXME: This appears to be an extension -- do we want this? */
831 if (len >= 1 && tolower (p[len - 1]) == 'f')
832 {
833 putithere->typed_val_float.type
834 = parse_type (par_state)->builtin_float;
835 len--;
836 }
837 else if (len >= 1 && tolower (p[len - 1]) == 'l')
838 {
839 putithere->typed_val_float.type
840 = parse_type (par_state)->builtin_long_double;
841 len--;
842 }
843 /* Default type for floating-point literals is double. */
844 else
845 {
846 putithere->typed_val_float.type
847 = parse_type (par_state)->builtin_double;
848 }
849
850 if (!parse_float (p, len,
851 putithere->typed_val_float.type,
852 putithere->typed_val_float.val))
853 return ERROR;
854 return FLOAT;
855 }
856
857 /* Handle base-switching prefixes 0x, 0t, 0d, 0. */
858 if (p[0] == '0')
859 switch (p[1])
860 {
861 case 'x':
862 case 'X':
863 if (len >= 3)
864 {
865 p += 2;
866 base = 16;
867 len -= 2;
868 }
869 break;
870
871 case 't':
872 case 'T':
873 case 'd':
874 case 'D':
875 if (len >= 3)
876 {
877 p += 2;
878 base = 10;
879 len -= 2;
880 }
881 break;
882
883 default:
884 base = 8;
885 break;
886 }
887
888 while (len-- > 0)
889 {
890 c = *p++;
891 if (c >= 'A' && c <= 'Z')
892 c += 'a' - 'A';
893 if (c != 'l' && c != 'u')
894 n *= base;
895 if (c >= '0' && c <= '9')
896 {
897 if (found_suffix)
898 return ERROR;
899 n += i = c - '0';
900 }
901 else
902 {
903 if (base > 10 && c >= 'a' && c <= 'f')
904 {
905 if (found_suffix)
906 return ERROR;
907 n += i = c - 'a' + 10;
908 }
909 else if (c == 'l')
910 {
911 ++long_p;
912 found_suffix = 1;
913 }
914 else if (c == 'u')
915 {
916 unsigned_p = 1;
917 found_suffix = 1;
918 }
919 else
920 return ERROR; /* Char not a digit */
921 }
922 if (i >= base)
923 return ERROR; /* Invalid digit in this base. */
924
925 /* Portably test for overflow (only works for nonzero values, so make
926 a second check for zero). FIXME: Can't we just make n and prevn
927 unsigned and avoid this? */
928 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
929 unsigned_p = 1; /* Try something unsigned. */
930
931 /* Portably test for unsigned overflow.
932 FIXME: This check is wrong; for example it doesn't find overflow
933 on 0x123456789 when LONGEST is 32 bits. */
934 if (c != 'l' && c != 'u' && n != 0)
935 {
936 if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
937 error (_("Numeric constant too large."));
938 }
939 prevn = n;
940 }
941
942 /* An integer constant is an int, a long, or a long long. An L
943 suffix forces it to be long; an LL suffix forces it to be long
944 long. If not forced to a larger size, it gets the first type of
945 the above that it fits in. To figure out whether it fits, we
946 shift it right and see whether anything remains. Note that we
947 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
948 operation, because many compilers will warn about such a shift
949 (which always produces a zero result). Sometimes gdbarch_int_bit
950 or gdbarch_long_bit will be that big, sometimes not. To deal with
951 the case where it is we just always shift the value more than
952 once, with fewer bits each time. */
953
954 un = (ULONGEST)n >> 2;
955 if (long_p == 0
956 && (un >> (gdbarch_int_bit (par_state->gdbarch ()) - 2)) == 0)
957 {
958 high_bit
959 = ((ULONGEST)1) << (gdbarch_int_bit (par_state->gdbarch ()) - 1);
960
961 /* A large decimal (not hex or octal) constant (between INT_MAX
962 and UINT_MAX) is a long or unsigned long, according to ANSI,
963 never an unsigned int, but this code treats it as unsigned
964 int. This probably should be fixed. GCC gives a warning on
965 such constants. */
966
967 unsigned_type = parse_type (par_state)->builtin_unsigned_int;
968 signed_type = parse_type (par_state)->builtin_int;
969 }
970 else if (long_p <= 1
971 && (un >> (gdbarch_long_bit (par_state->gdbarch ()) - 2)) == 0)
972 {
973 high_bit
974 = ((ULONGEST)1) << (gdbarch_long_bit (par_state->gdbarch ()) - 1);
975 unsigned_type = parse_type (par_state)->builtin_unsigned_long;
976 signed_type = parse_type (par_state)->builtin_long;
977 }
978 else
979 {
980 int shift;
981 if (sizeof (ULONGEST) * HOST_CHAR_BIT
982 < gdbarch_long_long_bit (par_state->gdbarch ()))
983 /* A long long does not fit in a LONGEST. */
984 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
985 else
986 shift = (gdbarch_long_long_bit (par_state->gdbarch ()) - 1);
987 high_bit = (ULONGEST) 1 << shift;
988 unsigned_type = parse_type (par_state)->builtin_unsigned_long_long;
989 signed_type = parse_type (par_state)->builtin_long_long;
990 }
991
992 putithere->typed_val_int.val = n;
993
994 /* If the high bit of the worked out type is set then this number
995 has to be unsigned. */
996
997 if (unsigned_p || (n & high_bit))
998 {
999 putithere->typed_val_int.type = unsigned_type;
1000 }
1001 else
1002 {
1003 putithere->typed_val_int.type = signed_type;
1004 }
1005
1006 return INT;
1007 }
1008
1009
1010 struct type_push
1011 {
1012 struct type *stored;
1013 struct type_push *next;
1014 };
1015
1016 static struct type_push *tp_top = NULL;
1017
1018 static void
1019 push_current_type (void)
1020 {
1021 struct type_push *tpnew;
1022 tpnew = (struct type_push *) malloc (sizeof (struct type_push));
1023 tpnew->next = tp_top;
1024 tpnew->stored = current_type;
1025 current_type = NULL;
1026 tp_top = tpnew;
1027 }
1028
1029 static void
1030 pop_current_type (void)
1031 {
1032 struct type_push *tp = tp_top;
1033 if (tp)
1034 {
1035 current_type = tp->stored;
1036 tp_top = tp->next;
1037 free (tp);
1038 }
1039 }
1040
1041 struct token
1042 {
1043 const char *oper;
1044 int token;
1045 enum exp_opcode opcode;
1046 };
1047
1048 static const struct token tokentab3[] =
1049 {
1050 {"shr", RSH, OP_NULL},
1051 {"shl", LSH, OP_NULL},
1052 {"and", ANDAND, OP_NULL},
1053 {"div", DIV, OP_NULL},
1054 {"not", NOT, OP_NULL},
1055 {"mod", MOD, OP_NULL},
1056 {"inc", INCREMENT, OP_NULL},
1057 {"dec", DECREMENT, OP_NULL},
1058 {"xor", XOR, OP_NULL}
1059 };
1060
1061 static const struct token tokentab2[] =
1062 {
1063 {"or", OR, OP_NULL},
1064 {"<>", NOTEQUAL, OP_NULL},
1065 {"<=", LEQ, OP_NULL},
1066 {">=", GEQ, OP_NULL},
1067 {":=", ASSIGN, OP_NULL},
1068 {"::", COLONCOLON, OP_NULL} };
1069
1070 /* Allocate uppercased var: */
1071 /* make an uppercased copy of tokstart. */
1072 static char *
1073 uptok (const char *tokstart, int namelen)
1074 {
1075 int i;
1076 char *uptokstart = (char *)malloc(namelen+1);
1077 for (i = 0;i <= namelen;i++)
1078 {
1079 if ((tokstart[i]>='a' && tokstart[i]<='z'))
1080 uptokstart[i] = tokstart[i]-('a'-'A');
1081 else
1082 uptokstart[i] = tokstart[i];
1083 }
1084 uptokstart[namelen]='\0';
1085 return uptokstart;
1086 }
1087
1088 /* Read one token, getting characters through lexptr. */
1089
1090 static int
1091 yylex (void)
1092 {
1093 int c;
1094 int namelen;
1095 const char *tokstart;
1096 char *uptokstart;
1097 const char *tokptr;
1098 int explen, tempbufindex;
1099 static char *tempbuf;
1100 static int tempbufsize;
1101
1102 retry:
1103
1104 pstate->prev_lexptr = pstate->lexptr;
1105
1106 tokstart = pstate->lexptr;
1107 explen = strlen (pstate->lexptr);
1108
1109 /* See if it is a special token of length 3. */
1110 if (explen > 2)
1111 for (const auto &token : tokentab3)
1112 if (strncasecmp (tokstart, token.oper, 3) == 0
1113 && (!isalpha (token.oper[0]) || explen == 3
1114 || (!isalpha (tokstart[3])
1115 && !isdigit (tokstart[3]) && tokstart[3] != '_')))
1116 {
1117 pstate->lexptr += 3;
1118 yylval.opcode = token.opcode;
1119 return token.token;
1120 }
1121
1122 /* See if it is a special token of length 2. */
1123 if (explen > 1)
1124 for (const auto &token : tokentab2)
1125 if (strncasecmp (tokstart, token.oper, 2) == 0
1126 && (!isalpha (token.oper[0]) || explen == 2
1127 || (!isalpha (tokstart[2])
1128 && !isdigit (tokstart[2]) && tokstart[2] != '_')))
1129 {
1130 pstate->lexptr += 2;
1131 yylval.opcode = token.opcode;
1132 return token.token;
1133 }
1134
1135 switch (c = *tokstart)
1136 {
1137 case 0:
1138 if (search_field && pstate->parse_completion)
1139 return COMPLETE;
1140 else
1141 return 0;
1142
1143 case ' ':
1144 case '\t':
1145 case '\n':
1146 pstate->lexptr++;
1147 goto retry;
1148
1149 case '\'':
1150 /* We either have a character constant ('0' or '\177' for example)
1151 or we have a quoted symbol reference ('foo(int,int)' in object pascal
1152 for example). */
1153 pstate->lexptr++;
1154 c = *pstate->lexptr++;
1155 if (c == '\\')
1156 c = parse_escape (pstate->gdbarch (), &pstate->lexptr);
1157 else if (c == '\'')
1158 error (_("Empty character constant."));
1159
1160 yylval.typed_val_int.val = c;
1161 yylval.typed_val_int.type = parse_type (pstate)->builtin_char;
1162
1163 c = *pstate->lexptr++;
1164 if (c != '\'')
1165 {
1166 namelen = skip_quoted (tokstart) - tokstart;
1167 if (namelen > 2)
1168 {
1169 pstate->lexptr = tokstart + namelen;
1170 if (pstate->lexptr[-1] != '\'')
1171 error (_("Unmatched single quote."));
1172 namelen -= 2;
1173 tokstart++;
1174 uptokstart = uptok(tokstart,namelen);
1175 goto tryname;
1176 }
1177 error (_("Invalid character constant."));
1178 }
1179 return INT;
1180
1181 case '(':
1182 paren_depth++;
1183 pstate->lexptr++;
1184 return c;
1185
1186 case ')':
1187 if (paren_depth == 0)
1188 return 0;
1189 paren_depth--;
1190 pstate->lexptr++;
1191 return c;
1192
1193 case ',':
1194 if (pstate->comma_terminates && paren_depth == 0)
1195 return 0;
1196 pstate->lexptr++;
1197 return c;
1198
1199 case '.':
1200 /* Might be a floating point number. */
1201 if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9')
1202 {
1203 goto symbol; /* Nope, must be a symbol. */
1204 }
1205
1206 /* FALL THRU. */
1207
1208 case '0':
1209 case '1':
1210 case '2':
1211 case '3':
1212 case '4':
1213 case '5':
1214 case '6':
1215 case '7':
1216 case '8':
1217 case '9':
1218 {
1219 /* It's a number. */
1220 int got_dot = 0, got_e = 0, toktype;
1221 const char *p = tokstart;
1222 int hex = input_radix > 10;
1223
1224 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1225 {
1226 p += 2;
1227 hex = 1;
1228 }
1229 else if (c == '0' && (p[1]=='t' || p[1]=='T'
1230 || p[1]=='d' || p[1]=='D'))
1231 {
1232 p += 2;
1233 hex = 0;
1234 }
1235
1236 for (;; ++p)
1237 {
1238 /* This test includes !hex because 'e' is a valid hex digit
1239 and thus does not indicate a floating point number when
1240 the radix is hex. */
1241 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1242 got_dot = got_e = 1;
1243 /* This test does not include !hex, because a '.' always indicates
1244 a decimal floating point number regardless of the radix. */
1245 else if (!got_dot && *p == '.')
1246 got_dot = 1;
1247 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
1248 && (*p == '-' || *p == '+'))
1249 /* This is the sign of the exponent, not the end of the
1250 number. */
1251 continue;
1252 /* We will take any letters or digits. parse_number will
1253 complain if past the radix, or if L or U are not final. */
1254 else if ((*p < '0' || *p > '9')
1255 && ((*p < 'a' || *p > 'z')
1256 && (*p < 'A' || *p > 'Z')))
1257 break;
1258 }
1259 toktype = parse_number (pstate, tokstart,
1260 p - tokstart, got_dot | got_e, &yylval);
1261 if (toktype == ERROR)
1262 {
1263 char *err_copy = (char *) alloca (p - tokstart + 1);
1264
1265 memcpy (err_copy, tokstart, p - tokstart);
1266 err_copy[p - tokstart] = 0;
1267 error (_("Invalid number \"%s\"."), err_copy);
1268 }
1269 pstate->lexptr = p;
1270 return toktype;
1271 }
1272
1273 case '+':
1274 case '-':
1275 case '*':
1276 case '/':
1277 case '|':
1278 case '&':
1279 case '^':
1280 case '~':
1281 case '!':
1282 case '@':
1283 case '<':
1284 case '>':
1285 case '[':
1286 case ']':
1287 case '?':
1288 case ':':
1289 case '=':
1290 case '{':
1291 case '}':
1292 symbol:
1293 pstate->lexptr++;
1294 return c;
1295
1296 case '"':
1297
1298 /* Build the gdb internal form of the input string in tempbuf,
1299 translating any standard C escape forms seen. Note that the
1300 buffer is null byte terminated *only* for the convenience of
1301 debugging gdb itself and printing the buffer contents when
1302 the buffer contains no embedded nulls. Gdb does not depend
1303 upon the buffer being null byte terminated, it uses the length
1304 string instead. This allows gdb to handle C strings (as well
1305 as strings in other languages) with embedded null bytes. */
1306
1307 tokptr = ++tokstart;
1308 tempbufindex = 0;
1309
1310 do {
1311 /* Grow the static temp buffer if necessary, including allocating
1312 the first one on demand. */
1313 if (tempbufindex + 1 >= tempbufsize)
1314 {
1315 tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
1316 }
1317
1318 switch (*tokptr)
1319 {
1320 case '\0':
1321 case '"':
1322 /* Do nothing, loop will terminate. */
1323 break;
1324 case '\\':
1325 ++tokptr;
1326 c = parse_escape (pstate->gdbarch (), &tokptr);
1327 if (c == -1)
1328 {
1329 continue;
1330 }
1331 tempbuf[tempbufindex++] = c;
1332 break;
1333 default:
1334 tempbuf[tempbufindex++] = *tokptr++;
1335 break;
1336 }
1337 } while ((*tokptr != '"') && (*tokptr != '\0'));
1338 if (*tokptr++ != '"')
1339 {
1340 error (_("Unterminated string in expression."));
1341 }
1342 tempbuf[tempbufindex] = '\0'; /* See note above. */
1343 yylval.sval.ptr = tempbuf;
1344 yylval.sval.length = tempbufindex;
1345 pstate->lexptr = tokptr;
1346 return (STRING);
1347 }
1348
1349 if (!(c == '_' || c == '$'
1350 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1351 /* We must have come across a bad character (e.g. ';'). */
1352 error (_("Invalid character '%c' in expression."), c);
1353
1354 /* It's a name. See how long it is. */
1355 namelen = 0;
1356 for (c = tokstart[namelen];
1357 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1358 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
1359 {
1360 /* Template parameter lists are part of the name.
1361 FIXME: This mishandles `print $a<4&&$a>3'. */
1362 if (c == '<')
1363 {
1364 int i = namelen;
1365 int nesting_level = 1;
1366 while (tokstart[++i])
1367 {
1368 if (tokstart[i] == '<')
1369 nesting_level++;
1370 else if (tokstart[i] == '>')
1371 {
1372 if (--nesting_level == 0)
1373 break;
1374 }
1375 }
1376 if (tokstart[i] == '>')
1377 namelen = i;
1378 else
1379 break;
1380 }
1381
1382 /* do NOT uppercase internals because of registers !!! */
1383 c = tokstart[++namelen];
1384 }
1385
1386 uptokstart = uptok(tokstart,namelen);
1387
1388 /* The token "if" terminates the expression and is NOT
1389 removed from the input stream. */
1390 if (namelen == 2 && uptokstart[0] == 'I' && uptokstart[1] == 'F')
1391 {
1392 free (uptokstart);
1393 return 0;
1394 }
1395
1396 pstate->lexptr += namelen;
1397
1398 tryname:
1399
1400 /* Catch specific keywords. Should be done with a data structure. */
1401 switch (namelen)
1402 {
1403 case 6:
1404 if (strcmp (uptokstart, "OBJECT") == 0)
1405 {
1406 free (uptokstart);
1407 return CLASS;
1408 }
1409 if (strcmp (uptokstart, "RECORD") == 0)
1410 {
1411 free (uptokstart);
1412 return STRUCT;
1413 }
1414 if (strcmp (uptokstart, "SIZEOF") == 0)
1415 {
1416 free (uptokstart);
1417 return SIZEOF;
1418 }
1419 break;
1420 case 5:
1421 if (strcmp (uptokstart, "CLASS") == 0)
1422 {
1423 free (uptokstart);
1424 return CLASS;
1425 }
1426 if (strcmp (uptokstart, "FALSE") == 0)
1427 {
1428 yylval.lval = 0;
1429 free (uptokstart);
1430 return FALSEKEYWORD;
1431 }
1432 break;
1433 case 4:
1434 if (strcmp (uptokstart, "TRUE") == 0)
1435 {
1436 yylval.lval = 1;
1437 free (uptokstart);
1438 return TRUEKEYWORD;
1439 }
1440 if (strcmp (uptokstart, "SELF") == 0)
1441 {
1442 /* Here we search for 'this' like
1443 inserted in FPC stabs debug info. */
1444 static const char this_name[] = "this";
1445
1446 if (lookup_symbol (this_name, pstate->expression_context_block,
1447 VAR_DOMAIN, NULL).symbol)
1448 {
1449 free (uptokstart);
1450 return THIS;
1451 }
1452 }
1453 break;
1454 default:
1455 break;
1456 }
1457
1458 yylval.sval.ptr = tokstart;
1459 yylval.sval.length = namelen;
1460
1461 if (*tokstart == '$')
1462 {
1463 free (uptokstart);
1464 return DOLLAR_VARIABLE;
1465 }
1466
1467 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1468 functions or symtabs. If this is not so, then ...
1469 Use token-type TYPENAME for symbols that happen to be defined
1470 currently as names of types; NAME for other symbols.
1471 The caller is not constrained to care about the distinction. */
1472 {
1473 std::string tmp = copy_name (yylval.sval);
1474 struct symbol *sym;
1475 struct field_of_this_result is_a_field_of_this;
1476 int is_a_field = 0;
1477 int hextype;
1478
1479 is_a_field_of_this.type = NULL;
1480 if (search_field && current_type)
1481 is_a_field = (lookup_struct_elt_type (current_type,
1482 tmp.c_str (), 1) != NULL);
1483 if (is_a_field)
1484 sym = NULL;
1485 else
1486 sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
1487 VAR_DOMAIN, &is_a_field_of_this).symbol;
1488 /* second chance uppercased (as Free Pascal does). */
1489 if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
1490 {
1491 for (int i = 0; i <= namelen; i++)
1492 {
1493 if ((tmp[i] >= 'a' && tmp[i] <= 'z'))
1494 tmp[i] -= ('a'-'A');
1495 }
1496 if (search_field && current_type)
1497 is_a_field = (lookup_struct_elt_type (current_type,
1498 tmp.c_str (), 1) != NULL);
1499 if (is_a_field)
1500 sym = NULL;
1501 else
1502 sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
1503 VAR_DOMAIN, &is_a_field_of_this).symbol;
1504 }
1505 /* Third chance Capitalized (as GPC does). */
1506 if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
1507 {
1508 for (int i = 0; i <= namelen; i++)
1509 {
1510 if (i == 0)
1511 {
1512 if ((tmp[i] >= 'a' && tmp[i] <= 'z'))
1513 tmp[i] -= ('a'-'A');
1514 }
1515 else
1516 if ((tmp[i] >= 'A' && tmp[i] <= 'Z'))
1517 tmp[i] -= ('A'-'a');
1518 }
1519 if (search_field && current_type)
1520 is_a_field = (lookup_struct_elt_type (current_type,
1521 tmp.c_str (), 1) != NULL);
1522 if (is_a_field)
1523 sym = NULL;
1524 else
1525 sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
1526 VAR_DOMAIN, &is_a_field_of_this).symbol;
1527 }
1528
1529 if (is_a_field || (is_a_field_of_this.type != NULL))
1530 {
1531 tempbuf = (char *) realloc (tempbuf, namelen + 1);
1532 strncpy (tempbuf, tmp.c_str (), namelen);
1533 tempbuf [namelen] = 0;
1534 yylval.sval.ptr = tempbuf;
1535 yylval.sval.length = namelen;
1536 yylval.ssym.sym.symbol = NULL;
1537 yylval.ssym.sym.block = NULL;
1538 free (uptokstart);
1539 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
1540 if (is_a_field)
1541 return FIELDNAME;
1542 else
1543 return NAME;
1544 }
1545 /* Call lookup_symtab, not lookup_partial_symtab, in case there are
1546 no psymtabs (coff, xcoff, or some future change to blow away the
1547 psymtabs once once symbols are read). */
1548 if ((sym && sym->aclass () == LOC_BLOCK)
1549 || lookup_symtab (tmp.c_str ()))
1550 {
1551 yylval.ssym.sym.symbol = sym;
1552 yylval.ssym.sym.block = NULL;
1553 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
1554 free (uptokstart);
1555 return BLOCKNAME;
1556 }
1557 if (sym && sym->aclass () == LOC_TYPEDEF)
1558 {
1559 #if 1
1560 /* Despite the following flaw, we need to keep this code enabled.
1561 Because we can get called from check_stub_method, if we don't
1562 handle nested types then it screws many operations in any
1563 program which uses nested types. */
1564 /* In "A::x", if x is a member function of A and there happens
1565 to be a type (nested or not, since the stabs don't make that
1566 distinction) named x, then this code incorrectly thinks we
1567 are dealing with nested types rather than a member function. */
1568
1569 const char *p;
1570 const char *namestart;
1571 struct symbol *best_sym;
1572
1573 /* Look ahead to detect nested types. This probably should be
1574 done in the grammar, but trying seemed to introduce a lot
1575 of shift/reduce and reduce/reduce conflicts. It's possible
1576 that it could be done, though. Or perhaps a non-grammar, but
1577 less ad hoc, approach would work well. */
1578
1579 /* Since we do not currently have any way of distinguishing
1580 a nested type from a non-nested one (the stabs don't tell
1581 us whether a type is nested), we just ignore the
1582 containing type. */
1583
1584 p = pstate->lexptr;
1585 best_sym = sym;
1586 while (1)
1587 {
1588 /* Skip whitespace. */
1589 while (*p == ' ' || *p == '\t' || *p == '\n')
1590 ++p;
1591 if (*p == ':' && p[1] == ':')
1592 {
1593 /* Skip the `::'. */
1594 p += 2;
1595 /* Skip whitespace. */
1596 while (*p == ' ' || *p == '\t' || *p == '\n')
1597 ++p;
1598 namestart = p;
1599 while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9')
1600 || (*p >= 'a' && *p <= 'z')
1601 || (*p >= 'A' && *p <= 'Z'))
1602 ++p;
1603 if (p != namestart)
1604 {
1605 struct symbol *cur_sym;
1606 /* As big as the whole rest of the expression, which is
1607 at least big enough. */
1608 char *ncopy
1609 = (char *) alloca (tmp.size () + strlen (namestart)
1610 + 3);
1611 char *tmp1;
1612
1613 tmp1 = ncopy;
1614 memcpy (tmp1, tmp.c_str (), tmp.size ());
1615 tmp1 += tmp.size ();
1616 memcpy (tmp1, "::", 2);
1617 tmp1 += 2;
1618 memcpy (tmp1, namestart, p - namestart);
1619 tmp1[p - namestart] = '\0';
1620 cur_sym
1621 = lookup_symbol (ncopy,
1622 pstate->expression_context_block,
1623 VAR_DOMAIN, NULL).symbol;
1624 if (cur_sym)
1625 {
1626 if (cur_sym->aclass () == LOC_TYPEDEF)
1627 {
1628 best_sym = cur_sym;
1629 pstate->lexptr = p;
1630 }
1631 else
1632 break;
1633 }
1634 else
1635 break;
1636 }
1637 else
1638 break;
1639 }
1640 else
1641 break;
1642 }
1643
1644 yylval.tsym.type = best_sym->type ();
1645 #else /* not 0 */
1646 yylval.tsym.type = sym->type ();
1647 #endif /* not 0 */
1648 free (uptokstart);
1649 return TYPENAME;
1650 }
1651 yylval.tsym.type
1652 = language_lookup_primitive_type (pstate->language (),
1653 pstate->gdbarch (), tmp.c_str ());
1654 if (yylval.tsym.type != NULL)
1655 {
1656 free (uptokstart);
1657 return TYPENAME;
1658 }
1659
1660 /* Input names that aren't symbols but ARE valid hex numbers,
1661 when the input radix permits them, can be names or numbers
1662 depending on the parse. Note we support radixes > 16 here. */
1663 if (!sym
1664 && ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10)
1665 || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1666 {
1667 YYSTYPE newlval; /* Its value is ignored. */
1668 hextype = parse_number (pstate, tokstart, namelen, 0, &newlval);
1669 if (hextype == INT)
1670 {
1671 yylval.ssym.sym.symbol = sym;
1672 yylval.ssym.sym.block = NULL;
1673 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
1674 free (uptokstart);
1675 return NAME_OR_INT;
1676 }
1677 }
1678
1679 free(uptokstart);
1680 /* Any other kind of symbol. */
1681 yylval.ssym.sym.symbol = sym;
1682 yylval.ssym.sym.block = NULL;
1683 return NAME;
1684 }
1685 }
1686
1687 /* See language.h. */
1688
1689 int
1690 pascal_language::parser (struct parser_state *par_state) const
1691 {
1692 /* Setting up the parser state. */
1693 scoped_restore pstate_restore = make_scoped_restore (&pstate);
1694 gdb_assert (par_state != NULL);
1695 pstate = par_state;
1696 paren_depth = 0;
1697
1698 int result = yyparse ();
1699 if (!result)
1700 pstate->set_operation (pstate->pop ());
1701 return result;
1702 }
1703
1704 static void
1705 yyerror (const char *msg)
1706 {
1707 if (pstate->prev_lexptr)
1708 pstate->lexptr = pstate->prev_lexptr;
1709
1710 error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
1711 }