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