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