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