Commit | Line | Data |
---|---|---|
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" | |
39 | #include "gdb_string.h" | |
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 | 121 | int yyparse (void); |
c906108c | 122 | |
a14ed312 | 123 | static int yylex (void); |
c906108c | 124 | |
a14ed312 | 125 | void 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 */ | |
a14ed312 | 167 | static int parse_number (char *, int, int, YYSTYPE *); |
66c53f2b | 168 | static struct stoken operator_stoken (const char *); |
e314d629 | 169 | static void check_parameter_typelist (VEC (type_ptr) *); |
24955f63 | 170 | static void write_destructor_name (struct stoken); |
9507860e TT |
171 | |
172 | static 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 | ||
279 | start : exp1 | |
280 | | type_exp | |
281 | ; | |
282 | ||
283 | type_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. */ | |
304 | exp1 : exp | |
305 | | exp1 ',' exp | |
306 | { write_exp_elt_opcode (BINOP_COMMA); } | |
307 | ; | |
308 | ||
309 | /* Expressions, not including the comma operator. */ | |
310 | exp : '*' exp %prec UNARY | |
311 | { write_exp_elt_opcode (UNOP_IND); } | |
ef944135 | 312 | ; |
c906108c SS |
313 | |
314 | exp : '&' exp %prec UNARY | |
315 | { write_exp_elt_opcode (UNOP_ADDR); } | |
ef944135 | 316 | ; |
c906108c SS |
317 | |
318 | exp : '-' exp %prec UNARY | |
319 | { write_exp_elt_opcode (UNOP_NEG); } | |
320 | ; | |
321 | ||
36e9969c NS |
322 | exp : '+' exp %prec UNARY |
323 | { write_exp_elt_opcode (UNOP_PLUS); } | |
324 | ; | |
325 | ||
c906108c SS |
326 | exp : '!' exp %prec UNARY |
327 | { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } | |
328 | ; | |
329 | ||
330 | exp : '~' exp %prec UNARY | |
331 | { write_exp_elt_opcode (UNOP_COMPLEMENT); } | |
332 | ; | |
333 | ||
334 | exp : INCREMENT exp %prec UNARY | |
335 | { write_exp_elt_opcode (UNOP_PREINCREMENT); } | |
336 | ; | |
337 | ||
338 | exp : DECREMENT exp %prec UNARY | |
339 | { write_exp_elt_opcode (UNOP_PREDECREMENT); } | |
340 | ; | |
341 | ||
342 | exp : exp INCREMENT %prec UNARY | |
343 | { write_exp_elt_opcode (UNOP_POSTINCREMENT); } | |
344 | ; | |
345 | ||
346 | exp : exp DECREMENT %prec UNARY | |
347 | { write_exp_elt_opcode (UNOP_POSTDECREMENT); } | |
348 | ; | |
349 | ||
6e72ca20 TT |
350 | exp : TYPEID '(' exp ')' %prec UNARY |
351 | { write_exp_elt_opcode (OP_TYPEID); } | |
352 | ; | |
353 | ||
354 | exp : TYPEID '(' type_exp ')' %prec UNARY | |
355 | { write_exp_elt_opcode (OP_TYPEID); } | |
356 | ; | |
357 | ||
c906108c SS |
358 | exp : SIZEOF exp %prec UNARY |
359 | { write_exp_elt_opcode (UNOP_SIZEOF); } | |
360 | ; | |
361 | ||
362 | exp : 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 |
368 | exp : 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 | ||
375 | exp : 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 |
385 | exp : exp ARROW '~' name |
386 | { write_exp_elt_opcode (STRUCTOP_PTR); | |
387 | write_destructor_name ($4); | |
388 | write_exp_elt_opcode (STRUCTOP_PTR); } | |
389 | ; | |
390 | ||
391 | exp : 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 |
398 | exp : 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 | 406 | exp : exp ARROW_STAR exp |
c906108c SS |
407 | { write_exp_elt_opcode (STRUCTOP_MPTR); } |
408 | ; | |
409 | ||
410 | exp : 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 |
416 | exp : 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 | ||
423 | exp : 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 |
433 | exp : exp '.' '~' name |
434 | { write_exp_elt_opcode (STRUCTOP_STRUCT); | |
435 | write_destructor_name ($4); | |
436 | write_exp_elt_opcode (STRUCTOP_STRUCT); } | |
437 | ; | |
438 | ||
439 | exp : 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 |
446 | exp : 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 | 454 | exp : exp DOT_STAR exp |
c906108c SS |
455 | { write_exp_elt_opcode (STRUCTOP_MEMBER); } |
456 | ; | |
457 | ||
458 | exp : exp '[' exp1 ']' | |
459 | { write_exp_elt_opcode (BINOP_SUBSCRIPT); } | |
460 | ; | |
461 | ||
f2e8016f TT |
462 | exp : 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 | ||
471 | exp : 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 | ||
493 | exp : 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 | ||
508 | exp : 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 | ||
517 | msglist : name | |
518 | { add_msglist(&$1, 0); } | |
519 | | msgarglist | |
520 | ; | |
521 | ||
522 | msgarglist : msgarg | |
523 | | msgarglist msgarg | |
524 | ; | |
525 | ||
526 | msgarg : 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 |
534 | exp : 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 | 544 | exp : 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 |
567 | lcurly : '{' |
568 | { start_arglist (); } | |
569 | ; | |
570 | ||
571 | arglist : | |
572 | ; | |
573 | ||
574 | arglist : exp | |
575 | { arglist_len = 1; } | |
576 | ; | |
577 | ||
578 | arglist : arglist ',' exp %prec ABOVE_COMMA | |
579 | { arglist_len++; } | |
580 | ; | |
581 | ||
a6fb9c08 | 582 | exp : 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 |
600 | rcurly : '}' |
601 | { $$ = end_arglist () - 1; } | |
602 | ; | |
603 | exp : 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 |
610 | exp : lcurly type_exp rcurly exp %prec UNARY |
611 | { write_exp_elt_opcode (UNOP_MEMVAL_TYPE); } | |
c906108c SS |
612 | ; |
613 | ||
9eaf6705 TT |
614 | exp : '(' type_exp ')' exp %prec UNARY |
615 | { write_exp_elt_opcode (UNOP_CAST_TYPE); } | |
c906108c SS |
616 | ; |
617 | ||
618 | exp : '(' exp1 ')' | |
619 | { } | |
620 | ; | |
621 | ||
622 | /* Binary operators in order of decreasing precedence. */ | |
623 | ||
624 | exp : exp '@' exp | |
625 | { write_exp_elt_opcode (BINOP_REPEAT); } | |
626 | ; | |
627 | ||
628 | exp : exp '*' exp | |
629 | { write_exp_elt_opcode (BINOP_MUL); } | |
630 | ; | |
631 | ||
632 | exp : exp '/' exp | |
633 | { write_exp_elt_opcode (BINOP_DIV); } | |
634 | ; | |
635 | ||
636 | exp : exp '%' exp | |
637 | { write_exp_elt_opcode (BINOP_REM); } | |
638 | ; | |
639 | ||
640 | exp : exp '+' exp | |
641 | { write_exp_elt_opcode (BINOP_ADD); } | |
642 | ; | |
643 | ||
644 | exp : exp '-' exp | |
645 | { write_exp_elt_opcode (BINOP_SUB); } | |
646 | ; | |
647 | ||
648 | exp : exp LSH exp | |
649 | { write_exp_elt_opcode (BINOP_LSH); } | |
650 | ; | |
651 | ||
652 | exp : exp RSH exp | |
653 | { write_exp_elt_opcode (BINOP_RSH); } | |
654 | ; | |
655 | ||
656 | exp : exp EQUAL exp | |
657 | { write_exp_elt_opcode (BINOP_EQUAL); } | |
658 | ; | |
659 | ||
660 | exp : exp NOTEQUAL exp | |
661 | { write_exp_elt_opcode (BINOP_NOTEQUAL); } | |
662 | ; | |
663 | ||
664 | exp : exp LEQ exp | |
665 | { write_exp_elt_opcode (BINOP_LEQ); } | |
666 | ; | |
667 | ||
668 | exp : exp GEQ exp | |
669 | { write_exp_elt_opcode (BINOP_GEQ); } | |
670 | ; | |
671 | ||
672 | exp : exp '<' exp | |
673 | { write_exp_elt_opcode (BINOP_LESS); } | |
674 | ; | |
675 | ||
676 | exp : exp '>' exp | |
677 | { write_exp_elt_opcode (BINOP_GTR); } | |
678 | ; | |
679 | ||
680 | exp : exp '&' exp | |
681 | { write_exp_elt_opcode (BINOP_BITWISE_AND); } | |
682 | ; | |
683 | ||
684 | exp : exp '^' exp | |
685 | { write_exp_elt_opcode (BINOP_BITWISE_XOR); } | |
686 | ; | |
687 | ||
688 | exp : exp '|' exp | |
689 | { write_exp_elt_opcode (BINOP_BITWISE_IOR); } | |
690 | ; | |
691 | ||
692 | exp : exp ANDAND exp | |
693 | { write_exp_elt_opcode (BINOP_LOGICAL_AND); } | |
694 | ; | |
695 | ||
696 | exp : exp OROR exp | |
697 | { write_exp_elt_opcode (BINOP_LOGICAL_OR); } | |
698 | ; | |
699 | ||
700 | exp : exp '?' exp ':' exp %prec '?' | |
701 | { write_exp_elt_opcode (TERNOP_COND); } | |
702 | ; | |
703 | ||
704 | exp : exp '=' exp | |
705 | { write_exp_elt_opcode (BINOP_ASSIGN); } | |
706 | ; | |
707 | ||
708 | exp : 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 | ||
714 | exp : 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 |
721 | exp : 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 |
730 | exp : 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 | ||
741 | exp : 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 |
748 | exp : 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 |
755 | exp : variable |
756 | ; | |
757 | ||
758 | exp : VARIABLE | |
48e32051 TT |
759 | { |
760 | write_dollar_variable ($1); | |
761 | } | |
c906108c SS |
762 | ; |
763 | ||
f2e8016f TT |
764 | exp : 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 |
771 | exp : 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 |
781 | exp : REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY |
782 | { write_exp_elt_opcode (UNOP_REINTERPRET_CAST); } | |
4e8f195d TT |
783 | ; |
784 | ||
9eaf6705 TT |
785 | exp : STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY |
786 | { write_exp_elt_opcode (UNOP_CAST_TYPE); } | |
4e8f195d TT |
787 | ; |
788 | ||
9eaf6705 TT |
789 | exp : DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY |
790 | { write_exp_elt_opcode (UNOP_DYNAMIC_CAST); } | |
4e8f195d TT |
791 | ; |
792 | ||
9eaf6705 | 793 | exp : 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 |
799 | string_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 | ||
835 | exp : 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 |
868 | exp : 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 |
877 | exp : 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 | ||
884 | exp : 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 | ||
893 | block : 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 | ||
907 | block : 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 | 917 | variable: 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 |
932 | variable: 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 | 954 | qualified_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; |
e8269d5f | 973 | CHECK_TYPEDEF (type); |
c906108c | 974 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT |
79c2c32d DC |
975 | && TYPE_CODE (type) != TYPE_CODE_UNION |
976 | && TYPE_CODE (type) != TYPE_CODE_NAMESPACE) | |
001083c6 | 977 | error (_("`%s' is not defined as an aggregate type."), |
7fc75ca7 | 978 | TYPE_SAFE_NAME (type)); |
c906108c SS |
979 | |
980 | tmp_token.ptr = (char*) alloca ($4.length + 2); | |
981 | tmp_token.length = $4.length + 1; | |
982 | tmp_token.ptr[0] = '~'; | |
983 | memcpy (tmp_token.ptr+1, $4.ptr, $4.length); | |
984 | tmp_token.ptr[tmp_token.length] = 0; | |
985 | ||
986 | /* Check for valid destructor name. */ | |
d8228535 | 987 | destructor_name_p (tmp_token.ptr, $1.type); |
c906108c SS |
988 | write_exp_elt_opcode (OP_SCOPE); |
989 | write_exp_elt_type (type); | |
990 | write_exp_string (tmp_token); | |
991 | write_exp_elt_opcode (OP_SCOPE); | |
992 | } | |
48e32051 TT |
993 | | TYPENAME COLONCOLON name COLONCOLON name |
994 | { | |
995 | char *copy = copy_name ($3); | |
996 | error (_("No type \"%s\" within class " | |
997 | "or namespace \"%s\"."), | |
7fc75ca7 | 998 | copy, TYPE_SAFE_NAME ($1.type)); |
48e32051 | 999 | } |
c906108c SS |
1000 | ; |
1001 | ||
1002 | variable: qualified_name | |
48e32051 | 1003 | | COLONCOLON name_not_typename |
c906108c | 1004 | { |
48e32051 | 1005 | char *name = copy_name ($2.stoken); |
c906108c | 1006 | struct symbol *sym; |
7c7b6655 | 1007 | struct bound_minimal_symbol msymbol; |
c906108c SS |
1008 | |
1009 | sym = | |
1010 | lookup_symbol (name, (const struct block *) NULL, | |
1993b719 | 1011 | VAR_DOMAIN, NULL); |
c906108c SS |
1012 | if (sym) |
1013 | { | |
1014 | write_exp_elt_opcode (OP_VAR_VALUE); | |
1015 | write_exp_elt_block (NULL); | |
1016 | write_exp_elt_sym (sym); | |
1017 | write_exp_elt_opcode (OP_VAR_VALUE); | |
1018 | break; | |
1019 | } | |
1020 | ||
7c7b6655 TT |
1021 | msymbol = lookup_bound_minimal_symbol (name); |
1022 | if (msymbol.minsym != NULL) | |
c841afd5 UW |
1023 | write_exp_msymbol (msymbol); |
1024 | else if (!have_full_symbols () && !have_partial_symbols ()) | |
001083c6 | 1025 | error (_("No symbol table is loaded. Use the \"file\" command.")); |
c906108c | 1026 | else |
001083c6 | 1027 | error (_("No symbol \"%s\" in current context."), name); |
c906108c SS |
1028 | } |
1029 | ; | |
1030 | ||
1031 | variable: name_not_typename | |
1032 | { struct symbol *sym = $1.sym; | |
1033 | ||
1034 | if (sym) | |
1035 | { | |
1036 | if (symbol_read_needs_frame (sym)) | |
1037 | { | |
5aafa1cc PM |
1038 | if (innermost_block == 0 |
1039 | || contained_in (block_found, | |
1040 | innermost_block)) | |
c906108c SS |
1041 | innermost_block = block_found; |
1042 | } | |
1043 | ||
1044 | write_exp_elt_opcode (OP_VAR_VALUE); | |
1045 | /* We want to use the selected frame, not | |
1046 | another more inner frame which happens to | |
1047 | be in the same block. */ | |
1048 | write_exp_elt_block (NULL); | |
1049 | write_exp_elt_sym (sym); | |
1050 | write_exp_elt_opcode (OP_VAR_VALUE); | |
1051 | } | |
1052 | else if ($1.is_a_field_of_this) | |
1053 | { | |
1054 | /* C++: it hangs off of `this'. Must | |
1055 | not inadvertently convert from a method call | |
1056 | to data ref. */ | |
5aafa1cc PM |
1057 | if (innermost_block == 0 |
1058 | || contained_in (block_found, | |
1059 | innermost_block)) | |
c906108c SS |
1060 | innermost_block = block_found; |
1061 | write_exp_elt_opcode (OP_THIS); | |
1062 | write_exp_elt_opcode (OP_THIS); | |
1063 | write_exp_elt_opcode (STRUCTOP_PTR); | |
1064 | write_exp_string ($1.stoken); | |
1065 | write_exp_elt_opcode (STRUCTOP_PTR); | |
1066 | } | |
1067 | else | |
1068 | { | |
7c7b6655 | 1069 | struct bound_minimal_symbol msymbol; |
710122da | 1070 | char *arg = copy_name ($1.stoken); |
c906108c SS |
1071 | |
1072 | msymbol = | |
7c7b6655 TT |
1073 | lookup_bound_minimal_symbol (arg); |
1074 | if (msymbol.minsym != NULL) | |
c841afd5 | 1075 | write_exp_msymbol (msymbol); |
c906108c | 1076 | else if (!have_full_symbols () && !have_partial_symbols ()) |
001083c6 | 1077 | error (_("No symbol table is loaded. Use the \"file\" command.")); |
c906108c | 1078 | else |
001083c6 | 1079 | error (_("No symbol \"%s\" in current context."), |
c906108c SS |
1080 | copy_name ($1.stoken)); |
1081 | } | |
1082 | } | |
1083 | ; | |
1084 | ||
47663de5 | 1085 | space_identifier : '@' NAME |
95c391b6 | 1086 | { insert_type_address_space (copy_name ($2.stoken)); } |
47663de5 | 1087 | ; |
c906108c | 1088 | |
47663de5 MS |
1089 | const_or_volatile: const_or_volatile_noopt |
1090 | | | |
c906108c | 1091 | ; |
47663de5 MS |
1092 | |
1093 | cv_with_space_id : const_or_volatile space_identifier const_or_volatile | |
56e2d25a | 1094 | ; |
47663de5 MS |
1095 | |
1096 | const_or_volatile_or_space_identifier_noopt: cv_with_space_id | |
1097 | | const_or_volatile_noopt | |
56e2d25a | 1098 | ; |
47663de5 MS |
1099 | |
1100 | const_or_volatile_or_space_identifier: | |
1101 | const_or_volatile_or_space_identifier_noopt | |
1102 | | | |
56e2d25a | 1103 | ; |
47663de5 | 1104 | |
95c391b6 TT |
1105 | ptr_operator: |
1106 | ptr_operator '*' | |
1107 | { insert_type (tp_pointer); } | |
1108 | const_or_volatile_or_space_identifier | |
95c391b6 TT |
1109 | | '*' |
1110 | { insert_type (tp_pointer); } | |
1111 | const_or_volatile_or_space_identifier | |
c906108c | 1112 | | '&' |
16d01384 | 1113 | { insert_type (tp_reference); } |
95c391b6 | 1114 | | '&' ptr_operator |
16d01384 | 1115 | { insert_type (tp_reference); } |
95c391b6 TT |
1116 | ; |
1117 | ||
fcde5961 TT |
1118 | ptr_operator_ts: ptr_operator |
1119 | { | |
1120 | $$ = get_type_stack (); | |
1121 | /* This cleanup is eventually run by | |
1122 | c_parse. */ | |
1123 | make_cleanup (type_stack_cleanup, $$); | |
1124 | } | |
1125 | ; | |
1126 | ||
1127 | abs_decl: ptr_operator_ts direct_abs_decl | |
1128 | { $$ = append_type_stack ($2, $1); } | |
1129 | | ptr_operator_ts | |
c906108c SS |
1130 | | direct_abs_decl |
1131 | ; | |
1132 | ||
1133 | direct_abs_decl: '(' abs_decl ')' | |
fcde5961 | 1134 | { $$ = $2; } |
c906108c SS |
1135 | | direct_abs_decl array_mod |
1136 | { | |
fcde5961 | 1137 | push_type_stack ($1); |
c906108c SS |
1138 | push_type_int ($2); |
1139 | push_type (tp_array); | |
fcde5961 | 1140 | $$ = get_type_stack (); |
c906108c SS |
1141 | } |
1142 | | array_mod | |
1143 | { | |
1144 | push_type_int ($1); | |
1145 | push_type (tp_array); | |
fcde5961 | 1146 | $$ = get_type_stack (); |
c906108c SS |
1147 | } |
1148 | ||
1149 | | direct_abs_decl func_mod | |
fcde5961 TT |
1150 | { |
1151 | push_type_stack ($1); | |
71918a86 | 1152 | push_typelist ($2); |
fcde5961 TT |
1153 | $$ = get_type_stack (); |
1154 | } | |
c906108c | 1155 | | func_mod |
fcde5961 | 1156 | { |
71918a86 | 1157 | push_typelist ($1); |
fcde5961 TT |
1158 | $$ = get_type_stack (); |
1159 | } | |
c906108c SS |
1160 | ; |
1161 | ||
1162 | array_mod: '[' ']' | |
1163 | { $$ = -1; } | |
f2e8016f TT |
1164 | | OBJC_LBRAC ']' |
1165 | { $$ = -1; } | |
c906108c SS |
1166 | | '[' INT ']' |
1167 | { $$ = $2.val; } | |
f2e8016f TT |
1168 | | OBJC_LBRAC INT ']' |
1169 | { $$ = $2.val; } | |
c906108c SS |
1170 | ; |
1171 | ||
1172 | func_mod: '(' ')' | |
71918a86 | 1173 | { $$ = NULL; } |
a6fb9c08 | 1174 | | '(' parameter_typelist ')' |
71918a86 | 1175 | { $$ = $2; } |
c906108c SS |
1176 | ; |
1177 | ||
a22229c4 | 1178 | /* We used to try to recognize pointer to member types here, but |
c906108c SS |
1179 | that didn't work (shift/reduce conflicts meant that these rules never |
1180 | got executed). The problem is that | |
1181 | int (foo::bar::baz::bizzle) | |
1182 | is a function type but | |
1183 | int (foo::bar::baz::bizzle::*) | |
1184 | is a pointer to member type. Stroustrup loses again! */ | |
1185 | ||
1186 | type : ptype | |
c906108c SS |
1187 | ; |
1188 | ||
1189 | typebase /* Implements (approximately): (type-qualifier)* type-specifier */ | |
1190 | : TYPENAME | |
1191 | { $$ = $1.type; } | |
1192 | | INT_KEYWORD | |
f4b8a18d KW |
1193 | { $$ = lookup_signed_typename (parse_language, |
1194 | parse_gdbarch, | |
1195 | "int"); } | |
c906108c | 1196 | | LONG |
f4b8a18d KW |
1197 | { $$ = lookup_signed_typename (parse_language, |
1198 | parse_gdbarch, | |
1199 | "long"); } | |
c906108c | 1200 | | SHORT |
f4b8a18d KW |
1201 | { $$ = lookup_signed_typename (parse_language, |
1202 | parse_gdbarch, | |
1203 | "short"); } | |
c906108c | 1204 | | LONG INT_KEYWORD |
f4b8a18d KW |
1205 | { $$ = lookup_signed_typename (parse_language, |
1206 | parse_gdbarch, | |
1207 | "long"); } | |
b2c4da81 | 1208 | | LONG SIGNED_KEYWORD INT_KEYWORD |
f4b8a18d KW |
1209 | { $$ = lookup_signed_typename (parse_language, |
1210 | parse_gdbarch, | |
1211 | "long"); } | |
b2c4da81 | 1212 | | LONG SIGNED_KEYWORD |
f4b8a18d KW |
1213 | { $$ = lookup_signed_typename (parse_language, |
1214 | parse_gdbarch, | |
1215 | "long"); } | |
b2c4da81 | 1216 | | SIGNED_KEYWORD LONG INT_KEYWORD |
f4b8a18d KW |
1217 | { $$ = lookup_signed_typename (parse_language, |
1218 | parse_gdbarch, | |
1219 | "long"); } | |
c906108c | 1220 | | UNSIGNED LONG INT_KEYWORD |
f4b8a18d KW |
1221 | { $$ = lookup_unsigned_typename (parse_language, |
1222 | parse_gdbarch, | |
1223 | "long"); } | |
b2c4da81 | 1224 | | LONG UNSIGNED INT_KEYWORD |
f4b8a18d KW |
1225 | { $$ = lookup_unsigned_typename (parse_language, |
1226 | parse_gdbarch, | |
1227 | "long"); } | |
b2c4da81 | 1228 | | LONG UNSIGNED |
f4b8a18d KW |
1229 | { $$ = lookup_unsigned_typename (parse_language, |
1230 | parse_gdbarch, | |
1231 | "long"); } | |
c906108c | 1232 | | LONG LONG |
f4b8a18d KW |
1233 | { $$ = lookup_signed_typename (parse_language, |
1234 | parse_gdbarch, | |
1235 | "long long"); } | |
c906108c | 1236 | | LONG LONG INT_KEYWORD |
f4b8a18d KW |
1237 | { $$ = lookup_signed_typename (parse_language, |
1238 | parse_gdbarch, | |
1239 | "long long"); } | |
b2c4da81 | 1240 | | LONG LONG SIGNED_KEYWORD INT_KEYWORD |
f4b8a18d KW |
1241 | { $$ = lookup_signed_typename (parse_language, |
1242 | parse_gdbarch, | |
1243 | "long long"); } | |
b2c4da81 | 1244 | | LONG LONG SIGNED_KEYWORD |
f4b8a18d KW |
1245 | { $$ = lookup_signed_typename (parse_language, |
1246 | parse_gdbarch, | |
1247 | "long long"); } | |
b2c4da81 | 1248 | | SIGNED_KEYWORD LONG LONG |
f4b8a18d KW |
1249 | { $$ = lookup_signed_typename (parse_language, |
1250 | parse_gdbarch, | |
1251 | "long long"); } | |
55baeb84 | 1252 | | SIGNED_KEYWORD LONG LONG INT_KEYWORD |
f4b8a18d KW |
1253 | { $$ = lookup_signed_typename (parse_language, |
1254 | parse_gdbarch, | |
1255 | "long long"); } | |
c906108c | 1256 | | UNSIGNED LONG LONG |
f4b8a18d KW |
1257 | { $$ = lookup_unsigned_typename (parse_language, |
1258 | parse_gdbarch, | |
1259 | "long long"); } | |
c906108c | 1260 | | UNSIGNED LONG LONG INT_KEYWORD |
f4b8a18d KW |
1261 | { $$ = lookup_unsigned_typename (parse_language, |
1262 | parse_gdbarch, | |
1263 | "long long"); } | |
b2c4da81 | 1264 | | LONG LONG UNSIGNED |
f4b8a18d KW |
1265 | { $$ = lookup_unsigned_typename (parse_language, |
1266 | parse_gdbarch, | |
1267 | "long long"); } | |
b2c4da81 | 1268 | | LONG LONG UNSIGNED INT_KEYWORD |
f4b8a18d KW |
1269 | { $$ = lookup_unsigned_typename (parse_language, |
1270 | parse_gdbarch, | |
1271 | "long long"); } | |
c906108c | 1272 | | SHORT INT_KEYWORD |
f4b8a18d KW |
1273 | { $$ = lookup_signed_typename (parse_language, |
1274 | parse_gdbarch, | |
1275 | "short"); } | |
b2c4da81 | 1276 | | SHORT SIGNED_KEYWORD INT_KEYWORD |
f4b8a18d KW |
1277 | { $$ = lookup_signed_typename (parse_language, |
1278 | parse_gdbarch, | |
1279 | "short"); } | |
b2c4da81 | 1280 | | SHORT SIGNED_KEYWORD |
f4b8a18d KW |
1281 | { $$ = lookup_signed_typename (parse_language, |
1282 | parse_gdbarch, | |
1283 | "short"); } | |
c906108c | 1284 | | UNSIGNED SHORT INT_KEYWORD |
f4b8a18d KW |
1285 | { $$ = lookup_unsigned_typename (parse_language, |
1286 | parse_gdbarch, | |
1287 | "short"); } | |
b2c4da81 | 1288 | | SHORT UNSIGNED |
f4b8a18d KW |
1289 | { $$ = lookup_unsigned_typename (parse_language, |
1290 | parse_gdbarch, | |
1291 | "short"); } | |
b2c4da81 | 1292 | | SHORT UNSIGNED INT_KEYWORD |
f4b8a18d KW |
1293 | { $$ = lookup_unsigned_typename (parse_language, |
1294 | parse_gdbarch, | |
1295 | "short"); } | |
c906108c | 1296 | | DOUBLE_KEYWORD |
f4b8a18d KW |
1297 | { $$ = lookup_typename (parse_language, parse_gdbarch, |
1298 | "double", (struct block *) NULL, | |
1299 | 0); } | |
c906108c | 1300 | | LONG DOUBLE_KEYWORD |
f4b8a18d KW |
1301 | { $$ = lookup_typename (parse_language, parse_gdbarch, |
1302 | "long double", | |
1303 | (struct block *) NULL, 0); } | |
c906108c SS |
1304 | | STRUCT name |
1305 | { $$ = lookup_struct (copy_name ($2), | |
1306 | expression_context_block); } | |
2f68a895 TT |
1307 | | STRUCT COMPLETE |
1308 | { | |
1309 | mark_completion_tag (TYPE_CODE_STRUCT, "", 0); | |
1310 | $$ = NULL; | |
1311 | } | |
1312 | | STRUCT name COMPLETE | |
1313 | { | |
1314 | mark_completion_tag (TYPE_CODE_STRUCT, $2.ptr, | |
1315 | $2.length); | |
1316 | $$ = NULL; | |
1317 | } | |
c906108c SS |
1318 | | CLASS name |
1319 | { $$ = lookup_struct (copy_name ($2), | |
1320 | expression_context_block); } | |
2f68a895 TT |
1321 | | CLASS COMPLETE |
1322 | { | |
1323 | mark_completion_tag (TYPE_CODE_CLASS, "", 0); | |
1324 | $$ = NULL; | |
1325 | } | |
1326 | | CLASS name COMPLETE | |
1327 | { | |
1328 | mark_completion_tag (TYPE_CODE_CLASS, $2.ptr, | |
1329 | $2.length); | |
1330 | $$ = NULL; | |
1331 | } | |
c906108c SS |
1332 | | UNION name |
1333 | { $$ = lookup_union (copy_name ($2), | |
1334 | expression_context_block); } | |
2f68a895 TT |
1335 | | UNION COMPLETE |
1336 | { | |
1337 | mark_completion_tag (TYPE_CODE_UNION, "", 0); | |
1338 | $$ = NULL; | |
1339 | } | |
1340 | | UNION name COMPLETE | |
1341 | { | |
1342 | mark_completion_tag (TYPE_CODE_UNION, $2.ptr, | |
1343 | $2.length); | |
1344 | $$ = NULL; | |
1345 | } | |
c906108c SS |
1346 | | ENUM name |
1347 | { $$ = lookup_enum (copy_name ($2), | |
1348 | expression_context_block); } | |
2f68a895 TT |
1349 | | ENUM COMPLETE |
1350 | { | |
1351 | mark_completion_tag (TYPE_CODE_ENUM, "", 0); | |
1352 | $$ = NULL; | |
1353 | } | |
1354 | | ENUM name COMPLETE | |
1355 | { | |
1356 | mark_completion_tag (TYPE_CODE_ENUM, $2.ptr, | |
1357 | $2.length); | |
1358 | $$ = NULL; | |
1359 | } | |
c906108c | 1360 | | UNSIGNED typename |
e6c014f2 UW |
1361 | { $$ = lookup_unsigned_typename (parse_language, |
1362 | parse_gdbarch, | |
1363 | TYPE_NAME($2.type)); } | |
c906108c | 1364 | | UNSIGNED |
f4b8a18d KW |
1365 | { $$ = lookup_unsigned_typename (parse_language, |
1366 | parse_gdbarch, | |
1367 | "int"); } | |
c906108c | 1368 | | SIGNED_KEYWORD typename |
e6c014f2 UW |
1369 | { $$ = lookup_signed_typename (parse_language, |
1370 | parse_gdbarch, | |
1371 | TYPE_NAME($2.type)); } | |
c906108c | 1372 | | SIGNED_KEYWORD |
f4b8a18d KW |
1373 | { $$ = lookup_signed_typename (parse_language, |
1374 | parse_gdbarch, | |
1375 | "int"); } | |
c906108c SS |
1376 | /* It appears that this rule for templates is never |
1377 | reduced; template recognition happens by lookahead | |
1378 | in the token processing code in yylex. */ | |
1379 | | TEMPLATE name '<' type '>' | |
1380 | { $$ = lookup_template_type(copy_name($2), $4, | |
1381 | expression_context_block); | |
1382 | } | |
47663de5 MS |
1383 | | const_or_volatile_or_space_identifier_noopt typebase |
1384 | { $$ = follow_types ($2); } | |
1385 | | typebase const_or_volatile_or_space_identifier_noopt | |
1386 | { $$ = follow_types ($1); } | |
c906108c SS |
1387 | ; |
1388 | ||
1389 | typename: TYPENAME | |
1390 | | INT_KEYWORD | |
1391 | { | |
1392 | $$.stoken.ptr = "int"; | |
1393 | $$.stoken.length = 3; | |
f4b8a18d KW |
1394 | $$.type = lookup_signed_typename (parse_language, |
1395 | parse_gdbarch, | |
1396 | "int"); | |
c906108c SS |
1397 | } |
1398 | | LONG | |
1399 | { | |
1400 | $$.stoken.ptr = "long"; | |
1401 | $$.stoken.length = 4; | |
f4b8a18d KW |
1402 | $$.type = lookup_signed_typename (parse_language, |
1403 | parse_gdbarch, | |
1404 | "long"); | |
c906108c SS |
1405 | } |
1406 | | SHORT | |
1407 | { | |
1408 | $$.stoken.ptr = "short"; | |
1409 | $$.stoken.length = 5; | |
f4b8a18d KW |
1410 | $$.type = lookup_signed_typename (parse_language, |
1411 | parse_gdbarch, | |
1412 | "short"); | |
c906108c SS |
1413 | } |
1414 | ; | |
1415 | ||
a6fb9c08 TT |
1416 | parameter_typelist: |
1417 | nonempty_typelist | |
e314d629 | 1418 | { check_parameter_typelist ($1); } |
a6fb9c08 TT |
1419 | | nonempty_typelist ',' DOTDOTDOT |
1420 | { | |
1421 | VEC_safe_push (type_ptr, $1, NULL); | |
e314d629 | 1422 | check_parameter_typelist ($1); |
a6fb9c08 TT |
1423 | $$ = $1; |
1424 | } | |
1425 | ; | |
1426 | ||
c906108c SS |
1427 | nonempty_typelist |
1428 | : type | |
71918a86 TT |
1429 | { |
1430 | VEC (type_ptr) *typelist = NULL; | |
1431 | VEC_safe_push (type_ptr, typelist, $1); | |
1432 | $$ = typelist; | |
c906108c SS |
1433 | } |
1434 | | nonempty_typelist ',' type | |
71918a86 TT |
1435 | { |
1436 | VEC_safe_push (type_ptr, $1, $3); | |
1437 | $$ = $1; | |
c906108c SS |
1438 | } |
1439 | ; | |
1440 | ||
47663de5 | 1441 | ptype : typebase |
95c391b6 | 1442 | | ptype abs_decl |
fcde5961 TT |
1443 | { |
1444 | push_type_stack ($2); | |
1445 | $$ = follow_types ($1); | |
1446 | } | |
47663de5 MS |
1447 | ; |
1448 | ||
95c391b6 TT |
1449 | conversion_type_id: typebase conversion_declarator |
1450 | { $$ = follow_types ($1); } | |
1451 | ; | |
1452 | ||
1453 | conversion_declarator: /* Nothing. */ | |
1454 | | ptr_operator conversion_declarator | |
1455 | ; | |
1456 | ||
47663de5 MS |
1457 | const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD |
1458 | | VOLATILE_KEYWORD CONST_KEYWORD | |
1459 | ; | |
1460 | ||
1461 | const_or_volatile_noopt: const_and_volatile | |
95c391b6 TT |
1462 | { insert_type (tp_const); |
1463 | insert_type (tp_volatile); | |
47663de5 MS |
1464 | } |
1465 | | CONST_KEYWORD | |
95c391b6 | 1466 | { insert_type (tp_const); } |
47663de5 | 1467 | | VOLATILE_KEYWORD |
95c391b6 | 1468 | { insert_type (tp_volatile); } |
47663de5 MS |
1469 | ; |
1470 | ||
66c53f2b KS |
1471 | operator: OPERATOR NEW |
1472 | { $$ = operator_stoken (" new"); } | |
1473 | | OPERATOR DELETE | |
4cd18215 | 1474 | { $$ = operator_stoken (" delete"); } |
66c53f2b KS |
1475 | | OPERATOR NEW '[' ']' |
1476 | { $$ = operator_stoken (" new[]"); } | |
1477 | | OPERATOR DELETE '[' ']' | |
4cd18215 | 1478 | { $$ = operator_stoken (" delete[]"); } |
f2e8016f TT |
1479 | | OPERATOR NEW OBJC_LBRAC ']' |
1480 | { $$ = operator_stoken (" new[]"); } | |
1481 | | OPERATOR DELETE OBJC_LBRAC ']' | |
1482 | { $$ = operator_stoken (" delete[]"); } | |
66c53f2b KS |
1483 | | OPERATOR '+' |
1484 | { $$ = operator_stoken ("+"); } | |
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 ASSIGN_MODIFY | |
1510 | { const char *op = "unknown"; | |
1511 | switch ($2) | |
1512 | { | |
1513 | case BINOP_RSH: | |
1514 | op = ">>="; | |
1515 | break; | |
1516 | case BINOP_LSH: | |
1517 | op = "<<="; | |
1518 | break; | |
1519 | case BINOP_ADD: | |
1520 | op = "+="; | |
1521 | break; | |
1522 | case BINOP_SUB: | |
1523 | op = "-="; | |
1524 | break; | |
1525 | case BINOP_MUL: | |
1526 | op = "*="; | |
1527 | break; | |
1528 | case BINOP_DIV: | |
1529 | op = "/="; | |
1530 | break; | |
1531 | case BINOP_REM: | |
1532 | op = "%="; | |
1533 | break; | |
1534 | case BINOP_BITWISE_IOR: | |
1535 | op = "|="; | |
1536 | break; | |
1537 | case BINOP_BITWISE_AND: | |
1538 | op = "&="; | |
1539 | break; | |
1540 | case BINOP_BITWISE_XOR: | |
1541 | op = "^="; | |
1542 | break; | |
1543 | default: | |
1544 | break; | |
1545 | } | |
1546 | ||
1547 | $$ = operator_stoken (op); | |
1548 | } | |
1549 | | OPERATOR LSH | |
1550 | { $$ = operator_stoken ("<<"); } | |
1551 | | OPERATOR RSH | |
1552 | { $$ = operator_stoken (">>"); } | |
1553 | | OPERATOR EQUAL | |
1554 | { $$ = operator_stoken ("=="); } | |
1555 | | OPERATOR NOTEQUAL | |
1556 | { $$ = operator_stoken ("!="); } | |
1557 | | OPERATOR LEQ | |
1558 | { $$ = operator_stoken ("<="); } | |
1559 | | OPERATOR GEQ | |
1560 | { $$ = operator_stoken (">="); } | |
1561 | | OPERATOR ANDAND | |
1562 | { $$ = operator_stoken ("&&"); } | |
1563 | | OPERATOR OROR | |
1564 | { $$ = operator_stoken ("||"); } | |
1565 | | OPERATOR INCREMENT | |
1566 | { $$ = operator_stoken ("++"); } | |
1567 | | OPERATOR DECREMENT | |
1568 | { $$ = operator_stoken ("--"); } | |
1569 | | OPERATOR ',' | |
1570 | { $$ = operator_stoken (","); } | |
1571 | | OPERATOR ARROW_STAR | |
1572 | { $$ = operator_stoken ("->*"); } | |
1573 | | OPERATOR ARROW | |
1574 | { $$ = operator_stoken ("->"); } | |
1575 | | OPERATOR '(' ')' | |
1576 | { $$ = operator_stoken ("()"); } | |
1577 | | OPERATOR '[' ']' | |
1578 | { $$ = operator_stoken ("[]"); } | |
f2e8016f TT |
1579 | | OPERATOR OBJC_LBRAC ']' |
1580 | { $$ = operator_stoken ("[]"); } | |
95c391b6 | 1581 | | OPERATOR conversion_type_id |
66c53f2b KS |
1582 | { char *name; |
1583 | long length; | |
1584 | struct ui_file *buf = mem_fileopen (); | |
1585 | ||
79d43c61 TT |
1586 | c_print_type ($2, NULL, buf, -1, 0, |
1587 | &type_print_raw_options); | |
66c53f2b KS |
1588 | name = ui_file_xstrdup (buf, &length); |
1589 | ui_file_delete (buf); | |
1590 | $$ = operator_stoken (name); | |
1591 | free (name); | |
1592 | } | |
1593 | ; | |
1594 | ||
1595 | ||
1596 | ||
c906108c SS |
1597 | name : NAME { $$ = $1.stoken; } |
1598 | | BLOCKNAME { $$ = $1.stoken; } | |
1599 | | TYPENAME { $$ = $1.stoken; } | |
1600 | | NAME_OR_INT { $$ = $1.stoken; } | |
7322dca9 | 1601 | | UNKNOWN_CPP_NAME { $$ = $1.stoken; } |
66c53f2b | 1602 | | operator { $$ = $1; } |
c906108c SS |
1603 | ; |
1604 | ||
1605 | name_not_typename : NAME | |
1606 | | BLOCKNAME | |
1607 | /* These would be useful if name_not_typename was useful, but it is just | |
1608 | a fake for "variable", so these cause reduce/reduce conflicts because | |
1609 | the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable, | |
1610 | =exp) or just an exp. If name_not_typename was ever used in an lvalue | |
1611 | context where only a name could occur, this might be useful. | |
1612 | | NAME_OR_INT | |
1613 | */ | |
6e31430b TT |
1614 | | operator |
1615 | { | |
1993b719 TT |
1616 | struct field_of_this_result is_a_field_of_this; |
1617 | ||
6e31430b TT |
1618 | $$.stoken = $1; |
1619 | $$.sym = lookup_symbol ($1.ptr, | |
1620 | expression_context_block, | |
1621 | VAR_DOMAIN, | |
1993b719 TT |
1622 | &is_a_field_of_this); |
1623 | $$.is_a_field_of_this | |
1624 | = is_a_field_of_this.type != NULL; | |
6e31430b | 1625 | } |
7322dca9 | 1626 | | UNKNOWN_CPP_NAME |
c906108c SS |
1627 | ; |
1628 | ||
1629 | %% | |
1630 | ||
24955f63 TT |
1631 | /* Like write_exp_string, but prepends a '~'. */ |
1632 | ||
1633 | static void | |
1634 | write_destructor_name (struct stoken token) | |
1635 | { | |
1636 | char *copy = alloca (token.length + 1); | |
1637 | ||
1638 | copy[0] = '~'; | |
1639 | memcpy (©[1], token.ptr, token.length); | |
1640 | ||
1641 | token.ptr = copy; | |
1642 | ++token.length; | |
1643 | ||
1644 | write_exp_string (token); | |
1645 | } | |
1646 | ||
66c53f2b KS |
1647 | /* Returns a stoken of the operator name given by OP (which does not |
1648 | include the string "operator"). */ | |
1649 | static struct stoken | |
1650 | operator_stoken (const char *op) | |
1651 | { | |
1652 | static const char *operator_string = "operator"; | |
1653 | struct stoken st = { NULL, 0 }; | |
1654 | st.length = strlen (operator_string) + strlen (op); | |
1655 | st.ptr = malloc (st.length + 1); | |
1656 | strcpy (st.ptr, operator_string); | |
1657 | strcat (st.ptr, op); | |
1658 | ||
1659 | /* The toplevel (c_parse) will free the memory allocated here. */ | |
1660 | make_cleanup (free, st.ptr); | |
1661 | return st; | |
1662 | }; | |
1663 | ||
e314d629 TT |
1664 | /* Validate a parameter typelist. */ |
1665 | ||
1666 | static void | |
1667 | check_parameter_typelist (VEC (type_ptr) *params) | |
1668 | { | |
1669 | struct type *type; | |
1670 | int ix; | |
1671 | ||
1672 | for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix) | |
1673 | { | |
1674 | if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID) | |
1675 | { | |
1676 | if (ix == 0) | |
1677 | { | |
1678 | if (VEC_length (type_ptr, params) == 1) | |
1679 | { | |
1680 | /* Ok. */ | |
1681 | break; | |
1682 | } | |
1683 | VEC_free (type_ptr, params); | |
1684 | error (_("parameter types following 'void'")); | |
1685 | } | |
1686 | else | |
1687 | { | |
1688 | VEC_free (type_ptr, params); | |
1689 | error (_("'void' invalid as parameter type")); | |
1690 | } | |
1691 | } | |
1692 | } | |
1693 | } | |
1694 | ||
c906108c SS |
1695 | /* Take care of parsing a number (anything that starts with a digit). |
1696 | Set yylval and return the token type; update lexptr. | |
1697 | LEN is the number of characters in it. */ | |
1698 | ||
1699 | /*** Needs some error checking for the float case ***/ | |
1700 | ||
1701 | static int | |
68c1b02d | 1702 | parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) |
c906108c SS |
1703 | { |
1704 | /* FIXME: Shouldn't these be unsigned? We don't deal with negative values | |
1705 | here, and we do kind of silly things like cast to unsigned. */ | |
710122da DC |
1706 | LONGEST n = 0; |
1707 | LONGEST prevn = 0; | |
c906108c SS |
1708 | ULONGEST un; |
1709 | ||
710122da DC |
1710 | int i = 0; |
1711 | int c; | |
1712 | int base = input_radix; | |
c906108c SS |
1713 | int unsigned_p = 0; |
1714 | ||
1715 | /* Number of "L" suffixes encountered. */ | |
1716 | int long_p = 0; | |
1717 | ||
1718 | /* We have found a "L" or "U" suffix. */ | |
1719 | int found_suffix = 0; | |
1720 | ||
1721 | ULONGEST high_bit; | |
1722 | struct type *signed_type; | |
1723 | struct type *unsigned_type; | |
1724 | ||
1725 | if (parsed_float) | |
1726 | { | |
27bc4d80 TJB |
1727 | /* If it ends at "df", "dd" or "dl", take it as type of decimal floating |
1728 | point. Return DECFLOAT. */ | |
1729 | ||
fe9441f6 | 1730 | if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f') |
27bc4d80 TJB |
1731 | { |
1732 | p[len - 2] = '\0'; | |
1733 | putithere->typed_val_decfloat.type | |
3e79cecf | 1734 | = parse_type->builtin_decfloat; |
e17a4113 UW |
1735 | decimal_from_string (putithere->typed_val_decfloat.val, 4, |
1736 | gdbarch_byte_order (parse_gdbarch), p); | |
fe9441f6 JK |
1737 | p[len - 2] = 'd'; |
1738 | return DECFLOAT; | |
27bc4d80 TJB |
1739 | } |
1740 | ||
fe9441f6 | 1741 | if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd') |
27bc4d80 TJB |
1742 | { |
1743 | p[len - 2] = '\0'; | |
1744 | putithere->typed_val_decfloat.type | |
3e79cecf | 1745 | = parse_type->builtin_decdouble; |
e17a4113 UW |
1746 | decimal_from_string (putithere->typed_val_decfloat.val, 8, |
1747 | gdbarch_byte_order (parse_gdbarch), p); | |
fe9441f6 JK |
1748 | p[len - 2] = 'd'; |
1749 | return DECFLOAT; | |
27bc4d80 TJB |
1750 | } |
1751 | ||
fe9441f6 | 1752 | if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l') |
27bc4d80 TJB |
1753 | { |
1754 | p[len - 2] = '\0'; | |
1755 | putithere->typed_val_decfloat.type | |
3e79cecf | 1756 | = parse_type->builtin_declong; |
e17a4113 UW |
1757 | decimal_from_string (putithere->typed_val_decfloat.val, 16, |
1758 | gdbarch_byte_order (parse_gdbarch), p); | |
fe9441f6 JK |
1759 | p[len - 2] = 'd'; |
1760 | return DECFLOAT; | |
27bc4d80 TJB |
1761 | } |
1762 | ||
d30f5e1f DE |
1763 | if (! parse_c_float (parse_gdbarch, p, len, |
1764 | &putithere->typed_val_float.dval, | |
1765 | &putithere->typed_val_float.type)) | |
1766 | return ERROR; | |
c906108c SS |
1767 | return FLOAT; |
1768 | } | |
1769 | ||
1770 | /* Handle base-switching prefixes 0x, 0t, 0d, 0 */ | |
1771 | if (p[0] == '0') | |
1772 | switch (p[1]) | |
1773 | { | |
1774 | case 'x': | |
1775 | case 'X': | |
1776 | if (len >= 3) | |
1777 | { | |
1778 | p += 2; | |
1779 | base = 16; | |
1780 | len -= 2; | |
1781 | } | |
1782 | break; | |
1783 | ||
b5cfddf5 JK |
1784 | case 'b': |
1785 | case 'B': | |
1786 | if (len >= 3) | |
1787 | { | |
1788 | p += 2; | |
1789 | base = 2; | |
1790 | len -= 2; | |
1791 | } | |
1792 | break; | |
1793 | ||
c906108c SS |
1794 | case 't': |
1795 | case 'T': | |
1796 | case 'd': | |
1797 | case 'D': | |
1798 | if (len >= 3) | |
1799 | { | |
1800 | p += 2; | |
1801 | base = 10; | |
1802 | len -= 2; | |
1803 | } | |
1804 | break; | |
1805 | ||
1806 | default: | |
1807 | base = 8; | |
1808 | break; | |
1809 | } | |
1810 | ||
1811 | while (len-- > 0) | |
1812 | { | |
1813 | c = *p++; | |
1814 | if (c >= 'A' && c <= 'Z') | |
1815 | c += 'a' - 'A'; | |
1816 | if (c != 'l' && c != 'u') | |
1817 | n *= base; | |
1818 | if (c >= '0' && c <= '9') | |
1819 | { | |
1820 | if (found_suffix) | |
1821 | return ERROR; | |
1822 | n += i = c - '0'; | |
1823 | } | |
1824 | else | |
1825 | { | |
1826 | if (base > 10 && c >= 'a' && c <= 'f') | |
1827 | { | |
1828 | if (found_suffix) | |
1829 | return ERROR; | |
1830 | n += i = c - 'a' + 10; | |
1831 | } | |
1832 | else if (c == 'l') | |
1833 | { | |
1834 | ++long_p; | |
1835 | found_suffix = 1; | |
1836 | } | |
1837 | else if (c == 'u') | |
1838 | { | |
1839 | unsigned_p = 1; | |
1840 | found_suffix = 1; | |
1841 | } | |
1842 | else | |
1843 | return ERROR; /* Char not a digit */ | |
1844 | } | |
1845 | if (i >= base) | |
1846 | return ERROR; /* Invalid digit in this base */ | |
1847 | ||
1848 | /* Portably test for overflow (only works for nonzero values, so make | |
1849 | a second check for zero). FIXME: Can't we just make n and prevn | |
1850 | unsigned and avoid this? */ | |
1851 | if (c != 'l' && c != 'u' && (prevn >= n) && n != 0) | |
1852 | unsigned_p = 1; /* Try something unsigned */ | |
1853 | ||
1854 | /* Portably test for unsigned overflow. | |
1855 | FIXME: This check is wrong; for example it doesn't find overflow | |
1856 | on 0x123456789 when LONGEST is 32 bits. */ | |
1857 | if (c != 'l' && c != 'u' && n != 0) | |
1858 | { | |
1859 | if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n)) | |
001083c6 | 1860 | error (_("Numeric constant too large.")); |
c906108c SS |
1861 | } |
1862 | prevn = n; | |
1863 | } | |
1864 | ||
1865 | /* An integer constant is an int, a long, or a long long. An L | |
1866 | suffix forces it to be long; an LL suffix forces it to be long | |
1867 | long. If not forced to a larger size, it gets the first type of | |
1868 | the above that it fits in. To figure out whether it fits, we | |
1869 | shift it right and see whether anything remains. Note that we | |
1870 | can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one | |
1871 | operation, because many compilers will warn about such a shift | |
9a76efb6 UW |
1872 | (which always produces a zero result). Sometimes gdbarch_int_bit |
1873 | or gdbarch_long_bit will be that big, sometimes not. To deal with | |
c906108c SS |
1874 | the case where it is we just always shift the value more than |
1875 | once, with fewer bits each time. */ | |
1876 | ||
1877 | un = (ULONGEST)n >> 2; | |
1878 | if (long_p == 0 | |
3e79cecf | 1879 | && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0) |
c906108c | 1880 | { |
3e79cecf | 1881 | high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1); |
c906108c SS |
1882 | |
1883 | /* A large decimal (not hex or octal) constant (between INT_MAX | |
1884 | and UINT_MAX) is a long or unsigned long, according to ANSI, | |
1885 | never an unsigned int, but this code treats it as unsigned | |
1886 | int. This probably should be fixed. GCC gives a warning on | |
1887 | such constants. */ | |
1888 | ||
3e79cecf UW |
1889 | unsigned_type = parse_type->builtin_unsigned_int; |
1890 | signed_type = parse_type->builtin_int; | |
c906108c SS |
1891 | } |
1892 | else if (long_p <= 1 | |
3e79cecf | 1893 | && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0) |
c906108c | 1894 | { |
3e79cecf UW |
1895 | high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1); |
1896 | unsigned_type = parse_type->builtin_unsigned_long; | |
1897 | signed_type = parse_type->builtin_long; | |
c906108c SS |
1898 | } |
1899 | else | |
1900 | { | |
1901 | int shift; | |
9a76efb6 | 1902 | if (sizeof (ULONGEST) * HOST_CHAR_BIT |
3e79cecf | 1903 | < gdbarch_long_long_bit (parse_gdbarch)) |
c906108c SS |
1904 | /* A long long does not fit in a LONGEST. */ |
1905 | shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1); | |
1906 | else | |
3e79cecf | 1907 | shift = (gdbarch_long_long_bit (parse_gdbarch) - 1); |
c906108c | 1908 | high_bit = (ULONGEST) 1 << shift; |
3e79cecf UW |
1909 | unsigned_type = parse_type->builtin_unsigned_long_long; |
1910 | signed_type = parse_type->builtin_long_long; | |
c906108c SS |
1911 | } |
1912 | ||
1913 | putithere->typed_val_int.val = n; | |
1914 | ||
1915 | /* If the high bit of the worked out type is set then this number | |
1916 | has to be unsigned. */ | |
1917 | ||
1918 | if (unsigned_p || (n & high_bit)) | |
1919 | { | |
1920 | putithere->typed_val_int.type = unsigned_type; | |
1921 | } | |
1922 | else | |
1923 | { | |
1924 | putithere->typed_val_int.type = signed_type; | |
1925 | } | |
1926 | ||
1927 | return INT; | |
1928 | } | |
1929 | ||
6c7a06a3 TT |
1930 | /* Temporary obstack used for holding strings. */ |
1931 | static struct obstack tempbuf; | |
1932 | static int tempbuf_init; | |
1933 | ||
1934 | /* Parse a C escape sequence. The initial backslash of the sequence | |
1935 | is at (*PTR)[-1]. *PTR will be updated to point to just after the | |
1936 | last character of the sequence. If OUTPUT is not NULL, the | |
1937 | translated form of the escape sequence will be written there. If | |
1938 | OUTPUT is NULL, no output is written and the call will only affect | |
1939 | *PTR. If an escape sequence is expressed in target bytes, then the | |
1940 | entire sequence will simply be copied to OUTPUT. Return 1 if any | |
1941 | character was emitted, 0 otherwise. */ | |
1942 | ||
1943 | int | |
1944 | c_parse_escape (char **ptr, struct obstack *output) | |
1945 | { | |
1946 | char *tokptr = *ptr; | |
1947 | int result = 1; | |
1948 | ||
1949 | /* Some escape sequences undergo character set conversion. Those we | |
1950 | translate here. */ | |
1951 | switch (*tokptr) | |
1952 | { | |
1953 | /* Hex escapes do not undergo character set conversion, so keep | |
1954 | the escape sequence for later. */ | |
1955 | case 'x': | |
1956 | if (output) | |
1957 | obstack_grow_str (output, "\\x"); | |
1958 | ++tokptr; | |
1959 | if (!isxdigit (*tokptr)) | |
1960 | error (_("\\x escape without a following hex digit")); | |
1961 | while (isxdigit (*tokptr)) | |
1962 | { | |
1963 | if (output) | |
1964 | obstack_1grow (output, *tokptr); | |
1965 | ++tokptr; | |
1966 | } | |
1967 | break; | |
1968 | ||
1969 | /* Octal escapes do not undergo character set conversion, so | |
1970 | keep the escape sequence for later. */ | |
1971 | case '0': | |
1972 | case '1': | |
1973 | case '2': | |
1974 | case '3': | |
1975 | case '4': | |
1976 | case '5': | |
1977 | case '6': | |
1978 | case '7': | |
30b66ecc TT |
1979 | { |
1980 | int i; | |
1981 | if (output) | |
1982 | obstack_grow_str (output, "\\"); | |
1983 | for (i = 0; | |
1984 | i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9'; | |
1985 | ++i) | |
1986 | { | |
1987 | if (output) | |
1988 | obstack_1grow (output, *tokptr); | |
1989 | ++tokptr; | |
1990 | } | |
1991 | } | |
6c7a06a3 TT |
1992 | break; |
1993 | ||
1994 | /* We handle UCNs later. We could handle them here, but that | |
1995 | would mean a spurious error in the case where the UCN could | |
1996 | be converted to the target charset but not the host | |
1997 | charset. */ | |
1998 | case 'u': | |
1999 | case 'U': | |
2000 | { | |
2001 | char c = *tokptr; | |
2002 | int i, len = c == 'U' ? 8 : 4; | |
2003 | if (output) | |
2004 | { | |
2005 | obstack_1grow (output, '\\'); | |
2006 | obstack_1grow (output, *tokptr); | |
2007 | } | |
2008 | ++tokptr; | |
2009 | if (!isxdigit (*tokptr)) | |
2010 | error (_("\\%c escape without a following hex digit"), c); | |
2011 | for (i = 0; i < len && isxdigit (*tokptr); ++i) | |
2012 | { | |
2013 | if (output) | |
2014 | obstack_1grow (output, *tokptr); | |
2015 | ++tokptr; | |
2016 | } | |
2017 | } | |
2018 | break; | |
2019 | ||
2020 | /* We must pass backslash through so that it does not | |
2021 | cause quoting during the second expansion. */ | |
2022 | case '\\': | |
2023 | if (output) | |
2024 | obstack_grow_str (output, "\\\\"); | |
2025 | ++tokptr; | |
2026 | break; | |
2027 | ||
2028 | /* Escapes which undergo conversion. */ | |
2029 | case 'a': | |
2030 | if (output) | |
2031 | obstack_1grow (output, '\a'); | |
2032 | ++tokptr; | |
2033 | break; | |
2034 | case 'b': | |
2035 | if (output) | |
2036 | obstack_1grow (output, '\b'); | |
2037 | ++tokptr; | |
2038 | break; | |
2039 | case 'f': | |
2040 | if (output) | |
2041 | obstack_1grow (output, '\f'); | |
2042 | ++tokptr; | |
2043 | break; | |
2044 | case 'n': | |
2045 | if (output) | |
2046 | obstack_1grow (output, '\n'); | |
2047 | ++tokptr; | |
2048 | break; | |
2049 | case 'r': | |
2050 | if (output) | |
2051 | obstack_1grow (output, '\r'); | |
2052 | ++tokptr; | |
2053 | break; | |
2054 | case 't': | |
2055 | if (output) | |
2056 | obstack_1grow (output, '\t'); | |
2057 | ++tokptr; | |
2058 | break; | |
2059 | case 'v': | |
2060 | if (output) | |
2061 | obstack_1grow (output, '\v'); | |
2062 | ++tokptr; | |
2063 | break; | |
2064 | ||
2065 | /* GCC extension. */ | |
2066 | case 'e': | |
2067 | if (output) | |
2068 | obstack_1grow (output, HOST_ESCAPE_CHAR); | |
2069 | ++tokptr; | |
2070 | break; | |
2071 | ||
2072 | /* Backslash-newline expands to nothing at all. */ | |
2073 | case '\n': | |
2074 | ++tokptr; | |
2075 | result = 0; | |
2076 | break; | |
2077 | ||
2078 | /* A few escapes just expand to the character itself. */ | |
2079 | case '\'': | |
2080 | case '\"': | |
2081 | case '?': | |
2082 | /* GCC extensions. */ | |
2083 | case '(': | |
2084 | case '{': | |
2085 | case '[': | |
2086 | case '%': | |
2087 | /* Unrecognized escapes turn into the character itself. */ | |
2088 | default: | |
2089 | if (output) | |
2090 | obstack_1grow (output, *tokptr); | |
2091 | ++tokptr; | |
2092 | break; | |
2093 | } | |
2094 | *ptr = tokptr; | |
2095 | return result; | |
2096 | } | |
2097 | ||
2098 | /* Parse a string or character literal from TOKPTR. The string or | |
2099 | character may be wide or unicode. *OUTPTR is set to just after the | |
2100 | end of the literal in the input string. The resulting token is | |
2101 | stored in VALUE. This returns a token value, either STRING or | |
2102 | CHAR, depending on what was parsed. *HOST_CHARS is set to the | |
2103 | number of host characters in the literal. */ | |
2104 | static int | |
2105 | parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value, | |
2106 | int *host_chars) | |
2107 | { | |
8c5630cb | 2108 | int quote; |
6c7a06a3 | 2109 | enum c_string_type type; |
f2e8016f | 2110 | int is_objc = 0; |
6c7a06a3 TT |
2111 | |
2112 | /* Build the gdb internal form of the input string in tempbuf. Note | |
2113 | that the buffer is null byte terminated *only* for the | |
2114 | convenience of debugging gdb itself and printing the buffer | |
2115 | contents when the buffer contains no embedded nulls. Gdb does | |
2116 | not depend upon the buffer being null byte terminated, it uses | |
2117 | the length string instead. This allows gdb to handle C strings | |
2118 | (as well as strings in other languages) with embedded null | |
2119 | bytes */ | |
2120 | ||
2121 | if (!tempbuf_init) | |
2122 | tempbuf_init = 1; | |
2123 | else | |
2124 | obstack_free (&tempbuf, NULL); | |
2125 | obstack_init (&tempbuf); | |
2126 | ||
2127 | /* Record the string type. */ | |
2128 | if (*tokptr == 'L') | |
2129 | { | |
2130 | type = C_WIDE_STRING; | |
2131 | ++tokptr; | |
2132 | } | |
2133 | else if (*tokptr == 'u') | |
2134 | { | |
2135 | type = C_STRING_16; | |
2136 | ++tokptr; | |
2137 | } | |
2138 | else if (*tokptr == 'U') | |
2139 | { | |
2140 | type = C_STRING_32; | |
2141 | ++tokptr; | |
2142 | } | |
f2e8016f TT |
2143 | else if (*tokptr == '@') |
2144 | { | |
2145 | /* An Objective C string. */ | |
2146 | is_objc = 1; | |
2147 | type = C_STRING; | |
2148 | ++tokptr; | |
2149 | } | |
6c7a06a3 TT |
2150 | else |
2151 | type = C_STRING; | |
2152 | ||
2153 | /* Skip the quote. */ | |
2154 | quote = *tokptr; | |
2155 | if (quote == '\'') | |
2156 | type |= C_CHAR; | |
2157 | ++tokptr; | |
2158 | ||
2159 | *host_chars = 0; | |
2160 | ||
2161 | while (*tokptr) | |
2162 | { | |
2163 | char c = *tokptr; | |
2164 | if (c == '\\') | |
2165 | { | |
2166 | ++tokptr; | |
2167 | *host_chars += c_parse_escape (&tokptr, &tempbuf); | |
2168 | } | |
2169 | else if (c == quote) | |
2170 | break; | |
2171 | else | |
2172 | { | |
2173 | obstack_1grow (&tempbuf, c); | |
2174 | ++tokptr; | |
2175 | /* FIXME: this does the wrong thing with multi-byte host | |
2176 | characters. We could use mbrlen here, but that would | |
2177 | make "set host-charset" a bit less useful. */ | |
2178 | ++*host_chars; | |
2179 | } | |
2180 | } | |
2181 | ||
2182 | if (*tokptr != quote) | |
2183 | { | |
2184 | if (quote == '"') | |
001083c6 | 2185 | error (_("Unterminated string in expression.")); |
6c7a06a3 | 2186 | else |
001083c6 | 2187 | error (_("Unmatched single quote.")); |
6c7a06a3 TT |
2188 | } |
2189 | ++tokptr; | |
2190 | ||
2191 | value->type = type; | |
2192 | value->ptr = obstack_base (&tempbuf); | |
2193 | value->length = obstack_object_size (&tempbuf); | |
2194 | ||
2195 | *outptr = tokptr; | |
2196 | ||
f2e8016f | 2197 | return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR; |
6c7a06a3 TT |
2198 | } |
2199 | ||
274b54d7 TT |
2200 | /* This is used to associate some attributes with a token. */ |
2201 | ||
2202 | enum token_flags | |
2203 | { | |
2204 | /* If this bit is set, the token is C++-only. */ | |
2205 | ||
2206 | FLAG_CXX = 1, | |
2207 | ||
2208 | /* If this bit is set, the token is conditional: if there is a | |
2209 | symbol of the same name, then the token is a symbol; otherwise, | |
2210 | the token is a keyword. */ | |
2211 | ||
2212 | FLAG_SHADOW = 2 | |
2213 | }; | |
2214 | ||
c906108c SS |
2215 | struct token |
2216 | { | |
2217 | char *operator; | |
2218 | int token; | |
2219 | enum exp_opcode opcode; | |
274b54d7 | 2220 | enum token_flags flags; |
c906108c SS |
2221 | }; |
2222 | ||
2223 | static const struct token tokentab3[] = | |
2224 | { | |
ba163c7e | 2225 | {">>=", ASSIGN_MODIFY, BINOP_RSH, 0}, |
c1af96a0 | 2226 | {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0}, |
274b54d7 | 2227 | {"->*", ARROW_STAR, BINOP_END, FLAG_CXX}, |
a6fb9c08 | 2228 | {"...", DOTDOTDOT, BINOP_END, 0} |
c906108c SS |
2229 | }; |
2230 | ||
2231 | static const struct token tokentab2[] = | |
2232 | { | |
ba163c7e TT |
2233 | {"+=", ASSIGN_MODIFY, BINOP_ADD, 0}, |
2234 | {"-=", ASSIGN_MODIFY, BINOP_SUB, 0}, | |
2235 | {"*=", ASSIGN_MODIFY, BINOP_MUL, 0}, | |
2236 | {"/=", ASSIGN_MODIFY, BINOP_DIV, 0}, | |
2237 | {"%=", ASSIGN_MODIFY, BINOP_REM, 0}, | |
2238 | {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0}, | |
2239 | {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0}, | |
2240 | {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0}, | |
2241 | {"++", INCREMENT, BINOP_END, 0}, | |
2242 | {"--", DECREMENT, BINOP_END, 0}, | |
2243 | {"->", ARROW, BINOP_END, 0}, | |
2244 | {"&&", ANDAND, BINOP_END, 0}, | |
2245 | {"||", OROR, BINOP_END, 0}, | |
ec7f2efe KS |
2246 | /* "::" is *not* only C++: gdb overrides its meaning in several |
2247 | different ways, e.g., 'filename'::func, function::variable. */ | |
ba163c7e TT |
2248 | {"::", COLONCOLON, BINOP_END, 0}, |
2249 | {"<<", LSH, BINOP_END, 0}, | |
2250 | {">>", RSH, BINOP_END, 0}, | |
2251 | {"==", EQUAL, BINOP_END, 0}, | |
2252 | {"!=", NOTEQUAL, BINOP_END, 0}, | |
2253 | {"<=", LEQ, BINOP_END, 0}, | |
c1af96a0 | 2254 | {">=", GEQ, BINOP_END, 0}, |
274b54d7 | 2255 | {".*", DOT_STAR, BINOP_END, FLAG_CXX} |
ba163c7e TT |
2256 | }; |
2257 | ||
2258 | /* Identifier-like tokens. */ | |
2259 | static const struct token ident_tokens[] = | |
2260 | { | |
2261 | {"unsigned", UNSIGNED, OP_NULL, 0}, | |
274b54d7 | 2262 | {"template", TEMPLATE, OP_NULL, FLAG_CXX}, |
ba163c7e TT |
2263 | {"volatile", VOLATILE_KEYWORD, OP_NULL, 0}, |
2264 | {"struct", STRUCT, OP_NULL, 0}, | |
2265 | {"signed", SIGNED_KEYWORD, OP_NULL, 0}, | |
2266 | {"sizeof", SIZEOF, OP_NULL, 0}, | |
2267 | {"double", DOUBLE_KEYWORD, OP_NULL, 0}, | |
274b54d7 TT |
2268 | {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX}, |
2269 | {"class", CLASS, OP_NULL, FLAG_CXX}, | |
ba163c7e TT |
2270 | {"union", UNION, OP_NULL, 0}, |
2271 | {"short", SHORT, OP_NULL, 0}, | |
2272 | {"const", CONST_KEYWORD, OP_NULL, 0}, | |
2273 | {"enum", ENUM, OP_NULL, 0}, | |
2274 | {"long", LONG, OP_NULL, 0}, | |
274b54d7 | 2275 | {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX}, |
ba163c7e | 2276 | {"int", INT_KEYWORD, OP_NULL, 0}, |
274b54d7 TT |
2277 | {"new", NEW, OP_NULL, FLAG_CXX}, |
2278 | {"delete", DELETE, OP_NULL, FLAG_CXX}, | |
2279 | {"operator", OPERATOR, OP_NULL, FLAG_CXX}, | |
2280 | ||
2281 | {"and", ANDAND, BINOP_END, FLAG_CXX}, | |
2282 | {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX}, | |
2283 | {"bitand", '&', OP_NULL, FLAG_CXX}, | |
2284 | {"bitor", '|', OP_NULL, FLAG_CXX}, | |
2285 | {"compl", '~', OP_NULL, FLAG_CXX}, | |
2286 | {"not", '!', OP_NULL, FLAG_CXX}, | |
2287 | {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX}, | |
2288 | {"or", OROR, BINOP_END, FLAG_CXX}, | |
2289 | {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX}, | |
2290 | {"xor", '^', OP_NULL, FLAG_CXX}, | |
2291 | {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX}, | |
2292 | ||
2293 | {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX }, | |
2294 | {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX }, | |
2295 | {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX }, | |
608b4967 TT |
2296 | {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX }, |
2297 | ||
2298 | {"__typeof__", TYPEOF, OP_TYPEOF, 0 }, | |
2299 | {"__typeof", TYPEOF, OP_TYPEOF, 0 }, | |
2300 | {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW }, | |
2301 | {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX }, | |
6e72ca20 TT |
2302 | {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW }, |
2303 | ||
2304 | {"typeid", TYPEID, OP_TYPEID, FLAG_CXX} | |
c906108c SS |
2305 | }; |
2306 | ||
7c8adf68 TT |
2307 | /* When we find that lexptr (the global var defined in parse.c) is |
2308 | pointing at a macro invocation, we expand the invocation, and call | |
2309 | scan_macro_expansion to save the old lexptr here and point lexptr | |
2310 | into the expanded text. When we reach the end of that, we call | |
2311 | end_macro_expansion to pop back to the value we saved here. The | |
2312 | macro expansion code promises to return only fully-expanded text, | |
2313 | so we don't need to "push" more than one level. | |
2314 | ||
2315 | This is disgusting, of course. It would be cleaner to do all macro | |
2316 | expansion beforehand, and then hand that to lexptr. But we don't | |
2317 | really know where the expression ends. Remember, in a command like | |
2318 | ||
2319 | (gdb) break *ADDRESS if CONDITION | |
2320 | ||
2321 | we evaluate ADDRESS in the scope of the current frame, but we | |
2322 | evaluate CONDITION in the scope of the breakpoint's location. So | |
2323 | it's simply wrong to try to macro-expand the whole thing at once. */ | |
2324 | static char *macro_original_text; | |
2325 | ||
2326 | /* We save all intermediate macro expansions on this obstack for the | |
2327 | duration of a single parse. The expansion text may sometimes have | |
2328 | to live past the end of the expansion, due to yacc lookahead. | |
2329 | Rather than try to be clever about saving the data for a single | |
2330 | token, we simply keep it all and delete it after parsing has | |
2331 | completed. */ | |
2332 | static struct obstack expansion_obstack; | |
2333 | ||
2334 | static void | |
2335 | scan_macro_expansion (char *expansion) | |
2336 | { | |
2337 | char *copy; | |
2338 | ||
2339 | /* We'd better not be trying to push the stack twice. */ | |
2340 | gdb_assert (! macro_original_text); | |
2341 | ||
2342 | /* Copy to the obstack, and then free the intermediate | |
2343 | expansion. */ | |
2344 | copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion)); | |
2345 | xfree (expansion); | |
2346 | ||
2347 | /* Save the old lexptr value, so we can return to it when we're done | |
2348 | parsing the expanded text. */ | |
2349 | macro_original_text = lexptr; | |
2350 | lexptr = copy; | |
2351 | } | |
2352 | ||
2353 | ||
2354 | static int | |
2355 | scanning_macro_expansion (void) | |
2356 | { | |
2357 | return macro_original_text != 0; | |
2358 | } | |
2359 | ||
2360 | ||
2361 | static void | |
2362 | finished_macro_expansion (void) | |
2363 | { | |
2364 | /* There'd better be something to pop back to. */ | |
2365 | gdb_assert (macro_original_text); | |
2366 | ||
2367 | /* Pop back to the original text. */ | |
2368 | lexptr = macro_original_text; | |
2369 | macro_original_text = 0; | |
2370 | } | |
2371 | ||
2372 | ||
2373 | static void | |
2374 | scan_macro_cleanup (void *dummy) | |
2375 | { | |
2376 | if (macro_original_text) | |
2377 | finished_macro_expansion (); | |
2378 | ||
2379 | obstack_free (&expansion_obstack, NULL); | |
2380 | } | |
2381 | ||
4e8f195d TT |
2382 | /* Return true iff the token represents a C++ cast operator. */ |
2383 | ||
2384 | static int | |
2385 | is_cast_operator (const char *token, int len) | |
2386 | { | |
2387 | return (! strncmp (token, "dynamic_cast", len) | |
2388 | || ! strncmp (token, "static_cast", len) | |
2389 | || ! strncmp (token, "reinterpret_cast", len) | |
2390 | || ! strncmp (token, "const_cast", len)); | |
2391 | } | |
7c8adf68 TT |
2392 | |
2393 | /* The scope used for macro expansion. */ | |
2394 | static struct macro_scope *expression_macro_scope; | |
2395 | ||
65d12d83 TT |
2396 | /* This is set if a NAME token appeared at the very end of the input |
2397 | string, with no whitespace separating the name from the EOF. This | |
2398 | is used only when parsing to do field name completion. */ | |
2399 | static int saw_name_at_eof; | |
2400 | ||
2401 | /* This is set if the previously-returned token was a structure | |
2402 | operator -- either '.' or ARROW. This is used only when parsing to | |
2403 | do field name completion. */ | |
2404 | static int last_was_structop; | |
2405 | ||
c906108c SS |
2406 | /* Read one token, getting characters through lexptr. */ |
2407 | ||
2408 | static int | |
48e32051 | 2409 | lex_one_token (void) |
c906108c SS |
2410 | { |
2411 | int c; | |
2412 | int namelen; | |
2413 | unsigned int i; | |
2414 | char *tokstart; | |
65d12d83 | 2415 | int saw_structop = last_was_structop; |
ba163c7e | 2416 | char *copy; |
65d12d83 TT |
2417 | |
2418 | last_was_structop = 0; | |
2419 | ||
c906108c SS |
2420 | retry: |
2421 | ||
84f0252a JB |
2422 | /* Check if this is a macro invocation that we need to expand. */ |
2423 | if (! scanning_macro_expansion ()) | |
2424 | { | |
2425 | char *expanded = macro_expand_next (&lexptr, | |
7c8adf68 TT |
2426 | standard_macro_lookup, |
2427 | expression_macro_scope); | |
84f0252a JB |
2428 | |
2429 | if (expanded) | |
2430 | scan_macro_expansion (expanded); | |
2431 | } | |
2432 | ||
665132f9 | 2433 | prev_lexptr = lexptr; |
c906108c SS |
2434 | |
2435 | tokstart = lexptr; | |
2436 | /* See if it is a special token of length 3. */ | |
2437 | for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++) | |
bf896cb0 | 2438 | if (strncmp (tokstart, tokentab3[i].operator, 3) == 0) |
c906108c | 2439 | { |
274b54d7 | 2440 | if ((tokentab3[i].flags & FLAG_CXX) != 0 |
ec7f2efe KS |
2441 | && parse_language->la_language != language_cplus) |
2442 | break; | |
2443 | ||
c906108c SS |
2444 | lexptr += 3; |
2445 | yylval.opcode = tokentab3[i].opcode; | |
2446 | return tokentab3[i].token; | |
2447 | } | |
2448 | ||
2449 | /* See if it is a special token of length 2. */ | |
2450 | for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++) | |
bf896cb0 | 2451 | if (strncmp (tokstart, tokentab2[i].operator, 2) == 0) |
c906108c | 2452 | { |
274b54d7 | 2453 | if ((tokentab2[i].flags & FLAG_CXX) != 0 |
ec7f2efe KS |
2454 | && parse_language->la_language != language_cplus) |
2455 | break; | |
2456 | ||
c906108c SS |
2457 | lexptr += 2; |
2458 | yylval.opcode = tokentab2[i].opcode; | |
155da517 | 2459 | if (parse_completion && tokentab2[i].token == ARROW) |
65d12d83 | 2460 | last_was_structop = 1; |
c906108c SS |
2461 | return tokentab2[i].token; |
2462 | } | |
2463 | ||
2464 | switch (c = *tokstart) | |
2465 | { | |
2466 | case 0: | |
84f0252a JB |
2467 | /* If we were just scanning the result of a macro expansion, |
2468 | then we need to resume scanning the original text. | |
65d12d83 TT |
2469 | If we're parsing for field name completion, and the previous |
2470 | token allows such completion, return a COMPLETE token. | |
84f0252a JB |
2471 | Otherwise, we were already scanning the original text, and |
2472 | we're really done. */ | |
2473 | if (scanning_macro_expansion ()) | |
2474 | { | |
2475 | finished_macro_expansion (); | |
2476 | goto retry; | |
2477 | } | |
65d12d83 TT |
2478 | else if (saw_name_at_eof) |
2479 | { | |
2480 | saw_name_at_eof = 0; | |
2481 | return COMPLETE; | |
2482 | } | |
2483 | else if (saw_structop) | |
2484 | return COMPLETE; | |
84f0252a JB |
2485 | else |
2486 | return 0; | |
c906108c SS |
2487 | |
2488 | case ' ': | |
2489 | case '\t': | |
2490 | case '\n': | |
2491 | lexptr++; | |
2492 | goto retry; | |
2493 | ||
379a77b5 | 2494 | case '[': |
c906108c SS |
2495 | case '(': |
2496 | paren_depth++; | |
2497 | lexptr++; | |
f2e8016f TT |
2498 | if (parse_language->la_language == language_objc && c == '[') |
2499 | return OBJC_LBRAC; | |
c906108c SS |
2500 | return c; |
2501 | ||
379a77b5 | 2502 | case ']': |
c906108c SS |
2503 | case ')': |
2504 | if (paren_depth == 0) | |
2505 | return 0; | |
2506 | paren_depth--; | |
2507 | lexptr++; | |
2508 | return c; | |
2509 | ||
2510 | case ',': | |
84f0252a JB |
2511 | if (comma_terminates |
2512 | && paren_depth == 0 | |
2513 | && ! scanning_macro_expansion ()) | |
c906108c SS |
2514 | return 0; |
2515 | lexptr++; | |
2516 | return c; | |
2517 | ||
2518 | case '.': | |
2519 | /* Might be a floating point number. */ | |
2520 | if (lexptr[1] < '0' || lexptr[1] > '9') | |
65d12d83 | 2521 | { |
155da517 | 2522 | if (parse_completion) |
65d12d83 TT |
2523 | last_was_structop = 1; |
2524 | goto symbol; /* Nope, must be a symbol. */ | |
2525 | } | |
c906108c SS |
2526 | /* FALL THRU into number case. */ |
2527 | ||
2528 | case '0': | |
2529 | case '1': | |
2530 | case '2': | |
2531 | case '3': | |
2532 | case '4': | |
2533 | case '5': | |
2534 | case '6': | |
2535 | case '7': | |
2536 | case '8': | |
2537 | case '9': | |
2538 | { | |
2539 | /* It's a number. */ | |
2540 | int got_dot = 0, got_e = 0, toktype; | |
710122da | 2541 | char *p = tokstart; |
c906108c SS |
2542 | int hex = input_radix > 10; |
2543 | ||
2544 | if (c == '0' && (p[1] == 'x' || p[1] == 'X')) | |
2545 | { | |
2546 | p += 2; | |
2547 | hex = 1; | |
2548 | } | |
2549 | else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D')) | |
2550 | { | |
2551 | p += 2; | |
2552 | hex = 0; | |
2553 | } | |
2554 | ||
2555 | for (;; ++p) | |
2556 | { | |
2557 | /* This test includes !hex because 'e' is a valid hex digit | |
2558 | and thus does not indicate a floating point number when | |
2559 | the radix is hex. */ | |
2560 | if (!hex && !got_e && (*p == 'e' || *p == 'E')) | |
2561 | got_dot = got_e = 1; | |
2562 | /* This test does not include !hex, because a '.' always indicates | |
2563 | a decimal floating point number regardless of the radix. */ | |
2564 | else if (!got_dot && *p == '.') | |
2565 | got_dot = 1; | |
2566 | else if (got_e && (p[-1] == 'e' || p[-1] == 'E') | |
2567 | && (*p == '-' || *p == '+')) | |
2568 | /* This is the sign of the exponent, not the end of the | |
2569 | number. */ | |
2570 | continue; | |
2571 | /* We will take any letters or digits. parse_number will | |
2572 | complain if past the radix, or if L or U are not final. */ | |
2573 | else if ((*p < '0' || *p > '9') | |
2574 | && ((*p < 'a' || *p > 'z') | |
2575 | && (*p < 'A' || *p > 'Z'))) | |
2576 | break; | |
2577 | } | |
2578 | toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval); | |
2579 | if (toktype == ERROR) | |
2580 | { | |
2581 | char *err_copy = (char *) alloca (p - tokstart + 1); | |
2582 | ||
2583 | memcpy (err_copy, tokstart, p - tokstart); | |
2584 | err_copy[p - tokstart] = 0; | |
001083c6 | 2585 | error (_("Invalid number \"%s\"."), err_copy); |
c906108c SS |
2586 | } |
2587 | lexptr = p; | |
2588 | return toktype; | |
2589 | } | |
2590 | ||
941b2081 JK |
2591 | case '@': |
2592 | { | |
2593 | char *p = &tokstart[1]; | |
2594 | size_t len = strlen ("entry"); | |
2595 | ||
f2e8016f TT |
2596 | if (parse_language->la_language == language_objc) |
2597 | { | |
2598 | size_t len = strlen ("selector"); | |
2599 | ||
2600 | if (strncmp (p, "selector", len) == 0 | |
2601 | && (p[len] == '\0' || isspace (p[len]))) | |
2602 | { | |
2603 | lexptr = p + len; | |
2604 | return SELECTOR; | |
2605 | } | |
2606 | else if (*p == '"') | |
2607 | goto parse_string; | |
2608 | } | |
2609 | ||
941b2081 JK |
2610 | while (isspace (*p)) |
2611 | p++; | |
2612 | if (strncmp (p, "entry", len) == 0 && !isalnum (p[len]) | |
2613 | && p[len] != '_') | |
2614 | { | |
2615 | lexptr = &p[len]; | |
2616 | return ENTRY; | |
2617 | } | |
2618 | } | |
2619 | /* FALLTHRU */ | |
c906108c SS |
2620 | case '+': |
2621 | case '-': | |
2622 | case '*': | |
2623 | case '/': | |
2624 | case '%': | |
2625 | case '|': | |
2626 | case '&': | |
2627 | case '^': | |
2628 | case '~': | |
2629 | case '!': | |
c906108c SS |
2630 | case '<': |
2631 | case '>': | |
c906108c SS |
2632 | case '?': |
2633 | case ':': | |
2634 | case '=': | |
2635 | case '{': | |
2636 | case '}': | |
2637 | symbol: | |
2638 | lexptr++; | |
2639 | return c; | |
2640 | ||
6c7a06a3 TT |
2641 | case 'L': |
2642 | case 'u': | |
2643 | case 'U': | |
2644 | if (tokstart[1] != '"' && tokstart[1] != '\'') | |
2645 | break; | |
2646 | /* Fall through. */ | |
2647 | case '\'': | |
c906108c | 2648 | case '"': |
f2e8016f TT |
2649 | |
2650 | parse_string: | |
6c7a06a3 TT |
2651 | { |
2652 | int host_len; | |
2653 | int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval, | |
2654 | &host_len); | |
2655 | if (result == CHAR) | |
c906108c | 2656 | { |
6c7a06a3 | 2657 | if (host_len == 0) |
001083c6 | 2658 | error (_("Empty character constant.")); |
6c7a06a3 | 2659 | else if (host_len > 2 && c == '\'') |
c906108c | 2660 | { |
6c7a06a3 TT |
2661 | ++tokstart; |
2662 | namelen = lexptr - tokstart - 1; | |
2663 | goto tryname; | |
c906108c | 2664 | } |
6c7a06a3 | 2665 | else if (host_len > 1) |
001083c6 | 2666 | error (_("Invalid character constant.")); |
c906108c | 2667 | } |
6c7a06a3 TT |
2668 | return result; |
2669 | } | |
c906108c SS |
2670 | } |
2671 | ||
2672 | if (!(c == '_' || c == '$' | |
2673 | || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) | |
2674 | /* We must have come across a bad character (e.g. ';'). */ | |
001083c6 | 2675 | error (_("Invalid character '%c' in expression."), c); |
c906108c SS |
2676 | |
2677 | /* It's a name. See how long it is. */ | |
2678 | namelen = 0; | |
2679 | for (c = tokstart[namelen]; | |
2680 | (c == '_' || c == '$' || (c >= '0' && c <= '9') | |
2681 | || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');) | |
2682 | { | |
2683 | /* Template parameter lists are part of the name. | |
2684 | FIXME: This mishandles `print $a<4&&$a>3'. */ | |
2685 | ||
2686 | if (c == '<') | |
4e8f195d TT |
2687 | { |
2688 | if (! is_cast_operator (tokstart, namelen)) | |
2689 | { | |
2690 | /* Scan ahead to get rest of the template specification. Note | |
2691 | that we look ahead only when the '<' adjoins non-whitespace | |
2692 | characters; for comparison expressions, e.g. "a < b > c", | |
2693 | there must be spaces before the '<', etc. */ | |
c906108c | 2694 | |
4e8f195d TT |
2695 | char * p = find_template_name_end (tokstart + namelen); |
2696 | if (p) | |
2697 | namelen = p - tokstart; | |
2698 | } | |
2699 | break; | |
c906108c SS |
2700 | } |
2701 | c = tokstart[++namelen]; | |
2702 | } | |
2703 | ||
84f0252a JB |
2704 | /* The token "if" terminates the expression and is NOT removed from |
2705 | the input stream. It doesn't count if it appears in the | |
2706 | expansion of a macro. */ | |
2707 | if (namelen == 2 | |
2708 | && tokstart[0] == 'i' | |
2709 | && tokstart[1] == 'f' | |
2710 | && ! scanning_macro_expansion ()) | |
c906108c SS |
2711 | { |
2712 | return 0; | |
2713 | } | |
2714 | ||
b6199126 DJ |
2715 | /* For the same reason (breakpoint conditions), "thread N" |
2716 | terminates the expression. "thread" could be an identifier, but | |
2717 | an identifier is never followed by a number without intervening | |
2718 | punctuation. "task" is similar. Handle abbreviations of these, | |
2719 | similarly to breakpoint.c:find_condition_and_thread. */ | |
2720 | if (namelen >= 1 | |
2721 | && (strncmp (tokstart, "thread", namelen) == 0 | |
2722 | || strncmp (tokstart, "task", namelen) == 0) | |
2723 | && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t') | |
2724 | && ! scanning_macro_expansion ()) | |
2725 | { | |
2726 | char *p = tokstart + namelen + 1; | |
2727 | while (*p == ' ' || *p == '\t') | |
2728 | p++; | |
2729 | if (*p >= '0' && *p <= '9') | |
2730 | return 0; | |
2731 | } | |
2732 | ||
c906108c SS |
2733 | lexptr += namelen; |
2734 | ||
2735 | tryname: | |
2736 | ||
c906108c SS |
2737 | yylval.sval.ptr = tokstart; |
2738 | yylval.sval.length = namelen; | |
2739 | ||
ba163c7e TT |
2740 | /* Catch specific keywords. */ |
2741 | copy = copy_name (yylval.sval); | |
2742 | for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++) | |
2743 | if (strcmp (copy, ident_tokens[i].operator) == 0) | |
2744 | { | |
274b54d7 | 2745 | if ((ident_tokens[i].flags & FLAG_CXX) != 0 |
ba163c7e TT |
2746 | && parse_language->la_language != language_cplus) |
2747 | break; | |
2748 | ||
274b54d7 TT |
2749 | if ((ident_tokens[i].flags & FLAG_SHADOW) != 0) |
2750 | { | |
1993b719 | 2751 | struct field_of_this_result is_a_field_of_this; |
274b54d7 TT |
2752 | |
2753 | if (lookup_symbol (copy, expression_context_block, | |
2754 | VAR_DOMAIN, | |
2755 | (parse_language->la_language == language_cplus | |
2756 | ? &is_a_field_of_this | |
2757 | : NULL)) | |
2758 | != NULL) | |
2759 | { | |
2760 | /* The keyword is shadowed. */ | |
2761 | break; | |
2762 | } | |
2763 | } | |
2764 | ||
ba163c7e TT |
2765 | /* It is ok to always set this, even though we don't always |
2766 | strictly need to. */ | |
2767 | yylval.opcode = ident_tokens[i].opcode; | |
2768 | return ident_tokens[i].token; | |
2769 | } | |
2770 | ||
c906108c | 2771 | if (*tokstart == '$') |
48e32051 TT |
2772 | return VARIABLE; |
2773 | ||
155da517 | 2774 | if (parse_completion && *lexptr == '\0') |
48e32051 | 2775 | saw_name_at_eof = 1; |
e234dfaf TT |
2776 | |
2777 | yylval.ssym.stoken = yylval.sval; | |
2778 | yylval.ssym.sym = NULL; | |
2779 | yylval.ssym.is_a_field_of_this = 0; | |
48e32051 TT |
2780 | return NAME; |
2781 | } | |
2782 | ||
2783 | /* An object of this type is pushed on a FIFO by the "outer" lexer. */ | |
2784 | typedef struct | |
2785 | { | |
2786 | int token; | |
e707a91d | 2787 | YYSTYPE value; |
48e32051 TT |
2788 | } token_and_value; |
2789 | ||
2790 | DEF_VEC_O (token_and_value); | |
2791 | ||
2792 | /* A FIFO of tokens that have been read but not yet returned to the | |
2793 | parser. */ | |
2794 | static VEC (token_and_value) *token_fifo; | |
2795 | ||
2796 | /* Non-zero if the lexer should return tokens from the FIFO. */ | |
2797 | static int popping; | |
2798 | ||
2799 | /* Temporary storage for c_lex; this holds symbol names as they are | |
2800 | built up. */ | |
2801 | static struct obstack name_obstack; | |
2802 | ||
2803 | /* Classify a NAME token. The contents of the token are in `yylval'. | |
2804 | Updates yylval and returns the new token type. BLOCK is the block | |
2805 | in which lookups start; this can be NULL to mean the global | |
2806 | scope. */ | |
2807 | static int | |
270140bd | 2808 | classify_name (const struct block *block) |
48e32051 TT |
2809 | { |
2810 | struct symbol *sym; | |
2811 | char *copy; | |
1993b719 | 2812 | struct field_of_this_result is_a_field_of_this; |
48e32051 TT |
2813 | |
2814 | copy = copy_name (yylval.sval); | |
2815 | ||
1993b719 TT |
2816 | /* Initialize this in case we *don't* use it in this call; that way |
2817 | we can refer to it unconditionally below. */ | |
2818 | memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this)); | |
2819 | ||
48e32051 | 2820 | sym = lookup_symbol (copy, block, VAR_DOMAIN, |
f2e8016f | 2821 | parse_language->la_name_of_this |
1993b719 | 2822 | ? &is_a_field_of_this : NULL); |
48e32051 TT |
2823 | |
2824 | if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
c906108c | 2825 | { |
48e32051 | 2826 | yylval.ssym.sym = sym; |
1993b719 | 2827 | yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; |
48e32051 | 2828 | return BLOCKNAME; |
c906108c | 2829 | } |
48e32051 TT |
2830 | else if (!sym) |
2831 | { | |
2832 | /* See if it's a file name. */ | |
2833 | struct symtab *symtab; | |
c906108c | 2834 | |
48e32051 TT |
2835 | symtab = lookup_symtab (copy); |
2836 | if (symtab) | |
2837 | { | |
2838 | yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK); | |
2839 | return FILENAME; | |
2840 | } | |
6592e36f TT |
2841 | |
2842 | /* If we found a field of 'this', we might have erroneously | |
2843 | found a constructor where we wanted a type name. Handle this | |
2844 | case by noticing that we found a constructor and then look up | |
2845 | the type tag instead. */ | |
2846 | if (is_a_field_of_this.type != NULL | |
2847 | && is_a_field_of_this.fn_field != NULL | |
2848 | && TYPE_FN_FIELD_CONSTRUCTOR (is_a_field_of_this.fn_field->fn_fields, | |
2849 | 0)) | |
2850 | { | |
2851 | struct field_of_this_result inner_is_a_field_of_this; | |
2852 | ||
2853 | sym = lookup_symbol (copy, block, STRUCT_DOMAIN, | |
2854 | &inner_is_a_field_of_this); | |
2855 | if (sym != NULL) | |
2856 | { | |
2857 | yylval.tsym.type = SYMBOL_TYPE (sym); | |
2858 | return TYPENAME; | |
2859 | } | |
2860 | } | |
48e32051 | 2861 | } |
c906108c | 2862 | |
48e32051 TT |
2863 | if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF) |
2864 | { | |
2865 | yylval.tsym.type = SYMBOL_TYPE (sym); | |
47663de5 | 2866 | return TYPENAME; |
48e32051 | 2867 | } |
c906108c | 2868 | |
48e32051 TT |
2869 | yylval.tsym.type |
2870 | = language_lookup_primitive_type_by_name (parse_language, | |
2871 | parse_gdbarch, copy); | |
2872 | if (yylval.tsym.type != NULL) | |
2873 | return TYPENAME; | |
2874 | ||
f2e8016f TT |
2875 | /* See if it's an ObjC classname. */ |
2876 | if (parse_language->la_language == language_objc && !sym) | |
2877 | { | |
2878 | CORE_ADDR Class = lookup_objc_class (parse_gdbarch, copy); | |
2879 | if (Class) | |
2880 | { | |
2881 | yylval.class.class = Class; | |
826f0041 TT |
2882 | sym = lookup_struct_typedef (copy, expression_context_block, 1); |
2883 | if (sym) | |
f2e8016f TT |
2884 | yylval.class.type = SYMBOL_TYPE (sym); |
2885 | return CLASSNAME; | |
2886 | } | |
2887 | } | |
2888 | ||
48e32051 TT |
2889 | /* Input names that aren't symbols but ARE valid hex numbers, when |
2890 | the input radix permits them, can be names or numbers depending | |
2891 | on the parse. Note we support radixes > 16 here. */ | |
2892 | if (!sym | |
2893 | && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10) | |
2894 | || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10))) | |
2895 | { | |
2896 | YYSTYPE newlval; /* Its value is ignored. */ | |
2897 | int hextype = parse_number (copy, yylval.sval.length, 0, &newlval); | |
2898 | if (hextype == INT) | |
2899 | { | |
2900 | yylval.ssym.sym = sym; | |
1993b719 | 2901 | yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; |
48e32051 TT |
2902 | return NAME_OR_INT; |
2903 | } | |
2904 | } | |
2905 | ||
2906 | /* Any other kind of symbol */ | |
2907 | yylval.ssym.sym = sym; | |
1993b719 | 2908 | yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; |
7322dca9 SW |
2909 | |
2910 | if (sym == NULL | |
2911 | && parse_language->la_language == language_cplus | |
1993b719 | 2912 | && is_a_field_of_this.type == NULL |
7322dca9 SW |
2913 | && !lookup_minimal_symbol (copy, NULL, NULL)) |
2914 | return UNKNOWN_CPP_NAME; | |
2915 | ||
48e32051 TT |
2916 | return NAME; |
2917 | } | |
c906108c | 2918 | |
48e32051 | 2919 | /* Like classify_name, but used by the inner loop of the lexer, when a |
e234dfaf TT |
2920 | name might have already been seen. CONTEXT is the context type, or |
2921 | NULL if this is the first component of a name. */ | |
50af5481 | 2922 | |
48e32051 | 2923 | static int |
e234dfaf | 2924 | classify_inner_name (const struct block *block, struct type *context) |
48e32051 | 2925 | { |
df54f8eb | 2926 | struct type *type; |
48e32051 TT |
2927 | char *copy; |
2928 | ||
e234dfaf | 2929 | if (context == NULL) |
48e32051 TT |
2930 | return classify_name (block); |
2931 | ||
e234dfaf | 2932 | type = check_typedef (context); |
48e32051 TT |
2933 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT |
2934 | && TYPE_CODE (type) != TYPE_CODE_UNION | |
2935 | && TYPE_CODE (type) != TYPE_CODE_NAMESPACE) | |
50af5481 | 2936 | return ERROR; |
48e32051 | 2937 | |
e234dfaf TT |
2938 | copy = copy_name (yylval.ssym.stoken); |
2939 | yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block); | |
50af5481 JK |
2940 | if (yylval.ssym.sym == NULL) |
2941 | return ERROR; | |
2942 | ||
2943 | switch (SYMBOL_CLASS (yylval.ssym.sym)) | |
2944 | { | |
2945 | case LOC_BLOCK: | |
2946 | case LOC_LABEL: | |
2947 | return ERROR; | |
48e32051 | 2948 | |
50af5481 JK |
2949 | case LOC_TYPEDEF: |
2950 | yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);; | |
2951 | return TYPENAME; | |
48e32051 | 2952 | |
50af5481 | 2953 | default: |
50af5481 JK |
2954 | return NAME; |
2955 | } | |
2956 | internal_error (__FILE__, __LINE__, _("not reached")); | |
48e32051 TT |
2957 | } |
2958 | ||
2959 | /* The outer level of a two-level lexer. This calls the inner lexer | |
2960 | to return tokens. It then either returns these tokens, or | |
2961 | aggregates them into a larger token. This lets us work around a | |
2962 | problem in our parsing approach, where the parser could not | |
2963 | distinguish between qualified names and qualified types at the | |
2964 | right point. | |
2965 | ||
2966 | This approach is still not ideal, because it mishandles template | |
2967 | types. See the comment in lex_one_token for an example. However, | |
2968 | this is still an improvement over the earlier approach, and will | |
2969 | suffice until we move to better parsing technology. */ | |
2970 | static int | |
2971 | yylex (void) | |
2972 | { | |
2973 | token_and_value current; | |
b2f83c08 | 2974 | int first_was_coloncolon, last_was_coloncolon; |
e234dfaf | 2975 | struct type *context_type = NULL; |
b2f83c08 TT |
2976 | int last_to_examine, next_to_examine, checkpoint; |
2977 | const struct block *search_block; | |
48e32051 TT |
2978 | |
2979 | if (popping && !VEC_empty (token_and_value, token_fifo)) | |
b2f83c08 | 2980 | goto do_pop; |
48e32051 TT |
2981 | popping = 0; |
2982 | ||
b2f83c08 TT |
2983 | /* Read the first token and decide what to do. Most of the |
2984 | subsequent code is C++-only; but also depends on seeing a "::" or | |
2985 | name-like token. */ | |
48e32051 TT |
2986 | current.token = lex_one_token (); |
2987 | if (current.token == NAME) | |
2988 | current.token = classify_name (expression_context_block); | |
2989 | if (parse_language->la_language != language_cplus | |
b2f83c08 TT |
2990 | || (current.token != TYPENAME && current.token != COLONCOLON |
2991 | && current.token != FILENAME)) | |
48e32051 TT |
2992 | return current.token; |
2993 | ||
b2f83c08 TT |
2994 | /* Read any sequence of alternating "::" and name-like tokens into |
2995 | the token FIFO. */ | |
2996 | current.value = yylval; | |
2997 | VEC_safe_push (token_and_value, token_fifo, ¤t); | |
2998 | last_was_coloncolon = current.token == COLONCOLON; | |
2999 | while (1) | |
3000 | { | |
3001 | current.token = lex_one_token (); | |
3002 | current.value = yylval; | |
3003 | VEC_safe_push (token_and_value, token_fifo, ¤t); | |
3004 | ||
3005 | if ((last_was_coloncolon && current.token != NAME) | |
3006 | || (!last_was_coloncolon && current.token != COLONCOLON)) | |
3007 | break; | |
3008 | last_was_coloncolon = !last_was_coloncolon; | |
3009 | } | |
3010 | popping = 1; | |
3011 | ||
3012 | /* We always read one extra token, so compute the number of tokens | |
3013 | to examine accordingly. */ | |
3014 | last_to_examine = VEC_length (token_and_value, token_fifo) - 2; | |
3015 | next_to_examine = 0; | |
3016 | ||
3017 | current = *VEC_index (token_and_value, token_fifo, next_to_examine); | |
3018 | ++next_to_examine; | |
3019 | ||
48e32051 | 3020 | obstack_free (&name_obstack, obstack_base (&name_obstack)); |
b2f83c08 TT |
3021 | checkpoint = 0; |
3022 | if (current.token == FILENAME) | |
3023 | search_block = current.value.bval; | |
3024 | else if (current.token == COLONCOLON) | |
3025 | search_block = NULL; | |
3026 | else | |
e234dfaf | 3027 | { |
b2f83c08 TT |
3028 | gdb_assert (current.token == TYPENAME); |
3029 | search_block = expression_context_block; | |
3030 | obstack_grow (&name_obstack, current.value.sval.ptr, | |
3031 | current.value.sval.length); | |
3032 | context_type = current.value.tsym.type; | |
3033 | checkpoint = 1; | |
e234dfaf | 3034 | } |
b2f83c08 TT |
3035 | |
3036 | first_was_coloncolon = current.token == COLONCOLON; | |
3037 | last_was_coloncolon = first_was_coloncolon; | |
3038 | ||
3039 | while (next_to_examine <= last_to_examine) | |
48e32051 | 3040 | { |
b2f83c08 | 3041 | token_and_value *next; |
48e32051 | 3042 | |
b2f83c08 TT |
3043 | next = VEC_index (token_and_value, token_fifo, next_to_examine); |
3044 | ++next_to_examine; | |
48e32051 | 3045 | |
b2f83c08 | 3046 | if (next->token == NAME && last_was_coloncolon) |
48e32051 TT |
3047 | { |
3048 | int classification; | |
3049 | ||
b2f83c08 TT |
3050 | yylval = next->value; |
3051 | classification = classify_inner_name (search_block, context_type); | |
48e32051 TT |
3052 | /* We keep going until we either run out of names, or until |
3053 | we have a qualified name which is not a type. */ | |
50af5481 | 3054 | if (classification != TYPENAME && classification != NAME) |
b2f83c08 TT |
3055 | break; |
3056 | ||
3057 | /* Accept up to this token. */ | |
3058 | checkpoint = next_to_examine; | |
48e32051 TT |
3059 | |
3060 | /* Update the partial name we are constructing. */ | |
e234dfaf | 3061 | if (context_type != NULL) |
48e32051 TT |
3062 | { |
3063 | /* We don't want to put a leading "::" into the name. */ | |
3064 | obstack_grow_str (&name_obstack, "::"); | |
3065 | } | |
b2f83c08 TT |
3066 | obstack_grow (&name_obstack, next->value.sval.ptr, |
3067 | next->value.sval.length); | |
48e32051 TT |
3068 | |
3069 | yylval.sval.ptr = obstack_base (&name_obstack); | |
3070 | yylval.sval.length = obstack_object_size (&name_obstack); | |
3071 | current.value = yylval; | |
3072 | current.token = classification; | |
3073 | ||
3074 | last_was_coloncolon = 0; | |
e234dfaf TT |
3075 | |
3076 | if (classification == NAME) | |
3077 | break; | |
3078 | ||
3079 | context_type = yylval.tsym.type; | |
48e32051 | 3080 | } |
b2f83c08 | 3081 | else if (next->token == COLONCOLON && !last_was_coloncolon) |
48e32051 TT |
3082 | last_was_coloncolon = 1; |
3083 | else | |
3084 | { | |
3085 | /* We've reached the end of the name. */ | |
48e32051 TT |
3086 | break; |
3087 | } | |
48e32051 TT |
3088 | } |
3089 | ||
b2f83c08 TT |
3090 | /* If we have a replacement token, install it as the first token in |
3091 | the FIFO, and delete the other constituent tokens. */ | |
3092 | if (checkpoint > 0) | |
48e32051 | 3093 | { |
b2f83c08 TT |
3094 | current.value.sval.ptr = obstack_copy0 (&expansion_obstack, |
3095 | current.value.sval.ptr, | |
3096 | current.value.sval.length); | |
3097 | ||
3098 | VEC_replace (token_and_value, token_fifo, 0, ¤t); | |
3099 | if (checkpoint > 1) | |
3100 | VEC_block_remove (token_and_value, token_fifo, 1, checkpoint - 1); | |
48e32051 TT |
3101 | } |
3102 | ||
b2f83c08 TT |
3103 | do_pop: |
3104 | current = *VEC_index (token_and_value, token_fifo, 0); | |
3105 | VEC_ordered_remove (token_and_value, token_fifo, 0); | |
48e32051 | 3106 | yylval = current.value; |
48e32051 | 3107 | return current.token; |
c906108c SS |
3108 | } |
3109 | ||
65d12d83 TT |
3110 | int |
3111 | c_parse (void) | |
3112 | { | |
7c8adf68 TT |
3113 | int result; |
3114 | struct cleanup *back_to = make_cleanup (free_current_contents, | |
3115 | &expression_macro_scope); | |
3116 | ||
3117 | /* Set up the scope for macro expansion. */ | |
3118 | expression_macro_scope = NULL; | |
3119 | ||
3120 | if (expression_context_block) | |
3121 | expression_macro_scope | |
3122 | = sal_macro_scope (find_pc_line (expression_context_pc, 0)); | |
3123 | else | |
3124 | expression_macro_scope = default_macro_scope (); | |
3125 | if (! expression_macro_scope) | |
3126 | expression_macro_scope = user_macro_scope (); | |
3127 | ||
3128 | /* Initialize macro expansion code. */ | |
3129 | obstack_init (&expansion_obstack); | |
3130 | gdb_assert (! macro_original_text); | |
3131 | make_cleanup (scan_macro_cleanup, 0); | |
3132 | ||
92981e24 TT |
3133 | make_cleanup_restore_integer (&yydebug); |
3134 | yydebug = parser_debug; | |
3135 | ||
7c8adf68 | 3136 | /* Initialize some state used by the lexer. */ |
65d12d83 TT |
3137 | last_was_structop = 0; |
3138 | saw_name_at_eof = 0; | |
7c8adf68 | 3139 | |
48e32051 TT |
3140 | VEC_free (token_and_value, token_fifo); |
3141 | popping = 0; | |
3142 | obstack_init (&name_obstack); | |
3143 | make_cleanup_obstack_free (&name_obstack); | |
3144 | ||
7c8adf68 TT |
3145 | result = yyparse (); |
3146 | do_cleanups (back_to); | |
3147 | return result; | |
65d12d83 TT |
3148 | } |
3149 | ||
9507860e TT |
3150 | /* This is called via the YYPRINT macro when parser debugging is |
3151 | enabled. It prints a token's value. */ | |
3152 | ||
3153 | static void | |
3154 | c_print_token (FILE *file, int type, YYSTYPE value) | |
3155 | { | |
3156 | switch (type) | |
3157 | { | |
3158 | case INT: | |
3159 | fprintf (file, "typed_val_int<%s, %s>", | |
3160 | TYPE_SAFE_NAME (value.typed_val_int.type), | |
3161 | pulongest (value.typed_val_int.val)); | |
3162 | break; | |
3163 | ||
3164 | case CHAR: | |
3165 | case STRING: | |
3166 | { | |
3167 | char *copy = alloca (value.tsval.length + 1); | |
3168 | ||
3169 | memcpy (copy, value.tsval.ptr, value.tsval.length); | |
3170 | copy[value.tsval.length] = '\0'; | |
3171 | ||
3172 | fprintf (file, "tsval<type=%d, %s>", value.tsval.type, copy); | |
3173 | } | |
3174 | break; | |
3175 | ||
3176 | case NSSTRING: | |
3177 | case VARIABLE: | |
3178 | fprintf (file, "sval<%s>", copy_name (value.sval)); | |
3179 | break; | |
3180 | ||
3181 | case TYPENAME: | |
3182 | fprintf (file, "tsym<type=%s, name=%s>", | |
3183 | TYPE_SAFE_NAME (value.tsym.type), | |
3184 | copy_name (value.tsym.stoken)); | |
3185 | break; | |
3186 | ||
3187 | case NAME: | |
3188 | case UNKNOWN_CPP_NAME: | |
3189 | case NAME_OR_INT: | |
3190 | case BLOCKNAME: | |
3191 | fprintf (file, "ssym<name=%s, sym=%s, field_of_this=%d>", | |
3192 | copy_name (value.ssym.stoken), | |
3193 | (value.ssym.sym == NULL | |
3194 | ? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym)), | |
3195 | value.ssym.is_a_field_of_this); | |
3196 | break; | |
3197 | ||
3198 | case FILENAME: | |
3199 | fprintf (file, "bval<%s>", host_address_to_string (value.bval)); | |
3200 | break; | |
3201 | } | |
3202 | } | |
7c8adf68 | 3203 | |
c906108c | 3204 | void |
68c1b02d | 3205 | yyerror (char *msg) |
c906108c | 3206 | { |
665132f9 MS |
3207 | if (prev_lexptr) |
3208 | lexptr = prev_lexptr; | |
3209 | ||
001083c6 | 3210 | error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr); |
c906108c | 3211 | } |