Preparation for gdb-4.1 release.
[binutils-gdb.git] / gdb / c-exp.y
1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* Parse a C 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 %{
30
31 #include <stdio.h>
32 #include <string.h>
33 #include "defs.h"
34 #include "param.h"
35 #include "symtab.h"
36 #include "frame.h"
37 #include "expression.h"
38 #include "parser-defs.h"
39 #include "value.h"
40 #include "language.h"
41
42 /* These MUST be included in any grammar file!!!!
43 Please choose unique names! */
44 #define yyparse c_parse
45 #define yylex c_lex
46 #define yyerror c_error
47 #define yylval c_lval
48 #define yychar c_char
49 #define yydebug c_debug
50 #define yypact c_pact
51 #define yyr1 c_r1
52 #define yyr2 c_r2
53 #define yydef c_def
54 #define yychk c_chk
55 #define yypgo c_pgo
56 #define yyact c_act
57 #define yyexca c_exca
58
59 /* Forward decls */
60 void yyerror ();
61 static int parse_number ();
62 int yyparse ();
63
64 /* #define YYDEBUG 1 */
65
66 %}
67
68 /* Although the yacc "value" of an expression is not used,
69 since the result is stored in the structure being created,
70 other node types do have values. */
71
72 %union
73 {
74 LONGEST lval;
75 unsigned LONGEST ulval;
76 double dval;
77 struct symbol *sym;
78 struct type *tval;
79 struct stoken sval;
80 struct ttype tsym;
81 struct symtoken ssym;
82 int voidval;
83 struct block *bval;
84 enum exp_opcode opcode;
85 struct internalvar *ivar;
86
87 struct type **tvec;
88 int *ivec;
89 }
90
91 %type <voidval> exp exp1 type_exp start variable
92 %type <tval> type typebase
93 %type <tvec> nonempty_typelist
94 /* %type <bval> block */
95
96 /* Fancy type parsing. */
97 %type <voidval> func_mod direct_abs_decl abs_decl
98 %type <tval> ptype
99 %type <lval> array_mod
100
101 %token <lval> INT CHAR
102 %token <ulval> UINT
103 %token <dval> FLOAT
104
105 /* Both NAME and TYPENAME tokens represent symbols in the input,
106 and both convey their data as strings.
107 But a TYPENAME is a string that happens to be defined as a typedef
108 or builtin type name (such as int or char)
109 and a NAME is any other symbol.
110 Contexts where this distinction is not important can use the
111 nonterminal "name", which matches either NAME or TYPENAME. */
112
113 %token <sval> STRING
114 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
115 %token <tsym> TYPENAME
116 %type <sval> name
117 %type <ssym> name_not_typename
118 %type <tsym> typename
119
120 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
121 but which would parse as a valid number in the current input radix.
122 E.g. "c" when input_radix==16. Depending on the parse, it will be
123 turned into a name or into a number. NAME_OR_UINT ditto. */
124
125 %token <ssym> NAME_OR_INT NAME_OR_UINT
126
127 %token STRUCT UNION ENUM SIZEOF UNSIGNED COLONCOLON
128 %token ERROR
129
130 /* Special type cases, put in to allow the parser to distinguish different
131 legal basetypes. */
132 %token SIGNED LONG SHORT INT_KEYWORD
133
134 %token <lval> LAST REGNAME
135
136 %token <ivar> VARIABLE
137
138 %token <opcode> ASSIGN_MODIFY
139
140 /* C++ */
141 %token THIS
142
143 %left ','
144 %left ABOVE_COMMA
145 %right '=' ASSIGN_MODIFY
146 %right '?'
147 %left OR
148 %left AND
149 %left '|'
150 %left '^'
151 %left '&'
152 %left EQUAL NOTEQUAL
153 %left '<' '>' LEQ GEQ
154 %left LSH RSH
155 %left '@'
156 %left '+' '-'
157 %left '*' '/' '%'
158 %right UNARY INCREMENT DECREMENT
159 %right ARROW '.' '[' '('
160 %token <ssym> BLOCKNAME
161 %type <bval> block
162 %left COLONCOLON
163 \f
164 %%
165
166 start : exp1
167 | type_exp
168 ;
169
170 type_exp: type
171 { write_exp_elt_opcode(OP_TYPE);
172 write_exp_elt_type($1);
173 write_exp_elt_opcode(OP_TYPE);}
174 ;
175
176 /* Expressions, including the comma operator. */
177 exp1 : exp
178 | exp1 ',' exp
179 { write_exp_elt_opcode (BINOP_COMMA); }
180 ;
181
182 /* Expressions, not including the comma operator. */
183 exp : '*' exp %prec UNARY
184 { write_exp_elt_opcode (UNOP_IND); }
185
186 exp : '&' exp %prec UNARY
187 { write_exp_elt_opcode (UNOP_ADDR); }
188
189 exp : '-' exp %prec UNARY
190 { write_exp_elt_opcode (UNOP_NEG); }
191 ;
192
193 exp : '!' exp %prec UNARY
194 { write_exp_elt_opcode (UNOP_ZEROP); }
195 ;
196
197 exp : '~' exp %prec UNARY
198 { write_exp_elt_opcode (UNOP_LOGNOT); }
199 ;
200
201 exp : INCREMENT exp %prec UNARY
202 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
203 ;
204
205 exp : DECREMENT exp %prec UNARY
206 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
207 ;
208
209 exp : exp INCREMENT %prec UNARY
210 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
211 ;
212
213 exp : exp DECREMENT %prec UNARY
214 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
215 ;
216
217 exp : SIZEOF exp %prec UNARY
218 { write_exp_elt_opcode (UNOP_SIZEOF); }
219 ;
220
221 exp : exp ARROW name
222 { write_exp_elt_opcode (STRUCTOP_PTR);
223 write_exp_string ($3);
224 write_exp_elt_opcode (STRUCTOP_PTR); }
225 ;
226
227 exp : exp ARROW '*' exp
228 { write_exp_elt_opcode (STRUCTOP_MPTR); }
229 ;
230
231 exp : exp '.' name
232 { write_exp_elt_opcode (STRUCTOP_STRUCT);
233 write_exp_string ($3);
234 write_exp_elt_opcode (STRUCTOP_STRUCT); }
235 ;
236
237 exp : exp '.' '*' exp
238 { write_exp_elt_opcode (STRUCTOP_MEMBER); }
239 ;
240
241 exp : exp '[' exp1 ']'
242 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
243 ;
244
245 exp : exp '('
246 /* This is to save the value of arglist_len
247 being accumulated by an outer function call. */
248 { start_arglist (); }
249 arglist ')' %prec ARROW
250 { write_exp_elt_opcode (OP_FUNCALL);
251 write_exp_elt_longcst ((LONGEST) end_arglist ());
252 write_exp_elt_opcode (OP_FUNCALL); }
253 ;
254
255 arglist :
256 ;
257
258 arglist : exp
259 { arglist_len = 1; }
260 ;
261
262 arglist : arglist ',' exp %prec ABOVE_COMMA
263 { arglist_len++; }
264 ;
265
266 exp : '{' type '}' exp %prec UNARY
267 { write_exp_elt_opcode (UNOP_MEMVAL);
268 write_exp_elt_type ($2);
269 write_exp_elt_opcode (UNOP_MEMVAL); }
270 ;
271
272 exp : '(' type ')' exp %prec UNARY
273 { write_exp_elt_opcode (UNOP_CAST);
274 write_exp_elt_type ($2);
275 write_exp_elt_opcode (UNOP_CAST); }
276 ;
277
278 exp : '(' exp1 ')'
279 { }
280 ;
281
282 /* Binary operators in order of decreasing precedence. */
283
284 exp : exp '@' exp
285 { write_exp_elt_opcode (BINOP_REPEAT); }
286 ;
287
288 exp : exp '*' exp
289 { write_exp_elt_opcode (BINOP_MUL); }
290 ;
291
292 exp : exp '/' exp
293 { write_exp_elt_opcode (BINOP_DIV); }
294 ;
295
296 exp : exp '%' exp
297 { write_exp_elt_opcode (BINOP_REM); }
298 ;
299
300 exp : exp '+' exp
301 { write_exp_elt_opcode (BINOP_ADD); }
302 ;
303
304 exp : exp '-' exp
305 { write_exp_elt_opcode (BINOP_SUB); }
306 ;
307
308 exp : exp LSH exp
309 { write_exp_elt_opcode (BINOP_LSH); }
310 ;
311
312 exp : exp RSH exp
313 { write_exp_elt_opcode (BINOP_RSH); }
314 ;
315
316 exp : exp EQUAL exp
317 { write_exp_elt_opcode (BINOP_EQUAL); }
318 ;
319
320 exp : exp NOTEQUAL exp
321 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
322 ;
323
324 exp : exp LEQ exp
325 { write_exp_elt_opcode (BINOP_LEQ); }
326 ;
327
328 exp : exp GEQ exp
329 { write_exp_elt_opcode (BINOP_GEQ); }
330 ;
331
332 exp : exp '<' exp
333 { write_exp_elt_opcode (BINOP_LESS); }
334 ;
335
336 exp : exp '>' exp
337 { write_exp_elt_opcode (BINOP_GTR); }
338 ;
339
340 exp : exp '&' exp
341 { write_exp_elt_opcode (BINOP_LOGAND); }
342 ;
343
344 exp : exp '^' exp
345 { write_exp_elt_opcode (BINOP_LOGXOR); }
346 ;
347
348 exp : exp '|' exp
349 { write_exp_elt_opcode (BINOP_LOGIOR); }
350 ;
351
352 exp : exp AND exp
353 { write_exp_elt_opcode (BINOP_AND); }
354 ;
355
356 exp : exp OR exp
357 { write_exp_elt_opcode (BINOP_OR); }
358 ;
359
360 exp : exp '?' exp ':' exp %prec '?'
361 { write_exp_elt_opcode (TERNOP_COND); }
362 ;
363
364 exp : exp '=' exp
365 { write_exp_elt_opcode (BINOP_ASSIGN); }
366 ;
367
368 exp : exp ASSIGN_MODIFY exp
369 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
370 write_exp_elt_opcode ($2);
371 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
372 ;
373
374 exp : INT
375 { write_exp_elt_opcode (OP_LONG);
376 if ($1 == (int) $1 || $1 == (unsigned int) $1)
377 write_exp_elt_type (builtin_type_int);
378 else
379 write_exp_elt_type (BUILTIN_TYPE_LONGEST);
380 write_exp_elt_longcst ((LONGEST) $1);
381 write_exp_elt_opcode (OP_LONG); }
382 ;
383
384 exp : NAME_OR_INT
385 { YYSTYPE val;
386 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
387 write_exp_elt_opcode (OP_LONG);
388 if (val.lval == (int) val.lval ||
389 val.lval == (unsigned int) val.lval)
390 write_exp_elt_type (builtin_type_int);
391 else
392 write_exp_elt_type (BUILTIN_TYPE_LONGEST);
393 write_exp_elt_longcst (val.lval);
394 write_exp_elt_opcode (OP_LONG); }
395 ;
396
397 exp : UINT
398 {
399 write_exp_elt_opcode (OP_LONG);
400 if ($1 == (unsigned int) $1)
401 write_exp_elt_type (builtin_type_unsigned_int);
402 else
403 write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST);
404 write_exp_elt_longcst ((LONGEST) $1);
405 write_exp_elt_opcode (OP_LONG);
406 }
407 ;
408
409 exp : NAME_OR_UINT
410 { YYSTYPE val;
411 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
412 write_exp_elt_opcode (OP_LONG);
413 if (val.ulval == (unsigned int) val.ulval)
414 write_exp_elt_type (builtin_type_unsigned_int);
415 else
416 write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST);
417 write_exp_elt_longcst ((LONGEST)val.ulval);
418 write_exp_elt_opcode (OP_LONG);
419 }
420 ;
421
422 exp : CHAR
423 { write_exp_elt_opcode (OP_LONG);
424 write_exp_elt_type (builtin_type_char);
425 write_exp_elt_longcst ((LONGEST) $1);
426 write_exp_elt_opcode (OP_LONG); }
427 ;
428
429 exp : FLOAT
430 { write_exp_elt_opcode (OP_DOUBLE);
431 write_exp_elt_type (builtin_type_double);
432 write_exp_elt_dblcst ($1);
433 write_exp_elt_opcode (OP_DOUBLE); }
434 ;
435
436 exp : variable
437 ;
438
439 exp : LAST
440 { write_exp_elt_opcode (OP_LAST);
441 write_exp_elt_longcst ((LONGEST) $1);
442 write_exp_elt_opcode (OP_LAST); }
443 ;
444
445 exp : REGNAME
446 { write_exp_elt_opcode (OP_REGISTER);
447 write_exp_elt_longcst ((LONGEST) $1);
448 write_exp_elt_opcode (OP_REGISTER); }
449 ;
450
451 exp : VARIABLE
452 { write_exp_elt_opcode (OP_INTERNALVAR);
453 write_exp_elt_intern ($1);
454 write_exp_elt_opcode (OP_INTERNALVAR); }
455 ;
456
457 exp : SIZEOF '(' type ')' %prec UNARY
458 { write_exp_elt_opcode (OP_LONG);
459 write_exp_elt_type (builtin_type_int);
460 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
461 write_exp_elt_opcode (OP_LONG); }
462 ;
463
464 exp : STRING
465 { write_exp_elt_opcode (OP_STRING);
466 write_exp_string ($1);
467 write_exp_elt_opcode (OP_STRING); }
468 ;
469
470 /* C++. */
471 exp : THIS
472 { write_exp_elt_opcode (OP_THIS);
473 write_exp_elt_opcode (OP_THIS); }
474 ;
475
476 /* end of C++. */
477
478 block : BLOCKNAME
479 {
480 if ($1.sym != 0)
481 $$ = SYMBOL_BLOCK_VALUE ($1.sym);
482 else
483 {
484 struct symtab *tem =
485 lookup_symtab (copy_name ($1.stoken));
486 if (tem)
487 $$ = BLOCKVECTOR_BLOCK
488 (BLOCKVECTOR (tem), STATIC_BLOCK);
489 else
490 error ("No file or function \"%s\".",
491 copy_name ($1.stoken));
492 }
493 }
494 ;
495
496 block : block COLONCOLON name
497 { struct symbol *tem
498 = lookup_symbol (copy_name ($3), $1,
499 VAR_NAMESPACE, 0, NULL);
500 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
501 error ("No function \"%s\" in specified context.",
502 copy_name ($3));
503 $$ = SYMBOL_BLOCK_VALUE (tem); }
504 ;
505
506 variable: block COLONCOLON name
507 { struct symbol *sym;
508 sym = lookup_symbol (copy_name ($3), $1,
509 VAR_NAMESPACE, 0, NULL);
510 if (sym == 0)
511 error ("No symbol \"%s\" in specified context.",
512 copy_name ($3));
513
514 write_exp_elt_opcode (OP_VAR_VALUE);
515 write_exp_elt_sym (sym);
516 write_exp_elt_opcode (OP_VAR_VALUE); }
517 ;
518
519 variable: typebase COLONCOLON name
520 {
521 struct type *type = $1;
522 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
523 && TYPE_CODE (type) != TYPE_CODE_UNION)
524 error ("`%s' is not defined as an aggregate type.",
525 TYPE_NAME (type));
526
527 write_exp_elt_opcode (OP_SCOPE);
528 write_exp_elt_type (type);
529 write_exp_string ($3);
530 write_exp_elt_opcode (OP_SCOPE);
531 }
532 | typebase COLONCOLON '~' name
533 {
534 struct type *type = $1;
535 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
536 && TYPE_CODE (type) != TYPE_CODE_UNION)
537 error ("`%s' is not defined as an aggregate type.",
538 TYPE_NAME (type));
539
540 if (strcmp (type_name_no_tag (type), $4.ptr))
541 error ("invalid destructor `%s::~%s'",
542 type_name_no_tag (type), $4.ptr);
543
544 write_exp_elt_opcode (OP_SCOPE);
545 write_exp_elt_type (type);
546 write_exp_string ($4);
547 write_exp_elt_opcode (OP_SCOPE);
548 write_exp_elt_opcode (UNOP_LOGNOT);
549 }
550 | COLONCOLON name
551 {
552 char *name = copy_name ($2);
553 struct symbol *sym;
554 int i;
555
556 sym =
557 lookup_symbol (name, 0, VAR_NAMESPACE, 0, NULL);
558 if (sym)
559 {
560 write_exp_elt_opcode (OP_VAR_VALUE);
561 write_exp_elt_sym (sym);
562 write_exp_elt_opcode (OP_VAR_VALUE);
563 break;
564 }
565 for (i = 0; i < misc_function_count; i++)
566 if (!strcmp (misc_function_vector[i].name, name))
567 break;
568
569 if (i < misc_function_count)
570 {
571 enum misc_function_type mft =
572 misc_function_vector[i].type;
573
574 write_exp_elt_opcode (OP_LONG);
575 write_exp_elt_type (builtin_type_int);
576 write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
577 write_exp_elt_opcode (OP_LONG);
578 write_exp_elt_opcode (UNOP_MEMVAL);
579 if (mft == mf_data || mft == mf_bss)
580 write_exp_elt_type (builtin_type_int);
581 else if (mft == mf_text)
582 write_exp_elt_type (lookup_function_type (builtin_type_int));
583 else
584 write_exp_elt_type (builtin_type_char);
585 write_exp_elt_opcode (UNOP_MEMVAL);
586 }
587 else
588 if (symtab_list == 0
589 && partial_symtab_list == 0)
590 error ("No symbol table is loaded. Use the \"file\" command.");
591 else
592 error ("No symbol \"%s\" in current context.", name);
593 }
594 ;
595
596 variable: name_not_typename
597 { struct symbol *sym = $1.sym;
598
599 if (sym)
600 {
601 switch (sym->class)
602 {
603 case LOC_REGISTER:
604 case LOC_ARG:
605 case LOC_REF_ARG:
606 case LOC_REGPARM:
607 case LOC_LOCAL:
608 case LOC_LOCAL_ARG:
609 if (innermost_block == 0 ||
610 contained_in (block_found,
611 innermost_block))
612 innermost_block = block_found;
613 case LOC_UNDEF:
614 case LOC_CONST:
615 case LOC_STATIC:
616 case LOC_TYPEDEF:
617 case LOC_LABEL:
618 case LOC_BLOCK:
619 case LOC_CONST_BYTES:
620
621 /* In this case the expression can
622 be evaluated regardless of what
623 frame we are in, so there is no
624 need to check for the
625 innermost_block. These cases are
626 listed so that gcc -Wall will
627 report types that may not have
628 been considered. */
629
630 break;
631 }
632 write_exp_elt_opcode (OP_VAR_VALUE);
633 write_exp_elt_sym (sym);
634 write_exp_elt_opcode (OP_VAR_VALUE);
635 }
636 else if ($1.is_a_field_of_this)
637 {
638 /* C++: it hangs off of `this'. Must
639 not inadvertently convert from a method call
640 to data ref. */
641 if (innermost_block == 0 ||
642 contained_in (block_found, innermost_block))
643 innermost_block = block_found;
644 write_exp_elt_opcode (OP_THIS);
645 write_exp_elt_opcode (OP_THIS);
646 write_exp_elt_opcode (STRUCTOP_PTR);
647 write_exp_string ($1.stoken);
648 write_exp_elt_opcode (STRUCTOP_PTR);
649 }
650 else
651 {
652 register int i;
653 register char *arg = copy_name ($1.stoken);
654
655 /* FIXME, this search is linear! At least
656 optimize the strcmp with a 1-char cmp... */
657 for (i = 0; i < misc_function_count; i++)
658 if (!strcmp (misc_function_vector[i].name, arg))
659 break;
660
661 if (i < misc_function_count)
662 {
663 enum misc_function_type mft =
664 misc_function_vector[i].type;
665
666 write_exp_elt_opcode (OP_LONG);
667 write_exp_elt_type (builtin_type_int);
668 write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
669 write_exp_elt_opcode (OP_LONG);
670 write_exp_elt_opcode (UNOP_MEMVAL);
671 if (mft == mf_data || mft == mf_bss)
672 write_exp_elt_type (builtin_type_int);
673 else if (mft == mf_text)
674 write_exp_elt_type (lookup_function_type (builtin_type_int));
675 else
676 write_exp_elt_type (builtin_type_char);
677 write_exp_elt_opcode (UNOP_MEMVAL);
678 }
679 else if (symtab_list == 0
680 && partial_symtab_list == 0)
681 error ("No symbol table is loaded. Use the \"file\" command.");
682 else
683 error ("No symbol \"%s\" in current context.",
684 copy_name ($1.stoken));
685 }
686 }
687 ;
688
689
690 ptype : typebase
691 | typebase abs_decl
692 {
693 /* This is where the interesting stuff happens. */
694 int done = 0;
695 int array_size;
696 struct type *follow_type = $1;
697
698 while (!done)
699 switch (pop_type ())
700 {
701 case tp_end:
702 done = 1;
703 break;
704 case tp_pointer:
705 follow_type = lookup_pointer_type (follow_type);
706 break;
707 case tp_reference:
708 follow_type = lookup_reference_type (follow_type);
709 break;
710 case tp_array:
711 array_size = pop_type_int ();
712 if (array_size != -1)
713 follow_type = create_array_type (follow_type,
714 array_size);
715 else
716 follow_type = lookup_pointer_type (follow_type);
717 break;
718 case tp_function:
719 follow_type = lookup_function_type (follow_type);
720 break;
721 }
722 $$ = follow_type;
723 }
724 ;
725
726 abs_decl: '*'
727 { push_type (tp_pointer); $$ = 0; }
728 | '*' abs_decl
729 { push_type (tp_pointer); $$ = $2; }
730 | '&'
731 { push_type (tp_reference); $$ = 0; }
732 | '&' abs_decl
733 { push_type (tp_reference); $$ = $2; }
734 | direct_abs_decl
735 ;
736
737 direct_abs_decl: '(' abs_decl ')'
738 { $$ = $2; }
739 | direct_abs_decl array_mod
740 {
741 push_type_int ($2);
742 push_type (tp_array);
743 }
744 | array_mod
745 {
746 push_type_int ($1);
747 push_type (tp_array);
748 $$ = 0;
749 }
750 | direct_abs_decl func_mod
751 { push_type (tp_function); }
752 | func_mod
753 { push_type (tp_function); }
754 ;
755
756 array_mod: '[' ']'
757 { $$ = -1; }
758 | '[' INT ']'
759 { $$ = $2; }
760 ;
761
762 func_mod: '(' ')'
763 { $$ = 0; }
764 ;
765
766 type : ptype
767 | typebase COLONCOLON '*'
768 { $$ = lookup_member_type (builtin_type_int, $1); }
769 | type '(' typebase COLONCOLON '*' ')'
770 { $$ = lookup_member_type ($1, $3); }
771 | type '(' typebase COLONCOLON '*' ')' '(' ')'
772 { $$ = lookup_member_type
773 (lookup_function_type ($1), $3); }
774 | type '(' typebase COLONCOLON '*' ')' '(' nonempty_typelist ')'
775 { $$ = lookup_member_type
776 (lookup_function_type ($1), $3);
777 free ($8); }
778 ;
779
780 typebase
781 : TYPENAME
782 { $$ = $1.type; }
783 | INT_KEYWORD
784 { $$ = builtin_type_int; }
785 | LONG
786 { $$ = builtin_type_long; }
787 | SHORT
788 { $$ = builtin_type_short; }
789 | LONG INT_KEYWORD
790 { $$ = builtin_type_long; }
791 | UNSIGNED LONG INT_KEYWORD
792 { $$ = builtin_type_unsigned_long; }
793 | LONG LONG
794 { $$ = builtin_type_long_long; }
795 | LONG LONG INT_KEYWORD
796 { $$ = builtin_type_long_long; }
797 | UNSIGNED LONG LONG
798 { $$ = builtin_type_unsigned_long_long; }
799 | UNSIGNED LONG LONG INT_KEYWORD
800 { $$ = builtin_type_unsigned_long_long; }
801 | SHORT INT_KEYWORD
802 { $$ = builtin_type_short; }
803 | UNSIGNED SHORT INT_KEYWORD
804 { $$ = builtin_type_unsigned_short; }
805 | STRUCT name
806 { $$ = lookup_struct (copy_name ($2),
807 expression_context_block); }
808 | UNION name
809 { $$ = lookup_union (copy_name ($2),
810 expression_context_block); }
811 | ENUM name
812 { $$ = lookup_enum (copy_name ($2),
813 expression_context_block); }
814 | UNSIGNED typename
815 { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
816 | UNSIGNED
817 { $$ = builtin_type_unsigned_int; }
818 | SIGNED typename
819 { $$ = $2.type; }
820 | SIGNED
821 { $$ = builtin_type_int; }
822 ;
823
824 typename: TYPENAME
825 | INT_KEYWORD
826 {
827 $$.stoken.ptr = "int";
828 $$.stoken.length = 3;
829 $$.type = builtin_type_int;
830 }
831 | LONG
832 {
833 $$.stoken.ptr = "long";
834 $$.stoken.length = 4;
835 $$.type = builtin_type_long;
836 }
837 | SHORT
838 {
839 $$.stoken.ptr = "short";
840 $$.stoken.length = 5;
841 $$.type = builtin_type_short;
842 }
843 ;
844
845 nonempty_typelist
846 : type
847 { $$ = (struct type **)xmalloc (sizeof (struct type *) * 2);
848 $$[0] = (struct type *)0;
849 $$[1] = $1;
850 }
851 | nonempty_typelist ',' type
852 { int len = sizeof (struct type *) * ++($<ivec>1[0]);
853 $$ = (struct type **)xrealloc ($1, len);
854 $$[$<ivec>$[0]] = $3;
855 }
856 ;
857
858 name : NAME { $$ = $1.stoken; }
859 | BLOCKNAME { $$ = $1.stoken; }
860 | TYPENAME { $$ = $1.stoken; }
861 | NAME_OR_INT { $$ = $1.stoken; }
862 | NAME_OR_UINT { $$ = $1.stoken; }
863 ;
864
865 name_not_typename : NAME
866 | BLOCKNAME
867 /* These would be useful if name_not_typename was useful, but it is just
868 a fake for "variable", so these cause reduce/reduce conflicts because
869 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
870 =exp) or just an exp. If name_not_typename was ever used in an lvalue
871 context where only a name could occur, this might be useful.
872 | NAME_OR_INT
873 | NAME_OR_UINT
874 */
875 ;
876
877 %%
878
879 /* Take care of parsing a number (anything that starts with a digit).
880 Set yylval and return the token type; update lexptr.
881 LEN is the number of characters in it. */
882
883 /*** Needs some error checking for the float case ***/
884
885 static int
886 parse_number (p, len, parsed_float, putithere)
887 register char *p;
888 register int len;
889 int parsed_float;
890 YYSTYPE *putithere;
891 {
892 register LONGEST n = 0;
893 register LONGEST prevn = 0;
894 register int i;
895 register int c;
896 register int base = input_radix;
897 int unsigned_p = 0;
898
899 extern double atof ();
900
901 if (parsed_float)
902 {
903 /* It's a float since it contains a point or an exponent. */
904 putithere->dval = atof (p);
905 return FLOAT;
906 }
907
908 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
909 if (p[0] == '0')
910 switch (p[1])
911 {
912 case 'x':
913 case 'X':
914 if (len >= 3)
915 {
916 p += 2;
917 base = 16;
918 len -= 2;
919 }
920 break;
921
922 case 't':
923 case 'T':
924 case 'd':
925 case 'D':
926 if (len >= 3)
927 {
928 p += 2;
929 base = 10;
930 len -= 2;
931 }
932 break;
933
934 default:
935 base = 8;
936 break;
937 }
938
939 while (len-- > 0)
940 {
941 c = *p++;
942 if (c >= 'A' && c <= 'Z')
943 c += 'a' - 'A';
944 if (c != 'l' && c != 'u')
945 n *= base;
946 if (c >= '0' && c <= '9')
947 n += i = c - '0';
948 else
949 {
950 if (base > 10 && c >= 'a' && c <= 'f')
951 n += i = c - 'a' + 10;
952 else if (len == 0 && c == 'l')
953 ;
954 else if (len == 0 && c == 'u')
955 unsigned_p = 1;
956 else
957 return ERROR; /* Char not a digit */
958 }
959 if (i >= base)
960 return ERROR; /* Invalid digit in this base */
961 if(!unsigned_p && (prevn >= n))
962 unsigned_p=1; /* Try something unsigned */
963 /* Don't do the range check if n==i and i==0, since that special
964 case will give an overflow error. */
965 if(RANGE_CHECK && n!=0)
966 {
967 if((unsigned_p && (unsigned)prevn >= (unsigned)n))
968 range_error("Overflow on numeric constant.");
969 }
970 prevn=n;
971 }
972
973 if (unsigned_p)
974 {
975 putithere->ulval = n;
976 return UINT;
977 }
978 else
979 {
980 putithere->lval = n;
981 return INT;
982 }
983 }
984
985 struct token
986 {
987 char *operator;
988 int token;
989 enum exp_opcode opcode;
990 };
991
992 const static struct token tokentab3[] =
993 {
994 {">>=", ASSIGN_MODIFY, BINOP_RSH},
995 {"<<=", ASSIGN_MODIFY, BINOP_LSH}
996 };
997
998 const static struct token tokentab2[] =
999 {
1000 {"+=", ASSIGN_MODIFY, BINOP_ADD},
1001 {"-=", ASSIGN_MODIFY, BINOP_SUB},
1002 {"*=", ASSIGN_MODIFY, BINOP_MUL},
1003 {"/=", ASSIGN_MODIFY, BINOP_DIV},
1004 {"%=", ASSIGN_MODIFY, BINOP_REM},
1005 {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
1006 {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
1007 {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
1008 {"++", INCREMENT, BINOP_END},
1009 {"--", DECREMENT, BINOP_END},
1010 {"->", ARROW, BINOP_END},
1011 {"&&", AND, BINOP_END},
1012 {"||", OR, BINOP_END},
1013 {"::", COLONCOLON, BINOP_END},
1014 {"<<", LSH, BINOP_END},
1015 {">>", RSH, BINOP_END},
1016 {"==", EQUAL, BINOP_END},
1017 {"!=", NOTEQUAL, BINOP_END},
1018 {"<=", LEQ, BINOP_END},
1019 {">=", GEQ, BINOP_END}
1020 };
1021
1022 /* Read one token, getting characters through lexptr. */
1023
1024 int
1025 yylex ()
1026 {
1027 register int c;
1028 register int namelen;
1029 register unsigned i;
1030 register char *tokstart;
1031
1032 retry:
1033
1034 tokstart = lexptr;
1035 /* See if it is a special token of length 3. */
1036 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
1037 if (!strncmp (tokstart, tokentab3[i].operator, 3))
1038 {
1039 lexptr += 3;
1040 yylval.opcode = tokentab3[i].opcode;
1041 return tokentab3[i].token;
1042 }
1043
1044 /* See if it is a special token of length 2. */
1045 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
1046 if (!strncmp (tokstart, tokentab2[i].operator, 2))
1047 {
1048 lexptr += 2;
1049 yylval.opcode = tokentab2[i].opcode;
1050 return tokentab2[i].token;
1051 }
1052
1053 switch (c = *tokstart)
1054 {
1055 case 0:
1056 return 0;
1057
1058 case ' ':
1059 case '\t':
1060 case '\n':
1061 lexptr++;
1062 goto retry;
1063
1064 case '\'':
1065 lexptr++;
1066 c = *lexptr++;
1067 if (c == '\\')
1068 c = parse_escape (&lexptr);
1069 yylval.lval = c;
1070 c = *lexptr++;
1071 if (c != '\'')
1072 error ("Invalid character constant.");
1073 return CHAR;
1074
1075 case '(':
1076 paren_depth++;
1077 lexptr++;
1078 return c;
1079
1080 case ')':
1081 if (paren_depth == 0)
1082 return 0;
1083 paren_depth--;
1084 lexptr++;
1085 return c;
1086
1087 case ',':
1088 if (comma_terminates && paren_depth == 0)
1089 return 0;
1090 lexptr++;
1091 return c;
1092
1093 case '.':
1094 /* Might be a floating point number. */
1095 if (lexptr[1] < '0' || lexptr[1] > '9')
1096 goto symbol; /* Nope, must be a symbol. */
1097 /* FALL THRU into number case. */
1098
1099 case '0':
1100 case '1':
1101 case '2':
1102 case '3':
1103 case '4':
1104 case '5':
1105 case '6':
1106 case '7':
1107 case '8':
1108 case '9':
1109 {
1110 /* It's a number. */
1111 int got_dot = 0, got_e = 0, toktype;
1112 register char *p = tokstart;
1113 int hex = input_radix > 10;
1114
1115 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1116 {
1117 p += 2;
1118 hex = 1;
1119 }
1120 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
1121 {
1122 p += 2;
1123 hex = 0;
1124 }
1125
1126 for (;; ++p)
1127 {
1128 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1129 got_dot = got_e = 1;
1130 else if (!hex && !got_dot && *p == '.')
1131 got_dot = 1;
1132 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
1133 && (*p == '-' || *p == '+'))
1134 /* This is the sign of the exponent, not the end of the
1135 number. */
1136 continue;
1137 /* We will take any letters or digits. parse_number will
1138 complain if past the radix, or if L or U are not final. */
1139 else if ((*p < '0' || *p > '9')
1140 && ((*p < 'a' || *p > 'z')
1141 && (*p < 'A' || *p > 'Z')))
1142 break;
1143 }
1144 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
1145 if (toktype == ERROR)
1146 {
1147 char *err_copy = (char *) alloca (p - tokstart + 1);
1148
1149 bcopy (tokstart, err_copy, p - tokstart);
1150 err_copy[p - tokstart] = 0;
1151 error ("Invalid number \"%s\".", err_copy);
1152 }
1153 lexptr = p;
1154 return toktype;
1155 }
1156
1157 case '+':
1158 case '-':
1159 case '*':
1160 case '/':
1161 case '%':
1162 case '|':
1163 case '&':
1164 case '^':
1165 case '~':
1166 case '!':
1167 case '@':
1168 case '<':
1169 case '>':
1170 case '[':
1171 case ']':
1172 case '?':
1173 case ':':
1174 case '=':
1175 case '{':
1176 case '}':
1177 symbol:
1178 lexptr++;
1179 return c;
1180
1181 case '"':
1182 for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
1183 if (c == '\\')
1184 {
1185 c = tokstart[++namelen];
1186 if (c >= '0' && c <= '9')
1187 {
1188 c = tokstart[++namelen];
1189 if (c >= '0' && c <= '9')
1190 c = tokstart[++namelen];
1191 }
1192 }
1193 yylval.sval.ptr = tokstart + 1;
1194 yylval.sval.length = namelen - 1;
1195 lexptr += namelen + 1;
1196 return STRING;
1197 }
1198
1199 if (!(c == '_' || c == '$'
1200 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1201 /* We must have come across a bad character (e.g. ';'). */
1202 error ("Invalid character '%c' in expression.", c);
1203
1204 /* It's a name. See how long it is. */
1205 namelen = 0;
1206 for (c = tokstart[namelen];
1207 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1208 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1209 c = tokstart[++namelen])
1210 ;
1211
1212 /* The token "if" terminates the expression and is NOT
1213 removed from the input stream. */
1214 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1215 {
1216 return 0;
1217 }
1218
1219 lexptr += namelen;
1220
1221 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
1222 and $$digits (equivalent to $<-digits> if you could type that).
1223 Make token type LAST, and put the number (the digits) in yylval. */
1224
1225 if (*tokstart == '$')
1226 {
1227 register int negate = 0;
1228 c = 1;
1229 /* Double dollar means negate the number and add -1 as well.
1230 Thus $$ alone means -1. */
1231 if (namelen >= 2 && tokstart[1] == '$')
1232 {
1233 negate = 1;
1234 c = 2;
1235 }
1236 if (c == namelen)
1237 {
1238 /* Just dollars (one or two) */
1239 yylval.lval = - negate;
1240 return LAST;
1241 }
1242 /* Is the rest of the token digits? */
1243 for (; c < namelen; c++)
1244 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
1245 break;
1246 if (c == namelen)
1247 {
1248 yylval.lval = atoi (tokstart + 1 + negate);
1249 if (negate)
1250 yylval.lval = - yylval.lval;
1251 return LAST;
1252 }
1253 }
1254
1255 /* Handle tokens that refer to machine registers:
1256 $ followed by a register name. */
1257
1258 if (*tokstart == '$') {
1259 for (c = 0; c < NUM_REGS; c++)
1260 if (namelen - 1 == strlen (reg_names[c])
1261 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
1262 {
1263 yylval.lval = c;
1264 return REGNAME;
1265 }
1266 for (c = 0; c < num_std_regs; c++)
1267 if (namelen - 1 == strlen (std_regs[c].name)
1268 && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
1269 {
1270 yylval.lval = std_regs[c].regnum;
1271 return REGNAME;
1272 }
1273 }
1274 /* Catch specific keywords. Should be done with a data structure. */
1275 switch (namelen)
1276 {
1277 case 8:
1278 if (!strncmp (tokstart, "unsigned", 8))
1279 return UNSIGNED;
1280 break;
1281 case 6:
1282 if (!strncmp (tokstart, "struct", 6))
1283 return STRUCT;
1284 if (!strncmp (tokstart, "signed", 6))
1285 return SIGNED;
1286 if (!strncmp (tokstart, "sizeof", 6))
1287 return SIZEOF;
1288 break;
1289 case 5:
1290 if (!strncmp (tokstart, "union", 5))
1291 return UNION;
1292 if (!strncmp (tokstart, "short", 5))
1293 return SHORT;
1294 break;
1295 case 4:
1296 if (!strncmp (tokstart, "enum", 4))
1297 return ENUM;
1298 if (!strncmp (tokstart, "long", 4))
1299 return LONG;
1300 if (!strncmp (tokstart, "this", 4))
1301 {
1302 static const char this_name[] =
1303 { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' };
1304
1305 if (lookup_symbol (this_name, expression_context_block,
1306 VAR_NAMESPACE, 0, NULL))
1307 return THIS;
1308 }
1309 break;
1310 case 3:
1311 if (!strncmp (tokstart, "int", 3))
1312 return INT_KEYWORD;
1313 break;
1314 default:
1315 break;
1316 }
1317
1318 yylval.sval.ptr = tokstart;
1319 yylval.sval.length = namelen;
1320
1321 /* Any other names starting in $ are debugger internal variables. */
1322
1323 if (*tokstart == '$')
1324 {
1325 yylval.ivar = lookup_internalvar (copy_name (yylval.sval) + 1);
1326 return VARIABLE;
1327 }
1328
1329 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1330 functions or symtabs. If this is not so, then ...
1331 Use token-type TYPENAME for symbols that happen to be defined
1332 currently as names of types; NAME for other symbols.
1333 The caller is not constrained to care about the distinction. */
1334 {
1335 char *tmp = copy_name (yylval.sval);
1336 struct symbol *sym;
1337 int is_a_field_of_this = 0;
1338 int hextype;
1339
1340 sym = lookup_symbol (tmp, expression_context_block,
1341 VAR_NAMESPACE, &is_a_field_of_this, NULL);
1342 if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) ||
1343 lookup_partial_symtab (tmp))
1344 {
1345 yylval.ssym.sym = sym;
1346 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1347 return BLOCKNAME;
1348 }
1349 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1350 {
1351 yylval.tsym.type = SYMBOL_TYPE (sym);
1352 return TYPENAME;
1353 }
1354 if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
1355 return TYPENAME;
1356
1357 /* Input names that aren't symbols but ARE valid hex numbers,
1358 when the input radix permits them, can be names or numbers
1359 depending on the parse. Note we support radixes > 16 here. */
1360 if (!sym &&
1361 ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
1362 (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1363 {
1364 YYSTYPE newlval; /* Its value is ignored. */
1365 hextype = parse_number (tokstart, namelen, 0, &newlval);
1366 if (hextype == INT)
1367 {
1368 yylval.ssym.sym = sym;
1369 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1370 return NAME_OR_INT;
1371 }
1372 if (hextype == UINT)
1373 {
1374 yylval.ssym.sym = sym;
1375 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1376 return NAME_OR_UINT;
1377 }
1378 }
1379
1380 /* Any other kind of symbol */
1381 yylval.ssym.sym = sym;
1382 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1383 return NAME;
1384 }
1385 }
1386
1387 void
1388 yyerror (msg)
1389 char *msg;
1390 {
1391 error ("Invalid syntax in expression.");
1392 }
1393 \f
1394 /* Table mapping opcodes into strings for printing operators
1395 and precedences of the operators. */
1396
1397 const static struct op_print c_op_print_tab[] =
1398 {
1399 {",", BINOP_COMMA, PREC_COMMA, 0},
1400 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1401 {"||", BINOP_OR, PREC_OR, 0},
1402 {"&&", BINOP_AND, PREC_AND, 0},
1403 {"|", BINOP_LOGIOR, PREC_LOGIOR, 0},
1404 {"&", BINOP_LOGAND, PREC_LOGAND, 0},
1405 {"^", BINOP_LOGXOR, PREC_LOGXOR, 0},
1406 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
1407 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1408 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1409 {">=", BINOP_GEQ, PREC_ORDER, 0},
1410 {">", BINOP_GTR, PREC_ORDER, 0},
1411 {"<", BINOP_LESS, PREC_ORDER, 0},
1412 {">>", BINOP_RSH, PREC_SHIFT, 0},
1413 {"<<", BINOP_LSH, PREC_SHIFT, 0},
1414 {"+", BINOP_ADD, PREC_ADD, 0},
1415 {"-", BINOP_SUB, PREC_ADD, 0},
1416 {"*", BINOP_MUL, PREC_MUL, 0},
1417 {"/", BINOP_DIV, PREC_MUL, 0},
1418 {"%", BINOP_REM, PREC_MUL, 0},
1419 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1420 {"-", UNOP_NEG, PREC_PREFIX, 0},
1421 {"!", UNOP_ZEROP, PREC_PREFIX, 0},
1422 {"~", UNOP_LOGNOT, PREC_PREFIX, 0},
1423 {"*", UNOP_IND, PREC_PREFIX, 0},
1424 {"&", UNOP_ADDR, PREC_PREFIX, 0},
1425 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
1426 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
1427 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
1428 /* C++ */
1429 {"::", BINOP_SCOPE, PREC_PREFIX, 0},
1430 };
1431 \f
1432 /* These variables point to the objects
1433 representing the predefined C data types. */
1434
1435 struct type *builtin_type_void;
1436 struct type *builtin_type_char;
1437 struct type *builtin_type_short;
1438 struct type *builtin_type_int;
1439 struct type *builtin_type_long;
1440 struct type *builtin_type_long_long;
1441 struct type *builtin_type_unsigned_char;
1442 struct type *builtin_type_unsigned_short;
1443 struct type *builtin_type_unsigned_int;
1444 struct type *builtin_type_unsigned_long;
1445 struct type *builtin_type_unsigned_long_long;
1446 struct type *builtin_type_float;
1447 struct type *builtin_type_double;
1448
1449 struct type ** const (c_builtin_types[]) =
1450 {
1451 &builtin_type_int,
1452 &builtin_type_long,
1453 &builtin_type_short,
1454 &builtin_type_char,
1455 &builtin_type_float,
1456 &builtin_type_double,
1457 &builtin_type_void,
1458 &builtin_type_long_long,
1459 &builtin_type_unsigned_char,
1460 &builtin_type_unsigned_short,
1461 &builtin_type_unsigned_int,
1462 &builtin_type_unsigned_long,
1463 &builtin_type_unsigned_long_long,
1464 0
1465 };
1466
1467 /* FIXME: Eventually do a separate defintion for C++. */
1468
1469 const struct language_defn c_language_defn = {
1470 "c", /* Language name */
1471 language_c,
1472 c_builtin_types,
1473 range_check_off,
1474 type_check_off,
1475 c_parse,
1476 c_error,
1477 &BUILTIN_TYPE_LONGEST, /* longest signed integral type */
1478 &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */
1479 &builtin_type_double, /* longest floating point type */
1480 "0x%x", "0x%", "x", /* Hex format, prefix, suffix */
1481 "0%o", "0%", "o", /* Octal format, prefix, suffix */
1482 c_op_print_tab, /* expression operators for printing */
1483 LANG_MAGIC
1484 };
1485
1486 void
1487 _initialize_c_exp ()
1488 {
1489 /* FIXME: The code below assumes that the sizes of the basic data
1490 types are the same on the host and target machines!!! */
1491
1492 builtin_type_void = init_type (TYPE_CODE_VOID, 1, 0, "void");
1493
1494 builtin_type_float = init_type (TYPE_CODE_FLT, sizeof (float), 0, "float");
1495 builtin_type_double = init_type (TYPE_CODE_FLT, sizeof (double), 0, "double");
1496
1497 builtin_type_char = init_type (TYPE_CODE_INT, sizeof (char), 0, "char");
1498 builtin_type_short = init_type (TYPE_CODE_INT, sizeof (short), 0, "short");
1499 builtin_type_long = init_type (TYPE_CODE_INT, sizeof (long), 0, "long");
1500 builtin_type_int = init_type (TYPE_CODE_INT, sizeof (int), 0, "int");
1501
1502 builtin_type_unsigned_char = init_type (TYPE_CODE_INT, sizeof (char), 1, "unsigned char");
1503 builtin_type_unsigned_short = init_type (TYPE_CODE_INT, sizeof (short), 1, "unsigned short");
1504 builtin_type_unsigned_long = init_type (TYPE_CODE_INT, sizeof (long), 1, "unsigned long");
1505 builtin_type_unsigned_int = init_type (TYPE_CODE_INT, sizeof (int), 1, "unsigned int");
1506
1507 builtin_type_long_long =
1508 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1509 0, "long long");
1510 builtin_type_unsigned_long_long =
1511 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1512 1, "unsigned long long");
1513
1514 add_language (&c_language_defn);
1515 set_language (language_c); /* Make C the default language */
1516 }