* parse.c (write_dollar_variable): New function.
[deliverable/binutils-gdb.git] / gdb / ch-exp.y
1 /* YACC grammar for Chill expressions, for GDB.
2 Copyright 1992, 1993, 1994 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
29 Note that malloc's and realloc's in this file are transformed to
30 xmalloc and xrealloc respectively by the same sed command in the
31 makefile that remaps any other malloc/realloc inserted by the parser
32 generator. Doing this with #defines and trying to control the interaction
33 with include files (<malloc.h> and <stdlib.h> for example) just became
34 too messy, particularly when such includes can be inserted at random
35 times by the parser generator.
36
37 Also note that the language accepted by this parser is more liberal
38 than the one accepted by an actual Chill compiler. For example, the
39 language rule that a simple name string can not be one of the reserved
40 simple name strings is not enforced (e.g "case" is not treated as a
41 reserved name). Another example is that Chill is a strongly typed
42 language, and certain expressions that violate the type constraints
43 may still be evaluated if gdb can do so in a meaningful manner, while
44 such expressions would be rejected by the compiler. The reason for
45 this more liberal behavior is the philosophy that the debugger
46 is intended to be a tool that is used by the programmer when things
47 go wrong, and as such, it should provide as few artificial barriers
48 to it's use as possible. If it can do something meaningful, even
49 something that violates language contraints that are enforced by the
50 compiler, it should do so without complaint.
51
52 */
53
54 %{
55
56 #include "defs.h"
57 #include <string.h>
58 #include <ctype.h>
59 #include "expression.h"
60 #include "language.h"
61 #include "value.h"
62 #include "parser-defs.h"
63 #include "ch-lang.h"
64 #include "bfd.h" /* Required by objfiles.h. */
65 #include "symfile.h" /* Required by objfiles.h. */
66 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
67
68 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
69 as well as gratuitiously global symbol names, so we can have multiple
70 yacc generated parsers in gdb. Note that these are only the variables
71 produced by yacc. If other parser generators (bison, byacc, etc) produce
72 additional global names that conflict at link time, then those parser
73 generators need to be fixed instead of adding those names to this list. */
74
75 #define yymaxdepth chill_maxdepth
76 #define yyparse chill_parse
77 #define yylex chill_lex
78 #define yyerror chill_error
79 #define yylval chill_lval
80 #define yychar chill_char
81 #define yydebug chill_debug
82 #define yypact chill_pact
83 #define yyr1 chill_r1
84 #define yyr2 chill_r2
85 #define yydef chill_def
86 #define yychk chill_chk
87 #define yypgo chill_pgo
88 #define yyact chill_act
89 #define yyexca chill_exca
90 #define yyerrflag chill_errflag
91 #define yynerrs chill_nerrs
92 #define yyps chill_ps
93 #define yypv chill_pv
94 #define yys chill_s
95 #define yy_yys chill_yys
96 #define yystate chill_state
97 #define yytmp chill_tmp
98 #define yyv chill_v
99 #define yy_yyv chill_yyv
100 #define yyval chill_val
101 #define yylloc chill_lloc
102 #define yyreds chill_reds /* With YYDEBUG defined */
103 #define yytoks chill_toks /* With YYDEBUG defined */
104 #define yylhs chill_yylhs
105 #define yylen chill_yylen
106 #define yydefred chill_yydefred
107 #define yydgoto chill_yydgoto
108 #define yysindex chill_yysindex
109 #define yyrindex chill_yyrindex
110 #define yygindex chill_yygindex
111 #define yytable chill_yytable
112 #define yycheck chill_yycheck
113
114 #ifndef YYDEBUG
115 #define YYDEBUG 0 /* Default to no yydebug support */
116 #endif
117
118 static void
119 write_lower_upper_value PARAMS ((enum exp_opcode, struct type *type));
120
121 int
122 yyparse PARAMS ((void));
123
124 static int
125 yylex PARAMS ((void));
126
127 void
128 yyerror PARAMS ((char *));
129
130 %}
131
132 /* Although the yacc "value" of an expression is not used,
133 since the result is stored in the structure being created,
134 other node types do have values. */
135
136 %union
137 {
138 LONGEST lval;
139 unsigned LONGEST ulval;
140 struct {
141 LONGEST val;
142 struct type *type;
143 } typed_val;
144 double dval;
145 struct symbol *sym;
146 struct type *tval;
147 struct stoken sval;
148 struct ttype tsym;
149 struct symtoken ssym;
150 int voidval;
151 struct block *bval;
152 enum exp_opcode opcode;
153 struct internalvar *ivar;
154
155 struct type **tvec;
156 int *ivec;
157 }
158
159 %token <typed_val> INTEGER_LITERAL
160 %token <ulval> BOOLEAN_LITERAL
161 %token <typed_val> CHARACTER_LITERAL
162 %token <dval> FLOAT_LITERAL
163 %token <ssym> GENERAL_PROCEDURE_NAME
164 %token <ssym> LOCATION_NAME
165 %token <voidval> EMPTINESS_LITERAL
166 %token <sval> CHARACTER_STRING_LITERAL
167 %token <sval> BIT_STRING_LITERAL
168 %token <tsym> TYPENAME
169 %token <sval> FIELD_NAME
170
171 %token <voidval> '.'
172 %token <voidval> ';'
173 %token <voidval> ':'
174 %token <voidval> CASE
175 %token <voidval> OF
176 %token <voidval> ESAC
177 %token <voidval> LOGIOR
178 %token <voidval> ORIF
179 %token <voidval> LOGXOR
180 %token <voidval> LOGAND
181 %token <voidval> ANDIF
182 %token <voidval> '='
183 %token <voidval> NOTEQUAL
184 %token <voidval> '>'
185 %token <voidval> GTR
186 %token <voidval> '<'
187 %token <voidval> LEQ
188 %token <voidval> IN
189 %token <voidval> '+'
190 %token <voidval> '-'
191 %token <voidval> '*'
192 %token <voidval> '/'
193 %token <voidval> SLASH_SLASH
194 %token <voidval> MOD
195 %token <voidval> REM
196 %token <voidval> NOT
197 %token <voidval> POINTER
198 %token <voidval> RECEIVE
199 %token <voidval> '['
200 %token <voidval> ']'
201 %token <voidval> '('
202 %token <voidval> ')'
203 %token <voidval> UP
204 %token <voidval> IF
205 %token <voidval> THEN
206 %token <voidval> ELSE
207 %token <voidval> FI
208 %token <voidval> ELSIF
209 %token <voidval> ILLEGAL_TOKEN
210 %token <voidval> NUM
211 %token <voidval> PRED
212 %token <voidval> SUCC
213 %token <voidval> ABS
214 %token <voidval> CARD
215 %token <voidval> MAX_TOKEN
216 %token <voidval> MIN_TOKEN
217 %token <voidval> ADDR_TOKEN
218 %token <voidval> SIZE
219 %token <voidval> UPPER
220 %token <voidval> LOWER
221 %token <voidval> LENGTH
222 %token <voidval> ARRAY
223
224 /* Tokens which are not Chill tokens used in expressions, but rather GDB
225 specific things that we recognize in the same context as Chill tokens
226 (register names for example). */
227
228 %token <voidval> GDB_VARIABLE /* Convenience variable */
229 %token <voidval> GDB_ASSIGNMENT /* Assign value to somewhere */
230
231 %type <voidval> access_name
232 %type <voidval> primitive_value
233 %type <voidval> value_name
234 %type <voidval> literal
235 %type <voidval> tuple
236 %type <voidval> slice
237 %type <voidval> expression_conversion
238 %type <voidval> value_built_in_routine_call
239 %type <voidval> parenthesised_expression
240 %type <voidval> value
241 %type <voidval> expression
242 %type <voidval> conditional_expression
243 %type <voidval> then_alternative
244 %type <voidval> else_alternative
245 %type <voidval> operand_0
246 %type <voidval> operand_1
247 %type <voidval> operand_2
248 %type <voidval> operand_3
249 %type <voidval> operand_4
250 %type <voidval> operand_5
251 %type <voidval> operand_6
252 %type <voidval> expression_list
253 %type <tval> mode_argument
254 %type <voidval> single_assignment_action
255 %type <tsym> mode_name
256 %type <lval> rparen
257
258 /* Not implemented:
259 %type <voidval> undefined_value
260 %type <voidval> array_mode_name
261 %type <voidval> string_mode_name
262 %type <voidval> variant_structure_mode_name
263 */
264
265 %%
266
267 /* Z.200, 5.3.1 */
268
269 start : value { }
270 | mode_name
271 { write_exp_elt_opcode(OP_TYPE);
272 write_exp_elt_type($1.type);
273 write_exp_elt_opcode(OP_TYPE);}
274 ;
275
276 value : expression
277 /*
278 | undefined_value
279 { ??? }
280 */
281 ;
282
283 /* Z.200, 4.2.2 */
284
285 access_name : LOCATION_NAME
286 {
287 write_exp_elt_opcode (OP_VAR_VALUE);
288 write_exp_elt_block (NULL);
289 write_exp_elt_sym ($1.sym);
290 write_exp_elt_opcode (OP_VAR_VALUE);
291 }
292 | GDB_VARIABLE /* gdb specific */
293 ;
294
295 /* Z.200, 4.2.8 */
296
297 expression_list : expression
298 {
299 arglist_len = 1;
300 }
301 | expression_list ',' expression
302 {
303 arglist_len++;
304 }
305 ;
306
307 maybe_expression_list: /* EMPTY */
308 {
309 arglist_len = 0;
310 }
311 | expression_list
312 ;
313
314
315 /* Z.200, 5.2.1 */
316
317 primitive_value_lparen: primitive_value '('
318 /* This is to save the value of arglist_len
319 being accumulated for each dimension. */
320 { start_arglist (); }
321 ;
322
323 rparen : ')'
324 { $$ = end_arglist (); }
325 ;
326
327 primitive_value :
328 access_name
329 | primitive_value_lparen maybe_expression_list rparen
330 {
331 write_exp_elt_opcode (MULTI_SUBSCRIPT);
332 write_exp_elt_longcst ($3);
333 write_exp_elt_opcode (MULTI_SUBSCRIPT);
334 }
335 | primitive_value FIELD_NAME
336 { write_exp_elt_opcode (STRUCTOP_STRUCT);
337 write_exp_string ($2);
338 write_exp_elt_opcode (STRUCTOP_STRUCT);
339 }
340 | primitive_value POINTER
341 {
342 write_exp_elt_opcode (UNOP_IND);
343 }
344 | primitive_value POINTER mode_name
345 {
346 write_exp_elt_opcode (UNOP_CAST);
347 write_exp_elt_type (lookup_pointer_type ($3.type));
348 write_exp_elt_opcode (UNOP_CAST);
349 write_exp_elt_opcode (UNOP_IND);
350 }
351 | value_name
352 | literal
353 | tuple
354 | slice
355 | expression_conversion
356 | value_built_in_routine_call
357 /*
358 | start_expression
359 { ??? }
360 | zero_adic_operator
361 { ??? }
362 */
363 | parenthesised_expression
364 ;
365
366 /* Z.200, 5.2.3 */
367
368 value_name : GENERAL_PROCEDURE_NAME
369 {
370 write_exp_elt_opcode (OP_VAR_VALUE);
371 write_exp_elt_block (NULL);
372 write_exp_elt_sym ($1.sym);
373 write_exp_elt_opcode (OP_VAR_VALUE);
374 }
375 ;
376
377 /* Z.200, 5.2.4.1 */
378
379 literal : INTEGER_LITERAL
380 {
381 write_exp_elt_opcode (OP_LONG);
382 write_exp_elt_type ($1.type);
383 write_exp_elt_longcst ((LONGEST) ($1.val));
384 write_exp_elt_opcode (OP_LONG);
385 }
386 | BOOLEAN_LITERAL
387 {
388 write_exp_elt_opcode (OP_BOOL);
389 write_exp_elt_longcst ((LONGEST) $1);
390 write_exp_elt_opcode (OP_BOOL);
391 }
392 | CHARACTER_LITERAL
393 {
394 write_exp_elt_opcode (OP_LONG);
395 write_exp_elt_type ($1.type);
396 write_exp_elt_longcst ((LONGEST) ($1.val));
397 write_exp_elt_opcode (OP_LONG);
398 }
399 | FLOAT_LITERAL
400 {
401 write_exp_elt_opcode (OP_DOUBLE);
402 write_exp_elt_type (builtin_type_double);
403 write_exp_elt_dblcst ($1);
404 write_exp_elt_opcode (OP_DOUBLE);
405 }
406 | EMPTINESS_LITERAL
407 {
408 struct type *void_ptr_type
409 = lookup_pointer_type (builtin_type_void);
410 write_exp_elt_opcode (OP_LONG);
411 write_exp_elt_type (void_ptr_type);
412 write_exp_elt_longcst (0);
413 write_exp_elt_opcode (OP_LONG);
414 }
415 | CHARACTER_STRING_LITERAL
416 {
417 write_exp_elt_opcode (OP_STRING);
418 write_exp_string ($1);
419 write_exp_elt_opcode (OP_STRING);
420 }
421 | BIT_STRING_LITERAL
422 {
423 write_exp_elt_opcode (OP_BITSTRING);
424 write_exp_bitstring ($1);
425 write_exp_elt_opcode (OP_BITSTRING);
426 }
427 ;
428
429 /* Z.200, 5.2.5 */
430
431 tuple_element : expression
432 | named_record_element
433 ;
434
435 named_record_element: FIELD_NAME ',' named_record_element
436 { write_exp_elt_opcode (OP_LABELED);
437 write_exp_string ($1);
438 write_exp_elt_opcode (OP_LABELED);
439 }
440 | FIELD_NAME ':' expression
441 { write_exp_elt_opcode (OP_LABELED);
442 write_exp_string ($1);
443 write_exp_elt_opcode (OP_LABELED);
444 }
445 ;
446
447 tuple_elements : tuple_element
448 {
449 arglist_len = 1;
450 }
451 | tuple_elements ',' tuple_element
452 {
453 arglist_len++;
454 }
455 ;
456
457 maybe_tuple_elements : tuple_elements
458 | /* EMPTY */
459 ;
460
461 tuple : '['
462 { start_arglist (); }
463 maybe_tuple_elements ']'
464 {
465 write_exp_elt_opcode (OP_ARRAY);
466 write_exp_elt_longcst ((LONGEST) 0);
467 write_exp_elt_longcst ((LONGEST) end_arglist () - 1);
468 write_exp_elt_opcode (OP_ARRAY);
469 }
470 |
471 mode_name '['
472 { start_arglist (); }
473 maybe_tuple_elements ']'
474 {
475 write_exp_elt_opcode (OP_ARRAY);
476 write_exp_elt_longcst ((LONGEST) 0);
477 write_exp_elt_longcst ((LONGEST) end_arglist () - 1);
478 write_exp_elt_opcode (OP_ARRAY);
479
480 write_exp_elt_opcode (UNOP_CAST);
481 write_exp_elt_type ($1.type);
482 write_exp_elt_opcode (UNOP_CAST);
483 }
484 ;
485
486
487 /* Z.200, 5.2.6 */
488
489
490 slice: primitive_value_lparen expression ':' expression rparen
491 {
492 write_exp_elt_opcode (TERNOP_SLICE);
493 }
494 | primitive_value_lparen expression UP expression rparen
495 {
496 write_exp_elt_opcode (TERNOP_SLICE_COUNT);
497 }
498 ;
499
500 /* Z.200, 5.2.11 */
501
502 expression_conversion: mode_name parenthesised_expression
503 {
504 write_exp_elt_opcode (UNOP_CAST);
505 write_exp_elt_type ($1.type);
506 write_exp_elt_opcode (UNOP_CAST);
507 }
508 | ARRAY '(' ')' mode_name parenthesised_expression
509 /* This is pseudo-Chill, similar to C's '(TYPE[])EXPR'
510 which casts to an artificial array. */
511 {
512 struct type *range_type
513 = create_range_type ((struct type *) NULL,
514 builtin_type_int, 0, 0);
515 struct type *array_type
516 = create_array_type ((struct type *) NULL,
517 $4.type, range_type);
518 TYPE_ARRAY_UPPER_BOUND_TYPE(array_type)
519 = BOUND_CANNOT_BE_DETERMINED;
520 write_exp_elt_opcode (UNOP_CAST);
521 write_exp_elt_type (array_type);
522 write_exp_elt_opcode (UNOP_CAST);
523 }
524 ;
525
526 /* Z.200, 5.2.16 */
527
528 parenthesised_expression: '(' expression ')'
529 ;
530
531 /* Z.200, 5.3.2 */
532
533 expression : operand_0
534 | single_assignment_action
535 | conditional_expression
536 ;
537
538 conditional_expression : IF expression then_alternative else_alternative FI
539 { write_exp_elt_opcode (TERNOP_COND); }
540 /*
541 | CASE case_selector_list OF value_case_alternative ELSE expression ESAC
542 { error ("not implemented: CASE expression" }
543 */
544 ;
545
546 then_alternative: THEN expression
547 ;
548
549 else_alternative: ELSE expression
550 | ELSIF expression then_alternative else_alternative
551 { write_exp_elt_opcode (TERNOP_COND); }
552 ;
553
554 /* Z.200, 5.3.3 */
555
556 operand_0 : operand_1
557 | operand_0 LOGIOR operand_1
558 {
559 write_exp_elt_opcode (BINOP_BITWISE_IOR);
560 }
561 | operand_0 ORIF operand_1
562 {
563 write_exp_elt_opcode (BINOP_LOGICAL_OR);
564 }
565 | operand_0 LOGXOR operand_1
566 {
567 write_exp_elt_opcode (BINOP_BITWISE_XOR);
568 }
569 ;
570
571 /* Z.200, 5.3.4 */
572
573 operand_1 : operand_2
574 | operand_1 LOGAND operand_2
575 {
576 write_exp_elt_opcode (BINOP_BITWISE_AND);
577 }
578 | operand_1 ANDIF operand_2
579 {
580 write_exp_elt_opcode (BINOP_LOGICAL_AND);
581 }
582 ;
583
584 /* Z.200, 5.3.5 */
585
586 operand_2 : operand_3
587 | operand_2 '=' operand_3
588 {
589 write_exp_elt_opcode (BINOP_EQUAL);
590 }
591 | operand_2 NOTEQUAL operand_3
592 {
593 write_exp_elt_opcode (BINOP_NOTEQUAL);
594 }
595 | operand_2 '>' operand_3
596 {
597 write_exp_elt_opcode (BINOP_GTR);
598 }
599 | operand_2 GTR operand_3
600 {
601 write_exp_elt_opcode (BINOP_GEQ);
602 }
603 | operand_2 '<' operand_3
604 {
605 write_exp_elt_opcode (BINOP_LESS);
606 }
607 | operand_2 LEQ operand_3
608 {
609 write_exp_elt_opcode (BINOP_LEQ);
610 }
611 | operand_2 IN operand_3
612 {
613 write_exp_elt_opcode (BINOP_IN);
614 }
615 ;
616
617
618 /* Z.200, 5.3.6 */
619
620 operand_3 : operand_4
621 | operand_3 '+' operand_4
622 {
623 write_exp_elt_opcode (BINOP_ADD);
624 }
625 | operand_3 '-' operand_4
626 {
627 write_exp_elt_opcode (BINOP_SUB);
628 }
629 | operand_3 SLASH_SLASH operand_4
630 {
631 write_exp_elt_opcode (BINOP_CONCAT);
632 }
633 ;
634
635 /* Z.200, 5.3.7 */
636
637 operand_4 : operand_5
638 | operand_4 '*' operand_5
639 {
640 write_exp_elt_opcode (BINOP_MUL);
641 }
642 | operand_4 '/' operand_5
643 {
644 write_exp_elt_opcode (BINOP_DIV);
645 }
646 | operand_4 MOD operand_5
647 {
648 write_exp_elt_opcode (BINOP_MOD);
649 }
650 | operand_4 REM operand_5
651 {
652 write_exp_elt_opcode (BINOP_REM);
653 }
654 ;
655
656 /* Z.200, 5.3.8 */
657
658 operand_5 : operand_6
659 | '-' operand_6
660 {
661 write_exp_elt_opcode (UNOP_NEG);
662 }
663 | NOT operand_6
664 {
665 write_exp_elt_opcode (UNOP_LOGICAL_NOT);
666 }
667 | parenthesised_expression literal
668 /* We require the string operand to be a literal, to avoid some
669 nasty parsing ambiguities. */
670 {
671 write_exp_elt_opcode (BINOP_CONCAT);
672 }
673 ;
674
675 /* Z.200, 5.3.9 */
676
677 operand_6 : POINTER primitive_value
678 {
679 write_exp_elt_opcode (UNOP_ADDR);
680 }
681 | RECEIVE expression
682 { error ("not implemented: RECEIVE expression"); }
683 | primitive_value
684 ;
685
686
687 /* Z.200, 6.2 */
688
689 single_assignment_action :
690 primitive_value GDB_ASSIGNMENT value
691 {
692 write_exp_elt_opcode (BINOP_ASSIGN);
693 }
694 ;
695
696 /* Z.200, 6.20.3 */
697
698 value_built_in_routine_call :
699 NUM '(' expression ')'
700 {
701 write_exp_elt_opcode (UNOP_CAST);
702 write_exp_elt_type (builtin_type_int);
703 write_exp_elt_opcode (UNOP_CAST);
704 }
705 | PRED '(' expression ')'
706 { error ("not implemented: PRED builtin function"); }
707 | SUCC '(' expression ')'
708 { error ("not implemented: SUCC builtin function"); }
709 | ADDR_TOKEN '(' expression ')'
710 { write_exp_elt_opcode (UNOP_ADDR); }
711 | ABS '(' expression ')'
712 { error ("not implemented: ABS builtin function"); }
713 | CARD '(' expression ')'
714 { error ("not implemented: CARD builtin function"); }
715 | MAX_TOKEN '(' expression ')'
716 { error ("not implemented: MAX builtin function"); }
717 | MIN_TOKEN '(' expression ')'
718 { error ("not implemented: MIN builtin function"); }
719 | SIZE '(' expression ')'
720 { write_exp_elt_opcode (UNOP_SIZEOF); }
721 | SIZE '(' mode_argument ')'
722 { write_exp_elt_opcode (OP_LONG);
723 write_exp_elt_type (builtin_type_int);
724 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
725 write_exp_elt_opcode (OP_LONG); }
726 | LOWER '(' mode_argument ')'
727 { write_lower_upper_value (UNOP_LOWER, $3); }
728 | UPPER '(' mode_argument ')'
729 { write_lower_upper_value (UNOP_UPPER, $3); }
730 | LOWER '(' expression ')'
731 { write_exp_elt_opcode (UNOP_LOWER); }
732 | UPPER '(' expression ')'
733 { write_exp_elt_opcode (UNOP_UPPER); }
734 | LENGTH '(' expression ')'
735 { write_exp_elt_opcode (UNOP_LENGTH); }
736 ;
737
738 mode_argument : mode_name
739 {
740 $$ = $1.type;
741 }
742 /*
743 | array_mode_name '(' expression ')'
744 { ??? }
745 | string_mode_name '(' expression ')'
746 { ??? }
747 | variant_structure_mode_name '(' expression_list ')'
748 { ??? }
749 */
750 ;
751
752 mode_name : TYPENAME
753 ;
754
755 %%
756
757 /* Implementation of a dynamically expandable buffer for processing input
758 characters acquired through lexptr and building a value to return in
759 yylval. */
760
761 static char *tempbuf; /* Current buffer contents */
762 static int tempbufsize; /* Size of allocated buffer */
763 static int tempbufindex; /* Current index into buffer */
764
765 #define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */
766
767 #define CHECKBUF(size) \
768 do { \
769 if (tempbufindex + (size) >= tempbufsize) \
770 { \
771 growbuf_by_size (size); \
772 } \
773 } while (0);
774
775 /* Grow the static temp buffer if necessary, including allocating the first one
776 on demand. */
777
778 static void
779 growbuf_by_size (count)
780 int count;
781 {
782 int growby;
783
784 growby = max (count, GROWBY_MIN_SIZE);
785 tempbufsize += growby;
786 if (tempbuf == NULL)
787 {
788 tempbuf = (char *) malloc (tempbufsize);
789 }
790 else
791 {
792 tempbuf = (char *) realloc (tempbuf, tempbufsize);
793 }
794 }
795
796 /* Try to consume a simple name string token. If successful, returns
797 a pointer to a nullbyte terminated copy of the name that can be used
798 in symbol table lookups. If not successful, returns NULL. */
799
800 static char *
801 match_simple_name_string ()
802 {
803 char *tokptr = lexptr;
804
805 if (isalpha (*tokptr) || *tokptr == '_')
806 {
807 char *result;
808 do {
809 tokptr++;
810 } while (isalnum (*tokptr) || (*tokptr == '_'));
811 yylval.sval.ptr = lexptr;
812 yylval.sval.length = tokptr - lexptr;
813 lexptr = tokptr;
814 result = copy_name (yylval.sval);
815 return result;
816 }
817 return (NULL);
818 }
819
820 /* Start looking for a value composed of valid digits as set by the base
821 in use. Note that '_' characters are valid anywhere, in any quantity,
822 and are simply ignored. Since we must find at least one valid digit,
823 or reject this token as an integer literal, we keep track of how many
824 digits we have encountered. */
825
826 static int
827 decode_integer_value (base, tokptrptr, ivalptr)
828 int base;
829 char **tokptrptr;
830 int *ivalptr;
831 {
832 char *tokptr = *tokptrptr;
833 int temp;
834 int digits = 0;
835
836 while (*tokptr != '\0')
837 {
838 temp = *tokptr;
839 if (isupper (temp))
840 temp = tolower (temp);
841 tokptr++;
842 switch (temp)
843 {
844 case '_':
845 continue;
846 case '0': case '1': case '2': case '3': case '4':
847 case '5': case '6': case '7': case '8': case '9':
848 temp -= '0';
849 break;
850 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
851 temp -= 'a';
852 temp += 10;
853 break;
854 default:
855 temp = base;
856 break;
857 }
858 if (temp < base)
859 {
860 digits++;
861 *ivalptr *= base;
862 *ivalptr += temp;
863 }
864 else
865 {
866 /* Found something not in domain for current base. */
867 tokptr--; /* Unconsume what gave us indigestion. */
868 break;
869 }
870 }
871
872 /* If we didn't find any digits, then we don't have a valid integer
873 value, so reject the entire token. Otherwise, update the lexical
874 scan pointer, and return non-zero for success. */
875
876 if (digits == 0)
877 {
878 return (0);
879 }
880 else
881 {
882 *tokptrptr = tokptr;
883 return (1);
884 }
885 }
886
887 static int
888 decode_integer_literal (valptr, tokptrptr)
889 int *valptr;
890 char **tokptrptr;
891 {
892 char *tokptr = *tokptrptr;
893 int base = 0;
894 int ival = 0;
895 int explicit_base = 0;
896
897 /* Look for an explicit base specifier, which is optional. */
898
899 switch (*tokptr)
900 {
901 case 'd':
902 case 'D':
903 explicit_base++;
904 base = 10;
905 tokptr++;
906 break;
907 case 'b':
908 case 'B':
909 explicit_base++;
910 base = 2;
911 tokptr++;
912 break;
913 case 'h':
914 case 'H':
915 explicit_base++;
916 base = 16;
917 tokptr++;
918 break;
919 case 'o':
920 case 'O':
921 explicit_base++;
922 base = 8;
923 tokptr++;
924 break;
925 default:
926 base = 10;
927 break;
928 }
929
930 /* If we found an explicit base ensure that the character after the
931 explicit base is a single quote. */
932
933 if (explicit_base && (*tokptr++ != '\''))
934 {
935 return (0);
936 }
937
938 /* Attempt to decode whatever follows as an integer value in the
939 indicated base, updating the token pointer in the process and
940 computing the value into ival. Also, if we have an explicit
941 base, then the next character must not be a single quote, or we
942 have a bitstring literal, so reject the entire token in this case.
943 Otherwise, update the lexical scan pointer, and return non-zero
944 for success. */
945
946 if (!decode_integer_value (base, &tokptr, &ival))
947 {
948 return (0);
949 }
950 else if (explicit_base && (*tokptr == '\''))
951 {
952 return (0);
953 }
954 else
955 {
956 *valptr = ival;
957 *tokptrptr = tokptr;
958 return (1);
959 }
960 }
961
962 /* If it wasn't for the fact that floating point values can contain '_'
963 characters, we could just let strtod do all the hard work by letting it
964 try to consume as much of the current token buffer as possible and
965 find a legal conversion. Unfortunately we need to filter out the '_'
966 characters before calling strtod, which we do by copying the other
967 legal chars to a local buffer to be converted. However since we also
968 need to keep track of where the last unconsumed character in the input
969 buffer is, we have transfer only as many characters as may compose a
970 legal floating point value. */
971
972 static int
973 match_float_literal ()
974 {
975 char *tokptr = lexptr;
976 char *buf;
977 char *copy;
978 double dval;
979 extern double strtod ();
980
981 /* Make local buffer in which to build the string to convert. This is
982 required because underscores are valid in chill floating point numbers
983 but not in the string passed to strtod to convert. The string will be
984 no longer than our input string. */
985
986 copy = buf = (char *) alloca (strlen (tokptr) + 1);
987
988 /* Transfer all leading digits to the conversion buffer, discarding any
989 underscores. */
990
991 while (isdigit (*tokptr) || *tokptr == '_')
992 {
993 if (*tokptr != '_')
994 {
995 *copy++ = *tokptr;
996 }
997 tokptr++;
998 }
999
1000 /* Now accept either a '.', or one of [eEdD]. Dot is legal regardless
1001 of whether we found any leading digits, and we simply accept it and
1002 continue on to look for the fractional part and/or exponent. One of
1003 [eEdD] is legal only if we have seen digits, and means that there
1004 is no fractional part. If we find neither of these, then this is
1005 not a floating point number, so return failure. */
1006
1007 switch (*tokptr++)
1008 {
1009 case '.':
1010 /* Accept and then look for fractional part and/or exponent. */
1011 *copy++ = '.';
1012 break;
1013
1014 case 'e':
1015 case 'E':
1016 case 'd':
1017 case 'D':
1018 if (copy == buf)
1019 {
1020 return (0);
1021 }
1022 *copy++ = 'e';
1023 goto collect_exponent;
1024 break;
1025
1026 default:
1027 return (0);
1028 break;
1029 }
1030
1031 /* We found a '.', copy any fractional digits to the conversion buffer, up
1032 to the first nondigit, non-underscore character. */
1033
1034 while (isdigit (*tokptr) || *tokptr == '_')
1035 {
1036 if (*tokptr != '_')
1037 {
1038 *copy++ = *tokptr;
1039 }
1040 tokptr++;
1041 }
1042
1043 /* Look for an exponent, which must start with one of [eEdD]. If none
1044 is found, jump directly to trying to convert what we have collected
1045 so far. */
1046
1047 switch (*tokptr)
1048 {
1049 case 'e':
1050 case 'E':
1051 case 'd':
1052 case 'D':
1053 *copy++ = 'e';
1054 tokptr++;
1055 break;
1056 default:
1057 goto convert_float;
1058 break;
1059 }
1060
1061 /* Accept an optional '-' or '+' following one of [eEdD]. */
1062
1063 collect_exponent:
1064 if (*tokptr == '+' || *tokptr == '-')
1065 {
1066 *copy++ = *tokptr++;
1067 }
1068
1069 /* Now copy an exponent into the conversion buffer. Note that at the
1070 moment underscores are *not* allowed in exponents. */
1071
1072 while (isdigit (*tokptr))
1073 {
1074 *copy++ = *tokptr++;
1075 }
1076
1077 /* If we transfered any chars to the conversion buffer, try to interpret its
1078 contents as a floating point value. If any characters remain, then we
1079 must not have a valid floating point string. */
1080
1081 convert_float:
1082 *copy = '\0';
1083 if (copy != buf)
1084 {
1085 dval = strtod (buf, &copy);
1086 if (*copy == '\0')
1087 {
1088 yylval.dval = dval;
1089 lexptr = tokptr;
1090 return (FLOAT_LITERAL);
1091 }
1092 }
1093 return (0);
1094 }
1095
1096 /* Recognize a string literal. A string literal is a sequence
1097 of characters enclosed in matching single or double quotes, except that
1098 a single character inside single quotes is a character literal, which
1099 we reject as a string literal. To embed the terminator character inside
1100 a string, it is simply doubled (I.E. "this""is""one""string") */
1101
1102 static int
1103 match_string_literal ()
1104 {
1105 char *tokptr = lexptr;
1106
1107 for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
1108 {
1109 CHECKBUF (1);
1110 if (*tokptr == *lexptr)
1111 {
1112 if (*(tokptr + 1) == *lexptr)
1113 {
1114 tokptr++;
1115 }
1116 else
1117 {
1118 break;
1119 }
1120 }
1121 tempbuf[tempbufindex++] = *tokptr;
1122 }
1123 if (*tokptr == '\0' /* no terminator */
1124 || (tempbufindex == 1 && *tokptr == '\'')) /* char literal */
1125 {
1126 return (0);
1127 }
1128 else
1129 {
1130 tempbuf[tempbufindex] = '\0';
1131 yylval.sval.ptr = tempbuf;
1132 yylval.sval.length = tempbufindex;
1133 lexptr = ++tokptr;
1134 return (CHARACTER_STRING_LITERAL);
1135 }
1136 }
1137
1138 /* Recognize a character literal. A character literal is single character
1139 or a control sequence, enclosed in single quotes. A control sequence
1140 is a comma separated list of one or more integer literals, enclosed
1141 in parenthesis and introduced with a circumflex character.
1142
1143 EX: 'a' '^(7)' '^(7,8)'
1144
1145 As a GNU chill extension, the syntax C'xx' is also recognized as a
1146 character literal, where xx is a hex value for the character.
1147
1148 Note that more than a single character, enclosed in single quotes, is
1149 a string literal.
1150
1151 Also note that the control sequence form is not in GNU Chill since it
1152 is ambiguous with the string literal form using single quotes. I.E.
1153 is '^(7)' a character literal or a string literal. In theory it it
1154 possible to tell by context, but GNU Chill doesn't accept the control
1155 sequence form, so neither do we (for now the code is disabled).
1156
1157 Returns CHARACTER_LITERAL if a match is found.
1158 */
1159
1160 static int
1161 match_character_literal ()
1162 {
1163 char *tokptr = lexptr;
1164 int ival = 0;
1165
1166 if ((*tokptr == 'c' || *tokptr == 'C') && (*(tokptr + 1) == '\''))
1167 {
1168 /* We have a GNU chill extension form, so skip the leading "C'",
1169 decode the hex value, and then ensure that we have a trailing
1170 single quote character. */
1171 tokptr += 2;
1172 if (!decode_integer_value (16, &tokptr, &ival) || (*tokptr != '\''))
1173 {
1174 return (0);
1175 }
1176 tokptr++;
1177 }
1178 else if (*tokptr == '\'')
1179 {
1180 tokptr++;
1181
1182 /* Determine which form we have, either a control sequence or the
1183 single character form. */
1184
1185 if ((*tokptr == '^') && (*(tokptr + 1) == '('))
1186 {
1187 #if 0 /* Disable, see note above. -fnf */
1188 /* Match and decode a control sequence. Return zero if we don't
1189 find a valid integer literal, or if the next unconsumed character
1190 after the integer literal is not the trailing ')'.
1191 FIXME: We currently don't handle the multiple integer literal
1192 form. */
1193 tokptr += 2;
1194 if (!decode_integer_literal (&ival, &tokptr) || (*tokptr++ != ')'))
1195 {
1196 return (0);
1197 }
1198 #else
1199 return (0);
1200 #endif
1201 }
1202 else
1203 {
1204 ival = *tokptr++;
1205 }
1206
1207 /* The trailing quote has not yet been consumed. If we don't find
1208 it, then we have no match. */
1209
1210 if (*tokptr++ != '\'')
1211 {
1212 return (0);
1213 }
1214 }
1215 else
1216 {
1217 /* Not a character literal. */
1218 return (0);
1219 }
1220 yylval.typed_val.val = ival;
1221 yylval.typed_val.type = builtin_type_chill_char;
1222 lexptr = tokptr;
1223 return (CHARACTER_LITERAL);
1224 }
1225
1226 /* Recognize an integer literal, as specified in Z.200 sec 5.2.4.2.
1227 Note that according to 5.2.4.2, a single "_" is also a valid integer
1228 literal, however GNU-chill requires there to be at least one "digit"
1229 in any integer literal. */
1230
1231 static int
1232 match_integer_literal ()
1233 {
1234 char *tokptr = lexptr;
1235 int ival;
1236
1237 if (!decode_integer_literal (&ival, &tokptr))
1238 {
1239 return (0);
1240 }
1241 else
1242 {
1243 yylval.typed_val.val = ival;
1244 yylval.typed_val.type = builtin_type_int;
1245 lexptr = tokptr;
1246 return (INTEGER_LITERAL);
1247 }
1248 }
1249
1250 /* Recognize a bit-string literal, as specified in Z.200 sec 5.2.4.8
1251 Note that according to 5.2.4.8, a single "_" is also a valid bit-string
1252 literal, however GNU-chill requires there to be at least one "digit"
1253 in any bit-string literal. */
1254
1255 static int
1256 match_bitstring_literal ()
1257 {
1258 register char *tokptr = lexptr;
1259 int bitoffset = 0;
1260 int bitcount = 0;
1261 int bits_per_char;
1262 int digit;
1263
1264 tempbufindex = 0;
1265 CHECKBUF (1);
1266 tempbuf[0] = 0;
1267
1268 /* Look for the required explicit base specifier. */
1269
1270 switch (*tokptr++)
1271 {
1272 case 'b':
1273 case 'B':
1274 bits_per_char = 1;
1275 break;
1276 case 'o':
1277 case 'O':
1278 bits_per_char = 3;
1279 break;
1280 case 'h':
1281 case 'H':
1282 bits_per_char = 4;
1283 break;
1284 default:
1285 return (0);
1286 break;
1287 }
1288
1289 /* Ensure that the character after the explicit base is a single quote. */
1290
1291 if (*tokptr++ != '\'')
1292 {
1293 return (0);
1294 }
1295
1296 while (*tokptr != '\0' && *tokptr != '\'')
1297 {
1298 digit = *tokptr;
1299 if (isupper (digit))
1300 digit = tolower (digit);
1301 tokptr++;
1302 switch (digit)
1303 {
1304 case '_':
1305 continue;
1306 case '0': case '1': case '2': case '3': case '4':
1307 case '5': case '6': case '7': case '8': case '9':
1308 digit -= '0';
1309 break;
1310 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
1311 digit -= 'a';
1312 digit += 10;
1313 break;
1314 default:
1315 return (0);
1316 break;
1317 }
1318 if (digit >= 1 << bits_per_char)
1319 {
1320 /* Found something not in domain for current base. */
1321 return (0);
1322 }
1323 else
1324 {
1325 /* Extract bits from digit, packing them into the bitstring byte. */
1326 int k = TARGET_BYTE_ORDER == BIG_ENDIAN ? bits_per_char - 1 : 0;
1327 for (; TARGET_BYTE_ORDER == BIG_ENDIAN ? k >= 0 : k < bits_per_char;
1328 TARGET_BYTE_ORDER == BIG_ENDIAN ? k-- : k++)
1329 {
1330 bitcount++;
1331 if (digit & (1 << k))
1332 {
1333 tempbuf[tempbufindex] |=
1334 (TARGET_BYTE_ORDER == BIG_ENDIAN)
1335 ? (1 << (HOST_CHAR_BIT - 1 - bitoffset))
1336 : (1 << bitoffset);
1337 }
1338 bitoffset++;
1339 if (bitoffset == HOST_CHAR_BIT)
1340 {
1341 bitoffset = 0;
1342 tempbufindex++;
1343 CHECKBUF(1);
1344 tempbuf[tempbufindex] = 0;
1345 }
1346 }
1347 }
1348 }
1349
1350 /* Verify that we consumed everything up to the trailing single quote,
1351 and that we found some bits (IE not just underbars). */
1352
1353 if (*tokptr++ != '\'')
1354 {
1355 return (0);
1356 }
1357 else
1358 {
1359 yylval.sval.ptr = tempbuf;
1360 yylval.sval.length = bitcount;
1361 lexptr = tokptr;
1362 return (BIT_STRING_LITERAL);
1363 }
1364 }
1365
1366 struct token
1367 {
1368 char *operator;
1369 int token;
1370 };
1371
1372 static const struct token idtokentab[] =
1373 {
1374 { "array", ARRAY },
1375 { "length", LENGTH },
1376 { "lower", LOWER },
1377 { "upper", UPPER },
1378 { "andif", ANDIF },
1379 { "pred", PRED },
1380 { "succ", SUCC },
1381 { "card", CARD },
1382 { "size", SIZE },
1383 { "orif", ORIF },
1384 { "num", NUM },
1385 { "abs", ABS },
1386 { "max", MAX_TOKEN },
1387 { "min", MIN_TOKEN },
1388 { "mod", MOD },
1389 { "rem", REM },
1390 { "not", NOT },
1391 { "xor", LOGXOR },
1392 { "and", LOGAND },
1393 { "in", IN },
1394 { "or", LOGIOR },
1395 { "up", UP },
1396 { "addr", ADDR_TOKEN },
1397 { "null", EMPTINESS_LITERAL }
1398 };
1399
1400 static const struct token tokentab2[] =
1401 {
1402 { ":=", GDB_ASSIGNMENT },
1403 { "//", SLASH_SLASH },
1404 { "->", POINTER },
1405 { "/=", NOTEQUAL },
1406 { "<=", LEQ },
1407 { ">=", GTR }
1408 };
1409
1410 /* Read one token, getting characters through lexptr. */
1411 /* This is where we will check to make sure that the language and the
1412 operators used are compatible. */
1413
1414 static int
1415 yylex ()
1416 {
1417 unsigned int i;
1418 int token;
1419 char *inputname;
1420 struct symbol *sym;
1421
1422 /* Skip over any leading whitespace. */
1423 while (isspace (*lexptr))
1424 {
1425 lexptr++;
1426 }
1427 /* Look for special single character cases which can't be the first
1428 character of some other multicharacter token. */
1429 switch (*lexptr)
1430 {
1431 case '\0':
1432 return (0);
1433 case ',':
1434 case '=':
1435 case ';':
1436 case '!':
1437 case '+':
1438 case '*':
1439 case '(':
1440 case ')':
1441 case '[':
1442 case ']':
1443 return (*lexptr++);
1444 }
1445 /* Look for characters which start a particular kind of multicharacter
1446 token, such as a character literal, register name, convenience
1447 variable name, string literal, etc. */
1448 switch (*lexptr)
1449 {
1450 case '\'':
1451 case '\"':
1452 /* First try to match a string literal, which is any
1453 sequence of characters enclosed in matching single or double
1454 quotes, except that a single character inside single quotes
1455 is a character literal, so we have to catch that case also. */
1456 token = match_string_literal ();
1457 if (token != 0)
1458 {
1459 return (token);
1460 }
1461 if (*lexptr == '\'')
1462 {
1463 token = match_character_literal ();
1464 if (token != 0)
1465 {
1466 return (token);
1467 }
1468 }
1469 break;
1470 case 'C':
1471 case 'c':
1472 token = match_character_literal ();
1473 if (token != 0)
1474 {
1475 return (token);
1476 }
1477 break;
1478 case '$':
1479 yylval.sval.ptr = lexptr;
1480 do {
1481 lexptr++;
1482 } while (isalnum (*lexptr) || (lexptr == '_'));
1483 yylval.sval.length = lexptr - yylval.sval.ptr;
1484 write_dollar_variable (yylval.sval);
1485 return GDB_VARIABLE;
1486 break;
1487 }
1488 /* See if it is a special token of length 2. */
1489 for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
1490 {
1491 if (STREQN (lexptr, tokentab2[i].operator, 2))
1492 {
1493 lexptr += 2;
1494 return (tokentab2[i].token);
1495 }
1496 }
1497 /* Look for single character cases which which could be the first
1498 character of some other multicharacter token, but aren't, or we
1499 would already have found it. */
1500 switch (*lexptr)
1501 {
1502 case '-':
1503 case ':':
1504 case '/':
1505 case '<':
1506 case '>':
1507 return (*lexptr++);
1508 }
1509 /* Look for a float literal before looking for an integer literal, so
1510 we match as much of the input stream as possible. */
1511 token = match_float_literal ();
1512 if (token != 0)
1513 {
1514 return (token);
1515 }
1516 token = match_bitstring_literal ();
1517 if (token != 0)
1518 {
1519 return (token);
1520 }
1521 token = match_integer_literal ();
1522 if (token != 0)
1523 {
1524 return (token);
1525 }
1526
1527 /* Try to match a simple name string, and if a match is found, then
1528 further classify what sort of name it is and return an appropriate
1529 token. Note that attempting to match a simple name string consumes
1530 the token from lexptr, so we can't back out if we later find that
1531 we can't classify what sort of name it is. */
1532
1533 inputname = match_simple_name_string ();
1534
1535 if (inputname != NULL)
1536 {
1537 char *simplename = (char*) alloca (strlen (inputname) + 1);
1538
1539 char *dptr = simplename, *sptr = inputname;
1540 for (; *sptr; sptr++)
1541 *dptr++ = isupper (*sptr) ? tolower(*sptr) : *sptr;
1542 *dptr = '\0';
1543
1544 /* See if it is a reserved identifier. */
1545 for (i = 0; i < sizeof (idtokentab) / sizeof (idtokentab[0]); i++)
1546 {
1547 if (STREQ (simplename, idtokentab[i].operator))
1548 {
1549 return (idtokentab[i].token);
1550 }
1551 }
1552
1553 /* Look for other special tokens. */
1554 if (STREQ (simplename, "true"))
1555 {
1556 yylval.ulval = 1;
1557 return (BOOLEAN_LITERAL);
1558 }
1559 if (STREQ (simplename, "false"))
1560 {
1561 yylval.ulval = 0;
1562 return (BOOLEAN_LITERAL);
1563 }
1564
1565 sym = lookup_symbol (inputname, expression_context_block,
1566 VAR_NAMESPACE, (int *) NULL,
1567 (struct symtab **) NULL);
1568 if (sym == NULL && strcmp (inputname, simplename) != 0)
1569 {
1570 sym = lookup_symbol (simplename, expression_context_block,
1571 VAR_NAMESPACE, (int *) NULL,
1572 (struct symtab **) NULL);
1573 }
1574 if (sym != NULL)
1575 {
1576 yylval.ssym.stoken.ptr = NULL;
1577 yylval.ssym.stoken.length = 0;
1578 yylval.ssym.sym = sym;
1579 yylval.ssym.is_a_field_of_this = 0; /* FIXME, C++'ism */
1580 switch (SYMBOL_CLASS (sym))
1581 {
1582 case LOC_BLOCK:
1583 /* Found a procedure name. */
1584 return (GENERAL_PROCEDURE_NAME);
1585 case LOC_STATIC:
1586 /* Found a global or local static variable. */
1587 return (LOCATION_NAME);
1588 case LOC_REGISTER:
1589 case LOC_ARG:
1590 case LOC_REF_ARG:
1591 case LOC_REGPARM:
1592 case LOC_REGPARM_ADDR:
1593 case LOC_LOCAL:
1594 case LOC_LOCAL_ARG:
1595 case LOC_BASEREG:
1596 case LOC_BASEREG_ARG:
1597 if (innermost_block == NULL
1598 || contained_in (block_found, innermost_block))
1599 {
1600 innermost_block = block_found;
1601 }
1602 return (LOCATION_NAME);
1603 break;
1604 case LOC_CONST:
1605 case LOC_LABEL:
1606 return (LOCATION_NAME);
1607 break;
1608 case LOC_TYPEDEF:
1609 yylval.tsym.type = SYMBOL_TYPE (sym);
1610 return TYPENAME;
1611 case LOC_UNDEF:
1612 case LOC_CONST_BYTES:
1613 case LOC_OPTIMIZED_OUT:
1614 error ("Symbol \"%s\" names no location.", inputname);
1615 break;
1616 }
1617 }
1618 else if (!have_full_symbols () && !have_partial_symbols ())
1619 {
1620 error ("No symbol table is loaded. Use the \"file\" command.");
1621 }
1622 else
1623 {
1624 error ("No symbol \"%s\" in current context.", inputname);
1625 }
1626 }
1627
1628 /* Catch single character tokens which are not part of some
1629 longer token. */
1630
1631 switch (*lexptr)
1632 {
1633 case '.': /* Not float for example. */
1634 lexptr++;
1635 while (isspace (*lexptr)) lexptr++;
1636 inputname = match_simple_name_string ();
1637 if (!inputname)
1638 return '.';
1639 return FIELD_NAME;
1640 }
1641
1642 return (ILLEGAL_TOKEN);
1643 }
1644
1645 static void
1646 write_lower_upper_value (opcode, type)
1647 enum exp_opcode opcode; /* Either UNOP_LOWER or UNOP_UPPER */
1648 struct type *type;
1649 {
1650 extern LONGEST type_lower_upper ();
1651 struct type *result_type;
1652 LONGEST val = type_lower_upper (opcode, type, &result_type);
1653 write_exp_elt_opcode (OP_LONG);
1654 write_exp_elt_type (result_type);
1655 write_exp_elt_longcst (val);
1656 write_exp_elt_opcode (OP_LONG);
1657 }
1658
1659 void
1660 yyerror (msg)
1661 char *msg;
1662 {
1663 error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
1664 }
This page took 0.063595 seconds and 4 git commands to generate.