* c-exp.y (yylex): Recognize single-quoted strings that specify
[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 $<ivec>$[0] = 1; /* Number of types in vector */
900 $$[1] = $1;
901 }
902 | nonempty_typelist ',' type
903 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
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 /* We either have a character constant ('0' or '\177' for example)
1116 or we have a quoted symbol reference ('foo(int,int)' in C++
1117 for example). */
1118 lexptr++;
1119 c = *lexptr++;
1120 if (c == '\\')
1121 c = parse_escape (&lexptr);
1122 yylval.lval = c;
1123 c = *lexptr++;
1124 if (c != '\'')
1125 {
1126 namelen = skip_quoted (tokstart) - tokstart;
1127 if (namelen > 2)
1128 {
1129 lexptr = tokstart + namelen;
1130 namelen -= 2;
1131 tokstart++;
1132 goto tryname;
1133 }
1134 error ("Invalid character constant.");
1135 }
1136 return CHAR;
1137
1138 case '(':
1139 paren_depth++;
1140 lexptr++;
1141 return c;
1142
1143 case ')':
1144 if (paren_depth == 0)
1145 return 0;
1146 paren_depth--;
1147 lexptr++;
1148 return c;
1149
1150 case ',':
1151 if (comma_terminates && paren_depth == 0)
1152 return 0;
1153 lexptr++;
1154 return c;
1155
1156 case '.':
1157 /* Might be a floating point number. */
1158 if (lexptr[1] < '0' || lexptr[1] > '9')
1159 goto symbol; /* Nope, must be a symbol. */
1160 /* FALL THRU into number case. */
1161
1162 case '0':
1163 case '1':
1164 case '2':
1165 case '3':
1166 case '4':
1167 case '5':
1168 case '6':
1169 case '7':
1170 case '8':
1171 case '9':
1172 {
1173 /* It's a number. */
1174 int got_dot = 0, got_e = 0, toktype;
1175 register char *p = tokstart;
1176 int hex = input_radix > 10;
1177
1178 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1179 {
1180 p += 2;
1181 hex = 1;
1182 }
1183 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
1184 {
1185 p += 2;
1186 hex = 0;
1187 }
1188
1189 for (;; ++p)
1190 {
1191 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1192 got_dot = got_e = 1;
1193 else if (!hex && !got_dot && *p == '.')
1194 got_dot = 1;
1195 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
1196 && (*p == '-' || *p == '+'))
1197 /* This is the sign of the exponent, not the end of the
1198 number. */
1199 continue;
1200 /* We will take any letters or digits. parse_number will
1201 complain if past the radix, or if L or U are not final. */
1202 else if ((*p < '0' || *p > '9')
1203 && ((*p < 'a' || *p > 'z')
1204 && (*p < 'A' || *p > 'Z')))
1205 break;
1206 }
1207 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
1208 if (toktype == ERROR)
1209 {
1210 char *err_copy = (char *) alloca (p - tokstart + 1);
1211
1212 bcopy (tokstart, err_copy, p - tokstart);
1213 err_copy[p - tokstart] = 0;
1214 error ("Invalid number \"%s\".", err_copy);
1215 }
1216 lexptr = p;
1217 return toktype;
1218 }
1219
1220 case '+':
1221 case '-':
1222 case '*':
1223 case '/':
1224 case '%':
1225 case '|':
1226 case '&':
1227 case '^':
1228 case '~':
1229 case '!':
1230 case '@':
1231 case '<':
1232 case '>':
1233 case '[':
1234 case ']':
1235 case '?':
1236 case ':':
1237 case '=':
1238 case '{':
1239 case '}':
1240 symbol:
1241 lexptr++;
1242 return c;
1243
1244 case '"':
1245 for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
1246 if (c == '\\')
1247 {
1248 c = tokstart[++namelen];
1249 if (c >= '0' && c <= '9')
1250 {
1251 c = tokstart[++namelen];
1252 if (c >= '0' && c <= '9')
1253 c = tokstart[++namelen];
1254 }
1255 }
1256 yylval.sval.ptr = tokstart + 1;
1257 yylval.sval.length = namelen - 1;
1258 lexptr += namelen + 1;
1259 return STRING;
1260 }
1261
1262 if (!(c == '_' || c == '$'
1263 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1264 /* We must have come across a bad character (e.g. ';'). */
1265 error ("Invalid character '%c' in expression.", c);
1266
1267 /* It's a name. See how long it is. */
1268 namelen = 0;
1269 for (c = tokstart[namelen];
1270 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1271 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1272 c = tokstart[++namelen])
1273 ;
1274
1275 /* The token "if" terminates the expression and is NOT
1276 removed from the input stream. */
1277 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1278 {
1279 return 0;
1280 }
1281
1282 lexptr += namelen;
1283
1284 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
1285 and $$digits (equivalent to $<-digits> if you could type that).
1286 Make token type LAST, and put the number (the digits) in yylval. */
1287
1288 tryname:
1289 if (*tokstart == '$')
1290 {
1291 register int negate = 0;
1292 c = 1;
1293 /* Double dollar means negate the number and add -1 as well.
1294 Thus $$ alone means -1. */
1295 if (namelen >= 2 && tokstart[1] == '$')
1296 {
1297 negate = 1;
1298 c = 2;
1299 }
1300 if (c == namelen)
1301 {
1302 /* Just dollars (one or two) */
1303 yylval.lval = - negate;
1304 return LAST;
1305 }
1306 /* Is the rest of the token digits? */
1307 for (; c < namelen; c++)
1308 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
1309 break;
1310 if (c == namelen)
1311 {
1312 yylval.lval = atoi (tokstart + 1 + negate);
1313 if (negate)
1314 yylval.lval = - yylval.lval;
1315 return LAST;
1316 }
1317 }
1318
1319 /* Handle tokens that refer to machine registers:
1320 $ followed by a register name. */
1321
1322 if (*tokstart == '$') {
1323 for (c = 0; c < NUM_REGS; c++)
1324 if (namelen - 1 == strlen (reg_names[c])
1325 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
1326 {
1327 yylval.lval = c;
1328 return REGNAME;
1329 }
1330 for (c = 0; c < num_std_regs; c++)
1331 if (namelen - 1 == strlen (std_regs[c].name)
1332 && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
1333 {
1334 yylval.lval = std_regs[c].regnum;
1335 return REGNAME;
1336 }
1337 }
1338 /* Catch specific keywords. Should be done with a data structure. */
1339 switch (namelen)
1340 {
1341 case 8:
1342 if (!strncmp (tokstart, "unsigned", 8))
1343 return UNSIGNED;
1344 if (current_language->la_language == language_cplus
1345 && !strncmp (tokstart, "template", 8))
1346 return TEMPLATE;
1347 break;
1348 case 6:
1349 if (!strncmp (tokstart, "struct", 6))
1350 return STRUCT;
1351 if (!strncmp (tokstart, "signed", 6))
1352 return SIGNED_KEYWORD;
1353 if (!strncmp (tokstart, "sizeof", 6))
1354 return SIZEOF;
1355 break;
1356 case 5:
1357 if (!strncmp (tokstart, "union", 5))
1358 return UNION;
1359 if (!strncmp (tokstart, "short", 5))
1360 return SHORT;
1361 break;
1362 case 4:
1363 if (!strncmp (tokstart, "enum", 4))
1364 return ENUM;
1365 if (!strncmp (tokstart, "long", 4))
1366 return LONG;
1367 if (current_language->la_language == language_cplus
1368 && !strncmp (tokstart, "this", 4))
1369 {
1370 static const char this_name[] =
1371 { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' };
1372
1373 if (lookup_symbol (this_name, expression_context_block,
1374 VAR_NAMESPACE, 0, NULL))
1375 return THIS;
1376 }
1377 break;
1378 case 3:
1379 if (!strncmp (tokstart, "int", 3))
1380 return INT_KEYWORD;
1381 break;
1382 default:
1383 break;
1384 }
1385
1386 yylval.sval.ptr = tokstart;
1387 yylval.sval.length = namelen;
1388
1389 /* Any other names starting in $ are debugger internal variables. */
1390
1391 if (*tokstart == '$')
1392 {
1393 yylval.ivar = lookup_internalvar (copy_name (yylval.sval) + 1);
1394 return VARIABLE;
1395 }
1396
1397 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1398 functions or symtabs. If this is not so, then ...
1399 Use token-type TYPENAME for symbols that happen to be defined
1400 currently as names of types; NAME for other symbols.
1401 The caller is not constrained to care about the distinction. */
1402 {
1403 char *tmp = copy_name (yylval.sval);
1404 struct symbol *sym;
1405 int is_a_field_of_this = 0;
1406 int hextype;
1407
1408 sym = lookup_symbol (tmp, expression_context_block,
1409 VAR_NAMESPACE,
1410 current_language->la_language == language_cplus
1411 ? &is_a_field_of_this : NULL,
1412 NULL);
1413 if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) ||
1414 lookup_partial_symtab (tmp))
1415 {
1416 yylval.ssym.sym = sym;
1417 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1418 return BLOCKNAME;
1419 }
1420 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1421 {
1422 yylval.tsym.type = SYMBOL_TYPE (sym);
1423 return TYPENAME;
1424 }
1425 if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
1426 return TYPENAME;
1427
1428 /* Input names that aren't symbols but ARE valid hex numbers,
1429 when the input radix permits them, can be names or numbers
1430 depending on the parse. Note we support radixes > 16 here. */
1431 if (!sym &&
1432 ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
1433 (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1434 {
1435 YYSTYPE newlval; /* Its value is ignored. */
1436 hextype = parse_number (tokstart, namelen, 0, &newlval);
1437 if (hextype == INT)
1438 {
1439 yylval.ssym.sym = sym;
1440 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1441 return NAME_OR_INT;
1442 }
1443 if (hextype == UINT)
1444 {
1445 yylval.ssym.sym = sym;
1446 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1447 return NAME_OR_UINT;
1448 }
1449 }
1450
1451 /* Any other kind of symbol */
1452 yylval.ssym.sym = sym;
1453 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1454 return NAME;
1455 }
1456 }
1457
1458 void
1459 yyerror (msg)
1460 char *msg;
1461 {
1462 error (msg ? msg : "Invalid syntax in expression.");
1463 }
1464 \f
1465 /* Table mapping opcodes into strings for printing operators
1466 and precedences of the operators. */
1467
1468 const static struct op_print c_op_print_tab[] =
1469 {
1470 {",", BINOP_COMMA, PREC_COMMA, 0},
1471 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1472 {"||", BINOP_OR, PREC_OR, 0},
1473 {"&&", BINOP_AND, PREC_AND, 0},
1474 {"|", BINOP_LOGIOR, PREC_LOGIOR, 0},
1475 {"&", BINOP_LOGAND, PREC_LOGAND, 0},
1476 {"^", BINOP_LOGXOR, PREC_LOGXOR, 0},
1477 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
1478 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1479 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1480 {">=", BINOP_GEQ, PREC_ORDER, 0},
1481 {">", BINOP_GTR, PREC_ORDER, 0},
1482 {"<", BINOP_LESS, PREC_ORDER, 0},
1483 {">>", BINOP_RSH, PREC_SHIFT, 0},
1484 {"<<", BINOP_LSH, PREC_SHIFT, 0},
1485 {"+", BINOP_ADD, PREC_ADD, 0},
1486 {"-", BINOP_SUB, PREC_ADD, 0},
1487 {"*", BINOP_MUL, PREC_MUL, 0},
1488 {"/", BINOP_DIV, PREC_MUL, 0},
1489 {"%", BINOP_REM, PREC_MUL, 0},
1490 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1491 {"-", UNOP_NEG, PREC_PREFIX, 0},
1492 {"!", UNOP_ZEROP, PREC_PREFIX, 0},
1493 {"~", UNOP_LOGNOT, PREC_PREFIX, 0},
1494 {"*", UNOP_IND, PREC_PREFIX, 0},
1495 {"&", UNOP_ADDR, PREC_PREFIX, 0},
1496 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
1497 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
1498 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
1499 /* C++ */
1500 {"::", BINOP_SCOPE, PREC_PREFIX, 0},
1501 };
1502 \f
1503 /* These variables point to the objects
1504 representing the predefined C data types. */
1505
1506 struct type *builtin_type_void;
1507 struct type *builtin_type_char;
1508 struct type *builtin_type_short;
1509 struct type *builtin_type_int;
1510 struct type *builtin_type_long;
1511 struct type *builtin_type_long_long;
1512 struct type *builtin_type_signed_char;
1513 struct type *builtin_type_unsigned_char;
1514 struct type *builtin_type_unsigned_short;
1515 struct type *builtin_type_unsigned_int;
1516 struct type *builtin_type_unsigned_long;
1517 struct type *builtin_type_unsigned_long_long;
1518 struct type *builtin_type_float;
1519 struct type *builtin_type_double;
1520 struct type *builtin_type_long_double;
1521 struct type *builtin_type_complex;
1522 struct type *builtin_type_double_complex;
1523
1524 struct type ** const (c_builtin_types[]) =
1525 {
1526 &builtin_type_int,
1527 &builtin_type_long,
1528 &builtin_type_short,
1529 &builtin_type_char,
1530 &builtin_type_float,
1531 &builtin_type_double,
1532 &builtin_type_void,
1533 &builtin_type_long_long,
1534 &builtin_type_signed_char,
1535 &builtin_type_unsigned_char,
1536 &builtin_type_unsigned_short,
1537 &builtin_type_unsigned_int,
1538 &builtin_type_unsigned_long,
1539 &builtin_type_unsigned_long_long,
1540 &builtin_type_long_double,
1541 &builtin_type_complex,
1542 &builtin_type_double_complex,
1543 0
1544 };
1545
1546 const struct language_defn c_language_defn = {
1547 "c", /* Language name */
1548 language_c,
1549 c_builtin_types,
1550 range_check_off,
1551 type_check_off,
1552 c_parse,
1553 c_error,
1554 &BUILTIN_TYPE_LONGEST, /* longest signed integral type */
1555 &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */
1556 &builtin_type_double, /* longest floating point type */ /*FIXME*/
1557 "0x%x", "0x%", "x", /* Hex format, prefix, suffix */
1558 "0%o", "0%", "o", /* Octal format, prefix, suffix */
1559 c_op_print_tab, /* expression operators for printing */
1560 LANG_MAGIC
1561 };
1562
1563 const struct language_defn cplus_language_defn = {
1564 "c++", /* Language name */
1565 language_cplus,
1566 c_builtin_types,
1567 range_check_off,
1568 type_check_off,
1569 c_parse,
1570 c_error,
1571 &BUILTIN_TYPE_LONGEST, /* longest signed integral type */
1572 &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */
1573 &builtin_type_double, /* longest floating point type */ /*FIXME*/
1574 "0x%x", "0x%", "x", /* Hex format, prefix, suffix */
1575 "0%o", "0%", "o", /* Octal format, prefix, suffix */
1576 c_op_print_tab, /* expression operators for printing */
1577 LANG_MAGIC
1578 };
1579
1580 void
1581 _initialize_c_exp ()
1582 {
1583 builtin_type_void =
1584 init_type (TYPE_CODE_VOID, 1,
1585 0,
1586 "void", (struct objfile *) NULL);
1587 builtin_type_char =
1588 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1589 0,
1590 "char", (struct objfile *) NULL);
1591 builtin_type_signed_char =
1592 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1593 TYPE_FLAG_SIGNED,
1594 "signed char", (struct objfile *) NULL);
1595 builtin_type_unsigned_char =
1596 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1597 TYPE_FLAG_UNSIGNED,
1598 "unsigned char", (struct objfile *) NULL);
1599 builtin_type_short =
1600 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1601 0,
1602 "short", (struct objfile *) NULL);
1603 builtin_type_unsigned_short =
1604 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1605 TYPE_FLAG_UNSIGNED,
1606 "unsigned short", (struct objfile *) NULL);
1607 builtin_type_int =
1608 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1609 0,
1610 "int", (struct objfile *) NULL);
1611 builtin_type_unsigned_int =
1612 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1613 TYPE_FLAG_UNSIGNED,
1614 "unsigned int", (struct objfile *) NULL);
1615 builtin_type_long =
1616 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1617 0,
1618 "long", (struct objfile *) NULL);
1619 builtin_type_unsigned_long =
1620 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1621 TYPE_FLAG_UNSIGNED,
1622 "unsigned long", (struct objfile *) NULL);
1623 builtin_type_long_long =
1624 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1625 0,
1626 "long long", (struct objfile *) NULL);
1627 builtin_type_unsigned_long_long =
1628 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1629 TYPE_FLAG_UNSIGNED,
1630 "unsigned long long", (struct objfile *) NULL);
1631 builtin_type_float =
1632 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1633 0,
1634 "float", (struct objfile *) NULL);
1635 builtin_type_double =
1636 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
1637 0,
1638 "double", (struct objfile *) NULL);
1639 builtin_type_long_double =
1640 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
1641 0,
1642 "long double", (struct objfile *) NULL);
1643 builtin_type_complex =
1644 init_type (TYPE_CODE_FLT, TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
1645 0,
1646 "complex", (struct objfile *) NULL);
1647 builtin_type_double_complex =
1648 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
1649 0,
1650 "double complex", (struct objfile *) NULL);
1651
1652 add_language (&c_language_defn);
1653 add_language (&cplus_language_defn);
1654 }