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