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