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