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