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