* Makefile.in (VERSION): Bump to 4.5.6.
[deliverable/binutils-gdb.git] / gdb / c-exp.y
1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* Parse a C expression from text in a string,
21 and return the result as a struct expression pointer.
22 That structure contains arithmetic operations in reverse polish,
23 with constants represented by operations that are followed by special data.
24 See expression.h for the details of the format.
25 What is important here is that it can be built up sequentially
26 during the process of parsing; the lower levels of the tree always
27 come first in the result. */
28
29 %{
30
31 #include <stdio.h>
32 #include <string.h>
33 #include "defs.h"
34 #include "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 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 | UNION name
868 { $$ = lookup_union (copy_name ($2),
869 expression_context_block); }
870 | ENUM name
871 { $$ = lookup_enum (copy_name ($2),
872 expression_context_block); }
873 | UNSIGNED typename
874 { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
875 | UNSIGNED
876 { $$ = builtin_type_unsigned_int; }
877 | SIGNED_KEYWORD typename
878 { $$ = $2.type; }
879 | SIGNED_KEYWORD
880 { $$ = builtin_type_int; }
881 | TEMPLATE name '<' type '>'
882 { $$ = lookup_template_type(copy_name($2), $4,
883 expression_context_block);
884 }
885 ;
886
887 typename: TYPENAME
888 | INT_KEYWORD
889 {
890 $$.stoken.ptr = "int";
891 $$.stoken.length = 3;
892 $$.type = builtin_type_int;
893 }
894 | LONG
895 {
896 $$.stoken.ptr = "long";
897 $$.stoken.length = 4;
898 $$.type = builtin_type_long;
899 }
900 | SHORT
901 {
902 $$.stoken.ptr = "short";
903 $$.stoken.length = 5;
904 $$.type = builtin_type_short;
905 }
906 ;
907
908 nonempty_typelist
909 : type
910 { $$ = (struct type **) xmalloc (sizeof (struct type *) * 2);
911 $<ivec>$[0] = 1; /* Number of types in vector */
912 $$[1] = $1;
913 }
914 | nonempty_typelist ',' type
915 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
916 $$ = (struct type **) xrealloc ((char *) $1, len);
917 $$[$<ivec>$[0]] = $3;
918 }
919 ;
920
921 name : NAME { $$ = $1.stoken; }
922 | BLOCKNAME { $$ = $1.stoken; }
923 | TYPENAME { $$ = $1.stoken; }
924 | NAME_OR_INT { $$ = $1.stoken; }
925 | NAME_OR_UINT { $$ = $1.stoken; }
926 ;
927
928 name_not_typename : NAME
929 | BLOCKNAME
930 /* These would be useful if name_not_typename was useful, but it is just
931 a fake for "variable", so these cause reduce/reduce conflicts because
932 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
933 =exp) or just an exp. If name_not_typename was ever used in an lvalue
934 context where only a name could occur, this might be useful.
935 | NAME_OR_INT
936 | NAME_OR_UINT
937 */
938 ;
939
940 %%
941
942 /* Take care of parsing a number (anything that starts with a digit).
943 Set yylval and return the token type; update lexptr.
944 LEN is the number of characters in it. */
945
946 /*** Needs some error checking for the float case ***/
947
948 static int
949 parse_number (p, len, parsed_float, putithere)
950 register char *p;
951 register int len;
952 int parsed_float;
953 YYSTYPE *putithere;
954 {
955 register LONGEST n = 0;
956 register LONGEST prevn = 0;
957 register int i;
958 register int c;
959 register int base = input_radix;
960 int unsigned_p = 0;
961
962 if (parsed_float)
963 {
964 /* It's a float since it contains a point or an exponent. */
965 putithere->dval = atof (p);
966 return FLOAT;
967 }
968
969 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
970 if (p[0] == '0')
971 switch (p[1])
972 {
973 case 'x':
974 case 'X':
975 if (len >= 3)
976 {
977 p += 2;
978 base = 16;
979 len -= 2;
980 }
981 break;
982
983 case 't':
984 case 'T':
985 case 'd':
986 case 'D':
987 if (len >= 3)
988 {
989 p += 2;
990 base = 10;
991 len -= 2;
992 }
993 break;
994
995 default:
996 base = 8;
997 break;
998 }
999
1000 while (len-- > 0)
1001 {
1002 c = *p++;
1003 if (c >= 'A' && c <= 'Z')
1004 c += 'a' - 'A';
1005 if (c != 'l' && c != 'u')
1006 n *= base;
1007 if (c >= '0' && c <= '9')
1008 n += i = c - '0';
1009 else
1010 {
1011 if (base > 10 && c >= 'a' && c <= 'f')
1012 n += i = c - 'a' + 10;
1013 else if (len == 0 && c == 'l')
1014 ;
1015 else if (len == 0 && c == 'u')
1016 unsigned_p = 1;
1017 else
1018 return ERROR; /* Char not a digit */
1019 }
1020 if (i >= base)
1021 return ERROR; /* Invalid digit in this base */
1022 /* Portably test for overflow (only works for nonzero values, so make
1023 a second check for zero). */
1024 if((prevn >= n) && n != 0)
1025 unsigned_p=1; /* Try something unsigned */
1026 /* If range checking enabled, portably test for unsigned overflow. */
1027 if(RANGE_CHECK && n!=0)
1028 {
1029 if((unsigned_p && (unsigned)prevn >= (unsigned)n))
1030 range_error("Overflow on numeric constant.");
1031 }
1032 prevn=n;
1033 }
1034
1035 if (unsigned_p)
1036 {
1037 putithere->ulval = n;
1038 return UINT;
1039 }
1040 else
1041 {
1042 putithere->lval = n;
1043 return INT;
1044 }
1045 }
1046
1047 struct token
1048 {
1049 char *operator;
1050 int token;
1051 enum exp_opcode opcode;
1052 };
1053
1054 const static struct token tokentab3[] =
1055 {
1056 {">>=", ASSIGN_MODIFY, BINOP_RSH},
1057 {"<<=", ASSIGN_MODIFY, BINOP_LSH}
1058 };
1059
1060 const static struct token tokentab2[] =
1061 {
1062 {"+=", ASSIGN_MODIFY, BINOP_ADD},
1063 {"-=", ASSIGN_MODIFY, BINOP_SUB},
1064 {"*=", ASSIGN_MODIFY, BINOP_MUL},
1065 {"/=", ASSIGN_MODIFY, BINOP_DIV},
1066 {"%=", ASSIGN_MODIFY, BINOP_REM},
1067 {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
1068 {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
1069 {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
1070 {"++", INCREMENT, BINOP_END},
1071 {"--", DECREMENT, BINOP_END},
1072 {"->", ARROW, BINOP_END},
1073 {"&&", ANDAND, BINOP_END},
1074 {"||", OROR, BINOP_END},
1075 {"::", COLONCOLON, BINOP_END},
1076 {"<<", LSH, BINOP_END},
1077 {">>", RSH, BINOP_END},
1078 {"==", EQUAL, BINOP_END},
1079 {"!=", NOTEQUAL, BINOP_END},
1080 {"<=", LEQ, BINOP_END},
1081 {">=", GEQ, BINOP_END}
1082 };
1083
1084 /* Read one token, getting characters through lexptr. */
1085
1086 int
1087 yylex ()
1088 {
1089 register int c;
1090 register int namelen;
1091 register unsigned i;
1092 register char *tokstart;
1093
1094 retry:
1095
1096 tokstart = lexptr;
1097 /* See if it is a special token of length 3. */
1098 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
1099 if (!strncmp (tokstart, tokentab3[i].operator, 3))
1100 {
1101 lexptr += 3;
1102 yylval.opcode = tokentab3[i].opcode;
1103 return tokentab3[i].token;
1104 }
1105
1106 /* See if it is a special token of length 2. */
1107 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
1108 if (!strncmp (tokstart, tokentab2[i].operator, 2))
1109 {
1110 lexptr += 2;
1111 yylval.opcode = tokentab2[i].opcode;
1112 return tokentab2[i].token;
1113 }
1114
1115 switch (c = *tokstart)
1116 {
1117 case 0:
1118 return 0;
1119
1120 case ' ':
1121 case '\t':
1122 case '\n':
1123 lexptr++;
1124 goto retry;
1125
1126 case '\'':
1127 /* We either have a character constant ('0' or '\177' for example)
1128 or we have a quoted symbol reference ('foo(int,int)' in C++
1129 for example). */
1130 lexptr++;
1131 c = *lexptr++;
1132 if (c == '\\')
1133 c = parse_escape (&lexptr);
1134 yylval.lval = c;
1135 c = *lexptr++;
1136 if (c != '\'')
1137 {
1138 namelen = skip_quoted (tokstart) - tokstart;
1139 if (namelen > 2)
1140 {
1141 lexptr = tokstart + namelen;
1142 namelen -= 2;
1143 tokstart++;
1144 goto tryname;
1145 }
1146 error ("Invalid character constant.");
1147 }
1148 return CHAR;
1149
1150 case '(':
1151 paren_depth++;
1152 lexptr++;
1153 return c;
1154
1155 case ')':
1156 if (paren_depth == 0)
1157 return 0;
1158 paren_depth--;
1159 lexptr++;
1160 return c;
1161
1162 case ',':
1163 if (comma_terminates && paren_depth == 0)
1164 return 0;
1165 lexptr++;
1166 return c;
1167
1168 case '.':
1169 /* Might be a floating point number. */
1170 if (lexptr[1] < '0' || lexptr[1] > '9')
1171 goto symbol; /* Nope, must be a symbol. */
1172 /* FALL THRU into number case. */
1173
1174 case '0':
1175 case '1':
1176 case '2':
1177 case '3':
1178 case '4':
1179 case '5':
1180 case '6':
1181 case '7':
1182 case '8':
1183 case '9':
1184 {
1185 /* It's a number. */
1186 int got_dot = 0, got_e = 0, toktype;
1187 register char *p = tokstart;
1188 int hex = input_radix > 10;
1189
1190 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1191 {
1192 p += 2;
1193 hex = 1;
1194 }
1195 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
1196 {
1197 p += 2;
1198 hex = 0;
1199 }
1200
1201 for (;; ++p)
1202 {
1203 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1204 got_dot = got_e = 1;
1205 else if (!hex && !got_dot && *p == '.')
1206 got_dot = 1;
1207 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
1208 && (*p == '-' || *p == '+'))
1209 /* This is the sign of the exponent, not the end of the
1210 number. */
1211 continue;
1212 /* We will take any letters or digits. parse_number will
1213 complain if past the radix, or if L or U are not final. */
1214 else if ((*p < '0' || *p > '9')
1215 && ((*p < 'a' || *p > 'z')
1216 && (*p < 'A' || *p > 'Z')))
1217 break;
1218 }
1219 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
1220 if (toktype == ERROR)
1221 {
1222 char *err_copy = (char *) alloca (p - tokstart + 1);
1223
1224 bcopy (tokstart, err_copy, p - tokstart);
1225 err_copy[p - tokstart] = 0;
1226 error ("Invalid number \"%s\".", err_copy);
1227 }
1228 lexptr = p;
1229 return toktype;
1230 }
1231
1232 case '+':
1233 case '-':
1234 case '*':
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 symbol:
1253 lexptr++;
1254 return c;
1255
1256 case '"':
1257 for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
1258 if (c == '\\')
1259 {
1260 c = tokstart[++namelen];
1261 if (c >= '0' && c <= '9')
1262 {
1263 c = tokstart[++namelen];
1264 if (c >= '0' && c <= '9')
1265 c = tokstart[++namelen];
1266 }
1267 }
1268 yylval.sval.ptr = tokstart + 1;
1269 yylval.sval.length = namelen - 1;
1270 lexptr += namelen + 1;
1271 return STRING;
1272 }
1273
1274 if (!(c == '_' || c == '$'
1275 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1276 /* We must have come across a bad character (e.g. ';'). */
1277 error ("Invalid character '%c' in expression.", c);
1278
1279 /* It's a name. See how long it is. */
1280 namelen = 0;
1281 for (c = tokstart[namelen];
1282 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1283 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1284 c = tokstart[++namelen])
1285 ;
1286
1287 /* The token "if" terminates the expression and is NOT
1288 removed from the input stream. */
1289 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1290 {
1291 return 0;
1292 }
1293
1294 lexptr += namelen;
1295
1296 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
1297 and $$digits (equivalent to $<-digits> if you could type that).
1298 Make token type LAST, and put the number (the digits) in yylval. */
1299
1300 tryname:
1301 if (*tokstart == '$')
1302 {
1303 register int negate = 0;
1304 c = 1;
1305 /* Double dollar means negate the number and add -1 as well.
1306 Thus $$ alone means -1. */
1307 if (namelen >= 2 && tokstart[1] == '$')
1308 {
1309 negate = 1;
1310 c = 2;
1311 }
1312 if (c == namelen)
1313 {
1314 /* Just dollars (one or two) */
1315 yylval.lval = - negate;
1316 return LAST;
1317 }
1318 /* Is the rest of the token digits? */
1319 for (; c < namelen; c++)
1320 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
1321 break;
1322 if (c == namelen)
1323 {
1324 yylval.lval = atoi (tokstart + 1 + negate);
1325 if (negate)
1326 yylval.lval = - yylval.lval;
1327 return LAST;
1328 }
1329 }
1330
1331 /* Handle tokens that refer to machine registers:
1332 $ followed by a register name. */
1333
1334 if (*tokstart == '$') {
1335 for (c = 0; c < NUM_REGS; c++)
1336 if (namelen - 1 == strlen (reg_names[c])
1337 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
1338 {
1339 yylval.lval = c;
1340 return REGNAME;
1341 }
1342 for (c = 0; c < num_std_regs; c++)
1343 if (namelen - 1 == strlen (std_regs[c].name)
1344 && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
1345 {
1346 yylval.lval = std_regs[c].regnum;
1347 return REGNAME;
1348 }
1349 }
1350 /* Catch specific keywords. Should be done with a data structure. */
1351 switch (namelen)
1352 {
1353 case 8:
1354 if (!strncmp (tokstart, "unsigned", 8))
1355 return UNSIGNED;
1356 if (current_language->la_language == language_cplus
1357 && !strncmp (tokstart, "template", 8))
1358 return TEMPLATE;
1359 break;
1360 case 6:
1361 if (!strncmp (tokstart, "struct", 6))
1362 return STRUCT;
1363 if (!strncmp (tokstart, "signed", 6))
1364 return SIGNED_KEYWORD;
1365 if (!strncmp (tokstart, "sizeof", 6))
1366 return SIZEOF;
1367 break;
1368 case 5:
1369 if (!strncmp (tokstart, "union", 5))
1370 return UNION;
1371 if (!strncmp (tokstart, "short", 5))
1372 return SHORT;
1373 break;
1374 case 4:
1375 if (!strncmp (tokstart, "enum", 4))
1376 return ENUM;
1377 if (!strncmp (tokstart, "long", 4))
1378 return LONG;
1379 if (current_language->la_language == language_cplus
1380 && !strncmp (tokstart, "this", 4))
1381 {
1382 static const char this_name[] =
1383 { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' };
1384
1385 if (lookup_symbol (this_name, expression_context_block,
1386 VAR_NAMESPACE, 0, NULL))
1387 return THIS;
1388 }
1389 break;
1390 case 3:
1391 if (!strncmp (tokstart, "int", 3))
1392 return INT_KEYWORD;
1393 break;
1394 default:
1395 break;
1396 }
1397
1398 yylval.sval.ptr = tokstart;
1399 yylval.sval.length = namelen;
1400
1401 /* Any other names starting in $ are debugger internal variables. */
1402
1403 if (*tokstart == '$')
1404 {
1405 yylval.ivar = lookup_internalvar (copy_name (yylval.sval) + 1);
1406 return VARIABLE;
1407 }
1408
1409 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1410 functions or symtabs. If this is not so, then ...
1411 Use token-type TYPENAME for symbols that happen to be defined
1412 currently as names of types; NAME for other symbols.
1413 The caller is not constrained to care about the distinction. */
1414 {
1415 char *tmp = copy_name (yylval.sval);
1416 struct symbol *sym;
1417 int is_a_field_of_this = 0;
1418 int hextype;
1419
1420 sym = lookup_symbol (tmp, expression_context_block,
1421 VAR_NAMESPACE,
1422 current_language->la_language == language_cplus
1423 ? &is_a_field_of_this : NULL,
1424 NULL);
1425 if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) ||
1426 lookup_partial_symtab (tmp))
1427 {
1428 yylval.ssym.sym = sym;
1429 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1430 return BLOCKNAME;
1431 }
1432 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1433 {
1434 yylval.tsym.type = SYMBOL_TYPE (sym);
1435 return TYPENAME;
1436 }
1437 if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
1438 return TYPENAME;
1439
1440 /* Input names that aren't symbols but ARE valid hex numbers,
1441 when the input radix permits them, can be names or numbers
1442 depending on the parse. Note we support radixes > 16 here. */
1443 if (!sym &&
1444 ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
1445 (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1446 {
1447 YYSTYPE newlval; /* Its value is ignored. */
1448 hextype = parse_number (tokstart, namelen, 0, &newlval);
1449 if (hextype == INT)
1450 {
1451 yylval.ssym.sym = sym;
1452 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1453 return NAME_OR_INT;
1454 }
1455 if (hextype == UINT)
1456 {
1457 yylval.ssym.sym = sym;
1458 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1459 return NAME_OR_UINT;
1460 }
1461 }
1462
1463 /* Any other kind of symbol */
1464 yylval.ssym.sym = sym;
1465 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1466 return NAME;
1467 }
1468 }
1469
1470 void
1471 yyerror (msg)
1472 char *msg;
1473 {
1474 error (msg ? msg : "Invalid syntax in expression.");
1475 }
1476 \f
1477 /* Table mapping opcodes into strings for printing operators
1478 and precedences of the operators. */
1479
1480 const static struct op_print c_op_print_tab[] =
1481 {
1482 {",", BINOP_COMMA, PREC_COMMA, 0},
1483 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1484 {"||", BINOP_OR, PREC_OR, 0},
1485 {"&&", BINOP_AND, PREC_AND, 0},
1486 {"|", BINOP_LOGIOR, PREC_LOGIOR, 0},
1487 {"&", BINOP_LOGAND, PREC_LOGAND, 0},
1488 {"^", BINOP_LOGXOR, PREC_LOGXOR, 0},
1489 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
1490 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1491 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1492 {">=", BINOP_GEQ, PREC_ORDER, 0},
1493 {">", BINOP_GTR, PREC_ORDER, 0},
1494 {"<", BINOP_LESS, PREC_ORDER, 0},
1495 {">>", BINOP_RSH, PREC_SHIFT, 0},
1496 {"<<", BINOP_LSH, PREC_SHIFT, 0},
1497 {"+", BINOP_ADD, PREC_ADD, 0},
1498 {"-", BINOP_SUB, PREC_ADD, 0},
1499 {"*", BINOP_MUL, PREC_MUL, 0},
1500 {"/", BINOP_DIV, PREC_MUL, 0},
1501 {"%", BINOP_REM, PREC_MUL, 0},
1502 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1503 {"-", UNOP_NEG, PREC_PREFIX, 0},
1504 {"!", UNOP_ZEROP, PREC_PREFIX, 0},
1505 {"~", UNOP_LOGNOT, PREC_PREFIX, 0},
1506 {"*", UNOP_IND, PREC_PREFIX, 0},
1507 {"&", UNOP_ADDR, PREC_PREFIX, 0},
1508 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
1509 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
1510 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
1511 /* C++ */
1512 {"::", BINOP_SCOPE, PREC_PREFIX, 0},
1513 };
1514 \f
1515 /* These variables point to the objects
1516 representing the predefined C data types. */
1517
1518 struct type *builtin_type_void;
1519 struct type *builtin_type_char;
1520 struct type *builtin_type_short;
1521 struct type *builtin_type_int;
1522 struct type *builtin_type_long;
1523 struct type *builtin_type_long_long;
1524 struct type *builtin_type_signed_char;
1525 struct type *builtin_type_unsigned_char;
1526 struct type *builtin_type_unsigned_short;
1527 struct type *builtin_type_unsigned_int;
1528 struct type *builtin_type_unsigned_long;
1529 struct type *builtin_type_unsigned_long_long;
1530 struct type *builtin_type_float;
1531 struct type *builtin_type_double;
1532 struct type *builtin_type_long_double;
1533 struct type *builtin_type_complex;
1534 struct type *builtin_type_double_complex;
1535
1536 struct type ** const (c_builtin_types[]) =
1537 {
1538 &builtin_type_int,
1539 &builtin_type_long,
1540 &builtin_type_short,
1541 &builtin_type_char,
1542 &builtin_type_float,
1543 &builtin_type_double,
1544 &builtin_type_void,
1545 &builtin_type_long_long,
1546 &builtin_type_signed_char,
1547 &builtin_type_unsigned_char,
1548 &builtin_type_unsigned_short,
1549 &builtin_type_unsigned_int,
1550 &builtin_type_unsigned_long,
1551 &builtin_type_unsigned_long_long,
1552 &builtin_type_long_double,
1553 &builtin_type_complex,
1554 &builtin_type_double_complex,
1555 0
1556 };
1557
1558 const struct language_defn c_language_defn = {
1559 "c", /* Language name */
1560 language_c,
1561 c_builtin_types,
1562 range_check_off,
1563 type_check_off,
1564 c_parse,
1565 c_error,
1566 &BUILTIN_TYPE_LONGEST, /* longest signed integral type */
1567 &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */
1568 &builtin_type_double, /* longest floating point type */ /*FIXME*/
1569 "0x%x", "0x%", "x", /* Hex format, prefix, suffix */
1570 "0%o", "0%", "o", /* Octal format, prefix, suffix */
1571 c_op_print_tab, /* expression operators for printing */
1572 LANG_MAGIC
1573 };
1574
1575 const struct language_defn cplus_language_defn = {
1576 "c++", /* Language name */
1577 language_cplus,
1578 c_builtin_types,
1579 range_check_off,
1580 type_check_off,
1581 c_parse,
1582 c_error,
1583 &BUILTIN_TYPE_LONGEST, /* longest signed integral type */
1584 &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */
1585 &builtin_type_double, /* longest floating point type */ /*FIXME*/
1586 "0x%x", "0x%", "x", /* Hex format, prefix, suffix */
1587 "0%o", "0%", "o", /* Octal format, prefix, suffix */
1588 c_op_print_tab, /* expression operators for printing */
1589 LANG_MAGIC
1590 };
1591
1592 void
1593 _initialize_c_exp ()
1594 {
1595 builtin_type_void =
1596 init_type (TYPE_CODE_VOID, 1,
1597 0,
1598 "void", (struct objfile *) NULL);
1599 builtin_type_char =
1600 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1601 0,
1602 "char", (struct objfile *) NULL);
1603 builtin_type_signed_char =
1604 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1605 TYPE_FLAG_SIGNED,
1606 "signed char", (struct objfile *) NULL);
1607 builtin_type_unsigned_char =
1608 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1609 TYPE_FLAG_UNSIGNED,
1610 "unsigned char", (struct objfile *) NULL);
1611 builtin_type_short =
1612 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1613 0,
1614 "short", (struct objfile *) NULL);
1615 builtin_type_unsigned_short =
1616 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1617 TYPE_FLAG_UNSIGNED,
1618 "unsigned short", (struct objfile *) NULL);
1619 builtin_type_int =
1620 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1621 0,
1622 "int", (struct objfile *) NULL);
1623 builtin_type_unsigned_int =
1624 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1625 TYPE_FLAG_UNSIGNED,
1626 "unsigned int", (struct objfile *) NULL);
1627 builtin_type_long =
1628 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1629 0,
1630 "long", (struct objfile *) NULL);
1631 builtin_type_unsigned_long =
1632 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1633 TYPE_FLAG_UNSIGNED,
1634 "unsigned long", (struct objfile *) NULL);
1635 builtin_type_long_long =
1636 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1637 0,
1638 "long long", (struct objfile *) NULL);
1639 builtin_type_unsigned_long_long =
1640 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1641 TYPE_FLAG_UNSIGNED,
1642 "unsigned long long", (struct objfile *) NULL);
1643 builtin_type_float =
1644 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1645 0,
1646 "float", (struct objfile *) NULL);
1647 builtin_type_double =
1648 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
1649 0,
1650 "double", (struct objfile *) NULL);
1651 builtin_type_long_double =
1652 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
1653 0,
1654 "long double", (struct objfile *) NULL);
1655 builtin_type_complex =
1656 init_type (TYPE_CODE_FLT, TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
1657 0,
1658 "complex", (struct objfile *) NULL);
1659 builtin_type_double_complex =
1660 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
1661 0,
1662 "double complex", (struct objfile *) NULL);
1663
1664 add_language (&c_language_defn);
1665 add_language (&cplus_language_defn);
1666 }
This page took 0.065646 seconds and 4 git commands to generate.