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