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