* Add native support for long double data type.
[deliverable/binutils-gdb.git] / gdb / c-exp.y
1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /* Parse a C expression from text in a string,
22 and return the result as a struct expression pointer.
23 That structure contains arithmetic operations in reverse polish,
24 with constants represented by operations that are followed by special data.
25 See expression.h for the details of the format.
26 What is important here is that it can be built up sequentially
27 during the process of parsing; the lower levels of the tree always
28 come first in the result.
29
30 Note that malloc's and realloc's in this file are transformed to
31 xmalloc and xrealloc respectively by the same sed command in the
32 makefile that remaps any other malloc/realloc inserted by the parser
33 generator. Doing this with #defines and trying to control the interaction
34 with include files (<malloc.h> and <stdlib.h> for example) just became
35 too messy, particularly when such includes can be inserted at random
36 times by the parser generator. */
37
38 %{
39
40 #include "defs.h"
41 #include <string.h>
42 #include "expression.h"
43 #include "value.h"
44 #include "parser-defs.h"
45 #include "language.h"
46 #include "c-lang.h"
47 #include "bfd.h" /* Required by objfiles.h. */
48 #include "symfile.h" /* Required by objfiles.h. */
49 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
50
51 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
52 as well as gratuitiously global symbol names, so we can have multiple
53 yacc generated parsers in gdb. Note that these are only the variables
54 produced by yacc. If other parser generators (bison, byacc, etc) produce
55 additional global names that conflict at link time, then those parser
56 generators need to be fixed instead of adding those names to this list. */
57
58 #define yymaxdepth c_maxdepth
59 #define yyparse c_parse
60 #define yylex c_lex
61 #define yyerror c_error
62 #define yylval c_lval
63 #define yychar c_char
64 #define yydebug c_debug
65 #define yypact c_pact
66 #define yyr1 c_r1
67 #define yyr2 c_r2
68 #define yydef c_def
69 #define yychk c_chk
70 #define yypgo c_pgo
71 #define yyact c_act
72 #define yyexca c_exca
73 #define yyerrflag c_errflag
74 #define yynerrs c_nerrs
75 #define yyps c_ps
76 #define yypv c_pv
77 #define yys c_s
78 #define yy_yys c_yys
79 #define yystate c_state
80 #define yytmp c_tmp
81 #define yyv c_v
82 #define yy_yyv c_yyv
83 #define yyval c_val
84 #define yylloc c_lloc
85 #define yyreds c_reds /* With YYDEBUG defined */
86 #define yytoks c_toks /* With YYDEBUG defined */
87 #define yylhs c_yylhs
88 #define yylen c_yylen
89 #define yydefred c_yydefred
90 #define yydgoto c_yydgoto
91 #define yysindex c_yysindex
92 #define yyrindex c_yyrindex
93 #define yygindex c_yygindex
94 #define yytable c_yytable
95 #define yycheck c_yycheck
96
97 #ifndef YYDEBUG
98 #define YYDEBUG 0 /* Default to no yydebug support */
99 #endif
100
101 int
102 yyparse PARAMS ((void));
103
104 static int
105 yylex PARAMS ((void));
106
107 void
108 yyerror PARAMS ((char *));
109
110 %}
111
112 /* Although the yacc "value" of an expression is not used,
113 since the result is stored in the structure being created,
114 other node types do have values. */
115
116 %union
117 {
118 LONGEST lval;
119 struct {
120 LONGEST val;
121 struct type *type;
122 } typed_val_int;
123 struct {
124 DOUBLEST dval;
125 struct type *type;
126 } typed_val_float;
127 struct symbol *sym;
128 struct type *tval;
129 struct stoken sval;
130 struct ttype tsym;
131 struct symtoken ssym;
132 int voidval;
133 struct block *bval;
134 enum exp_opcode opcode;
135 struct internalvar *ivar;
136
137 struct type **tvec;
138 int *ivec;
139 }
140
141 %{
142 /* YYSTYPE gets defined by %union */
143 static int
144 parse_number PARAMS ((char *, int, int, YYSTYPE *));
145 %}
146
147 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
148 %type <lval> rcurly
149 %type <tval> type typebase
150 %type <tvec> nonempty_typelist
151 /* %type <bval> block */
152
153 /* Fancy type parsing. */
154 %type <voidval> func_mod direct_abs_decl abs_decl
155 %type <tval> ptype
156 %type <lval> array_mod
157
158 %token <typed_val_int> INT
159 %token <typed_val_float> FLOAT
160
161 /* Both NAME and TYPENAME tokens represent symbols in the input,
162 and both convey their data as strings.
163 But a TYPENAME is a string that happens to be defined as a typedef
164 or builtin type name (such as int or char)
165 and a NAME is any other symbol.
166 Contexts where this distinction is not important can use the
167 nonterminal "name", which matches either NAME or TYPENAME. */
168
169 %token <sval> STRING
170 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
171 %token <tsym> TYPENAME
172 %type <sval> name
173 %type <ssym> name_not_typename
174 %type <tsym> typename
175
176 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
177 but which would parse as a valid number in the current input radix.
178 E.g. "c" when input_radix==16. Depending on the parse, it will be
179 turned into a name or into a number. */
180
181 %token <ssym> NAME_OR_INT
182
183 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
184 %token TEMPLATE
185 %token ERROR
186
187 /* Special type cases, put in to allow the parser to distinguish different
188 legal basetypes. */
189 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
190
191 %token <voidval> VARIABLE
192
193 %token <opcode> ASSIGN_MODIFY
194
195 /* C++ */
196 %token THIS
197
198 %left ','
199 %left ABOVE_COMMA
200 %right '=' ASSIGN_MODIFY
201 %right '?'
202 %left OROR
203 %left ANDAND
204 %left '|'
205 %left '^'
206 %left '&'
207 %left EQUAL NOTEQUAL
208 %left '<' '>' LEQ GEQ
209 %left LSH RSH
210 %left '@'
211 %left '+' '-'
212 %left '*' '/' '%'
213 %right UNARY INCREMENT DECREMENT
214 %right ARROW '.' '[' '('
215 %token <ssym> BLOCKNAME
216 %type <bval> block
217 %left COLONCOLON
218
219 \f
220 %%
221
222 start : exp1
223 | type_exp
224 ;
225
226 type_exp: type
227 { write_exp_elt_opcode(OP_TYPE);
228 write_exp_elt_type($1);
229 write_exp_elt_opcode(OP_TYPE);}
230 ;
231
232 /* Expressions, including the comma operator. */
233 exp1 : exp
234 | exp1 ',' exp
235 { write_exp_elt_opcode (BINOP_COMMA); }
236 ;
237
238 /* Expressions, not including the comma operator. */
239 exp : '*' exp %prec UNARY
240 { write_exp_elt_opcode (UNOP_IND); }
241
242 exp : '&' exp %prec UNARY
243 { write_exp_elt_opcode (UNOP_ADDR); }
244
245 exp : '-' exp %prec UNARY
246 { write_exp_elt_opcode (UNOP_NEG); }
247 ;
248
249 exp : '!' exp %prec UNARY
250 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
251 ;
252
253 exp : '~' exp %prec UNARY
254 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
255 ;
256
257 exp : INCREMENT exp %prec UNARY
258 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
259 ;
260
261 exp : DECREMENT exp %prec UNARY
262 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
263 ;
264
265 exp : exp INCREMENT %prec UNARY
266 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
267 ;
268
269 exp : exp DECREMENT %prec UNARY
270 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
271 ;
272
273 exp : SIZEOF exp %prec UNARY
274 { write_exp_elt_opcode (UNOP_SIZEOF); }
275 ;
276
277 exp : exp ARROW name
278 { write_exp_elt_opcode (STRUCTOP_PTR);
279 write_exp_string ($3);
280 write_exp_elt_opcode (STRUCTOP_PTR); }
281 ;
282
283 exp : exp ARROW qualified_name
284 { /* exp->type::name becomes exp->*(&type::name) */
285 /* Note: this doesn't work if name is a
286 static member! FIXME */
287 write_exp_elt_opcode (UNOP_ADDR);
288 write_exp_elt_opcode (STRUCTOP_MPTR); }
289 ;
290 exp : exp ARROW '*' exp
291 { write_exp_elt_opcode (STRUCTOP_MPTR); }
292 ;
293
294 exp : exp '.' name
295 { write_exp_elt_opcode (STRUCTOP_STRUCT);
296 write_exp_string ($3);
297 write_exp_elt_opcode (STRUCTOP_STRUCT); }
298 ;
299
300 /* start-sanitize-gm
301 Need to find a better way to do this...
302 exp : exp '@' name
303 { write_exp_elt_opcode (STRUCTOP_FIELD);
304 write_exp_string ($3);
305 write_exp_elt_opcode (STRUCTOP_FIELD);
306 }
307 end-sanitize-gm */
308
309 exp : exp '.' qualified_name
310 { /* exp.type::name becomes exp.*(&type::name) */
311 /* Note: this doesn't work if name is a
312 static member! FIXME */
313 write_exp_elt_opcode (UNOP_ADDR);
314 write_exp_elt_opcode (STRUCTOP_MEMBER); }
315 ;
316
317 exp : exp '.' '*' exp
318 { write_exp_elt_opcode (STRUCTOP_MEMBER); }
319 ;
320
321 exp : exp '[' exp1 ']'
322 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
323 ;
324
325 exp : exp '('
326 /* This is to save the value of arglist_len
327 being accumulated by an outer function call. */
328 { start_arglist (); }
329 arglist ')' %prec ARROW
330 { write_exp_elt_opcode (OP_FUNCALL);
331 write_exp_elt_longcst ((LONGEST) end_arglist ());
332 write_exp_elt_opcode (OP_FUNCALL); }
333 ;
334
335 lcurly : '{'
336 { start_arglist (); }
337 ;
338
339 arglist :
340 ;
341
342 arglist : exp
343 { arglist_len = 1; }
344 ;
345
346 arglist : arglist ',' exp %prec ABOVE_COMMA
347 { arglist_len++; }
348 ;
349
350 rcurly : '}'
351 { $$ = end_arglist () - 1; }
352 ;
353 exp : lcurly arglist rcurly %prec ARROW
354 { write_exp_elt_opcode (OP_ARRAY);
355 write_exp_elt_longcst ((LONGEST) 0);
356 write_exp_elt_longcst ((LONGEST) $3);
357 write_exp_elt_opcode (OP_ARRAY); }
358 ;
359
360 exp : lcurly type rcurly exp %prec UNARY
361 { write_exp_elt_opcode (UNOP_MEMVAL);
362 write_exp_elt_type ($2);
363 write_exp_elt_opcode (UNOP_MEMVAL); }
364 ;
365
366 exp : '(' type ')' exp %prec UNARY
367 { write_exp_elt_opcode (UNOP_CAST);
368 write_exp_elt_type ($2);
369 write_exp_elt_opcode (UNOP_CAST); }
370 ;
371
372 exp : '(' exp1 ')'
373 { }
374 ;
375
376 /* Binary operators in order of decreasing precedence. */
377
378 exp : exp '@' exp
379 { write_exp_elt_opcode (BINOP_REPEAT); }
380 ;
381
382 exp : exp '*' exp
383 { write_exp_elt_opcode (BINOP_MUL); }
384 ;
385
386 exp : exp '/' exp
387 { write_exp_elt_opcode (BINOP_DIV); }
388 ;
389
390 exp : exp '%' exp
391 { write_exp_elt_opcode (BINOP_REM); }
392 ;
393
394 exp : exp '+' exp
395 { write_exp_elt_opcode (BINOP_ADD); }
396 ;
397
398 exp : exp '-' exp
399 { write_exp_elt_opcode (BINOP_SUB); }
400 ;
401
402 exp : exp LSH exp
403 { write_exp_elt_opcode (BINOP_LSH); }
404 ;
405
406 exp : exp RSH exp
407 { write_exp_elt_opcode (BINOP_RSH); }
408 ;
409
410 exp : exp EQUAL exp
411 { write_exp_elt_opcode (BINOP_EQUAL); }
412 ;
413
414 exp : exp NOTEQUAL exp
415 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
416 ;
417
418 exp : exp LEQ exp
419 { write_exp_elt_opcode (BINOP_LEQ); }
420 ;
421
422 exp : exp GEQ exp
423 { write_exp_elt_opcode (BINOP_GEQ); }
424 ;
425
426 exp : exp '<' exp
427 { write_exp_elt_opcode (BINOP_LESS); }
428 ;
429
430 exp : exp '>' exp
431 { write_exp_elt_opcode (BINOP_GTR); }
432 ;
433
434 exp : exp '&' exp
435 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
436 ;
437
438 exp : exp '^' exp
439 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
440 ;
441
442 exp : exp '|' exp
443 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
444 ;
445
446 exp : exp ANDAND exp
447 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
448 ;
449
450 exp : exp OROR exp
451 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
452 ;
453
454 exp : exp '?' exp ':' exp %prec '?'
455 { write_exp_elt_opcode (TERNOP_COND); }
456 ;
457
458 exp : exp '=' exp
459 { write_exp_elt_opcode (BINOP_ASSIGN); }
460 ;
461
462 exp : exp ASSIGN_MODIFY exp
463 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
464 write_exp_elt_opcode ($2);
465 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
466 ;
467
468 exp : INT
469 { write_exp_elt_opcode (OP_LONG);
470 write_exp_elt_type ($1.type);
471 write_exp_elt_longcst ((LONGEST)($1.val));
472 write_exp_elt_opcode (OP_LONG); }
473 ;
474
475 exp : NAME_OR_INT
476 { YYSTYPE val;
477 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
478 write_exp_elt_opcode (OP_LONG);
479 write_exp_elt_type (val.typed_val_int.type);
480 write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
481 write_exp_elt_opcode (OP_LONG);
482 }
483 ;
484
485
486 exp : FLOAT
487 { write_exp_elt_opcode (OP_DOUBLE);
488 write_exp_elt_type ($1.type);
489 write_exp_elt_dblcst ($1.dval);
490 write_exp_elt_opcode (OP_DOUBLE); }
491 ;
492
493 exp : variable
494 ;
495
496 exp : VARIABLE
497 /* Already written by write_dollar_variable. */
498 ;
499
500 exp : SIZEOF '(' type ')' %prec UNARY
501 { write_exp_elt_opcode (OP_LONG);
502 write_exp_elt_type (builtin_type_int);
503 CHECK_TYPEDEF ($3);
504 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
505 write_exp_elt_opcode (OP_LONG); }
506 ;
507
508 exp : STRING
509 { /* C strings are converted into array constants with
510 an explicit null byte added at the end. Thus
511 the array upper bound is the string length.
512 There is no such thing in C as a completely empty
513 string. */
514 char *sp = $1.ptr; int count = $1.length;
515 while (count-- > 0)
516 {
517 write_exp_elt_opcode (OP_LONG);
518 write_exp_elt_type (builtin_type_char);
519 write_exp_elt_longcst ((LONGEST)(*sp++));
520 write_exp_elt_opcode (OP_LONG);
521 }
522 write_exp_elt_opcode (OP_LONG);
523 write_exp_elt_type (builtin_type_char);
524 write_exp_elt_longcst ((LONGEST)'\0');
525 write_exp_elt_opcode (OP_LONG);
526 write_exp_elt_opcode (OP_ARRAY);
527 write_exp_elt_longcst ((LONGEST) 0);
528 write_exp_elt_longcst ((LONGEST) ($1.length));
529 write_exp_elt_opcode (OP_ARRAY); }
530 ;
531
532 /* C++. */
533 exp : THIS
534 { write_exp_elt_opcode (OP_THIS);
535 write_exp_elt_opcode (OP_THIS); }
536 ;
537
538 /* end of C++. */
539
540 block : BLOCKNAME
541 {
542 if ($1.sym != 0)
543 $$ = SYMBOL_BLOCK_VALUE ($1.sym);
544 else
545 {
546 struct symtab *tem =
547 lookup_symtab (copy_name ($1.stoken));
548 if (tem)
549 $$ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), STATIC_BLOCK);
550 else
551 error ("No file or function \"%s\".",
552 copy_name ($1.stoken));
553 }
554 }
555 ;
556
557 block : block COLONCOLON name
558 { struct symbol *tem
559 = lookup_symbol (copy_name ($3), $1,
560 VAR_NAMESPACE, (int *) NULL,
561 (struct symtab **) NULL);
562 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
563 error ("No function \"%s\" in specified context.",
564 copy_name ($3));
565 $$ = SYMBOL_BLOCK_VALUE (tem); }
566 ;
567
568 variable: block COLONCOLON name
569 { struct symbol *sym;
570 sym = lookup_symbol (copy_name ($3), $1,
571 VAR_NAMESPACE, (int *) NULL,
572 (struct symtab **) NULL);
573 if (sym == 0)
574 error ("No symbol \"%s\" in specified context.",
575 copy_name ($3));
576
577 write_exp_elt_opcode (OP_VAR_VALUE);
578 /* block_found is set by lookup_symbol. */
579 write_exp_elt_block (block_found);
580 write_exp_elt_sym (sym);
581 write_exp_elt_opcode (OP_VAR_VALUE); }
582 ;
583
584 qualified_name: typebase COLONCOLON name
585 {
586 struct type *type = $1;
587 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
588 && TYPE_CODE (type) != TYPE_CODE_UNION)
589 error ("`%s' is not defined as an aggregate type.",
590 TYPE_NAME (type));
591
592 write_exp_elt_opcode (OP_SCOPE);
593 write_exp_elt_type (type);
594 write_exp_string ($3);
595 write_exp_elt_opcode (OP_SCOPE);
596 }
597 | typebase COLONCOLON '~' name
598 {
599 struct type *type = $1;
600 struct stoken tmp_token;
601 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
602 && TYPE_CODE (type) != TYPE_CODE_UNION)
603 error ("`%s' is not defined as an aggregate type.",
604 TYPE_NAME (type));
605
606 if (!STREQ (type_name_no_tag (type), $4.ptr))
607 error ("invalid destructor `%s::~%s'",
608 type_name_no_tag (type), $4.ptr);
609
610 tmp_token.ptr = (char*) alloca ($4.length + 2);
611 tmp_token.length = $4.length + 1;
612 tmp_token.ptr[0] = '~';
613 memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
614 tmp_token.ptr[tmp_token.length] = 0;
615 write_exp_elt_opcode (OP_SCOPE);
616 write_exp_elt_type (type);
617 write_exp_string (tmp_token);
618 write_exp_elt_opcode (OP_SCOPE);
619 }
620 ;
621
622 variable: qualified_name
623 | COLONCOLON name
624 {
625 char *name = copy_name ($2);
626 struct symbol *sym;
627 struct minimal_symbol *msymbol;
628
629 sym =
630 lookup_symbol (name, (const struct block *) NULL,
631 VAR_NAMESPACE, (int *) NULL,
632 (struct symtab **) NULL);
633 if (sym)
634 {
635 write_exp_elt_opcode (OP_VAR_VALUE);
636 write_exp_elt_block (NULL);
637 write_exp_elt_sym (sym);
638 write_exp_elt_opcode (OP_VAR_VALUE);
639 break;
640 }
641
642 msymbol = lookup_minimal_symbol (name, NULL, NULL);
643 if (msymbol != NULL)
644 {
645 write_exp_msymbol (msymbol,
646 lookup_function_type (builtin_type_int),
647 builtin_type_int);
648 }
649 else
650 if (!have_full_symbols () && !have_partial_symbols ())
651 error ("No symbol table is loaded. Use the \"file\" command.");
652 else
653 error ("No symbol \"%s\" in current context.", name);
654 }
655 ;
656
657 variable: name_not_typename
658 { struct symbol *sym = $1.sym;
659
660 if (sym)
661 {
662 if (symbol_read_needs_frame (sym))
663 {
664 if (innermost_block == 0 ||
665 contained_in (block_found,
666 innermost_block))
667 innermost_block = block_found;
668 }
669
670 write_exp_elt_opcode (OP_VAR_VALUE);
671 /* We want to use the selected frame, not
672 another more inner frame which happens to
673 be in the same block. */
674 write_exp_elt_block (NULL);
675 write_exp_elt_sym (sym);
676 write_exp_elt_opcode (OP_VAR_VALUE);
677 }
678 else if ($1.is_a_field_of_this)
679 {
680 /* C++: it hangs off of `this'. Must
681 not inadvertently convert from a method call
682 to data ref. */
683 if (innermost_block == 0 ||
684 contained_in (block_found, innermost_block))
685 innermost_block = block_found;
686 write_exp_elt_opcode (OP_THIS);
687 write_exp_elt_opcode (OP_THIS);
688 write_exp_elt_opcode (STRUCTOP_PTR);
689 write_exp_string ($1.stoken);
690 write_exp_elt_opcode (STRUCTOP_PTR);
691 }
692 else
693 {
694 struct minimal_symbol *msymbol;
695 register char *arg = copy_name ($1.stoken);
696
697 msymbol =
698 lookup_minimal_symbol (arg, NULL, NULL);
699 if (msymbol != NULL)
700 {
701 write_exp_msymbol (msymbol,
702 lookup_function_type (builtin_type_int),
703 builtin_type_int);
704 }
705 else if (!have_full_symbols () && !have_partial_symbols ())
706 error ("No symbol table is loaded. Use the \"file\" command.");
707 else
708 error ("No symbol \"%s\" in current context.",
709 copy_name ($1.stoken));
710 }
711 }
712 ;
713
714
715 ptype : typebase
716 /* "const" and "volatile" are curently ignored. A type qualifier
717 before the type is currently handled in the typebase rule.
718 The reason for recognizing these here (shift/reduce conflicts)
719 might be obsolete now that some pointer to member rules have
720 been deleted. */
721 | typebase CONST_KEYWORD
722 | typebase VOLATILE_KEYWORD
723 | typebase abs_decl
724 { $$ = follow_types ($1); }
725 | typebase CONST_KEYWORD abs_decl
726 { $$ = follow_types ($1); }
727 | typebase VOLATILE_KEYWORD abs_decl
728 { $$ = follow_types ($1); }
729 ;
730
731 abs_decl: '*'
732 { push_type (tp_pointer); $$ = 0; }
733 | '*' abs_decl
734 { push_type (tp_pointer); $$ = $2; }
735 | '&'
736 { push_type (tp_reference); $$ = 0; }
737 | '&' abs_decl
738 { push_type (tp_reference); $$ = $2; }
739 | direct_abs_decl
740 ;
741
742 direct_abs_decl: '(' abs_decl ')'
743 { $$ = $2; }
744 | direct_abs_decl array_mod
745 {
746 push_type_int ($2);
747 push_type (tp_array);
748 }
749 | array_mod
750 {
751 push_type_int ($1);
752 push_type (tp_array);
753 $$ = 0;
754 }
755
756 | direct_abs_decl func_mod
757 { push_type (tp_function); }
758 | func_mod
759 { push_type (tp_function); }
760 ;
761
762 array_mod: '[' ']'
763 { $$ = -1; }
764 | '[' INT ']'
765 { $$ = $2.val; }
766 ;
767
768 func_mod: '(' ')'
769 { $$ = 0; }
770 | '(' nonempty_typelist ')'
771 { free ((PTR)$2); $$ = 0; }
772 ;
773
774 /* We used to try to recognize more pointer to member types here, but
775 that didn't work (shift/reduce conflicts meant that these rules never
776 got executed). The problem is that
777 int (foo::bar::baz::bizzle)
778 is a function type but
779 int (foo::bar::baz::bizzle::*)
780 is a pointer to member type. Stroustrup loses again! */
781
782 type : ptype
783 | typebase COLONCOLON '*'
784 { $$ = lookup_member_type (builtin_type_int, $1); }
785 ;
786
787 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
788 : TYPENAME
789 { $$ = $1.type; }
790 | INT_KEYWORD
791 { $$ = builtin_type_int; }
792 | LONG
793 { $$ = builtin_type_long; }
794 | SHORT
795 { $$ = builtin_type_short; }
796 | LONG INT_KEYWORD
797 { $$ = builtin_type_long; }
798 | UNSIGNED LONG INT_KEYWORD
799 { $$ = builtin_type_unsigned_long; }
800 | LONG LONG
801 { $$ = builtin_type_long_long; }
802 | LONG LONG INT_KEYWORD
803 { $$ = builtin_type_long_long; }
804 | UNSIGNED LONG LONG
805 { $$ = builtin_type_unsigned_long_long; }
806 | UNSIGNED LONG LONG INT_KEYWORD
807 { $$ = builtin_type_unsigned_long_long; }
808 | SHORT INT_KEYWORD
809 { $$ = builtin_type_short; }
810 | UNSIGNED SHORT INT_KEYWORD
811 { $$ = builtin_type_unsigned_short; }
812 | DOUBLE_KEYWORD
813 { $$ = builtin_type_double; }
814 | LONG DOUBLE_KEYWORD
815 { $$ = builtin_type_long_double; }
816 | STRUCT name
817 { $$ = lookup_struct (copy_name ($2),
818 expression_context_block); }
819 | CLASS name
820 { $$ = lookup_struct (copy_name ($2),
821 expression_context_block); }
822 | UNION name
823 { $$ = lookup_union (copy_name ($2),
824 expression_context_block); }
825 | ENUM name
826 { $$ = lookup_enum (copy_name ($2),
827 expression_context_block); }
828 | UNSIGNED typename
829 { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
830 | UNSIGNED
831 { $$ = builtin_type_unsigned_int; }
832 | SIGNED_KEYWORD typename
833 { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
834 | SIGNED_KEYWORD
835 { $$ = builtin_type_int; }
836 | TEMPLATE name '<' type '>'
837 { $$ = lookup_template_type(copy_name($2), $4,
838 expression_context_block);
839 }
840 /* "const" and "volatile" are curently ignored. A type qualifier
841 after the type is handled in the ptype rule. I think these could
842 be too. */
843 | CONST_KEYWORD typebase { $$ = $2; }
844 | VOLATILE_KEYWORD typebase { $$ = $2; }
845 ;
846
847 typename: TYPENAME
848 | INT_KEYWORD
849 {
850 $$.stoken.ptr = "int";
851 $$.stoken.length = 3;
852 $$.type = builtin_type_int;
853 }
854 | LONG
855 {
856 $$.stoken.ptr = "long";
857 $$.stoken.length = 4;
858 $$.type = builtin_type_long;
859 }
860 | SHORT
861 {
862 $$.stoken.ptr = "short";
863 $$.stoken.length = 5;
864 $$.type = builtin_type_short;
865 }
866 ;
867
868 nonempty_typelist
869 : type
870 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
871 $<ivec>$[0] = 1; /* Number of types in vector */
872 $$[1] = $1;
873 }
874 | nonempty_typelist ',' type
875 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
876 $$ = (struct type **) realloc ((char *) $1, len);
877 $$[$<ivec>$[0]] = $3;
878 }
879 ;
880
881 name : NAME { $$ = $1.stoken; }
882 | BLOCKNAME { $$ = $1.stoken; }
883 | TYPENAME { $$ = $1.stoken; }
884 | NAME_OR_INT { $$ = $1.stoken; }
885 ;
886
887 name_not_typename : NAME
888 | BLOCKNAME
889 /* These would be useful if name_not_typename was useful, but it is just
890 a fake for "variable", so these cause reduce/reduce conflicts because
891 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
892 =exp) or just an exp. If name_not_typename was ever used in an lvalue
893 context where only a name could occur, this might be useful.
894 | NAME_OR_INT
895 */
896 ;
897
898 %%
899
900 /* Take care of parsing a number (anything that starts with a digit).
901 Set yylval and return the token type; update lexptr.
902 LEN is the number of characters in it. */
903
904 /*** Needs some error checking for the float case ***/
905
906 static int
907 parse_number (p, len, parsed_float, putithere)
908 register char *p;
909 register int len;
910 int parsed_float;
911 YYSTYPE *putithere;
912 {
913 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
914 here, and we do kind of silly things like cast to unsigned. */
915 register LONGEST n = 0;
916 register LONGEST prevn = 0;
917 unsigned LONGEST un;
918
919 register int i = 0;
920 register int c;
921 register int base = input_radix;
922 int unsigned_p = 0;
923
924 /* Number of "L" suffixes encountered. */
925 int long_p = 0;
926
927 /* We have found a "L" or "U" suffix. */
928 int found_suffix = 0;
929
930 unsigned LONGEST high_bit;
931 struct type *signed_type;
932 struct type *unsigned_type;
933
934 if (parsed_float)
935 {
936 char c;
937
938 /* It's a float since it contains a point or an exponent. */
939
940 if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
941 sscanf (p, "%g", &putithere->typed_val_float.dval);
942 else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
943 sscanf (p, "%lg", &putithere->typed_val_float.dval);
944 else
945 sscanf (p, "%Lg", &putithere->typed_val_float.dval);
946
947 /* See if it has `f' or `l' suffix (float or long double). */
948
949 c = tolower (p[len - 1]);
950
951 if (c == 'f')
952 putithere->typed_val_float.type = builtin_type_float;
953 else if (c == 'l')
954 putithere->typed_val_float.type = builtin_type_long_double;
955 else if (isdigit (c) || c == '.')
956 putithere->typed_val_float.type = builtin_type_double;
957 else
958 return ERROR;
959
960 return FLOAT;
961 }
962
963 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
964 if (p[0] == '0')
965 switch (p[1])
966 {
967 case 'x':
968 case 'X':
969 if (len >= 3)
970 {
971 p += 2;
972 base = 16;
973 len -= 2;
974 }
975 break;
976
977 case 't':
978 case 'T':
979 case 'd':
980 case 'D':
981 if (len >= 3)
982 {
983 p += 2;
984 base = 10;
985 len -= 2;
986 }
987 break;
988
989 default:
990 base = 8;
991 break;
992 }
993
994 while (len-- > 0)
995 {
996 c = *p++;
997 if (c >= 'A' && c <= 'Z')
998 c += 'a' - 'A';
999 if (c != 'l' && c != 'u')
1000 n *= base;
1001 if (c >= '0' && c <= '9')
1002 {
1003 if (found_suffix)
1004 return ERROR;
1005 n += i = c - '0';
1006 }
1007 else
1008 {
1009 if (base > 10 && c >= 'a' && c <= 'f')
1010 {
1011 if (found_suffix)
1012 return ERROR;
1013 n += i = c - 'a' + 10;
1014 }
1015 else if (c == 'l')
1016 {
1017 ++long_p;
1018 found_suffix = 1;
1019 }
1020 else if (c == 'u')
1021 {
1022 unsigned_p = 1;
1023 found_suffix = 1;
1024 }
1025 else
1026 return ERROR; /* Char not a digit */
1027 }
1028 if (i >= base)
1029 return ERROR; /* Invalid digit in this base */
1030
1031 /* Portably test for overflow (only works for nonzero values, so make
1032 a second check for zero). FIXME: Can't we just make n and prevn
1033 unsigned and avoid this? */
1034 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1035 unsigned_p = 1; /* Try something unsigned */
1036
1037 /* Portably test for unsigned overflow.
1038 FIXME: This check is wrong; for example it doesn't find overflow
1039 on 0x123456789 when LONGEST is 32 bits. */
1040 if (c != 'l' && c != 'u' && n != 0)
1041 {
1042 if ((unsigned_p && (unsigned LONGEST) prevn >= (unsigned LONGEST) n))
1043 error ("Numeric constant too large.");
1044 }
1045 prevn = n;
1046 }
1047
1048 /* An integer constant is an int, a long, or a long long. An L
1049 suffix forces it to be long; an LL suffix forces it to be long
1050 long. If not forced to a larger size, it gets the first type of
1051 the above that it fits in. To figure out whether it fits, we
1052 shift it right and see whether anything remains. Note that we
1053 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1054 operation, because many compilers will warn about such a shift
1055 (which always produces a zero result). Sometimes TARGET_INT_BIT
1056 or TARGET_LONG_BIT will be that big, sometimes not. To deal with
1057 the case where it is we just always shift the value more than
1058 once, with fewer bits each time. */
1059
1060 un = (unsigned LONGEST)n >> 2;
1061 if (long_p == 0
1062 && (un >> (TARGET_INT_BIT - 2)) == 0)
1063 {
1064 high_bit = ((unsigned LONGEST)1) << (TARGET_INT_BIT-1);
1065
1066 /* A large decimal (not hex or octal) constant (between INT_MAX
1067 and UINT_MAX) is a long or unsigned long, according to ANSI,
1068 never an unsigned int, but this code treats it as unsigned
1069 int. This probably should be fixed. GCC gives a warning on
1070 such constants. */
1071
1072 unsigned_type = builtin_type_unsigned_int;
1073 signed_type = builtin_type_int;
1074 }
1075 else if (long_p <= 1
1076 && (un >> (TARGET_LONG_BIT - 2)) == 0)
1077 {
1078 high_bit = ((unsigned LONGEST)1) << (TARGET_LONG_BIT-1);
1079 unsigned_type = builtin_type_unsigned_long;
1080 signed_type = builtin_type_long;
1081 }
1082 else
1083 {
1084 high_bit = (((unsigned LONGEST)1)
1085 << (TARGET_LONG_LONG_BIT - 32 - 1)
1086 << 16
1087 << 16);
1088 if (high_bit == 0)
1089 /* A long long does not fit in a LONGEST. */
1090 high_bit =
1091 (unsigned LONGEST)1 << (sizeof (LONGEST) * HOST_CHAR_BIT - 1);
1092 unsigned_type = builtin_type_unsigned_long_long;
1093 signed_type = builtin_type_long_long;
1094 }
1095
1096 putithere->typed_val_int.val = n;
1097
1098 /* If the high bit of the worked out type is set then this number
1099 has to be unsigned. */
1100
1101 if (unsigned_p || (n & high_bit))
1102 {
1103 putithere->typed_val_int.type = unsigned_type;
1104 }
1105 else
1106 {
1107 putithere->typed_val_int.type = signed_type;
1108 }
1109
1110 return INT;
1111 }
1112
1113 struct token
1114 {
1115 char *operator;
1116 int token;
1117 enum exp_opcode opcode;
1118 };
1119
1120 static const struct token tokentab3[] =
1121 {
1122 {">>=", ASSIGN_MODIFY, BINOP_RSH},
1123 {"<<=", ASSIGN_MODIFY, BINOP_LSH}
1124 };
1125
1126 static const struct token tokentab2[] =
1127 {
1128 {"+=", ASSIGN_MODIFY, BINOP_ADD},
1129 {"-=", ASSIGN_MODIFY, BINOP_SUB},
1130 {"*=", ASSIGN_MODIFY, BINOP_MUL},
1131 {"/=", ASSIGN_MODIFY, BINOP_DIV},
1132 {"%=", ASSIGN_MODIFY, BINOP_REM},
1133 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR},
1134 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND},
1135 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR},
1136 {"++", INCREMENT, BINOP_END},
1137 {"--", DECREMENT, BINOP_END},
1138 {"->", ARROW, BINOP_END},
1139 {"&&", ANDAND, BINOP_END},
1140 {"||", OROR, BINOP_END},
1141 {"::", COLONCOLON, BINOP_END},
1142 {"<<", LSH, BINOP_END},
1143 {">>", RSH, BINOP_END},
1144 {"==", EQUAL, BINOP_END},
1145 {"!=", NOTEQUAL, BINOP_END},
1146 {"<=", LEQ, BINOP_END},
1147 {">=", GEQ, BINOP_END}
1148 };
1149
1150 /* Read one token, getting characters through lexptr. */
1151
1152 static int
1153 yylex ()
1154 {
1155 int c;
1156 int namelen;
1157 unsigned int i;
1158 char *tokstart;
1159 char *tokptr;
1160 int tempbufindex;
1161 static char *tempbuf;
1162 static int tempbufsize;
1163
1164 retry:
1165
1166 tokstart = lexptr;
1167 /* See if it is a special token of length 3. */
1168 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
1169 if (STREQN (tokstart, tokentab3[i].operator, 3))
1170 {
1171 lexptr += 3;
1172 yylval.opcode = tokentab3[i].opcode;
1173 return tokentab3[i].token;
1174 }
1175
1176 /* See if it is a special token of length 2. */
1177 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
1178 if (STREQN (tokstart, tokentab2[i].operator, 2))
1179 {
1180 lexptr += 2;
1181 yylval.opcode = tokentab2[i].opcode;
1182 return tokentab2[i].token;
1183 }
1184
1185 switch (c = *tokstart)
1186 {
1187 case 0:
1188 return 0;
1189
1190 case ' ':
1191 case '\t':
1192 case '\n':
1193 lexptr++;
1194 goto retry;
1195
1196 case '\'':
1197 /* We either have a character constant ('0' or '\177' for example)
1198 or we have a quoted symbol reference ('foo(int,int)' in C++
1199 for example). */
1200 lexptr++;
1201 c = *lexptr++;
1202 if (c == '\\')
1203 c = parse_escape (&lexptr);
1204 else if (c == '\'')
1205 error ("Empty character constant.");
1206
1207 yylval.typed_val_int.val = c;
1208 yylval.typed_val_int.type = builtin_type_char;
1209
1210 c = *lexptr++;
1211 if (c != '\'')
1212 {
1213 namelen = skip_quoted (tokstart) - tokstart;
1214 if (namelen > 2)
1215 {
1216 lexptr = tokstart + namelen;
1217 if (lexptr[-1] != '\'')
1218 error ("Unmatched single quote.");
1219 namelen -= 2;
1220 tokstart++;
1221 goto tryname;
1222 }
1223 error ("Invalid character constant.");
1224 }
1225 return INT;
1226
1227 case '(':
1228 paren_depth++;
1229 lexptr++;
1230 return c;
1231
1232 case ')':
1233 if (paren_depth == 0)
1234 return 0;
1235 paren_depth--;
1236 lexptr++;
1237 return c;
1238
1239 case ',':
1240 if (comma_terminates && paren_depth == 0)
1241 return 0;
1242 lexptr++;
1243 return c;
1244
1245 case '.':
1246 /* Might be a floating point number. */
1247 if (lexptr[1] < '0' || lexptr[1] > '9')
1248 goto symbol; /* Nope, must be a symbol. */
1249 /* FALL THRU into number case. */
1250
1251 case '0':
1252 case '1':
1253 case '2':
1254 case '3':
1255 case '4':
1256 case '5':
1257 case '6':
1258 case '7':
1259 case '8':
1260 case '9':
1261 {
1262 /* It's a number. */
1263 int got_dot = 0, got_e = 0, toktype;
1264 register char *p = tokstart;
1265 int hex = input_radix > 10;
1266
1267 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1268 {
1269 p += 2;
1270 hex = 1;
1271 }
1272 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
1273 {
1274 p += 2;
1275 hex = 0;
1276 }
1277
1278 for (;; ++p)
1279 {
1280 /* This test includes !hex because 'e' is a valid hex digit
1281 and thus does not indicate a floating point number when
1282 the radix is hex. */
1283 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1284 got_dot = got_e = 1;
1285 /* This test does not include !hex, because a '.' always indicates
1286 a decimal floating point number regardless of the radix. */
1287 else if (!got_dot && *p == '.')
1288 got_dot = 1;
1289 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
1290 && (*p == '-' || *p == '+'))
1291 /* This is the sign of the exponent, not the end of the
1292 number. */
1293 continue;
1294 /* We will take any letters or digits. parse_number will
1295 complain if past the radix, or if L or U are not final. */
1296 else if ((*p < '0' || *p > '9')
1297 && ((*p < 'a' || *p > 'z')
1298 && (*p < 'A' || *p > 'Z')))
1299 break;
1300 }
1301 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
1302 if (toktype == ERROR)
1303 {
1304 char *err_copy = (char *) alloca (p - tokstart + 1);
1305
1306 memcpy (err_copy, tokstart, p - tokstart);
1307 err_copy[p - tokstart] = 0;
1308 error ("Invalid number \"%s\".", err_copy);
1309 }
1310 lexptr = p;
1311 return toktype;
1312 }
1313
1314 case '+':
1315 case '-':
1316 case '*':
1317 case '/':
1318 case '%':
1319 case '|':
1320 case '&':
1321 case '^':
1322 case '~':
1323 case '!':
1324 case '@':
1325 case '<':
1326 case '>':
1327 case '[':
1328 case ']':
1329 case '?':
1330 case ':':
1331 case '=':
1332 case '{':
1333 case '}':
1334 symbol:
1335 lexptr++;
1336 return c;
1337
1338 case '"':
1339
1340 /* Build the gdb internal form of the input string in tempbuf,
1341 translating any standard C escape forms seen. Note that the
1342 buffer is null byte terminated *only* for the convenience of
1343 debugging gdb itself and printing the buffer contents when
1344 the buffer contains no embedded nulls. Gdb does not depend
1345 upon the buffer being null byte terminated, it uses the length
1346 string instead. This allows gdb to handle C strings (as well
1347 as strings in other languages) with embedded null bytes */
1348
1349 tokptr = ++tokstart;
1350 tempbufindex = 0;
1351
1352 do {
1353 /* Grow the static temp buffer if necessary, including allocating
1354 the first one on demand. */
1355 if (tempbufindex + 1 >= tempbufsize)
1356 {
1357 tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
1358 }
1359 switch (*tokptr)
1360 {
1361 case '\0':
1362 case '"':
1363 /* Do nothing, loop will terminate. */
1364 break;
1365 case '\\':
1366 tokptr++;
1367 c = parse_escape (&tokptr);
1368 if (c == -1)
1369 {
1370 continue;
1371 }
1372 tempbuf[tempbufindex++] = c;
1373 break;
1374 default:
1375 tempbuf[tempbufindex++] = *tokptr++;
1376 break;
1377 }
1378 } while ((*tokptr != '"') && (*tokptr != '\0'));
1379 if (*tokptr++ != '"')
1380 {
1381 error ("Unterminated string in expression.");
1382 }
1383 tempbuf[tempbufindex] = '\0'; /* See note above */
1384 yylval.sval.ptr = tempbuf;
1385 yylval.sval.length = tempbufindex;
1386 lexptr = tokptr;
1387 return (STRING);
1388 }
1389
1390 if (!(c == '_' || c == '$'
1391 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1392 /* We must have come across a bad character (e.g. ';'). */
1393 error ("Invalid character '%c' in expression.", c);
1394
1395 /* It's a name. See how long it is. */
1396 namelen = 0;
1397 for (c = tokstart[namelen];
1398 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1399 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
1400 {
1401 if (c == '<')
1402 {
1403 int i = namelen;
1404 while (tokstart[++i] && tokstart[i] != '>');
1405 if (tokstart[i] == '>')
1406 namelen = i;
1407 }
1408 c = tokstart[++namelen];
1409 }
1410
1411 /* The token "if" terminates the expression and is NOT
1412 removed from the input stream. */
1413 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1414 {
1415 return 0;
1416 }
1417
1418 lexptr += namelen;
1419
1420 tryname:
1421
1422 /* Catch specific keywords. Should be done with a data structure. */
1423 switch (namelen)
1424 {
1425 case 8:
1426 if (STREQN (tokstart, "unsigned", 8))
1427 return UNSIGNED;
1428 if (current_language->la_language == language_cplus
1429 && STREQN (tokstart, "template", 8))
1430 return TEMPLATE;
1431 if (STREQN (tokstart, "volatile", 8))
1432 return VOLATILE_KEYWORD;
1433 break;
1434 case 6:
1435 if (STREQN (tokstart, "struct", 6))
1436 return STRUCT;
1437 if (STREQN (tokstart, "signed", 6))
1438 return SIGNED_KEYWORD;
1439 if (STREQN (tokstart, "sizeof", 6))
1440 return SIZEOF;
1441 if (STREQN (tokstart, "double", 6))
1442 return DOUBLE_KEYWORD;
1443 break;
1444 case 5:
1445 if (current_language->la_language == language_cplus
1446 && STREQN (tokstart, "class", 5))
1447 return CLASS;
1448 if (STREQN (tokstart, "union", 5))
1449 return UNION;
1450 if (STREQN (tokstart, "short", 5))
1451 return SHORT;
1452 if (STREQN (tokstart, "const", 5))
1453 return CONST_KEYWORD;
1454 break;
1455 case 4:
1456 if (STREQN (tokstart, "enum", 4))
1457 return ENUM;
1458 if (STREQN (tokstart, "long", 4))
1459 return LONG;
1460 if (current_language->la_language == language_cplus
1461 && STREQN (tokstart, "this", 4))
1462 {
1463 static const char this_name[] =
1464 { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' };
1465
1466 if (lookup_symbol (this_name, expression_context_block,
1467 VAR_NAMESPACE, (int *) NULL,
1468 (struct symtab **) NULL))
1469 return THIS;
1470 }
1471 break;
1472 case 3:
1473 if (STREQN (tokstart, "int", 3))
1474 return INT_KEYWORD;
1475 break;
1476 default:
1477 break;
1478 }
1479
1480 yylval.sval.ptr = tokstart;
1481 yylval.sval.length = namelen;
1482
1483 if (*tokstart == '$')
1484 {
1485 write_dollar_variable (yylval.sval);
1486 return VARIABLE;
1487 }
1488
1489 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1490 functions or symtabs. If this is not so, then ...
1491 Use token-type TYPENAME for symbols that happen to be defined
1492 currently as names of types; NAME for other symbols.
1493 The caller is not constrained to care about the distinction. */
1494 {
1495 char *tmp = copy_name (yylval.sval);
1496 struct symbol *sym;
1497 int is_a_field_of_this = 0;
1498 int hextype;
1499
1500 sym = lookup_symbol (tmp, expression_context_block,
1501 VAR_NAMESPACE,
1502 current_language->la_language == language_cplus
1503 ? &is_a_field_of_this : (int *) NULL,
1504 (struct symtab **) NULL);
1505 /* Call lookup_symtab, not lookup_partial_symtab, in case there are
1506 no psymtabs (coff, xcoff, or some future change to blow away the
1507 psymtabs once once symbols are read). */
1508 if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) ||
1509 lookup_symtab (tmp))
1510 {
1511 yylval.ssym.sym = sym;
1512 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1513 return BLOCKNAME;
1514 }
1515 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1516 {
1517 #if 1
1518 /* Despite the following flaw, we need to keep this code enabled.
1519 Because we can get called from check_stub_method, if we don't
1520 handle nested types then it screws many operations in any
1521 program which uses nested types. */
1522 /* In "A::x", if x is a member function of A and there happens
1523 to be a type (nested or not, since the stabs don't make that
1524 distinction) named x, then this code incorrectly thinks we
1525 are dealing with nested types rather than a member function. */
1526
1527 char *p;
1528 char *namestart;
1529 struct symbol *best_sym;
1530
1531 /* Look ahead to detect nested types. This probably should be
1532 done in the grammar, but trying seemed to introduce a lot
1533 of shift/reduce and reduce/reduce conflicts. It's possible
1534 that it could be done, though. Or perhaps a non-grammar, but
1535 less ad hoc, approach would work well. */
1536
1537 /* Since we do not currently have any way of distinguishing
1538 a nested type from a non-nested one (the stabs don't tell
1539 us whether a type is nested), we just ignore the
1540 containing type. */
1541
1542 p = lexptr;
1543 best_sym = sym;
1544 while (1)
1545 {
1546 /* Skip whitespace. */
1547 while (*p == ' ' || *p == '\t' || *p == '\n')
1548 ++p;
1549 if (*p == ':' && p[1] == ':')
1550 {
1551 /* Skip the `::'. */
1552 p += 2;
1553 /* Skip whitespace. */
1554 while (*p == ' ' || *p == '\t' || *p == '\n')
1555 ++p;
1556 namestart = p;
1557 while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9')
1558 || (*p >= 'a' && *p <= 'z')
1559 || (*p >= 'A' && *p <= 'Z'))
1560 ++p;
1561 if (p != namestart)
1562 {
1563 struct symbol *cur_sym;
1564 /* As big as the whole rest of the expression, which is
1565 at least big enough. */
1566 char *ncopy = alloca (strlen (tmp)+strlen (namestart)+3);
1567 char *tmp1;
1568
1569 tmp1 = ncopy;
1570 memcpy (tmp1, tmp, strlen (tmp));
1571 tmp1 += strlen (tmp);
1572 memcpy (tmp1, "::", 2);
1573 tmp1 += 2;
1574 memcpy (tmp1, namestart, p - namestart);
1575 tmp1[p - namestart] = '\0';
1576 cur_sym = lookup_symbol (ncopy, expression_context_block,
1577 VAR_NAMESPACE, (int *) NULL,
1578 (struct symtab **) NULL);
1579 if (cur_sym)
1580 {
1581 if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
1582 {
1583 best_sym = cur_sym;
1584 lexptr = p;
1585 }
1586 else
1587 break;
1588 }
1589 else
1590 break;
1591 }
1592 else
1593 break;
1594 }
1595 else
1596 break;
1597 }
1598
1599 yylval.tsym.type = SYMBOL_TYPE (best_sym);
1600 #else /* not 0 */
1601 yylval.tsym.type = SYMBOL_TYPE (sym);
1602 #endif /* not 0 */
1603 return TYPENAME;
1604 }
1605 if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
1606 return TYPENAME;
1607
1608 /* Input names that aren't symbols but ARE valid hex numbers,
1609 when the input radix permits them, can be names or numbers
1610 depending on the parse. Note we support radixes > 16 here. */
1611 if (!sym &&
1612 ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
1613 (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1614 {
1615 YYSTYPE newlval; /* Its value is ignored. */
1616 hextype = parse_number (tokstart, namelen, 0, &newlval);
1617 if (hextype == INT)
1618 {
1619 yylval.ssym.sym = sym;
1620 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1621 return NAME_OR_INT;
1622 }
1623 }
1624
1625 /* Any other kind of symbol */
1626 yylval.ssym.sym = sym;
1627 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1628 return NAME;
1629 }
1630 }
1631
1632 void
1633 yyerror (msg)
1634 char *msg;
1635 {
1636 error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
1637 }
This page took 0.061611 seconds and 5 git commands to generate.