Commit | Line | Data |
---|---|---|
b81654f1 | 1 | /* YACC parser for C expressions, for GDB. |
b81654f1 | 2 | |
48426bc2 AO |
3 | Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994, 2002, 2006 |
4 | Free Software Foundation, Inc. | |
b81654f1 | 5 | |
437666f8 AC |
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 2 of the License, or | |
9 | (at your option) any later version. | |
b81654f1 | 10 | |
437666f8 AC |
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. | |
b81654f1 | 15 | |
437666f8 AC |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. */ | |
b81654f1 | 20 | |
3b4efeaa MS |
21 | /* Parse a C expression from text in a string, and return the result |
22 | as a struct expression pointer. That structure contains arithmetic | |
23 | operations in reverse polish, with constants represented by | |
24 | operations that are followed by special data. See expression.h for | |
25 | the details of the format. What is important here is that it can | |
26 | be built up sequentially during the process of parsing; the lower | |
27 | levels of the tree always come first in the result. | |
b81654f1 MS |
28 | |
29 | Note that malloc's and realloc's in this file are transformed to | |
30 | xmalloc and xrealloc respectively by the same sed command in the | |
3b4efeaa MS |
31 | makefile that remaps any other malloc/realloc inserted by the |
32 | parser generator. Doing this with #defines and trying to control | |
33 | the interaction with include files (<malloc.h> and <stdlib.h> for | |
34 | example) just became too messy, particularly when such includes can | |
35 | be inserted at random times by the parser generator. */ | |
b81654f1 MS |
36 | |
37 | %{ | |
38 | ||
39 | #include "defs.h" | |
40 | #include "gdb_string.h" | |
41 | #include <ctype.h> | |
42 | #include "expression.h" | |
43 | ||
3b4efeaa | 44 | #include "objc-lang.h" /* For objc language constructs. */ |
b81654f1 MS |
45 | |
46 | #include "value.h" | |
47 | #include "parser-defs.h" | |
48 | #include "language.h" | |
49 | #include "c-lang.h" | |
50 | #include "bfd.h" /* Required by objfiles.h. */ | |
51 | #include "symfile.h" /* Required by objfiles.h. */ | |
3b4efeaa | 52 | #include "objfiles.h" /* For have_full_symbols and have_partial_symbols. */ |
b81654f1 MS |
53 | #include "top.h" |
54 | #include "completer.h" /* For skip_quoted(). */ | |
fe898f56 | 55 | #include "block.h" |
b81654f1 | 56 | |
3b4efeaa MS |
57 | /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, |
58 | etc), as well as gratuitiously global symbol names, so we can have | |
59 | multiple yacc generated parsers in gdb. Note that these are only | |
60 | the variables produced by yacc. If other parser generators (bison, | |
61 | byacc, etc) produce additional global names that conflict at link | |
62 | time, then those parser generators need to be fixed instead of | |
63 | adding those names to this list. */ | |
b81654f1 MS |
64 | |
65 | #define yymaxdepth objc_maxdepth | |
66 | #define yyparse objc_parse | |
67 | #define yylex objc_lex | |
68 | #define yyerror objc_error | |
69 | #define yylval objc_lval | |
70 | #define yychar objc_char | |
71 | #define yydebug objc_debug | |
72 | #define yypact objc_pact | |
73 | #define yyr1 objc_r1 | |
74 | #define yyr2 objc_r2 | |
75 | #define yydef objc_def | |
76 | #define yychk objc_chk | |
77 | #define yypgo objc_pgo | |
78 | #define yyact objc_act | |
79 | #define yyexca objc_exca | |
80 | #define yyerrflag objc_errflag | |
81 | #define yynerrs objc_nerrs | |
82 | #define yyps objc_ps | |
83 | #define yypv objc_pv | |
84 | #define yys objc_s | |
85 | #define yy_yys objc_yys | |
86 | #define yystate objc_state | |
87 | #define yytmp objc_tmp | |
88 | #define yyv objc_v | |
89 | #define yy_yyv objc_yyv | |
90 | #define yyval objc_val | |
91 | #define yylloc objc_lloc | |
92 | #define yyreds objc_reds /* With YYDEBUG defined */ | |
93 | #define yytoks objc_toks /* With YYDEBUG defined */ | |
94 | #define yyname objc_name /* With YYDEBUG defined */ | |
95 | #define yyrule objc_rule /* With YYDEBUG defined */ | |
96 | #define yylhs objc_yylhs | |
97 | #define yylen objc_yylen | |
98 | #define yydefred objc_yydefred | |
99 | #define yydgoto objc_yydgoto | |
100 | #define yysindex objc_yysindex | |
101 | #define yyrindex objc_yyrindex | |
102 | #define yygindex objc_yygindex | |
103 | #define yytable objc_yytable | |
104 | #define yycheck objc_yycheck | |
105 | ||
106 | #ifndef YYDEBUG | |
3b4efeaa | 107 | #define YYDEBUG 0 /* Default to no yydebug support. */ |
b81654f1 MS |
108 | #endif |
109 | ||
110 | int | |
111 | yyparse PARAMS ((void)); | |
112 | ||
113 | static int | |
114 | yylex PARAMS ((void)); | |
115 | ||
116 | void | |
117 | yyerror PARAMS ((char *)); | |
118 | ||
119 | %} | |
120 | ||
121 | /* Although the yacc "value" of an expression is not used, | |
122 | since the result is stored in the structure being created, | |
123 | other node types do have values. */ | |
124 | ||
125 | %union | |
126 | { | |
127 | LONGEST lval; | |
128 | struct { | |
129 | LONGEST val; | |
130 | struct type *type; | |
131 | } typed_val_int; | |
132 | struct { | |
133 | DOUBLEST dval; | |
134 | struct type *type; | |
135 | } typed_val_float; | |
136 | struct symbol *sym; | |
137 | struct type *tval; | |
138 | struct stoken sval; | |
139 | struct ttype tsym; | |
140 | struct symtoken ssym; | |
141 | int voidval; | |
142 | struct block *bval; | |
143 | enum exp_opcode opcode; | |
144 | struct internalvar *ivar; | |
145 | struct objc_class_str class; | |
146 | ||
147 | struct type **tvec; | |
148 | int *ivec; | |
149 | } | |
150 | ||
151 | %{ | |
3b4efeaa | 152 | /* YYSTYPE gets defined by %union. */ |
b81654f1 MS |
153 | static int |
154 | parse_number PARAMS ((char *, int, int, YYSTYPE *)); | |
155 | %} | |
156 | ||
157 | %type <voidval> exp exp1 type_exp start variable qualified_name lcurly | |
158 | %type <lval> rcurly | |
159 | %type <tval> type typebase | |
160 | %type <tvec> nonempty_typelist | |
161 | /* %type <bval> block */ | |
162 | ||
163 | /* Fancy type parsing. */ | |
164 | %type <voidval> func_mod direct_abs_decl abs_decl | |
165 | %type <tval> ptype | |
166 | %type <lval> array_mod | |
167 | ||
168 | %token <typed_val_int> INT | |
169 | %token <typed_val_float> FLOAT | |
170 | ||
3b4efeaa MS |
171 | /* Both NAME and TYPENAME tokens represent symbols in the input, and |
172 | both convey their data as strings. But a TYPENAME is a string that | |
173 | happens to be defined as a typedef or builtin type name (such as | |
174 | int or char) and a NAME is any other symbol. Contexts where this | |
175 | distinction is not important can use the nonterminal "name", which | |
176 | matches either NAME or TYPENAME. */ | |
b81654f1 MS |
177 | |
178 | %token <sval> STRING | |
179 | %token <sval> NSSTRING /* ObjC Foundation "NSString" literal */ | |
180 | %token <sval> SELECTOR /* ObjC "@selector" pseudo-operator */ | |
181 | %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */ | |
182 | %token <tsym> TYPENAME | |
183 | %token <class> CLASSNAME /* ObjC Class name */ | |
184 | %type <sval> name | |
185 | %type <ssym> name_not_typename | |
186 | %type <tsym> typename | |
187 | ||
188 | /* A NAME_OR_INT is a symbol which is not known in the symbol table, | |
189 | but which would parse as a valid number in the current input radix. | |
190 | E.g. "c" when input_radix==16. Depending on the parse, it will be | |
191 | turned into a name or into a number. */ | |
192 | ||
193 | %token <ssym> NAME_OR_INT | |
194 | ||
195 | %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON | |
196 | %token TEMPLATE | |
197 | %token ERROR | |
198 | ||
3b4efeaa MS |
199 | /* Special type cases, put in to allow the parser to distinguish |
200 | different legal basetypes. */ | |
b81654f1 MS |
201 | %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD |
202 | ||
203 | %token <voidval> VARIABLE | |
204 | ||
205 | %token <opcode> ASSIGN_MODIFY | |
206 | ||
b81654f1 MS |
207 | %left ',' |
208 | %left ABOVE_COMMA | |
209 | %right '=' ASSIGN_MODIFY | |
210 | %right '?' | |
211 | %left OROR | |
212 | %left ANDAND | |
213 | %left '|' | |
214 | %left '^' | |
215 | %left '&' | |
216 | %left EQUAL NOTEQUAL | |
217 | %left '<' '>' LEQ GEQ | |
218 | %left LSH RSH | |
219 | %left '@' | |
220 | %left '+' '-' | |
221 | %left '*' '/' '%' | |
222 | %right UNARY INCREMENT DECREMENT | |
223 | %right ARROW '.' '[' '(' | |
224 | %token <ssym> BLOCKNAME | |
225 | %type <bval> block | |
226 | %left COLONCOLON | |
227 | ||
228 | \f | |
229 | %% | |
230 | ||
231 | start : exp1 | |
232 | | type_exp | |
233 | ; | |
234 | ||
235 | type_exp: type | |
236 | { write_exp_elt_opcode(OP_TYPE); | |
237 | write_exp_elt_type($1); | |
238 | write_exp_elt_opcode(OP_TYPE);} | |
239 | ; | |
240 | ||
241 | /* Expressions, including the comma operator. */ | |
242 | exp1 : exp | |
243 | | exp1 ',' exp | |
244 | { write_exp_elt_opcode (BINOP_COMMA); } | |
245 | ; | |
246 | ||
247 | /* Expressions, not including the comma operator. */ | |
248 | exp : '*' exp %prec UNARY | |
249 | { write_exp_elt_opcode (UNOP_IND); } | |
5edc9ca6 | 250 | ; |
b81654f1 MS |
251 | |
252 | exp : '&' exp %prec UNARY | |
253 | { write_exp_elt_opcode (UNOP_ADDR); } | |
5edc9ca6 | 254 | ; |
b81654f1 MS |
255 | |
256 | exp : '-' exp %prec UNARY | |
257 | { write_exp_elt_opcode (UNOP_NEG); } | |
258 | ; | |
259 | ||
260 | exp : '!' exp %prec UNARY | |
261 | { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } | |
262 | ; | |
263 | ||
264 | exp : '~' exp %prec UNARY | |
265 | { write_exp_elt_opcode (UNOP_COMPLEMENT); } | |
266 | ; | |
267 | ||
268 | exp : INCREMENT exp %prec UNARY | |
269 | { write_exp_elt_opcode (UNOP_PREINCREMENT); } | |
270 | ; | |
271 | ||
272 | exp : DECREMENT exp %prec UNARY | |
273 | { write_exp_elt_opcode (UNOP_PREDECREMENT); } | |
274 | ; | |
275 | ||
276 | exp : exp INCREMENT %prec UNARY | |
277 | { write_exp_elt_opcode (UNOP_POSTINCREMENT); } | |
278 | ; | |
279 | ||
280 | exp : exp DECREMENT %prec UNARY | |
281 | { write_exp_elt_opcode (UNOP_POSTDECREMENT); } | |
282 | ; | |
283 | ||
284 | exp : SIZEOF exp %prec UNARY | |
285 | { write_exp_elt_opcode (UNOP_SIZEOF); } | |
286 | ; | |
287 | ||
288 | exp : exp ARROW name | |
289 | { write_exp_elt_opcode (STRUCTOP_PTR); | |
290 | write_exp_string ($3); | |
291 | write_exp_elt_opcode (STRUCTOP_PTR); } | |
292 | ; | |
293 | ||
294 | exp : exp ARROW qualified_name | |
295 | { /* exp->type::name becomes exp->*(&type::name) */ | |
296 | /* Note: this doesn't work if name is a | |
297 | static member! FIXME */ | |
298 | write_exp_elt_opcode (UNOP_ADDR); | |
299 | write_exp_elt_opcode (STRUCTOP_MPTR); } | |
300 | ; | |
301 | exp : exp ARROW '*' exp | |
302 | { write_exp_elt_opcode (STRUCTOP_MPTR); } | |
303 | ; | |
304 | ||
305 | exp : exp '.' name | |
306 | { write_exp_elt_opcode (STRUCTOP_STRUCT); | |
307 | write_exp_string ($3); | |
308 | write_exp_elt_opcode (STRUCTOP_STRUCT); } | |
309 | ; | |
310 | ||
311 | ||
312 | exp : exp '.' qualified_name | |
313 | { /* exp.type::name becomes exp.*(&type::name) */ | |
314 | /* Note: this doesn't work if name is a | |
315 | static member! FIXME */ | |
316 | write_exp_elt_opcode (UNOP_ADDR); | |
317 | write_exp_elt_opcode (STRUCTOP_MEMBER); } | |
318 | ; | |
319 | ||
320 | exp : exp '.' '*' exp | |
321 | { write_exp_elt_opcode (STRUCTOP_MEMBER); } | |
322 | ; | |
323 | ||
324 | exp : exp '[' exp1 ']' | |
325 | { write_exp_elt_opcode (BINOP_SUBSCRIPT); } | |
326 | ; | |
327 | /* | |
328 | * The rules below parse ObjC message calls of the form: | |
329 | * '[' target selector {':' argument}* ']' | |
330 | */ | |
331 | ||
332 | exp : '[' TYPENAME | |
333 | { | |
334 | CORE_ADDR class; | |
335 | ||
336 | class = lookup_objc_class (copy_name ($2.stoken)); | |
337 | if (class == 0) | |
338 | error ("%s is not an ObjC Class", | |
339 | copy_name ($2.stoken)); | |
340 | write_exp_elt_opcode (OP_LONG); | |
341 | write_exp_elt_type (builtin_type_int); | |
342 | write_exp_elt_longcst ((LONGEST) class); | |
343 | write_exp_elt_opcode (OP_LONG); | |
344 | start_msglist(); | |
345 | } | |
346 | msglist ']' | |
646df18d | 347 | { write_exp_elt_opcode (OP_OBJC_MSGCALL); |
b81654f1 | 348 | end_msglist(); |
646df18d | 349 | write_exp_elt_opcode (OP_OBJC_MSGCALL); |
b81654f1 MS |
350 | } |
351 | ; | |
352 | ||
353 | exp : '[' CLASSNAME | |
354 | { | |
355 | write_exp_elt_opcode (OP_LONG); | |
356 | write_exp_elt_type (builtin_type_int); | |
357 | write_exp_elt_longcst ((LONGEST) $2.class); | |
358 | write_exp_elt_opcode (OP_LONG); | |
359 | start_msglist(); | |
360 | } | |
361 | msglist ']' | |
646df18d | 362 | { write_exp_elt_opcode (OP_OBJC_MSGCALL); |
b81654f1 | 363 | end_msglist(); |
646df18d | 364 | write_exp_elt_opcode (OP_OBJC_MSGCALL); |
b81654f1 MS |
365 | } |
366 | ; | |
367 | ||
368 | exp : '[' exp | |
369 | { start_msglist(); } | |
370 | msglist ']' | |
646df18d | 371 | { write_exp_elt_opcode (OP_OBJC_MSGCALL); |
b81654f1 | 372 | end_msglist(); |
646df18d | 373 | write_exp_elt_opcode (OP_OBJC_MSGCALL); |
b81654f1 MS |
374 | } |
375 | ; | |
376 | ||
377 | msglist : name | |
378 | { add_msglist(&$1, 0); } | |
379 | | msgarglist | |
380 | ; | |
381 | ||
382 | msgarglist : msgarg | |
383 | | msgarglist msgarg | |
384 | ; | |
385 | ||
386 | msgarg : name ':' exp | |
387 | { add_msglist(&$1, 1); } | |
3b4efeaa | 388 | | ':' exp /* Unnamed arg. */ |
b81654f1 | 389 | { add_msglist(0, 1); } |
3b4efeaa | 390 | | ',' exp /* Variable number of args. */ |
b81654f1 MS |
391 | { add_msglist(0, 0); } |
392 | ; | |
393 | ||
394 | exp : exp '(' | |
395 | /* This is to save the value of arglist_len | |
396 | being accumulated by an outer function call. */ | |
397 | { start_arglist (); } | |
398 | arglist ')' %prec ARROW | |
399 | { write_exp_elt_opcode (OP_FUNCALL); | |
400 | write_exp_elt_longcst ((LONGEST) end_arglist ()); | |
401 | write_exp_elt_opcode (OP_FUNCALL); } | |
402 | ; | |
403 | ||
404 | lcurly : '{' | |
405 | { start_arglist (); } | |
406 | ; | |
407 | ||
408 | arglist : | |
409 | ; | |
410 | ||
411 | arglist : exp | |
412 | { arglist_len = 1; } | |
413 | ; | |
414 | ||
415 | arglist : arglist ',' exp %prec ABOVE_COMMA | |
416 | { arglist_len++; } | |
417 | ; | |
418 | ||
419 | rcurly : '}' | |
420 | { $$ = end_arglist () - 1; } | |
421 | ; | |
422 | exp : lcurly arglist rcurly %prec ARROW | |
423 | { write_exp_elt_opcode (OP_ARRAY); | |
424 | write_exp_elt_longcst ((LONGEST) 0); | |
425 | write_exp_elt_longcst ((LONGEST) $3); | |
426 | write_exp_elt_opcode (OP_ARRAY); } | |
427 | ; | |
428 | ||
429 | exp : lcurly type rcurly exp %prec UNARY | |
430 | { write_exp_elt_opcode (UNOP_MEMVAL); | |
431 | write_exp_elt_type ($2); | |
432 | write_exp_elt_opcode (UNOP_MEMVAL); } | |
433 | ; | |
434 | ||
435 | exp : '(' type ')' exp %prec UNARY | |
436 | { write_exp_elt_opcode (UNOP_CAST); | |
437 | write_exp_elt_type ($2); | |
438 | write_exp_elt_opcode (UNOP_CAST); } | |
439 | ; | |
440 | ||
441 | exp : '(' exp1 ')' | |
442 | { } | |
443 | ; | |
444 | ||
445 | /* Binary operators in order of decreasing precedence. */ | |
446 | ||
447 | exp : exp '@' exp | |
448 | { write_exp_elt_opcode (BINOP_REPEAT); } | |
449 | ; | |
450 | ||
451 | exp : exp '*' exp | |
452 | { write_exp_elt_opcode (BINOP_MUL); } | |
453 | ; | |
454 | ||
455 | exp : exp '/' exp | |
456 | { write_exp_elt_opcode (BINOP_DIV); } | |
457 | ; | |
458 | ||
459 | exp : exp '%' exp | |
460 | { write_exp_elt_opcode (BINOP_REM); } | |
461 | ; | |
462 | ||
463 | exp : exp '+' exp | |
464 | { write_exp_elt_opcode (BINOP_ADD); } | |
465 | ; | |
466 | ||
467 | exp : exp '-' exp | |
468 | { write_exp_elt_opcode (BINOP_SUB); } | |
469 | ; | |
470 | ||
471 | exp : exp LSH exp | |
472 | { write_exp_elt_opcode (BINOP_LSH); } | |
473 | ; | |
474 | ||
475 | exp : exp RSH exp | |
476 | { write_exp_elt_opcode (BINOP_RSH); } | |
477 | ; | |
478 | ||
479 | exp : exp EQUAL exp | |
480 | { write_exp_elt_opcode (BINOP_EQUAL); } | |
481 | ; | |
482 | ||
483 | exp : exp NOTEQUAL exp | |
484 | { write_exp_elt_opcode (BINOP_NOTEQUAL); } | |
485 | ; | |
486 | ||
487 | exp : exp LEQ exp | |
488 | { write_exp_elt_opcode (BINOP_LEQ); } | |
489 | ; | |
490 | ||
491 | exp : exp GEQ exp | |
492 | { write_exp_elt_opcode (BINOP_GEQ); } | |
493 | ; | |
494 | ||
495 | exp : exp '<' exp | |
496 | { write_exp_elt_opcode (BINOP_LESS); } | |
497 | ; | |
498 | ||
499 | exp : exp '>' exp | |
500 | { write_exp_elt_opcode (BINOP_GTR); } | |
501 | ; | |
502 | ||
503 | exp : exp '&' exp | |
504 | { write_exp_elt_opcode (BINOP_BITWISE_AND); } | |
505 | ; | |
506 | ||
507 | exp : exp '^' exp | |
508 | { write_exp_elt_opcode (BINOP_BITWISE_XOR); } | |
509 | ; | |
510 | ||
511 | exp : exp '|' exp | |
512 | { write_exp_elt_opcode (BINOP_BITWISE_IOR); } | |
513 | ; | |
514 | ||
515 | exp : exp ANDAND exp | |
516 | { write_exp_elt_opcode (BINOP_LOGICAL_AND); } | |
517 | ; | |
518 | ||
519 | exp : exp OROR exp | |
520 | { write_exp_elt_opcode (BINOP_LOGICAL_OR); } | |
521 | ; | |
522 | ||
523 | exp : exp '?' exp ':' exp %prec '?' | |
524 | { write_exp_elt_opcode (TERNOP_COND); } | |
525 | ; | |
526 | ||
527 | exp : exp '=' exp | |
528 | { write_exp_elt_opcode (BINOP_ASSIGN); } | |
529 | ; | |
530 | ||
531 | exp : exp ASSIGN_MODIFY exp | |
532 | { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); | |
533 | write_exp_elt_opcode ($2); | |
534 | write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } | |
535 | ; | |
536 | ||
537 | exp : INT | |
538 | { write_exp_elt_opcode (OP_LONG); | |
539 | write_exp_elt_type ($1.type); | |
540 | write_exp_elt_longcst ((LONGEST)($1.val)); | |
541 | write_exp_elt_opcode (OP_LONG); } | |
542 | ; | |
543 | ||
544 | exp : NAME_OR_INT | |
545 | { YYSTYPE val; | |
546 | parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val); | |
547 | write_exp_elt_opcode (OP_LONG); | |
548 | write_exp_elt_type (val.typed_val_int.type); | |
549 | write_exp_elt_longcst ((LONGEST)val.typed_val_int.val); | |
550 | write_exp_elt_opcode (OP_LONG); | |
551 | } | |
552 | ; | |
553 | ||
554 | ||
555 | exp : FLOAT | |
556 | { write_exp_elt_opcode (OP_DOUBLE); | |
557 | write_exp_elt_type ($1.type); | |
558 | write_exp_elt_dblcst ($1.dval); | |
559 | write_exp_elt_opcode (OP_DOUBLE); } | |
560 | ; | |
561 | ||
562 | exp : variable | |
563 | ; | |
564 | ||
565 | exp : VARIABLE | |
3b4efeaa | 566 | /* Already written by write_dollar_variable. */ |
b81654f1 MS |
567 | ; |
568 | ||
569 | exp : SELECTOR | |
570 | { | |
646df18d | 571 | write_exp_elt_opcode (OP_OBJC_SELECTOR); |
b81654f1 | 572 | write_exp_string ($1); |
646df18d | 573 | write_exp_elt_opcode (OP_OBJC_SELECTOR); } |
5edc9ca6 | 574 | ; |
b81654f1 MS |
575 | |
576 | exp : SIZEOF '(' type ')' %prec UNARY | |
577 | { write_exp_elt_opcode (OP_LONG); | |
578 | write_exp_elt_type (builtin_type_int); | |
579 | CHECK_TYPEDEF ($3); | |
580 | write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); | |
581 | write_exp_elt_opcode (OP_LONG); } | |
582 | ; | |
583 | ||
584 | exp : STRING | |
3b4efeaa MS |
585 | { /* C strings are converted into array |
586 | constants with an explicit null byte | |
587 | added at the end. Thus the array upper | |
588 | bound is the string length. There is no | |
589 | such thing in C as a completely empty | |
590 | string. */ | |
b81654f1 MS |
591 | char *sp = $1.ptr; int count = $1.length; |
592 | while (count-- > 0) | |
593 | { | |
594 | write_exp_elt_opcode (OP_LONG); | |
595 | write_exp_elt_type (builtin_type_char); | |
596 | write_exp_elt_longcst ((LONGEST)(*sp++)); | |
597 | write_exp_elt_opcode (OP_LONG); | |
598 | } | |
599 | write_exp_elt_opcode (OP_LONG); | |
600 | write_exp_elt_type (builtin_type_char); | |
601 | write_exp_elt_longcst ((LONGEST)'\0'); | |
602 | write_exp_elt_opcode (OP_LONG); | |
603 | write_exp_elt_opcode (OP_ARRAY); | |
604 | write_exp_elt_longcst ((LONGEST) 0); | |
605 | write_exp_elt_longcst ((LONGEST) ($1.length)); | |
606 | write_exp_elt_opcode (OP_ARRAY); } | |
607 | ; | |
608 | ||
609 | exp : NSSTRING /* ObjC NextStep NSString constant | |
3b4efeaa | 610 | * of the form '@' '"' string '"'. |
b81654f1 | 611 | */ |
646df18d | 612 | { write_exp_elt_opcode (OP_OBJC_NSSTRING); |
b81654f1 | 613 | write_exp_string ($1); |
646df18d | 614 | write_exp_elt_opcode (OP_OBJC_NSSTRING); } |
b81654f1 MS |
615 | ; |
616 | ||
b81654f1 MS |
617 | block : BLOCKNAME |
618 | { | |
619 | if ($1.sym != 0) | |
620 | $$ = SYMBOL_BLOCK_VALUE ($1.sym); | |
621 | else | |
622 | { | |
623 | struct symtab *tem = | |
624 | lookup_symtab (copy_name ($1.stoken)); | |
625 | if (tem) | |
626 | $$ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), STATIC_BLOCK); | |
627 | else | |
628 | error ("No file or function \"%s\".", | |
629 | copy_name ($1.stoken)); | |
630 | } | |
631 | } | |
632 | ; | |
633 | ||
634 | block : block COLONCOLON name | |
635 | { struct symbol *tem | |
636 | = lookup_symbol (copy_name ($3), $1, | |
176620f1 | 637 | VAR_DOMAIN, (int *) NULL, |
b81654f1 MS |
638 | (struct symtab **) NULL); |
639 | if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK) | |
640 | error ("No function \"%s\" in specified context.", | |
641 | copy_name ($3)); | |
642 | $$ = SYMBOL_BLOCK_VALUE (tem); } | |
643 | ; | |
644 | ||
645 | variable: block COLONCOLON name | |
646 | { struct symbol *sym; | |
647 | sym = lookup_symbol (copy_name ($3), $1, | |
176620f1 | 648 | VAR_DOMAIN, (int *) NULL, |
b81654f1 MS |
649 | (struct symtab **) NULL); |
650 | if (sym == 0) | |
651 | error ("No symbol \"%s\" in specified context.", | |
652 | copy_name ($3)); | |
653 | ||
654 | write_exp_elt_opcode (OP_VAR_VALUE); | |
655 | /* block_found is set by lookup_symbol. */ | |
656 | write_exp_elt_block (block_found); | |
657 | write_exp_elt_sym (sym); | |
658 | write_exp_elt_opcode (OP_VAR_VALUE); } | |
659 | ; | |
660 | ||
661 | qualified_name: typebase COLONCOLON name | |
662 | { | |
663 | struct type *type = $1; | |
664 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT | |
665 | && TYPE_CODE (type) != TYPE_CODE_UNION) | |
666 | error ("`%s' is not defined as an aggregate type.", | |
667 | TYPE_NAME (type)); | |
668 | ||
669 | write_exp_elt_opcode (OP_SCOPE); | |
670 | write_exp_elt_type (type); | |
671 | write_exp_string ($3); | |
672 | write_exp_elt_opcode (OP_SCOPE); | |
673 | } | |
674 | | typebase COLONCOLON '~' name | |
675 | { | |
676 | struct type *type = $1; | |
677 | struct stoken tmp_token; | |
678 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT | |
679 | && TYPE_CODE (type) != TYPE_CODE_UNION) | |
680 | error ("`%s' is not defined as an aggregate type.", | |
681 | TYPE_NAME (type)); | |
682 | ||
cb137aa5 | 683 | if (!DEPRECATED_STREQ (type_name_no_tag (type), $4.ptr)) |
b81654f1 MS |
684 | error ("invalid destructor `%s::~%s'", |
685 | type_name_no_tag (type), $4.ptr); | |
686 | ||
687 | tmp_token.ptr = (char*) alloca ($4.length + 2); | |
688 | tmp_token.length = $4.length + 1; | |
689 | tmp_token.ptr[0] = '~'; | |
690 | memcpy (tmp_token.ptr+1, $4.ptr, $4.length); | |
691 | tmp_token.ptr[tmp_token.length] = 0; | |
692 | write_exp_elt_opcode (OP_SCOPE); | |
693 | write_exp_elt_type (type); | |
694 | write_exp_string (tmp_token); | |
695 | write_exp_elt_opcode (OP_SCOPE); | |
696 | } | |
697 | ; | |
698 | ||
699 | variable: qualified_name | |
700 | | COLONCOLON name | |
701 | { | |
702 | char *name = copy_name ($2); | |
703 | struct symbol *sym; | |
704 | struct minimal_symbol *msymbol; | |
705 | ||
706 | sym = | |
707 | lookup_symbol (name, (const struct block *) NULL, | |
176620f1 | 708 | VAR_DOMAIN, (int *) NULL, |
b81654f1 MS |
709 | (struct symtab **) NULL); |
710 | if (sym) | |
711 | { | |
712 | write_exp_elt_opcode (OP_VAR_VALUE); | |
713 | write_exp_elt_block (NULL); | |
714 | write_exp_elt_sym (sym); | |
715 | write_exp_elt_opcode (OP_VAR_VALUE); | |
716 | break; | |
717 | } | |
718 | ||
719 | msymbol = lookup_minimal_symbol (name, NULL, NULL); | |
720 | if (msymbol != NULL) | |
721 | { | |
722 | write_exp_msymbol (msymbol, | |
723 | lookup_function_type (builtin_type_int), | |
724 | builtin_type_int); | |
725 | } | |
726 | else | |
727 | if (!have_full_symbols () && !have_partial_symbols ()) | |
728 | error ("No symbol table is loaded. Use the \"file\" command."); | |
729 | else | |
730 | error ("No symbol \"%s\" in current context.", name); | |
731 | } | |
732 | ; | |
733 | ||
734 | variable: name_not_typename | |
735 | { struct symbol *sym = $1.sym; | |
736 | ||
737 | if (sym) | |
738 | { | |
739 | if (symbol_read_needs_frame (sym)) | |
740 | { | |
741 | if (innermost_block == 0 || | |
742 | contained_in (block_found, | |
743 | innermost_block)) | |
744 | innermost_block = block_found; | |
745 | } | |
746 | ||
747 | write_exp_elt_opcode (OP_VAR_VALUE); | |
748 | /* We want to use the selected frame, not | |
749 | another more inner frame which happens to | |
750 | be in the same block. */ | |
751 | write_exp_elt_block (NULL); | |
752 | write_exp_elt_sym (sym); | |
753 | write_exp_elt_opcode (OP_VAR_VALUE); | |
754 | } | |
755 | else if ($1.is_a_field_of_this) | |
756 | { | |
757 | /* C++/ObjC: it hangs off of `this'/'self'. | |
758 | Must not inadvertently convert from a | |
759 | method call to data ref. */ | |
760 | if (innermost_block == 0 || | |
761 | contained_in (block_found, innermost_block)) | |
762 | innermost_block = block_found; | |
646df18d AF |
763 | write_exp_elt_opcode (OP_OBJC_SELF); |
764 | write_exp_elt_opcode (OP_OBJC_SELF); | |
b81654f1 MS |
765 | write_exp_elt_opcode (STRUCTOP_PTR); |
766 | write_exp_string ($1.stoken); | |
767 | write_exp_elt_opcode (STRUCTOP_PTR); | |
768 | } | |
769 | else | |
770 | { | |
771 | struct minimal_symbol *msymbol; | |
710122da | 772 | char *arg = copy_name ($1.stoken); |
b81654f1 MS |
773 | |
774 | msymbol = | |
775 | lookup_minimal_symbol (arg, NULL, NULL); | |
776 | if (msymbol != NULL) | |
777 | { | |
778 | write_exp_msymbol (msymbol, | |
779 | lookup_function_type (builtin_type_int), | |
780 | builtin_type_int); | |
781 | } | |
782 | else if (!have_full_symbols () && | |
783 | !have_partial_symbols ()) | |
784 | error ("No symbol table is loaded. Use the \"file\" command."); | |
785 | else | |
786 | error ("No symbol \"%s\" in current context.", | |
787 | copy_name ($1.stoken)); | |
788 | } | |
789 | } | |
790 | ; | |
791 | ||
792 | ||
793 | ptype : typebase | |
3b4efeaa MS |
794 | /* "const" and "volatile" are curently ignored. A type |
795 | qualifier before the type is currently handled in the | |
796 | typebase rule. The reason for recognizing these here | |
797 | (shift/reduce conflicts) might be obsolete now that some | |
798 | pointer to member rules have been deleted. */ | |
b81654f1 MS |
799 | | typebase CONST_KEYWORD |
800 | | typebase VOLATILE_KEYWORD | |
801 | | typebase abs_decl | |
802 | { $$ = follow_types ($1); } | |
803 | | typebase CONST_KEYWORD abs_decl | |
804 | { $$ = follow_types ($1); } | |
805 | | typebase VOLATILE_KEYWORD abs_decl | |
806 | { $$ = follow_types ($1); } | |
807 | ; | |
808 | ||
809 | abs_decl: '*' | |
810 | { push_type (tp_pointer); $$ = 0; } | |
811 | | '*' abs_decl | |
812 | { push_type (tp_pointer); $$ = $2; } | |
813 | | '&' | |
814 | { push_type (tp_reference); $$ = 0; } | |
815 | | '&' abs_decl | |
816 | { push_type (tp_reference); $$ = $2; } | |
817 | | direct_abs_decl | |
818 | ; | |
819 | ||
820 | direct_abs_decl: '(' abs_decl ')' | |
821 | { $$ = $2; } | |
822 | | direct_abs_decl array_mod | |
823 | { | |
824 | push_type_int ($2); | |
825 | push_type (tp_array); | |
826 | } | |
827 | | array_mod | |
828 | { | |
829 | push_type_int ($1); | |
830 | push_type (tp_array); | |
831 | $$ = 0; | |
832 | } | |
833 | ||
834 | | direct_abs_decl func_mod | |
835 | { push_type (tp_function); } | |
836 | | func_mod | |
837 | { push_type (tp_function); } | |
838 | ; | |
839 | ||
840 | array_mod: '[' ']' | |
841 | { $$ = -1; } | |
842 | | '[' INT ']' | |
843 | { $$ = $2.val; } | |
844 | ; | |
845 | ||
846 | func_mod: '(' ')' | |
847 | { $$ = 0; } | |
848 | | '(' nonempty_typelist ')' | |
8dbb1c65 | 849 | { free ($2); $$ = 0; } |
b81654f1 MS |
850 | ; |
851 | ||
852 | /* We used to try to recognize more pointer to member types here, but | |
3b4efeaa MS |
853 | that didn't work (shift/reduce conflicts meant that these rules |
854 | never got executed). The problem is that | |
b81654f1 MS |
855 | int (foo::bar::baz::bizzle) |
856 | is a function type but | |
857 | int (foo::bar::baz::bizzle::*) | |
858 | is a pointer to member type. Stroustrup loses again! */ | |
859 | ||
860 | type : ptype | |
b81654f1 MS |
861 | ; |
862 | ||
3b4efeaa | 863 | typebase /* Implements (approximately): (type-qualifier)* type-specifier. */ |
b81654f1 MS |
864 | : TYPENAME |
865 | { $$ = $1.type; } | |
866 | | CLASSNAME | |
867 | { | |
868 | if ($1.type == NULL) | |
869 | error ("No symbol \"%s\" in current context.", | |
870 | copy_name($1.stoken)); | |
871 | else | |
872 | $$ = $1.type; | |
873 | } | |
874 | | INT_KEYWORD | |
875 | { $$ = builtin_type_int; } | |
876 | | LONG | |
877 | { $$ = builtin_type_long; } | |
878 | | SHORT | |
879 | { $$ = builtin_type_short; } | |
880 | | LONG INT_KEYWORD | |
881 | { $$ = builtin_type_long; } | |
882 | | UNSIGNED LONG INT_KEYWORD | |
883 | { $$ = builtin_type_unsigned_long; } | |
884 | | LONG LONG | |
885 | { $$ = builtin_type_long_long; } | |
886 | | LONG LONG INT_KEYWORD | |
887 | { $$ = builtin_type_long_long; } | |
888 | | UNSIGNED LONG LONG | |
889 | { $$ = builtin_type_unsigned_long_long; } | |
890 | | UNSIGNED LONG LONG INT_KEYWORD | |
891 | { $$ = builtin_type_unsigned_long_long; } | |
892 | | SHORT INT_KEYWORD | |
893 | { $$ = builtin_type_short; } | |
894 | | UNSIGNED SHORT INT_KEYWORD | |
895 | { $$ = builtin_type_unsigned_short; } | |
896 | | DOUBLE_KEYWORD | |
897 | { $$ = builtin_type_double; } | |
898 | | LONG DOUBLE_KEYWORD | |
899 | { $$ = builtin_type_long_double; } | |
900 | | STRUCT name | |
901 | { $$ = lookup_struct (copy_name ($2), | |
902 | expression_context_block); } | |
903 | | CLASS name | |
904 | { $$ = lookup_struct (copy_name ($2), | |
905 | expression_context_block); } | |
906 | | UNION name | |
907 | { $$ = lookup_union (copy_name ($2), | |
908 | expression_context_block); } | |
909 | | ENUM name | |
910 | { $$ = lookup_enum (copy_name ($2), | |
911 | expression_context_block); } | |
912 | | UNSIGNED typename | |
913 | { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); } | |
914 | | UNSIGNED | |
915 | { $$ = builtin_type_unsigned_int; } | |
916 | | SIGNED_KEYWORD typename | |
917 | { $$ = lookup_signed_typename (TYPE_NAME($2.type)); } | |
918 | | SIGNED_KEYWORD | |
919 | { $$ = builtin_type_int; } | |
920 | | TEMPLATE name '<' type '>' | |
921 | { $$ = lookup_template_type(copy_name($2), $4, | |
922 | expression_context_block); | |
923 | } | |
3b4efeaa MS |
924 | /* "const" and "volatile" are curently ignored. A type |
925 | qualifier after the type is handled in the ptype rule. I | |
926 | think these could be too. */ | |
b81654f1 MS |
927 | | CONST_KEYWORD typebase { $$ = $2; } |
928 | | VOLATILE_KEYWORD typebase { $$ = $2; } | |
929 | ; | |
930 | ||
931 | typename: TYPENAME | |
932 | | INT_KEYWORD | |
933 | { | |
934 | $$.stoken.ptr = "int"; | |
935 | $$.stoken.length = 3; | |
936 | $$.type = builtin_type_int; | |
937 | } | |
938 | | LONG | |
939 | { | |
940 | $$.stoken.ptr = "long"; | |
941 | $$.stoken.length = 4; | |
942 | $$.type = builtin_type_long; | |
943 | } | |
944 | | SHORT | |
945 | { | |
946 | $$.stoken.ptr = "short"; | |
947 | $$.stoken.length = 5; | |
948 | $$.type = builtin_type_short; | |
949 | } | |
950 | ; | |
951 | ||
952 | nonempty_typelist | |
953 | : type | |
954 | { $$ = (struct type **) malloc (sizeof (struct type *) * 2); | |
3b4efeaa | 955 | $<ivec>$[0] = 1; /* Number of types in vector. */ |
b81654f1 MS |
956 | $$[1] = $1; |
957 | } | |
958 | | nonempty_typelist ',' type | |
959 | { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1); | |
960 | $$ = (struct type **) realloc ((char *) $1, len); | |
961 | $$[$<ivec>$[0]] = $3; | |
962 | } | |
963 | ; | |
964 | ||
965 | name : NAME { $$ = $1.stoken; } | |
966 | | BLOCKNAME { $$ = $1.stoken; } | |
967 | | TYPENAME { $$ = $1.stoken; } | |
968 | | CLASSNAME { $$ = $1.stoken; } | |
969 | | NAME_OR_INT { $$ = $1.stoken; } | |
970 | ; | |
971 | ||
972 | name_not_typename : NAME | |
973 | | BLOCKNAME | |
3b4efeaa MS |
974 | /* These would be useful if name_not_typename was useful, but it is |
975 | just a fake for "variable", so these cause reduce/reduce conflicts | |
976 | because the parser can't tell whether NAME_OR_INT is a | |
977 | name_not_typename (=variable, =exp) or just an exp. If | |
978 | name_not_typename was ever used in an lvalue context where only a | |
979 | name could occur, this might be useful. */ | |
9c96f9f2 | 980 | /* | NAME_OR_INT */ |
b81654f1 MS |
981 | ; |
982 | ||
983 | %% | |
984 | ||
985 | /* Take care of parsing a number (anything that starts with a digit). | |
3b4efeaa MS |
986 | Set yylval and return the token type; update lexptr. LEN is the |
987 | number of characters in it. */ | |
b81654f1 | 988 | |
3b4efeaa | 989 | /*** Needs some error checking for the float case. ***/ |
b81654f1 MS |
990 | |
991 | static int | |
992 | parse_number (p, len, parsed_float, putithere) | |
710122da DC |
993 | char *p; |
994 | int len; | |
b81654f1 MS |
995 | int parsed_float; |
996 | YYSTYPE *putithere; | |
997 | { | |
3b4efeaa MS |
998 | /* FIXME: Shouldn't these be unsigned? We don't deal with negative |
999 | values here, and we do kind of silly things like cast to | |
1000 | unsigned. */ | |
710122da DC |
1001 | LONGEST n = 0; |
1002 | LONGEST prevn = 0; | |
b81654f1 MS |
1003 | unsigned LONGEST un; |
1004 | ||
710122da DC |
1005 | int i = 0; |
1006 | int c; | |
1007 | int base = input_radix; | |
b81654f1 MS |
1008 | int unsigned_p = 0; |
1009 | ||
1010 | /* Number of "L" suffixes encountered. */ | |
1011 | int long_p = 0; | |
1012 | ||
1013 | /* We have found a "L" or "U" suffix. */ | |
1014 | int found_suffix = 0; | |
1015 | ||
1016 | unsigned LONGEST high_bit; | |
1017 | struct type *signed_type; | |
1018 | struct type *unsigned_type; | |
1019 | ||
1020 | if (parsed_float) | |
1021 | { | |
1022 | char c; | |
1023 | ||
1024 | /* It's a float since it contains a point or an exponent. */ | |
1025 | ||
a6205f53 | 1026 | sscanf (p, DOUBLEST_SCAN_FORMAT "%c", |
96c1eda2 | 1027 | &putithere->typed_val_float.dval, &c); |
b81654f1 MS |
1028 | |
1029 | /* See if it has `f' or `l' suffix (float or long double). */ | |
1030 | ||
1031 | c = tolower (p[len - 1]); | |
1032 | ||
1033 | if (c == 'f') | |
1034 | putithere->typed_val_float.type = builtin_type_float; | |
1035 | else if (c == 'l') | |
1036 | putithere->typed_val_float.type = builtin_type_long_double; | |
1037 | else if (isdigit (c) || c == '.') | |
1038 | putithere->typed_val_float.type = builtin_type_double; | |
1039 | else | |
1040 | return ERROR; | |
1041 | ||
1042 | return FLOAT; | |
1043 | } | |
1044 | ||
3b4efeaa | 1045 | /* Handle base-switching prefixes 0x, 0t, 0d, and 0. */ |
b81654f1 MS |
1046 | if (p[0] == '0') |
1047 | switch (p[1]) | |
1048 | { | |
1049 | case 'x': | |
1050 | case 'X': | |
1051 | if (len >= 3) | |
1052 | { | |
1053 | p += 2; | |
1054 | base = 16; | |
1055 | len -= 2; | |
1056 | } | |
1057 | break; | |
1058 | ||
1059 | case 't': | |
1060 | case 'T': | |
1061 | case 'd': | |
1062 | case 'D': | |
1063 | if (len >= 3) | |
1064 | { | |
1065 | p += 2; | |
1066 | base = 10; | |
1067 | len -= 2; | |
1068 | } | |
1069 | break; | |
1070 | ||
1071 | default: | |
1072 | base = 8; | |
1073 | break; | |
1074 | } | |
1075 | ||
1076 | while (len-- > 0) | |
1077 | { | |
1078 | c = *p++; | |
1079 | if (c >= 'A' && c <= 'Z') | |
1080 | c += 'a' - 'A'; | |
1081 | if (c != 'l' && c != 'u') | |
1082 | n *= base; | |
1083 | if (c >= '0' && c <= '9') | |
1084 | { | |
1085 | if (found_suffix) | |
1086 | return ERROR; | |
1087 | n += i = c - '0'; | |
1088 | } | |
1089 | else | |
1090 | { | |
1091 | if (base > 10 && c >= 'a' && c <= 'f') | |
1092 | { | |
1093 | if (found_suffix) | |
1094 | return ERROR; | |
1095 | n += i = c - 'a' + 10; | |
1096 | } | |
1097 | else if (c == 'l') | |
1098 | { | |
1099 | ++long_p; | |
1100 | found_suffix = 1; | |
1101 | } | |
1102 | else if (c == 'u') | |
1103 | { | |
1104 | unsigned_p = 1; | |
1105 | found_suffix = 1; | |
1106 | } | |
1107 | else | |
3b4efeaa | 1108 | return ERROR; /* Char not a digit. */ |
b81654f1 MS |
1109 | } |
1110 | if (i >= base) | |
3b4efeaa | 1111 | return ERROR; /* Invalid digit in this base. */ |
b81654f1 | 1112 | |
3b4efeaa MS |
1113 | /* Portably test for overflow (only works for nonzero values, so |
1114 | make a second check for zero). FIXME: Can't we just make n | |
1115 | and prevn unsigned and avoid this? */ | |
b81654f1 | 1116 | if (c != 'l' && c != 'u' && (prevn >= n) && n != 0) |
3b4efeaa | 1117 | unsigned_p = 1; /* Try something unsigned. */ |
b81654f1 MS |
1118 | |
1119 | /* Portably test for unsigned overflow. | |
3b4efeaa MS |
1120 | FIXME: This check is wrong; for example it doesn't find |
1121 | overflow on 0x123456789 when LONGEST is 32 bits. */ | |
b81654f1 MS |
1122 | if (c != 'l' && c != 'u' && n != 0) |
1123 | { | |
1124 | if ((unsigned_p && (unsigned LONGEST) prevn >= (unsigned LONGEST) n)) | |
1125 | error ("Numeric constant too large."); | |
1126 | } | |
1127 | prevn = n; | |
1128 | } | |
1129 | ||
1130 | /* An integer constant is an int, a long, or a long long. An L | |
1131 | suffix forces it to be long; an LL suffix forces it to be long | |
1132 | long. If not forced to a larger size, it gets the first type of | |
1133 | the above that it fits in. To figure out whether it fits, we | |
1134 | shift it right and see whether anything remains. Note that we | |
1135 | can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one | |
1136 | operation, because many compilers will warn about such a shift | |
1137 | (which always produces a zero result). Sometimes TARGET_INT_BIT | |
1138 | or TARGET_LONG_BIT will be that big, sometimes not. To deal with | |
1139 | the case where it is we just always shift the value more than | |
1140 | once, with fewer bits each time. */ | |
1141 | ||
1142 | un = (unsigned LONGEST)n >> 2; | |
1143 | if (long_p == 0 | |
1144 | && (un >> (TARGET_INT_BIT - 2)) == 0) | |
1145 | { | |
1146 | high_bit = ((unsigned LONGEST)1) << (TARGET_INT_BIT-1); | |
1147 | ||
1148 | /* A large decimal (not hex or octal) constant (between INT_MAX | |
1149 | and UINT_MAX) is a long or unsigned long, according to ANSI, | |
1150 | never an unsigned int, but this code treats it as unsigned | |
1151 | int. This probably should be fixed. GCC gives a warning on | |
1152 | such constants. */ | |
1153 | ||
1154 | unsigned_type = builtin_type_unsigned_int; | |
1155 | signed_type = builtin_type_int; | |
1156 | } | |
1157 | else if (long_p <= 1 | |
1158 | && (un >> (TARGET_LONG_BIT - 2)) == 0) | |
1159 | { | |
1160 | high_bit = ((unsigned LONGEST)1) << (TARGET_LONG_BIT-1); | |
1161 | unsigned_type = builtin_type_unsigned_long; | |
1162 | signed_type = builtin_type_long; | |
1163 | } | |
1164 | else | |
1165 | { | |
1166 | high_bit = (((unsigned LONGEST)1) | |
1167 | << (TARGET_LONG_LONG_BIT - 32 - 1) | |
1168 | << 16 | |
1169 | << 16); | |
1170 | if (high_bit == 0) | |
1171 | /* A long long does not fit in a LONGEST. */ | |
1172 | high_bit = | |
1173 | (unsigned LONGEST)1 << (sizeof (LONGEST) * HOST_CHAR_BIT - 1); | |
1174 | unsigned_type = builtin_type_unsigned_long_long; | |
1175 | signed_type = builtin_type_long_long; | |
1176 | } | |
1177 | ||
1178 | putithere->typed_val_int.val = n; | |
1179 | ||
1180 | /* If the high bit of the worked out type is set then this number | |
3b4efeaa | 1181 | has to be unsigned. */ |
b81654f1 MS |
1182 | |
1183 | if (unsigned_p || (n & high_bit)) | |
1184 | { | |
1185 | putithere->typed_val_int.type = unsigned_type; | |
1186 | } | |
1187 | else | |
1188 | { | |
1189 | putithere->typed_val_int.type = signed_type; | |
1190 | } | |
1191 | ||
1192 | return INT; | |
1193 | } | |
1194 | ||
1195 | struct token | |
1196 | { | |
1197 | char *operator; | |
1198 | int token; | |
1199 | enum exp_opcode opcode; | |
1200 | }; | |
1201 | ||
1202 | static const struct token tokentab3[] = | |
1203 | { | |
1204 | {">>=", ASSIGN_MODIFY, BINOP_RSH}, | |
1205 | {"<<=", ASSIGN_MODIFY, BINOP_LSH} | |
1206 | }; | |
1207 | ||
1208 | static const struct token tokentab2[] = | |
1209 | { | |
1210 | {"+=", ASSIGN_MODIFY, BINOP_ADD}, | |
1211 | {"-=", ASSIGN_MODIFY, BINOP_SUB}, | |
1212 | {"*=", ASSIGN_MODIFY, BINOP_MUL}, | |
1213 | {"/=", ASSIGN_MODIFY, BINOP_DIV}, | |
1214 | {"%=", ASSIGN_MODIFY, BINOP_REM}, | |
1215 | {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR}, | |
1216 | {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND}, | |
1217 | {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR}, | |
1218 | {"++", INCREMENT, BINOP_END}, | |
1219 | {"--", DECREMENT, BINOP_END}, | |
1220 | {"->", ARROW, BINOP_END}, | |
1221 | {"&&", ANDAND, BINOP_END}, | |
1222 | {"||", OROR, BINOP_END}, | |
1223 | {"::", COLONCOLON, BINOP_END}, | |
1224 | {"<<", LSH, BINOP_END}, | |
1225 | {">>", RSH, BINOP_END}, | |
1226 | {"==", EQUAL, BINOP_END}, | |
1227 | {"!=", NOTEQUAL, BINOP_END}, | |
1228 | {"<=", LEQ, BINOP_END}, | |
1229 | {">=", GEQ, BINOP_END} | |
1230 | }; | |
1231 | ||
1232 | /* Read one token, getting characters through lexptr. */ | |
1233 | ||
1234 | static int | |
1235 | yylex () | |
1236 | { | |
1237 | int c, tokchr; | |
1238 | int namelen; | |
1239 | unsigned int i; | |
1240 | char *tokstart; | |
1241 | char *tokptr; | |
1242 | int tempbufindex; | |
1243 | static char *tempbuf; | |
1244 | static int tempbufsize; | |
1245 | ||
1246 | retry: | |
1247 | ||
1248 | tokstart = lexptr; | |
1249 | /* See if it is a special token of length 3. */ | |
1250 | for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++) | |
cb137aa5 | 1251 | if (DEPRECATED_STREQN (tokstart, tokentab3[i].operator, 3)) |
b81654f1 MS |
1252 | { |
1253 | lexptr += 3; | |
1254 | yylval.opcode = tokentab3[i].opcode; | |
1255 | return tokentab3[i].token; | |
1256 | } | |
1257 | ||
1258 | /* See if it is a special token of length 2. */ | |
1259 | for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++) | |
cb137aa5 | 1260 | if (DEPRECATED_STREQN (tokstart, tokentab2[i].operator, 2)) |
b81654f1 MS |
1261 | { |
1262 | lexptr += 2; | |
1263 | yylval.opcode = tokentab2[i].opcode; | |
1264 | return tokentab2[i].token; | |
1265 | } | |
1266 | ||
7ee21aad | 1267 | c = 0; |
b81654f1 MS |
1268 | switch (tokchr = *tokstart) |
1269 | { | |
1270 | case 0: | |
1271 | return 0; | |
1272 | ||
1273 | case ' ': | |
1274 | case '\t': | |
1275 | case '\n': | |
1276 | lexptr++; | |
1277 | goto retry; | |
1278 | ||
1279 | case '\'': | |
3b4efeaa MS |
1280 | /* We either have a character constant ('0' or '\177' for |
1281 | example) or we have a quoted symbol reference ('foo(int,int)' | |
1282 | in C++ for example). */ | |
b81654f1 MS |
1283 | lexptr++; |
1284 | c = *lexptr++; | |
1285 | if (c == '\\') | |
1286 | c = parse_escape (&lexptr); | |
1287 | else if (c == '\'') | |
1288 | error ("Empty character constant."); | |
1289 | ||
1290 | yylval.typed_val_int.val = c; | |
1291 | yylval.typed_val_int.type = builtin_type_char; | |
1292 | ||
1293 | c = *lexptr++; | |
1294 | if (c != '\'') | |
1295 | { | |
e8afa4d7 | 1296 | namelen = skip_quoted (tokstart) - tokstart; |
b81654f1 MS |
1297 | if (namelen > 2) |
1298 | { | |
1299 | lexptr = tokstart + namelen; | |
1300 | if (lexptr[-1] != '\'') | |
1301 | error ("Unmatched single quote."); | |
1302 | namelen -= 2; | |
1303 | tokstart++; | |
1304 | goto tryname; | |
1305 | } | |
1306 | error ("Invalid character constant."); | |
1307 | } | |
1308 | return INT; | |
1309 | ||
1310 | case '(': | |
1311 | paren_depth++; | |
1312 | lexptr++; | |
1313 | return '('; | |
1314 | ||
1315 | case ')': | |
1316 | if (paren_depth == 0) | |
1317 | return 0; | |
1318 | paren_depth--; | |
1319 | lexptr++; | |
1320 | return ')'; | |
1321 | ||
1322 | case ',': | |
1323 | if (comma_terminates && paren_depth == 0) | |
1324 | return 0; | |
1325 | lexptr++; | |
1326 | return ','; | |
1327 | ||
1328 | case '.': | |
1329 | /* Might be a floating point number. */ | |
1330 | if (lexptr[1] < '0' || lexptr[1] > '9') | |
3b4efeaa | 1331 | goto symbol; /* Nope, must be a symbol. */ |
b81654f1 MS |
1332 | /* FALL THRU into number case. */ |
1333 | ||
1334 | case '0': | |
1335 | case '1': | |
1336 | case '2': | |
1337 | case '3': | |
1338 | case '4': | |
1339 | case '5': | |
1340 | case '6': | |
1341 | case '7': | |
1342 | case '8': | |
1343 | case '9': | |
1344 | { | |
1345 | /* It's a number. */ | |
1346 | int got_dot = 0, got_e = 0, toktype = FLOAT; | |
3b4efeaa | 1347 | /* Initialize toktype to anything other than ERROR. */ |
710122da | 1348 | char *p = tokstart; |
b81654f1 MS |
1349 | int hex = input_radix > 10; |
1350 | int local_radix = input_radix; | |
1351 | if (tokchr == '0' && (p[1] == 'x' || p[1] == 'X')) | |
1352 | { | |
1353 | p += 2; | |
1354 | hex = 1; | |
1355 | local_radix = 16; | |
1356 | } | |
1357 | else if (tokchr == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D')) | |
1358 | { | |
1359 | p += 2; | |
1360 | hex = 0; | |
1361 | local_radix = 10; | |
1362 | } | |
1363 | ||
1364 | for (;; ++p) | |
1365 | { | |
1366 | /* This test includes !hex because 'e' is a valid hex digit | |
1367 | and thus does not indicate a floating point number when | |
1368 | the radix is hex. */ | |
1369 | ||
1370 | if (!hex && (*p == 'e' || *p == 'E')) | |
1371 | if (got_e) | |
3b4efeaa | 1372 | toktype = ERROR; /* Only one 'e' in a float. */ |
b81654f1 MS |
1373 | else |
1374 | got_e = 1; | |
3b4efeaa MS |
1375 | /* This test does not include !hex, because a '.' always |
1376 | indicates a decimal floating point number regardless of | |
1377 | the radix. */ | |
b81654f1 MS |
1378 | else if (*p == '.') |
1379 | if (got_dot) | |
3b4efeaa | 1380 | toktype = ERROR; /* Only one '.' in a float. */ |
b81654f1 MS |
1381 | else |
1382 | got_dot = 1; | |
1383 | else if (got_e && (p[-1] == 'e' || p[-1] == 'E') && | |
1384 | (*p == '-' || *p == '+')) | |
1385 | /* This is the sign of the exponent, not the end of the | |
1386 | number. */ | |
1387 | continue; | |
3b4efeaa MS |
1388 | /* Always take decimal digits; parse_number handles radix |
1389 | error. */ | |
b81654f1 MS |
1390 | else if (*p >= '0' && *p <= '9') |
1391 | continue; | |
3b4efeaa MS |
1392 | /* We will take letters only if hex is true, and only up |
1393 | to what the input radix would permit. FSF was content | |
1394 | to rely on parse_number to validate; but it leaks. */ | |
1395 | else if (*p >= 'a' && *p <= 'z') | |
1396 | { | |
1397 | if (!hex || *p >= ('a' + local_radix - 10)) | |
1398 | toktype = ERROR; | |
1399 | } | |
1400 | else if (*p >= 'A' && *p <= 'Z') | |
1401 | { | |
1402 | if (!hex || *p >= ('A' + local_radix - 10)) | |
1403 | toktype = ERROR; | |
1404 | } | |
b81654f1 MS |
1405 | else break; |
1406 | } | |
1407 | if (toktype != ERROR) | |
3b4efeaa MS |
1408 | toktype = parse_number (tokstart, p - tokstart, |
1409 | got_dot | got_e, &yylval); | |
b81654f1 MS |
1410 | if (toktype == ERROR) |
1411 | { | |
1412 | char *err_copy = (char *) alloca (p - tokstart + 1); | |
1413 | ||
1414 | memcpy (err_copy, tokstart, p - tokstart); | |
1415 | err_copy[p - tokstart] = 0; | |
1416 | error ("Invalid number \"%s\".", err_copy); | |
1417 | } | |
1418 | lexptr = p; | |
1419 | return toktype; | |
1420 | } | |
1421 | ||
1422 | case '+': | |
1423 | case '-': | |
1424 | case '*': | |
1425 | case '/': | |
1426 | case '%': | |
1427 | case '|': | |
1428 | case '&': | |
1429 | case '^': | |
1430 | case '~': | |
1431 | case '!': | |
1432 | #if 0 | |
3b4efeaa | 1433 | case '@': /* Moved out below. */ |
b81654f1 MS |
1434 | #endif |
1435 | case '<': | |
1436 | case '>': | |
1437 | case '[': | |
1438 | case ']': | |
1439 | case '?': | |
1440 | case ':': | |
1441 | case '=': | |
1442 | case '{': | |
1443 | case '}': | |
1444 | symbol: | |
1445 | lexptr++; | |
1446 | return tokchr; | |
1447 | ||
1448 | case '@': | |
1449 | if (strncmp(tokstart, "@selector", 9) == 0) | |
1450 | { | |
1451 | tokptr = strchr(tokstart, '('); | |
1452 | if (tokptr == NULL) | |
1453 | { | |
1454 | error ("Missing '(' in @selector(...)"); | |
1455 | } | |
1456 | tempbufindex = 0; | |
3b4efeaa | 1457 | tokptr++; /* Skip the '('. */ |
b81654f1 | 1458 | do { |
3b4efeaa MS |
1459 | /* Grow the static temp buffer if necessary, including |
1460 | allocating the first one on demand. */ | |
b81654f1 MS |
1461 | if (tempbufindex + 1 >= tempbufsize) |
1462 | { | |
1463 | tempbuf = (char *) realloc (tempbuf, tempbufsize += 64); | |
1464 | } | |
1465 | tempbuf[tempbufindex++] = *tokptr++; | |
1466 | } while ((*tokptr != ')') && (*tokptr != '\0')); | |
1467 | if (*tokptr++ != ')') | |
1468 | { | |
1469 | error ("Missing ')' in @selector(...)"); | |
1470 | } | |
1471 | tempbuf[tempbufindex] = '\0'; | |
1472 | yylval.sval.ptr = tempbuf; | |
1473 | yylval.sval.length = tempbufindex; | |
1474 | lexptr = tokptr; | |
1475 | return SELECTOR; | |
1476 | } | |
1477 | if (tokstart[1] != '"') | |
1478 | { | |
1479 | lexptr++; | |
1480 | return tokchr; | |
1481 | } | |
3b4efeaa MS |
1482 | /* ObjC NextStep NSString constant: fall thru and parse like |
1483 | STRING. */ | |
b81654f1 MS |
1484 | tokstart++; |
1485 | ||
1486 | case '"': | |
1487 | ||
1488 | /* Build the gdb internal form of the input string in tempbuf, | |
1489 | translating any standard C escape forms seen. Note that the | |
1490 | buffer is null byte terminated *only* for the convenience of | |
1491 | debugging gdb itself and printing the buffer contents when | |
1492 | the buffer contains no embedded nulls. Gdb does not depend | |
3b4efeaa MS |
1493 | upon the buffer being null byte terminated, it uses the |
1494 | length string instead. This allows gdb to handle C strings | |
1495 | (as well as strings in other languages) with embedded null | |
1496 | bytes. */ | |
b81654f1 MS |
1497 | |
1498 | tokptr = ++tokstart; | |
1499 | tempbufindex = 0; | |
1500 | ||
1501 | do { | |
3b4efeaa MS |
1502 | /* Grow the static temp buffer if necessary, including |
1503 | allocating the first one on demand. */ | |
b81654f1 MS |
1504 | if (tempbufindex + 1 >= tempbufsize) |
1505 | { | |
1506 | tempbuf = (char *) realloc (tempbuf, tempbufsize += 64); | |
1507 | } | |
1508 | switch (*tokptr) | |
1509 | { | |
1510 | case '\0': | |
1511 | case '"': | |
3b4efeaa | 1512 | /* Do nothing, loop will terminate. */ |
b81654f1 MS |
1513 | break; |
1514 | case '\\': | |
1515 | tokptr++; | |
1516 | c = parse_escape (&tokptr); | |
1517 | if (c == -1) | |
1518 | { | |
1519 | continue; | |
1520 | } | |
1521 | tempbuf[tempbufindex++] = c; | |
1522 | break; | |
1523 | default: | |
1524 | tempbuf[tempbufindex++] = *tokptr++; | |
1525 | break; | |
1526 | } | |
1527 | } while ((*tokptr != '"') && (*tokptr != '\0')); | |
1528 | if (*tokptr++ != '"') | |
1529 | { | |
1530 | error ("Unterminated string in expression."); | |
1531 | } | |
3b4efeaa | 1532 | tempbuf[tempbufindex] = '\0'; /* See note above. */ |
b81654f1 MS |
1533 | yylval.sval.ptr = tempbuf; |
1534 | yylval.sval.length = tempbufindex; | |
1535 | lexptr = tokptr; | |
1536 | return (tokchr == '@' ? NSSTRING : STRING); | |
1537 | } | |
1538 | ||
1539 | if (!(tokchr == '_' || tokchr == '$' || | |
1540 | (tokchr >= 'a' && tokchr <= 'z') || (tokchr >= 'A' && tokchr <= 'Z'))) | |
1541 | /* We must have come across a bad character (e.g. ';'). */ | |
1542 | error ("Invalid character '%c' in expression.", c); | |
1543 | ||
1544 | /* It's a name. See how long it is. */ | |
1545 | namelen = 0; | |
1546 | for (c = tokstart[namelen]; | |
1547 | (c == '_' || c == '$' || (c >= '0' && c <= '9') | |
1548 | || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');) | |
1549 | { | |
1550 | if (c == '<') | |
1551 | { | |
1552 | int i = namelen; | |
1553 | while (tokstart[++i] && tokstart[i] != '>'); | |
1554 | if (tokstart[i] == '>') | |
1555 | namelen = i; | |
1556 | } | |
1557 | c = tokstart[++namelen]; | |
1558 | } | |
1559 | ||
1560 | /* The token "if" terminates the expression and is NOT | |
1561 | removed from the input stream. */ | |
1562 | if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f') | |
1563 | { | |
1564 | return 0; | |
1565 | } | |
1566 | ||
1567 | lexptr += namelen; | |
1568 | ||
1569 | tryname: | |
1570 | ||
1571 | /* Catch specific keywords. Should be done with a data structure. */ | |
1572 | switch (namelen) | |
1573 | { | |
1574 | case 8: | |
cb137aa5 | 1575 | if (DEPRECATED_STREQN (tokstart, "unsigned", 8)) |
b81654f1 MS |
1576 | return UNSIGNED; |
1577 | if (current_language->la_language == language_cplus | |
bf896cb0 | 1578 | && strncmp (tokstart, "template", 8) == 0) |
b81654f1 | 1579 | return TEMPLATE; |
cb137aa5 | 1580 | if (DEPRECATED_STREQN (tokstart, "volatile", 8)) |
b81654f1 MS |
1581 | return VOLATILE_KEYWORD; |
1582 | break; | |
1583 | case 6: | |
cb137aa5 | 1584 | if (DEPRECATED_STREQN (tokstart, "struct", 6)) |
b81654f1 | 1585 | return STRUCT; |
cb137aa5 | 1586 | if (DEPRECATED_STREQN (tokstart, "signed", 6)) |
b81654f1 | 1587 | return SIGNED_KEYWORD; |
cb137aa5 | 1588 | if (DEPRECATED_STREQN (tokstart, "sizeof", 6)) |
b81654f1 | 1589 | return SIZEOF; |
cb137aa5 | 1590 | if (DEPRECATED_STREQN (tokstart, "double", 6)) |
b81654f1 MS |
1591 | return DOUBLE_KEYWORD; |
1592 | break; | |
1593 | case 5: | |
1594 | if ((current_language->la_language == language_cplus) | |
bf896cb0 | 1595 | && strncmp (tokstart, "class", 5) == 0) |
b81654f1 | 1596 | return CLASS; |
cb137aa5 | 1597 | if (DEPRECATED_STREQN (tokstart, "union", 5)) |
b81654f1 | 1598 | return UNION; |
cb137aa5 | 1599 | if (DEPRECATED_STREQN (tokstart, "short", 5)) |
b81654f1 | 1600 | return SHORT; |
cb137aa5 | 1601 | if (DEPRECATED_STREQN (tokstart, "const", 5)) |
b81654f1 MS |
1602 | return CONST_KEYWORD; |
1603 | break; | |
1604 | case 4: | |
cb137aa5 | 1605 | if (DEPRECATED_STREQN (tokstart, "enum", 4)) |
b81654f1 | 1606 | return ENUM; |
cb137aa5 | 1607 | if (DEPRECATED_STREQN (tokstart, "long", 4)) |
b81654f1 | 1608 | return LONG; |
b81654f1 MS |
1609 | break; |
1610 | case 3: | |
cb137aa5 | 1611 | if (DEPRECATED_STREQN (tokstart, "int", 3)) |
b81654f1 MS |
1612 | return INT_KEYWORD; |
1613 | break; | |
1614 | default: | |
1615 | break; | |
1616 | } | |
1617 | ||
1618 | yylval.sval.ptr = tokstart; | |
1619 | yylval.sval.length = namelen; | |
1620 | ||
1621 | if (*tokstart == '$') | |
1622 | { | |
1623 | write_dollar_variable (yylval.sval); | |
1624 | return VARIABLE; | |
1625 | } | |
1626 | ||
1627 | /* Use token-type BLOCKNAME for symbols that happen to be defined as | |
1628 | functions or symtabs. If this is not so, then ... | |
1629 | Use token-type TYPENAME for symbols that happen to be defined | |
1630 | currently as names of types; NAME for other symbols. | |
1631 | The caller is not constrained to care about the distinction. */ | |
1632 | { | |
1633 | char *tmp = copy_name (yylval.sval); | |
1634 | struct symbol *sym; | |
1635 | int is_a_field_of_this = 0, *need_this; | |
1636 | int hextype; | |
1637 | ||
1638 | if (current_language->la_language == language_cplus || | |
1639 | current_language->la_language == language_objc) | |
1640 | need_this = &is_a_field_of_this; | |
1641 | else | |
1642 | need_this = (int *) NULL; | |
1643 | ||
1644 | sym = lookup_symbol (tmp, expression_context_block, | |
176620f1 | 1645 | VAR_DOMAIN, |
b81654f1 MS |
1646 | need_this, |
1647 | (struct symtab **) NULL); | |
3b4efeaa MS |
1648 | /* Call lookup_symtab, not lookup_partial_symtab, in case there |
1649 | are no psymtabs (coff, xcoff, or some future change to blow | |
1650 | away the psymtabs once symbols are read). */ | |
b81654f1 MS |
1651 | if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) || |
1652 | lookup_symtab (tmp)) | |
1653 | { | |
1654 | yylval.ssym.sym = sym; | |
1655 | yylval.ssym.is_a_field_of_this = is_a_field_of_this; | |
1656 | return BLOCKNAME; | |
1657 | } | |
1658 | if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF) | |
1659 | { | |
1660 | #if 1 | |
3b4efeaa MS |
1661 | /* Despite the following flaw, we need to keep this code |
1662 | enabled. Because we can get called from | |
1663 | check_stub_method, if we don't handle nested types then | |
1664 | it screws many operations in any program which uses | |
1665 | nested types. */ | |
1666 | /* In "A::x", if x is a member function of A and there | |
1667 | happens to be a type (nested or not, since the stabs | |
1668 | don't make that distinction) named x, then this code | |
1669 | incorrectly thinks we are dealing with nested types | |
1670 | rather than a member function. */ | |
b81654f1 MS |
1671 | |
1672 | char *p; | |
1673 | char *namestart; | |
1674 | struct symbol *best_sym; | |
1675 | ||
3b4efeaa MS |
1676 | /* Look ahead to detect nested types. This probably should |
1677 | be done in the grammar, but trying seemed to introduce a | |
1678 | lot of shift/reduce and reduce/reduce conflicts. It's | |
1679 | possible that it could be done, though. Or perhaps a | |
1680 | non-grammar, but less ad hoc, approach would work well. */ | |
b81654f1 MS |
1681 | |
1682 | /* Since we do not currently have any way of distinguishing | |
1683 | a nested type from a non-nested one (the stabs don't tell | |
1684 | us whether a type is nested), we just ignore the | |
1685 | containing type. */ | |
1686 | ||
1687 | p = lexptr; | |
1688 | best_sym = sym; | |
1689 | while (1) | |
1690 | { | |
1691 | /* Skip whitespace. */ | |
1692 | while (*p == ' ' || *p == '\t' || *p == '\n') | |
1693 | ++p; | |
1694 | if (*p == ':' && p[1] == ':') | |
1695 | { | |
1696 | /* Skip the `::'. */ | |
1697 | p += 2; | |
1698 | /* Skip whitespace. */ | |
1699 | while (*p == ' ' || *p == '\t' || *p == '\n') | |
1700 | ++p; | |
1701 | namestart = p; | |
1702 | while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9') | |
1703 | || (*p >= 'a' && *p <= 'z') | |
1704 | || (*p >= 'A' && *p <= 'Z')) | |
1705 | ++p; | |
1706 | if (p != namestart) | |
1707 | { | |
1708 | struct symbol *cur_sym; | |
3b4efeaa MS |
1709 | /* As big as the whole rest of the expression, |
1710 | which is at least big enough. */ | |
1711 | char *ncopy = alloca (strlen (tmp) + | |
1712 | strlen (namestart) + 3); | |
b81654f1 MS |
1713 | char *tmp1; |
1714 | ||
1715 | tmp1 = ncopy; | |
1716 | memcpy (tmp1, tmp, strlen (tmp)); | |
1717 | tmp1 += strlen (tmp); | |
1718 | memcpy (tmp1, "::", 2); | |
1719 | tmp1 += 2; | |
1720 | memcpy (tmp1, namestart, p - namestart); | |
1721 | tmp1[p - namestart] = '\0'; | |
3b4efeaa MS |
1722 | cur_sym = lookup_symbol (ncopy, |
1723 | expression_context_block, | |
176620f1 | 1724 | VAR_DOMAIN, (int *) NULL, |
b81654f1 MS |
1725 | (struct symtab **) NULL); |
1726 | if (cur_sym) | |
1727 | { | |
1728 | if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF) | |
1729 | { | |
1730 | best_sym = cur_sym; | |
1731 | lexptr = p; | |
1732 | } | |
1733 | else | |
1734 | break; | |
1735 | } | |
1736 | else | |
1737 | break; | |
1738 | } | |
1739 | else | |
1740 | break; | |
1741 | } | |
1742 | else | |
1743 | break; | |
1744 | } | |
1745 | ||
1746 | yylval.tsym.type = SYMBOL_TYPE (best_sym); | |
1747 | #else /* not 0 */ | |
1748 | yylval.tsym.type = SYMBOL_TYPE (sym); | |
1749 | #endif /* not 0 */ | |
1750 | return TYPENAME; | |
1751 | } | |
54a5b07d AC |
1752 | yylval.tsym.type |
1753 | = language_lookup_primitive_type_by_name (current_language, | |
1754 | current_gdbarch, tmp); | |
1755 | if (yylval.tsym.type != NULL) | |
1756 | return TYPENAME; | |
b81654f1 | 1757 | |
3b4efeaa MS |
1758 | /* See if it's an ObjC classname. */ |
1759 | if (!sym) | |
b81654f1 MS |
1760 | { |
1761 | CORE_ADDR Class = lookup_objc_class(tmp); | |
1762 | if (Class) | |
1763 | { | |
b81654f1 | 1764 | yylval.class.class = Class; |
3b4efeaa MS |
1765 | if ((sym = lookup_struct_typedef (tmp, |
1766 | expression_context_block, | |
1767 | 1))) | |
b81654f1 MS |
1768 | yylval.class.type = SYMBOL_TYPE (sym); |
1769 | return CLASSNAME; | |
1770 | } | |
1771 | } | |
1772 | ||
1773 | /* Input names that aren't symbols but ARE valid hex numbers, | |
1774 | when the input radix permits them, can be names or numbers | |
1775 | depending on the parse. Note we support radixes > 16 here. */ | |
1776 | if (!sym && | |
1777 | ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) || | |
1778 | (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10))) | |
1779 | { | |
1780 | YYSTYPE newlval; /* Its value is ignored. */ | |
1781 | hextype = parse_number (tokstart, namelen, 0, &newlval); | |
1782 | if (hextype == INT) | |
1783 | { | |
1784 | yylval.ssym.sym = sym; | |
1785 | yylval.ssym.is_a_field_of_this = is_a_field_of_this; | |
1786 | return NAME_OR_INT; | |
1787 | } | |
1788 | } | |
1789 | ||
3b4efeaa | 1790 | /* Any other kind of symbol. */ |
b81654f1 MS |
1791 | yylval.ssym.sym = sym; |
1792 | yylval.ssym.is_a_field_of_this = is_a_field_of_this; | |
1793 | return NAME; | |
1794 | } | |
1795 | } | |
1796 | ||
1797 | void | |
1798 | yyerror (msg) | |
1799 | char *msg; | |
1800 | { | |
1801 | if (*lexptr == '\0') | |
1802 | error("A %s near end of expression.", (msg ? msg : "error")); | |
1803 | else | |
3b4efeaa MS |
1804 | error ("A %s in expression, near `%s'.", (msg ? msg : "error"), |
1805 | lexptr); | |
b81654f1 | 1806 | } |