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