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