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