libiberty/md5: fix strict alias warnings
[deliverable/binutils-gdb.git] / gdb / c-exp.y
1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986, 1989-2000, 2003-2004, 2006-2012 Free Software
3 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 3 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, see <http://www.gnu.org/licenses/>. */
19
20 /* Parse a C expression from text in a string,
21 and return the result as a struct expression pointer.
22 That structure contains arithmetic operations in reverse polish,
23 with constants represented by operations that are followed by special data.
24 See expression.h for the details of the format.
25 What is important here is that it can be built up sequentially
26 during the process of parsing; the lower levels of the tree always
27 come first in the result.
28
29 Note that malloc's and realloc's in this file are transformed to
30 xmalloc and xrealloc respectively by the same sed command in the
31 makefile that remaps any other malloc/realloc inserted by the parser
32 generator. Doing this with #defines and trying to control the interaction
33 with include files (<malloc.h> and <stdlib.h> for example) just became
34 too messy, particularly when such includes can be inserted at random
35 times by the parser generator. */
36
37 %{
38
39 #include "defs.h"
40 #include "gdb_string.h"
41 #include <ctype.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 #include "charset.h"
51 #include "block.h"
52 #include "cp-support.h"
53 #include "dfp.h"
54 #include "gdb_assert.h"
55 #include "macroscope.h"
56 #include "objc-lang.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 #define yyss c_yyss
108 #define yysslim c_yysslim
109 #define yyssp c_yyssp
110 #define yystacksize c_yystacksize
111 #define yyvs c_yyvs
112 #define yyvsp c_yyvsp
113
114 #ifndef YYDEBUG
115 #define YYDEBUG 1 /* Default to yydebug support */
116 #endif
117
118 #define YYFPRINTF parser_fprintf
119
120 int yyparse (void);
121
122 static int yylex (void);
123
124 void yyerror (char *);
125
126 %}
127
128 /* Although the yacc "value" of an expression is not used,
129 since the result is stored in the structure being created,
130 other node types do have values. */
131
132 %union
133 {
134 LONGEST lval;
135 struct {
136 LONGEST val;
137 struct type *type;
138 } typed_val_int;
139 struct {
140 DOUBLEST dval;
141 struct type *type;
142 } typed_val_float;
143 struct {
144 gdb_byte val[16];
145 struct type *type;
146 } typed_val_decfloat;
147 struct symbol *sym;
148 struct type *tval;
149 struct stoken sval;
150 struct typed_stoken tsval;
151 struct ttype tsym;
152 struct symtoken ssym;
153 int voidval;
154 struct block *bval;
155 enum exp_opcode opcode;
156 struct internalvar *ivar;
157
158 struct stoken_vector svec;
159 VEC (type_ptr) *tvec;
160 int *ivec;
161
162 struct type_stack *type_stack;
163
164 struct objc_class_str class;
165 }
166
167 %{
168 /* YYSTYPE gets defined by %union */
169 static int parse_number (char *, int, int, YYSTYPE *);
170 static struct stoken operator_stoken (const char *);
171 static void check_parameter_typelist (VEC (type_ptr) *);
172 %}
173
174 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
175 %type <lval> rcurly
176 %type <tval> type typebase
177 %type <tvec> nonempty_typelist func_mod parameter_typelist
178 /* %type <bval> block */
179
180 /* Fancy type parsing. */
181 %type <tval> ptype
182 %type <lval> array_mod
183 %type <tval> conversion_type_id
184
185 %type <type_stack> ptr_operator_ts abs_decl direct_abs_decl
186
187 %token <typed_val_int> INT
188 %token <typed_val_float> FLOAT
189 %token <typed_val_decfloat> DECFLOAT
190
191 /* Both NAME and TYPENAME tokens represent symbols in the input,
192 and both convey their data as strings.
193 But a TYPENAME is a string that happens to be defined as a typedef
194 or builtin type name (such as int or char)
195 and a NAME is any other symbol.
196 Contexts where this distinction is not important can use the
197 nonterminal "name", which matches either NAME or TYPENAME. */
198
199 %token <tsval> STRING
200 %token <sval> NSSTRING /* ObjC Foundation "NSString" literal */
201 %token SELECTOR /* ObjC "@selector" pseudo-operator */
202 %token <tsval> CHAR
203 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
204 %token <ssym> UNKNOWN_CPP_NAME
205 %token <voidval> COMPLETE
206 %token <tsym> TYPENAME
207 %token <class> CLASSNAME /* ObjC Class name */
208 %type <sval> name
209 %type <svec> string_exp
210 %type <ssym> name_not_typename
211 %type <tsym> typename
212
213 /* This is like a '[' token, but is only generated when parsing
214 Objective C. This lets us reuse the same parser without
215 erroneously parsing ObjC-specific expressions in C. */
216 %token OBJC_LBRAC
217
218 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
219 but which would parse as a valid number in the current input radix.
220 E.g. "c" when input_radix==16. Depending on the parse, it will be
221 turned into a name or into a number. */
222
223 %token <ssym> NAME_OR_INT
224
225 %token OPERATOR
226 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
227 %token TEMPLATE
228 %token ERROR
229 %token NEW DELETE
230 %type <sval> operator
231 %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
232 %token ENTRY
233 %token TYPEOF
234 %token DECLTYPE
235
236 /* Special type cases, put in to allow the parser to distinguish different
237 legal basetypes. */
238 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
239
240 %token <sval> VARIABLE
241
242 %token <opcode> ASSIGN_MODIFY
243
244 /* C++ */
245 %token TRUEKEYWORD
246 %token FALSEKEYWORD
247
248
249 %left ','
250 %left ABOVE_COMMA
251 %right '=' ASSIGN_MODIFY
252 %right '?'
253 %left OROR
254 %left ANDAND
255 %left '|'
256 %left '^'
257 %left '&'
258 %left EQUAL NOTEQUAL
259 %left '<' '>' LEQ GEQ
260 %left LSH RSH
261 %left '@'
262 %left '+' '-'
263 %left '*' '/' '%'
264 %right UNARY INCREMENT DECREMENT
265 %right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '('
266 %token <ssym> BLOCKNAME
267 %token <bval> FILENAME
268 %type <bval> block
269 %left COLONCOLON
270
271 %token DOTDOTDOT
272
273 \f
274 %%
275
276 start : exp1
277 | type_exp
278 ;
279
280 type_exp: type
281 { write_exp_elt_opcode(OP_TYPE);
282 write_exp_elt_type($1);
283 write_exp_elt_opcode(OP_TYPE);}
284 | TYPEOF '(' exp ')'
285 {
286 write_exp_elt_opcode (OP_TYPEOF);
287 }
288 | TYPEOF '(' type ')'
289 {
290 write_exp_elt_opcode (OP_TYPE);
291 write_exp_elt_type ($3);
292 write_exp_elt_opcode (OP_TYPE);
293 }
294 | DECLTYPE '(' exp ')'
295 {
296 write_exp_elt_opcode (OP_DECLTYPE);
297 }
298 ;
299
300 /* Expressions, including the comma operator. */
301 exp1 : exp
302 | exp1 ',' exp
303 { write_exp_elt_opcode (BINOP_COMMA); }
304 ;
305
306 /* Expressions, not including the comma operator. */
307 exp : '*' exp %prec UNARY
308 { write_exp_elt_opcode (UNOP_IND); }
309 ;
310
311 exp : '&' exp %prec UNARY
312 { write_exp_elt_opcode (UNOP_ADDR); }
313 ;
314
315 exp : '-' exp %prec UNARY
316 { write_exp_elt_opcode (UNOP_NEG); }
317 ;
318
319 exp : '+' exp %prec UNARY
320 { write_exp_elt_opcode (UNOP_PLUS); }
321 ;
322
323 exp : '!' exp %prec UNARY
324 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
325 ;
326
327 exp : '~' exp %prec UNARY
328 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
329 ;
330
331 exp : INCREMENT exp %prec UNARY
332 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
333 ;
334
335 exp : DECREMENT exp %prec UNARY
336 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
337 ;
338
339 exp : exp INCREMENT %prec UNARY
340 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
341 ;
342
343 exp : exp DECREMENT %prec UNARY
344 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
345 ;
346
347 exp : SIZEOF exp %prec UNARY
348 { write_exp_elt_opcode (UNOP_SIZEOF); }
349 ;
350
351 exp : exp ARROW name
352 { write_exp_elt_opcode (STRUCTOP_PTR);
353 write_exp_string ($3);
354 write_exp_elt_opcode (STRUCTOP_PTR); }
355 ;
356
357 exp : exp ARROW name COMPLETE
358 { mark_struct_expression ();
359 write_exp_elt_opcode (STRUCTOP_PTR);
360 write_exp_string ($3);
361 write_exp_elt_opcode (STRUCTOP_PTR); }
362 ;
363
364 exp : exp ARROW COMPLETE
365 { struct stoken s;
366 mark_struct_expression ();
367 write_exp_elt_opcode (STRUCTOP_PTR);
368 s.ptr = "";
369 s.length = 0;
370 write_exp_string (s);
371 write_exp_elt_opcode (STRUCTOP_PTR); }
372 ;
373
374 exp : exp ARROW qualified_name
375 { /* exp->type::name becomes exp->*(&type::name) */
376 /* Note: this doesn't work if name is a
377 static member! FIXME */
378 write_exp_elt_opcode (UNOP_ADDR);
379 write_exp_elt_opcode (STRUCTOP_MPTR); }
380 ;
381
382 exp : exp ARROW_STAR exp
383 { write_exp_elt_opcode (STRUCTOP_MPTR); }
384 ;
385
386 exp : exp '.' name
387 { write_exp_elt_opcode (STRUCTOP_STRUCT);
388 write_exp_string ($3);
389 write_exp_elt_opcode (STRUCTOP_STRUCT); }
390 ;
391
392 exp : exp '.' name COMPLETE
393 { mark_struct_expression ();
394 write_exp_elt_opcode (STRUCTOP_STRUCT);
395 write_exp_string ($3);
396 write_exp_elt_opcode (STRUCTOP_STRUCT); }
397 ;
398
399 exp : exp '.' COMPLETE
400 { struct stoken s;
401 mark_struct_expression ();
402 write_exp_elt_opcode (STRUCTOP_STRUCT);
403 s.ptr = "";
404 s.length = 0;
405 write_exp_string (s);
406 write_exp_elt_opcode (STRUCTOP_STRUCT); }
407 ;
408
409 exp : exp '.' qualified_name
410 { /* exp.type::name becomes exp.*(&type::name) */
411 /* Note: this doesn't work if name is a
412 static member! FIXME */
413 write_exp_elt_opcode (UNOP_ADDR);
414 write_exp_elt_opcode (STRUCTOP_MEMBER); }
415 ;
416
417 exp : exp DOT_STAR exp
418 { write_exp_elt_opcode (STRUCTOP_MEMBER); }
419 ;
420
421 exp : exp '[' exp1 ']'
422 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
423 ;
424
425 exp : exp OBJC_LBRAC exp1 ']'
426 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
427 ;
428
429 /*
430 * The rules below parse ObjC message calls of the form:
431 * '[' target selector {':' argument}* ']'
432 */
433
434 exp : OBJC_LBRAC TYPENAME
435 {
436 CORE_ADDR class;
437
438 class = lookup_objc_class (parse_gdbarch,
439 copy_name ($2.stoken));
440 if (class == 0)
441 error (_("%s is not an ObjC Class"),
442 copy_name ($2.stoken));
443 write_exp_elt_opcode (OP_LONG);
444 write_exp_elt_type (parse_type->builtin_int);
445 write_exp_elt_longcst ((LONGEST) class);
446 write_exp_elt_opcode (OP_LONG);
447 start_msglist();
448 }
449 msglist ']'
450 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
451 end_msglist();
452 write_exp_elt_opcode (OP_OBJC_MSGCALL);
453 }
454 ;
455
456 exp : OBJC_LBRAC CLASSNAME
457 {
458 write_exp_elt_opcode (OP_LONG);
459 write_exp_elt_type (parse_type->builtin_int);
460 write_exp_elt_longcst ((LONGEST) $2.class);
461 write_exp_elt_opcode (OP_LONG);
462 start_msglist();
463 }
464 msglist ']'
465 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
466 end_msglist();
467 write_exp_elt_opcode (OP_OBJC_MSGCALL);
468 }
469 ;
470
471 exp : OBJC_LBRAC exp
472 { start_msglist(); }
473 msglist ']'
474 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
475 end_msglist();
476 write_exp_elt_opcode (OP_OBJC_MSGCALL);
477 }
478 ;
479
480 msglist : name
481 { add_msglist(&$1, 0); }
482 | msgarglist
483 ;
484
485 msgarglist : msgarg
486 | msgarglist msgarg
487 ;
488
489 msgarg : name ':' exp
490 { add_msglist(&$1, 1); }
491 | ':' exp /* Unnamed arg. */
492 { add_msglist(0, 1); }
493 | ',' exp /* Variable number of args. */
494 { add_msglist(0, 0); }
495 ;
496
497 exp : exp '('
498 /* This is to save the value of arglist_len
499 being accumulated by an outer function call. */
500 { start_arglist (); }
501 arglist ')' %prec ARROW
502 { write_exp_elt_opcode (OP_FUNCALL);
503 write_exp_elt_longcst ((LONGEST) end_arglist ());
504 write_exp_elt_opcode (OP_FUNCALL); }
505 ;
506
507 exp : UNKNOWN_CPP_NAME '('
508 {
509 /* This could potentially be a an argument defined
510 lookup function (Koenig). */
511 write_exp_elt_opcode (OP_ADL_FUNC);
512 write_exp_elt_block (expression_context_block);
513 write_exp_elt_sym (NULL); /* Placeholder. */
514 write_exp_string ($1.stoken);
515 write_exp_elt_opcode (OP_ADL_FUNC);
516
517 /* This is to save the value of arglist_len
518 being accumulated by an outer function call. */
519
520 start_arglist ();
521 }
522 arglist ')' %prec ARROW
523 {
524 write_exp_elt_opcode (OP_FUNCALL);
525 write_exp_elt_longcst ((LONGEST) end_arglist ());
526 write_exp_elt_opcode (OP_FUNCALL);
527 }
528 ;
529
530 lcurly : '{'
531 { start_arglist (); }
532 ;
533
534 arglist :
535 ;
536
537 arglist : exp
538 { arglist_len = 1; }
539 ;
540
541 arglist : arglist ',' exp %prec ABOVE_COMMA
542 { arglist_len++; }
543 ;
544
545 exp : exp '(' parameter_typelist ')' const_or_volatile
546 { int i;
547 VEC (type_ptr) *type_list = $3;
548 struct type *type_elt;
549 LONGEST len = VEC_length (type_ptr, type_list);
550
551 write_exp_elt_opcode (TYPE_INSTANCE);
552 write_exp_elt_longcst (len);
553 for (i = 0;
554 VEC_iterate (type_ptr, type_list, i, type_elt);
555 ++i)
556 write_exp_elt_type (type_elt);
557 write_exp_elt_longcst(len);
558 write_exp_elt_opcode (TYPE_INSTANCE);
559 VEC_free (type_ptr, type_list);
560 }
561 ;
562
563 rcurly : '}'
564 { $$ = end_arglist () - 1; }
565 ;
566 exp : lcurly arglist rcurly %prec ARROW
567 { write_exp_elt_opcode (OP_ARRAY);
568 write_exp_elt_longcst ((LONGEST) 0);
569 write_exp_elt_longcst ((LONGEST) $3);
570 write_exp_elt_opcode (OP_ARRAY); }
571 ;
572
573 exp : lcurly type_exp rcurly exp %prec UNARY
574 { write_exp_elt_opcode (UNOP_MEMVAL_TYPE); }
575 ;
576
577 exp : '(' type_exp ')' exp %prec UNARY
578 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
579 ;
580
581 exp : '(' exp1 ')'
582 { }
583 ;
584
585 /* Binary operators in order of decreasing precedence. */
586
587 exp : exp '@' exp
588 { write_exp_elt_opcode (BINOP_REPEAT); }
589 ;
590
591 exp : exp '*' exp
592 { write_exp_elt_opcode (BINOP_MUL); }
593 ;
594
595 exp : exp '/' exp
596 { write_exp_elt_opcode (BINOP_DIV); }
597 ;
598
599 exp : exp '%' exp
600 { write_exp_elt_opcode (BINOP_REM); }
601 ;
602
603 exp : exp '+' exp
604 { write_exp_elt_opcode (BINOP_ADD); }
605 ;
606
607 exp : exp '-' exp
608 { write_exp_elt_opcode (BINOP_SUB); }
609 ;
610
611 exp : exp LSH exp
612 { write_exp_elt_opcode (BINOP_LSH); }
613 ;
614
615 exp : exp RSH exp
616 { write_exp_elt_opcode (BINOP_RSH); }
617 ;
618
619 exp : exp EQUAL exp
620 { write_exp_elt_opcode (BINOP_EQUAL); }
621 ;
622
623 exp : exp NOTEQUAL exp
624 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
625 ;
626
627 exp : exp LEQ exp
628 { write_exp_elt_opcode (BINOP_LEQ); }
629 ;
630
631 exp : exp GEQ exp
632 { write_exp_elt_opcode (BINOP_GEQ); }
633 ;
634
635 exp : exp '<' exp
636 { write_exp_elt_opcode (BINOP_LESS); }
637 ;
638
639 exp : exp '>' exp
640 { write_exp_elt_opcode (BINOP_GTR); }
641 ;
642
643 exp : exp '&' exp
644 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
645 ;
646
647 exp : exp '^' exp
648 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
649 ;
650
651 exp : exp '|' exp
652 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
653 ;
654
655 exp : exp ANDAND exp
656 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
657 ;
658
659 exp : exp OROR exp
660 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
661 ;
662
663 exp : exp '?' exp ':' exp %prec '?'
664 { write_exp_elt_opcode (TERNOP_COND); }
665 ;
666
667 exp : exp '=' exp
668 { write_exp_elt_opcode (BINOP_ASSIGN); }
669 ;
670
671 exp : exp ASSIGN_MODIFY exp
672 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
673 write_exp_elt_opcode ($2);
674 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
675 ;
676
677 exp : INT
678 { write_exp_elt_opcode (OP_LONG);
679 write_exp_elt_type ($1.type);
680 write_exp_elt_longcst ((LONGEST)($1.val));
681 write_exp_elt_opcode (OP_LONG); }
682 ;
683
684 exp : CHAR
685 {
686 struct stoken_vector vec;
687 vec.len = 1;
688 vec.tokens = &$1;
689 write_exp_string_vector ($1.type, &vec);
690 }
691 ;
692
693 exp : NAME_OR_INT
694 { YYSTYPE val;
695 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
696 write_exp_elt_opcode (OP_LONG);
697 write_exp_elt_type (val.typed_val_int.type);
698 write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
699 write_exp_elt_opcode (OP_LONG);
700 }
701 ;
702
703
704 exp : FLOAT
705 { write_exp_elt_opcode (OP_DOUBLE);
706 write_exp_elt_type ($1.type);
707 write_exp_elt_dblcst ($1.dval);
708 write_exp_elt_opcode (OP_DOUBLE); }
709 ;
710
711 exp : DECFLOAT
712 { write_exp_elt_opcode (OP_DECFLOAT);
713 write_exp_elt_type ($1.type);
714 write_exp_elt_decfloatcst ($1.val);
715 write_exp_elt_opcode (OP_DECFLOAT); }
716 ;
717
718 exp : variable
719 ;
720
721 exp : VARIABLE
722 {
723 write_dollar_variable ($1);
724 }
725 ;
726
727 exp : SELECTOR '(' name ')'
728 {
729 write_exp_elt_opcode (OP_OBJC_SELECTOR);
730 write_exp_string ($3);
731 write_exp_elt_opcode (OP_OBJC_SELECTOR); }
732 ;
733
734 exp : SIZEOF '(' type ')' %prec UNARY
735 { write_exp_elt_opcode (OP_LONG);
736 write_exp_elt_type (lookup_signed_typename
737 (parse_language, parse_gdbarch,
738 "int"));
739 CHECK_TYPEDEF ($3);
740 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
741 write_exp_elt_opcode (OP_LONG); }
742 ;
743
744 exp : REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
745 { write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
746 ;
747
748 exp : STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
749 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
750 ;
751
752 exp : DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
753 { write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
754 ;
755
756 exp : CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
757 { /* We could do more error checking here, but
758 it doesn't seem worthwhile. */
759 write_exp_elt_opcode (UNOP_CAST_TYPE); }
760 ;
761
762 string_exp:
763 STRING
764 {
765 /* We copy the string here, and not in the
766 lexer, to guarantee that we do not leak a
767 string. Note that we follow the
768 NUL-termination convention of the
769 lexer. */
770 struct typed_stoken *vec = XNEW (struct typed_stoken);
771 $$.len = 1;
772 $$.tokens = vec;
773
774 vec->type = $1.type;
775 vec->length = $1.length;
776 vec->ptr = malloc ($1.length + 1);
777 memcpy (vec->ptr, $1.ptr, $1.length + 1);
778 }
779
780 | string_exp STRING
781 {
782 /* Note that we NUL-terminate here, but just
783 for convenience. */
784 char *p;
785 ++$$.len;
786 $$.tokens = realloc ($$.tokens,
787 $$.len * sizeof (struct typed_stoken));
788
789 p = malloc ($2.length + 1);
790 memcpy (p, $2.ptr, $2.length + 1);
791
792 $$.tokens[$$.len - 1].type = $2.type;
793 $$.tokens[$$.len - 1].length = $2.length;
794 $$.tokens[$$.len - 1].ptr = p;
795 }
796 ;
797
798 exp : string_exp
799 {
800 int i;
801 enum c_string_type type = C_STRING;
802
803 for (i = 0; i < $1.len; ++i)
804 {
805 switch ($1.tokens[i].type)
806 {
807 case C_STRING:
808 break;
809 case C_WIDE_STRING:
810 case C_STRING_16:
811 case C_STRING_32:
812 if (type != C_STRING
813 && type != $1.tokens[i].type)
814 error (_("Undefined string concatenation."));
815 type = $1.tokens[i].type;
816 break;
817 default:
818 /* internal error */
819 internal_error (__FILE__, __LINE__,
820 "unrecognized type in string concatenation");
821 }
822 }
823
824 write_exp_string_vector (type, &$1);
825 for (i = 0; i < $1.len; ++i)
826 free ($1.tokens[i].ptr);
827 free ($1.tokens);
828 }
829 ;
830
831 exp : NSSTRING /* ObjC NextStep NSString constant
832 * of the form '@' '"' string '"'.
833 */
834 { write_exp_elt_opcode (OP_OBJC_NSSTRING);
835 write_exp_string ($1);
836 write_exp_elt_opcode (OP_OBJC_NSSTRING); }
837 ;
838
839 /* C++. */
840 exp : TRUEKEYWORD
841 { write_exp_elt_opcode (OP_LONG);
842 write_exp_elt_type (parse_type->builtin_bool);
843 write_exp_elt_longcst ((LONGEST) 1);
844 write_exp_elt_opcode (OP_LONG); }
845 ;
846
847 exp : FALSEKEYWORD
848 { write_exp_elt_opcode (OP_LONG);
849 write_exp_elt_type (parse_type->builtin_bool);
850 write_exp_elt_longcst ((LONGEST) 0);
851 write_exp_elt_opcode (OP_LONG); }
852 ;
853
854 /* end of C++. */
855
856 block : BLOCKNAME
857 {
858 if ($1.sym)
859 $$ = SYMBOL_BLOCK_VALUE ($1.sym);
860 else
861 error (_("No file or function \"%s\"."),
862 copy_name ($1.stoken));
863 }
864 | FILENAME
865 {
866 $$ = $1;
867 }
868 ;
869
870 block : block COLONCOLON name
871 { struct symbol *tem
872 = lookup_symbol (copy_name ($3), $1,
873 VAR_DOMAIN, (int *) NULL);
874 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
875 error (_("No function \"%s\" in specified context."),
876 copy_name ($3));
877 $$ = SYMBOL_BLOCK_VALUE (tem); }
878 ;
879
880 variable: name_not_typename ENTRY
881 { struct symbol *sym = $1.sym;
882
883 if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
884 || !symbol_read_needs_frame (sym))
885 error (_("@entry can be used only for function "
886 "parameters, not for \"%s\""),
887 copy_name ($1.stoken));
888
889 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
890 write_exp_elt_sym (sym);
891 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
892 }
893 ;
894
895 variable: block COLONCOLON name
896 { struct symbol *sym;
897 sym = lookup_symbol (copy_name ($3), $1,
898 VAR_DOMAIN, (int *) NULL);
899 if (sym == 0)
900 error (_("No symbol \"%s\" in specified context."),
901 copy_name ($3));
902 if (symbol_read_needs_frame (sym))
903 {
904 if (innermost_block == 0
905 || contained_in (block_found,
906 innermost_block))
907 innermost_block = block_found;
908 }
909
910 write_exp_elt_opcode (OP_VAR_VALUE);
911 /* block_found is set by lookup_symbol. */
912 write_exp_elt_block (block_found);
913 write_exp_elt_sym (sym);
914 write_exp_elt_opcode (OP_VAR_VALUE); }
915 ;
916
917 qualified_name: TYPENAME COLONCOLON name
918 {
919 struct type *type = $1.type;
920 CHECK_TYPEDEF (type);
921 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
922 && TYPE_CODE (type) != TYPE_CODE_UNION
923 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
924 error (_("`%s' is not defined as an aggregate type."),
925 TYPE_NAME (type));
926
927 write_exp_elt_opcode (OP_SCOPE);
928 write_exp_elt_type (type);
929 write_exp_string ($3);
930 write_exp_elt_opcode (OP_SCOPE);
931 }
932 | TYPENAME COLONCOLON '~' name
933 {
934 struct type *type = $1.type;
935 struct stoken tmp_token;
936 CHECK_TYPEDEF (type);
937 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
938 && TYPE_CODE (type) != TYPE_CODE_UNION
939 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
940 error (_("`%s' is not defined as an aggregate type."),
941 TYPE_NAME (type));
942
943 tmp_token.ptr = (char*) alloca ($4.length + 2);
944 tmp_token.length = $4.length + 1;
945 tmp_token.ptr[0] = '~';
946 memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
947 tmp_token.ptr[tmp_token.length] = 0;
948
949 /* Check for valid destructor name. */
950 destructor_name_p (tmp_token.ptr, $1.type);
951 write_exp_elt_opcode (OP_SCOPE);
952 write_exp_elt_type (type);
953 write_exp_string (tmp_token);
954 write_exp_elt_opcode (OP_SCOPE);
955 }
956 | TYPENAME COLONCOLON name COLONCOLON name
957 {
958 char *copy = copy_name ($3);
959 error (_("No type \"%s\" within class "
960 "or namespace \"%s\"."),
961 copy, TYPE_NAME ($1.type));
962 }
963 ;
964
965 variable: qualified_name
966 | COLONCOLON name_not_typename
967 {
968 char *name = copy_name ($2.stoken);
969 struct symbol *sym;
970 struct minimal_symbol *msymbol;
971
972 sym =
973 lookup_symbol (name, (const struct block *) NULL,
974 VAR_DOMAIN, (int *) NULL);
975 if (sym)
976 {
977 write_exp_elt_opcode (OP_VAR_VALUE);
978 write_exp_elt_block (NULL);
979 write_exp_elt_sym (sym);
980 write_exp_elt_opcode (OP_VAR_VALUE);
981 break;
982 }
983
984 msymbol = lookup_minimal_symbol (name, NULL, NULL);
985 if (msymbol != NULL)
986 write_exp_msymbol (msymbol);
987 else if (!have_full_symbols () && !have_partial_symbols ())
988 error (_("No symbol table is loaded. Use the \"file\" command."));
989 else
990 error (_("No symbol \"%s\" in current context."), name);
991 }
992 ;
993
994 variable: name_not_typename
995 { struct symbol *sym = $1.sym;
996
997 if (sym)
998 {
999 if (symbol_read_needs_frame (sym))
1000 {
1001 if (innermost_block == 0
1002 || contained_in (block_found,
1003 innermost_block))
1004 innermost_block = block_found;
1005 }
1006
1007 write_exp_elt_opcode (OP_VAR_VALUE);
1008 /* We want to use the selected frame, not
1009 another more inner frame which happens to
1010 be in the same block. */
1011 write_exp_elt_block (NULL);
1012 write_exp_elt_sym (sym);
1013 write_exp_elt_opcode (OP_VAR_VALUE);
1014 }
1015 else if ($1.is_a_field_of_this)
1016 {
1017 /* C++: it hangs off of `this'. Must
1018 not inadvertently convert from a method call
1019 to data ref. */
1020 if (innermost_block == 0
1021 || contained_in (block_found,
1022 innermost_block))
1023 innermost_block = block_found;
1024 write_exp_elt_opcode (OP_THIS);
1025 write_exp_elt_opcode (OP_THIS);
1026 write_exp_elt_opcode (STRUCTOP_PTR);
1027 write_exp_string ($1.stoken);
1028 write_exp_elt_opcode (STRUCTOP_PTR);
1029 }
1030 else
1031 {
1032 struct minimal_symbol *msymbol;
1033 char *arg = copy_name ($1.stoken);
1034
1035 msymbol =
1036 lookup_minimal_symbol (arg, NULL, NULL);
1037 if (msymbol != NULL)
1038 write_exp_msymbol (msymbol);
1039 else if (!have_full_symbols () && !have_partial_symbols ())
1040 error (_("No symbol table is loaded. Use the \"file\" command."));
1041 else
1042 error (_("No symbol \"%s\" in current context."),
1043 copy_name ($1.stoken));
1044 }
1045 }
1046 ;
1047
1048 space_identifier : '@' NAME
1049 { insert_type_address_space (copy_name ($2.stoken)); }
1050 ;
1051
1052 const_or_volatile: const_or_volatile_noopt
1053 |
1054 ;
1055
1056 cv_with_space_id : const_or_volatile space_identifier const_or_volatile
1057 ;
1058
1059 const_or_volatile_or_space_identifier_noopt: cv_with_space_id
1060 | const_or_volatile_noopt
1061 ;
1062
1063 const_or_volatile_or_space_identifier:
1064 const_or_volatile_or_space_identifier_noopt
1065 |
1066 ;
1067
1068 ptr_operator:
1069 ptr_operator '*'
1070 { insert_type (tp_pointer); }
1071 const_or_volatile_or_space_identifier
1072 | '*'
1073 { insert_type (tp_pointer); }
1074 const_or_volatile_or_space_identifier
1075 | '&'
1076 { insert_type (tp_reference); }
1077 | '&' ptr_operator
1078 { insert_type (tp_reference); }
1079 ;
1080
1081 ptr_operator_ts: ptr_operator
1082 {
1083 $$ = get_type_stack ();
1084 /* This cleanup is eventually run by
1085 c_parse. */
1086 make_cleanup (type_stack_cleanup, $$);
1087 }
1088 ;
1089
1090 abs_decl: ptr_operator_ts direct_abs_decl
1091 { $$ = append_type_stack ($2, $1); }
1092 | ptr_operator_ts
1093 | direct_abs_decl
1094 ;
1095
1096 direct_abs_decl: '(' abs_decl ')'
1097 { $$ = $2; }
1098 | direct_abs_decl array_mod
1099 {
1100 push_type_stack ($1);
1101 push_type_int ($2);
1102 push_type (tp_array);
1103 $$ = get_type_stack ();
1104 }
1105 | array_mod
1106 {
1107 push_type_int ($1);
1108 push_type (tp_array);
1109 $$ = get_type_stack ();
1110 }
1111
1112 | direct_abs_decl func_mod
1113 {
1114 push_type_stack ($1);
1115 push_typelist ($2);
1116 $$ = get_type_stack ();
1117 }
1118 | func_mod
1119 {
1120 push_typelist ($1);
1121 $$ = get_type_stack ();
1122 }
1123 ;
1124
1125 array_mod: '[' ']'
1126 { $$ = -1; }
1127 | OBJC_LBRAC ']'
1128 { $$ = -1; }
1129 | '[' INT ']'
1130 { $$ = $2.val; }
1131 | OBJC_LBRAC INT ']'
1132 { $$ = $2.val; }
1133 ;
1134
1135 func_mod: '(' ')'
1136 { $$ = NULL; }
1137 | '(' parameter_typelist ')'
1138 { $$ = $2; }
1139 ;
1140
1141 /* We used to try to recognize pointer to member types here, but
1142 that didn't work (shift/reduce conflicts meant that these rules never
1143 got executed). The problem is that
1144 int (foo::bar::baz::bizzle)
1145 is a function type but
1146 int (foo::bar::baz::bizzle::*)
1147 is a pointer to member type. Stroustrup loses again! */
1148
1149 type : ptype
1150 ;
1151
1152 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
1153 : TYPENAME
1154 { $$ = $1.type; }
1155 | INT_KEYWORD
1156 { $$ = lookup_signed_typename (parse_language,
1157 parse_gdbarch,
1158 "int"); }
1159 | LONG
1160 { $$ = lookup_signed_typename (parse_language,
1161 parse_gdbarch,
1162 "long"); }
1163 | SHORT
1164 { $$ = lookup_signed_typename (parse_language,
1165 parse_gdbarch,
1166 "short"); }
1167 | LONG INT_KEYWORD
1168 { $$ = lookup_signed_typename (parse_language,
1169 parse_gdbarch,
1170 "long"); }
1171 | LONG SIGNED_KEYWORD INT_KEYWORD
1172 { $$ = lookup_signed_typename (parse_language,
1173 parse_gdbarch,
1174 "long"); }
1175 | LONG SIGNED_KEYWORD
1176 { $$ = lookup_signed_typename (parse_language,
1177 parse_gdbarch,
1178 "long"); }
1179 | SIGNED_KEYWORD LONG INT_KEYWORD
1180 { $$ = lookup_signed_typename (parse_language,
1181 parse_gdbarch,
1182 "long"); }
1183 | UNSIGNED LONG INT_KEYWORD
1184 { $$ = lookup_unsigned_typename (parse_language,
1185 parse_gdbarch,
1186 "long"); }
1187 | LONG UNSIGNED INT_KEYWORD
1188 { $$ = lookup_unsigned_typename (parse_language,
1189 parse_gdbarch,
1190 "long"); }
1191 | LONG UNSIGNED
1192 { $$ = lookup_unsigned_typename (parse_language,
1193 parse_gdbarch,
1194 "long"); }
1195 | LONG LONG
1196 { $$ = lookup_signed_typename (parse_language,
1197 parse_gdbarch,
1198 "long long"); }
1199 | LONG LONG INT_KEYWORD
1200 { $$ = lookup_signed_typename (parse_language,
1201 parse_gdbarch,
1202 "long long"); }
1203 | LONG LONG SIGNED_KEYWORD INT_KEYWORD
1204 { $$ = lookup_signed_typename (parse_language,
1205 parse_gdbarch,
1206 "long long"); }
1207 | LONG LONG SIGNED_KEYWORD
1208 { $$ = lookup_signed_typename (parse_language,
1209 parse_gdbarch,
1210 "long long"); }
1211 | SIGNED_KEYWORD LONG LONG
1212 { $$ = lookup_signed_typename (parse_language,
1213 parse_gdbarch,
1214 "long long"); }
1215 | SIGNED_KEYWORD LONG LONG INT_KEYWORD
1216 { $$ = lookup_signed_typename (parse_language,
1217 parse_gdbarch,
1218 "long long"); }
1219 | UNSIGNED LONG LONG
1220 { $$ = lookup_unsigned_typename (parse_language,
1221 parse_gdbarch,
1222 "long long"); }
1223 | UNSIGNED LONG LONG INT_KEYWORD
1224 { $$ = lookup_unsigned_typename (parse_language,
1225 parse_gdbarch,
1226 "long long"); }
1227 | LONG LONG UNSIGNED
1228 { $$ = lookup_unsigned_typename (parse_language,
1229 parse_gdbarch,
1230 "long long"); }
1231 | LONG LONG UNSIGNED INT_KEYWORD
1232 { $$ = lookup_unsigned_typename (parse_language,
1233 parse_gdbarch,
1234 "long long"); }
1235 | SHORT INT_KEYWORD
1236 { $$ = lookup_signed_typename (parse_language,
1237 parse_gdbarch,
1238 "short"); }
1239 | SHORT SIGNED_KEYWORD INT_KEYWORD
1240 { $$ = lookup_signed_typename (parse_language,
1241 parse_gdbarch,
1242 "short"); }
1243 | SHORT SIGNED_KEYWORD
1244 { $$ = lookup_signed_typename (parse_language,
1245 parse_gdbarch,
1246 "short"); }
1247 | UNSIGNED SHORT INT_KEYWORD
1248 { $$ = lookup_unsigned_typename (parse_language,
1249 parse_gdbarch,
1250 "short"); }
1251 | SHORT UNSIGNED
1252 { $$ = lookup_unsigned_typename (parse_language,
1253 parse_gdbarch,
1254 "short"); }
1255 | SHORT UNSIGNED INT_KEYWORD
1256 { $$ = lookup_unsigned_typename (parse_language,
1257 parse_gdbarch,
1258 "short"); }
1259 | DOUBLE_KEYWORD
1260 { $$ = lookup_typename (parse_language, parse_gdbarch,
1261 "double", (struct block *) NULL,
1262 0); }
1263 | LONG DOUBLE_KEYWORD
1264 { $$ = lookup_typename (parse_language, parse_gdbarch,
1265 "long double",
1266 (struct block *) NULL, 0); }
1267 | STRUCT name
1268 { $$ = lookup_struct (copy_name ($2),
1269 expression_context_block); }
1270 | CLASS name
1271 { $$ = lookup_struct (copy_name ($2),
1272 expression_context_block); }
1273 | UNION name
1274 { $$ = lookup_union (copy_name ($2),
1275 expression_context_block); }
1276 | ENUM name
1277 { $$ = lookup_enum (copy_name ($2),
1278 expression_context_block); }
1279 | UNSIGNED typename
1280 { $$ = lookup_unsigned_typename (parse_language,
1281 parse_gdbarch,
1282 TYPE_NAME($2.type)); }
1283 | UNSIGNED
1284 { $$ = lookup_unsigned_typename (parse_language,
1285 parse_gdbarch,
1286 "int"); }
1287 | SIGNED_KEYWORD typename
1288 { $$ = lookup_signed_typename (parse_language,
1289 parse_gdbarch,
1290 TYPE_NAME($2.type)); }
1291 | SIGNED_KEYWORD
1292 { $$ = lookup_signed_typename (parse_language,
1293 parse_gdbarch,
1294 "int"); }
1295 /* It appears that this rule for templates is never
1296 reduced; template recognition happens by lookahead
1297 in the token processing code in yylex. */
1298 | TEMPLATE name '<' type '>'
1299 { $$ = lookup_template_type(copy_name($2), $4,
1300 expression_context_block);
1301 }
1302 | const_or_volatile_or_space_identifier_noopt typebase
1303 { $$ = follow_types ($2); }
1304 | typebase const_or_volatile_or_space_identifier_noopt
1305 { $$ = follow_types ($1); }
1306 ;
1307
1308 typename: TYPENAME
1309 | INT_KEYWORD
1310 {
1311 $$.stoken.ptr = "int";
1312 $$.stoken.length = 3;
1313 $$.type = lookup_signed_typename (parse_language,
1314 parse_gdbarch,
1315 "int");
1316 }
1317 | LONG
1318 {
1319 $$.stoken.ptr = "long";
1320 $$.stoken.length = 4;
1321 $$.type = lookup_signed_typename (parse_language,
1322 parse_gdbarch,
1323 "long");
1324 }
1325 | SHORT
1326 {
1327 $$.stoken.ptr = "short";
1328 $$.stoken.length = 5;
1329 $$.type = lookup_signed_typename (parse_language,
1330 parse_gdbarch,
1331 "short");
1332 }
1333 ;
1334
1335 parameter_typelist:
1336 nonempty_typelist
1337 { check_parameter_typelist ($1); }
1338 | nonempty_typelist ',' DOTDOTDOT
1339 {
1340 VEC_safe_push (type_ptr, $1, NULL);
1341 check_parameter_typelist ($1);
1342 $$ = $1;
1343 }
1344 ;
1345
1346 nonempty_typelist
1347 : type
1348 {
1349 VEC (type_ptr) *typelist = NULL;
1350 VEC_safe_push (type_ptr, typelist, $1);
1351 $$ = typelist;
1352 }
1353 | nonempty_typelist ',' type
1354 {
1355 VEC_safe_push (type_ptr, $1, $3);
1356 $$ = $1;
1357 }
1358 ;
1359
1360 ptype : typebase
1361 | ptype abs_decl
1362 {
1363 push_type_stack ($2);
1364 $$ = follow_types ($1);
1365 }
1366 ;
1367
1368 conversion_type_id: typebase conversion_declarator
1369 { $$ = follow_types ($1); }
1370 ;
1371
1372 conversion_declarator: /* Nothing. */
1373 | ptr_operator conversion_declarator
1374 ;
1375
1376 const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
1377 | VOLATILE_KEYWORD CONST_KEYWORD
1378 ;
1379
1380 const_or_volatile_noopt: const_and_volatile
1381 { insert_type (tp_const);
1382 insert_type (tp_volatile);
1383 }
1384 | CONST_KEYWORD
1385 { insert_type (tp_const); }
1386 | VOLATILE_KEYWORD
1387 { insert_type (tp_volatile); }
1388 ;
1389
1390 operator: OPERATOR NEW
1391 { $$ = operator_stoken (" new"); }
1392 | OPERATOR DELETE
1393 { $$ = operator_stoken (" delete"); }
1394 | OPERATOR NEW '[' ']'
1395 { $$ = operator_stoken (" new[]"); }
1396 | OPERATOR DELETE '[' ']'
1397 { $$ = operator_stoken (" delete[]"); }
1398 | OPERATOR NEW OBJC_LBRAC ']'
1399 { $$ = operator_stoken (" new[]"); }
1400 | OPERATOR DELETE OBJC_LBRAC ']'
1401 { $$ = operator_stoken (" delete[]"); }
1402 | OPERATOR '+'
1403 { $$ = operator_stoken ("+"); }
1404 | OPERATOR '-'
1405 { $$ = operator_stoken ("-"); }
1406 | OPERATOR '*'
1407 { $$ = operator_stoken ("*"); }
1408 | OPERATOR '/'
1409 { $$ = operator_stoken ("/"); }
1410 | OPERATOR '%'
1411 { $$ = operator_stoken ("%"); }
1412 | OPERATOR '^'
1413 { $$ = operator_stoken ("^"); }
1414 | OPERATOR '&'
1415 { $$ = operator_stoken ("&"); }
1416 | OPERATOR '|'
1417 { $$ = operator_stoken ("|"); }
1418 | OPERATOR '~'
1419 { $$ = operator_stoken ("~"); }
1420 | OPERATOR '!'
1421 { $$ = operator_stoken ("!"); }
1422 | OPERATOR '='
1423 { $$ = operator_stoken ("="); }
1424 | OPERATOR '<'
1425 { $$ = operator_stoken ("<"); }
1426 | OPERATOR '>'
1427 { $$ = operator_stoken (">"); }
1428 | OPERATOR ASSIGN_MODIFY
1429 { const char *op = "unknown";
1430 switch ($2)
1431 {
1432 case BINOP_RSH:
1433 op = ">>=";
1434 break;
1435 case BINOP_LSH:
1436 op = "<<=";
1437 break;
1438 case BINOP_ADD:
1439 op = "+=";
1440 break;
1441 case BINOP_SUB:
1442 op = "-=";
1443 break;
1444 case BINOP_MUL:
1445 op = "*=";
1446 break;
1447 case BINOP_DIV:
1448 op = "/=";
1449 break;
1450 case BINOP_REM:
1451 op = "%=";
1452 break;
1453 case BINOP_BITWISE_IOR:
1454 op = "|=";
1455 break;
1456 case BINOP_BITWISE_AND:
1457 op = "&=";
1458 break;
1459 case BINOP_BITWISE_XOR:
1460 op = "^=";
1461 break;
1462 default:
1463 break;
1464 }
1465
1466 $$ = operator_stoken (op);
1467 }
1468 | OPERATOR LSH
1469 { $$ = operator_stoken ("<<"); }
1470 | OPERATOR RSH
1471 { $$ = operator_stoken (">>"); }
1472 | OPERATOR EQUAL
1473 { $$ = operator_stoken ("=="); }
1474 | OPERATOR NOTEQUAL
1475 { $$ = operator_stoken ("!="); }
1476 | OPERATOR LEQ
1477 { $$ = operator_stoken ("<="); }
1478 | OPERATOR GEQ
1479 { $$ = operator_stoken (">="); }
1480 | OPERATOR ANDAND
1481 { $$ = operator_stoken ("&&"); }
1482 | OPERATOR OROR
1483 { $$ = operator_stoken ("||"); }
1484 | OPERATOR INCREMENT
1485 { $$ = operator_stoken ("++"); }
1486 | OPERATOR DECREMENT
1487 { $$ = operator_stoken ("--"); }
1488 | OPERATOR ','
1489 { $$ = operator_stoken (","); }
1490 | OPERATOR ARROW_STAR
1491 { $$ = operator_stoken ("->*"); }
1492 | OPERATOR ARROW
1493 { $$ = operator_stoken ("->"); }
1494 | OPERATOR '(' ')'
1495 { $$ = operator_stoken ("()"); }
1496 | OPERATOR '[' ']'
1497 { $$ = operator_stoken ("[]"); }
1498 | OPERATOR OBJC_LBRAC ']'
1499 { $$ = operator_stoken ("[]"); }
1500 | OPERATOR conversion_type_id
1501 { char *name;
1502 long length;
1503 struct ui_file *buf = mem_fileopen ();
1504
1505 c_print_type ($2, NULL, buf, -1, 0);
1506 name = ui_file_xstrdup (buf, &length);
1507 ui_file_delete (buf);
1508 $$ = operator_stoken (name);
1509 free (name);
1510 }
1511 ;
1512
1513
1514
1515 name : NAME { $$ = $1.stoken; }
1516 | BLOCKNAME { $$ = $1.stoken; }
1517 | TYPENAME { $$ = $1.stoken; }
1518 | NAME_OR_INT { $$ = $1.stoken; }
1519 | UNKNOWN_CPP_NAME { $$ = $1.stoken; }
1520 | operator { $$ = $1; }
1521 ;
1522
1523 name_not_typename : NAME
1524 | BLOCKNAME
1525 /* These would be useful if name_not_typename was useful, but it is just
1526 a fake for "variable", so these cause reduce/reduce conflicts because
1527 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1528 =exp) or just an exp. If name_not_typename was ever used in an lvalue
1529 context where only a name could occur, this might be useful.
1530 | NAME_OR_INT
1531 */
1532 | operator
1533 {
1534 $$.stoken = $1;
1535 $$.sym = lookup_symbol ($1.ptr,
1536 expression_context_block,
1537 VAR_DOMAIN,
1538 &$$.is_a_field_of_this);
1539 }
1540 | UNKNOWN_CPP_NAME
1541 ;
1542
1543 %%
1544
1545 /* Returns a stoken of the operator name given by OP (which does not
1546 include the string "operator"). */
1547 static struct stoken
1548 operator_stoken (const char *op)
1549 {
1550 static const char *operator_string = "operator";
1551 struct stoken st = { NULL, 0 };
1552 st.length = strlen (operator_string) + strlen (op);
1553 st.ptr = malloc (st.length + 1);
1554 strcpy (st.ptr, operator_string);
1555 strcat (st.ptr, op);
1556
1557 /* The toplevel (c_parse) will free the memory allocated here. */
1558 make_cleanup (free, st.ptr);
1559 return st;
1560 };
1561
1562 /* Validate a parameter typelist. */
1563
1564 static void
1565 check_parameter_typelist (VEC (type_ptr) *params)
1566 {
1567 struct type *type;
1568 int ix;
1569
1570 for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix)
1571 {
1572 if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
1573 {
1574 if (ix == 0)
1575 {
1576 if (VEC_length (type_ptr, params) == 1)
1577 {
1578 /* Ok. */
1579 break;
1580 }
1581 VEC_free (type_ptr, params);
1582 error (_("parameter types following 'void'"));
1583 }
1584 else
1585 {
1586 VEC_free (type_ptr, params);
1587 error (_("'void' invalid as parameter type"));
1588 }
1589 }
1590 }
1591 }
1592
1593 /* Take care of parsing a number (anything that starts with a digit).
1594 Set yylval and return the token type; update lexptr.
1595 LEN is the number of characters in it. */
1596
1597 /*** Needs some error checking for the float case ***/
1598
1599 static int
1600 parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
1601 {
1602 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
1603 here, and we do kind of silly things like cast to unsigned. */
1604 LONGEST n = 0;
1605 LONGEST prevn = 0;
1606 ULONGEST un;
1607
1608 int i = 0;
1609 int c;
1610 int base = input_radix;
1611 int unsigned_p = 0;
1612
1613 /* Number of "L" suffixes encountered. */
1614 int long_p = 0;
1615
1616 /* We have found a "L" or "U" suffix. */
1617 int found_suffix = 0;
1618
1619 ULONGEST high_bit;
1620 struct type *signed_type;
1621 struct type *unsigned_type;
1622
1623 if (parsed_float)
1624 {
1625 /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
1626 point. Return DECFLOAT. */
1627
1628 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
1629 {
1630 p[len - 2] = '\0';
1631 putithere->typed_val_decfloat.type
1632 = parse_type->builtin_decfloat;
1633 decimal_from_string (putithere->typed_val_decfloat.val, 4,
1634 gdbarch_byte_order (parse_gdbarch), p);
1635 p[len - 2] = 'd';
1636 return DECFLOAT;
1637 }
1638
1639 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
1640 {
1641 p[len - 2] = '\0';
1642 putithere->typed_val_decfloat.type
1643 = parse_type->builtin_decdouble;
1644 decimal_from_string (putithere->typed_val_decfloat.val, 8,
1645 gdbarch_byte_order (parse_gdbarch), p);
1646 p[len - 2] = 'd';
1647 return DECFLOAT;
1648 }
1649
1650 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
1651 {
1652 p[len - 2] = '\0';
1653 putithere->typed_val_decfloat.type
1654 = parse_type->builtin_declong;
1655 decimal_from_string (putithere->typed_val_decfloat.val, 16,
1656 gdbarch_byte_order (parse_gdbarch), p);
1657 p[len - 2] = 'd';
1658 return DECFLOAT;
1659 }
1660
1661 if (! parse_c_float (parse_gdbarch, p, len,
1662 &putithere->typed_val_float.dval,
1663 &putithere->typed_val_float.type))
1664 return ERROR;
1665 return FLOAT;
1666 }
1667
1668 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1669 if (p[0] == '0')
1670 switch (p[1])
1671 {
1672 case 'x':
1673 case 'X':
1674 if (len >= 3)
1675 {
1676 p += 2;
1677 base = 16;
1678 len -= 2;
1679 }
1680 break;
1681
1682 case 'b':
1683 case 'B':
1684 if (len >= 3)
1685 {
1686 p += 2;
1687 base = 2;
1688 len -= 2;
1689 }
1690 break;
1691
1692 case 't':
1693 case 'T':
1694 case 'd':
1695 case 'D':
1696 if (len >= 3)
1697 {
1698 p += 2;
1699 base = 10;
1700 len -= 2;
1701 }
1702 break;
1703
1704 default:
1705 base = 8;
1706 break;
1707 }
1708
1709 while (len-- > 0)
1710 {
1711 c = *p++;
1712 if (c >= 'A' && c <= 'Z')
1713 c += 'a' - 'A';
1714 if (c != 'l' && c != 'u')
1715 n *= base;
1716 if (c >= '0' && c <= '9')
1717 {
1718 if (found_suffix)
1719 return ERROR;
1720 n += i = c - '0';
1721 }
1722 else
1723 {
1724 if (base > 10 && c >= 'a' && c <= 'f')
1725 {
1726 if (found_suffix)
1727 return ERROR;
1728 n += i = c - 'a' + 10;
1729 }
1730 else if (c == 'l')
1731 {
1732 ++long_p;
1733 found_suffix = 1;
1734 }
1735 else if (c == 'u')
1736 {
1737 unsigned_p = 1;
1738 found_suffix = 1;
1739 }
1740 else
1741 return ERROR; /* Char not a digit */
1742 }
1743 if (i >= base)
1744 return ERROR; /* Invalid digit in this base */
1745
1746 /* Portably test for overflow (only works for nonzero values, so make
1747 a second check for zero). FIXME: Can't we just make n and prevn
1748 unsigned and avoid this? */
1749 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1750 unsigned_p = 1; /* Try something unsigned */
1751
1752 /* Portably test for unsigned overflow.
1753 FIXME: This check is wrong; for example it doesn't find overflow
1754 on 0x123456789 when LONGEST is 32 bits. */
1755 if (c != 'l' && c != 'u' && n != 0)
1756 {
1757 if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1758 error (_("Numeric constant too large."));
1759 }
1760 prevn = n;
1761 }
1762
1763 /* An integer constant is an int, a long, or a long long. An L
1764 suffix forces it to be long; an LL suffix forces it to be long
1765 long. If not forced to a larger size, it gets the first type of
1766 the above that it fits in. To figure out whether it fits, we
1767 shift it right and see whether anything remains. Note that we
1768 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1769 operation, because many compilers will warn about such a shift
1770 (which always produces a zero result). Sometimes gdbarch_int_bit
1771 or gdbarch_long_bit will be that big, sometimes not. To deal with
1772 the case where it is we just always shift the value more than
1773 once, with fewer bits each time. */
1774
1775 un = (ULONGEST)n >> 2;
1776 if (long_p == 0
1777 && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
1778 {
1779 high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
1780
1781 /* A large decimal (not hex or octal) constant (between INT_MAX
1782 and UINT_MAX) is a long or unsigned long, according to ANSI,
1783 never an unsigned int, but this code treats it as unsigned
1784 int. This probably should be fixed. GCC gives a warning on
1785 such constants. */
1786
1787 unsigned_type = parse_type->builtin_unsigned_int;
1788 signed_type = parse_type->builtin_int;
1789 }
1790 else if (long_p <= 1
1791 && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
1792 {
1793 high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
1794 unsigned_type = parse_type->builtin_unsigned_long;
1795 signed_type = parse_type->builtin_long;
1796 }
1797 else
1798 {
1799 int shift;
1800 if (sizeof (ULONGEST) * HOST_CHAR_BIT
1801 < gdbarch_long_long_bit (parse_gdbarch))
1802 /* A long long does not fit in a LONGEST. */
1803 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
1804 else
1805 shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
1806 high_bit = (ULONGEST) 1 << shift;
1807 unsigned_type = parse_type->builtin_unsigned_long_long;
1808 signed_type = parse_type->builtin_long_long;
1809 }
1810
1811 putithere->typed_val_int.val = n;
1812
1813 /* If the high bit of the worked out type is set then this number
1814 has to be unsigned. */
1815
1816 if (unsigned_p || (n & high_bit))
1817 {
1818 putithere->typed_val_int.type = unsigned_type;
1819 }
1820 else
1821 {
1822 putithere->typed_val_int.type = signed_type;
1823 }
1824
1825 return INT;
1826 }
1827
1828 /* Temporary obstack used for holding strings. */
1829 static struct obstack tempbuf;
1830 static int tempbuf_init;
1831
1832 /* Parse a C escape sequence. The initial backslash of the sequence
1833 is at (*PTR)[-1]. *PTR will be updated to point to just after the
1834 last character of the sequence. If OUTPUT is not NULL, the
1835 translated form of the escape sequence will be written there. If
1836 OUTPUT is NULL, no output is written and the call will only affect
1837 *PTR. If an escape sequence is expressed in target bytes, then the
1838 entire sequence will simply be copied to OUTPUT. Return 1 if any
1839 character was emitted, 0 otherwise. */
1840
1841 int
1842 c_parse_escape (char **ptr, struct obstack *output)
1843 {
1844 char *tokptr = *ptr;
1845 int result = 1;
1846
1847 /* Some escape sequences undergo character set conversion. Those we
1848 translate here. */
1849 switch (*tokptr)
1850 {
1851 /* Hex escapes do not undergo character set conversion, so keep
1852 the escape sequence for later. */
1853 case 'x':
1854 if (output)
1855 obstack_grow_str (output, "\\x");
1856 ++tokptr;
1857 if (!isxdigit (*tokptr))
1858 error (_("\\x escape without a following hex digit"));
1859 while (isxdigit (*tokptr))
1860 {
1861 if (output)
1862 obstack_1grow (output, *tokptr);
1863 ++tokptr;
1864 }
1865 break;
1866
1867 /* Octal escapes do not undergo character set conversion, so
1868 keep the escape sequence for later. */
1869 case '0':
1870 case '1':
1871 case '2':
1872 case '3':
1873 case '4':
1874 case '5':
1875 case '6':
1876 case '7':
1877 {
1878 int i;
1879 if (output)
1880 obstack_grow_str (output, "\\");
1881 for (i = 0;
1882 i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
1883 ++i)
1884 {
1885 if (output)
1886 obstack_1grow (output, *tokptr);
1887 ++tokptr;
1888 }
1889 }
1890 break;
1891
1892 /* We handle UCNs later. We could handle them here, but that
1893 would mean a spurious error in the case where the UCN could
1894 be converted to the target charset but not the host
1895 charset. */
1896 case 'u':
1897 case 'U':
1898 {
1899 char c = *tokptr;
1900 int i, len = c == 'U' ? 8 : 4;
1901 if (output)
1902 {
1903 obstack_1grow (output, '\\');
1904 obstack_1grow (output, *tokptr);
1905 }
1906 ++tokptr;
1907 if (!isxdigit (*tokptr))
1908 error (_("\\%c escape without a following hex digit"), c);
1909 for (i = 0; i < len && isxdigit (*tokptr); ++i)
1910 {
1911 if (output)
1912 obstack_1grow (output, *tokptr);
1913 ++tokptr;
1914 }
1915 }
1916 break;
1917
1918 /* We must pass backslash through so that it does not
1919 cause quoting during the second expansion. */
1920 case '\\':
1921 if (output)
1922 obstack_grow_str (output, "\\\\");
1923 ++tokptr;
1924 break;
1925
1926 /* Escapes which undergo conversion. */
1927 case 'a':
1928 if (output)
1929 obstack_1grow (output, '\a');
1930 ++tokptr;
1931 break;
1932 case 'b':
1933 if (output)
1934 obstack_1grow (output, '\b');
1935 ++tokptr;
1936 break;
1937 case 'f':
1938 if (output)
1939 obstack_1grow (output, '\f');
1940 ++tokptr;
1941 break;
1942 case 'n':
1943 if (output)
1944 obstack_1grow (output, '\n');
1945 ++tokptr;
1946 break;
1947 case 'r':
1948 if (output)
1949 obstack_1grow (output, '\r');
1950 ++tokptr;
1951 break;
1952 case 't':
1953 if (output)
1954 obstack_1grow (output, '\t');
1955 ++tokptr;
1956 break;
1957 case 'v':
1958 if (output)
1959 obstack_1grow (output, '\v');
1960 ++tokptr;
1961 break;
1962
1963 /* GCC extension. */
1964 case 'e':
1965 if (output)
1966 obstack_1grow (output, HOST_ESCAPE_CHAR);
1967 ++tokptr;
1968 break;
1969
1970 /* Backslash-newline expands to nothing at all. */
1971 case '\n':
1972 ++tokptr;
1973 result = 0;
1974 break;
1975
1976 /* A few escapes just expand to the character itself. */
1977 case '\'':
1978 case '\"':
1979 case '?':
1980 /* GCC extensions. */
1981 case '(':
1982 case '{':
1983 case '[':
1984 case '%':
1985 /* Unrecognized escapes turn into the character itself. */
1986 default:
1987 if (output)
1988 obstack_1grow (output, *tokptr);
1989 ++tokptr;
1990 break;
1991 }
1992 *ptr = tokptr;
1993 return result;
1994 }
1995
1996 /* Parse a string or character literal from TOKPTR. The string or
1997 character may be wide or unicode. *OUTPTR is set to just after the
1998 end of the literal in the input string. The resulting token is
1999 stored in VALUE. This returns a token value, either STRING or
2000 CHAR, depending on what was parsed. *HOST_CHARS is set to the
2001 number of host characters in the literal. */
2002 static int
2003 parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
2004 int *host_chars)
2005 {
2006 int quote;
2007 enum c_string_type type;
2008 int is_objc = 0;
2009
2010 /* Build the gdb internal form of the input string in tempbuf. Note
2011 that the buffer is null byte terminated *only* for the
2012 convenience of debugging gdb itself and printing the buffer
2013 contents when the buffer contains no embedded nulls. Gdb does
2014 not depend upon the buffer being null byte terminated, it uses
2015 the length string instead. This allows gdb to handle C strings
2016 (as well as strings in other languages) with embedded null
2017 bytes */
2018
2019 if (!tempbuf_init)
2020 tempbuf_init = 1;
2021 else
2022 obstack_free (&tempbuf, NULL);
2023 obstack_init (&tempbuf);
2024
2025 /* Record the string type. */
2026 if (*tokptr == 'L')
2027 {
2028 type = C_WIDE_STRING;
2029 ++tokptr;
2030 }
2031 else if (*tokptr == 'u')
2032 {
2033 type = C_STRING_16;
2034 ++tokptr;
2035 }
2036 else if (*tokptr == 'U')
2037 {
2038 type = C_STRING_32;
2039 ++tokptr;
2040 }
2041 else if (*tokptr == '@')
2042 {
2043 /* An Objective C string. */
2044 is_objc = 1;
2045 type = C_STRING;
2046 ++tokptr;
2047 }
2048 else
2049 type = C_STRING;
2050
2051 /* Skip the quote. */
2052 quote = *tokptr;
2053 if (quote == '\'')
2054 type |= C_CHAR;
2055 ++tokptr;
2056
2057 *host_chars = 0;
2058
2059 while (*tokptr)
2060 {
2061 char c = *tokptr;
2062 if (c == '\\')
2063 {
2064 ++tokptr;
2065 *host_chars += c_parse_escape (&tokptr, &tempbuf);
2066 }
2067 else if (c == quote)
2068 break;
2069 else
2070 {
2071 obstack_1grow (&tempbuf, c);
2072 ++tokptr;
2073 /* FIXME: this does the wrong thing with multi-byte host
2074 characters. We could use mbrlen here, but that would
2075 make "set host-charset" a bit less useful. */
2076 ++*host_chars;
2077 }
2078 }
2079
2080 if (*tokptr != quote)
2081 {
2082 if (quote == '"')
2083 error (_("Unterminated string in expression."));
2084 else
2085 error (_("Unmatched single quote."));
2086 }
2087 ++tokptr;
2088
2089 value->type = type;
2090 value->ptr = obstack_base (&tempbuf);
2091 value->length = obstack_object_size (&tempbuf);
2092
2093 *outptr = tokptr;
2094
2095 return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR;
2096 }
2097
2098 /* This is used to associate some attributes with a token. */
2099
2100 enum token_flags
2101 {
2102 /* If this bit is set, the token is C++-only. */
2103
2104 FLAG_CXX = 1,
2105
2106 /* If this bit is set, the token is conditional: if there is a
2107 symbol of the same name, then the token is a symbol; otherwise,
2108 the token is a keyword. */
2109
2110 FLAG_SHADOW = 2
2111 };
2112
2113 struct token
2114 {
2115 char *operator;
2116 int token;
2117 enum exp_opcode opcode;
2118 enum token_flags flags;
2119 };
2120
2121 static const struct token tokentab3[] =
2122 {
2123 {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
2124 {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
2125 {"->*", ARROW_STAR, BINOP_END, FLAG_CXX},
2126 {"...", DOTDOTDOT, BINOP_END, 0}
2127 };
2128
2129 static const struct token tokentab2[] =
2130 {
2131 {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
2132 {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
2133 {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
2134 {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
2135 {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
2136 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
2137 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
2138 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
2139 {"++", INCREMENT, BINOP_END, 0},
2140 {"--", DECREMENT, BINOP_END, 0},
2141 {"->", ARROW, BINOP_END, 0},
2142 {"&&", ANDAND, BINOP_END, 0},
2143 {"||", OROR, BINOP_END, 0},
2144 /* "::" is *not* only C++: gdb overrides its meaning in several
2145 different ways, e.g., 'filename'::func, function::variable. */
2146 {"::", COLONCOLON, BINOP_END, 0},
2147 {"<<", LSH, BINOP_END, 0},
2148 {">>", RSH, BINOP_END, 0},
2149 {"==", EQUAL, BINOP_END, 0},
2150 {"!=", NOTEQUAL, BINOP_END, 0},
2151 {"<=", LEQ, BINOP_END, 0},
2152 {">=", GEQ, BINOP_END, 0},
2153 {".*", DOT_STAR, BINOP_END, FLAG_CXX}
2154 };
2155
2156 /* Identifier-like tokens. */
2157 static const struct token ident_tokens[] =
2158 {
2159 {"unsigned", UNSIGNED, OP_NULL, 0},
2160 {"template", TEMPLATE, OP_NULL, FLAG_CXX},
2161 {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
2162 {"struct", STRUCT, OP_NULL, 0},
2163 {"signed", SIGNED_KEYWORD, OP_NULL, 0},
2164 {"sizeof", SIZEOF, OP_NULL, 0},
2165 {"double", DOUBLE_KEYWORD, OP_NULL, 0},
2166 {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
2167 {"class", CLASS, OP_NULL, FLAG_CXX},
2168 {"union", UNION, OP_NULL, 0},
2169 {"short", SHORT, OP_NULL, 0},
2170 {"const", CONST_KEYWORD, OP_NULL, 0},
2171 {"enum", ENUM, OP_NULL, 0},
2172 {"long", LONG, OP_NULL, 0},
2173 {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
2174 {"int", INT_KEYWORD, OP_NULL, 0},
2175 {"new", NEW, OP_NULL, FLAG_CXX},
2176 {"delete", DELETE, OP_NULL, FLAG_CXX},
2177 {"operator", OPERATOR, OP_NULL, FLAG_CXX},
2178
2179 {"and", ANDAND, BINOP_END, FLAG_CXX},
2180 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
2181 {"bitand", '&', OP_NULL, FLAG_CXX},
2182 {"bitor", '|', OP_NULL, FLAG_CXX},
2183 {"compl", '~', OP_NULL, FLAG_CXX},
2184 {"not", '!', OP_NULL, FLAG_CXX},
2185 {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX},
2186 {"or", OROR, BINOP_END, FLAG_CXX},
2187 {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX},
2188 {"xor", '^', OP_NULL, FLAG_CXX},
2189 {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX},
2190
2191 {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX },
2192 {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX },
2193 {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX },
2194 {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX },
2195
2196 {"__typeof__", TYPEOF, OP_TYPEOF, 0 },
2197 {"__typeof", TYPEOF, OP_TYPEOF, 0 },
2198 {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW },
2199 {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX },
2200 {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW }
2201 };
2202
2203 /* When we find that lexptr (the global var defined in parse.c) is
2204 pointing at a macro invocation, we expand the invocation, and call
2205 scan_macro_expansion to save the old lexptr here and point lexptr
2206 into the expanded text. When we reach the end of that, we call
2207 end_macro_expansion to pop back to the value we saved here. The
2208 macro expansion code promises to return only fully-expanded text,
2209 so we don't need to "push" more than one level.
2210
2211 This is disgusting, of course. It would be cleaner to do all macro
2212 expansion beforehand, and then hand that to lexptr. But we don't
2213 really know where the expression ends. Remember, in a command like
2214
2215 (gdb) break *ADDRESS if CONDITION
2216
2217 we evaluate ADDRESS in the scope of the current frame, but we
2218 evaluate CONDITION in the scope of the breakpoint's location. So
2219 it's simply wrong to try to macro-expand the whole thing at once. */
2220 static char *macro_original_text;
2221
2222 /* We save all intermediate macro expansions on this obstack for the
2223 duration of a single parse. The expansion text may sometimes have
2224 to live past the end of the expansion, due to yacc lookahead.
2225 Rather than try to be clever about saving the data for a single
2226 token, we simply keep it all and delete it after parsing has
2227 completed. */
2228 static struct obstack expansion_obstack;
2229
2230 static void
2231 scan_macro_expansion (char *expansion)
2232 {
2233 char *copy;
2234
2235 /* We'd better not be trying to push the stack twice. */
2236 gdb_assert (! macro_original_text);
2237
2238 /* Copy to the obstack, and then free the intermediate
2239 expansion. */
2240 copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
2241 xfree (expansion);
2242
2243 /* Save the old lexptr value, so we can return to it when we're done
2244 parsing the expanded text. */
2245 macro_original_text = lexptr;
2246 lexptr = copy;
2247 }
2248
2249
2250 static int
2251 scanning_macro_expansion (void)
2252 {
2253 return macro_original_text != 0;
2254 }
2255
2256
2257 static void
2258 finished_macro_expansion (void)
2259 {
2260 /* There'd better be something to pop back to. */
2261 gdb_assert (macro_original_text);
2262
2263 /* Pop back to the original text. */
2264 lexptr = macro_original_text;
2265 macro_original_text = 0;
2266 }
2267
2268
2269 static void
2270 scan_macro_cleanup (void *dummy)
2271 {
2272 if (macro_original_text)
2273 finished_macro_expansion ();
2274
2275 obstack_free (&expansion_obstack, NULL);
2276 }
2277
2278 /* Return true iff the token represents a C++ cast operator. */
2279
2280 static int
2281 is_cast_operator (const char *token, int len)
2282 {
2283 return (! strncmp (token, "dynamic_cast", len)
2284 || ! strncmp (token, "static_cast", len)
2285 || ! strncmp (token, "reinterpret_cast", len)
2286 || ! strncmp (token, "const_cast", len));
2287 }
2288
2289 /* The scope used for macro expansion. */
2290 static struct macro_scope *expression_macro_scope;
2291
2292 /* This is set if a NAME token appeared at the very end of the input
2293 string, with no whitespace separating the name from the EOF. This
2294 is used only when parsing to do field name completion. */
2295 static int saw_name_at_eof;
2296
2297 /* This is set if the previously-returned token was a structure
2298 operator -- either '.' or ARROW. This is used only when parsing to
2299 do field name completion. */
2300 static int last_was_structop;
2301
2302 /* Read one token, getting characters through lexptr. */
2303
2304 static int
2305 lex_one_token (void)
2306 {
2307 int c;
2308 int namelen;
2309 unsigned int i;
2310 char *tokstart;
2311 int saw_structop = last_was_structop;
2312 char *copy;
2313
2314 last_was_structop = 0;
2315
2316 retry:
2317
2318 /* Check if this is a macro invocation that we need to expand. */
2319 if (! scanning_macro_expansion ())
2320 {
2321 char *expanded = macro_expand_next (&lexptr,
2322 standard_macro_lookup,
2323 expression_macro_scope);
2324
2325 if (expanded)
2326 scan_macro_expansion (expanded);
2327 }
2328
2329 prev_lexptr = lexptr;
2330
2331 tokstart = lexptr;
2332 /* See if it is a special token of length 3. */
2333 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
2334 if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
2335 {
2336 if ((tokentab3[i].flags & FLAG_CXX) != 0
2337 && parse_language->la_language != language_cplus)
2338 break;
2339
2340 lexptr += 3;
2341 yylval.opcode = tokentab3[i].opcode;
2342 return tokentab3[i].token;
2343 }
2344
2345 /* See if it is a special token of length 2. */
2346 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
2347 if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
2348 {
2349 if ((tokentab2[i].flags & FLAG_CXX) != 0
2350 && parse_language->la_language != language_cplus)
2351 break;
2352
2353 lexptr += 2;
2354 yylval.opcode = tokentab2[i].opcode;
2355 if (in_parse_field && tokentab2[i].token == ARROW)
2356 last_was_structop = 1;
2357 return tokentab2[i].token;
2358 }
2359
2360 switch (c = *tokstart)
2361 {
2362 case 0:
2363 /* If we were just scanning the result of a macro expansion,
2364 then we need to resume scanning the original text.
2365 If we're parsing for field name completion, and the previous
2366 token allows such completion, return a COMPLETE token.
2367 Otherwise, we were already scanning the original text, and
2368 we're really done. */
2369 if (scanning_macro_expansion ())
2370 {
2371 finished_macro_expansion ();
2372 goto retry;
2373 }
2374 else if (saw_name_at_eof)
2375 {
2376 saw_name_at_eof = 0;
2377 return COMPLETE;
2378 }
2379 else if (saw_structop)
2380 return COMPLETE;
2381 else
2382 return 0;
2383
2384 case ' ':
2385 case '\t':
2386 case '\n':
2387 lexptr++;
2388 goto retry;
2389
2390 case '[':
2391 case '(':
2392 paren_depth++;
2393 lexptr++;
2394 if (parse_language->la_language == language_objc && c == '[')
2395 return OBJC_LBRAC;
2396 return c;
2397
2398 case ']':
2399 case ')':
2400 if (paren_depth == 0)
2401 return 0;
2402 paren_depth--;
2403 lexptr++;
2404 return c;
2405
2406 case ',':
2407 if (comma_terminates
2408 && paren_depth == 0
2409 && ! scanning_macro_expansion ())
2410 return 0;
2411 lexptr++;
2412 return c;
2413
2414 case '.':
2415 /* Might be a floating point number. */
2416 if (lexptr[1] < '0' || lexptr[1] > '9')
2417 {
2418 if (in_parse_field)
2419 last_was_structop = 1;
2420 goto symbol; /* Nope, must be a symbol. */
2421 }
2422 /* FALL THRU into number case. */
2423
2424 case '0':
2425 case '1':
2426 case '2':
2427 case '3':
2428 case '4':
2429 case '5':
2430 case '6':
2431 case '7':
2432 case '8':
2433 case '9':
2434 {
2435 /* It's a number. */
2436 int got_dot = 0, got_e = 0, toktype;
2437 char *p = tokstart;
2438 int hex = input_radix > 10;
2439
2440 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
2441 {
2442 p += 2;
2443 hex = 1;
2444 }
2445 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
2446 {
2447 p += 2;
2448 hex = 0;
2449 }
2450
2451 for (;; ++p)
2452 {
2453 /* This test includes !hex because 'e' is a valid hex digit
2454 and thus does not indicate a floating point number when
2455 the radix is hex. */
2456 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2457 got_dot = got_e = 1;
2458 /* This test does not include !hex, because a '.' always indicates
2459 a decimal floating point number regardless of the radix. */
2460 else if (!got_dot && *p == '.')
2461 got_dot = 1;
2462 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2463 && (*p == '-' || *p == '+'))
2464 /* This is the sign of the exponent, not the end of the
2465 number. */
2466 continue;
2467 /* We will take any letters or digits. parse_number will
2468 complain if past the radix, or if L or U are not final. */
2469 else if ((*p < '0' || *p > '9')
2470 && ((*p < 'a' || *p > 'z')
2471 && (*p < 'A' || *p > 'Z')))
2472 break;
2473 }
2474 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
2475 if (toktype == ERROR)
2476 {
2477 char *err_copy = (char *) alloca (p - tokstart + 1);
2478
2479 memcpy (err_copy, tokstart, p - tokstart);
2480 err_copy[p - tokstart] = 0;
2481 error (_("Invalid number \"%s\"."), err_copy);
2482 }
2483 lexptr = p;
2484 return toktype;
2485 }
2486
2487 case '@':
2488 {
2489 char *p = &tokstart[1];
2490 size_t len = strlen ("entry");
2491
2492 if (parse_language->la_language == language_objc)
2493 {
2494 size_t len = strlen ("selector");
2495
2496 if (strncmp (p, "selector", len) == 0
2497 && (p[len] == '\0' || isspace (p[len])))
2498 {
2499 lexptr = p + len;
2500 return SELECTOR;
2501 }
2502 else if (*p == '"')
2503 goto parse_string;
2504 }
2505
2506 while (isspace (*p))
2507 p++;
2508 if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
2509 && p[len] != '_')
2510 {
2511 lexptr = &p[len];
2512 return ENTRY;
2513 }
2514 }
2515 /* FALLTHRU */
2516 case '+':
2517 case '-':
2518 case '*':
2519 case '/':
2520 case '%':
2521 case '|':
2522 case '&':
2523 case '^':
2524 case '~':
2525 case '!':
2526 case '<':
2527 case '>':
2528 case '?':
2529 case ':':
2530 case '=':
2531 case '{':
2532 case '}':
2533 symbol:
2534 lexptr++;
2535 return c;
2536
2537 case 'L':
2538 case 'u':
2539 case 'U':
2540 if (tokstart[1] != '"' && tokstart[1] != '\'')
2541 break;
2542 /* Fall through. */
2543 case '\'':
2544 case '"':
2545
2546 parse_string:
2547 {
2548 int host_len;
2549 int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
2550 &host_len);
2551 if (result == CHAR)
2552 {
2553 if (host_len == 0)
2554 error (_("Empty character constant."));
2555 else if (host_len > 2 && c == '\'')
2556 {
2557 ++tokstart;
2558 namelen = lexptr - tokstart - 1;
2559 goto tryname;
2560 }
2561 else if (host_len > 1)
2562 error (_("Invalid character constant."));
2563 }
2564 return result;
2565 }
2566 }
2567
2568 if (!(c == '_' || c == '$'
2569 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2570 /* We must have come across a bad character (e.g. ';'). */
2571 error (_("Invalid character '%c' in expression."), c);
2572
2573 /* It's a name. See how long it is. */
2574 namelen = 0;
2575 for (c = tokstart[namelen];
2576 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2577 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2578 {
2579 /* Template parameter lists are part of the name.
2580 FIXME: This mishandles `print $a<4&&$a>3'. */
2581
2582 if (c == '<')
2583 {
2584 if (! is_cast_operator (tokstart, namelen))
2585 {
2586 /* Scan ahead to get rest of the template specification. Note
2587 that we look ahead only when the '<' adjoins non-whitespace
2588 characters; for comparison expressions, e.g. "a < b > c",
2589 there must be spaces before the '<', etc. */
2590
2591 char * p = find_template_name_end (tokstart + namelen);
2592 if (p)
2593 namelen = p - tokstart;
2594 }
2595 break;
2596 }
2597 c = tokstart[++namelen];
2598 }
2599
2600 /* The token "if" terminates the expression and is NOT removed from
2601 the input stream. It doesn't count if it appears in the
2602 expansion of a macro. */
2603 if (namelen == 2
2604 && tokstart[0] == 'i'
2605 && tokstart[1] == 'f'
2606 && ! scanning_macro_expansion ())
2607 {
2608 return 0;
2609 }
2610
2611 /* For the same reason (breakpoint conditions), "thread N"
2612 terminates the expression. "thread" could be an identifier, but
2613 an identifier is never followed by a number without intervening
2614 punctuation. "task" is similar. Handle abbreviations of these,
2615 similarly to breakpoint.c:find_condition_and_thread. */
2616 if (namelen >= 1
2617 && (strncmp (tokstart, "thread", namelen) == 0
2618 || strncmp (tokstart, "task", namelen) == 0)
2619 && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
2620 && ! scanning_macro_expansion ())
2621 {
2622 char *p = tokstart + namelen + 1;
2623 while (*p == ' ' || *p == '\t')
2624 p++;
2625 if (*p >= '0' && *p <= '9')
2626 return 0;
2627 }
2628
2629 lexptr += namelen;
2630
2631 tryname:
2632
2633 yylval.sval.ptr = tokstart;
2634 yylval.sval.length = namelen;
2635
2636 /* Catch specific keywords. */
2637 copy = copy_name (yylval.sval);
2638 for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
2639 if (strcmp (copy, ident_tokens[i].operator) == 0)
2640 {
2641 if ((ident_tokens[i].flags & FLAG_CXX) != 0
2642 && parse_language->la_language != language_cplus)
2643 break;
2644
2645 if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
2646 {
2647 int is_a_field_of_this = 0;
2648
2649 if (lookup_symbol (copy, expression_context_block,
2650 VAR_DOMAIN,
2651 (parse_language->la_language == language_cplus
2652 ? &is_a_field_of_this
2653 : NULL))
2654 != NULL)
2655 {
2656 /* The keyword is shadowed. */
2657 break;
2658 }
2659 }
2660
2661 /* It is ok to always set this, even though we don't always
2662 strictly need to. */
2663 yylval.opcode = ident_tokens[i].opcode;
2664 return ident_tokens[i].token;
2665 }
2666
2667 if (*tokstart == '$')
2668 return VARIABLE;
2669
2670 if (in_parse_field && *lexptr == '\0')
2671 saw_name_at_eof = 1;
2672 return NAME;
2673 }
2674
2675 /* An object of this type is pushed on a FIFO by the "outer" lexer. */
2676 typedef struct
2677 {
2678 int token;
2679 YYSTYPE value;
2680 } token_and_value;
2681
2682 DEF_VEC_O (token_and_value);
2683
2684 /* A FIFO of tokens that have been read but not yet returned to the
2685 parser. */
2686 static VEC (token_and_value) *token_fifo;
2687
2688 /* Non-zero if the lexer should return tokens from the FIFO. */
2689 static int popping;
2690
2691 /* Temporary storage for c_lex; this holds symbol names as they are
2692 built up. */
2693 static struct obstack name_obstack;
2694
2695 /* Classify a NAME token. The contents of the token are in `yylval'.
2696 Updates yylval and returns the new token type. BLOCK is the block
2697 in which lookups start; this can be NULL to mean the global
2698 scope. */
2699 static int
2700 classify_name (struct block *block)
2701 {
2702 struct symbol *sym;
2703 char *copy;
2704 int is_a_field_of_this = 0;
2705
2706 copy = copy_name (yylval.sval);
2707
2708 sym = lookup_symbol (copy, block, VAR_DOMAIN,
2709 parse_language->la_name_of_this
2710 ? &is_a_field_of_this : (int *) NULL);
2711
2712 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2713 {
2714 yylval.ssym.sym = sym;
2715 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2716 return BLOCKNAME;
2717 }
2718 else if (!sym)
2719 {
2720 /* See if it's a file name. */
2721 struct symtab *symtab;
2722
2723 symtab = lookup_symtab (copy);
2724 if (symtab)
2725 {
2726 yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
2727 return FILENAME;
2728 }
2729 }
2730
2731 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2732 {
2733 yylval.tsym.type = SYMBOL_TYPE (sym);
2734 return TYPENAME;
2735 }
2736
2737 yylval.tsym.type
2738 = language_lookup_primitive_type_by_name (parse_language,
2739 parse_gdbarch, copy);
2740 if (yylval.tsym.type != NULL)
2741 return TYPENAME;
2742
2743 /* See if it's an ObjC classname. */
2744 if (parse_language->la_language == language_objc && !sym)
2745 {
2746 CORE_ADDR Class = lookup_objc_class (parse_gdbarch, copy);
2747 if (Class)
2748 {
2749 yylval.class.class = Class;
2750 sym = lookup_struct_typedef (copy, expression_context_block, 1);
2751 if (sym)
2752 yylval.class.type = SYMBOL_TYPE (sym);
2753 return CLASSNAME;
2754 }
2755 }
2756
2757 /* Input names that aren't symbols but ARE valid hex numbers, when
2758 the input radix permits them, can be names or numbers depending
2759 on the parse. Note we support radixes > 16 here. */
2760 if (!sym
2761 && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
2762 || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
2763 {
2764 YYSTYPE newlval; /* Its value is ignored. */
2765 int hextype = parse_number (copy, yylval.sval.length, 0, &newlval);
2766 if (hextype == INT)
2767 {
2768 yylval.ssym.sym = sym;
2769 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2770 return NAME_OR_INT;
2771 }
2772 }
2773
2774 /* Any other kind of symbol */
2775 yylval.ssym.sym = sym;
2776 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2777
2778 if (sym == NULL
2779 && parse_language->la_language == language_cplus
2780 && !is_a_field_of_this
2781 && !lookup_minimal_symbol (copy, NULL, NULL))
2782 return UNKNOWN_CPP_NAME;
2783
2784 return NAME;
2785 }
2786
2787 /* Like classify_name, but used by the inner loop of the lexer, when a
2788 name might have already been seen. FIRST_NAME is true if the token
2789 in `yylval' is the first component of a name, false otherwise. */
2790
2791 static int
2792 classify_inner_name (struct block *block, int first_name)
2793 {
2794 struct type *type, *new_type;
2795 char *copy;
2796
2797 if (first_name)
2798 return classify_name (block);
2799
2800 type = check_typedef (yylval.tsym.type);
2801 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2802 && TYPE_CODE (type) != TYPE_CODE_UNION
2803 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2804 return ERROR;
2805
2806 copy = copy_name (yylval.tsym.stoken);
2807 yylval.ssym.sym = cp_lookup_nested_symbol (yylval.tsym.type, copy, block);
2808 if (yylval.ssym.sym == NULL)
2809 return ERROR;
2810
2811 switch (SYMBOL_CLASS (yylval.ssym.sym))
2812 {
2813 case LOC_BLOCK:
2814 case LOC_LABEL:
2815 return ERROR;
2816
2817 case LOC_TYPEDEF:
2818 yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);;
2819 return TYPENAME;
2820
2821 default:
2822 yylval.ssym.is_a_field_of_this = 0;
2823 return NAME;
2824 }
2825 internal_error (__FILE__, __LINE__, _("not reached"));
2826 }
2827
2828 /* The outer level of a two-level lexer. This calls the inner lexer
2829 to return tokens. It then either returns these tokens, or
2830 aggregates them into a larger token. This lets us work around a
2831 problem in our parsing approach, where the parser could not
2832 distinguish between qualified names and qualified types at the
2833 right point.
2834
2835 This approach is still not ideal, because it mishandles template
2836 types. See the comment in lex_one_token for an example. However,
2837 this is still an improvement over the earlier approach, and will
2838 suffice until we move to better parsing technology. */
2839 static int
2840 yylex (void)
2841 {
2842 token_and_value current;
2843 int first_was_coloncolon, last_was_coloncolon, first_iter;
2844
2845 if (popping && !VEC_empty (token_and_value, token_fifo))
2846 {
2847 token_and_value tv = *VEC_index (token_and_value, token_fifo, 0);
2848 VEC_ordered_remove (token_and_value, token_fifo, 0);
2849 yylval = tv.value;
2850 return tv.token;
2851 }
2852 popping = 0;
2853
2854 current.token = lex_one_token ();
2855 if (current.token == NAME)
2856 current.token = classify_name (expression_context_block);
2857 if (parse_language->la_language != language_cplus
2858 || (current.token != TYPENAME && current.token != COLONCOLON))
2859 return current.token;
2860
2861 first_was_coloncolon = current.token == COLONCOLON;
2862 last_was_coloncolon = first_was_coloncolon;
2863 obstack_free (&name_obstack, obstack_base (&name_obstack));
2864 if (!last_was_coloncolon)
2865 obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
2866 current.value = yylval;
2867 first_iter = 1;
2868 while (1)
2869 {
2870 token_and_value next;
2871
2872 next.token = lex_one_token ();
2873 next.value = yylval;
2874
2875 if (next.token == NAME && last_was_coloncolon)
2876 {
2877 int classification;
2878
2879 classification = classify_inner_name (first_was_coloncolon
2880 ? NULL
2881 : expression_context_block,
2882 first_iter);
2883 /* We keep going until we either run out of names, or until
2884 we have a qualified name which is not a type. */
2885 if (classification != TYPENAME && classification != NAME)
2886 {
2887 /* Push the final component and leave the loop. */
2888 VEC_safe_push (token_and_value, token_fifo, &next);
2889 break;
2890 }
2891
2892 /* Update the partial name we are constructing. */
2893 if (!first_iter)
2894 {
2895 /* We don't want to put a leading "::" into the name. */
2896 obstack_grow_str (&name_obstack, "::");
2897 }
2898 obstack_grow (&name_obstack, next.value.sval.ptr,
2899 next.value.sval.length);
2900
2901 yylval.sval.ptr = obstack_base (&name_obstack);
2902 yylval.sval.length = obstack_object_size (&name_obstack);
2903 current.value = yylval;
2904 current.token = classification;
2905
2906 last_was_coloncolon = 0;
2907 }
2908 else if (next.token == COLONCOLON && !last_was_coloncolon)
2909 last_was_coloncolon = 1;
2910 else
2911 {
2912 /* We've reached the end of the name. */
2913 VEC_safe_push (token_and_value, token_fifo, &next);
2914 break;
2915 }
2916
2917 first_iter = 0;
2918 }
2919
2920 popping = 1;
2921
2922 /* If we ended with a "::", insert it too. */
2923 if (last_was_coloncolon)
2924 {
2925 token_and_value cc;
2926 memset (&cc, 0, sizeof (token_and_value));
2927 if (first_was_coloncolon && first_iter)
2928 {
2929 yylval = cc.value;
2930 return COLONCOLON;
2931 }
2932 cc.token = COLONCOLON;
2933 VEC_safe_insert (token_and_value, token_fifo, 0, &cc);
2934 }
2935
2936 yylval = current.value;
2937 yylval.sval.ptr = obstack_copy0 (&expansion_obstack,
2938 yylval.sval.ptr,
2939 yylval.sval.length);
2940 return current.token;
2941 }
2942
2943 int
2944 c_parse (void)
2945 {
2946 int result;
2947 struct cleanup *back_to = make_cleanup (free_current_contents,
2948 &expression_macro_scope);
2949
2950 /* Set up the scope for macro expansion. */
2951 expression_macro_scope = NULL;
2952
2953 if (expression_context_block)
2954 expression_macro_scope
2955 = sal_macro_scope (find_pc_line (expression_context_pc, 0));
2956 else
2957 expression_macro_scope = default_macro_scope ();
2958 if (! expression_macro_scope)
2959 expression_macro_scope = user_macro_scope ();
2960
2961 /* Initialize macro expansion code. */
2962 obstack_init (&expansion_obstack);
2963 gdb_assert (! macro_original_text);
2964 make_cleanup (scan_macro_cleanup, 0);
2965
2966 make_cleanup_restore_integer (&yydebug);
2967 yydebug = parser_debug;
2968
2969 /* Initialize some state used by the lexer. */
2970 last_was_structop = 0;
2971 saw_name_at_eof = 0;
2972
2973 VEC_free (token_and_value, token_fifo);
2974 popping = 0;
2975 obstack_init (&name_obstack);
2976 make_cleanup_obstack_free (&name_obstack);
2977
2978 result = yyparse ();
2979 do_cleanups (back_to);
2980 return result;
2981 }
2982
2983
2984 void
2985 yyerror (char *msg)
2986 {
2987 if (prev_lexptr)
2988 lexptr = prev_lexptr;
2989
2990 error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
2991 }
This page took 0.094468 seconds and 4 git commands to generate.