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