* c-exp.y (parse_number): Don't use K&R definition.
[deliverable/binutils-gdb.git] / gdb / c-exp.y
1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2003, 2004, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 /* Parse a C expression from text in a string,
22 and return the result as a struct expression pointer.
23 That structure contains arithmetic operations in reverse polish,
24 with constants represented by operations that are followed by special data.
25 See expression.h for the details of the format.
26 What is important here is that it can be built up sequentially
27 during the process of parsing; the lower levels of the tree always
28 come first in the result.
29
30 Note that malloc's and realloc's in this file are transformed to
31 xmalloc and xrealloc respectively by the same sed command in the
32 makefile that remaps any other malloc/realloc inserted by the parser
33 generator. Doing this with #defines and trying to control the interaction
34 with include files (<malloc.h> and <stdlib.h> for example) just became
35 too messy, particularly when such includes can be inserted at random
36 times by the parser generator. */
37
38 %{
39
40 #include "defs.h"
41 #include "gdb_string.h"
42 #include <ctype.h>
43 #include "expression.h"
44 #include "value.h"
45 #include "parser-defs.h"
46 #include "language.h"
47 #include "c-lang.h"
48 #include "bfd.h" /* Required by objfiles.h. */
49 #include "symfile.h" /* Required by objfiles.h. */
50 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
51 #include "charset.h"
52 #include "block.h"
53 #include "cp-support.h"
54 #include "dfp.h"
55 #include "gdb_assert.h"
56 #include "macroscope.h"
57
58 #define parse_type builtin_type (parse_gdbarch)
59
60 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
61 as well as gratuitiously global symbol names, so we can have multiple
62 yacc generated parsers in gdb. Note that these are only the variables
63 produced by yacc. If other parser generators (bison, byacc, etc) produce
64 additional global names that conflict at link time, then those parser
65 generators need to be fixed instead of adding those names to this list. */
66
67 #define yymaxdepth c_maxdepth
68 #define yyparse c_parse_internal
69 #define yylex c_lex
70 #define yyerror c_error
71 #define yylval c_lval
72 #define yychar c_char
73 #define yydebug c_debug
74 #define yypact c_pact
75 #define yyr1 c_r1
76 #define yyr2 c_r2
77 #define yydef c_def
78 #define yychk c_chk
79 #define yypgo c_pgo
80 #define yyact c_act
81 #define yyexca c_exca
82 #define yyerrflag c_errflag
83 #define yynerrs c_nerrs
84 #define yyps c_ps
85 #define yypv c_pv
86 #define yys c_s
87 #define yy_yys c_yys
88 #define yystate c_state
89 #define yytmp c_tmp
90 #define yyv c_v
91 #define yy_yyv c_yyv
92 #define yyval c_val
93 #define yylloc c_lloc
94 #define yyreds c_reds /* With YYDEBUG defined */
95 #define yytoks c_toks /* With YYDEBUG defined */
96 #define yyname c_name /* With YYDEBUG defined */
97 #define yyrule c_rule /* With YYDEBUG defined */
98 #define yylhs c_yylhs
99 #define yylen c_yylen
100 #define yydefred c_yydefred
101 #define yydgoto c_yydgoto
102 #define yysindex c_yysindex
103 #define yyrindex c_yyrindex
104 #define yygindex c_yygindex
105 #define yytable c_yytable
106 #define yycheck c_yycheck
107
108 #ifndef YYDEBUG
109 #define YYDEBUG 1 /* Default to yydebug support */
110 #endif
111
112 #define YYFPRINTF parser_fprintf
113
114 int yyparse (void);
115
116 static int yylex (void);
117
118 void yyerror (char *);
119
120 %}
121
122 /* Although the yacc "value" of an expression is not used,
123 since the result is stored in the structure being created,
124 other node types do have values. */
125
126 %union
127 {
128 LONGEST lval;
129 struct {
130 LONGEST val;
131 struct type *type;
132 } typed_val_int;
133 struct {
134 DOUBLEST dval;
135 struct type *type;
136 } typed_val_float;
137 struct {
138 gdb_byte val[16];
139 struct type *type;
140 } typed_val_decfloat;
141 struct symbol *sym;
142 struct type *tval;
143 struct stoken sval;
144 struct typed_stoken tsval;
145 struct ttype tsym;
146 struct symtoken ssym;
147 int voidval;
148 struct block *bval;
149 enum exp_opcode opcode;
150 struct internalvar *ivar;
151
152 struct stoken_vector svec;
153 struct type **tvec;
154 int *ivec;
155 }
156
157 %{
158 /* YYSTYPE gets defined by %union */
159 static int parse_number (char *, int, int, YYSTYPE *);
160 %}
161
162 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
163 %type <lval> rcurly
164 %type <tval> type typebase qualified_type
165 %type <tvec> nonempty_typelist
166 /* %type <bval> block */
167
168 /* Fancy type parsing. */
169 %type <voidval> func_mod direct_abs_decl abs_decl
170 %type <tval> ptype
171 %type <lval> array_mod
172
173 %token <typed_val_int> INT
174 %token <typed_val_float> FLOAT
175 %token <typed_val_decfloat> DECFLOAT
176
177 /* Both NAME and TYPENAME tokens represent symbols in the input,
178 and both convey their data as strings.
179 But a TYPENAME is a string that happens to be defined as a typedef
180 or builtin type name (such as int or char)
181 and a NAME is any other symbol.
182 Contexts where this distinction is not important can use the
183 nonterminal "name", which matches either NAME or TYPENAME. */
184
185 %token <tsval> STRING
186 %token <tsval> CHAR
187 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
188 %token <voidval> COMPLETE
189 %token <tsym> TYPENAME
190 %type <sval> name
191 %type <svec> string_exp
192 %type <ssym> name_not_typename
193 %type <tsym> typename
194
195 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
196 but which would parse as a valid number in the current input radix.
197 E.g. "c" when input_radix==16. Depending on the parse, it will be
198 turned into a name or into a number. */
199
200 %token <ssym> NAME_OR_INT
201
202 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
203 %token TEMPLATE
204 %token ERROR
205
206 /* Special type cases, put in to allow the parser to distinguish different
207 legal basetypes. */
208 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
209
210 %token <voidval> VARIABLE
211
212 %token <opcode> ASSIGN_MODIFY
213
214 /* C++ */
215 %token TRUEKEYWORD
216 %token FALSEKEYWORD
217
218
219 %left ','
220 %left ABOVE_COMMA
221 %right '=' ASSIGN_MODIFY
222 %right '?'
223 %left OROR
224 %left ANDAND
225 %left '|'
226 %left '^'
227 %left '&'
228 %left EQUAL NOTEQUAL
229 %left '<' '>' LEQ GEQ
230 %left LSH RSH
231 %left '@'
232 %left '+' '-'
233 %left '*' '/' '%'
234 %right UNARY INCREMENT DECREMENT
235 %right ARROW '.' '[' '('
236 %token <ssym> BLOCKNAME
237 %token <bval> FILENAME
238 %type <bval> block
239 %left COLONCOLON
240
241 \f
242 %%
243
244 start : exp1
245 | type_exp
246 ;
247
248 type_exp: type
249 { write_exp_elt_opcode(OP_TYPE);
250 write_exp_elt_type($1);
251 write_exp_elt_opcode(OP_TYPE);}
252 ;
253
254 /* Expressions, including the comma operator. */
255 exp1 : exp
256 | exp1 ',' exp
257 { write_exp_elt_opcode (BINOP_COMMA); }
258 ;
259
260 /* Expressions, not including the comma operator. */
261 exp : '*' exp %prec UNARY
262 { write_exp_elt_opcode (UNOP_IND); }
263 ;
264
265 exp : '&' exp %prec UNARY
266 { write_exp_elt_opcode (UNOP_ADDR); }
267 ;
268
269 exp : '-' exp %prec UNARY
270 { write_exp_elt_opcode (UNOP_NEG); }
271 ;
272
273 exp : '+' exp %prec UNARY
274 { write_exp_elt_opcode (UNOP_PLUS); }
275 ;
276
277 exp : '!' exp %prec UNARY
278 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
279 ;
280
281 exp : '~' exp %prec UNARY
282 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
283 ;
284
285 exp : INCREMENT exp %prec UNARY
286 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
287 ;
288
289 exp : DECREMENT exp %prec UNARY
290 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
291 ;
292
293 exp : exp INCREMENT %prec UNARY
294 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
295 ;
296
297 exp : exp DECREMENT %prec UNARY
298 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
299 ;
300
301 exp : SIZEOF exp %prec UNARY
302 { write_exp_elt_opcode (UNOP_SIZEOF); }
303 ;
304
305 exp : exp ARROW name
306 { write_exp_elt_opcode (STRUCTOP_PTR);
307 write_exp_string ($3);
308 write_exp_elt_opcode (STRUCTOP_PTR); }
309 ;
310
311 exp : exp ARROW name COMPLETE
312 { mark_struct_expression ();
313 write_exp_elt_opcode (STRUCTOP_PTR);
314 write_exp_string ($3);
315 write_exp_elt_opcode (STRUCTOP_PTR); }
316 ;
317
318 exp : exp ARROW COMPLETE
319 { struct stoken s;
320 mark_struct_expression ();
321 write_exp_elt_opcode (STRUCTOP_PTR);
322 s.ptr = "";
323 s.length = 0;
324 write_exp_string (s);
325 write_exp_elt_opcode (STRUCTOP_PTR); }
326 ;
327
328 exp : exp ARROW qualified_name
329 { /* exp->type::name becomes exp->*(&type::name) */
330 /* Note: this doesn't work if name is a
331 static member! FIXME */
332 write_exp_elt_opcode (UNOP_ADDR);
333 write_exp_elt_opcode (STRUCTOP_MPTR); }
334 ;
335
336 exp : exp ARROW '*' exp
337 { write_exp_elt_opcode (STRUCTOP_MPTR); }
338 ;
339
340 exp : exp '.' name
341 { write_exp_elt_opcode (STRUCTOP_STRUCT);
342 write_exp_string ($3);
343 write_exp_elt_opcode (STRUCTOP_STRUCT); }
344 ;
345
346 exp : exp '.' name COMPLETE
347 { mark_struct_expression ();
348 write_exp_elt_opcode (STRUCTOP_STRUCT);
349 write_exp_string ($3);
350 write_exp_elt_opcode (STRUCTOP_STRUCT); }
351 ;
352
353 exp : exp '.' COMPLETE
354 { struct stoken s;
355 mark_struct_expression ();
356 write_exp_elt_opcode (STRUCTOP_STRUCT);
357 s.ptr = "";
358 s.length = 0;
359 write_exp_string (s);
360 write_exp_elt_opcode (STRUCTOP_STRUCT); }
361 ;
362
363 exp : exp '.' qualified_name
364 { /* exp.type::name becomes exp.*(&type::name) */
365 /* Note: this doesn't work if name is a
366 static member! FIXME */
367 write_exp_elt_opcode (UNOP_ADDR);
368 write_exp_elt_opcode (STRUCTOP_MEMBER); }
369 ;
370
371 exp : exp '.' '*' exp
372 { write_exp_elt_opcode (STRUCTOP_MEMBER); }
373 ;
374
375 exp : exp '[' exp1 ']'
376 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
377 ;
378
379 exp : exp '('
380 /* This is to save the value of arglist_len
381 being accumulated by an outer function call. */
382 { start_arglist (); }
383 arglist ')' %prec ARROW
384 { write_exp_elt_opcode (OP_FUNCALL);
385 write_exp_elt_longcst ((LONGEST) end_arglist ());
386 write_exp_elt_opcode (OP_FUNCALL); }
387 ;
388
389 lcurly : '{'
390 { start_arglist (); }
391 ;
392
393 arglist :
394 ;
395
396 arglist : exp
397 { arglist_len = 1; }
398 ;
399
400 arglist : arglist ',' exp %prec ABOVE_COMMA
401 { arglist_len++; }
402 ;
403
404 rcurly : '}'
405 { $$ = end_arglist () - 1; }
406 ;
407 exp : lcurly arglist rcurly %prec ARROW
408 { write_exp_elt_opcode (OP_ARRAY);
409 write_exp_elt_longcst ((LONGEST) 0);
410 write_exp_elt_longcst ((LONGEST) $3);
411 write_exp_elt_opcode (OP_ARRAY); }
412 ;
413
414 exp : lcurly type rcurly exp %prec UNARY
415 { write_exp_elt_opcode (UNOP_MEMVAL);
416 write_exp_elt_type ($2);
417 write_exp_elt_opcode (UNOP_MEMVAL); }
418 ;
419
420 exp : '(' type ')' exp %prec UNARY
421 { write_exp_elt_opcode (UNOP_CAST);
422 write_exp_elt_type ($2);
423 write_exp_elt_opcode (UNOP_CAST); }
424 ;
425
426 exp : '(' exp1 ')'
427 { }
428 ;
429
430 /* Binary operators in order of decreasing precedence. */
431
432 exp : exp '@' exp
433 { write_exp_elt_opcode (BINOP_REPEAT); }
434 ;
435
436 exp : exp '*' exp
437 { write_exp_elt_opcode (BINOP_MUL); }
438 ;
439
440 exp : exp '/' exp
441 { write_exp_elt_opcode (BINOP_DIV); }
442 ;
443
444 exp : exp '%' exp
445 { write_exp_elt_opcode (BINOP_REM); }
446 ;
447
448 exp : exp '+' exp
449 { write_exp_elt_opcode (BINOP_ADD); }
450 ;
451
452 exp : exp '-' exp
453 { write_exp_elt_opcode (BINOP_SUB); }
454 ;
455
456 exp : exp LSH exp
457 { write_exp_elt_opcode (BINOP_LSH); }
458 ;
459
460 exp : exp RSH exp
461 { write_exp_elt_opcode (BINOP_RSH); }
462 ;
463
464 exp : exp EQUAL exp
465 { write_exp_elt_opcode (BINOP_EQUAL); }
466 ;
467
468 exp : exp NOTEQUAL exp
469 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
470 ;
471
472 exp : exp LEQ exp
473 { write_exp_elt_opcode (BINOP_LEQ); }
474 ;
475
476 exp : exp GEQ exp
477 { write_exp_elt_opcode (BINOP_GEQ); }
478 ;
479
480 exp : exp '<' exp
481 { write_exp_elt_opcode (BINOP_LESS); }
482 ;
483
484 exp : exp '>' exp
485 { write_exp_elt_opcode (BINOP_GTR); }
486 ;
487
488 exp : exp '&' exp
489 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
490 ;
491
492 exp : exp '^' exp
493 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
494 ;
495
496 exp : exp '|' exp
497 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
498 ;
499
500 exp : exp ANDAND exp
501 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
502 ;
503
504 exp : exp OROR exp
505 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
506 ;
507
508 exp : exp '?' exp ':' exp %prec '?'
509 { write_exp_elt_opcode (TERNOP_COND); }
510 ;
511
512 exp : exp '=' exp
513 { write_exp_elt_opcode (BINOP_ASSIGN); }
514 ;
515
516 exp : exp ASSIGN_MODIFY exp
517 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
518 write_exp_elt_opcode ($2);
519 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
520 ;
521
522 exp : INT
523 { write_exp_elt_opcode (OP_LONG);
524 write_exp_elt_type ($1.type);
525 write_exp_elt_longcst ((LONGEST)($1.val));
526 write_exp_elt_opcode (OP_LONG); }
527 ;
528
529 exp : CHAR
530 {
531 struct stoken_vector vec;
532 vec.len = 1;
533 vec.tokens = &$1;
534 write_exp_string_vector ($1.type, &vec);
535 }
536 ;
537
538 exp : NAME_OR_INT
539 { YYSTYPE val;
540 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
541 write_exp_elt_opcode (OP_LONG);
542 write_exp_elt_type (val.typed_val_int.type);
543 write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
544 write_exp_elt_opcode (OP_LONG);
545 }
546 ;
547
548
549 exp : FLOAT
550 { write_exp_elt_opcode (OP_DOUBLE);
551 write_exp_elt_type ($1.type);
552 write_exp_elt_dblcst ($1.dval);
553 write_exp_elt_opcode (OP_DOUBLE); }
554 ;
555
556 exp : DECFLOAT
557 { write_exp_elt_opcode (OP_DECFLOAT);
558 write_exp_elt_type ($1.type);
559 write_exp_elt_decfloatcst ($1.val);
560 write_exp_elt_opcode (OP_DECFLOAT); }
561 ;
562
563 exp : variable
564 ;
565
566 exp : VARIABLE
567 /* Already written by write_dollar_variable. */
568 ;
569
570 exp : SIZEOF '(' type ')' %prec UNARY
571 { write_exp_elt_opcode (OP_LONG);
572 write_exp_elt_type (parse_type->builtin_int);
573 CHECK_TYPEDEF ($3);
574 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
575 write_exp_elt_opcode (OP_LONG); }
576 ;
577
578 string_exp:
579 STRING
580 {
581 /* We copy the string here, and not in the
582 lexer, to guarantee that we do not leak a
583 string. Note that we follow the
584 NUL-termination convention of the
585 lexer. */
586 struct typed_stoken *vec = XNEW (struct typed_stoken);
587 $$.len = 1;
588 $$.tokens = vec;
589
590 vec->type = $1.type;
591 vec->length = $1.length;
592 vec->ptr = malloc ($1.length + 1);
593 memcpy (vec->ptr, $1.ptr, $1.length + 1);
594 }
595
596 | string_exp STRING
597 {
598 /* Note that we NUL-terminate here, but just
599 for convenience. */
600 char *p;
601 ++$$.len;
602 $$.tokens = realloc ($$.tokens,
603 $$.len * sizeof (struct typed_stoken));
604
605 p = malloc ($2.length + 1);
606 memcpy (p, $2.ptr, $2.length + 1);
607
608 $$.tokens[$$.len - 1].type = $2.type;
609 $$.tokens[$$.len - 1].length = $2.length;
610 $$.tokens[$$.len - 1].ptr = p;
611 }
612 ;
613
614 exp : string_exp
615 {
616 int i;
617 enum c_string_type type = C_STRING;
618
619 for (i = 0; i < $1.len; ++i)
620 {
621 switch ($1.tokens[i].type)
622 {
623 case C_STRING:
624 break;
625 case C_WIDE_STRING:
626 case C_STRING_16:
627 case C_STRING_32:
628 if (type != C_STRING
629 && type != $1.tokens[i].type)
630 error ("Undefined string concatenation.");
631 type = $1.tokens[i].type;
632 break;
633 default:
634 /* internal error */
635 internal_error (__FILE__, __LINE__,
636 "unrecognized type in string concatenation");
637 }
638 }
639
640 write_exp_string_vector (type, &$1);
641 for (i = 0; i < $1.len; ++i)
642 free ($1.tokens[i].ptr);
643 free ($1.tokens);
644 }
645 ;
646
647 /* C++. */
648 exp : TRUEKEYWORD
649 { write_exp_elt_opcode (OP_LONG);
650 write_exp_elt_type (parse_type->builtin_bool);
651 write_exp_elt_longcst ((LONGEST) 1);
652 write_exp_elt_opcode (OP_LONG); }
653 ;
654
655 exp : FALSEKEYWORD
656 { write_exp_elt_opcode (OP_LONG);
657 write_exp_elt_type (parse_type->builtin_bool);
658 write_exp_elt_longcst ((LONGEST) 0);
659 write_exp_elt_opcode (OP_LONG); }
660 ;
661
662 /* end of C++. */
663
664 block : BLOCKNAME
665 {
666 if ($1.sym)
667 $$ = SYMBOL_BLOCK_VALUE ($1.sym);
668 else
669 error ("No file or function \"%s\".",
670 copy_name ($1.stoken));
671 }
672 | FILENAME
673 {
674 $$ = $1;
675 }
676 ;
677
678 block : block COLONCOLON name
679 { struct symbol *tem
680 = lookup_symbol (copy_name ($3), $1,
681 VAR_DOMAIN, (int *) NULL);
682 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
683 error ("No function \"%s\" in specified context.",
684 copy_name ($3));
685 $$ = SYMBOL_BLOCK_VALUE (tem); }
686 ;
687
688 variable: block COLONCOLON name
689 { struct symbol *sym;
690 sym = lookup_symbol (copy_name ($3), $1,
691 VAR_DOMAIN, (int *) NULL);
692 if (sym == 0)
693 error ("No symbol \"%s\" in specified context.",
694 copy_name ($3));
695
696 write_exp_elt_opcode (OP_VAR_VALUE);
697 /* block_found is set by lookup_symbol. */
698 write_exp_elt_block (block_found);
699 write_exp_elt_sym (sym);
700 write_exp_elt_opcode (OP_VAR_VALUE); }
701 ;
702
703 qualified_name: typebase COLONCOLON name
704 {
705 struct type *type = $1;
706 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
707 && TYPE_CODE (type) != TYPE_CODE_UNION
708 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
709 error ("`%s' is not defined as an aggregate type.",
710 TYPE_NAME (type));
711
712 write_exp_elt_opcode (OP_SCOPE);
713 write_exp_elt_type (type);
714 write_exp_string ($3);
715 write_exp_elt_opcode (OP_SCOPE);
716 }
717 | typebase COLONCOLON '~' name
718 {
719 struct type *type = $1;
720 struct stoken tmp_token;
721 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
722 && TYPE_CODE (type) != TYPE_CODE_UNION
723 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
724 error ("`%s' is not defined as an aggregate type.",
725 TYPE_NAME (type));
726
727 tmp_token.ptr = (char*) alloca ($4.length + 2);
728 tmp_token.length = $4.length + 1;
729 tmp_token.ptr[0] = '~';
730 memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
731 tmp_token.ptr[tmp_token.length] = 0;
732
733 /* Check for valid destructor name. */
734 destructor_name_p (tmp_token.ptr, type);
735 write_exp_elt_opcode (OP_SCOPE);
736 write_exp_elt_type (type);
737 write_exp_string (tmp_token);
738 write_exp_elt_opcode (OP_SCOPE);
739 }
740 ;
741
742 variable: qualified_name
743 | COLONCOLON name
744 {
745 char *name = copy_name ($2);
746 struct symbol *sym;
747 struct minimal_symbol *msymbol;
748
749 sym =
750 lookup_symbol (name, (const struct block *) NULL,
751 VAR_DOMAIN, (int *) NULL);
752 if (sym)
753 {
754 write_exp_elt_opcode (OP_VAR_VALUE);
755 write_exp_elt_block (NULL);
756 write_exp_elt_sym (sym);
757 write_exp_elt_opcode (OP_VAR_VALUE);
758 break;
759 }
760
761 msymbol = lookup_minimal_symbol (name, NULL, NULL);
762 if (msymbol != NULL)
763 write_exp_msymbol (msymbol);
764 else if (!have_full_symbols () && !have_partial_symbols ())
765 error ("No symbol table is loaded. Use the \"file\" command.");
766 else
767 error ("No symbol \"%s\" in current context.", name);
768 }
769 ;
770
771 variable: name_not_typename
772 { struct symbol *sym = $1.sym;
773
774 if (sym)
775 {
776 if (symbol_read_needs_frame (sym))
777 {
778 if (innermost_block == 0 ||
779 contained_in (block_found,
780 innermost_block))
781 innermost_block = block_found;
782 }
783
784 write_exp_elt_opcode (OP_VAR_VALUE);
785 /* We want to use the selected frame, not
786 another more inner frame which happens to
787 be in the same block. */
788 write_exp_elt_block (NULL);
789 write_exp_elt_sym (sym);
790 write_exp_elt_opcode (OP_VAR_VALUE);
791 }
792 else if ($1.is_a_field_of_this)
793 {
794 /* C++: it hangs off of `this'. Must
795 not inadvertently convert from a method call
796 to data ref. */
797 if (innermost_block == 0 ||
798 contained_in (block_found, innermost_block))
799 innermost_block = block_found;
800 write_exp_elt_opcode (OP_THIS);
801 write_exp_elt_opcode (OP_THIS);
802 write_exp_elt_opcode (STRUCTOP_PTR);
803 write_exp_string ($1.stoken);
804 write_exp_elt_opcode (STRUCTOP_PTR);
805 }
806 else
807 {
808 struct minimal_symbol *msymbol;
809 char *arg = copy_name ($1.stoken);
810
811 msymbol =
812 lookup_minimal_symbol (arg, NULL, NULL);
813 if (msymbol != NULL)
814 write_exp_msymbol (msymbol);
815 else if (!have_full_symbols () && !have_partial_symbols ())
816 error ("No symbol table is loaded. Use the \"file\" command.");
817 else
818 error ("No symbol \"%s\" in current context.",
819 copy_name ($1.stoken));
820 }
821 }
822 ;
823
824 space_identifier : '@' NAME
825 { push_type_address_space (copy_name ($2.stoken));
826 push_type (tp_space_identifier);
827 }
828 ;
829
830 const_or_volatile: const_or_volatile_noopt
831 |
832 ;
833
834 cv_with_space_id : const_or_volatile space_identifier const_or_volatile
835 ;
836
837 const_or_volatile_or_space_identifier_noopt: cv_with_space_id
838 | const_or_volatile_noopt
839 ;
840
841 const_or_volatile_or_space_identifier:
842 const_or_volatile_or_space_identifier_noopt
843 |
844 ;
845
846 abs_decl: '*'
847 { push_type (tp_pointer); $$ = 0; }
848 | '*' abs_decl
849 { push_type (tp_pointer); $$ = $2; }
850 | '&'
851 { push_type (tp_reference); $$ = 0; }
852 | '&' abs_decl
853 { push_type (tp_reference); $$ = $2; }
854 | direct_abs_decl
855 ;
856
857 direct_abs_decl: '(' abs_decl ')'
858 { $$ = $2; }
859 | direct_abs_decl array_mod
860 {
861 push_type_int ($2);
862 push_type (tp_array);
863 }
864 | array_mod
865 {
866 push_type_int ($1);
867 push_type (tp_array);
868 $$ = 0;
869 }
870
871 | direct_abs_decl func_mod
872 { push_type (tp_function); }
873 | func_mod
874 { push_type (tp_function); }
875 ;
876
877 array_mod: '[' ']'
878 { $$ = -1; }
879 | '[' INT ']'
880 { $$ = $2.val; }
881 ;
882
883 func_mod: '(' ')'
884 { $$ = 0; }
885 | '(' nonempty_typelist ')'
886 { free ($2); $$ = 0; }
887 ;
888
889 /* We used to try to recognize pointer to member types here, but
890 that didn't work (shift/reduce conflicts meant that these rules never
891 got executed). The problem is that
892 int (foo::bar::baz::bizzle)
893 is a function type but
894 int (foo::bar::baz::bizzle::*)
895 is a pointer to member type. Stroustrup loses again! */
896
897 type : ptype
898 ;
899
900 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
901 : TYPENAME
902 { $$ = $1.type; }
903 | INT_KEYWORD
904 { $$ = parse_type->builtin_int; }
905 | LONG
906 { $$ = parse_type->builtin_long; }
907 | SHORT
908 { $$ = parse_type->builtin_short; }
909 | LONG INT_KEYWORD
910 { $$ = parse_type->builtin_long; }
911 | LONG SIGNED_KEYWORD INT_KEYWORD
912 { $$ = parse_type->builtin_long; }
913 | LONG SIGNED_KEYWORD
914 { $$ = parse_type->builtin_long; }
915 | SIGNED_KEYWORD LONG INT_KEYWORD
916 { $$ = parse_type->builtin_long; }
917 | UNSIGNED LONG INT_KEYWORD
918 { $$ = parse_type->builtin_unsigned_long; }
919 | LONG UNSIGNED INT_KEYWORD
920 { $$ = parse_type->builtin_unsigned_long; }
921 | LONG UNSIGNED
922 { $$ = parse_type->builtin_unsigned_long; }
923 | LONG LONG
924 { $$ = parse_type->builtin_long_long; }
925 | LONG LONG INT_KEYWORD
926 { $$ = parse_type->builtin_long_long; }
927 | LONG LONG SIGNED_KEYWORD INT_KEYWORD
928 { $$ = parse_type->builtin_long_long; }
929 | LONG LONG SIGNED_KEYWORD
930 { $$ = parse_type->builtin_long_long; }
931 | SIGNED_KEYWORD LONG LONG
932 { $$ = parse_type->builtin_long_long; }
933 | SIGNED_KEYWORD LONG LONG INT_KEYWORD
934 { $$ = parse_type->builtin_long_long; }
935 | UNSIGNED LONG LONG
936 { $$ = parse_type->builtin_unsigned_long_long; }
937 | UNSIGNED LONG LONG INT_KEYWORD
938 { $$ = parse_type->builtin_unsigned_long_long; }
939 | LONG LONG UNSIGNED
940 { $$ = parse_type->builtin_unsigned_long_long; }
941 | LONG LONG UNSIGNED INT_KEYWORD
942 { $$ = parse_type->builtin_unsigned_long_long; }
943 | SHORT INT_KEYWORD
944 { $$ = parse_type->builtin_short; }
945 | SHORT SIGNED_KEYWORD INT_KEYWORD
946 { $$ = parse_type->builtin_short; }
947 | SHORT SIGNED_KEYWORD
948 { $$ = parse_type->builtin_short; }
949 | UNSIGNED SHORT INT_KEYWORD
950 { $$ = parse_type->builtin_unsigned_short; }
951 | SHORT UNSIGNED
952 { $$ = parse_type->builtin_unsigned_short; }
953 | SHORT UNSIGNED INT_KEYWORD
954 { $$ = parse_type->builtin_unsigned_short; }
955 | DOUBLE_KEYWORD
956 { $$ = parse_type->builtin_double; }
957 | LONG DOUBLE_KEYWORD
958 { $$ = parse_type->builtin_long_double; }
959 | STRUCT name
960 { $$ = lookup_struct (copy_name ($2),
961 expression_context_block); }
962 | CLASS name
963 { $$ = lookup_struct (copy_name ($2),
964 expression_context_block); }
965 | UNION name
966 { $$ = lookup_union (copy_name ($2),
967 expression_context_block); }
968 | ENUM name
969 { $$ = lookup_enum (copy_name ($2),
970 expression_context_block); }
971 | UNSIGNED typename
972 { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
973 | UNSIGNED
974 { $$ = parse_type->builtin_unsigned_int; }
975 | SIGNED_KEYWORD typename
976 { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
977 | SIGNED_KEYWORD
978 { $$ = parse_type->builtin_int; }
979 /* It appears that this rule for templates is never
980 reduced; template recognition happens by lookahead
981 in the token processing code in yylex. */
982 | TEMPLATE name '<' type '>'
983 { $$ = lookup_template_type(copy_name($2), $4,
984 expression_context_block);
985 }
986 | const_or_volatile_or_space_identifier_noopt typebase
987 { $$ = follow_types ($2); }
988 | typebase const_or_volatile_or_space_identifier_noopt
989 { $$ = follow_types ($1); }
990 | qualified_type
991 ;
992
993 /* FIXME: carlton/2003-09-25: This next bit leads to lots of
994 reduce-reduce conflicts, because the parser doesn't know whether or
995 not to use qualified_name or qualified_type: the rules are
996 identical. If the parser is parsing 'A::B::x', then, when it sees
997 the second '::', it knows that the expression to the left of it has
998 to be a type, so it uses qualified_type. But if it is parsing just
999 'A::B', then it doesn't have any way of knowing which rule to use,
1000 so there's a reduce-reduce conflict; it picks qualified_name, since
1001 that occurs earlier in this file than qualified_type.
1002
1003 There's no good way to fix this with the grammar as it stands; as
1004 far as I can tell, some of the problems arise from ambiguities that
1005 GDB introduces ('start' can be either an expression or a type), but
1006 some of it is inherent to the nature of C++ (you want to treat the
1007 input "(FOO)" fairly differently depending on whether FOO is an
1008 expression or a type, and if FOO is a complex expression, this can
1009 be hard to determine at the right time). Fortunately, it works
1010 pretty well in most cases. For example, if you do 'ptype A::B',
1011 where A::B is a nested type, then the parser will mistakenly
1012 misidentify it as an expression; but evaluate_subexp will get
1013 called with 'noside' set to EVAL_AVOID_SIDE_EFFECTS, and everything
1014 will work out anyways. But there are situations where the parser
1015 will get confused: the most common one that I've run into is when
1016 you want to do
1017
1018 print *((A::B *) x)"
1019
1020 where the parser doesn't realize that A::B has to be a type until
1021 it hits the first right paren, at which point it's too late. (The
1022 workaround is to type "print *(('A::B' *) x)" instead.) (And
1023 another solution is to fix our symbol-handling code so that the
1024 user never wants to type something like that in the first place,
1025 because we get all the types right without the user's help!)
1026
1027 Perhaps we could fix this by making the lexer smarter. Some of
1028 this functionality used to be in the lexer, but in a way that
1029 worked even less well than the current solution: that attempt
1030 involved having the parser sometimes handle '::' and having the
1031 lexer sometimes handle it, and without a clear division of
1032 responsibility, it quickly degenerated into a big mess. Probably
1033 the eventual correct solution will give more of a role to the lexer
1034 (ideally via code that is shared between the lexer and
1035 decode_line_1), but I'm not holding my breath waiting for somebody
1036 to get around to cleaning this up... */
1037
1038 qualified_type: typebase COLONCOLON name
1039 {
1040 struct type *type = $1;
1041 struct type *new_type;
1042 char *ncopy = alloca ($3.length + 1);
1043
1044 memcpy (ncopy, $3.ptr, $3.length);
1045 ncopy[$3.length] = '\0';
1046
1047 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1048 && TYPE_CODE (type) != TYPE_CODE_UNION
1049 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
1050 error ("`%s' is not defined as an aggregate type.",
1051 TYPE_NAME (type));
1052
1053 new_type = cp_lookup_nested_type (type, ncopy,
1054 expression_context_block);
1055 if (new_type == NULL)
1056 error ("No type \"%s\" within class or namespace \"%s\".",
1057 ncopy, TYPE_NAME (type));
1058
1059 $$ = new_type;
1060 }
1061 ;
1062
1063 typename: TYPENAME
1064 | INT_KEYWORD
1065 {
1066 $$.stoken.ptr = "int";
1067 $$.stoken.length = 3;
1068 $$.type = parse_type->builtin_int;
1069 }
1070 | LONG
1071 {
1072 $$.stoken.ptr = "long";
1073 $$.stoken.length = 4;
1074 $$.type = parse_type->builtin_long;
1075 }
1076 | SHORT
1077 {
1078 $$.stoken.ptr = "short";
1079 $$.stoken.length = 5;
1080 $$.type = parse_type->builtin_short;
1081 }
1082 ;
1083
1084 nonempty_typelist
1085 : type
1086 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
1087 $<ivec>$[0] = 1; /* Number of types in vector */
1088 $$[1] = $1;
1089 }
1090 | nonempty_typelist ',' type
1091 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
1092 $$ = (struct type **) realloc ((char *) $1, len);
1093 $$[$<ivec>$[0]] = $3;
1094 }
1095 ;
1096
1097 ptype : typebase
1098 | ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
1099 { $$ = follow_types ($1); }
1100 ;
1101
1102 const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
1103 | VOLATILE_KEYWORD CONST_KEYWORD
1104 ;
1105
1106 const_or_volatile_noopt: const_and_volatile
1107 { push_type (tp_const);
1108 push_type (tp_volatile);
1109 }
1110 | CONST_KEYWORD
1111 { push_type (tp_const); }
1112 | VOLATILE_KEYWORD
1113 { push_type (tp_volatile); }
1114 ;
1115
1116 name : NAME { $$ = $1.stoken; }
1117 | BLOCKNAME { $$ = $1.stoken; }
1118 | TYPENAME { $$ = $1.stoken; }
1119 | NAME_OR_INT { $$ = $1.stoken; }
1120 ;
1121
1122 name_not_typename : NAME
1123 | BLOCKNAME
1124 /* These would be useful if name_not_typename was useful, but it is just
1125 a fake for "variable", so these cause reduce/reduce conflicts because
1126 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1127 =exp) or just an exp. If name_not_typename was ever used in an lvalue
1128 context where only a name could occur, this might be useful.
1129 | NAME_OR_INT
1130 */
1131 ;
1132
1133 %%
1134
1135 /* Take care of parsing a number (anything that starts with a digit).
1136 Set yylval and return the token type; update lexptr.
1137 LEN is the number of characters in it. */
1138
1139 /*** Needs some error checking for the float case ***/
1140
1141 static int
1142 parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
1143 {
1144 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
1145 here, and we do kind of silly things like cast to unsigned. */
1146 LONGEST n = 0;
1147 LONGEST prevn = 0;
1148 ULONGEST un;
1149
1150 int i = 0;
1151 int c;
1152 int base = input_radix;
1153 int unsigned_p = 0;
1154
1155 /* Number of "L" suffixes encountered. */
1156 int long_p = 0;
1157
1158 /* We have found a "L" or "U" suffix. */
1159 int found_suffix = 0;
1160
1161 ULONGEST high_bit;
1162 struct type *signed_type;
1163 struct type *unsigned_type;
1164
1165 if (parsed_float)
1166 {
1167 /* It's a float since it contains a point or an exponent. */
1168 char *s;
1169 int num; /* number of tokens scanned by scanf */
1170 char saved_char;
1171
1172 /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
1173 point. Return DECFLOAT. */
1174
1175 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
1176 {
1177 p[len - 2] = '\0';
1178 putithere->typed_val_decfloat.type
1179 = parse_type->builtin_decfloat;
1180 decimal_from_string (putithere->typed_val_decfloat.val, 4, p);
1181 p[len - 2] = 'd';
1182 return DECFLOAT;
1183 }
1184
1185 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
1186 {
1187 p[len - 2] = '\0';
1188 putithere->typed_val_decfloat.type
1189 = parse_type->builtin_decdouble;
1190 decimal_from_string (putithere->typed_val_decfloat.val, 8, p);
1191 p[len - 2] = 'd';
1192 return DECFLOAT;
1193 }
1194
1195 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
1196 {
1197 p[len - 2] = '\0';
1198 putithere->typed_val_decfloat.type
1199 = parse_type->builtin_declong;
1200 decimal_from_string (putithere->typed_val_decfloat.val, 16, p);
1201 p[len - 2] = 'd';
1202 return DECFLOAT;
1203 }
1204
1205 s = malloc (len);
1206 saved_char = p[len];
1207 p[len] = 0; /* null-terminate the token */
1208 num = sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%s",
1209 &putithere->typed_val_float.dval, s);
1210 p[len] = saved_char; /* restore the input stream */
1211
1212 if (num == 1)
1213 putithere->typed_val_float.type =
1214 parse_type->builtin_double;
1215
1216 if (num == 2 )
1217 {
1218 /* See if it has any float suffix: 'f' for float, 'l' for long
1219 double. */
1220 if (!strcasecmp (s, "f"))
1221 putithere->typed_val_float.type =
1222 parse_type->builtin_float;
1223 else if (!strcasecmp (s, "l"))
1224 putithere->typed_val_float.type =
1225 parse_type->builtin_long_double;
1226 else
1227 {
1228 free (s);
1229 return ERROR;
1230 }
1231 }
1232
1233 free (s);
1234 return FLOAT;
1235 }
1236
1237 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1238 if (p[0] == '0')
1239 switch (p[1])
1240 {
1241 case 'x':
1242 case 'X':
1243 if (len >= 3)
1244 {
1245 p += 2;
1246 base = 16;
1247 len -= 2;
1248 }
1249 break;
1250
1251 case 't':
1252 case 'T':
1253 case 'd':
1254 case 'D':
1255 if (len >= 3)
1256 {
1257 p += 2;
1258 base = 10;
1259 len -= 2;
1260 }
1261 break;
1262
1263 default:
1264 base = 8;
1265 break;
1266 }
1267
1268 while (len-- > 0)
1269 {
1270 c = *p++;
1271 if (c >= 'A' && c <= 'Z')
1272 c += 'a' - 'A';
1273 if (c != 'l' && c != 'u')
1274 n *= base;
1275 if (c >= '0' && c <= '9')
1276 {
1277 if (found_suffix)
1278 return ERROR;
1279 n += i = c - '0';
1280 }
1281 else
1282 {
1283 if (base > 10 && c >= 'a' && c <= 'f')
1284 {
1285 if (found_suffix)
1286 return ERROR;
1287 n += i = c - 'a' + 10;
1288 }
1289 else if (c == 'l')
1290 {
1291 ++long_p;
1292 found_suffix = 1;
1293 }
1294 else if (c == 'u')
1295 {
1296 unsigned_p = 1;
1297 found_suffix = 1;
1298 }
1299 else
1300 return ERROR; /* Char not a digit */
1301 }
1302 if (i >= base)
1303 return ERROR; /* Invalid digit in this base */
1304
1305 /* Portably test for overflow (only works for nonzero values, so make
1306 a second check for zero). FIXME: Can't we just make n and prevn
1307 unsigned and avoid this? */
1308 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1309 unsigned_p = 1; /* Try something unsigned */
1310
1311 /* Portably test for unsigned overflow.
1312 FIXME: This check is wrong; for example it doesn't find overflow
1313 on 0x123456789 when LONGEST is 32 bits. */
1314 if (c != 'l' && c != 'u' && n != 0)
1315 {
1316 if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1317 error ("Numeric constant too large.");
1318 }
1319 prevn = n;
1320 }
1321
1322 /* An integer constant is an int, a long, or a long long. An L
1323 suffix forces it to be long; an LL suffix forces it to be long
1324 long. If not forced to a larger size, it gets the first type of
1325 the above that it fits in. To figure out whether it fits, we
1326 shift it right and see whether anything remains. Note that we
1327 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1328 operation, because many compilers will warn about such a shift
1329 (which always produces a zero result). Sometimes gdbarch_int_bit
1330 or gdbarch_long_bit will be that big, sometimes not. To deal with
1331 the case where it is we just always shift the value more than
1332 once, with fewer bits each time. */
1333
1334 un = (ULONGEST)n >> 2;
1335 if (long_p == 0
1336 && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
1337 {
1338 high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
1339
1340 /* A large decimal (not hex or octal) constant (between INT_MAX
1341 and UINT_MAX) is a long or unsigned long, according to ANSI,
1342 never an unsigned int, but this code treats it as unsigned
1343 int. This probably should be fixed. GCC gives a warning on
1344 such constants. */
1345
1346 unsigned_type = parse_type->builtin_unsigned_int;
1347 signed_type = parse_type->builtin_int;
1348 }
1349 else if (long_p <= 1
1350 && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
1351 {
1352 high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
1353 unsigned_type = parse_type->builtin_unsigned_long;
1354 signed_type = parse_type->builtin_long;
1355 }
1356 else
1357 {
1358 int shift;
1359 if (sizeof (ULONGEST) * HOST_CHAR_BIT
1360 < gdbarch_long_long_bit (parse_gdbarch))
1361 /* A long long does not fit in a LONGEST. */
1362 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
1363 else
1364 shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
1365 high_bit = (ULONGEST) 1 << shift;
1366 unsigned_type = parse_type->builtin_unsigned_long_long;
1367 signed_type = parse_type->builtin_long_long;
1368 }
1369
1370 putithere->typed_val_int.val = n;
1371
1372 /* If the high bit of the worked out type is set then this number
1373 has to be unsigned. */
1374
1375 if (unsigned_p || (n & high_bit))
1376 {
1377 putithere->typed_val_int.type = unsigned_type;
1378 }
1379 else
1380 {
1381 putithere->typed_val_int.type = signed_type;
1382 }
1383
1384 return INT;
1385 }
1386
1387 /* Temporary obstack used for holding strings. */
1388 static struct obstack tempbuf;
1389 static int tempbuf_init;
1390
1391 /* Parse a C escape sequence. The initial backslash of the sequence
1392 is at (*PTR)[-1]. *PTR will be updated to point to just after the
1393 last character of the sequence. If OUTPUT is not NULL, the
1394 translated form of the escape sequence will be written there. If
1395 OUTPUT is NULL, no output is written and the call will only affect
1396 *PTR. If an escape sequence is expressed in target bytes, then the
1397 entire sequence will simply be copied to OUTPUT. Return 1 if any
1398 character was emitted, 0 otherwise. */
1399
1400 int
1401 c_parse_escape (char **ptr, struct obstack *output)
1402 {
1403 char *tokptr = *ptr;
1404 int result = 1;
1405
1406 /* Some escape sequences undergo character set conversion. Those we
1407 translate here. */
1408 switch (*tokptr)
1409 {
1410 /* Hex escapes do not undergo character set conversion, so keep
1411 the escape sequence for later. */
1412 case 'x':
1413 if (output)
1414 obstack_grow_str (output, "\\x");
1415 ++tokptr;
1416 if (!isxdigit (*tokptr))
1417 error (_("\\x escape without a following hex digit"));
1418 while (isxdigit (*tokptr))
1419 {
1420 if (output)
1421 obstack_1grow (output, *tokptr);
1422 ++tokptr;
1423 }
1424 break;
1425
1426 /* Octal escapes do not undergo character set conversion, so
1427 keep the escape sequence for later. */
1428 case '0':
1429 case '1':
1430 case '2':
1431 case '3':
1432 case '4':
1433 case '5':
1434 case '6':
1435 case '7':
1436 if (output)
1437 obstack_grow_str (output, "\\");
1438 while (isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9')
1439 {
1440 if (output)
1441 obstack_1grow (output, *tokptr);
1442 ++tokptr;
1443 }
1444 break;
1445
1446 /* We handle UCNs later. We could handle them here, but that
1447 would mean a spurious error in the case where the UCN could
1448 be converted to the target charset but not the host
1449 charset. */
1450 case 'u':
1451 case 'U':
1452 {
1453 char c = *tokptr;
1454 int i, len = c == 'U' ? 8 : 4;
1455 if (output)
1456 {
1457 obstack_1grow (output, '\\');
1458 obstack_1grow (output, *tokptr);
1459 }
1460 ++tokptr;
1461 if (!isxdigit (*tokptr))
1462 error (_("\\%c escape without a following hex digit"), c);
1463 for (i = 0; i < len && isxdigit (*tokptr); ++i)
1464 {
1465 if (output)
1466 obstack_1grow (output, *tokptr);
1467 ++tokptr;
1468 }
1469 }
1470 break;
1471
1472 /* We must pass backslash through so that it does not
1473 cause quoting during the second expansion. */
1474 case '\\':
1475 if (output)
1476 obstack_grow_str (output, "\\\\");
1477 ++tokptr;
1478 break;
1479
1480 /* Escapes which undergo conversion. */
1481 case 'a':
1482 if (output)
1483 obstack_1grow (output, '\a');
1484 ++tokptr;
1485 break;
1486 case 'b':
1487 if (output)
1488 obstack_1grow (output, '\b');
1489 ++tokptr;
1490 break;
1491 case 'f':
1492 if (output)
1493 obstack_1grow (output, '\f');
1494 ++tokptr;
1495 break;
1496 case 'n':
1497 if (output)
1498 obstack_1grow (output, '\n');
1499 ++tokptr;
1500 break;
1501 case 'r':
1502 if (output)
1503 obstack_1grow (output, '\r');
1504 ++tokptr;
1505 break;
1506 case 't':
1507 if (output)
1508 obstack_1grow (output, '\t');
1509 ++tokptr;
1510 break;
1511 case 'v':
1512 if (output)
1513 obstack_1grow (output, '\v');
1514 ++tokptr;
1515 break;
1516
1517 /* GCC extension. */
1518 case 'e':
1519 if (output)
1520 obstack_1grow (output, HOST_ESCAPE_CHAR);
1521 ++tokptr;
1522 break;
1523
1524 /* Backslash-newline expands to nothing at all. */
1525 case '\n':
1526 ++tokptr;
1527 result = 0;
1528 break;
1529
1530 /* A few escapes just expand to the character itself. */
1531 case '\'':
1532 case '\"':
1533 case '?':
1534 /* GCC extensions. */
1535 case '(':
1536 case '{':
1537 case '[':
1538 case '%':
1539 /* Unrecognized escapes turn into the character itself. */
1540 default:
1541 if (output)
1542 obstack_1grow (output, *tokptr);
1543 ++tokptr;
1544 break;
1545 }
1546 *ptr = tokptr;
1547 return result;
1548 }
1549
1550 /* Parse a string or character literal from TOKPTR. The string or
1551 character may be wide or unicode. *OUTPTR is set to just after the
1552 end of the literal in the input string. The resulting token is
1553 stored in VALUE. This returns a token value, either STRING or
1554 CHAR, depending on what was parsed. *HOST_CHARS is set to the
1555 number of host characters in the literal. */
1556 static int
1557 parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
1558 int *host_chars)
1559 {
1560 int quote, i;
1561 enum c_string_type type;
1562
1563 /* Build the gdb internal form of the input string in tempbuf. Note
1564 that the buffer is null byte terminated *only* for the
1565 convenience of debugging gdb itself and printing the buffer
1566 contents when the buffer contains no embedded nulls. Gdb does
1567 not depend upon the buffer being null byte terminated, it uses
1568 the length string instead. This allows gdb to handle C strings
1569 (as well as strings in other languages) with embedded null
1570 bytes */
1571
1572 if (!tempbuf_init)
1573 tempbuf_init = 1;
1574 else
1575 obstack_free (&tempbuf, NULL);
1576 obstack_init (&tempbuf);
1577
1578 /* Record the string type. */
1579 if (*tokptr == 'L')
1580 {
1581 type = C_WIDE_STRING;
1582 ++tokptr;
1583 }
1584 else if (*tokptr == 'u')
1585 {
1586 type = C_STRING_16;
1587 ++tokptr;
1588 }
1589 else if (*tokptr == 'U')
1590 {
1591 type = C_STRING_32;
1592 ++tokptr;
1593 }
1594 else
1595 type = C_STRING;
1596
1597 /* Skip the quote. */
1598 quote = *tokptr;
1599 if (quote == '\'')
1600 type |= C_CHAR;
1601 ++tokptr;
1602
1603 *host_chars = 0;
1604
1605 while (*tokptr)
1606 {
1607 char c = *tokptr;
1608 if (c == '\\')
1609 {
1610 ++tokptr;
1611 *host_chars += c_parse_escape (&tokptr, &tempbuf);
1612 }
1613 else if (c == quote)
1614 break;
1615 else
1616 {
1617 obstack_1grow (&tempbuf, c);
1618 ++tokptr;
1619 /* FIXME: this does the wrong thing with multi-byte host
1620 characters. We could use mbrlen here, but that would
1621 make "set host-charset" a bit less useful. */
1622 ++*host_chars;
1623 }
1624 }
1625
1626 if (*tokptr != quote)
1627 {
1628 if (quote == '"')
1629 error ("Unterminated string in expression.");
1630 else
1631 error ("Unmatched single quote.");
1632 }
1633 ++tokptr;
1634
1635 value->type = type;
1636 value->ptr = obstack_base (&tempbuf);
1637 value->length = obstack_object_size (&tempbuf);
1638
1639 *outptr = tokptr;
1640
1641 return quote == '"' ? STRING : CHAR;
1642 }
1643
1644 struct token
1645 {
1646 char *operator;
1647 int token;
1648 enum exp_opcode opcode;
1649 int cxx_only;
1650 };
1651
1652 static const struct token tokentab3[] =
1653 {
1654 {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
1655 {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0}
1656 };
1657
1658 static const struct token tokentab2[] =
1659 {
1660 {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
1661 {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
1662 {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
1663 {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
1664 {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
1665 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
1666 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
1667 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
1668 {"++", INCREMENT, BINOP_END, 0},
1669 {"--", DECREMENT, BINOP_END, 0},
1670 {"->", ARROW, BINOP_END, 0},
1671 {"&&", ANDAND, BINOP_END, 0},
1672 {"||", OROR, BINOP_END, 0},
1673 {"::", COLONCOLON, BINOP_END, 0},
1674 {"<<", LSH, BINOP_END, 0},
1675 {">>", RSH, BINOP_END, 0},
1676 {"==", EQUAL, BINOP_END, 0},
1677 {"!=", NOTEQUAL, BINOP_END, 0},
1678 {"<=", LEQ, BINOP_END, 0},
1679 {">=", GEQ, BINOP_END, 0}
1680 };
1681
1682 /* Identifier-like tokens. */
1683 static const struct token ident_tokens[] =
1684 {
1685 {"unsigned", UNSIGNED, OP_NULL, 0},
1686 {"template", TEMPLATE, OP_NULL, 1},
1687 {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
1688 {"struct", STRUCT, OP_NULL, 0},
1689 {"signed", SIGNED_KEYWORD, OP_NULL, 0},
1690 {"sizeof", SIZEOF, OP_NULL, 0},
1691 {"double", DOUBLE_KEYWORD, OP_NULL, 0},
1692 {"false", FALSEKEYWORD, OP_NULL, 1},
1693 {"class", CLASS, OP_NULL, 1},
1694 {"union", UNION, OP_NULL, 0},
1695 {"short", SHORT, OP_NULL, 0},
1696 {"const", CONST_KEYWORD, OP_NULL, 0},
1697 {"enum", ENUM, OP_NULL, 0},
1698 {"long", LONG, OP_NULL, 0},
1699 {"true", TRUEKEYWORD, OP_NULL, 1},
1700 {"int", INT_KEYWORD, OP_NULL, 0},
1701
1702 {"and", ANDAND, BINOP_END, 1},
1703 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, 1},
1704 {"bitand", '&', OP_NULL, 1},
1705 {"bitor", '|', OP_NULL, 1},
1706 {"compl", '~', OP_NULL, 1},
1707 {"not", '!', OP_NULL, 1},
1708 {"not_eq", NOTEQUAL, BINOP_END, 1},
1709 {"or", OROR, BINOP_END, 1},
1710 {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 1},
1711 {"xor", '^', OP_NULL, 1},
1712 {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 1}
1713 };
1714
1715 /* When we find that lexptr (the global var defined in parse.c) is
1716 pointing at a macro invocation, we expand the invocation, and call
1717 scan_macro_expansion to save the old lexptr here and point lexptr
1718 into the expanded text. When we reach the end of that, we call
1719 end_macro_expansion to pop back to the value we saved here. The
1720 macro expansion code promises to return only fully-expanded text,
1721 so we don't need to "push" more than one level.
1722
1723 This is disgusting, of course. It would be cleaner to do all macro
1724 expansion beforehand, and then hand that to lexptr. But we don't
1725 really know where the expression ends. Remember, in a command like
1726
1727 (gdb) break *ADDRESS if CONDITION
1728
1729 we evaluate ADDRESS in the scope of the current frame, but we
1730 evaluate CONDITION in the scope of the breakpoint's location. So
1731 it's simply wrong to try to macro-expand the whole thing at once. */
1732 static char *macro_original_text;
1733
1734 /* We save all intermediate macro expansions on this obstack for the
1735 duration of a single parse. The expansion text may sometimes have
1736 to live past the end of the expansion, due to yacc lookahead.
1737 Rather than try to be clever about saving the data for a single
1738 token, we simply keep it all and delete it after parsing has
1739 completed. */
1740 static struct obstack expansion_obstack;
1741
1742 static void
1743 scan_macro_expansion (char *expansion)
1744 {
1745 char *copy;
1746
1747 /* We'd better not be trying to push the stack twice. */
1748 gdb_assert (! macro_original_text);
1749
1750 /* Copy to the obstack, and then free the intermediate
1751 expansion. */
1752 copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
1753 xfree (expansion);
1754
1755 /* Save the old lexptr value, so we can return to it when we're done
1756 parsing the expanded text. */
1757 macro_original_text = lexptr;
1758 lexptr = copy;
1759 }
1760
1761
1762 static int
1763 scanning_macro_expansion (void)
1764 {
1765 return macro_original_text != 0;
1766 }
1767
1768
1769 static void
1770 finished_macro_expansion (void)
1771 {
1772 /* There'd better be something to pop back to. */
1773 gdb_assert (macro_original_text);
1774
1775 /* Pop back to the original text. */
1776 lexptr = macro_original_text;
1777 macro_original_text = 0;
1778 }
1779
1780
1781 static void
1782 scan_macro_cleanup (void *dummy)
1783 {
1784 if (macro_original_text)
1785 finished_macro_expansion ();
1786
1787 obstack_free (&expansion_obstack, NULL);
1788 }
1789
1790
1791 /* The scope used for macro expansion. */
1792 static struct macro_scope *expression_macro_scope;
1793
1794 /* This is set if a NAME token appeared at the very end of the input
1795 string, with no whitespace separating the name from the EOF. This
1796 is used only when parsing to do field name completion. */
1797 static int saw_name_at_eof;
1798
1799 /* This is set if the previously-returned token was a structure
1800 operator -- either '.' or ARROW. This is used only when parsing to
1801 do field name completion. */
1802 static int last_was_structop;
1803
1804 /* Read one token, getting characters through lexptr. */
1805
1806 static int
1807 yylex (void)
1808 {
1809 int c;
1810 int namelen;
1811 unsigned int i;
1812 char *tokstart;
1813 int saw_structop = last_was_structop;
1814 char *copy;
1815
1816 last_was_structop = 0;
1817
1818 retry:
1819
1820 /* Check if this is a macro invocation that we need to expand. */
1821 if (! scanning_macro_expansion ())
1822 {
1823 char *expanded = macro_expand_next (&lexptr,
1824 standard_macro_lookup,
1825 expression_macro_scope);
1826
1827 if (expanded)
1828 scan_macro_expansion (expanded);
1829 }
1830
1831 prev_lexptr = lexptr;
1832
1833 tokstart = lexptr;
1834 /* See if it is a special token of length 3. */
1835 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
1836 if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
1837 {
1838 lexptr += 3;
1839 yylval.opcode = tokentab3[i].opcode;
1840 return tokentab3[i].token;
1841 }
1842
1843 /* See if it is a special token of length 2. */
1844 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
1845 if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
1846 {
1847 lexptr += 2;
1848 yylval.opcode = tokentab2[i].opcode;
1849 if (in_parse_field && tokentab2[i].token == ARROW)
1850 last_was_structop = 1;
1851 return tokentab2[i].token;
1852 }
1853
1854 switch (c = *tokstart)
1855 {
1856 case 0:
1857 /* If we were just scanning the result of a macro expansion,
1858 then we need to resume scanning the original text.
1859 If we're parsing for field name completion, and the previous
1860 token allows such completion, return a COMPLETE token.
1861 Otherwise, we were already scanning the original text, and
1862 we're really done. */
1863 if (scanning_macro_expansion ())
1864 {
1865 finished_macro_expansion ();
1866 goto retry;
1867 }
1868 else if (saw_name_at_eof)
1869 {
1870 saw_name_at_eof = 0;
1871 return COMPLETE;
1872 }
1873 else if (saw_structop)
1874 return COMPLETE;
1875 else
1876 return 0;
1877
1878 case ' ':
1879 case '\t':
1880 case '\n':
1881 lexptr++;
1882 goto retry;
1883
1884 case '[':
1885 case '(':
1886 paren_depth++;
1887 lexptr++;
1888 return c;
1889
1890 case ']':
1891 case ')':
1892 if (paren_depth == 0)
1893 return 0;
1894 paren_depth--;
1895 lexptr++;
1896 return c;
1897
1898 case ',':
1899 if (comma_terminates
1900 && paren_depth == 0
1901 && ! scanning_macro_expansion ())
1902 return 0;
1903 lexptr++;
1904 return c;
1905
1906 case '.':
1907 /* Might be a floating point number. */
1908 if (lexptr[1] < '0' || lexptr[1] > '9')
1909 {
1910 if (in_parse_field)
1911 last_was_structop = 1;
1912 goto symbol; /* Nope, must be a symbol. */
1913 }
1914 /* FALL THRU into number case. */
1915
1916 case '0':
1917 case '1':
1918 case '2':
1919 case '3':
1920 case '4':
1921 case '5':
1922 case '6':
1923 case '7':
1924 case '8':
1925 case '9':
1926 {
1927 /* It's a number. */
1928 int got_dot = 0, got_e = 0, toktype;
1929 char *p = tokstart;
1930 int hex = input_radix > 10;
1931
1932 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1933 {
1934 p += 2;
1935 hex = 1;
1936 }
1937 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
1938 {
1939 p += 2;
1940 hex = 0;
1941 }
1942
1943 for (;; ++p)
1944 {
1945 /* This test includes !hex because 'e' is a valid hex digit
1946 and thus does not indicate a floating point number when
1947 the radix is hex. */
1948 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1949 got_dot = got_e = 1;
1950 /* This test does not include !hex, because a '.' always indicates
1951 a decimal floating point number regardless of the radix. */
1952 else if (!got_dot && *p == '.')
1953 got_dot = 1;
1954 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
1955 && (*p == '-' || *p == '+'))
1956 /* This is the sign of the exponent, not the end of the
1957 number. */
1958 continue;
1959 /* We will take any letters or digits. parse_number will
1960 complain if past the radix, or if L or U are not final. */
1961 else if ((*p < '0' || *p > '9')
1962 && ((*p < 'a' || *p > 'z')
1963 && (*p < 'A' || *p > 'Z')))
1964 break;
1965 }
1966 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
1967 if (toktype == ERROR)
1968 {
1969 char *err_copy = (char *) alloca (p - tokstart + 1);
1970
1971 memcpy (err_copy, tokstart, p - tokstart);
1972 err_copy[p - tokstart] = 0;
1973 error ("Invalid number \"%s\".", err_copy);
1974 }
1975 lexptr = p;
1976 return toktype;
1977 }
1978
1979 case '+':
1980 case '-':
1981 case '*':
1982 case '/':
1983 case '%':
1984 case '|':
1985 case '&':
1986 case '^':
1987 case '~':
1988 case '!':
1989 case '@':
1990 case '<':
1991 case '>':
1992 case '?':
1993 case ':':
1994 case '=':
1995 case '{':
1996 case '}':
1997 symbol:
1998 lexptr++;
1999 return c;
2000
2001 case 'L':
2002 case 'u':
2003 case 'U':
2004 if (tokstart[1] != '"' && tokstart[1] != '\'')
2005 break;
2006 /* Fall through. */
2007 case '\'':
2008 case '"':
2009 {
2010 int host_len;
2011 int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
2012 &host_len);
2013 if (result == CHAR)
2014 {
2015 if (host_len == 0)
2016 error ("Empty character constant.");
2017 else if (host_len > 2 && c == '\'')
2018 {
2019 ++tokstart;
2020 namelen = lexptr - tokstart - 1;
2021 goto tryname;
2022 }
2023 else if (host_len > 1)
2024 error ("Invalid character constant.");
2025 }
2026 return result;
2027 }
2028 }
2029
2030 if (!(c == '_' || c == '$'
2031 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2032 /* We must have come across a bad character (e.g. ';'). */
2033 error ("Invalid character '%c' in expression.", c);
2034
2035 /* It's a name. See how long it is. */
2036 namelen = 0;
2037 for (c = tokstart[namelen];
2038 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2039 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2040 {
2041 /* Template parameter lists are part of the name.
2042 FIXME: This mishandles `print $a<4&&$a>3'. */
2043
2044 if (c == '<')
2045 {
2046 /* Scan ahead to get rest of the template specification. Note
2047 that we look ahead only when the '<' adjoins non-whitespace
2048 characters; for comparison expressions, e.g. "a < b > c",
2049 there must be spaces before the '<', etc. */
2050
2051 char * p = find_template_name_end (tokstart + namelen);
2052 if (p)
2053 namelen = p - tokstart;
2054 break;
2055 }
2056 c = tokstart[++namelen];
2057 }
2058
2059 /* The token "if" terminates the expression and is NOT removed from
2060 the input stream. It doesn't count if it appears in the
2061 expansion of a macro. */
2062 if (namelen == 2
2063 && tokstart[0] == 'i'
2064 && tokstart[1] == 'f'
2065 && ! scanning_macro_expansion ())
2066 {
2067 return 0;
2068 }
2069
2070 lexptr += namelen;
2071
2072 tryname:
2073
2074 yylval.sval.ptr = tokstart;
2075 yylval.sval.length = namelen;
2076
2077 /* Catch specific keywords. */
2078 copy = copy_name (yylval.sval);
2079 for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
2080 if (strcmp (copy, ident_tokens[i].operator) == 0)
2081 {
2082 if (ident_tokens[i].cxx_only
2083 && parse_language->la_language != language_cplus)
2084 break;
2085
2086 /* It is ok to always set this, even though we don't always
2087 strictly need to. */
2088 yylval.opcode = ident_tokens[i].opcode;
2089 return ident_tokens[i].token;
2090 }
2091
2092 if (*tokstart == '$')
2093 {
2094 write_dollar_variable (yylval.sval);
2095 return VARIABLE;
2096 }
2097
2098 /* Use token-type BLOCKNAME for symbols that happen to be defined as
2099 functions or symtabs. If this is not so, then ...
2100 Use token-type TYPENAME for symbols that happen to be defined
2101 currently as names of types; NAME for other symbols.
2102 The caller is not constrained to care about the distinction. */
2103 {
2104 struct symbol *sym;
2105 int is_a_field_of_this = 0;
2106 int hextype;
2107
2108 sym = lookup_symbol (copy, expression_context_block,
2109 VAR_DOMAIN,
2110 parse_language->la_language == language_cplus
2111 ? &is_a_field_of_this : (int *) NULL);
2112 /* Call lookup_symtab, not lookup_partial_symtab, in case there are
2113 no psymtabs (coff, xcoff, or some future change to blow away the
2114 psymtabs once once symbols are read). */
2115 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2116 {
2117 yylval.ssym.sym = sym;
2118 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2119 return BLOCKNAME;
2120 }
2121 else if (!sym)
2122 { /* See if it's a file name. */
2123 struct symtab *symtab;
2124
2125 symtab = lookup_symtab (copy);
2126
2127 if (symtab)
2128 {
2129 yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
2130 return FILENAME;
2131 }
2132 }
2133
2134 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2135 {
2136 /* NOTE: carlton/2003-09-25: There used to be code here to
2137 handle nested types. It didn't work very well. See the
2138 comment before qualified_type for more info. */
2139 yylval.tsym.type = SYMBOL_TYPE (sym);
2140 return TYPENAME;
2141 }
2142 yylval.tsym.type
2143 = language_lookup_primitive_type_by_name (parse_language,
2144 parse_gdbarch, copy);
2145 if (yylval.tsym.type != NULL)
2146 return TYPENAME;
2147
2148 /* Input names that aren't symbols but ARE valid hex numbers,
2149 when the input radix permits them, can be names or numbers
2150 depending on the parse. Note we support radixes > 16 here. */
2151 if (!sym &&
2152 ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
2153 (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
2154 {
2155 YYSTYPE newlval; /* Its value is ignored. */
2156 hextype = parse_number (tokstart, namelen, 0, &newlval);
2157 if (hextype == INT)
2158 {
2159 yylval.ssym.sym = sym;
2160 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2161 return NAME_OR_INT;
2162 }
2163 }
2164
2165 /* Any other kind of symbol */
2166 yylval.ssym.sym = sym;
2167 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2168 if (in_parse_field && *lexptr == '\0')
2169 saw_name_at_eof = 1;
2170 return NAME;
2171 }
2172 }
2173
2174 int
2175 c_parse (void)
2176 {
2177 int result;
2178 struct cleanup *back_to = make_cleanup (free_current_contents,
2179 &expression_macro_scope);
2180
2181 /* Set up the scope for macro expansion. */
2182 expression_macro_scope = NULL;
2183
2184 if (expression_context_block)
2185 expression_macro_scope
2186 = sal_macro_scope (find_pc_line (expression_context_pc, 0));
2187 else
2188 expression_macro_scope = default_macro_scope ();
2189 if (! expression_macro_scope)
2190 expression_macro_scope = user_macro_scope ();
2191
2192 /* Initialize macro expansion code. */
2193 obstack_init (&expansion_obstack);
2194 gdb_assert (! macro_original_text);
2195 make_cleanup (scan_macro_cleanup, 0);
2196
2197 /* Initialize some state used by the lexer. */
2198 last_was_structop = 0;
2199 saw_name_at_eof = 0;
2200
2201 result = yyparse ();
2202 do_cleanups (back_to);
2203 return result;
2204 }
2205
2206
2207 void
2208 yyerror (char *msg)
2209 {
2210 if (prev_lexptr)
2211 lexptr = prev_lexptr;
2212
2213 error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
2214 }
This page took 0.074643 seconds and 5 git commands to generate.