]>
Commit | Line | Data |
---|---|---|
5e548861 PB |
1 | /* Parser for GNU CHILL (CCITT High-Level Language) -*- C -*- |
2 | Copyright (C) 1992, 1993, 1995 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | /* Parse a Chill expression from text in a string, | |
21 | and return the result as a struct expression pointer. | |
22 | That structure contains arithmetic operations in reverse polish, | |
23 | with constants represented by operations that are followed by special data. | |
24 | See expression.h for the details of the format. | |
25 | What is important here is that it can be built up sequentially | |
26 | during the process of parsing; the lower levels of the tree always | |
27 | come first in the result. | |
28 | ||
6405302d | 29 | Note that the language accepted by this parser is more liberal |
5e548861 PB |
30 | than the one accepted by an actual Chill compiler. For example, the |
31 | language rule that a simple name string can not be one of the reserved | |
32 | simple name strings is not enforced (e.g "case" is not treated as a | |
33 | reserved name). Another example is that Chill is a strongly typed | |
34 | language, and certain expressions that violate the type constraints | |
35 | may still be evaluated if gdb can do so in a meaningful manner, while | |
36 | such expressions would be rejected by the compiler. The reason for | |
37 | this more liberal behavior is the philosophy that the debugger | |
38 | is intended to be a tool that is used by the programmer when things | |
39 | go wrong, and as such, it should provide as few artificial barriers | |
40 | to it's use as possible. If it can do something meaningful, even | |
41 | something that violates language contraints that are enforced by the | |
42 | compiler, it should do so without complaint. | |
43 | ||
44 | */ | |
45 | ||
46 | #include "defs.h" | |
47 | #include <string.h> | |
48 | #include <ctype.h> | |
49 | #include "expression.h" | |
50 | #include "language.h" | |
51 | #include "value.h" | |
52 | #include "parser-defs.h" | |
53 | #include "ch-lang.h" | |
54 | #include "bfd.h" /* Required by objfiles.h. */ | |
55 | #include "symfile.h" /* Required by objfiles.h. */ | |
56 | #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ | |
57 | ||
58 | typedef union | |
59 | ||
60 | { | |
61 | LONGEST lval; | |
62 | unsigned LONGEST ulval; | |
63 | struct { | |
64 | LONGEST val; | |
65 | struct type *type; | |
66 | } typed_val; | |
67 | double dval; | |
68 | struct symbol *sym; | |
69 | struct type *tval; | |
70 | struct stoken sval; | |
71 | struct ttype tsym; | |
72 | struct symtoken ssym; | |
73 | }YYSTYPE; | |
74 | ||
75 | enum ch_terminal { | |
76 | END_TOKEN = 0, | |
77 | /* '\001' ... '\xff' come first. */ | |
78 | TOKEN_NOT_READ = 999, | |
79 | INTEGER_LITERAL, | |
80 | BOOLEAN_LITERAL, | |
81 | CHARACTER_LITERAL, | |
82 | FLOAT_LITERAL, | |
83 | GENERAL_PROCEDURE_NAME, | |
84 | LOCATION_NAME, | |
85 | EMPTINESS_LITERAL, | |
86 | CHARACTER_STRING_LITERAL, | |
87 | BIT_STRING_LITERAL, | |
88 | TYPENAME, | |
89 | FIELD_NAME, | |
90 | CASE, | |
91 | OF, | |
92 | ESAC, | |
93 | LOGIOR, | |
94 | ORIF, | |
95 | LOGXOR, | |
96 | LOGAND, | |
97 | ANDIF, | |
98 | NOTEQUAL, | |
99 | GEQ, | |
100 | LEQ, | |
101 | IN, | |
102 | SLASH_SLASH, | |
103 | MOD, | |
104 | REM, | |
105 | NOT, | |
106 | POINTER, | |
107 | RECEIVE, | |
108 | UP, | |
109 | IF, | |
110 | THEN, | |
111 | ELSE, | |
112 | FI, | |
113 | ELSIF, | |
114 | ILLEGAL_TOKEN, | |
115 | NUM, | |
116 | PRED, | |
117 | SUCC, | |
118 | ABS, | |
119 | CARD, | |
120 | MAX_TOKEN, | |
121 | MIN_TOKEN, | |
122 | ADDR_TOKEN, | |
123 | SIZE, | |
124 | UPPER, | |
125 | LOWER, | |
126 | LENGTH, | |
127 | ARRAY, | |
128 | GDB_VARIABLE, | |
129 | GDB_ASSIGNMENT | |
130 | }; | |
131 | ||
132 | /* Forward declarations. */ | |
133 | static void parse_expr (); | |
134 | static void parse_primval (); | |
135 | static void parse_untyped_expr (); | |
136 | static int parse_opt_untyped_expr (); | |
137 | static void parse_if_expression_body PARAMS((void)); | |
138 | static void write_lower_upper_value PARAMS ((enum exp_opcode, struct type *)); | |
139 | static enum ch_terminal ch_lex (); | |
140 | ||
141 | #define MAX_LOOK_AHEAD 2 | |
142 | static enum ch_terminal terminal_buffer[MAX_LOOK_AHEAD+1] = { | |
143 | TOKEN_NOT_READ, TOKEN_NOT_READ, TOKEN_NOT_READ}; | |
144 | static YYSTYPE yylval; | |
145 | static YYSTYPE val_buffer[MAX_LOOK_AHEAD+1]; | |
146 | ||
147 | /*int current_token, lookahead_token;*/ | |
148 | ||
149 | #ifdef __GNUC__ | |
150 | __inline__ | |
151 | #endif | |
152 | static enum ch_terminal | |
153 | PEEK_TOKEN() | |
154 | { | |
155 | if (terminal_buffer[0] == TOKEN_NOT_READ) | |
156 | { | |
157 | terminal_buffer[0] = ch_lex (); | |
158 | val_buffer[0] = yylval; | |
159 | } | |
160 | return terminal_buffer[0]; | |
161 | } | |
162 | #define PEEK_LVAL() val_buffer[0] | |
163 | #define PEEK_TOKEN1() peek_token_(1) | |
164 | #define PEEK_TOKEN2() peek_token_(2) | |
165 | static enum ch_terminal | |
166 | peek_token_ (i) | |
167 | int i; | |
168 | { | |
169 | if (i > MAX_LOOK_AHEAD) | |
170 | fatal ("internal error - too much lookahead"); | |
171 | if (terminal_buffer[i] == TOKEN_NOT_READ) | |
172 | { | |
173 | terminal_buffer[i] = ch_lex (); | |
174 | val_buffer[i] = yylval; | |
175 | } | |
176 | return terminal_buffer[i]; | |
177 | } | |
178 | ||
179 | static void | |
180 | pushback_token (code, node) | |
181 | enum ch_terminal code; | |
182 | YYSTYPE node; | |
183 | { | |
184 | int i; | |
185 | if (terminal_buffer[MAX_LOOK_AHEAD] != TOKEN_NOT_READ) | |
186 | fatal ("internal error - cannot pushback token"); | |
187 | for (i = MAX_LOOK_AHEAD; i > 0; i--) | |
188 | { | |
189 | terminal_buffer[i] = terminal_buffer[i - 1]; | |
190 | val_buffer[i] = val_buffer[i - 1]; | |
191 | } | |
192 | terminal_buffer[0] = code; | |
193 | val_buffer[0] = node; | |
194 | } | |
195 | ||
196 | static void | |
197 | forward_token_() | |
198 | { | |
199 | int i; | |
200 | for (i = 0; i < MAX_LOOK_AHEAD; i++) | |
201 | { | |
202 | terminal_buffer[i] = terminal_buffer[i+1]; | |
203 | val_buffer[i] = val_buffer[i+1]; | |
204 | } | |
205 | terminal_buffer[MAX_LOOK_AHEAD] = TOKEN_NOT_READ; | |
206 | } | |
207 | #define FORWARD_TOKEN() forward_token_() | |
208 | ||
209 | /* Skip the next token. | |
210 | if it isn't TOKEN, the parser is broken. */ | |
211 | ||
212 | void | |
213 | require(token) | |
214 | enum ch_terminal token; | |
215 | { | |
216 | if (PEEK_TOKEN() != token) | |
217 | { | |
218 | char buf[80]; | |
219 | sprintf (buf, "internal parser error - expected token %d", (int)token); | |
220 | fatal(buf); | |
221 | } | |
222 | FORWARD_TOKEN(); | |
223 | } | |
224 | ||
225 | int | |
226 | check_token (token) | |
227 | enum ch_terminal token; | |
228 | { | |
229 | if (PEEK_TOKEN() != token) | |
230 | return 0; | |
231 | FORWARD_TOKEN (); | |
232 | return 1; | |
233 | } | |
234 | ||
235 | /* return 0 if expected token was not found, | |
236 | else return 1. | |
237 | */ | |
238 | int | |
239 | expect(token, message) | |
240 | enum ch_terminal token; | |
241 | char *message; | |
242 | { | |
243 | if (PEEK_TOKEN() != token) | |
244 | { | |
245 | if (message) | |
246 | error (message); | |
247 | else if (token < 256) | |
c8b2ba5d | 248 | error ("syntax error - expected a '%c' here \"%s\"", token, lexptr); |
5e548861 PB |
249 | else |
250 | error ("syntax error"); | |
251 | return 0; | |
252 | } | |
253 | else | |
254 | FORWARD_TOKEN(); | |
255 | return 1; | |
256 | } | |
257 | ||
258 | #if 0 | |
259 | static tree | |
260 | parse_opt_name_string (allow_all) | |
261 | int allow_all; /* 1 if ALL is allowed as a postfix */ | |
262 | { | |
263 | int token = PEEK_TOKEN(); | |
264 | tree name; | |
265 | if (token != NAME) | |
266 | { | |
267 | if (token == ALL && allow_all) | |
268 | { | |
269 | FORWARD_TOKEN (); | |
270 | return ALL_POSTFIX; | |
271 | } | |
272 | return NULL_TREE; | |
273 | } | |
274 | name = PEEK_LVAL(); | |
275 | for (;;) | |
276 | { | |
277 | FORWARD_TOKEN (); | |
278 | token = PEEK_TOKEN(); | |
279 | if (token != '!') | |
280 | return name; | |
281 | FORWARD_TOKEN(); | |
282 | token = PEEK_TOKEN(); | |
283 | if (token == ALL && allow_all) | |
284 | return get_identifier3(IDENTIFIER_POINTER (name), "!", "*"); | |
285 | if (token != NAME) | |
286 | { | |
287 | if (pass == 1) | |
288 | error ("'%s!' is not followed by an identifier", | |
289 | IDENTIFIER_POINTER (name)); | |
290 | return name; | |
291 | } | |
292 | name = get_identifier3(IDENTIFIER_POINTER(name), | |
293 | "!", IDENTIFIER_POINTER(PEEK_LVAL())); | |
294 | } | |
295 | } | |
296 | ||
297 | static tree | |
298 | parse_simple_name_string () | |
299 | { | |
300 | int token = PEEK_TOKEN(); | |
301 | tree name; | |
302 | if (token != NAME) | |
303 | { | |
304 | error ("expected a name here"); | |
305 | return error_mark_node; | |
306 | } | |
307 | name = PEEK_LVAL (); | |
308 | FORWARD_TOKEN (); | |
309 | return name; | |
310 | } | |
311 | ||
312 | static tree | |
313 | parse_name_string () | |
314 | { | |
315 | tree name = parse_opt_name_string (0); | |
316 | if (name) | |
317 | return name; | |
318 | if (pass == 1) | |
319 | error ("expected a name string here"); | |
320 | return error_mark_node; | |
321 | } | |
322 | ||
323 | /* Matches: <name_string> | |
324 | Returns if pass 1: the identifier. | |
325 | Returns if pass 2: a decl or value for identifier. */ | |
326 | ||
327 | static tree | |
328 | parse_name () | |
329 | { | |
330 | tree name = parse_name_string (); | |
331 | if (pass == 1 || ignoring) | |
332 | return name; | |
333 | else | |
334 | { | |
335 | tree decl = lookup_name (name); | |
336 | if (decl == NULL_TREE) | |
337 | { | |
338 | error ("`%s' undeclared", IDENTIFIER_POINTER (name)); | |
339 | return error_mark_node; | |
340 | } | |
341 | else if (TREE_CODE (TREE_TYPE (decl)) == ERROR_MARK) | |
342 | return error_mark_node; | |
343 | else if (TREE_CODE (decl) == CONST_DECL) | |
344 | return DECL_INITIAL (decl); | |
345 | else if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE) | |
346 | return convert_from_reference (decl); | |
347 | else | |
348 | return decl; | |
349 | } | |
350 | } | |
351 | #endif | |
352 | ||
353 | #if 0 | |
354 | static void | |
355 | pushback_paren_expr (expr) | |
356 | tree expr; | |
357 | { | |
358 | if (pass == 1 && !ignoring) | |
359 | expr = build1 (PAREN_EXPR, NULL_TREE, expr); | |
360 | pushback_token (EXPR, expr); | |
361 | } | |
362 | #endif | |
363 | ||
364 | /* Matches: <case label> */ | |
365 | ||
366 | static void | |
367 | parse_case_label () | |
368 | { | |
369 | if (check_token (ELSE)) | |
370 | error ("ELSE in tuples labels not implemented"); | |
371 | /* Does not handle the case of a mode name. FIXME */ | |
372 | parse_expr (); | |
373 | if (check_token (':')) | |
374 | { | |
375 | parse_expr (); | |
376 | write_exp_elt_opcode (BINOP_RANGE); | |
377 | } | |
378 | } | |
379 | ||
380 | static int | |
381 | parse_opt_untyped_expr () | |
382 | { | |
383 | switch (PEEK_TOKEN ()) | |
384 | { | |
385 | case ',': | |
386 | case ':': | |
387 | case ')': | |
388 | return 0; | |
389 | default: | |
390 | parse_untyped_expr (); | |
391 | return 1; | |
392 | } | |
393 | } | |
394 | ||
395 | static void | |
396 | parse_unary_call () | |
397 | { | |
398 | FORWARD_TOKEN (); | |
399 | expect ('(', NULL); | |
400 | parse_expr (); | |
401 | expect (')', NULL); | |
402 | } | |
403 | ||
404 | /* Parse NAME '(' MODENAME ')'. */ | |
405 | ||
406 | struct type * | |
407 | parse_mode_call () | |
408 | { | |
409 | struct type *type; | |
410 | FORWARD_TOKEN (); | |
411 | expect ('(', NULL); | |
412 | if (PEEK_TOKEN () != TYPENAME) | |
413 | error ("expect MODENAME here `%s'", lexptr); | |
414 | type = PEEK_LVAL().tsym.type; | |
415 | FORWARD_TOKEN (); | |
416 | expect (')', NULL); | |
417 | return type; | |
418 | } | |
419 | ||
420 | struct type * | |
421 | parse_mode_or_normal_call () | |
422 | { | |
423 | struct type *type; | |
424 | FORWARD_TOKEN (); | |
425 | expect ('(', NULL); | |
426 | if (PEEK_TOKEN () == TYPENAME) | |
427 | { | |
428 | type = PEEK_LVAL().tsym.type; | |
429 | FORWARD_TOKEN (); | |
430 | } | |
431 | else | |
432 | { | |
433 | parse_expr (); | |
434 | type = NULL; | |
435 | } | |
436 | expect (')', NULL); | |
437 | return type; | |
438 | } | |
439 | ||
440 | /* Parse something that looks like a function call. | |
441 | Assume we have parsed the function, and are at the '('. */ | |
442 | ||
443 | static void | |
444 | parse_call () | |
445 | { | |
446 | int arg_count; | |
447 | require ('('); | |
448 | /* This is to save the value of arglist_len | |
449 | being accumulated for each dimension. */ | |
450 | start_arglist (); | |
451 | if (parse_opt_untyped_expr ()) | |
452 | { | |
453 | int tok = PEEK_TOKEN (); | |
454 | arglist_len = 1; | |
455 | if (tok == UP || tok == ':') | |
456 | { | |
457 | FORWARD_TOKEN (); | |
458 | parse_expr (); | |
459 | expect (')', "expected ')' to terminate slice"); | |
460 | end_arglist (); | |
461 | write_exp_elt_opcode (tok == UP ? TERNOP_SLICE_COUNT | |
462 | : TERNOP_SLICE); | |
463 | return; | |
464 | } | |
465 | while (check_token (',')) | |
466 | { | |
467 | parse_untyped_expr (); | |
468 | arglist_len++; | |
469 | } | |
470 | } | |
471 | else | |
472 | arglist_len = 0; | |
c8b2ba5d | 473 | expect (')', NULL); |
5e548861 PB |
474 | arg_count = end_arglist (); |
475 | write_exp_elt_opcode (MULTI_SUBSCRIPT); | |
476 | write_exp_elt_longcst (arg_count); | |
477 | write_exp_elt_opcode (MULTI_SUBSCRIPT); | |
478 | } | |
479 | ||
480 | static void | |
481 | parse_named_record_element () | |
482 | { | |
f9384420 JL |
483 | struct stoken label; |
484 | ||
485 | label = PEEK_LVAL ().sval; | |
5e548861 PB |
486 | expect (FIELD_NAME, "expected a field name here `%s'", lexptr); |
487 | if (check_token (',')) | |
488 | parse_named_record_element (); | |
489 | else if (check_token (':')) | |
490 | parse_expr (); | |
491 | else | |
492 | error ("syntax error near `%s' in named record tuple element", lexptr); | |
493 | write_exp_elt_opcode (OP_LABELED); | |
494 | write_exp_string (label); | |
495 | write_exp_elt_opcode (OP_LABELED); | |
496 | } | |
497 | ||
498 | /* Returns one or nore TREE_LIST nodes, in reverse order. */ | |
499 | ||
500 | static void | |
501 | parse_tuple_element () | |
502 | { | |
503 | if (PEEK_TOKEN () == FIELD_NAME) | |
504 | { | |
505 | /* Parse a labelled structure tuple. */ | |
506 | parse_named_record_element (); | |
507 | return; | |
508 | } | |
509 | ||
510 | if (check_token ('(')) | |
511 | { | |
512 | if (check_token ('*')) | |
513 | { | |
514 | expect (')', "missing ')' after '*' case label list"); | |
515 | error ("(*) not implemented in case label list"); | |
516 | } | |
517 | else | |
518 | { | |
519 | parse_case_label (); | |
520 | while (check_token (',')) | |
521 | { | |
522 | parse_case_label (); | |
523 | write_exp_elt_opcode (BINOP_COMMA); | |
524 | } | |
525 | expect (')', NULL); | |
526 | } | |
527 | } | |
528 | else | |
529 | parse_untyped_expr (); | |
530 | if (check_token (':')) | |
531 | { | |
532 | /* A powerset range or a labeled Array. */ | |
533 | parse_untyped_expr (); | |
534 | write_exp_elt_opcode (BINOP_RANGE); | |
535 | } | |
536 | } | |
537 | ||
538 | /* Matches: a COMMA-separated list of tuple elements. | |
539 | Returns a list (of TREE_LIST nodes). */ | |
540 | static void | |
541 | parse_opt_element_list () | |
542 | { | |
543 | arglist_len = 0; | |
544 | if (PEEK_TOKEN () == ']') | |
545 | return; | |
546 | for (;;) | |
547 | { | |
548 | parse_tuple_element (); | |
549 | arglist_len++; | |
550 | if (PEEK_TOKEN () == ']') | |
551 | break; | |
552 | if (!check_token (',')) | |
553 | error ("bad syntax in tuple"); | |
554 | } | |
555 | } | |
556 | ||
557 | /* Parses: '[' elements ']' | |
558 | If modename is non-NULL it prefixed the tuple. */ | |
559 | ||
560 | static void | |
561 | parse_tuple (mode) | |
562 | struct type *mode; | |
563 | { | |
564 | require ('['); | |
565 | start_arglist (); | |
566 | parse_opt_element_list (); | |
567 | expect (']', "missing ']' after tuple"); | |
568 | write_exp_elt_opcode (OP_ARRAY); | |
569 | write_exp_elt_longcst ((LONGEST) 0); | |
570 | write_exp_elt_longcst ((LONGEST) end_arglist () - 1); | |
571 | write_exp_elt_opcode (OP_ARRAY); | |
572 | if (mode) | |
573 | { | |
9293e886 PB |
574 | struct type *type = check_typedef (mode); |
575 | if (TYPE_CODE (type) != TYPE_CODE_ARRAY | |
576 | && TYPE_CODE (type) != TYPE_CODE_STRUCT | |
577 | && TYPE_CODE (type) != TYPE_CODE_SET) | |
578 | error ("invalid tuple mode"); | |
5e548861 PB |
579 | write_exp_elt_opcode (UNOP_CAST); |
580 | write_exp_elt_type (mode); | |
581 | write_exp_elt_opcode (UNOP_CAST); | |
582 | } | |
583 | } | |
584 | ||
585 | static void | |
586 | parse_primval () | |
587 | { | |
588 | struct type *type; | |
589 | enum exp_opcode op; | |
590 | char *op_name; | |
591 | switch (PEEK_TOKEN ()) | |
592 | { | |
593 | case INTEGER_LITERAL: | |
594 | case CHARACTER_LITERAL: | |
595 | write_exp_elt_opcode (OP_LONG); | |
596 | write_exp_elt_type (PEEK_LVAL ().typed_val.type); | |
f6d16585 | 597 | write_exp_elt_longcst (PEEK_LVAL ().typed_val.val); |
5e548861 PB |
598 | write_exp_elt_opcode (OP_LONG); |
599 | FORWARD_TOKEN (); | |
600 | break; | |
601 | case BOOLEAN_LITERAL: | |
602 | write_exp_elt_opcode (OP_BOOL); | |
603 | write_exp_elt_longcst ((LONGEST) PEEK_LVAL ().ulval); | |
604 | write_exp_elt_opcode (OP_BOOL); | |
605 | FORWARD_TOKEN (); | |
606 | break; | |
607 | case FLOAT_LITERAL: | |
608 | write_exp_elt_opcode (OP_DOUBLE); | |
609 | write_exp_elt_type (builtin_type_double); | |
610 | write_exp_elt_dblcst (PEEK_LVAL ().dval); | |
611 | write_exp_elt_opcode (OP_DOUBLE); | |
612 | FORWARD_TOKEN (); | |
613 | break; | |
614 | case EMPTINESS_LITERAL: | |
615 | write_exp_elt_opcode (OP_LONG); | |
616 | write_exp_elt_type (lookup_pointer_type (builtin_type_void)); | |
617 | write_exp_elt_longcst (0); | |
618 | write_exp_elt_opcode (OP_LONG); | |
619 | FORWARD_TOKEN (); | |
620 | break; | |
621 | case CHARACTER_STRING_LITERAL: | |
622 | write_exp_elt_opcode (OP_STRING); | |
623 | write_exp_string (PEEK_LVAL ().sval); | |
624 | write_exp_elt_opcode (OP_STRING); | |
625 | FORWARD_TOKEN (); | |
626 | break; | |
627 | case BIT_STRING_LITERAL: | |
628 | write_exp_elt_opcode (OP_BITSTRING); | |
629 | write_exp_bitstring (PEEK_LVAL ().sval); | |
630 | write_exp_elt_opcode (OP_BITSTRING); | |
631 | FORWARD_TOKEN (); | |
632 | break; | |
633 | case ARRAY: | |
634 | FORWARD_TOKEN (); | |
635 | /* This is pseudo-Chill, similar to C's '(TYPE[])EXPR' | |
636 | which casts to an artificial array. */ | |
637 | expect ('(', NULL); | |
638 | expect (')', NULL); | |
639 | if (PEEK_TOKEN () != TYPENAME) | |
640 | error ("missing MODENAME after ARRAY()"); | |
641 | type = PEEK_LVAL().tsym.type; | |
d1f5c804 | 642 | FORWARD_TOKEN (); |
5e548861 PB |
643 | expect ('(', NULL); |
644 | parse_expr (); | |
645 | expect (')', "missing right parenthesis"); | |
646 | type = create_array_type ((struct type *) NULL, type, | |
647 | create_range_type ((struct type *) NULL, | |
648 | builtin_type_int, 0, 0)); | |
649 | TYPE_ARRAY_UPPER_BOUND_TYPE(type) = BOUND_CANNOT_BE_DETERMINED; | |
650 | write_exp_elt_opcode (UNOP_CAST); | |
651 | write_exp_elt_type (type); | |
652 | write_exp_elt_opcode (UNOP_CAST); | |
653 | break; | |
654 | #if 0 | |
655 | case CONST: | |
656 | case EXPR: | |
657 | val = PEEK_LVAL(); | |
658 | FORWARD_TOKEN (); | |
659 | break; | |
660 | #endif | |
661 | case '(': | |
662 | FORWARD_TOKEN (); | |
663 | parse_expr (); | |
664 | expect (')', "missing right parenthesis"); | |
665 | break; | |
666 | case '[': | |
667 | parse_tuple (NULL); | |
668 | break; | |
669 | case GENERAL_PROCEDURE_NAME: | |
670 | case LOCATION_NAME: | |
671 | write_exp_elt_opcode (OP_VAR_VALUE); | |
672 | write_exp_elt_block (NULL); | |
673 | write_exp_elt_sym (PEEK_LVAL ().ssym.sym); | |
674 | write_exp_elt_opcode (OP_VAR_VALUE); | |
675 | FORWARD_TOKEN (); | |
676 | break; | |
677 | case GDB_VARIABLE: /* gdb specific */ | |
678 | FORWARD_TOKEN (); | |
679 | break; | |
680 | case NUM: | |
681 | parse_unary_call (); | |
682 | write_exp_elt_opcode (UNOP_CAST); | |
683 | write_exp_elt_type (builtin_type_int); | |
684 | write_exp_elt_opcode (UNOP_CAST); | |
685 | break; | |
c105168f WM |
686 | case CARD: |
687 | parse_unary_call (); | |
688 | write_exp_elt_opcode (UNOP_CARD); | |
689 | break; | |
690 | case MAX_TOKEN: | |
691 | parse_unary_call (); | |
692 | write_exp_elt_opcode (UNOP_CHMAX); | |
693 | break; | |
694 | case MIN_TOKEN: | |
695 | parse_unary_call (); | |
696 | write_exp_elt_opcode (UNOP_CHMIN); | |
697 | break; | |
5e548861 PB |
698 | case PRED: op_name = "PRED"; goto unimplemented_unary_builtin; |
699 | case SUCC: op_name = "SUCC"; goto unimplemented_unary_builtin; | |
700 | case ABS: op_name = "ABS"; goto unimplemented_unary_builtin; | |
5e548861 PB |
701 | unimplemented_unary_builtin: |
702 | parse_unary_call (); | |
703 | error ("not implemented: %s builtin function", op_name); | |
704 | break; | |
705 | case ADDR_TOKEN: | |
706 | parse_unary_call (); | |
707 | write_exp_elt_opcode (UNOP_ADDR); | |
708 | break; | |
709 | case SIZE: | |
710 | type = parse_mode_or_normal_call (); | |
711 | if (type) | |
712 | { write_exp_elt_opcode (OP_LONG); | |
713 | write_exp_elt_type (builtin_type_int); | |
714 | CHECK_TYPEDEF (type); | |
715 | write_exp_elt_longcst ((LONGEST) TYPE_LENGTH (type)); | |
716 | write_exp_elt_opcode (OP_LONG); | |
717 | } | |
718 | else | |
719 | write_exp_elt_opcode (UNOP_SIZEOF); | |
720 | break; | |
721 | case LOWER: | |
722 | op = UNOP_LOWER; | |
723 | goto lower_upper; | |
724 | case UPPER: | |
725 | op = UNOP_UPPER; | |
726 | goto lower_upper; | |
727 | lower_upper: | |
728 | type = parse_mode_or_normal_call (); | |
729 | write_lower_upper_value (op, type); | |
730 | break; | |
731 | case LENGTH: | |
732 | parse_unary_call (); | |
733 | write_exp_elt_opcode (UNOP_LENGTH); | |
734 | break; | |
735 | case TYPENAME: | |
736 | type = PEEK_LVAL ().tsym.type; | |
737 | FORWARD_TOKEN (); | |
738 | switch (PEEK_TOKEN()) | |
739 | { | |
740 | case '[': | |
741 | parse_tuple (type); | |
742 | break; | |
743 | case '(': | |
744 | FORWARD_TOKEN (); | |
745 | parse_expr (); | |
746 | expect (')', "missing right parenthesis"); | |
747 | write_exp_elt_opcode (UNOP_CAST); | |
748 | write_exp_elt_type (type); | |
749 | write_exp_elt_opcode (UNOP_CAST); | |
750 | break; | |
751 | default: | |
752 | error ("typename in invalid context"); | |
753 | } | |
754 | break; | |
755 | ||
756 | default: | |
757 | error ("invalid expression syntax at `%s'", lexptr); | |
758 | } | |
759 | for (;;) | |
760 | { | |
761 | switch (PEEK_TOKEN ()) | |
762 | { | |
763 | case FIELD_NAME: | |
764 | write_exp_elt_opcode (STRUCTOP_STRUCT); | |
765 | write_exp_string (PEEK_LVAL ().sval); | |
766 | write_exp_elt_opcode (STRUCTOP_STRUCT); | |
767 | FORWARD_TOKEN (); | |
768 | continue; | |
769 | case POINTER: | |
770 | FORWARD_TOKEN (); | |
771 | if (PEEK_TOKEN () == TYPENAME) | |
772 | { | |
773 | type = PEEK_LVAL ().tsym.type; | |
774 | write_exp_elt_opcode (UNOP_CAST); | |
775 | write_exp_elt_type (lookup_pointer_type (type)); | |
776 | write_exp_elt_opcode (UNOP_CAST); | |
777 | FORWARD_TOKEN (); | |
778 | } | |
779 | write_exp_elt_opcode (UNOP_IND); | |
780 | continue; | |
781 | case '(': | |
782 | parse_call (); | |
783 | continue; | |
784 | case CHARACTER_STRING_LITERAL: | |
785 | case CHARACTER_LITERAL: | |
786 | case BIT_STRING_LITERAL: | |
787 | /* Handle string repetition. (See comment in parse_operand5.) */ | |
788 | parse_primval (); | |
789 | write_exp_elt_opcode (MULTI_SUBSCRIPT); | |
790 | write_exp_elt_longcst (1); | |
791 | write_exp_elt_opcode (MULTI_SUBSCRIPT); | |
792 | continue; | |
793 | } | |
794 | break; | |
795 | } | |
796 | return; | |
797 | } | |
798 | ||
799 | static void | |
800 | parse_operand6 () | |
801 | { | |
802 | if (check_token (RECEIVE)) | |
803 | { | |
804 | parse_primval (); | |
805 | error ("not implemented: RECEIVE expression"); | |
806 | } | |
807 | else if (check_token (POINTER)) | |
808 | { | |
809 | parse_primval (); | |
810 | write_exp_elt_opcode (UNOP_ADDR); | |
811 | } | |
812 | else | |
813 | parse_primval(); | |
814 | } | |
815 | ||
816 | static void | |
817 | parse_operand5() | |
818 | { | |
819 | enum exp_opcode op; | |
820 | /* We are supposed to be looking for a <string repetition operator>, | |
821 | but in general we can't distinguish that from a parenthesized | |
822 | expression. This is especially difficult if we allow the | |
823 | string operand to be a constant expression (as requested by | |
824 | some users), and not just a string literal. | |
825 | Consider: LPRN expr RPRN LPRN expr RPRN | |
826 | Is that a function call or string repetition? | |
827 | Instead, we handle string repetition in parse_primval, | |
828 | and build_generalized_call. */ | |
829 | switch (PEEK_TOKEN()) | |
830 | { | |
831 | case NOT: op = UNOP_LOGICAL_NOT; break; | |
832 | case '-': op = UNOP_NEG; break; | |
833 | default: | |
834 | op = OP_NULL; | |
835 | } | |
836 | if (op != OP_NULL) | |
837 | FORWARD_TOKEN(); | |
838 | parse_operand6(); | |
839 | if (op != OP_NULL) | |
840 | write_exp_elt_opcode (op); | |
841 | } | |
842 | ||
843 | static void | |
844 | parse_operand4 () | |
845 | { | |
846 | enum exp_opcode op; | |
847 | parse_operand5(); | |
848 | for (;;) | |
849 | { | |
850 | switch (PEEK_TOKEN()) | |
851 | { | |
852 | case '*': op = BINOP_MUL; break; | |
853 | case '/': op = BINOP_DIV; break; | |
854 | case MOD: op = BINOP_MOD; break; | |
855 | case REM: op = BINOP_REM; break; | |
856 | default: | |
857 | return; | |
858 | } | |
859 | FORWARD_TOKEN(); | |
860 | parse_operand5(); | |
861 | write_exp_elt_opcode (op); | |
862 | } | |
863 | } | |
864 | ||
865 | static void | |
866 | parse_operand3 () | |
867 | { | |
868 | enum exp_opcode op; | |
869 | parse_operand4 (); | |
870 | for (;;) | |
871 | { | |
872 | switch (PEEK_TOKEN()) | |
873 | { | |
874 | case '+': op = BINOP_ADD; break; | |
875 | case '-': op = BINOP_SUB; break; | |
876 | case SLASH_SLASH: op = BINOP_CONCAT; break; | |
877 | default: | |
878 | return; | |
879 | } | |
880 | FORWARD_TOKEN(); | |
881 | parse_operand4(); | |
882 | write_exp_elt_opcode (op); | |
883 | } | |
884 | } | |
885 | ||
886 | static void | |
887 | parse_operand2 () | |
888 | { | |
889 | enum exp_opcode op; | |
890 | parse_operand3 (); | |
891 | for (;;) | |
892 | { | |
893 | if (check_token (IN)) | |
894 | { | |
895 | parse_operand3(); | |
896 | write_exp_elt_opcode (BINOP_IN); | |
897 | } | |
898 | else | |
899 | { | |
900 | switch (PEEK_TOKEN()) | |
901 | { | |
902 | case '>': op = BINOP_GTR; break; | |
903 | case GEQ: op = BINOP_GEQ; break; | |
904 | case '<': op = BINOP_LESS; break; | |
905 | case LEQ: op = BINOP_LEQ; break; | |
906 | case '=': op = BINOP_EQUAL; break; | |
907 | case NOTEQUAL: op = BINOP_NOTEQUAL; break; | |
908 | default: | |
909 | return; | |
910 | } | |
911 | FORWARD_TOKEN(); | |
912 | parse_operand3(); | |
913 | write_exp_elt_opcode (op); | |
914 | } | |
915 | } | |
916 | } | |
917 | ||
918 | static void | |
919 | parse_operand1 () | |
920 | { | |
921 | enum exp_opcode op; | |
922 | parse_operand2 (); | |
923 | for (;;) | |
924 | { | |
925 | switch (PEEK_TOKEN()) | |
926 | { | |
927 | case LOGAND: op = BINOP_BITWISE_AND; break; | |
928 | case ANDIF: op = BINOP_LOGICAL_AND; break; | |
929 | default: | |
930 | return; | |
931 | } | |
932 | FORWARD_TOKEN(); | |
933 | parse_operand2(); | |
934 | write_exp_elt_opcode (op); | |
935 | } | |
936 | } | |
937 | ||
938 | static void | |
939 | parse_operand0 () | |
940 | { | |
941 | enum exp_opcode op; | |
942 | parse_operand1(); | |
943 | for (;;) | |
944 | { | |
945 | switch (PEEK_TOKEN()) | |
946 | { | |
947 | case LOGIOR: op = BINOP_BITWISE_IOR; break; | |
948 | case LOGXOR: op = BINOP_BITWISE_XOR; break; | |
949 | case ORIF: op = BINOP_LOGICAL_OR; break; | |
950 | default: | |
951 | return; | |
952 | } | |
953 | FORWARD_TOKEN(); | |
954 | parse_operand1(); | |
955 | write_exp_elt_opcode (op); | |
956 | } | |
957 | } | |
958 | ||
959 | static void | |
960 | parse_expr () | |
961 | { | |
962 | parse_operand0 (); | |
963 | if (check_token (GDB_ASSIGNMENT)) | |
964 | { | |
965 | parse_expr (); | |
966 | write_exp_elt_opcode (BINOP_ASSIGN); | |
967 | } | |
968 | } | |
969 | ||
970 | static void | |
971 | parse_then_alternative () | |
972 | { | |
973 | expect (THEN, "missing 'THEN' in 'IF' expression"); | |
974 | parse_expr (); | |
975 | } | |
976 | ||
977 | static void | |
978 | parse_else_alternative () | |
979 | { | |
980 | if (check_token (ELSIF)) | |
981 | parse_if_expression_body (); | |
982 | else if (check_token (ELSE)) | |
983 | parse_expr (); | |
984 | else | |
985 | error ("missing ELSE/ELSIF in IF expression"); | |
986 | } | |
987 | ||
988 | /* Matches: <boolean expression> <then alternative> <else alternative> */ | |
989 | ||
990 | static void | |
991 | parse_if_expression_body () | |
992 | { | |
993 | parse_expr (); | |
994 | parse_then_alternative (); | |
995 | parse_else_alternative (); | |
996 | write_exp_elt_opcode (TERNOP_COND); | |
997 | } | |
998 | ||
999 | static void | |
1000 | parse_if_expression () | |
1001 | { | |
1002 | require (IF); | |
1003 | parse_if_expression_body (); | |
1004 | expect (FI, "missing 'FI' at end of conditional expression"); | |
1005 | } | |
1006 | ||
1007 | /* An <untyped_expr> is a superset of <expr>. It also includes | |
1008 | <conditional expressions> and untyped <tuples>, whose types | |
1009 | are not given by their constituents. Hence, these are only | |
1010 | allowed in certain contexts that expect a certain type. | |
1011 | You should call convert() to fix up the <untyped_expr>. */ | |
1012 | ||
1013 | static void | |
1014 | parse_untyped_expr () | |
1015 | { | |
1016 | switch (PEEK_TOKEN()) | |
1017 | { | |
1018 | case IF: | |
1019 | parse_if_expression (); | |
1020 | return; | |
1021 | case CASE: | |
1022 | error ("not implemented: CASE expression"); | |
1023 | case '(': | |
1024 | switch (PEEK_TOKEN1()) | |
1025 | { | |
1026 | case IF: | |
1027 | case CASE: | |
1028 | goto skip_lprn; | |
1029 | case '[': | |
1030 | skip_lprn: | |
1031 | FORWARD_TOKEN (); | |
1032 | parse_untyped_expr (); | |
1033 | expect (')', "missing ')'"); | |
1034 | return; | |
1035 | default: ; | |
1036 | /* fall through */ | |
1037 | } | |
1038 | default: | |
1039 | parse_operand0 (); | |
1040 | } | |
1041 | } | |
1042 | ||
1043 | int | |
1044 | chill_parse () | |
1045 | { | |
1046 | terminal_buffer[0] = TOKEN_NOT_READ; | |
1047 | if (PEEK_TOKEN () == TYPENAME && PEEK_TOKEN1 () == END_TOKEN) | |
1048 | { | |
1049 | write_exp_elt_opcode(OP_TYPE); | |
1050 | write_exp_elt_type(PEEK_LVAL ().tsym.type); | |
1051 | write_exp_elt_opcode(OP_TYPE); | |
1052 | FORWARD_TOKEN (); | |
1053 | } | |
1054 | else | |
1055 | parse_expr (); | |
1056 | if (terminal_buffer[0] != END_TOKEN) | |
1057 | { | |
1058 | if (comma_terminates && terminal_buffer[0] == ',') | |
1059 | lexptr--; /* Put the comma back. */ | |
1060 | else | |
1061 | error ("Junk after end of expression."); | |
1062 | } | |
1063 | return 0; | |
1064 | } | |
1065 | ||
1066 | ||
1067 | /* Implementation of a dynamically expandable buffer for processing input | |
1068 | characters acquired through lexptr and building a value to return in | |
1069 | yylval. */ | |
1070 | ||
1071 | static char *tempbuf; /* Current buffer contents */ | |
1072 | static int tempbufsize; /* Size of allocated buffer */ | |
1073 | static int tempbufindex; /* Current index into buffer */ | |
1074 | ||
1075 | #define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */ | |
1076 | ||
1077 | #define CHECKBUF(size) \ | |
1078 | do { \ | |
1079 | if (tempbufindex + (size) >= tempbufsize) \ | |
1080 | { \ | |
1081 | growbuf_by_size (size); \ | |
1082 | } \ | |
1083 | } while (0); | |
1084 | ||
1085 | /* Grow the static temp buffer if necessary, including allocating the first one | |
1086 | on demand. */ | |
1087 | ||
1088 | static void | |
1089 | growbuf_by_size (count) | |
1090 | int count; | |
1091 | { | |
1092 | int growby; | |
1093 | ||
1094 | growby = max (count, GROWBY_MIN_SIZE); | |
1095 | tempbufsize += growby; | |
1096 | if (tempbuf == NULL) | |
1097 | { | |
6405302d | 1098 | tempbuf = (char *) xmalloc (tempbufsize); |
5e548861 PB |
1099 | } |
1100 | else | |
1101 | { | |
6405302d | 1102 | tempbuf = (char *) xrealloc (tempbuf, tempbufsize); |
5e548861 PB |
1103 | } |
1104 | } | |
1105 | ||
1106 | /* Try to consume a simple name string token. If successful, returns | |
1107 | a pointer to a nullbyte terminated copy of the name that can be used | |
1108 | in symbol table lookups. If not successful, returns NULL. */ | |
1109 | ||
1110 | static char * | |
1111 | match_simple_name_string () | |
1112 | { | |
1113 | char *tokptr = lexptr; | |
1114 | ||
1115 | if (isalpha (*tokptr) || *tokptr == '_') | |
1116 | { | |
1117 | char *result; | |
1118 | do { | |
1119 | tokptr++; | |
1120 | } while (isalnum (*tokptr) || (*tokptr == '_')); | |
1121 | yylval.sval.ptr = lexptr; | |
1122 | yylval.sval.length = tokptr - lexptr; | |
1123 | lexptr = tokptr; | |
1124 | result = copy_name (yylval.sval); | |
1125 | return result; | |
1126 | } | |
1127 | return (NULL); | |
1128 | } | |
1129 | ||
1130 | /* Start looking for a value composed of valid digits as set by the base | |
1131 | in use. Note that '_' characters are valid anywhere, in any quantity, | |
1132 | and are simply ignored. Since we must find at least one valid digit, | |
1133 | or reject this token as an integer literal, we keep track of how many | |
1134 | digits we have encountered. */ | |
1135 | ||
1136 | static int | |
1137 | decode_integer_value (base, tokptrptr, ivalptr) | |
1138 | int base; | |
1139 | char **tokptrptr; | |
1140 | LONGEST *ivalptr; | |
1141 | { | |
1142 | char *tokptr = *tokptrptr; | |
1143 | int temp; | |
1144 | int digits = 0; | |
1145 | ||
1146 | while (*tokptr != '\0') | |
1147 | { | |
1148 | temp = *tokptr; | |
1149 | if (isupper (temp)) | |
1150 | temp = tolower (temp); | |
1151 | tokptr++; | |
1152 | switch (temp) | |
1153 | { | |
1154 | case '_': | |
1155 | continue; | |
1156 | case '0': case '1': case '2': case '3': case '4': | |
1157 | case '5': case '6': case '7': case '8': case '9': | |
1158 | temp -= '0'; | |
1159 | break; | |
1160 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': | |
1161 | temp -= 'a'; | |
1162 | temp += 10; | |
1163 | break; | |
1164 | default: | |
1165 | temp = base; | |
1166 | break; | |
1167 | } | |
1168 | if (temp < base) | |
1169 | { | |
1170 | digits++; | |
1171 | *ivalptr *= base; | |
1172 | *ivalptr += temp; | |
1173 | } | |
1174 | else | |
1175 | { | |
1176 | /* Found something not in domain for current base. */ | |
1177 | tokptr--; /* Unconsume what gave us indigestion. */ | |
1178 | break; | |
1179 | } | |
1180 | } | |
1181 | ||
1182 | /* If we didn't find any digits, then we don't have a valid integer | |
1183 | value, so reject the entire token. Otherwise, update the lexical | |
1184 | scan pointer, and return non-zero for success. */ | |
1185 | ||
1186 | if (digits == 0) | |
1187 | { | |
1188 | return (0); | |
1189 | } | |
1190 | else | |
1191 | { | |
1192 | *tokptrptr = tokptr; | |
1193 | return (1); | |
1194 | } | |
1195 | } | |
1196 | ||
1197 | static int | |
1198 | decode_integer_literal (valptr, tokptrptr) | |
1199 | LONGEST *valptr; | |
1200 | char **tokptrptr; | |
1201 | { | |
1202 | char *tokptr = *tokptrptr; | |
1203 | int base = 0; | |
1204 | LONGEST ival = 0; | |
1205 | int explicit_base = 0; | |
1206 | ||
1207 | /* Look for an explicit base specifier, which is optional. */ | |
1208 | ||
1209 | switch (*tokptr) | |
1210 | { | |
1211 | case 'd': | |
1212 | case 'D': | |
1213 | explicit_base++; | |
1214 | base = 10; | |
1215 | tokptr++; | |
1216 | break; | |
1217 | case 'b': | |
1218 | case 'B': | |
1219 | explicit_base++; | |
1220 | base = 2; | |
1221 | tokptr++; | |
1222 | break; | |
1223 | case 'h': | |
1224 | case 'H': | |
1225 | explicit_base++; | |
1226 | base = 16; | |
1227 | tokptr++; | |
1228 | break; | |
1229 | case 'o': | |
1230 | case 'O': | |
1231 | explicit_base++; | |
1232 | base = 8; | |
1233 | tokptr++; | |
1234 | break; | |
1235 | default: | |
1236 | base = 10; | |
1237 | break; | |
1238 | } | |
1239 | ||
1240 | /* If we found an explicit base ensure that the character after the | |
1241 | explicit base is a single quote. */ | |
1242 | ||
1243 | if (explicit_base && (*tokptr++ != '\'')) | |
1244 | { | |
1245 | return (0); | |
1246 | } | |
1247 | ||
1248 | /* Attempt to decode whatever follows as an integer value in the | |
1249 | indicated base, updating the token pointer in the process and | |
1250 | computing the value into ival. Also, if we have an explicit | |
1251 | base, then the next character must not be a single quote, or we | |
1252 | have a bitstring literal, so reject the entire token in this case. | |
1253 | Otherwise, update the lexical scan pointer, and return non-zero | |
1254 | for success. */ | |
1255 | ||
1256 | if (!decode_integer_value (base, &tokptr, &ival)) | |
1257 | { | |
1258 | return (0); | |
1259 | } | |
1260 | else if (explicit_base && (*tokptr == '\'')) | |
1261 | { | |
1262 | return (0); | |
1263 | } | |
1264 | else | |
1265 | { | |
1266 | *valptr = ival; | |
1267 | *tokptrptr = tokptr; | |
1268 | return (1); | |
1269 | } | |
1270 | } | |
1271 | ||
1272 | /* If it wasn't for the fact that floating point values can contain '_' | |
1273 | characters, we could just let strtod do all the hard work by letting it | |
1274 | try to consume as much of the current token buffer as possible and | |
1275 | find a legal conversion. Unfortunately we need to filter out the '_' | |
1276 | characters before calling strtod, which we do by copying the other | |
1277 | legal chars to a local buffer to be converted. However since we also | |
1278 | need to keep track of where the last unconsumed character in the input | |
1279 | buffer is, we have transfer only as many characters as may compose a | |
1280 | legal floating point value. */ | |
1281 | ||
1282 | static enum ch_terminal | |
1283 | match_float_literal () | |
1284 | { | |
1285 | char *tokptr = lexptr; | |
1286 | char *buf; | |
1287 | char *copy; | |
1288 | double dval; | |
1289 | extern double strtod (); | |
1290 | ||
1291 | /* Make local buffer in which to build the string to convert. This is | |
1292 | required because underscores are valid in chill floating point numbers | |
1293 | but not in the string passed to strtod to convert. The string will be | |
1294 | no longer than our input string. */ | |
1295 | ||
1296 | copy = buf = (char *) alloca (strlen (tokptr) + 1); | |
1297 | ||
1298 | /* Transfer all leading digits to the conversion buffer, discarding any | |
1299 | underscores. */ | |
1300 | ||
1301 | while (isdigit (*tokptr) || *tokptr == '_') | |
1302 | { | |
1303 | if (*tokptr != '_') | |
1304 | { | |
1305 | *copy++ = *tokptr; | |
1306 | } | |
1307 | tokptr++; | |
1308 | } | |
1309 | ||
1310 | /* Now accept either a '.', or one of [eEdD]. Dot is legal regardless | |
1311 | of whether we found any leading digits, and we simply accept it and | |
1312 | continue on to look for the fractional part and/or exponent. One of | |
1313 | [eEdD] is legal only if we have seen digits, and means that there | |
1314 | is no fractional part. If we find neither of these, then this is | |
1315 | not a floating point number, so return failure. */ | |
1316 | ||
1317 | switch (*tokptr++) | |
1318 | { | |
1319 | case '.': | |
1320 | /* Accept and then look for fractional part and/or exponent. */ | |
1321 | *copy++ = '.'; | |
1322 | break; | |
1323 | ||
1324 | case 'e': | |
1325 | case 'E': | |
1326 | case 'd': | |
1327 | case 'D': | |
1328 | if (copy == buf) | |
1329 | { | |
1330 | return (0); | |
1331 | } | |
1332 | *copy++ = 'e'; | |
1333 | goto collect_exponent; | |
1334 | break; | |
1335 | ||
1336 | default: | |
1337 | return (0); | |
1338 | break; | |
1339 | } | |
1340 | ||
1341 | /* We found a '.', copy any fractional digits to the conversion buffer, up | |
1342 | to the first nondigit, non-underscore character. */ | |
1343 | ||
1344 | while (isdigit (*tokptr) || *tokptr == '_') | |
1345 | { | |
1346 | if (*tokptr != '_') | |
1347 | { | |
1348 | *copy++ = *tokptr; | |
1349 | } | |
1350 | tokptr++; | |
1351 | } | |
1352 | ||
1353 | /* Look for an exponent, which must start with one of [eEdD]. If none | |
1354 | is found, jump directly to trying to convert what we have collected | |
1355 | so far. */ | |
1356 | ||
1357 | switch (*tokptr) | |
1358 | { | |
1359 | case 'e': | |
1360 | case 'E': | |
1361 | case 'd': | |
1362 | case 'D': | |
1363 | *copy++ = 'e'; | |
1364 | tokptr++; | |
1365 | break; | |
1366 | default: | |
1367 | goto convert_float; | |
1368 | break; | |
1369 | } | |
1370 | ||
1371 | /* Accept an optional '-' or '+' following one of [eEdD]. */ | |
1372 | ||
1373 | collect_exponent: | |
1374 | if (*tokptr == '+' || *tokptr == '-') | |
1375 | { | |
1376 | *copy++ = *tokptr++; | |
1377 | } | |
1378 | ||
1379 | /* Now copy an exponent into the conversion buffer. Note that at the | |
1380 | moment underscores are *not* allowed in exponents. */ | |
1381 | ||
1382 | while (isdigit (*tokptr)) | |
1383 | { | |
1384 | *copy++ = *tokptr++; | |
1385 | } | |
1386 | ||
1387 | /* If we transfered any chars to the conversion buffer, try to interpret its | |
1388 | contents as a floating point value. If any characters remain, then we | |
1389 | must not have a valid floating point string. */ | |
1390 | ||
1391 | convert_float: | |
1392 | *copy = '\0'; | |
1393 | if (copy != buf) | |
1394 | { | |
1395 | dval = strtod (buf, ©); | |
1396 | if (*copy == '\0') | |
1397 | { | |
1398 | yylval.dval = dval; | |
1399 | lexptr = tokptr; | |
1400 | return (FLOAT_LITERAL); | |
1401 | } | |
1402 | } | |
1403 | return (0); | |
1404 | } | |
1405 | ||
1406 | /* Recognize a string literal. A string literal is a sequence | |
1407 | of characters enclosed in matching single or double quotes, except that | |
1408 | a single character inside single quotes is a character literal, which | |
1409 | we reject as a string literal. To embed the terminator character inside | |
1410 | a string, it is simply doubled (I.E. "this""is""one""string") */ | |
1411 | ||
1412 | static enum ch_terminal | |
1413 | match_string_literal () | |
1414 | { | |
1415 | char *tokptr = lexptr; | |
c105168f WM |
1416 | int in_ctrlseq = 0; |
1417 | LONGEST ival; | |
5e548861 PB |
1418 | |
1419 | for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++) | |
1420 | { | |
1421 | CHECKBUF (1); | |
c105168f WM |
1422 | tryagain: ; |
1423 | if (in_ctrlseq) | |
5e548861 | 1424 | { |
c105168f WM |
1425 | /* skip possible whitespaces */ |
1426 | while ((*tokptr == ' ' || *tokptr == '\t') && *tokptr) | |
1427 | tokptr++; | |
1428 | if (*tokptr == ')') | |
5e548861 | 1429 | { |
c105168f | 1430 | in_ctrlseq = 0; |
5e548861 | 1431 | tokptr++; |
c105168f WM |
1432 | goto tryagain; |
1433 | } | |
1434 | else if (*tokptr != ',') | |
1435 | error ("Invalid control sequence"); | |
1436 | tokptr++; | |
1437 | /* skip possible whitespaces */ | |
1438 | while ((*tokptr == ' ' || *tokptr == '\t') && *tokptr) | |
1439 | tokptr++; | |
1440 | if (!decode_integer_literal (&ival, &tokptr)) | |
1441 | error ("Invalid control sequence"); | |
1442 | tokptr--; | |
1443 | } | |
1444 | else if (*tokptr == *lexptr) | |
1445 | { | |
1446 | if (*(tokptr + 1) == *lexptr) | |
1447 | { | |
1448 | ival = *tokptr++; | |
5e548861 PB |
1449 | } |
1450 | else | |
1451 | { | |
1452 | break; | |
1453 | } | |
1454 | } | |
c105168f WM |
1455 | else if (*tokptr == '^') |
1456 | { | |
1457 | if (*(tokptr + 1) == '(') | |
1458 | { | |
1459 | in_ctrlseq = 1; | |
1460 | tokptr += 2; | |
1461 | if (!decode_integer_literal (&ival, &tokptr)) | |
1462 | error ("Invalid control sequence"); | |
1463 | tokptr--; | |
1464 | } | |
1465 | else if (*(tokptr + 1) == '^') | |
1466 | ival = *tokptr++; | |
1467 | else | |
1468 | error ("Invalid control sequence"); | |
1469 | } | |
1470 | else | |
1471 | ival = *tokptr; | |
1472 | tempbuf[tempbufindex++] = ival; | |
5e548861 | 1473 | } |
c105168f WM |
1474 | if (in_ctrlseq) |
1475 | error ("Invalid control sequence"); | |
1476 | ||
5e548861 PB |
1477 | if (*tokptr == '\0' /* no terminator */ |
1478 | || (tempbufindex == 1 && *tokptr == '\'')) /* char literal */ | |
1479 | { | |
1480 | return (0); | |
1481 | } | |
1482 | else | |
1483 | { | |
1484 | tempbuf[tempbufindex] = '\0'; | |
1485 | yylval.sval.ptr = tempbuf; | |
1486 | yylval.sval.length = tempbufindex; | |
1487 | lexptr = ++tokptr; | |
1488 | return (CHARACTER_STRING_LITERAL); | |
1489 | } | |
1490 | } | |
1491 | ||
1492 | /* Recognize a character literal. A character literal is single character | |
1493 | or a control sequence, enclosed in single quotes. A control sequence | |
1494 | is a comma separated list of one or more integer literals, enclosed | |
1495 | in parenthesis and introduced with a circumflex character. | |
1496 | ||
1497 | EX: 'a' '^(7)' '^(7,8)' | |
1498 | ||
1499 | As a GNU chill extension, the syntax C'xx' is also recognized as a | |
1500 | character literal, where xx is a hex value for the character. | |
1501 | ||
1502 | Note that more than a single character, enclosed in single quotes, is | |
1503 | a string literal. | |
1504 | ||
5e548861 PB |
1505 | Returns CHARACTER_LITERAL if a match is found. |
1506 | */ | |
1507 | ||
1508 | static enum ch_terminal | |
1509 | match_character_literal () | |
1510 | { | |
1511 | char *tokptr = lexptr; | |
1512 | LONGEST ival = 0; | |
1513 | ||
1514 | if ((*tokptr == 'c' || *tokptr == 'C') && (*(tokptr + 1) == '\'')) | |
1515 | { | |
1516 | /* We have a GNU chill extension form, so skip the leading "C'", | |
1517 | decode the hex value, and then ensure that we have a trailing | |
1518 | single quote character. */ | |
1519 | tokptr += 2; | |
1520 | if (!decode_integer_value (16, &tokptr, &ival) || (*tokptr != '\'')) | |
1521 | { | |
1522 | return (0); | |
1523 | } | |
1524 | tokptr++; | |
1525 | } | |
1526 | else if (*tokptr == '\'') | |
1527 | { | |
1528 | tokptr++; | |
1529 | ||
1530 | /* Determine which form we have, either a control sequence or the | |
1531 | single character form. */ | |
1532 | ||
c105168f | 1533 | if (*tokptr == '^') |
5e548861 | 1534 | { |
c105168f | 1535 | if (*(tokptr + 1) == '(') |
5e548861 | 1536 | { |
c105168f WM |
1537 | /* Match and decode a control sequence. Return zero if we don't |
1538 | find a valid integer literal, or if the next unconsumed character | |
1539 | after the integer literal is not the trailing ')'. */ | |
1540 | tokptr += 2; | |
1541 | if (!decode_integer_literal (&ival, &tokptr) || (*tokptr++ != ')')) | |
1542 | { | |
1543 | return (0); | |
1544 | } | |
5e548861 | 1545 | } |
c105168f WM |
1546 | else if (*(tokptr + 1) == '^') |
1547 | { | |
1548 | ival = *tokptr; | |
1549 | tokptr += 2; | |
1550 | } | |
1551 | else | |
1552 | /* fail */ | |
1553 | error ("Invalid control sequence"); | |
1554 | } | |
1555 | else if (*tokptr == '\'') | |
1556 | { | |
1557 | /* this must be duplicated */ | |
1558 | ival = *tokptr; | |
1559 | tokptr += 2; | |
5e548861 PB |
1560 | } |
1561 | else | |
1562 | { | |
1563 | ival = *tokptr++; | |
1564 | } | |
c105168f | 1565 | |
5e548861 PB |
1566 | /* The trailing quote has not yet been consumed. If we don't find |
1567 | it, then we have no match. */ | |
1568 | ||
1569 | if (*tokptr++ != '\'') | |
1570 | { | |
1571 | return (0); | |
1572 | } | |
1573 | } | |
1574 | else | |
1575 | { | |
1576 | /* Not a character literal. */ | |
1577 | return (0); | |
1578 | } | |
1579 | yylval.typed_val.val = ival; | |
1580 | yylval.typed_val.type = builtin_type_chill_char; | |
1581 | lexptr = tokptr; | |
1582 | return (CHARACTER_LITERAL); | |
1583 | } | |
1584 | ||
1585 | /* Recognize an integer literal, as specified in Z.200 sec 5.2.4.2. | |
1586 | Note that according to 5.2.4.2, a single "_" is also a valid integer | |
1587 | literal, however GNU-chill requires there to be at least one "digit" | |
1588 | in any integer literal. */ | |
1589 | ||
1590 | static enum ch_terminal | |
1591 | match_integer_literal () | |
1592 | { | |
1593 | char *tokptr = lexptr; | |
1594 | LONGEST ival; | |
1595 | ||
1596 | if (!decode_integer_literal (&ival, &tokptr)) | |
1597 | { | |
1598 | return (0); | |
1599 | } | |
1600 | else | |
1601 | { | |
1602 | yylval.typed_val.val = ival; | |
f6d16585 PB |
1603 | #if defined(CC_HAS_LONG_LONG) && defined(__STDC__) |
1604 | if (ival > (LONGEST)2147483647U || ival < -(LONGEST)2147483648U) | |
5e548861 PB |
1605 | yylval.typed_val.type = builtin_type_long_long; |
1606 | else | |
1607 | #endif | |
1608 | yylval.typed_val.type = builtin_type_int; | |
1609 | lexptr = tokptr; | |
1610 | return (INTEGER_LITERAL); | |
1611 | } | |
1612 | } | |
1613 | ||
1614 | /* Recognize a bit-string literal, as specified in Z.200 sec 5.2.4.8 | |
1615 | Note that according to 5.2.4.8, a single "_" is also a valid bit-string | |
1616 | literal, however GNU-chill requires there to be at least one "digit" | |
1617 | in any bit-string literal. */ | |
1618 | ||
1619 | static enum ch_terminal | |
1620 | match_bitstring_literal () | |
1621 | { | |
1622 | register char *tokptr = lexptr; | |
1623 | int bitoffset = 0; | |
1624 | int bitcount = 0; | |
1625 | int bits_per_char; | |
1626 | int digit; | |
1627 | ||
1628 | tempbufindex = 0; | |
1629 | CHECKBUF (1); | |
1630 | tempbuf[0] = 0; | |
1631 | ||
1632 | /* Look for the required explicit base specifier. */ | |
1633 | ||
1634 | switch (*tokptr++) | |
1635 | { | |
1636 | case 'b': | |
1637 | case 'B': | |
1638 | bits_per_char = 1; | |
1639 | break; | |
1640 | case 'o': | |
1641 | case 'O': | |
1642 | bits_per_char = 3; | |
1643 | break; | |
1644 | case 'h': | |
1645 | case 'H': | |
1646 | bits_per_char = 4; | |
1647 | break; | |
1648 | default: | |
1649 | return (0); | |
1650 | break; | |
1651 | } | |
1652 | ||
1653 | /* Ensure that the character after the explicit base is a single quote. */ | |
1654 | ||
1655 | if (*tokptr++ != '\'') | |
1656 | { | |
1657 | return (0); | |
1658 | } | |
1659 | ||
1660 | while (*tokptr != '\0' && *tokptr != '\'') | |
1661 | { | |
1662 | digit = *tokptr; | |
1663 | if (isupper (digit)) | |
1664 | digit = tolower (digit); | |
1665 | tokptr++; | |
1666 | switch (digit) | |
1667 | { | |
1668 | case '_': | |
1669 | continue; | |
1670 | case '0': case '1': case '2': case '3': case '4': | |
1671 | case '5': case '6': case '7': case '8': case '9': | |
1672 | digit -= '0'; | |
1673 | break; | |
1674 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': | |
1675 | digit -= 'a'; | |
1676 | digit += 10; | |
1677 | break; | |
1678 | default: | |
c105168f WM |
1679 | /* this is not a bitstring literal, probably an integer */ |
1680 | return 0; | |
5e548861 PB |
1681 | } |
1682 | if (digit >= 1 << bits_per_char) | |
1683 | { | |
1684 | /* Found something not in domain for current base. */ | |
1685 | error ("Too-large digit in bitstring or integer."); | |
1686 | } | |
1687 | else | |
1688 | { | |
1689 | /* Extract bits from digit, packing them into the bitstring byte. */ | |
1690 | int k = TARGET_BYTE_ORDER == BIG_ENDIAN ? bits_per_char - 1 : 0; | |
1691 | for (; TARGET_BYTE_ORDER == BIG_ENDIAN ? k >= 0 : k < bits_per_char; | |
1692 | TARGET_BYTE_ORDER == BIG_ENDIAN ? k-- : k++) | |
1693 | { | |
1694 | bitcount++; | |
1695 | if (digit & (1 << k)) | |
1696 | { | |
1697 | tempbuf[tempbufindex] |= | |
1698 | (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
1699 | ? (1 << (HOST_CHAR_BIT - 1 - bitoffset)) | |
1700 | : (1 << bitoffset); | |
1701 | } | |
1702 | bitoffset++; | |
1703 | if (bitoffset == HOST_CHAR_BIT) | |
1704 | { | |
1705 | bitoffset = 0; | |
1706 | tempbufindex++; | |
1707 | CHECKBUF(1); | |
1708 | tempbuf[tempbufindex] = 0; | |
1709 | } | |
1710 | } | |
1711 | } | |
1712 | } | |
1713 | ||
1714 | /* Verify that we consumed everything up to the trailing single quote, | |
1715 | and that we found some bits (IE not just underbars). */ | |
1716 | ||
1717 | if (*tokptr++ != '\'') | |
1718 | { | |
1719 | return (0); | |
1720 | } | |
1721 | else | |
1722 | { | |
1723 | yylval.sval.ptr = tempbuf; | |
1724 | yylval.sval.length = bitcount; | |
1725 | lexptr = tokptr; | |
1726 | return (BIT_STRING_LITERAL); | |
1727 | } | |
1728 | } | |
1729 | ||
1730 | struct token | |
1731 | { | |
1732 | char *operator; | |
1733 | int token; | |
1734 | }; | |
1735 | ||
1736 | static const struct token idtokentab[] = | |
1737 | { | |
1738 | { "array", ARRAY }, | |
1739 | { "length", LENGTH }, | |
1740 | { "lower", LOWER }, | |
1741 | { "upper", UPPER }, | |
1742 | { "andif", ANDIF }, | |
1743 | { "pred", PRED }, | |
1744 | { "succ", SUCC }, | |
1745 | { "card", CARD }, | |
1746 | { "size", SIZE }, | |
1747 | { "orif", ORIF }, | |
1748 | { "num", NUM }, | |
1749 | { "abs", ABS }, | |
1750 | { "max", MAX_TOKEN }, | |
1751 | { "min", MIN_TOKEN }, | |
1752 | { "mod", MOD }, | |
1753 | { "rem", REM }, | |
1754 | { "not", NOT }, | |
1755 | { "xor", LOGXOR }, | |
1756 | { "and", LOGAND }, | |
1757 | { "in", IN }, | |
1758 | { "or", LOGIOR }, | |
1759 | { "up", UP }, | |
1760 | { "addr", ADDR_TOKEN }, | |
1761 | { "null", EMPTINESS_LITERAL } | |
1762 | }; | |
1763 | ||
1764 | static const struct token tokentab2[] = | |
1765 | { | |
1766 | { ":=", GDB_ASSIGNMENT }, | |
1767 | { "//", SLASH_SLASH }, | |
1768 | { "->", POINTER }, | |
1769 | { "/=", NOTEQUAL }, | |
1770 | { "<=", LEQ }, | |
1771 | { ">=", GEQ } | |
1772 | }; | |
1773 | ||
1774 | /* Read one token, getting characters through lexptr. */ | |
1775 | /* This is where we will check to make sure that the language and the | |
1776 | operators used are compatible. */ | |
1777 | ||
1778 | static enum ch_terminal | |
1779 | ch_lex () | |
1780 | { | |
1781 | unsigned int i; | |
1782 | enum ch_terminal token; | |
1783 | char *inputname; | |
1784 | struct symbol *sym; | |
1785 | ||
1786 | /* Skip over any leading whitespace. */ | |
1787 | while (isspace (*lexptr)) | |
1788 | { | |
1789 | lexptr++; | |
1790 | } | |
1791 | /* Look for special single character cases which can't be the first | |
1792 | character of some other multicharacter token. */ | |
1793 | switch (*lexptr) | |
1794 | { | |
1795 | case '\0': | |
1796 | return END_TOKEN; | |
1797 | case ',': | |
1798 | case '=': | |
1799 | case ';': | |
1800 | case '!': | |
1801 | case '+': | |
1802 | case '*': | |
1803 | case '(': | |
1804 | case ')': | |
1805 | case '[': | |
1806 | case ']': | |
1807 | return (*lexptr++); | |
1808 | } | |
1809 | /* Look for characters which start a particular kind of multicharacter | |
1810 | token, such as a character literal, register name, convenience | |
1811 | variable name, string literal, etc. */ | |
1812 | switch (*lexptr) | |
1813 | { | |
1814 | case '\'': | |
1815 | case '\"': | |
1816 | /* First try to match a string literal, which is any | |
1817 | sequence of characters enclosed in matching single or double | |
1818 | quotes, except that a single character inside single quotes | |
1819 | is a character literal, so we have to catch that case also. */ | |
1820 | token = match_string_literal (); | |
1821 | if (token != 0) | |
1822 | { | |
1823 | return (token); | |
1824 | } | |
1825 | if (*lexptr == '\'') | |
1826 | { | |
1827 | token = match_character_literal (); | |
1828 | if (token != 0) | |
1829 | { | |
1830 | return (token); | |
1831 | } | |
1832 | } | |
1833 | break; | |
1834 | case 'C': | |
1835 | case 'c': | |
1836 | token = match_character_literal (); | |
1837 | if (token != 0) | |
1838 | { | |
1839 | return (token); | |
1840 | } | |
1841 | break; | |
1842 | case '$': | |
1843 | yylval.sval.ptr = lexptr; | |
1844 | do { | |
1845 | lexptr++; | |
1846 | } while (isalnum (*lexptr) || *lexptr == '_' || *lexptr == '$'); | |
1847 | yylval.sval.length = lexptr - yylval.sval.ptr; | |
1848 | write_dollar_variable (yylval.sval); | |
1849 | return GDB_VARIABLE; | |
1850 | break; | |
1851 | } | |
1852 | /* See if it is a special token of length 2. */ | |
1853 | for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++) | |
1854 | { | |
1855 | if (STREQN (lexptr, tokentab2[i].operator, 2)) | |
1856 | { | |
1857 | lexptr += 2; | |
1858 | return (tokentab2[i].token); | |
1859 | } | |
1860 | } | |
1861 | /* Look for single character cases which which could be the first | |
1862 | character of some other multicharacter token, but aren't, or we | |
1863 | would already have found it. */ | |
1864 | switch (*lexptr) | |
1865 | { | |
1866 | case '-': | |
1867 | case ':': | |
1868 | case '/': | |
1869 | case '<': | |
1870 | case '>': | |
1871 | return (*lexptr++); | |
1872 | } | |
1873 | /* Look for a float literal before looking for an integer literal, so | |
1874 | we match as much of the input stream as possible. */ | |
1875 | token = match_float_literal (); | |
1876 | if (token != 0) | |
1877 | { | |
1878 | return (token); | |
1879 | } | |
1880 | token = match_bitstring_literal (); | |
1881 | if (token != 0) | |
1882 | { | |
1883 | return (token); | |
1884 | } | |
1885 | token = match_integer_literal (); | |
1886 | if (token != 0) | |
1887 | { | |
1888 | return (token); | |
1889 | } | |
1890 | ||
1891 | /* Try to match a simple name string, and if a match is found, then | |
1892 | further classify what sort of name it is and return an appropriate | |
1893 | token. Note that attempting to match a simple name string consumes | |
1894 | the token from lexptr, so we can't back out if we later find that | |
1895 | we can't classify what sort of name it is. */ | |
1896 | ||
1897 | inputname = match_simple_name_string (); | |
1898 | ||
1899 | if (inputname != NULL) | |
1900 | { | |
1901 | char *simplename = (char*) alloca (strlen (inputname) + 1); | |
1902 | ||
1903 | char *dptr = simplename, *sptr = inputname; | |
1904 | for (; *sptr; sptr++) | |
1905 | *dptr++ = isupper (*sptr) ? tolower(*sptr) : *sptr; | |
1906 | *dptr = '\0'; | |
1907 | ||
1908 | /* See if it is a reserved identifier. */ | |
1909 | for (i = 0; i < sizeof (idtokentab) / sizeof (idtokentab[0]); i++) | |
1910 | { | |
1911 | if (STREQ (simplename, idtokentab[i].operator)) | |
1912 | { | |
1913 | return (idtokentab[i].token); | |
1914 | } | |
1915 | } | |
1916 | ||
1917 | /* Look for other special tokens. */ | |
1918 | if (STREQ (simplename, "true")) | |
1919 | { | |
1920 | yylval.ulval = 1; | |
1921 | return (BOOLEAN_LITERAL); | |
1922 | } | |
1923 | if (STREQ (simplename, "false")) | |
1924 | { | |
1925 | yylval.ulval = 0; | |
1926 | return (BOOLEAN_LITERAL); | |
1927 | } | |
1928 | ||
1929 | sym = lookup_symbol (inputname, expression_context_block, | |
1930 | VAR_NAMESPACE, (int *) NULL, | |
1931 | (struct symtab **) NULL); | |
1932 | if (sym == NULL && strcmp (inputname, simplename) != 0) | |
1933 | { | |
1934 | sym = lookup_symbol (simplename, expression_context_block, | |
1935 | VAR_NAMESPACE, (int *) NULL, | |
1936 | (struct symtab **) NULL); | |
1937 | } | |
1938 | if (sym != NULL) | |
1939 | { | |
1940 | yylval.ssym.stoken.ptr = NULL; | |
1941 | yylval.ssym.stoken.length = 0; | |
1942 | yylval.ssym.sym = sym; | |
1943 | yylval.ssym.is_a_field_of_this = 0; /* FIXME, C++'ism */ | |
1944 | switch (SYMBOL_CLASS (sym)) | |
1945 | { | |
1946 | case LOC_BLOCK: | |
1947 | /* Found a procedure name. */ | |
1948 | return (GENERAL_PROCEDURE_NAME); | |
1949 | case LOC_STATIC: | |
1950 | /* Found a global or local static variable. */ | |
1951 | return (LOCATION_NAME); | |
1952 | case LOC_REGISTER: | |
1953 | case LOC_ARG: | |
1954 | case LOC_REF_ARG: | |
1955 | case LOC_REGPARM: | |
1956 | case LOC_REGPARM_ADDR: | |
1957 | case LOC_LOCAL: | |
1958 | case LOC_LOCAL_ARG: | |
1959 | case LOC_BASEREG: | |
1960 | case LOC_BASEREG_ARG: | |
1961 | if (innermost_block == NULL | |
1962 | || contained_in (block_found, innermost_block)) | |
1963 | { | |
1964 | innermost_block = block_found; | |
1965 | } | |
1966 | return (LOCATION_NAME); | |
1967 | break; | |
1968 | case LOC_CONST: | |
1969 | case LOC_LABEL: | |
1970 | return (LOCATION_NAME); | |
1971 | break; | |
1972 | case LOC_TYPEDEF: | |
1973 | yylval.tsym.type = SYMBOL_TYPE (sym); | |
1974 | return TYPENAME; | |
1975 | case LOC_UNDEF: | |
1976 | case LOC_CONST_BYTES: | |
1977 | case LOC_OPTIMIZED_OUT: | |
1978 | error ("Symbol \"%s\" names no location.", inputname); | |
1979 | break; | |
1980 | } | |
1981 | } | |
1982 | else if (!have_full_symbols () && !have_partial_symbols ()) | |
1983 | { | |
1984 | error ("No symbol table is loaded. Use the \"file\" command."); | |
1985 | } | |
1986 | else | |
1987 | { | |
1988 | error ("No symbol \"%s\" in current context.", inputname); | |
1989 | } | |
1990 | } | |
1991 | ||
1992 | /* Catch single character tokens which are not part of some | |
1993 | longer token. */ | |
1994 | ||
1995 | switch (*lexptr) | |
1996 | { | |
1997 | case '.': /* Not float for example. */ | |
1998 | lexptr++; | |
1999 | while (isspace (*lexptr)) lexptr++; | |
2000 | inputname = match_simple_name_string (); | |
2001 | if (!inputname) | |
2002 | return '.'; | |
2003 | return FIELD_NAME; | |
2004 | } | |
2005 | ||
2006 | return (ILLEGAL_TOKEN); | |
2007 | } | |
2008 | ||
2009 | static void | |
2010 | write_lower_upper_value (opcode, type) | |
2011 | enum exp_opcode opcode; /* Either UNOP_LOWER or UNOP_UPPER */ | |
2012 | struct type *type; | |
2013 | { | |
2014 | if (type == NULL) | |
2015 | write_exp_elt_opcode (opcode); | |
2016 | else | |
2017 | { | |
2018 | extern LONGEST type_lower_upper (); | |
2019 | struct type *result_type; | |
2020 | LONGEST val = type_lower_upper (opcode, type, &result_type); | |
2021 | write_exp_elt_opcode (OP_LONG); | |
2022 | write_exp_elt_type (result_type); | |
2023 | write_exp_elt_longcst (val); | |
2024 | write_exp_elt_opcode (OP_LONG); | |
2025 | } | |
2026 | } | |
2027 | ||
2028 | void | |
2029 | chill_error (msg) | |
2030 | char *msg; | |
2031 | { | |
2032 | /* Never used. */ | |
2033 | } |