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