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