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